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

$errorMessage = '';

if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 70103) {
    $errorMessage = 'PHP needs to be a minimum version of PHP 7.1.3';
} 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);
}

require_once $targetAutoload;

use Alfonsomthd\Phpcc\PhpccApplication;

if (!class_exists(PhpccApplication::class)) {
    $phpccAutoload = __DIR__.'/vendor/autoload.php';
    if (file_exists($phpccAutoload)) {
        $autoload = $phpccAutoload;
    } else {
        $autoload = __DIR__.'/../../autoload.php';
    }

    require_once $autoload;
}

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