Skip to content

Commit

Permalink
[Renaming] Reduc parent attribute on ClassRenamer take 2 (#4341)
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Jun 25, 2023
1 parent 0efdd58 commit 8337f6f
Showing 1 changed file with 3 additions and 24 deletions.
27 changes: 3 additions & 24 deletions rules/Renaming/NodeManipulator/ClassRenamer.php
Expand Up @@ -4,7 +4,6 @@

namespace Rector\Renaming\NodeManipulator;

use Nette\Utils\Strings;
use PhpParser\Node;
use PhpParser\Node\AttributeGroup;
use PhpParser\Node\Expr\New_;
Expand Down Expand Up @@ -111,7 +110,7 @@ private function refactorPhpDoc(Node $node, array $oldToNewTypes, array $oldToNe
$this->phpDocClassRenamer->changeTypeInAnnotationTypes($node, $phpDocInfo, $oldToNewClasses);
}

private function shouldSkip(string $newName, Name $name, ?Node $parentNode = null): bool
private function shouldSkip(string $newName, Name $name): bool
{
if ($name->getAttribute(AttributeKey::IS_STATICCALL_CLASS_NAME) === true && $this->reflectionProvider->hasClass(
$newName
Expand All @@ -120,26 +119,7 @@ private function shouldSkip(string $newName, Name $name, ?Node $parentNode = nul
return $classReflection->isInterface();
}

// parent is not a Node, possibly removed by other rule
// skip change it
if (! $parentNode instanceof Node) {
return true;
}

if (! $parentNode instanceof Namespace_) {
return false;
}

if ($parentNode->name !== $name) {
return false;
}

$namespaceNewName = Strings::before($newName, '\\', -1);
if ($namespaceNewName === null) {
return false;
}

return $this->nodeNameResolver->isName($parentNode, $namespaceNewName);
return false;
}

/**
Expand Down Expand Up @@ -169,8 +149,7 @@ private function refactorName(Name $name, array $oldToNewClasses): ?Name
return null;
}

$parentNode = $name->getAttribute(AttributeKey::PARENT_NODE);
if ($this->shouldSkip($newName, $name, $parentNode)) {
if ($this->shouldSkip($newName, $name)) {
return null;
}

Expand Down

0 comments on commit 8337f6f

Please sign in to comment.