#!/usr/bin/env php
<?php
$vendorPath = __DIR__."/../../..";
require($vendorPath."/autoload.php");

$path = getcwd();
$exit = 0;

$commitSHA = substr(`cd $path && git rev-parse HEAD`, 0, 8);

$finder = new Ayeo\Sniffer\ChangedFilesFinder($path);
$files = $finder->findAll($commitSHA);

$defaultStandardFile = __DIR__."/../ISystems_v3/ruleset.xml";
$paramRecognizer = new \Ayeo\Sniffer\ParamRecognizer($argv);
$standardFile = $paramRecognizer->getStandardFilePath();
if (null === $standardFile)
{
    $standardFile = $defaultStandardFile;
}
$sniffer = new \Ayeo\Sniffer\Sniffer($standardFile, $vendorPath);

/* @var $file \Ayeo\Sniffer\File */
foreach ($files as $file) {
    $report = $sniffer->getReport($file);
    echo sprintf("\nFile: %s\n", $file->getFileFullPath());

    /* @var $row \Ayeo\Sniffer\ReportRow */
    foreach ($report as $row) {
        if ($file->isChanged($row->getLineNumber())) {
			echo sprintf("| %s | %s\t| %s\n", $row->getLineNumber(), $row->getType(), $row->getMessage());
			$exit = 1;
        }
    }
}

exit($exit);