Skip to content

Instantly share code, notes, and snippets.

@meotimdihia
Last active August 29, 2015 14:05
Show Gist options
  • Save meotimdihia/de3e1c3155e70b1fe7fc to your computer and use it in GitHub Desktop.
Save meotimdihia/de3e1c3155e70b1fe7fc to your computer and use it in GitHub Desktop.
Check error for php files.
#!/usr/bin/php
<?php
$output = array();
$return = 0;
exec('git rev-parse --verify HEAD 2> /dev/null', $output, $return);
exec("git diff-index --cached --name-only HEAD", $output);
exec("git diff-index --cached --name-only --diff-filter=D HEAD", $outputDels);
$filename_pattern = '/\.(php|ctp)$/';
$exit_status = 0;
foreach ($output as $file) {
if (!preg_match($filename_pattern, $file) || in_array($file, $outputDels)) {
// don't check files that aren't PHP
continue;
}
$lint_output = array();
exec("php -l " . escapeshellarg($file), $lint_output, $return);
if ($return == 0) {
continue;
}
echo implode("\n", $lint_output), "\n";
$exit_status = 1;
}
exit($exit_status);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment