File tree Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -130,11 +130,13 @@ public function transform(
130130 /** @var Stmt[] $newStmts */
131131 $ newStmts = $ traverser ->traverse ($ newStmts );
132132
133- $ printer = new PhpPrinter (['indent ' => str_repeat ($ indentDetector ->indentCharacter , $ indentDetector ->indentSize )]);
134- $ newCode = $ printer ->printFormatPreserving ($ newStmts , $ fileNodes , $ oldTokens );
133+ if ($ visitor ->isFound ()) {
134+ $ printer = new PhpPrinter (['indent ' => str_repeat ($ indentDetector ->indentCharacter , $ indentDetector ->indentSize )]);
135+ $ newCode = $ printer ->printFormatPreserving ($ newStmts , $ fileNodes , $ oldTokens );
135136
136- if ($ oldCode !== $ newCode ) {
137- $ fixedErrorDiff = new FixedErrorDiff ($ hash , $ this ->differ ->diff ($ oldCode , $ newCode ));
137+ if ($ oldCode !== $ newCode ) {
138+ $ fixedErrorDiff = new FixedErrorDiff ($ hash , $ this ->differ ->diff ($ oldCode , $ newCode ));
139+ }
138140 }
139141 }
140142
Original file line number Diff line number Diff line change 1010final class ReplacingNodeVisitor extends NodeVisitorAbstract
1111{
1212
13+ private bool $ found = false ;
14+
1315 /**
1416 * @param callable(Node): Node $newNodeCallable
1517 */
@@ -24,6 +26,8 @@ public function enterNode(Node $node): ?Node
2426 return null ;
2527 }
2628
29+ $ this ->found = true ;
30+
2731 $ callable = $ this ->newNodeCallable ;
2832 $ newNode = $ callable ($ node );
2933 if ($ newNode instanceof VirtualNode) {
@@ -33,4 +37,9 @@ public function enterNode(Node $node): ?Node
3337 return $ newNode ;
3438 }
3539
40+ public function isFound (): bool
41+ {
42+ return $ this ->found ;
43+ }
44+
3645}
You can’t perform that action at this time.
0 commit comments