21
21
use Rector \ChangesReporting \ValueObject \RectorWithLineChange ;
22
22
use Rector \Core \Application \ChangedNodeScopeRefresher ;
23
23
use Rector \Core \Configuration \CurrentNodeProvider ;
24
+ use Rector \Core \Console \Output \RectorOutputStyle ;
24
25
use Rector \Core \Contract \Rector \PhpRectorInterface ;
25
26
use Rector \Core \Exception \ShouldNotHappenException ;
26
27
use Rector \Core \Exclusion \ExclusionManager ;
@@ -123,6 +124,8 @@ abstract class AbstractRector extends NodeVisitorAbstract implements PhpRectorIn
123
124
124
125
private UnreachableStmtAnalyzer $ unreachableStmtAnalyzer ;
125
126
127
+ private RectorOutputStyle $ rectorOutputStyle ;
128
+
126
129
#[Required]
127
130
public function autowire (
128
131
NodesToRemoveCollector $ nodesToRemoveCollector ,
@@ -145,7 +148,8 @@ public function autowire(
145
148
RectifiedAnalyzer $ rectifiedAnalyzer ,
146
149
CreatedByRuleDecorator $ createdByRuleDecorator ,
147
150
ChangedNodeScopeRefresher $ changedNodeScopeRefresher ,
148
- UnreachableStmtAnalyzer $ unreachableStmtAnalyzer
151
+ UnreachableStmtAnalyzer $ unreachableStmtAnalyzer ,
152
+ RectorOutputStyle $ rectorOutputStyle ,
149
153
): void {
150
154
$ this ->nodesToRemoveCollector = $ nodesToRemoveCollector ;
151
155
$ this ->nodesToAddCollector = $ nodesToAddCollector ;
@@ -168,6 +172,7 @@ public function autowire(
168
172
$ this ->createdByRuleDecorator = $ createdByRuleDecorator ;
169
173
$ this ->changedNodeScopeRefresher = $ changedNodeScopeRefresher ;
170
174
$ this ->unreachableStmtAnalyzer = $ unreachableStmtAnalyzer ;
175
+ $ this ->rectorOutputStyle = $ rectorOutputStyle ;
171
176
}
172
177
173
178
/**
@@ -216,6 +221,8 @@ final public function enterNode(Node $node)
216
221
217
222
$ originalAttributes = $ node ->getAttributes ();
218
223
224
+ $ this ->printDebugCurrentFileAndRule ();
225
+
219
226
$ node = $ this ->refactor ($ node );
220
227
221
228
// nothing to change → continue
@@ -435,4 +442,15 @@ private function connectParentNodes(Node $node): void
435
442
$ nodeTraverser ->addVisitor (new ParentConnectingVisitor ());
436
443
$ nodeTraverser ->traverse ([$ node ]);
437
444
}
445
+
446
+ private function printDebugCurrentFileAndRule (): void
447
+ {
448
+ if (! $ this ->rectorOutputStyle ->isDebug ()) {
449
+ return ;
450
+ }
451
+
452
+ $ this ->rectorOutputStyle ->writeln ('[file] ' . $ this ->file ->getRelativeFilePath ());
453
+ $ this ->rectorOutputStyle ->writeln ('[rule] ' . static ::class);
454
+ $ this ->rectorOutputStyle ->newLine (1 );
455
+ }
438
456
}
0 commit comments