diff --git a/composer.json b/composer.json index 1645519..ba7471c 100644 --- a/composer.json +++ b/composer.json @@ -29,13 +29,13 @@ "php": ">=8.0", "php-static-analysis/attributes": "^0.3.1 || dev-main", "php-static-analysis/node-visitor": "^0.3.1 || dev-main", - "rector/rector": "^0.19 || ^1.0" + "rector/rector": "~2.0.0" }, "require-dev": { "php-static-analysis/phpstan-extension": "dev-main", "php-static-analysis/psalm-plugin": "dev-main", "phpstan/extension-installer": "^1.3", - "phpstan/phpstan": "^1.8", + "phpstan/phpstan": "^2.0", "phpunit/phpunit": "^9.0", "symplify/easy-coding-standard": "^12.1", "vimeo/psalm": "^5", diff --git a/phpstan.neon b/phpstan.neon index c14f9c4..e7ea0b1 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -6,3 +6,6 @@ parameters: excludePaths: - tests/Fixture/* - tests/SpecialFixture/* + + ignoreErrors: + - '#::provideMinPhpVersion\(\) never returns \d+ so it can be removed from the return type#' diff --git a/src/AnnotationsToAttributesRector.php b/src/AnnotationsToAttributesRector.php index 16e8b0c..5ab7b1b 100644 --- a/src/AnnotationsToAttributesRector.php +++ b/src/AnnotationsToAttributesRector.php @@ -207,6 +207,7 @@ public function getNodeTypes(): array #[Param(node: 'Stmt\Class_|Stmt\ClassConst|Stmt\ClassMethod|Stmt\Function_|Stmt\Interface_|Stmt\Property|Stmt\Trait_')] public function refactor(Node $node): ?Node { + $hasChanged = false; $phpDocInfo = $this->phpDocInfoFactory->createFromNode($node); $attributeGroups = []; @@ -215,6 +216,7 @@ public function refactor(Node $node): ?Node } if ($attributeGroups !== []) { + $hasChanged = true; $this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($node); $this->attributeGroupNamedArgumentManipulator->decorate($attributeGroups); @@ -243,6 +245,8 @@ public function refactor(Node $node): ?Node $arg->name = null; $parameterAttributeGroups = [new AttributeGroup([$attribute])]; $parameter->attrGroups = array_merge($parameter->attrGroups, $parameterAttributeGroups); + + $hasChanged = true; } } } @@ -250,6 +254,7 @@ public function refactor(Node $node): ?Node } if ($attributeGroup->attrs === []) { unset($attributeGroups[$attrKey]); + $hasChanged = true; } } } @@ -266,6 +271,8 @@ public function refactor(Node $node): ?Node $this->attributeGroupNamedArgumentManipulator->decorate($useAttributeGroups); $attributeGroups = array_merge($attributeGroups, $useAttributeGroups); + + $hasChanged = true; } } } @@ -274,6 +281,11 @@ public function refactor(Node $node): ?Node if ($attributeGroups !== []) { $node->attrGroups = array_merge($node->attrGroups, $attributeGroups); + $hasChanged = true; + } + + if (! $hasChanged) { + return null; } return $node;