@@ -54,46 +54,46 @@ public function processFile(File $file, Configuration $configuration): FileProce
5454 $ fileHasChanged = false ;
5555 $ filePath = $ file ->getFilePath ();
5656
57- // 2. change nodes with Rectors
58- $ rectorWithLineChanges = null ;
59-
6057 do {
6158 $ file ->changeHasChanged (false );
6259
60+ // 1. change nodes with Rector Rules
6361 $ newStmts = $ this ->rectorNodeTraverser ->traverse ($ file ->getNewStmts ());
6462
65- // apply post rectors
63+ // 2. apply post rectors
6664 $ postNewStmts = $ this ->postFileProcessor ->traverse ($ newStmts , $ file );
6765
68- // this is needed for new tokens added in "afterTraverse()"
66+ // 3. this is needed for new tokens added in "afterTraverse()"
6967 $ file ->changeNewStmts ($ postNewStmts );
7068
71- // 3 . print to file or string
69+ // 4 . print to file or string
7270 // important to detect if file has changed
7371 $ this ->printFile ($ file , $ configuration , $ filePath );
7472
75- $ fileHasChangedInCurrentPass = $ file ->hasChanged ();
76-
77- if ($ fileHasChangedInCurrentPass ) {
78- $ file ->setFileDiff ($ this ->fileDiffFactory ->createTempFileDiff ($ file ));
79- $ rectorWithLineChanges = $ file ->getRectorWithLineChanges ();
80-
81- $ fileHasChanged = true ;
73+ // no change in current iteration, stop
74+ if (! $ file ->hasChanged ()) {
75+ break ;
8276 }
83- } while ($ fileHasChangedInCurrentPass );
77+
78+ $ fileHasChanged = true ;
79+ } while (true );
8480
8581 // 5. add as cacheable if not changed at all
8682 if (! $ fileHasChanged ) {
8783 $ this ->changedFilesDetector ->addCachableFile ($ filePath );
88- }
84+ } else {
85+ // when changed, set final status changed to true
86+ // to ensure it make sense to verify in next process when needed
87+ $ file ->changeHasChanged (true );
8988
90- if ($ configuration ->shouldShowDiffs () && $ rectorWithLineChanges !== null ) {
9189 $ currentFileDiff = $ this ->fileDiffFactory ->createFileDiffWithLineChanges (
90+ $ configuration ->shouldShowDiffs (),
9291 $ file ,
9392 $ file ->getOriginalFileContent (),
9493 $ file ->getFileContent (),
95- $ rectorWithLineChanges
94+ $ file -> getRectorWithLineChanges ()
9695 );
96+
9797 $ file ->setFileDiff ($ currentFileDiff );
9898 }
9999
0 commit comments