#!/usr/bin/env php
<?php declare(strict_types=1);

use Composer\XdebugHandler\XdebugHandler;
use PHPStan\Command\AnalyseCommand;
use PHPStan\Command\DumpDependenciesCommand;

gc_disable(); // performance boost

define('__PHPSTAN_RUNNING__', true);

$autoloaderInWorkingDirectory = getcwd() . '/vendor/autoload.php';
if (is_file($autoloaderInWorkingDirectory)) {
	require_once $autoloaderInWorkingDirectory;
}

$composerAutoloadFile = __DIR__ . '/../vendor/autoload.php';
if (!is_file($composerAutoloadFile)) {
	$composerAutoloadFile = __DIR__ . '/../../../autoload.php';
}

require_once $composerAutoloadFile;

$xdebug = new XdebugHandler('phpstan', '--ansi');
$xdebug->check();
unset($xdebug);

$version = 'Version unknown';
try {
	$version = \Jean85\PrettyVersions::getVersion('phpstan/phpstan')->getPrettyVersion();
} catch (\OutOfBoundsException $e) {

}

$application = new \Symfony\Component\Console\Application(
	'PHPStan - PHP Static Analysis Tool',
	$version
);
$application->add(new AnalyseCommand());
$application->add(new DumpDependenciesCommand());
$application->run();
