Skip to content

Commit

Permalink
Remove PARENT_NODE from StringClassNameToClassConstantRector (#3928)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed May 22, 2023
1 parent 3c69a0f commit 26b32be
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 17 deletions.
Expand Up @@ -26,7 +26,7 @@ class UseNameFromAlias
{
public function run()
{
return SomeAlias::class;
return \Rector\Tests\Php55\Rector\String_\StringClassNameToClassConstantRector\Source\AnotherClass::class;
}
}

Expand Down
Expand Up @@ -26,7 +26,7 @@ class UseNameFromAlias
{
public function run()
{
return SomeAlias::class;
return \Rector\Tests\Php55\Rector\String_\StringClassNameToClassConstantRector\Source\AnotherClass::class;
}
}

Expand Down
Expand Up @@ -9,15 +9,14 @@
use PhpParser\Node\Expr\BinaryOp\Concat;
use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Name;
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt\ClassConst;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ReflectionProvider;
use Rector\Core\Contract\Rector\AllowEmptyConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\Rector\AbstractScopeAwareRector;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\Naming\Naming\AliasNameResolver;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
Expand All @@ -29,7 +28,7 @@
*
* @see \Rector\Tests\Php55\Rector\String_\StringClassNameToClassConstantRector\StringClassNameToClassConstantRectorTest
*/
final class StringClassNameToClassConstantRector extends AbstractRector implements AllowEmptyConfigurableRectorInterface, MinPhpVersionInterface
final class StringClassNameToClassConstantRector extends AbstractScopeAwareRector implements AllowEmptyConfigurableRectorInterface, MinPhpVersionInterface
{
/**
* @var string[]
Expand All @@ -38,7 +37,6 @@ final class StringClassNameToClassConstantRector extends AbstractRector implemen

public function __construct(
private readonly ReflectionProvider $reflectionProvider,
private readonly AliasNameResolver $aliasNameResolver
) {
}

Expand Down Expand Up @@ -90,7 +88,7 @@ public function getNodeTypes(): array
/**
* @param String_ $node
*/
public function refactor(Node $node): ?Node
public function refactorWithScope(Node $node, Scope $scope): ?Node
{
$classLikeName = $node->value;

Expand All @@ -105,15 +103,7 @@ public function refactor(Node $node): ?Node
}

$fullyQualified = new FullyQualified($classLikeName);

$name = clone $fullyQualified;
$name->setAttribute(AttributeKey::PARENT_NODE, $node->getAttribute(AttributeKey::PARENT_NODE));

$aliasName = $this->aliasNameResolver->resolveByName($name);

$fullyQualifiedOrAliasName = is_string($aliasName)
? new Name($aliasName)
: $fullyQualified;
$fullyQualifiedOrAliasName = new FullyQualified($scope->resolveName($fullyQualified));

if ($classLikeName !== $node->value) {
$preSlashCount = strlen($node->value) - strlen($classLikeName);
Expand Down

0 comments on commit 26b32be

Please sign in to comment.