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

declare(strict_types=1);

use NunoMaduro\PhpInsights\Domain\Kernel;
use Symfony\Component\Console\Application;

if (!defined('T_MATCH')) {
    // Avoid conflict using php-codesniffer and php-cs-fixer together.
    // codesniffer register this constant with string, cs-fixer v3 expect it as int
    // @TODO: Drop when require PHP8.0+
    define('T_MATCH', 341);
}

(static function () {
    require file_exists(__DIR__ . '/../vendor/autoload.php')
        ? __DIR__ . '/../vendor/autoload.php'
        : __DIR__ . '/../../../../vendor/autoload.php';

    /*
     * Bootstraps the domain kernel.
     */
    Kernel::bootstrap();

    /**
     * Gets the list of commands.
     */
    $commands = require __DIR__ . '/../config/routes/console.php';

    /**
     * Creates a new console application, and runs it.
     */
    $application = new Application('PHP Insights', Kernel::VERSION);
    foreach ($application->all() as $command) {
        $command->setHidden(true);
    }

    $application->addCommands($commands);
    $application->setDefaultCommand('analyse');

    $application->run();
})();
