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

if (file_exists(__DIR__ . '/vendor/autoload.php')) {
    define('COMPOSER_BINARY_DIR', __DIR__ . "/vendor/bin/");
    require_once __DIR__ . '/vendor/autoload.php';
} elseif (file_exists(__DIR__ . '/../../autoload.php')) {
    define('COMPOSER_BINARY_DIR', __DIR__ . "/../../bin/");
    require_once __DIR__ . '/../../autoload.php';
}

/**
 * RoboFile is in phpqa repository, but analysis is runned in cwd.
 * Robo\Runner:loadRoboFile calls chdir when option --load-from=__DIR__
 */
class QARunner extends \Robo\Runner
{
    protected function loadRoboFile()
    {
        require_once __DIR__ . "/RoboFile.php";
        return true;
    }
}

// IO
$isNotToolsCommand = !(count($argv) >= 2 && $argv[1] == 'tools');
if ($isNotToolsCommand) {
    // add robo command between the application name and the arguments
    array_splice($argv, 1, 0, 'ci');
}

// run robo
$robo = new QARunner('Edge\QA\RoboFile');
$robo->execute($argv);
