Skip to content

Commit

Permalink
[Core] Remove ParentConnectingVisitor usage on AbstractRector (#3519)
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Mar 25, 2023
1 parent 3445422 commit 6c8aa92
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/Rector/AbstractRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use PhpParser\Node\Stmt\Nop;
use PhpParser\NodeTraverser;
use PhpParser\NodeVisitor\NodeConnectingVisitor;
use PhpParser\NodeVisitor\ParentConnectingVisitor;
use PhpParser\NodeVisitorAbstract;
use PHPStan\Analyser\MutatingScope;
use PHPStan\Type\ObjectType;
Expand Down Expand Up @@ -239,7 +238,7 @@ final public function enterNode(Node $node)
$firstNode = current($refactoredNode);
$this->mirrorComments($firstNode, $originalNode);

$this->updateAndconnectParentNodes($refactoredNode, $parentNode);
$this->updateParentNodes($refactoredNode, $parentNode);
$this->connectNodes($refactoredNode, $node);
$this->refreshScopeNodes($refactoredNode, $filePath, $currentScope);

Expand All @@ -253,7 +252,7 @@ final public function enterNode(Node $node)
? new Expression($refactoredNode)
: $refactoredNode;

$this->updateAndconnectParentNodes($refactoredNode, $parentNode);
$this->updateParentNodes($refactoredNode, $parentNode);
$this->connectNodes([$refactoredNode], $node);
$this->refreshScopeNodes($refactoredNode, $filePath, $currentScope);

Expand Down Expand Up @@ -397,7 +396,7 @@ private function shouldSkipCurrentNode(Node $node): bool
/**
* @param Node[]|Node $node
*/
private function updateAndconnectParentNodes(array | Node $node, ?Node $parentNode): void
private function updateParentNodes(array | Node $node, ?Node $parentNode): void
{
if (! $parentNode instanceof Node) {
return;
Expand All @@ -406,13 +405,9 @@ private function updateAndconnectParentNodes(array | Node $node, ?Node $parentNo
$nodes = $node instanceof Node ? [$node] : $node;

foreach ($nodes as $node) {
// update parents relations - must run before addVisitor(new ParentConnectingVisitor())
// update parents relations
$node->setAttribute(AttributeKey::PARENT_NODE, $parentNode);
}

$nodeTraverser = new NodeTraverser();
$nodeTraverser->addVisitor(new ParentConnectingVisitor());
$nodeTraverser->traverse($nodes);
}

/**
Expand Down

0 comments on commit 6c8aa92

Please sign in to comment.