@@ -85,10 +85,9 @@ protected function traverseNode(Node $node): void
8585 continue ;
8686 }
8787 $ traverseChildren = \true;
88- $ visitorIndex = -1 ;
8988 $ currentNodeVisitors = $ this ->getVisitorsForNode ($ subNode );
90- foreach ($ currentNodeVisitors as $ visitorIndex => $ visitor ) {
91- $ return = $ visitor ->enterNode ($ subNode );
89+ foreach ($ currentNodeVisitors as $ currentNodeVisitor ) {
90+ $ return = $ currentNodeVisitor ->enterNode ($ subNode );
9291 if ($ return !== null ) {
9392 if ($ return instanceof Node) {
9493 $ originalSubNodeClass = get_class ($ subNode );
@@ -121,27 +120,6 @@ protected function traverseNode(Node $node): void
121120 break ;
122121 }
123122 }
124- for (; $ visitorIndex >= 0 ; --$ visitorIndex ) {
125- $ visitor = $ currentNodeVisitors [$ visitorIndex ];
126- $ return = $ visitor ->leaveNode ($ subNode );
127- if ($ return !== null ) {
128- if ($ return instanceof Node) {
129- $ this ->ensureReplacementReasonable ($ subNode , $ return );
130- $ subNode = $ return ;
131- $ node ->{$ name } = $ return ;
132- } elseif ($ return === NodeVisitor::STOP_TRAVERSAL ) {
133- $ this ->stopTraversal = \true;
134- break 2 ;
135- } elseif ($ return === NodeVisitor::REPLACE_WITH_NULL ) {
136- $ node ->{$ name } = null ;
137- break ;
138- } elseif (\is_array ($ return )) {
139- throw new LogicException ('leaveNode() may only return an array if the parent structure is an array ' );
140- } else {
141- throw new LogicException ('leaveNode() returned invalid value of type ' . gettype ($ return ));
142- }
143- }
144- }
145123 }
146124 }
147125 /**
@@ -159,10 +137,9 @@ protected function traverseArray(array $nodes): array
159137 continue ;
160138 }
161139 $ traverseChildren = \true;
162- $ visitorIndex = -1 ;
163140 $ currentNodeVisitors = $ this ->getVisitorsForNode ($ node );
164- foreach ($ currentNodeVisitors as $ visitorIndex => $ visitor ) {
165- $ return = $ visitor ->enterNode ($ node );
141+ foreach ($ currentNodeVisitors as $ currentNodeVisitor ) {
142+ $ return = $ currentNodeVisitor ->enterNode ($ node );
166143 if ($ return !== null ) {
167144 if ($ return instanceof Node) {
168145 $ originalNodeNodeClass = get_class ($ node );
@@ -199,29 +176,6 @@ protected function traverseArray(array $nodes): array
199176 break ;
200177 }
201178 }
202- for (; $ visitorIndex >= 0 ; --$ visitorIndex ) {
203- $ visitor = $ currentNodeVisitors [$ visitorIndex ];
204- $ return = $ visitor ->leaveNode ($ node );
205- if ($ return !== null ) {
206- if ($ return instanceof Node) {
207- $ this ->ensureReplacementReasonable ($ node , $ return );
208- $ nodes [$ i ] = $ node = $ return ;
209- } elseif (\is_array ($ return )) {
210- $ doNodes [] = [$ i , $ return ];
211- break ;
212- } elseif ($ return === NodeVisitor::REMOVE_NODE ) {
213- $ doNodes [] = [$ i , []];
214- break ;
215- } elseif ($ return === NodeVisitor::STOP_TRAVERSAL ) {
216- $ this ->stopTraversal = \true;
217- break 2 ;
218- } elseif ($ return === NodeVisitor::REPLACE_WITH_NULL ) {
219- throw new LogicException ('REPLACE_WITH_NULL can not be used if the parent structure is an array ' );
220- } else {
221- throw new LogicException ('leaveNode() returned invalid value of type ' . gettype ($ return ));
222- }
223- }
224- }
225179 }
226180 if ($ doNodes !== []) {
227181 while ([$ i , $ replace ] = array_pop ($ doNodes )) {
0 commit comments