Skip to content

Commit 6fa2549

Browse files
committed
fix
1 parent 0b54a31 commit 6fa2549

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/Rector/AbstractRector.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use PHPStan\Type\ObjectType;
1919
use PHPStan\Type\Type;
2020
use Rector\Application\ChangedNodeScopeRefresher;
21+
use Rector\Application\NodeAttributeReIndexer;
2122
use Rector\Application\Provider\CurrentFileProvider;
2223
use Rector\BetterPhpDocParser\Comment\CommentsMerger;
2324
use Rector\ChangesReporting\ValueObject\RectorWithLineChange;
@@ -136,6 +137,14 @@ final public function enterNode(Node $node): int|Node|null|array
136137
// ensure origNode pulled before refactor to avoid changed during refactor, ref https://3v4l.org/YMEGN
137138
$originalNode = $node->getAttribute(AttributeKey::ORIGINAL_NODE) ?? $node;
138139

140+
// this reindex is needed as when multiple rules apply
141+
// the existing node position can already be removed/moved by different rule from "parent" node
142+
//
143+
// that modify/remove deep node, for example:
144+
// - first rule: - Class_ → ClassMethod → remove index 0
145+
// - second rule: - ClassMethod → here fetch the index 0 no longer exists
146+
NodeAttributeReIndexer::reIndexNodeAttributes($node);
147+
139148
$refactoredNodeOrState = $this->refactor($node);
140149

141150
// nothing to change → continue

0 commit comments

Comments
 (0)