@@ -99,11 +99,10 @@ protected function traverseNode(Node $node): void
9999 }
100100
101101 $ traverseChildren = true ;
102- $ visitorIndex = -1 ;
103102 $ currentNodeVisitors = $ this ->getVisitorsForNode ($ subNode );
104103
105- foreach ($ currentNodeVisitors as $ visitorIndex => $ visitor ) {
106- $ return = $ visitor ->enterNode ($ subNode );
104+ foreach ($ currentNodeVisitors as $ currentNodeVisitor ) {
105+ $ return = $ currentNodeVisitor ->enterNode ($ subNode );
107106 if ($ return !== null ) {
108107 if ($ return instanceof Node) {
109108 $ originalSubNodeClass = $ subNode ::class;
@@ -140,30 +139,6 @@ protected function traverseNode(Node $node): void
140139 break ;
141140 }
142141 }
143-
144- for (; $ visitorIndex >= 0 ; --$ visitorIndex ) {
145- $ visitor = $ currentNodeVisitors [$ visitorIndex ];
146- $ return = $ visitor ->leaveNode ($ subNode );
147- if ($ return !== null ) {
148- if ($ return instanceof Node) {
149- $ this ->ensureReplacementReasonable ($ subNode , $ return );
150- $ subNode = $ return ;
151- $ node ->{$ name } = $ return ;
152- } elseif ($ return === NodeVisitor::STOP_TRAVERSAL ) {
153- $ this ->stopTraversal = true ;
154- break 2 ;
155- } elseif ($ return === NodeVisitor::REPLACE_WITH_NULL ) {
156- $ node ->{$ name } = null ;
157- break ;
158- } elseif (\is_array ($ return )) {
159- throw new LogicException (
160- 'leaveNode() may only return an array if the parent structure is an array '
161- );
162- } else {
163- throw new LogicException ('leaveNode() returned invalid value of type ' . gettype ($ return ));
164- }
165- }
166- }
167142 }
168143 }
169144
@@ -184,11 +159,10 @@ protected function traverseArray(array $nodes): array
184159 }
185160
186161 $ traverseChildren = true ;
187- $ visitorIndex = -1 ;
188162 $ currentNodeVisitors = $ this ->getVisitorsForNode ($ node );
189163
190- foreach ($ currentNodeVisitors as $ visitorIndex => $ visitor ) {
191- $ return = $ visitor ->enterNode ($ node );
164+ foreach ($ currentNodeVisitors as $ currentNodeVisitor ) {
165+ $ return = $ currentNodeVisitor ->enterNode ($ node );
192166 if ($ return !== null ) {
193167 if ($ return instanceof Node) {
194168 $ originalNodeNodeClass = $ node ::class;
@@ -229,32 +203,6 @@ protected function traverseArray(array $nodes): array
229203 break ;
230204 }
231205 }
232-
233- for (; $ visitorIndex >= 0 ; --$ visitorIndex ) {
234- $ visitor = $ currentNodeVisitors [$ visitorIndex ];
235- $ return = $ visitor ->leaveNode ($ node );
236- if ($ return !== null ) {
237- if ($ return instanceof Node) {
238- $ this ->ensureReplacementReasonable ($ node , $ return );
239- $ nodes [$ i ] = $ node = $ return ;
240- } elseif (\is_array ($ return )) {
241- $ doNodes [] = [$ i , $ return ];
242- break ;
243- } elseif ($ return === NodeVisitor::REMOVE_NODE ) {
244- $ doNodes [] = [$ i , []];
245- break ;
246- } elseif ($ return === NodeVisitor::STOP_TRAVERSAL ) {
247- $ this ->stopTraversal = true ;
248- break 2 ;
249- } elseif ($ return === NodeVisitor::REPLACE_WITH_NULL ) {
250- throw new LogicException (
251- 'REPLACE_WITH_NULL can not be used if the parent structure is an array '
252- );
253- } else {
254- throw new LogicException ('leaveNode() returned invalid value of type ' . gettype ($ return ));
255- }
256- }
257- }
258206 }
259207
260208 if ($ doNodes !== []) {
0 commit comments