File tree Expand file tree Collapse file tree 1 file changed +9
-0
lines changed
Expand file tree Collapse file tree 1 file changed +9
-0
lines changed Original file line number Diff line number Diff line change 1818use PHPStan \Type \ObjectType ;
1919use PHPStan \Type \Type ;
2020use Rector \Application \ChangedNodeScopeRefresher ;
21+ use Rector \Application \NodeAttributeReIndexer ;
2122use Rector \Application \Provider \CurrentFileProvider ;
2223use Rector \BetterPhpDocParser \Comment \CommentsMerger ;
2324use 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
You can’t perform that action at this time.
0 commit comments