Skip to content

Commit

Permalink
[NodeRemoval] Refactor NodeRemover to always use removeNode() method …
Browse files Browse the repository at this point in the history
…to ensure Node in NodesToRemoveCollector (#3255)
  • Loading branch information
samsonasik committed Jan 2, 2023
1 parent 79a34f9 commit cba980b
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions packages/NodeRemoval/NodeRemover.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public function removeNodeFromStatements(
continue;
}

$this->removeNode($stmt);
unset($nodeWithStatements->stmts[$key]);
break;
}
Expand Down Expand Up @@ -76,9 +77,7 @@ public function removeParam(ClassMethod $classMethod, int | Param $keyOrParam):
return;
}

// notify about remove node
$this->rectorChangeCollector->notifyNodeFileInfo($classMethod->params[$key]);

$this->removeNode($classMethod->params[$key]);
unset($classMethod->params[$key]);
}

Expand All @@ -93,9 +92,7 @@ public function removeArg(FuncCall | MethodCall | StaticCall $node, int $key): v
return;
}

// notify about remove node
$this->rectorChangeCollector->notifyNodeFileInfo($node->args[$key]);

$this->removeNode($node->args[$key]);
unset($node->args[$key]);
}

Expand All @@ -108,9 +105,12 @@ public function removeStmt(Closure | ClassMethod | Function_ $functionLike, int
throw new ShouldNotHappenException();
}

// notify about remove node
$this->rectorChangeCollector->notifyNodeFileInfo($functionLike->stmts[$key]);
// already removed
if (! isset($functionLike->stmts[$key])) {
return;
}

$this->removeNode($functionLike->stmts[$key]);
unset($functionLike->stmts[$key]);
}
}

0 comments on commit cba980b

Please sign in to comment.