@@ -54,14 +54,14 @@ public function renameNode(Node $node, array $oldToNewClasses, ?Scope $scope): ?
5454
5555 // execute FullyQualified before Name on purpose so next Name check is pure Name node
5656 if ($ node instanceof FullyQualified) {
57- return $ this ->refactorName ($ node , $ oldToNewClasses );
57+ return $ this ->refactorName ($ node , $ oldToNewClasses, $ scope );
5858 }
5959
6060 // Name as parent of FullyQualified executed for fallback annotation to attribute rename to Name
6161 if ($ node instanceof Name) {
6262 $ phpAttributeName = $ node ->getAttribute (AttributeKey::PHP_ATTRIBUTE_NAME );
6363 if (is_string ($ phpAttributeName )) {
64- return $ this ->refactorName (new FullyQualified ($ phpAttributeName ), $ oldToNewClasses );
64+ return $ this ->refactorName (new FullyQualified ($ phpAttributeName ), $ oldToNewClasses, $ scope );
6565 }
6666
6767 return null ;
@@ -133,8 +133,11 @@ private function shouldSkip(string $newName, FullyQualified $fullyQualified): bo
133133 /**
134134 * @param array<string, string> $oldToNewClasses
135135 */
136- private function refactorName (FullyQualified $ fullyQualified , array $ oldToNewClasses ): ?FullyQualified
137- {
136+ private function refactorName (
137+ FullyQualified $ fullyQualified ,
138+ array $ oldToNewClasses ,
139+ ?Scope $ scope
140+ ): ?FullyQualified {
138141 if ($ fullyQualified ->getAttribute (AttributeKey::IS_FUNCCALL_NAME ) === true ) {
139142 return null ;
140143 }
@@ -146,7 +149,7 @@ private function refactorName(FullyQualified $fullyQualified, array $oldToNewCla
146149 return null ;
147150 }
148151
149- if (! $ this ->isClassToInterfaceValidChange ($ fullyQualified , $ newName )) {
152+ if (! $ this ->isClassToInterfaceValidChange ($ fullyQualified , $ newName, $ scope )) {
150153 return null ;
151154 }
152155
@@ -202,15 +205,26 @@ private function refactorClassLike(ClassLike $classLike, array $oldToNewClasses,
202205 * - implements SomeInterface
203206 * - implements SomeClass
204207 */
205- private function isClassToInterfaceValidChange (FullyQualified $ fullyQualified , string $ newClassName ): bool
206- {
208+ private function isClassToInterfaceValidChange (
209+ FullyQualified $ fullyQualified ,
210+ string $ newClassName ,
211+ ?Scope $ scope
212+ ): bool {
207213 if (! $ this ->reflectionProvider ->hasClass ($ newClassName )) {
208214 return true ;
209215 }
210216
211217 $ classReflection = $ this ->reflectionProvider ->getClass ($ newClassName );
212218 // ensure new is not with interface
213219 if ($ fullyQualified ->getAttribute (AttributeKey::IS_NEW_INSTANCE_NAME ) !== true ) {
220+ if ($ fullyQualified ->getAttribute (AttributeKey::IS_CLASS_EXTENDS ) === true && $ scope instanceof Scope) {
221+ $ currentClassReflection = $ scope ->getClassReflection ();
222+
223+ if ($ currentClassReflection instanceof ClassReflection && $ currentClassReflection ->getName () === $ newClassName ) {
224+ return false ;
225+ }
226+ }
227+
214228 return $ this ->isValidClassNameChange ($ fullyQualified , $ classReflection );
215229 }
216230
0 commit comments