Last active
August 29, 2015 14:16
-
-
Save iolloyd/235e5876cbfca2e15072 to your computer and use it in GitHub Desktop.
php syntax checker before commiting to git
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/env php | |
<?php | |
exec ('git diff --cached --name-status --diff-filter=ACM', $files); | |
// remove the character before the fileName | |
$files = array_map(function($x) {return trim(substr($x, 1)); }, $files); | |
// we only want the php files | |
$phps = array_filter($files, function($x) {return "php" == pathinfo($x, PATHINFO_EXTENSION);}); | |
foreach ($phps as $file) { | |
$lint = []; | |
exec("php -l " . escapeshellarg($file), $lint, $return); | |
if (!$return) { continue; } | |
echo implode("\n", $lint), "\n"; | |
exit(1); | |
} | |
exit(0); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
chmod +x .git/hooks/pre-commit