From 44ef1755cc6249769f10f12caaac2f3b452ce743 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sat, 30 May 2026 19:31:10 +0700 Subject: [PATCH] Fix use of existing PhpAttributeAnalyzer service on AddReturnTypeWillChangeAttributeRector --- ...AddReturnTypeWillChangeAttributeRector.php | 20 ++++--------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/rules/DowngradePhp81/Rector/ClassMethod/AddReturnTypeWillChangeAttributeRector.php b/rules/DowngradePhp81/Rector/ClassMethod/AddReturnTypeWillChangeAttributeRector.php index 54364d20..80f60fde 100644 --- a/rules/DowngradePhp81/Rector/ClassMethod/AddReturnTypeWillChangeAttributeRector.php +++ b/rules/DowngradePhp81/Rector/ClassMethod/AddReturnTypeWillChangeAttributeRector.php @@ -9,8 +9,8 @@ use PhpParser\Node\AttributeGroup; use PhpParser\Node\Name\FullyQualified; use PhpParser\Node\Stmt\Class_; -use PhpParser\Node\Stmt\ClassMethod; use PHPStan\Reflection\ReflectionProvider; +use Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer; use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -42,6 +42,7 @@ final class AddReturnTypeWillChangeAttributeRector extends AbstractRector public function __construct( private readonly ReflectionProvider $reflectionProvider, + private readonly PhpAttributeAnalyzer $phpAttributeAnalyzer ) { } @@ -100,7 +101,7 @@ public function refactor(Node $node): ?Node $hasChanged = false; foreach ($node->getMethods() as $classMethod) { - if ($this->hasReturnTypeWillChangeAttribute($classMethod)) { + if ($this->phpAttributeAnalyzer->hasPhpAttribute($classMethod, self::RETURN_TYPE_WILL_CHANGE)) { continue; } @@ -124,7 +125,7 @@ public function refactor(Node $node): ?Node ]); $hasChanged = true; - break; + continue 2; } } @@ -134,17 +135,4 @@ public function refactor(Node $node): ?Node return null; } - - private function hasReturnTypeWillChangeAttribute(ClassMethod $classMethod): bool - { - foreach ($classMethod->attrGroups as $attrGroup) { - foreach ($attrGroup->attrs as $attr) { - if ($attr->name->getLast() === self::RETURN_TYPE_WILL_CHANGE) { - return true; - } - } - } - - return false; - } }