Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Oct 29, 2023
1 parent 4817f88 commit 72222b6
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/PostRector/Rector/NameImportingPostRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
use Rector\Core\Configuration\Option;
use Rector\Core\Configuration\Parameter\SimpleParameterProvider;
use Rector\Core\Configuration\RenamedClassesDataCollector;
use Rector\Core\PhpParser\Node\CustomNode\FileWithoutNamespace;
use Rector\Core\Provider\CurrentFileProvider;
use Rector\Core\ValueObject\Application\File;
Expand All @@ -40,6 +41,7 @@ public function __construct(
private readonly UseImportsResolver $useImportsResolver,
private readonly AliasNameResolver $aliasNameResolver,
private readonly DocBlockUpdater $docBlockUpdater,
private readonly RenamedClassesDataCollector $renamedClassesDataCollector
) {
}

Expand All @@ -60,6 +62,7 @@ public function enterNode(Node $node): ?Node
}

if ($node instanceof Name) {
$node = $this->resolveNameFromAttribute($node);
return $this->processNodeName($node, $file);
}

Expand All @@ -86,6 +89,22 @@ public function enterNode(Node $node): ?Node
return $node;
}

private function resolveNameFromAttribute(Name $name): Name
{
if ($name->hasAttribute(AttributeKey::PHP_ATTRIBUTE_NAME)) {
$oldToNewClasses = $this->renamedClassesDataCollector->getOldToNewClasses();
$phpAttributeName = $name->getAttribute(AttributeKey::PHP_ATTRIBUTE_NAME);

foreach ($oldToNewClasses as $oldName => $newName) {
if ($oldName === $phpAttributeName) {
return new FullyQualified($newName);
}
}
}

return $name;
}

private function processNodeName(Name $name, File $file): ?Node
{
if ($name->isSpecialClassName()) {
Expand Down

0 comments on commit 72222b6

Please sign in to comment.