Skip to content

Commit

Permalink
PHPStan 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mbabker committed Dec 4, 2024
1 parent 63b931e commit a40b4e0
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 23 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
fail-fast: true
matrix:
php: ['8.1', '8.2', '8.3', '8.4']
symfony: ['5.4.*', '6.4.*', '7.1.*', '7.2.*@rc']
symfony: ['5.4.*', '6.4.*', '7.1.*', '7.2.*']
pagerfanta: ['']
composer-flags: ['--prefer-stable']
can-fail: [false]
Expand All @@ -31,7 +31,7 @@ jobs:
- php: '8.1'
symfony: '7.1.*'
- php: '8.1'
symfony: '7.2.*@rc'
symfony: '7.2.*'

name: "PHP ${{ matrix.php }}${{ matrix.pagerfanta != '' && format(' - Pagerfanta {0}', matrix.pagerfanta) || '' }}${{ matrix.with-twig == false && ' - Without Twig' || '' }} - Symfony ${{ matrix.symfony }}${{ matrix.composer-flags != '' && format(' - Composer {0}', matrix.composer-flags) || '' }}"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Install dependencies
run: composer update --prefer-stable --prefer-dist
env:
SYMFONY_REQUIRE: '7.2.*@rc'
SYMFONY_REQUIRE: '7.2.*'

- name: Run PHPStan
run: vendor/bin/phpstan analyze --error-format=github
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
"matthiasnoback/symfony-dependency-injection-test": "^5.0",
"pagerfanta/twig": "^3.7 || ^4.0",
"phpstan/extension-installer": "^1.3",
"phpstan/phpstan": "1.12.11",
"phpstan/phpstan-phpunit": "1.4.1",
"phpstan/phpstan-symfony": "1.4.12",
"phpstan/phpstan": "2.0.3",
"phpstan/phpstan-phpunit": "2.0.1",
"phpstan/phpstan-symfony": "2.0.0",
"phpunit/phpunit": "9.6.21",
"symfony/phpunit-bridge": "^5.4 || ^6.4 || ^7.1",
"symfony/serializer": "^5.4 || ^6.4 || ^7.1",
Expand Down
48 changes: 42 additions & 6 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,32 +1,68 @@
parameters:
ignoreErrors:
-
message: "#^Parameter \\#2 \\.\\.\\.\\$arrays of function array_merge expects array, mixed given\\.$#"
message: '#^Cannot access offset ''not_valid_current_page'' on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 1
path: src/DependencyInjection/BabDevPagerfantaExtension.php

-
message: '#^Cannot access offset ''out_of_range_page'' on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 1
path: src/DependencyInjection/BabDevPagerfantaExtension.php

-
message: '#^Cannot access offset ''alias'' on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 2
path: src/DependencyInjection/CompilerPass/RegisterPagerfantaViewsPass.php

-
message: '#^Parameter \#2 \.\.\.\$arrays of function array_merge expects array, mixed given\.$#'
identifier: argument.type
count: 2
path: src/RouteGenerator/RequestAwareRouteGeneratorFactory.php

-
message: "#^Parameter \\#2 \\$parameters of method Symfony\\\\Component\\\\Routing\\\\Generator\\\\UrlGeneratorInterface\\:\\:generate\\(\\) expects array, array\\|object given\\.$#"
message: '#^Parameter \#3 \$options of class BabDev\\PagerfantaBundle\\RouteGenerator\\RouterAwareRouteGenerator constructor expects array\{routeName\: non\-empty\-string, pageParameter\?\: non\-empty\-string, omitFirstPage\?\: bool, routeParams\?\: array\<string, mixed\>, referenceType\?\: 0\|1\|2\|3\}, non\-empty\-array\<string, mixed\> given\.$#'
identifier: argument.type
count: 1
path: src/RouteGenerator/RequestAwareRouteGeneratorFactory.php

-
message: '#^Default value of the parameter \#3 \$options \(array\{\}\) of method BabDev\\PagerfantaBundle\\RouteGenerator\\RouterAwareRouteGenerator\:\:__construct\(\) is incompatible with type array\{routeName\: non\-empty\-string, pageParameter\?\: non\-empty\-string, omitFirstPage\?\: bool, routeParams\?\: array\<string, mixed\>, referenceType\?\: 0\|1\|2\|3\}\.$#'
identifier: parameter.defaultValue
count: 1
path: src/RouteGenerator/RouterAwareRouteGenerator.php

-
message: "#^Method BabDev\\\\PagerfantaBundle\\\\View\\\\ContainerBackedImmutableViewFactory\\:\\:get\\(\\) should return Pagerfanta\\\\View\\\\ViewInterface but returns mixed\\.$#"
message: '#^Method BabDev\\PagerfantaBundle\\Serializer\\Handler\\PagerfantaHandler\:\:serializeToJson\(\) should return array\<string, mixed\>\|ArrayObject\<string, mixed\> but returns array\|ArrayObject\.$#'
identifier: return.type
count: 1
path: src/Serializer/Handler/PagerfantaHandler.php

