From 2208f509835320c951b6e700fb5a1561e00f4710 Mon Sep 17 00:00:00 2001 From: Patrick Kenny Date: Thu, 12 Dec 2024 16:58:05 +0900 Subject: [PATCH 01/41] update to rector 2.0-rc2 and bump phpstan dependencies to 2.x --- composer.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 537f672b..bde7357e 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ "ast" ], "require": { - "rector/rector": "^1.0", + "rector/rector": "^2.0-rc2@rc", "webflo/drupal-finder": "^1.2" }, "license": "MIT", @@ -76,9 +76,9 @@ "php": "^8.2", "cweagans/composer-patches": "^1.7.2", "friendsofphp/php-cs-fixer": "^3.58", - "phpstan/extension-installer": "^1.1", - "phpstan/phpstan": "^1.0", - "phpstan/phpstan-deprecation-rules": "^1.0", + "phpstan/extension-installer": "^1.4.3", + "phpstan/phpstan": "^2.0", + "phpstan/phpstan-deprecation-rules": "^2.0", "phpunit/phpunit": "^10.0", "symfony/yaml": "^5 || ^6 || ^7", "symplify/vendor-patches": "^11.0" From 5148bed3d1f65aef2a0e2c9dc9681e8da73c83a3 Mon Sep 17 00:00:00 2001 From: Patrick Kenny Date: Thu, 12 Dec 2024 17:03:16 +0900 Subject: [PATCH 02/41] use rc3 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index bde7357e..06662c39 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ "ast" ], "require": { - "rector/rector": "^2.0-rc2@rc", + "rector/rector": "^2.0.0-rc3", "webflo/drupal-finder": "^1.2" }, "license": "MIT", From d83f9ece50ce7a2ca4b57136b05715a34b1cd677 Mon Sep 17 00:00:00 2001 From: Patrick Kenny Date: Thu, 12 Dec 2024 17:06:19 +0900 Subject: [PATCH 03/41] rector 2.0.0-rc3 requires phpstan 2.0.1 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 06662c39..30025cbb 100644 --- a/composer.json +++ b/composer.json @@ -77,7 +77,7 @@ "cweagans/composer-patches": "^1.7.2", "friendsofphp/php-cs-fixer": "^3.58", "phpstan/extension-installer": "^1.4.3", - "phpstan/phpstan": "^2.0", + "phpstan/phpstan": "^2.0.1", "phpstan/phpstan-deprecation-rules": "^2.0", "phpunit/phpunit": "^10.0", "symfony/yaml": "^5 || ^6 || ^7", From 1e5a085202144f53c7da1814326b45d8db2ffb9f Mon Sep 17 00:00:00 2001 From: Patrick Kenny Date: Thu, 12 Dec 2024 17:09:16 +0900 Subject: [PATCH 04/41] remove functional tests for Drupal 9 because PHP 8.0 is not supported by PHPStan 2.0 --- .github/workflows/functional_test__rector_examples.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/functional_test__rector_examples.yml b/.github/workflows/functional_test__rector_examples.yml index a2fbfb73..456c25fa 100644 --- a/.github/workflows/functional_test__rector_examples.yml +++ b/.github/workflows/functional_test__rector_examples.yml @@ -18,9 +18,6 @@ jobs: fail-fast: false matrix: include: - - php-version: "8.0" - drupal: "^9.2" - fixture: "d9" - php-version: "8.1" drupal: "^10.0" fixture: "d10" From 8c434cf5141ad66941081fa2632842a76000d58c Mon Sep 17 00:00:00 2001 From: Patrick Kenny Date: Mon, 6 Jan 2025 22:50:22 +0900 Subject: [PATCH 05/41] require rector 2.0 final --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 30025cbb..e8e66570 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ "ast" ], "require": { - "rector/rector": "^2.0.0-rc3", + "rector/rector": "^2.0", "webflo/drupal-finder": "^1.2" }, "license": "MIT", From b3b823c3d41ab4b238dd7473dd4dcc9cbdc2ea6b Mon Sep 17 00:00:00 2001 From: bjorn Date: Fri, 24 Jan 2025 10:20:52 +0100 Subject: [PATCH 06/41] fix: remove deprecated SetInterface --- phpstan-baseline.neon | 24 ------------------------ src/Set/Drupal10SetList.php | 4 +--- src/Set/Drupal8SetList.php | 4 +--- src/Set/Drupal9SetList.php | 4 +--- 4 files changed, 3 insertions(+), 33 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 38ca9036..8cb19a04 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -155,27 +155,3 @@ parameters: """ count: 1 path: src/Drupal9/Rector/Deprecation/PassRector.php - - - - message: """ - #^Class DrupalRector\\\\Set\\\\Drupal10SetList implements deprecated interface Rector\\\\Set\\\\Contract\\\\SetListInterface\\: - This interface needs a reflection to load and uses constant links\\. Now we changed to services provider architecture that can be used and registerd easily\\. Use$# - """ - count: 1 - path: src/Set/Drupal10SetList.php - - - - message: """ - #^Class DrupalRector\\\\Set\\\\Drupal8SetList implements deprecated interface Rector\\\\Set\\\\Contract\\\\SetListInterface\\: - This interface needs a reflection to load and uses constant links\\. Now we changed to services provider architecture that can be used and registerd easily\\. Use$# - """ - count: 1 - path: src/Set/Drupal8SetList.php - - - - message: """ - #^Class DrupalRector\\\\Set\\\\Drupal9SetList implements deprecated interface Rector\\\\Set\\\\Contract\\\\SetListInterface\\: - This interface needs a reflection to load and uses constant links\\. Now we changed to services provider architecture that can be used and registerd easily\\. Use$# - """ - count: 1 - path: src/Set/Drupal9SetList.php diff --git a/src/Set/Drupal10SetList.php b/src/Set/Drupal10SetList.php index 724dd993..c0829218 100644 --- a/src/Set/Drupal10SetList.php +++ b/src/Set/Drupal10SetList.php @@ -4,9 +4,7 @@ namespace DrupalRector\Set; -use Rector\Set\Contract\SetListInterface; - -final class Drupal10SetList implements SetListInterface +final class Drupal10SetList { public const DRUPAL_10 = __DIR__.'/../../config/drupal-10/drupal-10-all-deprecations.php'; public const DRUPAL_100 = __DIR__.'/../../config/drupal-10/drupal-10.0-deprecations.php'; diff --git a/src/Set/Drupal8SetList.php b/src/Set/Drupal8SetList.php index 17ced2b9..810190b7 100644 --- a/src/Set/Drupal8SetList.php +++ b/src/Set/Drupal8SetList.php @@ -4,9 +4,7 @@ namespace DrupalRector\Set; -use Rector\Set\Contract\SetListInterface; - -final class Drupal8SetList implements SetListInterface +final class Drupal8SetList { public const DRUPAL_8 = __DIR__.'/../../config/drupal-8/drupal-8-all-deprecations.php'; public const DRUPAL_80 = __DIR__.'/../../config/drupal-8/drupal-8.0-deprecations.php'; diff --git a/src/Set/Drupal9SetList.php b/src/Set/Drupal9SetList.php index 1141640f..b6397ec9 100644 --- a/src/Set/Drupal9SetList.php +++ b/src/Set/Drupal9SetList.php @@ -4,9 +4,7 @@ namespace DrupalRector\Set; -use Rector\Set\Contract\SetListInterface; - -final class Drupal9SetList implements SetListInterface +final class Drupal9SetList { public const DRUPAL_9 = __DIR__.'/../../config/drupal-9/drupal-9-all-deprecations.php'; public const DRUPAL_90 = __DIR__.'/../../config/drupal-9/drupal-9.0-deprecations.php'; From 6afdd39e340c80e169b87322a3a185b13a2ae5ad Mon Sep 17 00:00:00 2001 From: bjorn Date: Fri, 24 Jan 2025 10:23:39 +0100 Subject: [PATCH 07/41] build: fix codestyle --- src/Drupal8/Rector/Deprecation/DBRector.php | 2 +- src/Drupal8/Rector/Deprecation/DrupalServiceRenameRector.php | 2 +- src/Drupal8/Rector/Deprecation/EntityLoadRector.php | 2 +- src/Drupal9/Rector/Deprecation/ExtensionPathRector.php | 2 +- .../Rector/Deprecation/UiHelperTraitDrupalPostFormRector.php | 2 +- src/Rector/AbstractDrupalCoreRector.php | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Drupal8/Rector/Deprecation/DBRector.php b/src/Drupal8/Rector/Deprecation/DBRector.php index 4963b5f7..d4c6df70 100644 --- a/src/Drupal8/Rector/Deprecation/DBRector.php +++ b/src/Drupal8/Rector/Deprecation/DBRector.php @@ -56,7 +56,7 @@ class DBRector extends AbstractRector implements ConfigurableRectorInterface protected $optionsArgumentPosition; /** - * @var \DrupalRector\Drupal8\Rector\ValueObject\DBConfiguration[] + * @var DBConfiguration[] */ private array $configuration; diff --git a/src/Drupal8/Rector/Deprecation/DrupalServiceRenameRector.php b/src/Drupal8/Rector/Deprecation/DrupalServiceRenameRector.php index 43726353..61b17330 100644 --- a/src/Drupal8/Rector/Deprecation/DrupalServiceRenameRector.php +++ b/src/Drupal8/Rector/Deprecation/DrupalServiceRenameRector.php @@ -14,7 +14,7 @@ class DrupalServiceRenameRector extends AbstractRector implements ConfigurableRectorInterface { /** - * @var \DrupalRector\Drupal8\Rector\ValueObject\DrupalServiceRenameConfiguration[] + * @var DrupalServiceRenameConfiguration[] */ protected array $staticArgumentRenameConfigs = []; diff --git a/src/Drupal8/Rector/Deprecation/EntityLoadRector.php b/src/Drupal8/Rector/Deprecation/EntityLoadRector.php index 7c3bb7fa..66b5e5b5 100644 --- a/src/Drupal8/Rector/Deprecation/EntityLoadRector.php +++ b/src/Drupal8/Rector/Deprecation/EntityLoadRector.php @@ -27,7 +27,7 @@ final class EntityLoadRector extends AbstractRector implements ConfigurableRectorInterface { /** - * @var \DrupalRector\Drupal8\Rector\ValueObject\EntityLoadConfiguration[] + * @var EntityLoadConfiguration[] */ protected array $entityTypes; diff --git a/src/Drupal9/Rector/Deprecation/ExtensionPathRector.php b/src/Drupal9/Rector/Deprecation/ExtensionPathRector.php index e0d9ca33..a8043d94 100644 --- a/src/Drupal9/Rector/Deprecation/ExtensionPathRector.php +++ b/src/Drupal9/Rector/Deprecation/ExtensionPathRector.php @@ -15,7 +15,7 @@ class ExtensionPathRector extends AbstractRector implements ConfigurableRectorInterface { /** - * @var \DrupalRector\Drupal9\Rector\ValueObject\ExtensionPathConfiguration[] + * @var ExtensionPathConfiguration[] */ private array $configuration; diff --git a/src/Drupal9/Rector/Deprecation/UiHelperTraitDrupalPostFormRector.php b/src/Drupal9/Rector/Deprecation/UiHelperTraitDrupalPostFormRector.php index 208f4ebf..9a3462ee 100644 --- a/src/Drupal9/Rector/Deprecation/UiHelperTraitDrupalPostFormRector.php +++ b/src/Drupal9/Rector/Deprecation/UiHelperTraitDrupalPostFormRector.php @@ -48,7 +48,7 @@ public function getNodeTypes(): array * * @throws ShouldNotHappenException * - * @return array + * @return array */ private function safeArgDestructure(Node\Expr\MethodCall $node): array { diff --git a/src/Rector/AbstractDrupalCoreRector.php b/src/Rector/AbstractDrupalCoreRector.php index 89ac7c5b..8edfb174 100644 --- a/src/Rector/AbstractDrupalCoreRector.php +++ b/src/Rector/AbstractDrupalCoreRector.php @@ -16,7 +16,7 @@ abstract class AbstractDrupalCoreRector extends AbstractRector implements ConfigurableRectorInterface { /** - * @var array|\DrupalRector\Contract\VersionedConfigurationInterface[] + * @var array|VersionedConfigurationInterface[] */ protected array $configuration = []; From 3b2eb98da7b81644fe719a68f7383f385863ec22 Mon Sep 17 00:00:00 2001 From: bjorn Date: Fri, 24 Jan 2025 10:26:58 +0100 Subject: [PATCH 08/41] fix: BC twig setlist --- config/drupal-10/drupal-10.0-deprecations.php | 9 ++++++++- config/drupal-9/drupal-9.0-deprecations.php | 8 +++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/config/drupal-10/drupal-10.0-deprecations.php b/config/drupal-10/drupal-10.0-deprecations.php index 1c9e42f8..e296b381 100644 --- a/config/drupal-10/drupal-10.0-deprecations.php +++ b/config/drupal-10/drupal-10.0-deprecations.php @@ -9,6 +9,12 @@ use Rector\Symfony\Set\TwigSetList; return static function (RectorConfig $rectorConfig): void { + if (defined('TwigSetList::TWIG_24')) { + $twigSet = TwigSetList::TWIG_24; + } else { + $twigSet = TwigSetList::TWIG_240; + } + $rectorConfig->sets([ PHPUnitSetList::PHPUNIT_90, SymfonySetList::SYMFONY_50, @@ -19,8 +25,9 @@ SymfonySetList::SYMFONY_60, SymfonySetList::SYMFONY_61, SymfonySetList::SYMFONY_62, - TwigSetList::TWIG_240, + $twigSet, ]); + $rectorConfig->rule(ShouldCallParentMethodsRector::class); }; diff --git a/config/drupal-9/drupal-9.0-deprecations.php b/config/drupal-9/drupal-9.0-deprecations.php index e981836e..035f0dfd 100644 --- a/config/drupal-9/drupal-9.0-deprecations.php +++ b/config/drupal-9/drupal-9.0-deprecations.php @@ -15,6 +15,12 @@ return new AddCommentService(); }); + if (defined('TwigSetList::TWIG_24')) { + $twigSet = TwigSetList::TWIG_24; + } else { + $twigSet = TwigSetList::TWIG_240; + } + $rectorConfig->sets([ PHPUnitSetList::PHPUNIT_80, SymfonySetList::SYMFONY_40, @@ -22,7 +28,7 @@ SymfonySetList::SYMFONY_42, SymfonySetList::SYMFONY_43, SymfonySetList::SYMFONY_44, - TwigSetList::TWIG_240, + $twigSet, ]); $rectorConfig->rule(ProtectedStaticModulesPropertyRector::class); From 9a67073af33a0b7d07bcda76436fcbc93ff7aa06 Mon Sep 17 00:00:00 2001 From: bjorn Date: Fri, 24 Jan 2025 10:27:33 +0100 Subject: [PATCH 09/41] fix: narrow return --- .../Rector/Deprecation/AnnotationToAttributeRector.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Drupal10/Rector/Deprecation/AnnotationToAttributeRector.php b/src/Drupal10/Rector/Deprecation/AnnotationToAttributeRector.php index ba2b311b..5af227b4 100644 --- a/src/Drupal10/Rector/Deprecation/AnnotationToAttributeRector.php +++ b/src/Drupal10/Rector/Deprecation/AnnotationToAttributeRector.php @@ -130,6 +130,9 @@ public function getNodeTypes(): array return [Class_::class]; } + /** + * @return PhpVersion::PHP_81 + */ public function provideMinPhpVersion(): int { return PhpVersion::PHP_81; @@ -145,7 +148,7 @@ public function refactor(Node $node): ?Node continue; } - $result = $this->refactorWithConfiguration($node, $configuration); + $result = $this->refactorWithConficlearguration($node, $configuration); // Skip if no result. if ($result === null) { From 62678b9aeee4aa38cee54e784585ddf5e485bb83 Mon Sep 17 00:00:00 2001 From: bjorn Date: Fri, 24 Jan 2025 10:27:45 +0100 Subject: [PATCH 10/41] fix: remove unneeded assert --- src/Rector/Deprecation/MethodToMethodWithCheckRector.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Rector/Deprecation/MethodToMethodWithCheckRector.php b/src/Rector/Deprecation/MethodToMethodWithCheckRector.php index 409feee4..9ab91198 100644 --- a/src/Rector/Deprecation/MethodToMethodWithCheckRector.php +++ b/src/Rector/Deprecation/MethodToMethodWithCheckRector.php @@ -117,8 +117,6 @@ public function refactor(Node $node): ?Node public function refactorNode(Node\Expr\MethodCall $node, ?Node\Stmt\Expression $statement, MethodToMethodWithCheckConfiguration $configuration): ?Node\Expr\MethodCall { - assert($node instanceof Node\Expr\MethodCall); - $callerType = $this->nodeTypeResolver->getType($node->var); $expectedType = new ObjectType($configuration->getClassName()); From 95a6cffc59c451904e493ba7c95ad1c864c8867d Mon Sep 17 00:00:00 2001 From: bjorn Date: Fri, 24 Jan 2025 10:27:51 +0100 Subject: [PATCH 11/41] fix: remove unneeded assert --- src/Drupal8/Rector/Deprecation/DrupalSetMessageRector.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Drupal8/Rector/Deprecation/DrupalSetMessageRector.php b/src/Drupal8/Rector/Deprecation/DrupalSetMessageRector.php index 4d3addba..caf66587 100644 --- a/src/Drupal8/Rector/Deprecation/DrupalSetMessageRector.php +++ b/src/Drupal8/Rector/Deprecation/DrupalSetMessageRector.php @@ -84,7 +84,6 @@ public function refactor(Node $node): ?Node } $expression = $node->expr; - assert($expression instanceof Node\Expr\FuncCall); if ($this->getName($expression->name) === 'drupal_set_message') { $scope = $node->getAttribute(AttributeKey::SCOPE); From 5d00610d952c2f5e86e2a8a3e87c708ff26f620b Mon Sep 17 00:00:00 2001 From: bjorn Date: Fri, 24 Jan 2025 10:28:24 +0100 Subject: [PATCH 12/41] fix: remove unneeded instanceof check --- src/Drupal8/Rector/Deprecation/EntityManagerRector.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Drupal8/Rector/Deprecation/EntityManagerRector.php b/src/Drupal8/Rector/Deprecation/EntityManagerRector.php index 9cfb53b5..a8739d2e 100644 --- a/src/Drupal8/Rector/Deprecation/EntityManagerRector.php +++ b/src/Drupal8/Rector/Deprecation/EntityManagerRector.php @@ -148,7 +148,7 @@ public function findInstanceByNameInAssign(Node\Expr\Assign $assign, string $cla $depth = 0; // Should the expression be the class we are looking for and the name is the one we are looking for, we can return early. - if ($node instanceof Node && $node instanceof $class && $this->getName($node->name) === $name) { + if ($node instanceof $class && $this->getName($node->name) === $name) { $node->setAttribute(self::class, $depth); return $node; @@ -185,7 +185,7 @@ public function findInstanceByNameInAssign(Node\Expr\Assign $assign, string $cla * * @return Node|null */ - public function replaceInstanceByNameInAssign(Node\Expr\Assign $assign, Node $replacement, string $class, string $name): ?Node + public function replaceInstanceByNameInAssign(Node\Expr\Assign $assign, Node $replacement, string $class, string $name): Node { $node = $assign->expr; From 992a2baf1d08073e9e013c7244b04608581449cb Mon Sep 17 00:00:00 2001 From: bjorn Date: Fri, 24 Jan 2025 10:28:47 +0100 Subject: [PATCH 13/41] fix: remove unneeded instanceof check --- src/Drupal8/Rector/Deprecation/EntityInterfaceLinkRector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Drupal8/Rector/Deprecation/EntityInterfaceLinkRector.php b/src/Drupal8/Rector/Deprecation/EntityInterfaceLinkRector.php index 31b85b90..9ffc0274 100644 --- a/src/Drupal8/Rector/Deprecation/EntityInterfaceLinkRector.php +++ b/src/Drupal8/Rector/Deprecation/EntityInterfaceLinkRector.php @@ -87,7 +87,7 @@ public function refactor(Node $node): ?Node return $node; } - if ($node->expr instanceof Node\Expr\Assign && $node->expr->expr instanceof Node\Expr\MethodCall) { + if ($node->expr->expr instanceof Node\Expr\MethodCall) { $methodCall = $this->getMethodCall($node->expr->expr, $node); $node->expr->expr = $methodCall; From 114657c50945c23790e64ca1dcd7a197e058a087 Mon Sep 17 00:00:00 2001 From: bjorn Date: Fri, 24 Jan 2025 10:30:25 +0100 Subject: [PATCH 14/41] fix: remove extra ctype cheks --- .../Rector/Property/ProtectedStaticModulesPropertyRector.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Drupal9/Rector/Property/ProtectedStaticModulesPropertyRector.php b/src/Drupal9/Rector/Property/ProtectedStaticModulesPropertyRector.php index 7206b85f..7b8116f2 100644 --- a/src/Drupal9/Rector/Property/ProtectedStaticModulesPropertyRector.php +++ b/src/Drupal9/Rector/Property/ProtectedStaticModulesPropertyRector.php @@ -53,9 +53,8 @@ public function getNodeTypes(): array /** * @param Node\Stmt\Property $node */ - public function refactor(Node $node): ?Node + public function refactor(Node $node): Node { - assert($node instanceof Node\Stmt\Property); if (!$this->isName($node, 'modules')) { return $node; } From daf34966a93686719df945dcbbc8677834bc31e4 Mon Sep 17 00:00:00 2001 From: bjorn Date: Fri, 24 Jan 2025 10:33:52 +0100 Subject: [PATCH 15/41] fix: REMOVE_NODE constant has moved --- phpstan-baseline.neon | 8 -------- src/Drupal9/Rector/Deprecation/PassRector.php | 4 ++-- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 8cb19a04..266ed64c 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -147,11 +147,3 @@ parameters: message: "#^Call to an undefined method PHPStan\\\\Type\\\\Type\\:\\:getValue\\(\\)\\.$#" count: 1 path: src/Drupal9/Rector/Deprecation/ExtensionPathRector.php - - - - message: """ - #^Fetching deprecated class constant REMOVE_NODE of class PhpParser\\\\NodeTraverser\\: - Use NodeVisitor\\:\\:REMOVE_NODE instead\\.$# - """ - count: 1 - path: src/Drupal9/Rector/Deprecation/PassRector.php diff --git a/src/Drupal9/Rector/Deprecation/PassRector.php b/src/Drupal9/Rector/Deprecation/PassRector.php index 60b68900..94a3dd12 100644 --- a/src/Drupal9/Rector/Deprecation/PassRector.php +++ b/src/Drupal9/Rector/Deprecation/PassRector.php @@ -6,7 +6,7 @@ use DrupalRector\Utility\GetDeclaringSourceTrait; use PhpParser\Node; -use PhpParser\NodeTraverser; +use PhpParser\NodeVisitor; use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -51,7 +51,7 @@ public function refactor(Node $node) } if ($this->getDeclaringSource($node->expr) === 'Drupal\KernelTests\AssertLegacyTrait') { - return NodeTraverser::REMOVE_NODE; + return NodeVisitor::REMOVE_NODE; } return $node; From c00a3fba6b91b8456f2897498c57e751a2264813 Mon Sep 17 00:00:00 2001 From: bjorn Date: Fri, 24 Jan 2025 10:37:14 +0100 Subject: [PATCH 16/41] fix: small type --- src/Drupal10/Rector/Deprecation/AnnotationToAttributeRector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Drupal10/Rector/Deprecation/AnnotationToAttributeRector.php b/src/Drupal10/Rector/Deprecation/AnnotationToAttributeRector.php index 5af227b4..3cbb9b23 100644 --- a/src/Drupal10/Rector/Deprecation/AnnotationToAttributeRector.php +++ b/src/Drupal10/Rector/Deprecation/AnnotationToAttributeRector.php @@ -148,7 +148,7 @@ public function refactor(Node $node): ?Node continue; } - $result = $this->refactorWithConficlearguration($node, $configuration); + $result = $this->refactorWithConfiguration($node, $configuration); // Skip if no result. if ($result === null) { From 48ec445d39b233e5f6d1ebb5c464f6f8622c53bf Mon Sep 17 00:00:00 2001 From: bjorn Date: Fri, 24 Jan 2025 10:41:47 +0100 Subject: [PATCH 17/41] build: fix codestlye --- config/drupal-10/drupal-10.0-deprecations.php | 1 - 1 file changed, 1 deletion(-) diff --git a/config/drupal-10/drupal-10.0-deprecations.php b/config/drupal-10/drupal-10.0-deprecations.php index e296b381..b27b02f2 100644 --- a/config/drupal-10/drupal-10.0-deprecations.php +++ b/config/drupal-10/drupal-10.0-deprecations.php @@ -28,6 +28,5 @@ $twigSet, ]); - $rectorConfig->rule(ShouldCallParentMethodsRector::class); }; From ca9fcbe007752c6a51f4d7e3306c25503bc8abf0 Mon Sep 17 00:00:00 2001 From: bjorn Date: Fri, 24 Jan 2025 10:42:07 +0100 Subject: [PATCH 18/41] fix: fix types for EntityManagerRector.php --- phpstan-baseline.neon | 5 ----- src/Drupal8/Rector/Deprecation/EntityManagerRector.php | 4 ++-- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 266ed64c..378fa1de 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -133,11 +133,6 @@ parameters: count: 1 path: src/Drupal8/Rector/Deprecation/EntityManagerRector.php - - - message: "#^Property PhpParser\\\\Node\\\\Stmt\\\\Expression\\:\\:\\$expr \\(PhpParser\\\\Node\\\\Expr\\) does not accept PhpParser\\\\Node\\|null\\.$#" - count: 1 - path: src/Drupal8/Rector/Deprecation/EntityManagerRector.php - - message: "#^Doing instanceof PHPStan\\\\Type\\\\ObjectType is error\\-prone and deprecated\\. Use Type\\:\\:isObject\\(\\) or Type\\:\\:getObjectClassNames\\(\\) instead\\.$#" count: 1 diff --git a/src/Drupal8/Rector/Deprecation/EntityManagerRector.php b/src/Drupal8/Rector/Deprecation/EntityManagerRector.php index a8739d2e..4bbb78c5 100644 --- a/src/Drupal8/Rector/Deprecation/EntityManagerRector.php +++ b/src/Drupal8/Rector/Deprecation/EntityManagerRector.php @@ -183,9 +183,9 @@ public function findInstanceByNameInAssign(Node\Expr\Assign $assign, string $cla * * @throws ShouldNotHappenException * - * @return Node|null + * @return Node\Expr\Assign */ - public function replaceInstanceByNameInAssign(Node\Expr\Assign $assign, Node $replacement, string $class, string $name): Node + public function replaceInstanceByNameInAssign(Node\Expr\Assign $assign, Node $replacement, string $class, string $name): Node\Expr\Assign { $node = $assign->expr; From 3ad8fc8b7d6b399335f22550dab6606a607a7284 Mon Sep 17 00:00:00 2001 From: bjorn Date: Fri, 24 Jan 2025 10:59:02 +0100 Subject: [PATCH 19/41] fix: fix unit tests with check for consstant --- src/Drupal9/Rector/Deprecation/PassRector.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Drupal9/Rector/Deprecation/PassRector.php b/src/Drupal9/Rector/Deprecation/PassRector.php index 94a3dd12..3138163c 100644 --- a/src/Drupal9/Rector/Deprecation/PassRector.php +++ b/src/Drupal9/Rector/Deprecation/PassRector.php @@ -6,6 +6,7 @@ use DrupalRector\Utility\GetDeclaringSourceTrait; use PhpParser\Node; +use PhpParser\NodeTraverser; use PhpParser\NodeVisitor; use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; @@ -51,7 +52,12 @@ public function refactor(Node $node) } if ($this->getDeclaringSource($node->expr) === 'Drupal\KernelTests\AssertLegacyTrait') { - return NodeVisitor::REMOVE_NODE; + if (defined('\PhpParser\NodeVisitor::REMOVE_NODE')) { + return \PhpParser\NodeVisitor::REMOVE_NODE; + } else { + /** @@phpstan-ignore-next-line */ + return NodeTraverser::REMOVE_NODE; + } } return $node; From 26f94eb80dee4a7490feb6a831ac93b124db7455 Mon Sep 17 00:00:00 2001 From: bjorn Date: Fri, 24 Jan 2025 11:07:58 +0100 Subject: [PATCH 20/41] fix: remove scope aware rector as per upgrade notes --- .../FunctionalTestDefaultThemePropertyRector.php | 13 +++++-------- .../PHPUnit/ShouldCallParentMethodsRector.php | 12 ++++++------ 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/Drupal8/Rector/Deprecation/FunctionalTestDefaultThemePropertyRector.php b/src/Drupal8/Rector/Deprecation/FunctionalTestDefaultThemePropertyRector.php index 3cf939eb..73436b91 100644 --- a/src/Drupal8/Rector/Deprecation/FunctionalTestDefaultThemePropertyRector.php +++ b/src/Drupal8/Rector/Deprecation/FunctionalTestDefaultThemePropertyRector.php @@ -7,21 +7,19 @@ use Drupal\Tests\BrowserTestBase; use PhpParser\Builder\Property; use PhpParser\Node; -use PHPStan\Analyser\Scope; use PHPStan\Type\ObjectType; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory; use Rector\Exception\ShouldNotHappenException; use Rector\PhpParser\Node\Value\ValueResolver; -use Rector\Rector\AbstractScopeAwareRector; +use Rector\PHPStan\ScopeFetcher; +use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * @changelog https://www.drupal.org/node/3083055 - * - * @see \DrupalRector\Tests\Rector\Class_\FunctionalTestDefaultThemePropertyRector\FunctionalTestDefaultThemePropertyRectorTest */ -final class FunctionalTestDefaultThemePropertyRector extends AbstractScopeAwareRector +final class FunctionalTestDefaultThemePropertyRector extends AbstractRector { /** * @var PhpDocInfoFactory @@ -69,9 +67,8 @@ public function getNodeTypes(): array /** * @param Node\Stmt\Class_ $node */ - public function refactorWithScope(Node $node, Scope $scope): ?Node + public function refactor(Node $node): ?Node { - assert($node instanceof Node\Stmt\Class_); if ($node->isAbstract() || $node->isAnonymous()) { return null; } @@ -81,7 +78,6 @@ public function refactorWithScope(Node $node, Scope $scope): ?Node return null; } - assert($type instanceof ObjectType); $browserTestBaseType = new ObjectType(BrowserTestBase::class); if ($type->isSmallerThanOrEqual($browserTestBaseType)->yes()) { return null; @@ -94,6 +90,7 @@ public function refactorWithScope(Node $node, Scope $scope): ?Node throw new ShouldNotHappenException(sprintf('Functional test class %s should have had a defaultTheme property but one not found.', $type->getClassName())); } + $scope = ScopeFetcher::fetch($node); $defaultThemeProperty = $classReflection->getProperty('defaultTheme', $scope); assert($defaultThemeProperty instanceof \PHPStan\Reflection\Php\PhpPropertyReflection); diff --git a/src/Rector/PHPUnit/ShouldCallParentMethodsRector.php b/src/Rector/PHPUnit/ShouldCallParentMethodsRector.php index d142d486..efce07ea 100644 --- a/src/Rector/PHPUnit/ShouldCallParentMethodsRector.php +++ b/src/Rector/PHPUnit/ShouldCallParentMethodsRector.php @@ -5,12 +5,12 @@ namespace DrupalRector\Rector\PHPUnit; use PhpParser\Node; -use PHPStan\Analyser\Scope; -use Rector\Rector\AbstractScopeAwareRector; +use Rector\PHPStan\ScopeFetcher; +use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; -class ShouldCallParentMethodsRector extends AbstractScopeAwareRector +class ShouldCallParentMethodsRector extends AbstractRector { public function getNodeTypes(): array { @@ -22,13 +22,13 @@ public function getNodeTypes(): array /** * @phpstan-param Node\Stmt\ClassMethod $node * - * @param Node $node - * @param Scope $scope + * @param Node $node * * @return Node|null */ - public function refactorWithScope(Node $node, Scope $scope) + public function refactor(Node $node) { + $scope = ScopeFetcher::fetch($node); if ($scope->getClassReflection() === null) { return null; } From 634e415af61f145b48df4a7ee72f7d3e6d38e217 Mon Sep 17 00:00:00 2001 From: bjorn Date: Fri, 24 Jan 2025 11:08:11 +0100 Subject: [PATCH 21/41] build: codestyle passrector --- src/Drupal9/Rector/Deprecation/PassRector.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Drupal9/Rector/Deprecation/PassRector.php b/src/Drupal9/Rector/Deprecation/PassRector.php index 3138163c..e57df781 100644 --- a/src/Drupal9/Rector/Deprecation/PassRector.php +++ b/src/Drupal9/Rector/Deprecation/PassRector.php @@ -53,9 +53,9 @@ public function refactor(Node $node) if ($this->getDeclaringSource($node->expr) === 'Drupal\KernelTests\AssertLegacyTrait') { if (defined('\PhpParser\NodeVisitor::REMOVE_NODE')) { - return \PhpParser\NodeVisitor::REMOVE_NODE; + return NodeVisitor::REMOVE_NODE; } else { - /** @@phpstan-ignore-next-line */ + /* @@phpstan-ignore-next-line */ return NodeTraverser::REMOVE_NODE; } } From a795d2bbccb9c0679da1476308a23d18b0480f93 Mon Sep 17 00:00:00 2001 From: bjorn Date: Fri, 24 Jan 2025 11:08:26 +0100 Subject: [PATCH 22/41] fix: fix return types for AssertFieldByIdRector.php --- src/Drupal9/Rector/Deprecation/AssertFieldByIdRector.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Drupal9/Rector/Deprecation/AssertFieldByIdRector.php b/src/Drupal9/Rector/Deprecation/AssertFieldByIdRector.php index 677f5355..c5132e22 100644 --- a/src/Drupal9/Rector/Deprecation/AssertFieldByIdRector.php +++ b/src/Drupal9/Rector/Deprecation/AssertFieldByIdRector.php @@ -5,6 +5,7 @@ namespace DrupalRector\Drupal9\Rector\Deprecation; use PhpParser\Node; +use PhpParser\Node\Expr\MethodCall; use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -35,13 +36,13 @@ public function getRuleDefinition(): RuleDefinition public function getNodeTypes(): array { return [ - Node\Expr\MethodCall::class, + MethodCall::class, ]; } - public function refactor(Node $node) + public function refactor(Node $node): ?MethodCall { - assert($node instanceof Node\Expr\MethodCall); + assert($node instanceof MethodCall); if ($this->getName($node->name) !== 'assertFieldById') { return null; } From d0cd95733b5656ecda9abf8bf9cc4bd3be4eb192 Mon Sep 17 00:00:00 2001 From: bjorn Date: Fri, 24 Jan 2025 11:09:41 +0100 Subject: [PATCH 23/41] fix: AssertFieldByNameRector.php return type --- src/Drupal9/Rector/Deprecation/AssertFieldByNameRector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Drupal9/Rector/Deprecation/AssertFieldByNameRector.php b/src/Drupal9/Rector/Deprecation/AssertFieldByNameRector.php index 69ca6451..68666dae 100644 --- a/src/Drupal9/Rector/Deprecation/AssertFieldByNameRector.php +++ b/src/Drupal9/Rector/Deprecation/AssertFieldByNameRector.php @@ -37,7 +37,7 @@ public function getNodeTypes(): array ]; } - public function refactor(Node $node) + public function refactor(Node $node): ?Node\Expr\MethodCall { assert($node instanceof Node\Expr\MethodCall); if ($this->getName($node->name) !== 'assertFieldByName') { From 6198c0c0e29ab72bdc770880a687994b6bb8133e Mon Sep 17 00:00:00 2001 From: bjorn Date: Fri, 24 Jan 2025 11:12:44 +0100 Subject: [PATCH 24/41] fix: PassRector.php return type --- src/Drupal9/Rector/Deprecation/PassRector.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Drupal9/Rector/Deprecation/PassRector.php b/src/Drupal9/Rector/Deprecation/PassRector.php index e57df781..a7f0c380 100644 --- a/src/Drupal9/Rector/Deprecation/PassRector.php +++ b/src/Drupal9/Rector/Deprecation/PassRector.php @@ -39,6 +39,11 @@ public function getNodeTypes(): array ]; } + /** + * @param Node $node + * + * @return Node|NodeTraverser::REMOVE_NODE|NodeVisitor::REMOVE_NODE|null + */ public function refactor(Node $node) { assert($node instanceof Node\Stmt\Expression); From cc67b8f0653dff1af5e6109ebf930e1e46f946ab Mon Sep 17 00:00:00 2001 From: bjorn Date: Fri, 24 Jan 2025 11:41:01 +0100 Subject: [PATCH 25/41] fix: isSmallerThanOrEqual now requires phpversion as paramter --- .../FunctionalTestDefaultThemePropertyRector.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Drupal8/Rector/Deprecation/FunctionalTestDefaultThemePropertyRector.php b/src/Drupal8/Rector/Deprecation/FunctionalTestDefaultThemePropertyRector.php index 73436b91..d15fd451 100644 --- a/src/Drupal8/Rector/Deprecation/FunctionalTestDefaultThemePropertyRector.php +++ b/src/Drupal8/Rector/Deprecation/FunctionalTestDefaultThemePropertyRector.php @@ -7,6 +7,8 @@ use Drupal\Tests\BrowserTestBase; use PhpParser\Builder\Property; use PhpParser\Node; +use PHPStan\Php\PhpVersion; +use PHPStan\Php\PhpVersionFactory; use PHPStan\Type\ObjectType; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory; use Rector\Exception\ShouldNotHappenException; @@ -31,10 +33,14 @@ final class FunctionalTestDefaultThemePropertyRector extends AbstractRector */ private ValueResolver $valueResolver; - public function __construct(ValueResolver $valueResolver, PhpDocInfoFactory $phpDocInfoFactory) + private PhpVersionFactory $phpVersionFactory; + + public function __construct(ValueResolver $valueResolver, PhpDocInfoFactory $phpDocInfoFactory, PhpVersionFactory $phpVersionFactory) { $this->phpDocInfoFactory = $phpDocInfoFactory; $this->valueResolver = $valueResolver; + $this->phpVersionFactory = $phpVersionFactory; + } public function getRuleDefinition(): RuleDefinition @@ -79,7 +85,7 @@ public function refactor(Node $node): ?Node } $browserTestBaseType = new ObjectType(BrowserTestBase::class); - if ($type->isSmallerThanOrEqual($browserTestBaseType)->yes()) { + if ($type->isSmallerThanOrEqual($browserTestBaseType, $this->phpVersionFactory->create())->yes()) { return null; } if ($type->isSuperTypeOf(new ObjectType(BrowserTestBase::class))->no()) { From 70eaed8de61cb8a693ec92239ad27ea924d3f7ff Mon Sep 17 00:00:00 2001 From: bjorn Date: Fri, 24 Jan 2025 12:16:52 +0100 Subject: [PATCH 26/41] fix: BC for scopefetcher for phpstan 1 --- .../FunctionalTestDefaultThemePropertyRector.php | 6 +++++- src/Rector/PHPUnit/ShouldCallParentMethodsRector.php | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Drupal8/Rector/Deprecation/FunctionalTestDefaultThemePropertyRector.php b/src/Drupal8/Rector/Deprecation/FunctionalTestDefaultThemePropertyRector.php index d15fd451..059048b9 100644 --- a/src/Drupal8/Rector/Deprecation/FunctionalTestDefaultThemePropertyRector.php +++ b/src/Drupal8/Rector/Deprecation/FunctionalTestDefaultThemePropertyRector.php @@ -96,7 +96,11 @@ public function refactor(Node $node): ?Node throw new ShouldNotHappenException(sprintf('Functional test class %s should have had a defaultTheme property but one not found.', $type->getClassName())); } - $scope = ScopeFetcher::fetch($node); + if (class_exists('Rector\PHPStan\ScopeFetcher')) { + $scope = ScopeFetcher::fetch($node); + } else { + $scope = $node->getAttribute('scope'); + } $defaultThemeProperty = $classReflection->getProperty('defaultTheme', $scope); assert($defaultThemeProperty instanceof \PHPStan\Reflection\Php\PhpPropertyReflection); diff --git a/src/Rector/PHPUnit/ShouldCallParentMethodsRector.php b/src/Rector/PHPUnit/ShouldCallParentMethodsRector.php index efce07ea..e133f6a3 100644 --- a/src/Rector/PHPUnit/ShouldCallParentMethodsRector.php +++ b/src/Rector/PHPUnit/ShouldCallParentMethodsRector.php @@ -28,7 +28,11 @@ public function getNodeTypes(): array */ public function refactor(Node $node) { - $scope = ScopeFetcher::fetch($node); + if (class_exists('Rector\PHPStan\ScopeFetcher')) { + $scope = ScopeFetcher::fetch($node); + } else { + $scope = $node->getAttribute('scope'); + } if ($scope->getClassReflection() === null) { return null; } From 988ba9c969d2349b04118f02664ed02ed6206a9c Mon Sep 17 00:00:00 2001 From: bjorn Date: Fri, 24 Jan 2025 12:17:27 +0100 Subject: [PATCH 27/41] buid: add phpunit tests on phpstan 1 and 2 --- .github/workflows/phpunit.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index 5af6600d..e03cf8f8 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -16,8 +16,10 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-version: - - "8.2" + - php-version: "8.2" + phpstan: "^1" + - php-version: "8.2" + phpstan: "^2" steps: - uses: actions/checkout@v3 - uses: shivammathur/setup-php@v2 @@ -26,4 +28,5 @@ jobs: coverage: none tools: composer:v2 - run: composer install + - run: composer require phpstan/phpstan:${{ matrix.phpstan }} - run: composer test From f34bc0d8efb77044030967b84b9c2414e3bad5d3 Mon Sep 17 00:00:00 2001 From: bjorn Date: Fri, 24 Jan 2025 12:17:39 +0100 Subject: [PATCH 28/41] build: allow phpstan 1 and 2 --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index e8e66570..5c1eef25 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ "ast" ], "require": { - "rector/rector": "^2.0", + "rector/rector": "^1 | ^2", "webflo/drupal-finder": "^1.2" }, "license": "MIT", @@ -77,8 +77,8 @@ "cweagans/composer-patches": "^1.7.2", "friendsofphp/php-cs-fixer": "^3.58", "phpstan/extension-installer": "^1.4.3", - "phpstan/phpstan": "^2.0.1", - "phpstan/phpstan-deprecation-rules": "^2.0", + "phpstan/phpstan": "^1.12 || ^2.0", + "phpstan/phpstan-deprecation-rules": "^1.2 || ^2.0", "phpunit/phpunit": "^10.0", "symfony/yaml": "^5 || ^6 || ^7", "symplify/vendor-patches": "^11.0" From 1c3fc2d3756df4e82ca884cbcd929780ecb3cd13 Mon Sep 17 00:00:00 2001 From: bjorn Date: Fri, 24 Jan 2025 12:19:36 +0100 Subject: [PATCH 29/41] build: fix codestyle --- .../Deprecation/FunctionalTestDefaultThemePropertyRector.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Drupal8/Rector/Deprecation/FunctionalTestDefaultThemePropertyRector.php b/src/Drupal8/Rector/Deprecation/FunctionalTestDefaultThemePropertyRector.php index 059048b9..c69086f2 100644 --- a/src/Drupal8/Rector/Deprecation/FunctionalTestDefaultThemePropertyRector.php +++ b/src/Drupal8/Rector/Deprecation/FunctionalTestDefaultThemePropertyRector.php @@ -7,7 +7,6 @@ use Drupal\Tests\BrowserTestBase; use PhpParser\Builder\Property; use PhpParser\Node; -use PHPStan\Php\PhpVersion; use PHPStan\Php\PhpVersionFactory; use PHPStan\Type\ObjectType; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory; @@ -40,7 +39,6 @@ public function __construct(ValueResolver $valueResolver, PhpDocInfoFactory $php $this->phpDocInfoFactory = $phpDocInfoFactory; $this->valueResolver = $valueResolver; $this->phpVersionFactory = $phpVersionFactory; - } public function getRuleDefinition(): RuleDefinition From 26d0d754e4dc1fce57726b341ea4e587ef631b6c Mon Sep 17 00:00:00 2001 From: bjorn Date: Fri, 24 Jan 2025 12:21:45 +0100 Subject: [PATCH 30/41] build: fix unit tests workflow --- .github/workflows/phpunit.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index e03cf8f8..21d9e7b9 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -16,10 +16,11 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - - php-version: "8.2" - phpstan: "^1" - - php-version: "8.2" - phpstan: "^2" + include: + - php-version: "8.2" + phpstan: "^1" + - php-version: "8.2" + phpstan: "^2" steps: - uses: actions/checkout@v3 - uses: shivammathur/setup-php@v2 From 88704112abcd9e2061bffb9af5d873e002723e14 Mon Sep 17 00:00:00 2001 From: bjorn Date: Fri, 24 Jan 2025 12:22:16 +0100 Subject: [PATCH 31/41] build: fix unit tests workflow name --- .github/workflows/phpunit.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index 21d9e7b9..1a174866 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -12,7 +12,7 @@ on: jobs: tests: - name: 'PHPUnit | PHP ${{ matrix.php-version }}' + name: 'PHPUnit | PHP ${{ matrix.phpstan }}' runs-on: ubuntu-latest strategy: matrix: From af3ff27ed5e202c73c16df3fb43da09f11330e99 Mon Sep 17 00:00:00 2001 From: bjorn Date: Fri, 24 Jan 2025 12:24:18 +0100 Subject: [PATCH 32/41] build: fix unit tests workflow require --- .github/workflows/phpunit.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index 1a174866..77c461b2 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -28,6 +28,5 @@ jobs: php-version: ${{ matrix.php-version }} coverage: none tools: composer:v2 - - run: composer install - - run: composer require phpstan/phpstan:${{ matrix.phpstan }} + - run: composer require phpstan/phpstan:${{ matrix.phpstan }} --dev - run: composer test From 4f4760ca576bd27aabb78a093f377fafd1525ac5 Mon Sep 17 00:00:00 2001 From: bjorn Date: Fri, 24 Jan 2025 12:25:45 +0100 Subject: [PATCH 33/41] build: fix phpunit naming, do rector not phpstan. --- .github/workflows/phpunit.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index 77c461b2..0678b2f8 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -12,15 +12,15 @@ on: jobs: tests: - name: 'PHPUnit | PHP ${{ matrix.phpstan }}' + name: 'PHPUnit | rector/rector:${{ matrix.rector }}' runs-on: ubuntu-latest strategy: matrix: include: - php-version: "8.2" - phpstan: "^1" + rector: "^1" - php-version: "8.2" - phpstan: "^2" + rector: "^2" steps: - uses: actions/checkout@v3 - uses: shivammathur/setup-php@v2 @@ -28,5 +28,5 @@ jobs: php-version: ${{ matrix.php-version }} coverage: none tools: composer:v2 - - run: composer require phpstan/phpstan:${{ matrix.phpstan }} --dev + - run: composer require rector/rector:${{ matrix.rector }} --dev - run: composer test From a4dc6d754543e4e587c2aa13b403957c174b6a32 Mon Sep 17 00:00:00 2001 From: bjorn Date: Fri, 24 Jan 2025 13:20:32 +0100 Subject: [PATCH 34/41] build: fix a few phpstan erros --- .../FunctionalTestDefaultThemePropertyRector.php | 10 ++++++++-- .../Rector/Deprecation/AssertNoFieldByIdRector.php | 3 +++ .../Rector/Deprecation/AssertNoUniqueTextRector.php | 3 +++ .../Deprecation/UiHelperTraitDrupalPostFormRector.php | 3 +++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Drupal8/Rector/Deprecation/FunctionalTestDefaultThemePropertyRector.php b/src/Drupal8/Rector/Deprecation/FunctionalTestDefaultThemePropertyRector.php index c69086f2..2168b796 100644 --- a/src/Drupal8/Rector/Deprecation/FunctionalTestDefaultThemePropertyRector.php +++ b/src/Drupal8/Rector/Deprecation/FunctionalTestDefaultThemePropertyRector.php @@ -89,9 +89,15 @@ public function refactor(Node $node): ?Node if ($type->isSuperTypeOf(new ObjectType(BrowserTestBase::class))->no()) { return null; } - $classReflection = $type->getClassReflection(); + + $classReflections = $type->getObjectClassReflections(); + $classReflection = null; + if (count($classReflections) !== 0) { + $classReflection = $classReflections[0]; + } + if ($classReflection === null || !$classReflection->hasNativeProperty('defaultTheme')) { - throw new ShouldNotHappenException(sprintf('Functional test class %s should have had a defaultTheme property but one not found.', $type->getClassName())); + throw new ShouldNotHappenException(sprintf('Functional test class %s should have had a defaultTheme property but one not found.', $this->getName($node))); } if (class_exists('Rector\PHPStan\ScopeFetcher')) { diff --git a/src/Drupal9/Rector/Deprecation/AssertNoFieldByIdRector.php b/src/Drupal9/Rector/Deprecation/AssertNoFieldByIdRector.php index 202a8b27..7d4d313a 100644 --- a/src/Drupal9/Rector/Deprecation/AssertNoFieldByIdRector.php +++ b/src/Drupal9/Rector/Deprecation/AssertNoFieldByIdRector.php @@ -37,6 +37,9 @@ public function getNodeTypes(): array ]; } + /** + * @return Node|null + */ public function refactor(Node $node) { assert($node instanceof Node\Expr\MethodCall); diff --git a/src/Drupal9/Rector/Deprecation/AssertNoUniqueTextRector.php b/src/Drupal9/Rector/Deprecation/AssertNoUniqueTextRector.php index caabeefa..588b1785 100644 --- a/src/Drupal9/Rector/Deprecation/AssertNoUniqueTextRector.php +++ b/src/Drupal9/Rector/Deprecation/AssertNoUniqueTextRector.php @@ -39,6 +39,9 @@ public function getNodeTypes(): array ]; } + /** + * @return Node[]|null + */ public function refactor(Node $node) { assert($node instanceof Node\Stmt\Expression); diff --git a/src/Drupal9/Rector/Deprecation/UiHelperTraitDrupalPostFormRector.php b/src/Drupal9/Rector/Deprecation/UiHelperTraitDrupalPostFormRector.php index 9a3462ee..a531bcfa 100644 --- a/src/Drupal9/Rector/Deprecation/UiHelperTraitDrupalPostFormRector.php +++ b/src/Drupal9/Rector/Deprecation/UiHelperTraitDrupalPostFormRector.php @@ -72,6 +72,9 @@ private function safeArgDestructure(Node\Expr\MethodCall $node): array throw new ShouldNotHappenException('Unexpected argument count for drupalPostForm'); } + /** + * @return Node[]|null + */ public function refactor(Node $node) { assert($node instanceof Node\Stmt\Expression); From 14c08ebd91be2a1d6b9eed59f63f4bc3ad951ecd Mon Sep 17 00:00:00 2001 From: bjorn Date: Fri, 24 Jan 2025 13:20:41 +0100 Subject: [PATCH 35/41] build: remove error from baseline --- phpstan-baseline.neon | 5 ----- 1 file changed, 5 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 378fa1de..b1fd7c50 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -133,11 +133,6 @@ parameters: count: 1 path: src/Drupal8/Rector/Deprecation/EntityManagerRector.php - - - message: "#^Doing instanceof PHPStan\\\\Type\\\\ObjectType is error\\-prone and deprecated\\. Use Type\\:\\:isObject\\(\\) or Type\\:\\:getObjectClassNames\\(\\) instead\\.$#" - count: 1 - path: src/Drupal8/Rector/Deprecation/FunctionalTestDefaultThemePropertyRector.php - - message: "#^Call to an undefined method PHPStan\\\\Type\\\\Type\\:\\:getValue\\(\\)\\.$#" count: 1 From 23dd177250af137ebff7782fd9b93ec9728e5aea Mon Sep 17 00:00:00 2001 From: bjorn Date: Fri, 24 Jan 2025 13:20:55 +0100 Subject: [PATCH 36/41] build: composer.json update formatting for rector requirement --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 5c1eef25..996ac159 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ "ast" ], "require": { - "rector/rector": "^1 | ^2", + "rector/rector": "^1 || ^2", "webflo/drupal-finder": "^1.2" }, "license": "MIT", From e965770f4429cbb7e54a1f4c8f23ff561942ce26 Mon Sep 17 00:00:00 2001 From: bjorn Date: Fri, 24 Jan 2025 13:22:04 +0100 Subject: [PATCH 37/41] build: fix codestyle for PassRector.php --- src/Drupal9/Rector/Deprecation/PassRector.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Drupal9/Rector/Deprecation/PassRector.php b/src/Drupal9/Rector/Deprecation/PassRector.php index 3138163c..e57df781 100644 --- a/src/Drupal9/Rector/Deprecation/PassRector.php +++ b/src/Drupal9/Rector/Deprecation/PassRector.php @@ -53,9 +53,9 @@ public function refactor(Node $node) if ($this->getDeclaringSource($node->expr) === 'Drupal\KernelTests\AssertLegacyTrait') { if (defined('\PhpParser\NodeVisitor::REMOVE_NODE')) { - return \PhpParser\NodeVisitor::REMOVE_NODE; + return NodeVisitor::REMOVE_NODE; } else { - /** @@phpstan-ignore-next-line */ + /* @@phpstan-ignore-next-line */ return NodeTraverser::REMOVE_NODE; } } From f66b2760c75a1b2175af0cdf4d76d4836b022369 Mon Sep 17 00:00:00 2001 From: bjorn Date: Fri, 24 Jan 2025 13:23:46 +0100 Subject: [PATCH 38/41] build: typo in phpstan ignore --- src/Drupal9/Rector/Deprecation/PassRector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Drupal9/Rector/Deprecation/PassRector.php b/src/Drupal9/Rector/Deprecation/PassRector.php index e57df781..8e48d29a 100644 --- a/src/Drupal9/Rector/Deprecation/PassRector.php +++ b/src/Drupal9/Rector/Deprecation/PassRector.php @@ -55,7 +55,7 @@ public function refactor(Node $node) if (defined('\PhpParser\NodeVisitor::REMOVE_NODE')) { return NodeVisitor::REMOVE_NODE; } else { - /* @@phpstan-ignore-next-line */ + /* @phpstan-ignore-next-line */ return NodeTraverser::REMOVE_NODE; } } From d5cf117d2f1cc90357980dccdec9aca86a29d150 Mon Sep 17 00:00:00 2001 From: bjorn Date: Fri, 24 Jan 2025 13:26:24 +0100 Subject: [PATCH 39/41] build: update baseline to add the BC promise stuff --- phpstan-baseline.neon | 182 ++++++++++++++++++++++++++++++++---------- 1 file changed, 142 insertions(+), 40 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index b1fd7c50..74b1ed9c 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,139 +1,241 @@ parameters: ignoreErrors: - - message: """ - #^Call to deprecated method locateRoot\\(\\) of class DrupalFinder\\\\DrupalFinder\\: - Will be removed in v2\\. Future usage should instantiate + message: '#^Access to undefined constant Rector\\Symfony\\Set\\TwigSetList\:\:TWIG_240\.$#' + identifier: classConstant.notFound + count: 1 + path: config/drupal-10/drupal-10.0-deprecations.php + + - + message: '#^Access to undefined constant Rector\\Symfony\\Set\\TwigSetList\:\:TWIG_240\.$#' + identifier: classConstant.notFound + count: 1 + path: config/drupal-9/drupal-9.0-deprecations.php + + - + message: ''' + #^Call to deprecated method locateRoot\(\) of class DrupalFinder\\DrupalFinder\: + Will be removed in v2\. Future usage should instantiate a new DrupalFinder object by passing the starting path to its - constructor\\.$# - """ + constructor\.$# + ''' + identifier: method.deprecated count: 1 path: config/drupal-phpunit-bootstrap-file.php - - message: "#^Function drupal_phpunit_contrib_extension_directory_roots\\(\\) return type has no value type specified in iterable type array\\.$#" + message: '#^Function drupal_phpunit_contrib_extension_directory_roots\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue count: 1 path: config/drupal-phpunit-bootstrap-file.php - - message: "#^Function drupal_phpunit_find_extension_directories\\(\\) return type has no value type specified in iterable type array\\.$#" + message: '#^Function drupal_phpunit_find_extension_directories\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue count: 1 path: config/drupal-phpunit-bootstrap-file.php - - message: "#^Function drupal_phpunit_get_extension_namespaces\\(\\) has parameter \\$dirs with no value type specified in iterable type array\\.$#" + message: '#^Function drupal_phpunit_get_extension_namespaces\(\) has parameter \$dirs with no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue count: 1 path: config/drupal-phpunit-bootstrap-file.php - - message: "#^Function drupal_phpunit_get_extension_namespaces\\(\\) return type has no value type specified in iterable type array\\.$#" + message: '#^Function drupal_phpunit_get_extension_namespaces\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue count: 1 path: config/drupal-phpunit-bootstrap-file.php - - message: "#^Function drupal_phpunit_populate_class_loader\\(\\) has no return type specified\\.$#" + message: '#^Function drupal_phpunit_populate_class_loader\(\) has no return type specified\.$#' + identifier: missingType.return count: 1 path: config/drupal-phpunit-bootstrap-file.php - - message: "#^Function drupal_phpunit_populate_class_loader\\(\\) has parameter \\$drupalRoot with no type specified\\.$#" + message: '#^Function drupal_phpunit_populate_class_loader\(\) has parameter \$drupalRoot with no type specified\.$#' + identifier: missingType.parameter count: 1 path: config/drupal-phpunit-bootstrap-file.php - - message: "#^Function drupal_phpunit_populate_class_loader\\(\\) has parameter \\$vendorRoot with no type specified\\.$#" + message: '#^Function drupal_phpunit_populate_class_loader\(\) has parameter \$vendorRoot with no type specified\.$#' + identifier: missingType.parameter count: 1 path: config/drupal-phpunit-bootstrap-file.php - - message: """ - #^Instantiation of deprecated class DrupalFinder\\\\DrupalFinder\\: - in drupal\\-finder\\:1\\.3\\.0 and is removed from drupal\\-finder\\:2\\.0\\.0\\. - Use \\\\DrupalFinder\\\\DrupalFinderComposerRuntime instead\\.$# - """ + message: ''' + #^Instantiation of deprecated class DrupalFinder\\DrupalFinder\: + in drupal\-finder\:1\.3\.0 and is removed from drupal\-finder\:2\.0\.0\. + Use \\DrupalFinder\\DrupalFinderComposerRuntime instead\.$# + ''' + identifier: new.deprecated count: 1 path: config/drupal-phpunit-bootstrap-file.php - - message: """ - #^Call to deprecated method locateRoot\\(\\) of class DrupalFinder\\\\DrupalFinder\\: - Will be removed in v2\\. Future usage should instantiate + message: ''' + #^Call to deprecated method locateRoot\(\) of class DrupalFinder\\DrupalFinder\: + Will be removed in v2\. Future usage should instantiate a new DrupalFinder object by passing the starting path to its - constructor\\.$# - """ + constructor\.$# + ''' + identifier: method.deprecated count: 1 path: rector.php - - message: """ - #^Instantiation of deprecated class DrupalFinder\\\\DrupalFinder\\: - in drupal\\-finder\\:1\\.3\\.0 and is removed from drupal\\-finder\\:2\\.0\\.0\\. - Use \\\\DrupalFinder\\\\DrupalFinderComposerRuntime instead\\.$# - """ + message: ''' + #^Instantiation of deprecated class DrupalFinder\\DrupalFinder\: + in drupal\-finder\:1\.3\.0 and is removed from drupal\-finder\:2\.0\.0\. + Use \\DrupalFinder\\DrupalFinderComposerRuntime instead\.$# + ''' + identifier: new.deprecated count: 1 path: rector.php - - message: "#^Access to an undefined property PhpParser\\\\Node\\\\Expr\\:\\:\\$value\\.$#" + message: '#^Access to an undefined property PhpParser\\Node\\Expr\:\:\$value\.$#' + identifier: property.notFound count: 2 path: src/Drupal8/Rector/Deprecation/DBRector.php - - message: "#^Call to an undefined method PHPStan\\\\Type\\\\Type\\:\\:getValue\\(\\)\\.$#" + message: '#^Call to an undefined method PHPStan\\Type\\Type\:\:getValue\(\)\.$#' + identifier: method.notFound count: 1 path: src/Drupal8/Rector/Deprecation/DrupalSetMessageRector.php - - message: "#^Access to an undefined property PhpParser\\\\Node\\\\Expr\\:\\:\\$expr\\.$#" + message: '#^Access to an undefined property PhpParser\\Node\\Expr\:\:\$expr\.$#' + identifier: property.notFound count: 1 path: src/Drupal8/Rector/Deprecation/EntityLoadRector.php - - message: "#^Access to an undefined property PhpParser\\\\Node\\\\Expr\\:\\:\\$expr\\.$#" + message: '#^Access to an undefined property PhpParser\\Node\\Expr\:\:\$expr\.$#' + identifier: property.notFound count: 2 path: src/Drupal8/Rector/Deprecation/EntityManagerRector.php - - message: "#^Access to an undefined property PhpParser\\\\Node\\\\Expr\\:\\:\\$name\\.$#" + message: '#^Access to an undefined property PhpParser\\Node\\Expr\:\:\$name\.$#' + identifier: property.notFound count: 3 path: src/Drupal8/Rector/Deprecation/EntityManagerRector.php - - message: "#^Method DrupalRector\\\\Drupal8\\\\Rector\\\\Deprecation\\\\EntityManagerRector\\:\\:getServiceByMethodName\\(\\) has no return type specified\\.$#" + message: '#^Method DrupalRector\\Drupal8\\Rector\\Deprecation\\EntityManagerRector\:\:getServiceByMethodName\(\) has no return type specified\.$#' + identifier: missingType.return count: 1 path: src/Drupal8/Rector/Deprecation/EntityManagerRector.php - - message: "#^PHPDoc tag @param references unknown parameter\\: \\$node$#" + message: '#^PHPDoc tag @param references unknown parameter\: \$node$#' + identifier: parameter.notFound count: 1 path: src/Drupal8/Rector/Deprecation/EntityManagerRector.php - - message: "#^Parameter \\#1 \\$assign of method DrupalRector\\\\Drupal8\\\\Rector\\\\Deprecation\\\\EntityManagerRector\\:\\:findInstanceByNameInAssign\\(\\) expects PhpParser\\\\Node\\\\Expr\\\\Assign, PhpParser\\\\Node\\\\Expr given\\.$#" + message: '#^Parameter \#1 \$assign of method DrupalRector\\Drupal8\\Rector\\Deprecation\\EntityManagerRector\:\:findInstanceByNameInAssign\(\) expects PhpParser\\Node\\Expr\\Assign, PhpParser\\Node\\Expr given\.$#' + identifier: argument.type count: 1 path: src/Drupal8/Rector/Deprecation/EntityManagerRector.php - - message: "#^Parameter \\#1 \\$assign of method DrupalRector\\\\Drupal8\\\\Rector\\\\Deprecation\\\\EntityManagerRector\\:\\:replaceInstanceByNameInAssign\\(\\) expects PhpParser\\\\Node\\\\Expr\\\\Assign, PhpParser\\\\Node\\\\Expr given\\.$#" + message: '#^Parameter \#1 \$assign of method DrupalRector\\Drupal8\\Rector\\Deprecation\\EntityManagerRector\:\:replaceInstanceByNameInAssign\(\) expects PhpParser\\Node\\Expr\\Assign, PhpParser\\Node\\Expr given\.$#' + identifier: argument.type count: 1 path: src/Drupal8/Rector/Deprecation/EntityManagerRector.php - - message: "#^Parameter \\#1 \\$expr of method DrupalRector\\\\Drupal8\\\\Rector\\\\Deprecation\\\\EntityManagerRector\\:\\:refactorExpression\\(\\) expects PhpParser\\\\Node\\\\Expr\\\\MethodCall\\|PhpParser\\\\Node\\\\Expr\\\\StaticCall, PhpParser\\\\Node given\\.$#" + message: '#^Parameter \#1 \$expr of method DrupalRector\\Drupal8\\Rector\\Deprecation\\EntityManagerRector\:\:refactorExpression\(\) expects PhpParser\\Node\\Expr\\MethodCall\|PhpParser\\Node\\Expr\\StaticCall, PhpParser\\Node given\.$#' + identifier: argument.type count: 1 path: src/Drupal8/Rector/Deprecation/EntityManagerRector.php - - message: "#^Parameter \\#1 \\$expr of method DrupalRector\\\\Drupal8\\\\Rector\\\\Deprecation\\\\EntityManagerRector\\:\\:refactorExpression\\(\\) expects PhpParser\\\\Node\\\\Expr\\\\MethodCall\\|PhpParser\\\\Node\\\\Expr\\\\StaticCall, PhpParser\\\\Node\\\\Expr given\\.$#" + message: '#^Parameter \#1 \$expr of method DrupalRector\\Drupal8\\Rector\\Deprecation\\EntityManagerRector\:\:refactorExpression\(\) expects PhpParser\\Node\\Expr\\MethodCall\|PhpParser\\Node\\Expr\\StaticCall, PhpParser\\Node\\Expr given\.$#' + identifier: argument.type count: 1 path: src/Drupal8/Rector/Deprecation/EntityManagerRector.php - - message: "#^Property PhpParser\\\\Node\\\\Expr\\\\Assign\\:\\:\\$expr \\(PhpParser\\\\Node\\\\Expr\\) does not accept PhpParser\\\\Node\\.$#" + message: '#^Property PhpParser\\Node\\Expr\\Assign\:\:\$expr \(PhpParser\\Node\\Expr\) does not accept PhpParser\\Node\.$#' + identifier: assign.propertyType count: 1 path: src/Drupal8/Rector/Deprecation/EntityManagerRector.php - - message: "#^Call to an undefined method PHPStan\\\\Type\\\\Type\\:\\:getValue\\(\\)\\.$#" + message: '#^Although PHPStan\\Reflection\\Php\\PhpPropertyReflection is covered by backward compatibility promise, this instanceof assumption might break because it''s not guaranteed to always stay the same\.$#' + identifier: phpstanApi.instanceofAssumption + count: 1 + path: src/Drupal8/Rector/Deprecation/FunctionalTestDefaultThemePropertyRector.php + + - + message: '#^Calling PHPStan\\Php\\PhpVersionFactory\:\:create\(\) is not covered by backward compatibility promise\. The method might change in a minor PHPStan version\.$#' + identifier: phpstanApi.method + count: 1 + path: src/Drupal8/Rector/Deprecation/FunctionalTestDefaultThemePropertyRector.php + + - + message: '#^Although PHPStan\\Reflection\\Php\\PhpMethodReflection is covered by backward compatibility promise, this instanceof assumption might break because it''s not guaranteed to always stay the same\.$#' + identifier: phpstanApi.instanceofAssumption + count: 1 + path: src/Drupal9/Rector/Deprecation/AssertLegacyTraitRector.php + + - + message: '#^Although PHPStan\\Reflection\\Php\\PhpMethodReflection is covered by backward compatibility promise, this instanceof assumption might break because it''s not guaranteed to always stay the same\.$#' + identifier: phpstanApi.instanceofAssumption + count: 1 + path: src/Drupal9/Rector/Deprecation/AssertNoFieldByNameRector.php + + - + message: '#^Although PHPStan\\Reflection\\Php\\PhpMethodReflection is covered by backward compatibility promise, this instanceof assumption might break because it''s not guaranteed to always stay the same\.$#' + identifier: phpstanApi.instanceofAssumption + count: 1 + path: src/Drupal9/Rector/Deprecation/AssertNoUniqueTextRector.php + + - + message: '#^Although PHPStan\\Reflection\\Php\\PhpMethodReflection is covered by backward compatibility promise, this instanceof assumption might break because it''s not guaranteed to always stay the same\.$#' + identifier: phpstanApi.instanceofAssumption + count: 1 + path: src/Drupal9/Rector/Deprecation/ConstructFieldXpathRector.php + + - + message: '#^Call to an undefined method PHPStan\\Type\\Type\:\:getValue\(\)\.$#' + identifier: method.notFound count: 1 path: src/Drupal9/Rector/Deprecation/ExtensionPathRector.php + + - + message: '#^Although PHPStan\\Reflection\\Php\\PhpMethodReflection is covered by backward compatibility promise, this instanceof assumption might break because it''s not guaranteed to always stay the same\.$#' + identifier: phpstanApi.instanceofAssumption + count: 1 + path: src/Drupal9/Rector/Deprecation/FromUriRector.php + + - + message: '#^Although PHPStan\\Reflection\\Php\\PhpMethodReflection is covered by backward compatibility promise, this instanceof assumption might break because it''s not guaranteed to always stay the same\.$#' + identifier: phpstanApi.instanceofAssumption + count: 1 + path: src/Drupal9/Rector/Deprecation/GetAllOptionsRector.php + + - + message: '#^Although PHPStan\\Reflection\\Php\\PhpMethodReflection is covered by backward compatibility promise, this instanceof assumption might break because it''s not guaranteed to always stay the same\.$#' + identifier: phpstanApi.instanceofAssumption + count: 1 + path: src/Drupal9/Rector/Deprecation/GetRawContentRector.php + + - + message: '#^Although PHPStan\\Reflection\\Php\\PhpMethodReflection is covered by backward compatibility promise, this instanceof assumption might break because it''s not guaranteed to always stay the same\.$#' + identifier: phpstanApi.instanceofAssumption + count: 1 + path: src/Drupal9/Rector/Deprecation/PassRector.php + + - + message: '#^Parameter \#3 \$args of method Rector\\PhpParser\\Node\\NodeFactory\:\:createStaticCall\(\) expects array\, array\ given\.$#' + identifier: argument.type + count: 1 + path: src/Rector/AbstractDrupalCoreRector.php From afcbdb08e6cc2a589a112722a34c6c17a9b757b8 Mon Sep 17 00:00:00 2001 From: bjorn Date: Fri, 31 Jan 2025 16:08:39 +0100 Subject: [PATCH 40/41] fix: enhance AnnotationToAttributeRector to handle Doctrine annotations because of changes in phpparser --- .../AnnotationToAttributeRector.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Drupal10/Rector/Deprecation/AnnotationToAttributeRector.php b/src/Drupal10/Rector/Deprecation/AnnotationToAttributeRector.php index 3cbb9b23..7497fd53 100644 --- a/src/Drupal10/Rector/Deprecation/AnnotationToAttributeRector.php +++ b/src/Drupal10/Rector/Deprecation/AnnotationToAttributeRector.php @@ -189,17 +189,22 @@ protected function refactorWithConfiguration(Node $node, VersionedConfigurationI $docBlockHasChanged = \false; foreach ($tagsByName as $valueNode) { - if (!$valueNode->value instanceof GenericTagValueNode) { + if (!$valueNode->value instanceof GenericTagValueNode && !$valueNode->value instanceof DoctrineAnnotationTagValueNode) { continue; } if ($hasAttribute === false) { - $stringValue = $valueNode->value->value; - $stringValue = '{'.trim($stringValue, '()').'}'; - $tokenIterator = $this->tokenIteratorFactory->create($stringValue); - $data = $this->arrayParser->parseCurlyArray($tokenIterator, $node); - $attribute = $this->createAttribute($configuration->getAttributeClass(), $data); - $node->attrGroups[] = new AttributeGroup([$attribute]); + if ($valueNode->value instanceof GenericTagValueNode) { + $stringValue = $valueNode->value->value; + $stringValue = '{'.trim($stringValue, '()').'}'; + $tokenIterator = $this->tokenIteratorFactory->create($stringValue); + $data = $this->arrayParser->parseCurlyArray($tokenIterator, $node); + $attribute = $this->createAttribute($configuration->getAttributeClass(), $data); + $node->attrGroups[] = new AttributeGroup([$attribute]); + } elseif ($valueNode->value instanceof DoctrineAnnotationTagValueNode) { + $attribute = $this->createAttribute($configuration->getAttributeClass(), $valueNode->value->values); + $node->attrGroups[] = new AttributeGroup([$attribute]); + } } if (version_compare($this->installedDrupalVersion(), $configuration->getRemoveVersion(), '>=')) { From 024b06d0b70cefd0f6b1750561d7d20083a167e5 Mon Sep 17 00:00:00 2001 From: bjorn Date: Fri, 31 Jan 2025 16:20:30 +0100 Subject: [PATCH 41/41] build: add phpstan 1 check also for if we are gonna support both versions --- .github/workflows/phpstan.yml | 13 ++- phpstan-1-baseline.neon | 159 ++++++++++++++++++++++++++++++++++ phpstan-1.neon | 12 +++ 3 files changed, 182 insertions(+), 2 deletions(-) create mode 100644 phpstan-1-baseline.neon create mode 100644 phpstan-1.neon diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index af3574ca..537e5b5c 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -15,6 +15,15 @@ jobs: name: Static analysis with PHPStan # START: SHARED SETUP runs-on: ubuntu-latest + strategy: + matrix: + include: + - php-version: "8.2" + rector: "^1" + phpstan-config: phpstan-1.neon + - php-version: "8.2" + rector: "^2" + phpstan-config: phpstan.neon steps: - uses: actions/checkout@v3 - uses: shivammathur/setup-php@v2 @@ -28,5 +37,5 @@ jobs: # uses: mxschmitt/action-tmate@v2 # END: SHARED SETUP - - run: composer install - - run: composer phpstan + - run: composer require rector/rector:${{ matrix.rector }} --dev + - run: vendor/bin/phpstan analyse -c ${{ matrix.phpstan-config }} diff --git a/phpstan-1-baseline.neon b/phpstan-1-baseline.neon new file mode 100644 index 00000000..b9ccb198 --- /dev/null +++ b/phpstan-1-baseline.neon @@ -0,0 +1,159 @@ +parameters: + ignoreErrors: + - + message: "#^Access to undefined constant Rector\\\\Symfony\\\\Set\\\\TwigSetList\\:\\:TWIG_24\\.$#" + count: 1 + path: config/drupal-10/drupal-10.0-deprecations.php + + - + message: "#^Access to undefined constant Rector\\\\Symfony\\\\Set\\\\TwigSetList\\:\\:TWIG_24\\.$#" + count: 1 + path: config/drupal-9/drupal-9.0-deprecations.php + + - + message: """ + #^Call to deprecated method locateRoot\\(\\) of class DrupalFinder\\\\DrupalFinder\\: + Will be removed in v2\\. Future usage should instantiate + a new DrupalFinder object by passing the starting path to its + constructor\\.$# + """ + count: 1 + path: config/drupal-phpunit-bootstrap-file.php + + - + message: "#^Function drupal_phpunit_contrib_extension_directory_roots\\(\\) return type has no value type specified in iterable type array\\.$#" + count: 1 + path: config/drupal-phpunit-bootstrap-file.php + + - + message: "#^Function drupal_phpunit_find_extension_directories\\(\\) return type has no value type specified in iterable type array\\.$#" + count: 1 + path: config/drupal-phpunit-bootstrap-file.php + + - + message: "#^Function drupal_phpunit_get_extension_namespaces\\(\\) has parameter \\$dirs with no value type specified in iterable type array\\.$#" + count: 1 + path: config/drupal-phpunit-bootstrap-file.php + + - + message: "#^Function drupal_phpunit_get_extension_namespaces\\(\\) return type has no value type specified in iterable type array\\.$#" + count: 1 + path: config/drupal-phpunit-bootstrap-file.php + + - + message: "#^Function drupal_phpunit_populate_class_loader\\(\\) has no return type specified\\.$#" + count: 1 + path: config/drupal-phpunit-bootstrap-file.php + + - + message: "#^Function drupal_phpunit_populate_class_loader\\(\\) has parameter \\$drupalRoot with no type specified\\.$#" + count: 1 + path: config/drupal-phpunit-bootstrap-file.php + + - + message: "#^Function drupal_phpunit_populate_class_loader\\(\\) has parameter \\$vendorRoot with no type specified\\.$#" + count: 1 + path: config/drupal-phpunit-bootstrap-file.php + + - + message: """ + #^Instantiation of deprecated class DrupalFinder\\\\DrupalFinder\\: + in drupal\\-finder\\:1\\.3\\.0 and is removed from drupal\\-finder\\:2\\.0\\.0\\. + Use \\\\DrupalFinder\\\\DrupalFinderComposerRuntime instead\\.$# + """ + count: 1 + path: config/drupal-phpunit-bootstrap-file.php + + - + message: """ + #^Call to deprecated method locateRoot\\(\\) of class DrupalFinder\\\\DrupalFinder\\: + Will be removed in v2\\. Future usage should instantiate + a new DrupalFinder object by passing the starting path to its + constructor\\.$# + """ + count: 1 + path: rector.php + + - + message: """ + #^Instantiation of deprecated class DrupalFinder\\\\DrupalFinder\\: + in drupal\\-finder\\:1\\.3\\.0 and is removed from drupal\\-finder\\:2\\.0\\.0\\. + Use \\\\DrupalFinder\\\\DrupalFinderComposerRuntime instead\\.$# + """ + count: 1 + path: rector.php + + - + message: "#^Access to an undefined property PhpParser\\\\Node\\\\Expr\\:\\:\\$value\\.$#" + count: 2 + path: src/Drupal8/Rector/Deprecation/DBRector.php + + - + message: "#^Call to an undefined method PHPStan\\\\Type\\\\Type\\:\\:getValue\\(\\)\\.$#" + count: 1 + path: src/Drupal8/Rector/Deprecation/DrupalSetMessageRector.php + + - + message: "#^Access to an undefined property PhpParser\\\\Node\\\\Expr\\:\\:\\$expr\\.$#" + count: 1 + path: src/Drupal8/Rector/Deprecation/EntityLoadRector.php + + - + message: "#^Access to an undefined property PhpParser\\\\Node\\\\Expr\\:\\:\\$expr\\.$#" + count: 2 + path: src/Drupal8/Rector/Deprecation/EntityManagerRector.php + + - + message: "#^Access to an undefined property PhpParser\\\\Node\\\\Expr\\:\\:\\$name\\.$#" + count: 3 + path: src/Drupal8/Rector/Deprecation/EntityManagerRector.php + + - + message: "#^Method DrupalRector\\\\Drupal8\\\\Rector\\\\Deprecation\\\\EntityManagerRector\\:\\:getServiceByMethodName\\(\\) has no return type specified\\.$#" + count: 1 + path: src/Drupal8/Rector/Deprecation/EntityManagerRector.php + + - + message: "#^PHPDoc tag @param references unknown parameter\\: \\$node$#" + count: 1 + path: src/Drupal8/Rector/Deprecation/EntityManagerRector.php + + - + message: "#^Parameter \\#1 \\$assign of method DrupalRector\\\\Drupal8\\\\Rector\\\\Deprecation\\\\EntityManagerRector\\:\\:findInstanceByNameInAssign\\(\\) expects PhpParser\\\\Node\\\\Expr\\\\Assign, PhpParser\\\\Node\\\\Expr given\\.$#" + count: 1 + path: src/Drupal8/Rector/Deprecation/EntityManagerRector.php + + - + message: "#^Parameter \\#1 \\$assign of method DrupalRector\\\\Drupal8\\\\Rector\\\\Deprecation\\\\EntityManagerRector\\:\\:replaceInstanceByNameInAssign\\(\\) expects PhpParser\\\\Node\\\\Expr\\\\Assign, PhpParser\\\\Node\\\\Expr given\\.$#" + count: 1 + path: src/Drupal8/Rector/Deprecation/EntityManagerRector.php + + - + message: "#^Parameter \\#1 \\$expr of method DrupalRector\\\\Drupal8\\\\Rector\\\\Deprecation\\\\EntityManagerRector\\:\\:refactorExpression\\(\\) expects PhpParser\\\\Node\\\\Expr\\\\MethodCall\\|PhpParser\\\\Node\\\\Expr\\\\StaticCall, PhpParser\\\\Node given\\.$#" + count: 1 + path: src/Drupal8/Rector/Deprecation/EntityManagerRector.php + + - + message: "#^Parameter \\#1 \\$expr of method DrupalRector\\\\Drupal8\\\\Rector\\\\Deprecation\\\\EntityManagerRector\\:\\:refactorExpression\\(\\) expects PhpParser\\\\Node\\\\Expr\\\\MethodCall\\|PhpParser\\\\Node\\\\Expr\\\\StaticCall, PhpParser\\\\Node\\\\Expr given\\.$#" + count: 1 + path: src/Drupal8/Rector/Deprecation/EntityManagerRector.php + + - + message: "#^Property PhpParser\\\\Node\\\\Expr\\\\Assign\\:\\:\\$expr \\(PhpParser\\\\Node\\\\Expr\\) does not accept PhpParser\\\\Node\\.$#" + count: 1 + path: src/Drupal8/Rector/Deprecation/EntityManagerRector.php + + - + message: "#^Calling PHPStan\\\\Php\\\\PhpVersionFactory\\:\\:create\\(\\) is not covered by backward compatibility promise\\. The method might change in a minor PHPStan version\\.$#" + count: 1 + path: src/Drupal8/Rector/Deprecation/FunctionalTestDefaultThemePropertyRector.php + + - + message: "#^Method PHPStan\\\\Type\\\\Type\\:\\:isSmallerThanOrEqual\\(\\) invoked with 2 parameters, 1 required\\.$#" + count: 1 + path: src/Drupal8/Rector/Deprecation/FunctionalTestDefaultThemePropertyRector.php + + - + message: "#^Call to an undefined method PHPStan\\\\Type\\\\Type\\:\\:getValue\\(\\)\\.$#" + count: 1 + path: src/Drupal9/Rector/Deprecation/ExtensionPathRector.php diff --git a/phpstan-1.neon b/phpstan-1.neon new file mode 100644 index 00000000..74e16606 --- /dev/null +++ b/phpstan-1.neon @@ -0,0 +1,12 @@ +parameters: + level: 6 + paths: + - config + - src + - rector.php + bootstrapFiles: + - vendor/rector/rector/vendor/autoload.php + dynamicConstantNames: + - Drupal::VERSION +includes: + - phpstan-1-baseline.neon