$aChunk) { $iChunkNumber = $iIdx + 1; $sChunkFilesAsArgs = implode(' ', array_map('escapeshellarg', $aChunk)); $sPhpCsFixerCmd = escapeshellcmd(PHP_BINARY) .' '.escapeshellarg($sPhpCsFixerBinaryAbsPath) .' fix --using-cache=no --config='.escapeshellarg($sPhpCsFixerConfigFileAbsPath) .' --verbose '.$sChunkFilesAsArgs; echo "Executing chunk {$iChunkNumber}/{$iNbChunks} : {$sPhpCsFixerCmd}\n\n"; passthru($sPhpCsFixerCmd, $iExitCode); if ($iExitCode !== 0) { echo "Failed to fix chunk #{$iChunkNumber} Aborting.\n"; exit($iExitCode); } } // Find which files have been fixed and re-stage them $sFixedFilesCmd = 'git diff --name-only --diff-filter=M'; exec($sFixedFilesCmd, $aFixedFiles); $aFixedFilesToRestage = array_intersect($aFixedFiles, $aStagedFiles); // Re-stage fixed files to include them in the commit if (count($aFixedFilesToRestage) === 0) { echo "No file needed PHP code style fixing, it was already ok.\n"; exit(0); } echo "Re-staging fixed files:\n"; foreach ($aFixedFilesToRestage as $sFixedFileToRestage) { $sGitAddCmd = 'git add '.escapeshellarg($sFixedFileToRestage); echo " - {$sFixedFileToRestage}\n"; passthru($sGitAddCmd, $iRetCode); if ($iRetCode !== 0) { echo " Failed to re-stage fixed file '{$sFixedFileToRestage}'. Continuing anyway.\n"; } } echo "All done, file(s) PHP code style fixed and added to commit.\n"; exit($iExitCode);