Skip to content

Commit fff99ae

Browse files
authored
re-index changed nodes only (#7651)
1 parent f7f1dff commit fff99ae

File tree

5 files changed

+7
-27
lines changed

5 files changed

+7
-27
lines changed

rules/DeadCode/Rector/Assign/RemoveDoubleAssignRector.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,22 @@ public function getNodeTypes(): array
5555
*/
5656
public function refactor(Node $node): ?Node
5757
{
58-
$stmts = $node->stmts;
59-
if ($stmts === null) {
58+
if ($node->stmts === null) {
6059
return null;
6160
}
6261

6362
$hasChanged = false;
6463

65-
foreach ($stmts as $key => $stmt) {
66-
if (! isset($stmts[$key + 1])) {
64+
foreach ($node->stmts as $key => $stmt) {
65+
if (! isset($node->stmts[$key + 1])) {
6766
continue;
6867
}
6968

7069
if (! $stmt instanceof Expression) {
7170
continue;
7271
}
7372

74-
$nextStmt = $stmts[$key + 1];
73+
$nextStmt = $node->stmts[$key + 1];
7574
if (! $nextStmt instanceof Expression) {
7675
continue;
7776
}

src/Application/NodeAttributeReIndexer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public static function reIndexStmtsKeys(Node $node): ?Node
3636
}
3737

3838
$node->stmts = array_values($node->stmts);
39+
3940
return $node;
4041
}
4142

src/DependencyInjection/LazyContainerFactory.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@
103103
use Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor\GlobalVariableNodeVisitor;
104104
use Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor\NameNodeVisitor;
105105
use Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor\StaticVariableNodeVisitor;
106-
use Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor\StmtKeyNodeVisitor;
107106
use Rector\NodeTypeResolver\PHPStan\Scope\PHPStanNodeScopeResolver;
108107
use Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocatorProvider\DynamicSourceLocatorProvider;
109108
use Rector\Php80\AttributeDecorator\DoctrineConverterAttributeDecorator;
@@ -243,7 +242,6 @@ final class LazyContainerFactory
243242
GlobalVariableNodeVisitor::class,
244243
NameNodeVisitor::class,
245244
StaticVariableNodeVisitor::class,
246-
StmtKeyNodeVisitor::class,
247245
];
248246

249247
/**

src/NodeTypeResolver/PHPStan/Scope/NodeVisitor/StmtKeyNodeVisitor.php

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/Rector/AbstractRector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,6 @@ final public function enterNode(Node $node): int|Node|null
139139
// ensure origNode pulled before refactor to avoid changed during refactor, ref https://3v4l.org/YMEGN
140140
$originalNode = $node->getAttribute(AttributeKey::ORIGINAL_NODE) ?? $node;
141141

142-
NodeAttributeReIndexer::reIndexNodeAttributes($node);
143-
144142
$refactoredNode = $this->refactor($node);
145143

146144
// nothing to change → continue
@@ -153,6 +151,8 @@ final public function enterNode(Node $node): int|Node|null
153151
throw new ShouldNotHappenException($errorMessage);
154152
}
155153

154+
NodeAttributeReIndexer::reIndexNodeAttributes($node);
155+
156156
$isIntRefactoredNode = is_int($refactoredNode);
157157

158158
/**

0 commit comments

Comments
 (0)