PHPStan\Command\AnalyseCommand::execute PHP Method

execute() protected method

protected execute ( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output ) : integer
$input Symfony\Component\Console\Input\InputInterface
$output Symfony\Component\Console\Output\OutputInterface
return integer
    protected function execute(InputInterface $input, OutputInterface $output) : int
    {
        $rootDir = realpath(__DIR__ . '/../..');
        $tmpDir = $rootDir . '/tmp';
        $confDir = $rootDir . '/conf';
        $configurator = new Configurator();
        $configurator->defaultExtensions = [];
        $configurator->setDebugMode(true);
        $configurator->setTempDirectory($tmpDir);
        $projectConfigFile = $input->getOption('configuration');
        $levelOption = $input->getOption(self::OPTION_LEVEL);
        $defaultLevelUsed = false;
        if ($projectConfigFile === null && $levelOption === null) {
            $levelOption = self::DEFAULT_LEVEL;
            $defaultLevelUsed = true;
        }
        $configFiles = [$confDir . '/config.neon'];
        if ($levelOption !== null) {
            $levelConfigFile = sprintf('%s/config.level%s.neon', $confDir, $levelOption);
            if (!is_file($levelConfigFile)) {
                $output->writeln(sprintf('Level config file %s was not found.', $levelConfigFile));
                return 1;
            }
            $configFiles[] = $levelConfigFile;
        }
        if ($projectConfigFile !== null) {
            $projectConfigRealFilePath = realpath($projectConfigFile);
            if (!is_file($projectConfigFile)) {
                $output->writeln(sprintf('Project config file at path %s does not exist.', $projectConfigRealFilePath !== false ? $projectConfigRealFilePath : $projectConfigFile));
                return 1;
            }
            $configFiles[] = $projectConfigRealFilePath;
        }
        foreach ($configFiles as $configFile) {
            $configurator->addConfig($configFile);
        }
        $configurator->addParameters(['rootDir' => $rootDir, 'tmpDir' => $tmpDir]);
        $container = $configurator->createContainer();
        $consoleStyle = new ErrorsConsoleStyle($input, $output);
        $memoryLimitFile = $container->parameters['memoryLimitFile'];
        if (file_exists($memoryLimitFile)) {
            $consoleStyle->note(sprintf("PHPStan crashed in the previous run probably because of excessive memory consumption.\nIt consumed around %s of memory.\n\nTo avoid this issue, increase the memory_limit directive in your php.ini file here:\n%s\n\nIf you can't or don't want to change the system-wide memory limit, run PHPStan like this:\n%s", file_get_contents($memoryLimitFile), php_ini_loaded_file(), sprintf('php -d memory_limit=XX %s', implode(' ', $_SERVER['argv']))));
            unlink($memoryLimitFile);
        }
        if (PHP_VERSION_ID >= 70100 && !property_exists(Catch_::class, 'types')) {
            $consoleStyle->note('You\'re running PHP >= 7.1, but you still have PHP-Parser version 2.x. This will lead to parse errors in case you use PHP 7.1 syntax like nullable parameters, iterable and void typehints, union exception types, or class constant visibility. Update to PHP-Parser 3.x to dismiss this message.');
        }
        $this->setUpSignalHandler($consoleStyle, $memoryLimitFile);
        if (!isset($container->parameters['customRulesetUsed'])) {
            $output->writeln('');
            $output->writeln('<comment>No rules detected</comment>');
            $output->writeln('');
            $output->writeln('You have the following choices:');
            $output->writeln('');
            $output->writeln('* while running the analyse option, use the <info>--level</info> option to adjust your rule level - the higher the stricter');
            $output->writeln('');
            $output->writeln(sprintf('* create your own <info>custom ruleset</info> by selecting which rules you want to check by copying the service definitions from the built-in config level files in <options=bold>%s</>.', realpath(__DIR__ . '/../../conf')));
            $output->writeln('  * in this case, don\'t forget to define parameter <options=bold>customRulesetUsed</> in your config file.');
            $output->writeln('');
            return $this->handleReturn(1, $memoryLimitFile);
        } elseif ($container->parameters['customRulesetUsed']) {
            $defaultLevelUsed = false;
        }
        foreach ($container->parameters['autoload_files'] as $autoloadFile) {
            require_once $autoloadFile;
        }
        if (count($container->parameters['autoload_directories']) > 0) {
            $robotLoader = new \Nette\Loaders\RobotLoader();
            $robotLoader->setCacheStorage(new \Nette\Caching\Storages\MemoryStorage());
            foreach ($container->parameters['autoload_directories'] as $directory) {
                $robotLoader->addDirectory($directory);
            }
            $robotLoader->register();
        }
        $application = $container->getByType(AnalyseApplication::class);
        return $this->handleReturn($application->analyse($input->getArgument('paths'), $consoleStyle, $defaultLevelUsed), $memoryLimitFile);
    }