Skip to content

Commit

Permalink
Remove unused addNodeAfterNode(), return nodes instead (#4023)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed May 30, 2023
1 parent b97fe19 commit e2213f2
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 51 deletions.
46 changes: 1 addition & 45 deletions packages/PostRector/Collector/NodesToAddCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@
*/
final class NodesToAddCollector implements NodeCollectorInterface
{
/**
* @var Stmt[][]
*/
private array $nodesToAddAfter = [];

/**
* @var Stmt[][]
*/
Expand All @@ -43,7 +38,7 @@ public function __construct(

public function isActive(): bool
{
return $this->nodesToAddAfter !== [] || $this->nodesToAddBefore !== [];
return $this->nodesToAddBefore !== [];
}

/**
Expand All @@ -67,39 +62,6 @@ public function addNodeBeforeNode(Node $addedNode, Node $positionNode): void
$this->rectorChangeCollector->notifyNodeFileInfo($positionNode);
}

/**
* @api Used in downgrade still
* @deprecated
* Better return created nodes right in refactor() method to keep context
* @internal
*/
public function addNodeAfterNode(Node $addedNode, Node $positionNode): void
{
if ($positionNode->getAttributes() === []) {
$message = sprintf('Switch arguments in "%s()" method', __METHOD__);
throw new ShouldNotHappenException($message);
}

/** @var MutatingScope|null $currentScope */
$currentScope = $positionNode->getAttribute(AttributeKey::SCOPE);

$this->changedNodeScopeRefresher->refresh($addedNode, $currentScope);

$position = $this->resolveNearestStmtPosition($positionNode);
$this->nodesToAddAfter[$position][] = $this->wrapToExpression($addedNode);

$this->rectorChangeCollector->notifyNodeFileInfo($positionNode);
}

/**
* @return Stmt[]
*/
public function getNodesToAddAfterNode(Node $node): array
{
$position = spl_object_hash($node);
return $this->nodesToAddAfter[$position] ?? [];
}

/**
* @return Stmt[]
*/
Expand All @@ -109,12 +71,6 @@ public function getNodesToAddBeforeNode(Node $node): array
return $this->nodesToAddBefore[$position] ?? [];
}

public function clearNodesToAddAfter(Node $node): void
{
$objectHash = spl_object_hash($node);
unset($this->nodesToAddAfter[$objectHash]);
}

public function clearNodesToAddBefore(Node $node): void
{
$objectHash = spl_object_hash($node);
Expand Down
6 changes: 0 additions & 6 deletions packages/PostRector/Rector/NodeAddingPostRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ public function leaveNode(Node $node): array | Node
{
$newNodes = [$node];

$nodesToAddAfter = $this->nodesToAddCollector->getNodesToAddAfterNode($node);
if ($nodesToAddAfter !== []) {
$this->nodesToAddCollector->clearNodesToAddAfter($node);
$newNodes = array_merge($newNodes, $nodesToAddAfter);
}

$nodesToAddBefore = $this->nodesToAddCollector->getNodesToAddBeforeNode($node);
if ($nodesToAddBefore !== []) {
$this->nodesToAddCollector->clearNodesToAddBefore($node);
Expand Down

0 comments on commit e2213f2

Please sign in to comment.