diff --git a/bin/phpstan b/bin/phpstan index 5d28872eac..b8b82cbefd 100755 --- a/bin/phpstan +++ b/bin/phpstan @@ -3,7 +3,6 @@ use Composer\XdebugHandler\XdebugHandler; use PHPStan\Command\AnalyseCommand; -use Symfony\Component\Console\Exception\CommandNotFoundException; gc_disable(); // performance boost @@ -36,10 +35,5 @@ $application = new \Symfony\Component\Console\Application( 'PHPStan - PHP Static Analysis Tool', $version ); -$application->setCatchExceptions(false); $application->add(new AnalyseCommand()); -try { - $application->run(); -} catch (CommandNotFoundException $exception) { - echo $exception->getMessage()."\n"; -} +$application->run(); diff --git a/src/Command/AnalyseCommand.php b/src/Command/AnalyseCommand.php index bf0629a277..2ce65e327f 100644 --- a/src/Command/AnalyseCommand.php +++ b/src/Command/AnalyseCommand.php @@ -47,6 +47,13 @@ public function getAliases(): array return ['analyze']; } + protected function initialize(InputInterface $input, OutputInterface $output): void + { + if ((bool) $input->getOption('debug')) { + $this->getApplication()->setCatchExceptions(false); + } + } + protected function execute(InputInterface $input, OutputInterface $output): int { $errOutput = $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output;