-
message: '#^Method BabDev\\PagerfantaBundle\\View\\ContainerBackedImmutableViewFactory\:\:get\(\) should return Pagerfanta\\View\\ViewInterface but returns mixed\.$#'
identifier: return.type
count: 1
path: src/View/ContainerBackedImmutableViewFactory.php

-
message: "#^Parameter \\#2 \\$array of static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertArrayHasKey\\(\\) expects array\\|ArrayAccess, mixed given\\.$#"
message: '#^Parameter \#2 \$array of static method PHPUnit\\Framework\\Assert\:\:assertArrayHasKey\(\) expects array\|ArrayAccess, mixed given\.$#'
identifier: argument.type
count: 1
path: tests/DependencyInjection/BabDevPagerfantaExtensionTest.php

-
message: "#^Method BabDev\\\\PagerfantaBundle\\\\Tests\\\\View\\\\TwigViewIntegrationTest\\:\\:removeWhitespacesBetweenTags\\(\\) should return string but returns string\\|null\\.$#"
message: '#^Method BabDev\\PagerfantaBundle\\Tests\\View\\TwigViewIntegrationTest\:\:removeWhitespacesBetweenTags\(\) should return string but returns string\|null\.$#'
identifier: return.type
count: 1
path: tests/View/TwigViewIntegrationTest.php

-
message: "#^Parameter \\#1 \\$path of function dirname expects string, string\\|false given\\.$#"
message: '#^Parameter \#1 \$path of function dirname expects string, string\|false given\.$#'
identifier: argument.type
count: 1
path: tests/View/TwigViewIntegrationTest.php

6 changes: 6 additions & 0 deletions src/RouteGenerator/RouterAwareRouteGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@
use Symfony\Component\PropertyAccess\PropertyPath;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

/**
* @phpstan-type RouteGeneratorOptions array{routeName: non-empty-string, pageParameter?: non-empty-string, omitFirstPage?: bool, routeParams?: array<string, mixed>, referenceType?: UrlGeneratorInterface::*}
*/
final class RouterAwareRouteGenerator implements RouteGeneratorInterface
{
/**
* @phpstan-param RouteGeneratorOptions $options
*/
public function __construct(
private readonly UrlGeneratorInterface $router,
private readonly PropertyAccessorInterface $propertyAccessor,
Expand Down
2 changes: 1 addition & 1 deletion src/Twig/UndefinedCallableHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class UndefinedCallableHandler
/**
* @throws SyntaxError if the undefined function is supported by this handler
*/
public function onUndefinedFunction(string $name): ?bool
public function onUndefinedFunction(string $name): bool
{
if (!\in_array($name, self::SUPPORTED_FUNCTIONS, true)) {
return false;
Expand Down
16 changes: 8 additions & 8 deletions tests/RouteGenerator/RequestAwareRouteGeneratorFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ protected function tearDown(): void
} while (null !== $request);
}

/**
* @doesNotPerformAssertions
*/
public function testTheGeneratorIsCreatedWhenResolvingTheRouteNameFromTheRequest(): void
{
$request = Request::create('/');
Expand All @@ -42,12 +45,12 @@ public function testTheGeneratorIsCreatedWhenResolvingTheRouteNameFromTheRequest

$this->requestStack->push($request);

self::assertInstanceOf(
RouteGeneratorInterface::class,
$this->createFactory()->create(),
);
$this->createFactory()->create();
}

/**
* @doesNotPerformAssertions
*/
public function testTheGeneratorIsCreatedWhenGivenARouteNameDuringASubrequest(): void
{
$masterRequest = Request::create('/');
Expand All @@ -59,10 +62,7 @@ public function testTheGeneratorIsCreatedWhenGivenARouteNameDuringASubrequest():
$this->requestStack->push($masterRequest);
$this->requestStack->push($subRequest);

self::assertInstanceOf(
RouteGeneratorInterface::class,
$this->createFactory()->create(['routeName' => 'pagerfanta_view']),
);
$this->createFactory()->create(['routeName' => 'pagerfanta_view']);
}

public function testTheGeneratorIsNotCreatedWhenARouteNameIsNotGivenDuringASubrequest(): void
Expand Down
2 changes: 1 addition & 1 deletion tests/RouteGenerator/RouterAwareRouteGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function testARouteIsNotGeneratedWhenTheRouteNameParameterIsMissing(): vo
$generator = new RouterAwareRouteGenerator(
$this->createRouter(),
$this->createPropertyAccessor(),
['routeParams' => ['hello' => 'world']],
['routeParams' => ['hello' => 'world']], /** @phpstan-ignore-line argument.type */
);

$generator(1);
Expand Down
2 changes: 1 addition & 1 deletion tests/View/TwigViewIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected function tearDown(): void
}

/**
* @return Pagerfanta<int>
* @return Pagerfanta<int<1, 100>>
*/
private function createPagerfanta(): Pagerfanta
{
Expand Down

0 comments on commit a40b4e0

Please sign in to comment.