@@ -140,27 +140,14 @@ private function parseFileAndDecorateNodes(File $file): ?SystemError
140140 private function printFile (File $ file , Configuration $ configuration , string $ filePath ): void
141141 {
142142 // only save to string first, no need to print to file when not needed
143- $ newStmts = $ file ->getNewStmts ();
144-
145- $ oldStmts = $ file ->getOldStmts ();
146-
147- // unwrap FileNode stmts to allow printing
148- if ($ newStmts [0 ] instanceof FileNode) {
149- $ newStmts = $ newStmts [0 ]->stmts ;
150- }
151-
152- if ($ oldStmts [0 ] instanceof FileNode) {
153- $ oldStmts = $ oldStmts [0 ]->stmts ;
154- }
155-
156- $ newContent = $ this ->betterStandardPrinter ->printFormatPreserving (
157- $ newStmts ,
158- $ oldStmts ,
143+ $ newFileContent = $ this ->betterStandardPrinter ->printFormatPreserving (
144+ $ file ->getNewStmts (),
145+ $ file ->getOldStmts (),
159146 $ file ->getOldTokens ()
160147 );
161148
162149 // change file content early to make $file->hasChanged() based on new content
163- $ file ->changeFileContent ($ newContent );
150+ $ file ->changeFileContent ($ newFileContent );
164151 if ($ configuration ->isDryRun ()) {
165152 return ;
166153 }
@@ -169,7 +156,7 @@ private function printFile(File $file, Configuration $configuration, string $fil
169156 return ;
170157 }
171158
172- FileSystem::write ($ filePath , $ newContent , null );
159+ FileSystem::write ($ filePath , $ newFileContent , null );
173160 }
174161
175162 private function parseFileNodes (File $ file , bool $ forNewestSupportedVersion = true ): void
@@ -184,6 +171,7 @@ private function parseFileNodes(File $file, bool $forNewestSupportedVersion = tr
184171
185172 // wrap in FileNode to allow file-level rules
186173 $ oldStmts = [new FileNode ($ oldStmts )];
174+
187175 $ oldTokens = $ stmtsAndTokens ->getTokens ();
188176
189177 $ newStmts = $ this ->nodeScopeAndMetadataDecorator ->decorateNodesFromFile ($ file ->getFilePath (), $ oldStmts );
0 commit comments