#!/usr/bin/env php
<?php
chdir(__DIR__);

$returnStatus = null;
passthru('composer install', $returnStatus);
if ($returnStatus !== 0) {
    exit(1);
}

passthru('./vendor/bin/phpcs --standard=' . __DIR__ . '/vendor/dominionenterprises/dws-coding-standard/DWS -n src tests *.php', $returnStatus);
if ($returnStatus !== 0) {
    exit(1);
}

passthru('vendor/bin/phpunit --coverage-html coverage --coverage-clover clover.xml', $returnStatus);
if ($returnStatus !== 0) {
    exit(1);
}

$xml = new SimpleXMLElement(file_get_contents('clover.xml'));
foreach ($xml->xpath('//file/metrics') as $metric) {
    if ((int)$metric['elements'] !== (int)$metric['coveredelements']) {
        file_put_contents('php://stderr', "Code coverage was NOT 100%\n");
        exit(1);
    }
}

echo "Code coverage was 100%\n";

#!/usr/bin/env php
<?php
chdir(__DIR__);

$returnStatus = null;
passthru('composer install', $returnStatus);
if ($returnStatus !== 0) {
    exit(1);
}

require 'vendor/autoload.php';

$phpcsCLI = new PHP_CodeSniffer_CLI();
$phpcsArguments = array(
    'standard' => array(__DIR__ . '/vendor/dominionenterprises/dws-coding-standard/DWS'),
    'files' => array('src', 'tests', 'build.php'),
    'warningSeverity' => 0,
);
$phpcsViolations = $phpcsCLI->process($phpcsArguments);
if ($phpcsViolations > 0) {
    exit(1);
}

passthru('vendor/bin/phpunit --coverage-html coverage --coverage-clover clover.xml', $returnStatus);
if ($returnStatus !== 0) {
    exit(1);
}

$xml = new SimpleXMLElement(file_get_contents('clover.xml'));
foreach ($xml->xpath('//file/metrics') as $metric) {
    if ((int)$metric['elements'] !== (int)$metric['coveredelements']) {
        file_put_contents('php://stderr', "Code coverage was NOT 100%\n");
        exit(1);
    }
}

echo "Code coverage was 100%\n";

Use phpcs as a library.
Use phpcs as a library.

Rather than executing phpcs via passthru, pull it in as a library.  This
enables more programmatic access to it.
