#!/usr/bin/env php
<?php

$errorMessage = '';

if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 50600) {
    $errorMessage = 'PHP needs to be a minimum version of PHP 5.6.*';
} elseif (!getcwd()) {
    $errorMessage = 'this directory or one of its parent directories does not have the readable or search mode set.';
}

$targetAutoload = getcwd().'/vendor/autoload.php';

if (!file_exists($targetAutoload)) {
    $errorMessage = <<<'EOT'
composer's vendor/autoload.php not found.

Have you run "composer install"?

This tool must be run in your project's root directory
(the directory that contains your project's composer.json)

EOT;
}

if ('' !== $errorMessage) {
    fwrite(STDERR, 'Error: '.$errorMessage."\n");
    exit(1);
}

$autoload = $targetAutoload;
$phpccComposerPackageAutoload = __DIR__.'/../../autoload.php';
if (file_exists($phpccComposerPackageAutoload)) {
    $autoload = $phpccComposerPackageAutoload;
}

require_once $autoload;

use Alfonsomthd\Phpcc\PhpccApplication;

$application = new PhpccApplication();
$application->run();
