@@ -56,65 +56,73 @@ public function processFile(File $file, Configuration $configuration): FileProce
5656 return new FileProcessResult ([$ parsingSystemError ], null , false );
5757 }
5858
59- $ fileHasChanged = false ;
59+ // $fileHasChanged = false;
6060 $ filePath = $ file ->getFilePath ();
6161
62- do {
63- $ file ->changeHasChanged (false );
62+ // do {
63+ // $file->changeHasChanged(false);
6464
65- // every rule and post rector records a line change when it mutates the AST
66- $ changeCountBeforePass = count ($ file ->getRectorWithLineChanges ());
65+ // every rule and post rector records a line change when it mutates the AST
66+ // $changeCountBeforePass = count($file->getRectorWithLineChanges());
6767
68- // 1. change nodes with Rector Rules
69- $ newStmts = $ this ->rectorNodeTraverser ->traverse ($ file ->getNewStmts (), $ file );
68+ // 1. change nodes with Rector Rules
69+ $ newStmts = $ this ->rectorNodeTraverser ->traverse ($ file ->getNewStmts (), $ file );
7070
71- // 2. apply post rectors
72- $ postNewStmts = $ this ->postFileProcessor ->traverse ($ newStmts , $ file );
71+ // 2. apply post rectors
72+ $ postNewStmts = $ this ->postFileProcessor ->traverse ($ newStmts , $ file );
7373
74- // 3. this is needed for new tokens added in "afterTraverse()"
75- $ file ->changeNewStmts ($ postNewStmts );
74+ // 3. this is needed for new tokens added in "afterTraverse()"
75+ $ file ->changeNewStmts ($ postNewStmts );
7676
77- // file never changed and this pass changed nothing: the print would just reproduce the
78- // original content, so skip the expensive format-preserving print entirely.
79- // once the file has changed we keep printing every pass, as a reprint can still
80- // stabilize the output (e.g. drop a leftover trailing comma)
81- if (! $ fileHasChanged && count ($ file ->getRectorWithLineChanges ()) === $ changeCountBeforePass ) {
82- break ;
83- }
84-
85- // 4. print to file or string
86- // important to detect if file has changed
87- $ this ->printFile ($ file , $ configuration , $ filePath );
77+ // file never changed and this pass changed nothing: the print would just reproduce the
78+ // original content, so skip the expensive format-preserving print entirely.
79+ // once the file has changed we keep printing every pass, as a reprint can still
80+ // stabilize the output (e.g. drop a leftover trailing comma)
81+ // if (! $fileHasChanged && count($file->getRectorWithLineChanges()) === $changeCountBeforePass) {
82+ // break;
83+ // }
8884
89- // no change in current iteration, stop
90- if (! $ file ->hasChanged ()) {
91- break ;
92- }
85+ // if (! $file->hasChanged()) {
86+ // continue;
9387
94- $ fileHasChanged = true ;
95- } while (true );
88+ // 4. print to file or string
89+ // important to detect if file has changed
90+ // $this->printFile($file, $configuration, $filePath);
9691
97- // 5. add as cacheable if not changed at all
98- if (! $ fileHasChanged ) {
92+ // no change in current iteration, stop
93+ if (! $ file -> hasChanged () ) {
9994 $ this ->changedFilesDetector ->addCacheableFile ($ filePath );
95+ return new FileProcessResult ([], $ file ->getFileDiff (), $ file ->hasChanged ());
96+
97+ // break;
10098 } else {
101- // when changed, set final status changed to true
102- // to ensure it make sense to verify in next process when needed
103- $ file ->changeHasChanged (true );
99+ $ this ->printFile ($ file , $ configuration , $ filePath );
104100 }
105101
102+ // $fileHasChanged = true;
103+ // } while (true);
104+
105+ // 5. add as cacheable if not changed at all
106+ // if (! $fileHasChanged) {
107+ // $this->changedFilesDetector->addCacheableFile($filePath);
108+ // } else {
109+ // // when changed, set final status changed to true
110+ // // to ensure it make sense to verify in next process when needed
111+ // $file->changeHasChanged(true);
112+ // }
113+
106114 $ rectorWithLineChanges = $ file ->getRectorWithLineChanges ();
107- if ($ file ->hasChanged () || $ rectorWithLineChanges !== []) {
108- $ currentFileDiff = $ this ->fileDiffFactory ->createFileDiffWithLineChanges (
109- $ configuration ->shouldShowDiffs (),
110- $ file ,
111- $ file ->getOriginalFileContent (),
112- $ file ->getFileContent (),
113- $ file ->getRectorWithLineChanges ()
114- );
115-
116- $ file ->setFileDiff ($ currentFileDiff );
117- }
115+ // if ($file->hasChanged() || $rectorWithLineChanges !== []) {
116+ $ currentFileDiff = $ this ->fileDiffFactory ->createFileDiffWithLineChanges (
117+ $ configuration ->shouldShowDiffs (),
118+ $ file ,
119+ $ file ->getOriginalFileContent (),
120+ $ file ->getFileContent (),
121+ $ file ->getRectorWithLineChanges ()
122+ );
123+
124+ $ file ->setFileDiff ($ currentFileDiff );
125+ // }
118126
119127 return new FileProcessResult ([], $ file ->getFileDiff (), $ file ->hasChanged ());
120128 }
0 commit comments