diff --git a/packages/NodeTypeResolver/PhpDocNodeVisitor/ClassRenamePhpDocNodeVisitor.php b/packages/NodeTypeResolver/PhpDocNodeVisitor/ClassRenamePhpDocNodeVisitor.php index 68d53d1860a1..6add5ed36a75 100644 --- a/packages/NodeTypeResolver/PhpDocNodeVisitor/ClassRenamePhpDocNodeVisitor.php +++ b/packages/NodeTypeResolver/PhpDocNodeVisitor/ClassRenamePhpDocNodeVisitor.php @@ -6,6 +6,7 @@ use PhpParser\Node as PhpParserNode; use PhpParser\Node\Identifier; +use PhpParser\Node\Name\FullyQualified; use PhpParser\Node\Stmt\GroupUse; use PhpParser\Node\Stmt\Namespace_; use PhpParser\Node\Stmt\Use_; @@ -66,6 +67,11 @@ public function enterNode(Node $node): ?Node return null; } + $previousNode = $phpParserNode->getAttribute(AttributeKey::PREVIOUS_NODE); + if ($previousNode instanceof FullyQualified) { + return null; + } + $identifier = clone $node; $namespacedName = $this->resolveNamespacedName($phpParserNode, $node->name); $identifier->name = $namespacedName; diff --git a/rules-tests/Renaming/Rector/Name/RenameClassRector/FixtureAutoImportNames/do_not_rename_class_with_same_name_inside_different_namespace.php.inc b/rules-tests/Renaming/Rector/Name/RenameClassRector/FixtureAutoImportNames/do_not_rename_class_with_same_name_inside_different_namespace.php.inc new file mode 100644 index 000000000000..adbb5e9bf8bc --- /dev/null +++ b/rules-tests/Renaming/Rector/Name/RenameClassRector/FixtureAutoImportNames/do_not_rename_class_with_same_name_inside_different_namespace.php.inc @@ -0,0 +1,34 @@ + +----- + diff --git a/rules-tests/Renaming/Rector/Name/RenameClassRector/FixtureAutoImportNames/do_not_rename_class_with_same_name_inside_different_namespace2.php.inc b/rules-tests/Renaming/Rector/Name/RenameClassRector/FixtureAutoImportNames/do_not_rename_class_with_same_name_inside_different_namespace2.php.inc new file mode 100644 index 000000000000..c440733518e3 --- /dev/null +++ b/rules-tests/Renaming/Rector/Name/RenameClassRector/FixtureAutoImportNames/do_not_rename_class_with_same_name_inside_different_namespace2.php.inc @@ -0,0 +1,32 @@ + +----- +