Skip to content

Commit 0318691

Browse files
authored
[exp] Remove always-run key re-indexing on every node (#7649)
1 parent bcc8a96 commit 0318691

3 files changed

Lines changed: 16 additions & 3 deletions

File tree

rules/CodingStyle/Rector/FuncCall/CallUserFuncToMethodCallRector.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,15 @@ public function refactor(Node $node): ?Node
8282
return null;
8383
}
8484

85+
// remove first arg
86+
$originalArgs = $node->getArgs();
87+
array_shift($originalArgs);
88+
8589
$methodCall = $this->arrayCallableToMethodCallFactory->create($firstArgValue);
8690
if (! $methodCall instanceof MethodCall) {
8791
return null;
8892
}
8993

90-
$originalArgs = $node->args;
91-
unset($originalArgs[0]);
92-
9394
$methodCall->args = $originalArgs;
9495
return $methodCall;
9596
}

rules/DeadCode/Rector/Assign/RemoveDoubleAssignRector.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,17 @@ public function refactor(Node $node): ?Node
112112

113113
// remove current Stmt if will be overridden in next stmt
114114
unset($node->stmts[$key]);
115+
115116
$hasChanged = true;
116117
}
117118

118119
if (! $hasChanged) {
119120
return null;
120121
}
121122

123+
// update array keys to fit printer
124+
$node->stmts = array_values($node->stmts);
125+
122126
return $node;
123127
}
124128

rules/Php85/Rector/FuncCall/RemoveFinfoBufferContextArgRector.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public function getNodeTypes(): array
5656
*/
5757
public function refactor(Node $node): ?Node
5858
{
59+
// Cannot handle variadic args
5960
if ($node->isFirstClassCallable()) {
6061
return null;
6162
}
@@ -106,13 +107,20 @@ private function removeContextArg(FuncCall|MethodCall $callLike): bool
106107

107108
unset($callLike->args[3 + $methodArgCorrection]);
108109

110+
// update indexed to make printer work as expected
111+
$callLike->args = array_values($callLike->args);
112+
109113
return true;
110114
}
111115

116+
// process named arguments
112117
foreach ($args as $position => $arg) {
113118
if ($arg->name instanceof Identifier && $this->isName($arg->name, 'context')) {
114119
unset($callLike->args[$position]);
115120

121+
// update indexed to make printer work as expected
122+
$callLike->args = array_values($callLike->args);
123+
116124
return true;
117125
}
118126
}

0 commit comments

Comments
 (0)