From d6fa8dadb32196b9b95ffb5fb18257a8bc1dd19d Mon Sep 17 00:00:00 2001 From: LVoogd Date: Sat, 23 Nov 2024 13:16:46 +0100 Subject: [PATCH] Update phpstan In this commit phpstan is updated to the latest version (2.0.2). By doing so some new errors bubbled up, these are also addressed in this commit. --- composer.json | 2 +- composer.lock | 14 +++++------ phpstan-baseline.neon | 24 ++++++++++++++----- .../Repository/InMemoryArticleRepository.php | 2 +- ...oviderSourceShouldBeUniqueCompilerPass.php | 2 +- src/Feed/Infrastructure/Helper/DOM/DOM.php | 2 +- .../Article/DoctrineArticleRepository.php | 4 ++-- 7 files changed, 31 insertions(+), 19 deletions(-) diff --git a/composer.json b/composer.json index 3e78926..7b3a494 100644 --- a/composer.json +++ b/composer.json @@ -76,7 +76,7 @@ "require-dev": { "doctrine/doctrine-fixtures-bundle": "^3.4", "fakerphp/faker": "^1.21", - "phpstan/phpstan": "^1.10", + "phpstan/phpstan": "^2.0", "phpunit/phpunit": "^9.5", "squizlabs/php_codesniffer": "^3.7", "symfony/browser-kit": "7.1.*", diff --git a/composer.lock b/composer.lock index 366c9fa..625c087 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "fddb73ecc719253cea664337fb7dbdff", + "content-hash": "cb39f9597e049a090aa14afd845f44f5", "packages": [ { "name": "brick/math", @@ -6159,20 +6159,20 @@ }, { "name": "phpstan/phpstan", - "version": "1.12.6", + "version": "2.0.2", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "dc4d2f145a88ea7141ae698effd64d9df46527ae" + "reference": "6c98c7600fc717b2c78c11ef60040d5b1e359c82" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/dc4d2f145a88ea7141ae698effd64d9df46527ae", - "reference": "dc4d2f145a88ea7141ae698effd64d9df46527ae", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/6c98c7600fc717b2c78c11ef60040d5b1e359c82", + "reference": "6c98c7600fc717b2c78c11ef60040d5b1e359c82", "shasum": "" }, "require": { - "php": "^7.2|^8.0" + "php": "^7.4|^8.0" }, "conflict": { "phpstan/phpstan-shim": "*" @@ -6213,7 +6213,7 @@ "type": "github" } ], - "time": "2024-10-06T15:03:59+00:00" + "time": "2024-11-17T14:17:00+00:00" }, { "name": "phpunit/php-code-coverage", diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index c28551d..171cd6f 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,31 +1,43 @@ parameters: ignoreErrors: - - message: "#^Method Dev\\\\Common\\\\Infrastructure\\\\Cache\\\\RecordingCache\\:\\:get\\(\\) has parameter \\$metadata with no value type specified in iterable type array\\.$#" + message: '#^Method Dev\\Common\\Infrastructure\\Cache\\RecordingCache\:\:get\(\) has parameter \$metadata with no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue count: 1 path: src-dev/Common/Infrastructure/Cache/RecordingCache.php - - message: "#^Method App\\\\Feed\\\\Infrastructure\\\\Persistence\\\\Doctrine\\\\Article\\\\DoctrineArticleRepository\\:\\:findByUrl\\(\\) should return App\\\\Feed\\\\Domain\\\\Article\\\\Article\\|null but returns mixed\\.$#" + message: '#^Method App\\Feed\\Infrastructure\\Persistence\\Doctrine\\Article\\DoctrineArticleRepository\:\:findByUrl\(\) should return App\\Feed\\Domain\\Article\\Article\|null but returns mixed\.$#' + identifier: return.type count: 1 path: src/Feed/Infrastructure/Persistence/Doctrine/Article/DoctrineArticleRepository.php - - message: "#^Parameter \\#1 \\$id of class App\\\\Feed\\\\Domain\\\\Article\\\\ArticleId constructor expects string, mixed given\\.$#" + message: '#^Parameter \#1 \$id of class App\\Feed\\Domain\\Article\\ArticleId constructor expects string, mixed given\.$#' + identifier: argument.type count: 1 path: src/Feed/Infrastructure/Persistence/Doctrine/Article/DoctrineArticleRepository.php - - message: "#^Method App\\\\Feed\\\\Infrastructure\\\\Persistence\\\\Doctrine\\\\Source\\\\DoctrineSourceRepository\\:\\:findByNameOrThrow\\(\\) should return App\\\\Feed\\\\Domain\\\\Source\\\\Source but returns mixed\\.$#" + message: '#^Method App\\Feed\\Infrastructure\\Persistence\\Doctrine\\Source\\DoctrineSourceRepository\:\:findByNameOrThrow\(\) should return App\\Feed\\Domain\\Source\\Source but returns mixed\.$#' + identifier: return.type count: 1 path: src/Feed/Infrastructure/Persistence/Doctrine/Source/DoctrineSourceRepository.php - - message: "#^Parameter \\#2 \\$configurator of method Symfony\\\\Component\\\\DependencyInjection\\\\ContainerBuilder\\:\\:registerAttributeForAutoconfiguration\\(\\) expects callable\\(Symfony\\\\Component\\\\DependencyInjection\\\\ChildDefinition, App\\\\Common\\\\Infrastructure\\\\Messenger\\\\CommandBus\\\\AsCommandHandler, Reflector\\)\\: void, Closure\\(Symfony\\\\Component\\\\DependencyInjection\\\\ChildDefinition, App\\\\Common\\\\Infrastructure\\\\Messenger\\\\CommandBus\\\\AsCommandHandler, ReflectionClass\\|ReflectionMethod\\)\\: void given\\.$#" + message: '#^Parameter \#2 \$configurator of method Symfony\\Component\\DependencyInjection\\ContainerBuilder\:\:registerAttributeForAutoconfiguration\(\) expects callable\(Symfony\\Component\\DependencyInjection\\ChildDefinition, App\\Common\\Infrastructure\\Messenger\\CommandBus\\AsCommandHandler, Reflector\)\: void, Closure\(Symfony\\Component\\DependencyInjection\\ChildDefinition, App\\Common\\Infrastructure\\Messenger\\CommandBus\\AsCommandHandler, ReflectionClass\|ReflectionMethod\)\: void given\.$#' + identifier: argument.type count: 1 path: src/Kernel.php - - message: "#^Parameter \\#2 \\$configurator of method Symfony\\\\Component\\\\DependencyInjection\\\\ContainerBuilder\\:\\:registerAttributeForAutoconfiguration\\(\\) expects callable\\(Symfony\\\\Component\\\\DependencyInjection\\\\ChildDefinition, App\\\\Common\\\\Infrastructure\\\\Messenger\\\\EventBus\\\\AsEventSubscriber, Reflector\\)\\: void, Closure\\(Symfony\\\\Component\\\\DependencyInjection\\\\ChildDefinition, App\\\\Common\\\\Infrastructure\\\\Messenger\\\\EventBus\\\\AsEventSubscriber, ReflectionClass\\|ReflectionMethod\\)\\: void given\\.$#" + message: '#^Parameter \#2 \$configurator of method Symfony\\Component\\DependencyInjection\\ContainerBuilder\:\:registerAttributeForAutoconfiguration\(\) expects callable\(Symfony\\Component\\DependencyInjection\\ChildDefinition, App\\Common\\Infrastructure\\Messenger\\EventBus\\AsEventSubscriber, Reflector\)\: void, Closure\(Symfony\\Component\\DependencyInjection\\ChildDefinition, App\\Common\\Infrastructure\\Messenger\\EventBus\\AsEventSubscriber, ReflectionClass\|ReflectionMethod\)\: void given\.$#' + identifier: argument.type count: 1 path: src/Kernel.php + + - + message: '#^Expression "new class\(\$uuid\) extends \\App\\Common\\Identifier\\UuidId…" on a separate line does not do anything\.$#' + identifier: expr.resultUnused + count: 1 + path: tests/Unit/Common/Identifier/UuidIdTest.php diff --git a/src-dev/Feed/Repository/InMemoryArticleRepository.php b/src-dev/Feed/Repository/InMemoryArticleRepository.php index ced35ca..d844c46 100644 --- a/src-dev/Feed/Repository/InMemoryArticleRepository.php +++ b/src-dev/Feed/Repository/InMemoryArticleRepository.php @@ -46,7 +46,7 @@ public function findLatestIds(int $offset, int $numberOfArticles): array return array_map( fn(Article $entity) => $entity->getId(), - array_values(array_slice($entities, $offset, $numberOfArticles)) + array_slice($entities, $offset, $numberOfArticles) ); } diff --git a/src/Feed/Infrastructure/Framework/CompilerPass/FeedProviderSourceShouldBeUniqueCompilerPass.php b/src/Feed/Infrastructure/Framework/CompilerPass/FeedProviderSourceShouldBeUniqueCompilerPass.php index 810f4d6..9e19e1b 100644 --- a/src/Feed/Infrastructure/Framework/CompilerPass/FeedProviderSourceShouldBeUniqueCompilerPass.php +++ b/src/Feed/Infrastructure/Framework/CompilerPass/FeedProviderSourceShouldBeUniqueCompilerPass.php @@ -23,7 +23,7 @@ public function process(ContainerBuilder $container): void throw new \Exception('%s must implement static method `getSource`.'); } - $source = call_user_func([$service, 'getSource']); + $source = $service::getSource(); if (in_array($source, $sources)) { throw new \Exception(sprintf( diff --git a/src/Feed/Infrastructure/Helper/DOM/DOM.php b/src/Feed/Infrastructure/Helper/DOM/DOM.php index afcc9e2..8ee89e9 100644 --- a/src/Feed/Infrastructure/Helper/DOM/DOM.php +++ b/src/Feed/Infrastructure/Helper/DOM/DOM.php @@ -12,7 +12,7 @@ { public static function getString(DOMElement $element, string $key): string { - return $element->getElementsByTagName($key)->item(0)?->firstChild?->nodeValue + return $element->getElementsByTagName($key)->item(0)?->firstChild->nodeValue ?? throw new OutOfBoundsException(sprintf('`%s` does not exist in DOMElement', $key)); } diff --git a/src/Feed/Infrastructure/Persistence/Doctrine/Article/DoctrineArticleRepository.php b/src/Feed/Infrastructure/Persistence/Doctrine/Article/DoctrineArticleRepository.php index cb9c0df..301f954 100644 --- a/src/Feed/Infrastructure/Persistence/Doctrine/Article/DoctrineArticleRepository.php +++ b/src/Feed/Infrastructure/Persistence/Doctrine/Article/DoctrineArticleRepository.php @@ -56,7 +56,7 @@ public function findLatestIds( int $offset, int $numberOfArticles, ): array { - return array_map( + return array_values(array_map( fn($id) => new ArticleId($id), $this->createQueryBuilder('a') ->select('a.id') @@ -65,7 +65,7 @@ public function findLatestIds( ->setMaxResults($numberOfArticles) ->getQuery() ->getSingleColumnResult() - ); + )); } public function findByUrl(string $url): ?Article