diff --git a/rules/Php72/Rector/Assign/ListEachRector.php b/rules/Php72/Rector/Assign/ListEachRector.php index e3e9fa7d4f4..afc2f66d3e6 100644 --- a/rules/Php72/Rector/Assign/ListEachRector.php +++ b/rules/Php72/Rector/Assign/ListEachRector.php @@ -92,8 +92,6 @@ public function refactor(Node $node) // only value: list(, $value) = each($values); if ($listNode->items[1] instanceof ArrayItem && ! $listNode->items[0] instanceof ArrayItem) { $nextFuncCall = $this->nodeFactory->createFuncCall('next', $eachFuncCall->args); - // $this->nodesToAddCollector->addNodeAfterNode($nextFuncCall, $assign); - $currentFuncCall = $this->nodeFactory->createFuncCall('current', $eachFuncCall->args); $secondArrayItem = $listNode->items[1]; @@ -111,11 +109,8 @@ public function refactor(Node $node) } $currentAssign = new Assign($secondArrayItem->value, $currentFuncCall); - // $this->nodesToAddCollector->addNodeAfterNode($assign, $assign); $nextFuncCall = $this->nodeFactory->createFuncCall('next', $eachFuncCall->args); - // $this->nodesToAddCollector->addNodeAfterNode($nextFuncCall, $node); - $keyFuncCall = $this->nodeFactory->createFuncCall('key', $eachFuncCall->args); $firstArrayItem = $listNode->items[0]; diff --git a/tests/Issues/AddNodeAfterNodeStmt/Source/AddNextNopRector.php b/tests/Issues/AddNodeAfterNodeStmt/Source/AddNextNopRector.php index 9a07cd2157f..99c9eeedb2b 100644 --- a/tests/Issues/AddNodeAfterNodeStmt/Source/AddNextNopRector.php +++ b/tests/Issues/AddNodeAfterNodeStmt/Source/AddNextNopRector.php @@ -14,14 +14,8 @@ use Rector\PostRector\Collector\NodesToAddCollector; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; -class AddNextNopRector extends AbstractRector +final class AddNextNopRector extends AbstractRector { - private array $justAdded = []; - - public function __construct(private readonly NodesToAddCollector $nodesToAddCollector) - { - } - public function getRuleDefinition(): RuleDefinition { return new RuleDefinition('uff', []); @@ -36,10 +30,6 @@ public function getNodeTypes(): array public function refactor(Node $node) { - if (isset($this->justAdded[$this->file->getFilePath()])) { - return null; - } - $echo = new Echo_([new String_("this is new stmt after Nop")]); $phpDocInfo = $this->phpDocInfoFactory->createEmpty($echo); @@ -51,13 +41,9 @@ public function refactor(Node $node) ) ); - $this->nodesToAddCollector->addNodeAfterNode( + return [ + $node, $echo, - $node - ); - - $this->justAdded[$this->file->getFilePath()] = true; - - return $node; + ]; } } diff --git a/tests/Issues/AddNodeAfterNodeStmt/Source/AddNextStmtRector.php b/tests/Issues/AddNodeAfterNodeStmt/Source/AddNextStmtRector.php index c59e5e4e876..9e5e2ad7af9 100644 --- a/tests/Issues/AddNodeAfterNodeStmt/Source/AddNextStmtRector.php +++ b/tests/Issues/AddNodeAfterNodeStmt/Source/AddNextStmtRector.php @@ -12,14 +12,8 @@ use Rector\PostRector\Collector\NodesToAddCollector; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; -class AddNextStmtRector extends AbstractRector +final class AddNextStmtRector extends AbstractRector { - private array $justAdded = []; - - public function __construct(private readonly NodesToAddCollector $nodesToAddCollector) - { - } - public function getRuleDefinition(): RuleDefinition { return new RuleDefinition('uff', []); @@ -34,17 +28,9 @@ public function getNodeTypes(): array public function refactor(Node $node) { - if (isset($this->justAdded[$this->file->getFilePath()])) { - return null; - } - - $this->nodesToAddCollector->addNodeAfterNode( + return [ + $node, new Echo_([new String_("this is new stmt after if")]), - $node - ); - - $this->justAdded[$this->file->getFilePath()] = true; - - return $node; + ]; } } diff --git a/tests/Issues/AddNodeBeforeNodeStmt/Source/AddBeforeStmtRector.php b/tests/Issues/AddNodeBeforeNodeStmt/Source/AddBeforeStmtRector.php index aa74616cf91..27dac824cef 100644 --- a/tests/Issues/AddNodeBeforeNodeStmt/Source/AddBeforeStmtRector.php +++ b/tests/Issues/AddNodeBeforeNodeStmt/Source/AddBeforeStmtRector.php @@ -14,12 +14,6 @@ class AddBeforeStmtRector extends AbstractRector { - private array $justAdded = []; - - public function __construct(private readonly NodesToAddCollector $nodesToAddCollector) - { - } - public function getRuleDefinition(): RuleDefinition { return new RuleDefinition('uff', []); @@ -34,17 +28,9 @@ public function getNodeTypes(): array public function refactor(Node $node) { - if (isset($this->justAdded[$this->file->getFilePath()])) { - return null; - } - - $this->nodesToAddCollector->addNodeBeforeNode( + return [ new Echo_([new String_("this is new stmt before if")]), $node - ); - - $this->justAdded[$this->file->getFilePath()] = true; - - return $node; + ]; } }