@@ -117,30 +117,6 @@ public final function enterNode(Node $node)
117117 $ originalNode = $ node ->getAttribute (AttributeKey::ORIGINAL_NODE ) ?? $ node ;
118118 NodeAttributeReIndexer::reIndexNodeAttributes ($ node );
119119 $ refactoredNode = $ this ->refactor ($ node );
120- // take it step by step
121- if ($ refactoredNode !== null && $ this ->kaizenStepper ->enabled ()) {
122- $ this ->kaizenStepper ->recordAppliedRule (static ::class);
123- }
124- // @see NodeTraverser::* codes, e.g. removal of node of stopping the traversing
125- if ($ refactoredNode === NodeVisitor::REMOVE_NODE ) {
126- // log here, so we can remove the node in leaveNode() method
127- $ this ->toBeRemovedNodeId = \spl_object_id ($ originalNode );
128- // notify this rule changing code
129- $ rectorWithLineChange = new RectorWithLineChange (static ::class, $ originalNode ->getStartLine ());
130- $ this ->file ->addRectorClassWithLine ($ rectorWithLineChange );
131- return $ originalNode ;
132- }
133- if (\is_int ($ refactoredNode )) {
134- $ this ->createdByRuleDecorator ->decorate ($ node , $ originalNode , static ::class);
135- if (!\in_array ($ refactoredNode , [NodeVisitor::DONT_TRAVERSE_CHILDREN , NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN ], \true)) {
136- // notify this rule changing code
137- $ rectorWithLineChange = new RectorWithLineChange (static ::class, $ originalNode ->getStartLine ());
138- $ this ->file ->addRectorClassWithLine ($ rectorWithLineChange );
139- return $ refactoredNode ;
140- }
141- $ this ->decorateCurrentAndChildren ($ node );
142- return null ;
143- }
144120 // nothing to change → continue
145121 if ($ refactoredNode === null ) {
146122 return null ;
@@ -149,6 +125,33 @@ public final function enterNode(Node $node)
149125 $ errorMessage = \sprintf (self ::EMPTY_NODE_ARRAY_MESSAGE , static ::class);
150126 throw new ShouldNotHappenException ($ errorMessage );
151127 }
128+ $ isIntRefactoredNode = \is_int ($ refactoredNode );
129+ /**
130+ * If below node and/or its children not traversed on current rule
131+ * early return null with decorate current and children node with skipped by "only" current rule
132+ */
133+ if ($ isIntRefactoredNode ) {
134+ $ this ->createdByRuleDecorator ->decorate ($ node , $ originalNode , static ::class);
135+ if (\in_array ($ refactoredNode , [NodeVisitor::DONT_TRAVERSE_CHILDREN , NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN ], \true)) {
136+ $ this ->decorateCurrentAndChildren ($ node );
137+ return null ;
138+ }
139+ }
140+ // take it step by step
141+ if ($ this ->kaizenStepper ->enabled ()) {
142+ $ this ->kaizenStepper ->recordAppliedRule (static ::class);
143+ }
144+ if ($ isIntRefactoredNode ) {
145+ // @see NodeTraverser::* codes, e.g. removal of node of stopping the traversing
146+ if ($ refactoredNode === NodeVisitor::REMOVE_NODE ) {
147+ // log here, so we can remove the node in leaveNode() method
148+ $ this ->toBeRemovedNodeId = \spl_object_id ($ originalNode );
149+ }
150+ // notify this rule changing code
151+ $ rectorWithLineChange = new RectorWithLineChange (static ::class, $ originalNode ->getStartLine ());
152+ $ this ->file ->addRectorClassWithLine ($ rectorWithLineChange );
153+ return $ refactoredNode === NodeVisitor::REMOVE_NODE ? $ originalNode : $ refactoredNode ;
154+ }
152155 return $ this ->postRefactorProcess ($ originalNode , $ node , $ refactoredNode , $ filePath );
153156 }
154157 /**
0 commit comments