mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-22 18:54:39 +01:00
IdentifierRector: fix nesting Node
This commit is contained in:
parent
2c90337130
commit
e316e2aa94
@ -3,7 +3,6 @@
|
||||
namespace Rector\Rector\Contrib\PhpParser;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\ArrayDimFetch;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\PropertyFetch;
|
||||
use Rector\Node\Attribute;
|
||||
@ -47,15 +46,9 @@ final class IdentifierRector extends AbstractRector
|
||||
'PhpParser\Node\Stmt\UseUse' => ['alias'],
|
||||
];
|
||||
|
||||
/**
|
||||
* @var NodeFactory
|
||||
*/
|
||||
private $nodeFactory;
|
||||
|
||||
public function __construct(PropertyFetchAnalyzer $propertyFetchAnalyzer, NodeFactory $nodeFactory)
|
||||
public function __construct(PropertyFetchAnalyzer $propertyFetchAnalyzer)
|
||||
{
|
||||
$this->propertyFetchAnalyzer = $propertyFetchAnalyzer;
|
||||
$this->nodeFactory = $nodeFactory;
|
||||
}
|
||||
|
||||
public function isCandidate(Node $node): bool
|
||||
@ -82,23 +75,10 @@ final class IdentifierRector extends AbstractRector
|
||||
return $propertyFetchNode;
|
||||
}
|
||||
|
||||
if ($propertyFetchNode->var instanceof ArrayDimFetch) {
|
||||
$propertyFetchNode->var;
|
||||
$methodCallNode = new MethodCall($propertyFetchNode, 'toString');
|
||||
$propertyFetchNode->setAttribute(Attribute::PARENT_NODE, $methodCallNode);
|
||||
|
||||
return new MethodCall($propertyFetchNode, 'toString');
|
||||
}
|
||||
|
||||
$origPropertyFetchNode = $propertyFetchNode;
|
||||
|
||||
$firstPropertyName = $origPropertyFetchNode->var->name;
|
||||
$secondPropertyName = $origPropertyFetchNode->name->toString();
|
||||
|
||||
$newPropertyFetchNode = $this->nodeFactory->createPropertyFetch(
|
||||
$firstPropertyName,
|
||||
$secondPropertyName
|
||||
);
|
||||
|
||||
return new MethodCall($newPropertyFetchNode, 'toString');
|
||||
return $methodCallNode;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user