99use PhpParser \Node \AttributeGroup ;
1010use PhpParser \Node \Name \FullyQualified ;
1111use PhpParser \Node \Stmt \Class_ ;
12- use PhpParser \Node \Stmt \ClassMethod ;
1312use PHPStan \Reflection \ReflectionProvider ;
13+ use Rector \Php80 \NodeAnalyzer \PhpAttributeAnalyzer ;
1414use Rector \Rector \AbstractRector ;
1515use Symplify \RuleDocGenerator \ValueObject \CodeSample \CodeSample ;
1616use 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