mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-03 01:40:49 +00:00
fc10fce13d
* re-enable rectify and ecs * [Rectify] [Php81] Enable Rectify on Readonly Property only * comment * [ci-review] Rector Rectify * [ci-review] Rector Rectify * [ci-review] Rector Rectify * [ci-review] Rector Rectify * [ci-review] Rector Rectify Co-authored-by: GitHub Action <action@github.com>
48 lines
1.2 KiB
PHP
48 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Rector\NodeNameResolver\NodeNameResolver;
|
|
|
|
use PhpParser\Node;
|
|
use PhpParser\Node\Expr\FuncCall;
|
|
use PhpParser\Node\Name;
|
|
use PhpParser\Node\Name\FullyQualified;
|
|
use Rector\NodeNameResolver\Contract\NodeNameResolverInterface;
|
|
use Rector\NodeTypeResolver\Node\AttributeKey;
|
|
|
|
/**
|
|
* @implements NodeNameResolverInterface<Name>
|
|
*/
|
|
final class NameNameResolver implements NodeNameResolverInterface
|
|
{
|
|
public function __construct(
|
|
private readonly FuncCallNameResolver $funcCallNameResolver
|
|
) {
|
|
}
|
|
|
|
public function getNode(): string
|
|
{
|
|
return Name::class;
|
|
}
|
|
|
|
/**
|
|
* @param Name $node
|
|
*/
|
|
public function resolve(Node $node): ?string
|
|
{
|
|
// possible function parent
|
|
$parent = $node->getAttribute(AttributeKey::PARENT_NODE);
|
|
if ($parent instanceof FuncCall) {
|
|
return $this->funcCallNameResolver->resolve($parent);
|
|
}
|
|
|
|
$resolvedName = $node->getAttribute(AttributeKey::RESOLVED_NAME);
|
|
if ($resolvedName instanceof FullyQualified) {
|
|
return $resolvedName->toString();
|
|
}
|
|
|
|
return $node->toString();
|
|
}
|
|
}
|