Skip to content

Commit f1ec262

Browse files
committed
use explicit array node re-index as best practice to always keep node keys as list
1 parent fff99ae commit f1ec262

6 files changed

Lines changed: 23 additions & 8 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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ public function getNodeTypes(): array
5656
*/
5757
public function refactor(Node $node): ?Node
5858
{
59+
<<<<<<< HEAD
60+
=======
61+
// Cannot handle variadic args
62+
>>>>>>> afb1a4523d (use explicit array node re-index as best practice to always keep node keys as list)
5963
if ($node->isFirstClassCallable()) {
6064
return null;
6165
}
@@ -106,13 +110,20 @@ private function removeContextArg(FuncCall|MethodCall $callLike): bool
106110

107111
unset($callLike->args[3 + $methodArgCorrection]);
108112

113+
// update indexed to make printer work as expected
114+
$callLike->args = array_values($callLike->args);
115+
109116
return true;
110117
}
111118

119+
// process named arguments
112120
foreach ($args as $position => $arg) {
113121
if ($arg->name instanceof Identifier && $this->isName($arg->name, 'context')) {
114122
unset($callLike->args[$position]);
115123

124+
// update indexed to make printer work as expected
125+
$callLike->args = array_values($callLike->args);
126+
116127
return true;
117128
}
118129
}

src/Application/ChangedNodeScopeRefresher.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@ public function refresh(Node $node, string $filePath, ?MutatingScope $mutatingSc
5858
throw new ShouldNotHappenException($errorMessage);
5959
}
6060

61-
// reindex stmt_key already covered on StmtKeyNodeVisitor on next processNodes()
62-
// so set flag $reIndexStmtKey to false to avoid double loop
63-
NodeAttributeReIndexer::reIndexNodeAttributes($node, false);
64-
6561
$stmts = $this->resolveStmts($node);
6662
$this->phpStanNodeScopeResolver->processNodes($stmts, $filePath, $mutatingScope);
6763
}

src/DependencyInjection/LazyContainerFactory.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ final class LazyContainerFactory
242242
GlobalVariableNodeVisitor::class,
243243
NameNodeVisitor::class,
244244
StaticVariableNodeVisitor::class,
245+
<<<<<<< HEAD
246+
=======
247+
// StmtKeyNodeVisitor::class,
248+
>>>>>>> afb1a4523d (use explicit array node re-index as best practice to always keep node keys as list)
245249
];
246250

247251
/**

src/Rector/AbstractRector.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
use PHPStan\Type\ObjectType;
2121
use PHPStan\Type\Type;
2222
use Rector\Application\ChangedNodeScopeRefresher;
23-
use Rector\Application\NodeAttributeReIndexer;
2423
use Rector\Application\Provider\CurrentFileProvider;
2524
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
2625
use Rector\ChangesReporting\ValueObject\RectorWithLineChange;

0 commit comments

Comments
 (0)