@@ -223,18 +223,31 @@ public function generateDiff($filePath=null)
223223 $ filePath = $ this ->_currentFile ->getFilename ();
224224 }
225225
226- $ cwd = getcwd ().DIRECTORY_SEPARATOR ;
227- $ filename = str_replace ($ cwd , '' , $ filePath );
228- $ fixedFile = $ cwd .'phpcs-fixed.tmp ' ;
229- $ contents = $ this ->getContents ();
226+ $ cwd = getcwd ().DIRECTORY_SEPARATOR ;
227+ $ filename = str_replace ($ cwd , '' , $ filePath );
228+ $ contents = $ this ->getContents ();
229+
230+ if (function_exists ('sys_get_temp_dir ' ) === true ) {
231+ // This is needed for HHVM support, but only available from 5.2.1.
232+ $ tempName = tempnam (sys_get_temp_dir (), 'phpcs-fixer ' );
233+ $ fixedFile = fopen ($ tempName , 'w ' );
234+ } else {
235+ $ fixedFile = tmpfile ();
236+ $ data = stream_get_meta_data ($ fixedFile );
237+ $ tempName = $ data ['uri ' ];
238+ }
230239
231- file_put_contents ($ fixedFile , $ contents );
240+ fwrite ($ fixedFile , $ contents );
232241
233242 // We must use something like shell_exec() because whitespace at the end
234243 // of lines is critical to diff files.
235- $ cmd = "diff -u -L \"$ filename \" -LPHP_CodeSniffer \"$ filename \" \"$ fixedFile \"" ;
244+ $ cmd = "diff -u -L \"$ filename \" -LPHP_CodeSniffer \"$ filename \" \"$ tempName \"" ;
236245 $ diff = shell_exec ($ cmd );
237- unlink ($ fixedFile );
246+
247+ fclose ($ fixedFile );
248+ if (is_file ($ tempName ) === true ) {
249+ unlink ($ tempName );
250+ }
238251
239252 return $ diff ;
240253
0 commit comments