prevente re-importing renamed use imports

This commit is contained in:
TomasVotruba 2020-06-19 13:18:03 +02:00
parent a126eb4cb3
commit e4932e6782

View File

@ -136,10 +136,14 @@ final class ClassRenamer
$parentNode = $name->getAttribute(AttributeKey::PARENT_NODE); $parentNode = $name->getAttribute(AttributeKey::PARENT_NODE);
// no need to preslash "use \SomeNamespace" of imported namespace // no need to preslash "use \SomeNamespace" of imported namespace
if ($parentNode instanceof UseUse && ($parentNode->type === Use_::TYPE_NORMAL || $parentNode->type === Use_::TYPE_UNKNOWN)) { if ($parentNode instanceof UseUse && ($parentNode->type === Use_::TYPE_NORMAL || $parentNode->type === Use_::TYPE_UNKNOWN)) {
return new Name($newName); $name = new Name($newName);
} else {
$name = new FullyQualified($newName);
} }
return new FullyQualified($newName); $name->setAttribute(AttributeKey::PARENT_NODE, $parentNode);
return $name;
} }
private function refactorNamespaceNode(Namespace_ $namespace, array $oldToNewClasses): ?Node private function refactorNamespaceNode(Namespace_ $namespace, array $oldToNewClasses): ?Node
@ -208,7 +212,11 @@ final class ClassRenamer
if ($newNamespacePart && ! $this->classNaming->getNamespace($name)) { if ($newNamespacePart && ! $this->classNaming->getNamespace($name)) {
$this->changeNameToFullyQualifiedName($classLike); $this->changeNameToFullyQualifiedName($classLike);
return new Namespace_(new Name($newNamespacePart), [$classLike]); $nameNode = new Name($newNamespacePart);
$namespace = new Namespace_($nameNode, [$classLike]);
$nameNode->setAttribute(AttributeKey::PARENT_NODE, $namespace);
return $namespace;
} }
return $classLike; return $classLike;