Created
January 12, 2016 09:31
-
-
Save chalasr/56d52b3e92ffa6bb5ce3 to your computer and use it in GitHub Desktop.
Pre-commit hook that performs php-cs-fixer on each changed files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/php | |
| <?php | |
| exec('git diff --cached --name-status --diff-filter=ACM', $output); | |
| foreach ($output as $file) { | |
| $fileName = trim(substr($file, 1) ); | |
| if (pathinfo($fileName,PATHINFO_EXTENSION) == "php") { | |
| $lint_output = array(); | |
| exec("php -l " . escapeshellarg($fileName), $lint_output, $return); | |
| if ($return == 0) { | |
| exec("php php-cs-fixer.phar fix {$fileName} --config-file=.php_cs; git add {$fileName}"); | |
| echo $file.PHP_EOL; | |
| } else { | |
| echo implode("\n", $lint_output), "\n"; | |
| exit(1); | |
| } | |
| } | |
| } | |
| echo 'All source-code is clean'.PHP_EOL; | |
| exit(0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment