Skip to content

Commit 44ef175

Browse files
committed
Fix use of existing PhpAttributeAnalyzer service on AddReturnTypeWillChangeAttributeRector
1 parent c1940cb commit 44ef175

1 file changed

Lines changed: 4 additions & 16 deletions

File tree

rules/DowngradePhp81/Rector/ClassMethod/AddReturnTypeWillChangeAttributeRector.php

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
use PhpParser\Node\AttributeGroup;
1010
use PhpParser\Node\Name\FullyQualified;
1111
use PhpParser\Node\Stmt\Class_;
12-
use PhpParser\Node\Stmt\ClassMethod;
1312
use PHPStan\Reflection\ReflectionProvider;
13+
use Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer;
1414
use Rector\Rector\AbstractRector;
1515
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
1616
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
@@ -42,6 +42,7 @@ final class AddReturnTypeWillChangeAttributeRector extends AbstractRector
4242

4343
public function __construct(
4444
private readonly ReflectionProvider $reflectionProvider,
45+
private readonly PhpAttributeAnalyzer $phpAttributeAnalyzer
4546
) {
4647
}
4748

@@ -100,7 +101,7 @@ public function refactor(Node $node): ?Node
100101
$hasChanged = false;
101102

102103
foreach ($node->getMethods() as $classMethod) {
103-
if ($this->hasReturnTypeWillChangeAttribute($classMethod)) {
104+
if ($this->phpAttributeAnalyzer->hasPhpAttribute($classMethod, self::RETURN_TYPE_WILL_CHANGE)) {
104105
continue;
105106
}
106107

@@ -124,7 +125,7 @@ public function refactor(Node $node): ?Node
124125
]);
125126

126127
$hasChanged = true;
127-
break;
128+
continue 2;
128129
}
129130
}
130131

@@ -134,17 +135,4 @@ public function refactor(Node $node): ?Node
134135

135136
return null;
136137
}
137-
138-
private function hasReturnTypeWillChangeAttribute(ClassMethod $classMethod): bool
139-
{
140-
foreach ($classMethod->attrGroups as $attrGroup) {
141-
foreach ($attrGroup->attrs as $attr) {
142-
if ($attr->name->getLast() === self::RETURN_TYPE_WILL_CHANGE) {
143-
return true;
144-
}
145-
}
146-
}
147-
148-
return false;
149-
}
150138
}

0 commit comments

Comments
 (0)