Jordan Savant // Software Engineer

#!/usr/bin/php
<?php
$error = 0;

# File Checks
exec('git diff --cached --name-status --diff-filter=ACM', $output);
foreach ($output as $line) {
    $action = trim($line[0]);
    $fileName = trim( substr($line, 1) );

    # PHP Syntax
    if(strpos($fileName, '.php') !== false)
    {
        checkSyntax($fileName);
    }
}

# Content checks

// Whitespace
#exec('git diff --cached --check', $output2);
#foreach($output2 as $line) {
#    echo $line."\n";
#    $error = 1;
#}

exit($error);

function checkSyntax($fileName)
{
    global $error;

    $op = array();
    exec('/usr/bin/php -l '.$fileName.' 2> /dev/null', $output, $failed);

    if (!$failed)
    {
        return;
    }

    echo "\033[31mSyntax error in $fileName: " . $output[1] . "\033[37m\n";

    $error = 1;
}