Skip to content

Commit cba980b

Browse files
authored
[NodeRemoval] Refactor NodeRemover to always use removeNode() method to ensure Node in NodesToRemoveCollector (rectorphp#3255)
1 parent 79a34f9 commit cba980b

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

packages/NodeRemoval/NodeRemover.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public function removeNodeFromStatements(
4848
continue;
4949
}
5050

51+
$this->removeNode($stmt);
5152
unset($nodeWithStatements->stmts[$key]);
5253
break;
5354
}
@@ -76,9 +77,7 @@ public function removeParam(ClassMethod $classMethod, int | Param $keyOrParam):
7677
return;
7778
}
7879

79-
// notify about remove node
80-
$this->rectorChangeCollector->notifyNodeFileInfo($classMethod->params[$key]);
81-
80+
$this->removeNode($classMethod->params[$key]);
8281
unset($classMethod->params[$key]);
8382
}
8483

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

96-
// notify about remove node
97-
$this->rectorChangeCollector->notifyNodeFileInfo($node->args[$key]);
98-
95+
$this->removeNode($node->args[$key]);
9996
unset($node->args[$key]);
10097
}
10198

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

111-
// notify about remove node
112-
$this->rectorChangeCollector->notifyNodeFileInfo($functionLike->stmts[$key]);
108+
// already removed
109+
if (! isset($functionLike->stmts[$key])) {
110+
return;
111+
}
113112

113+
$this->removeNode($functionLike->stmts[$key]);
114114
unset($functionLike->stmts[$key]);
115115
}
116116
}

0 commit comments

Comments
 (0)