@@ -58,37 +58,13 @@ public function supports(SplFileInfo $file) {
5858 }
5959
6060 /**
61- * {@inheritdoc}
62- */
63- private function applyFix (SplFileInfo $ file , Tokens $ tokens ) {
64- $ tmpFile = $ this ->getTmpFile ($ file );
65- exec ("yarn exec -- prettier --write $ tmpFile " );
66-
67- $ content = file_get_contents ($ tmpFile );
68- $ tokens ->setCode ($ content );
69-
70- (new Filesystem ())->remove ($ tmpFile );
71- }
72-
73- /**
74- * Create a Temp file with the same content as given file.
75- *
76- * @param SplFileInfo $file file to be copied
77- *
78- * @return string tmp file name
61+ * @param SplFileInfo $file
62+ * @param Tokens $tokens
7963 */
80- private function getTmpFile (SplFileInfo $ file ): string {
81- $ fileSys = new Filesystem ();
82- $ tmpFolderPath = __DIR__ .DIRECTORY_SEPARATOR .'tmp ' ;
83- $ fileSys ->mkdir ($ tmpFolderPath );
84-
85- $ tmpFileName = str_replace (
86- array (DIRECTORY_SEPARATOR , ': ' ),
87- '_ ' ,
88- $ file ->getRealPath ()
89- );
90- $ tmpFilePath = $ tmpFolderPath .DIRECTORY_SEPARATOR .'__ ' .$ tmpFileName ;
91- $ fileSys ->copy ($ file ->getRealPath (), $ tmpFilePath , true );
92- return $ tmpFilePath ;
64+ private function applyFix (SplFileInfo $ file , Tokens $ tokens ): void
65+ {
66+ exec ("yarn exec -- prettier $ file " , $ prettierOutput );
67+ $ code = implode (PHP_EOL , $ prettierOutput );
68+ $ tokens ->setCode ($ code );
9369 }
9470}
0 commit comments