From 4a0131d19b5475ec29d76552981d5a1623be810e Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Thu, 20 Nov 2025 19:21:20 +0000 Subject: [PATCH] [exp] Remove always-run key re-indexing on every node --- .../Rector/FuncCall/CallUserFuncToMethodCallRector.php | 7 ++++--- rules/DeadCode/Rector/Assign/RemoveDoubleAssignRector.php | 4 ++++ .../Rector/FuncCall/RemoveFinfoBufferContextArgRector.php | 8 ++++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/rules/CodingStyle/Rector/FuncCall/CallUserFuncToMethodCallRector.php b/rules/CodingStyle/Rector/FuncCall/CallUserFuncToMethodCallRector.php index ee7e828533c..a4d7bf6d4b9 100644 --- a/rules/CodingStyle/Rector/FuncCall/CallUserFuncToMethodCallRector.php +++ b/rules/CodingStyle/Rector/FuncCall/CallUserFuncToMethodCallRector.php @@ -82,14 +82,15 @@ public function refactor(Node $node): ?Node return null; } + // remove first arg + $originalArgs = $node->getArgs(); + array_shift($originalArgs); + $methodCall = $this->arrayCallableToMethodCallFactory->create($firstArgValue); if (! $methodCall instanceof MethodCall) { return null; } - $originalArgs = $node->args; - unset($originalArgs[0]); - $methodCall->args = $originalArgs; return $methodCall; } diff --git a/rules/DeadCode/Rector/Assign/RemoveDoubleAssignRector.php b/rules/DeadCode/Rector/Assign/RemoveDoubleAssignRector.php index e1464a6fe08..b62ea2bd211 100644 --- a/rules/DeadCode/Rector/Assign/RemoveDoubleAssignRector.php +++ b/rules/DeadCode/Rector/Assign/RemoveDoubleAssignRector.php @@ -112,6 +112,7 @@ public function refactor(Node $node): ?Node // remove current Stmt if will be overridden in next stmt unset($node->stmts[$key]); + $hasChanged = true; } @@ -119,6 +120,9 @@ public function refactor(Node $node): ?Node return null; } + // update array keys to fit printer + $node->stmts = array_values($node->stmts); + return $node; } diff --git a/rules/Php85/Rector/FuncCall/RemoveFinfoBufferContextArgRector.php b/rules/Php85/Rector/FuncCall/RemoveFinfoBufferContextArgRector.php index 17ce17e29e2..7db9eb0514c 100644 --- a/rules/Php85/Rector/FuncCall/RemoveFinfoBufferContextArgRector.php +++ b/rules/Php85/Rector/FuncCall/RemoveFinfoBufferContextArgRector.php @@ -56,6 +56,7 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?Node { + // Cannot handle variadic args if ($node->isFirstClassCallable()) { return null; } @@ -106,13 +107,20 @@ private function removeContextArg(FuncCall|MethodCall $callLike): bool unset($callLike->args[3 + $methodArgCorrection]); + // update indexed to make printer work as expected + $callLike->args = array_values($callLike->args); + return true; } + // process named arguments foreach ($args as $position => $arg) { if ($arg->name instanceof Identifier && $this->isName($arg->name, 'context')) { unset($callLike->args[$position]); + // update indexed to make printer work as expected + $callLike->args = array_values($callLike->args); + return true; } }