From bdf954eb435c94fc65d042002afef50b1cf15df8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Unger?= Date: Fri, 29 Jun 2018 10:10:23 +0200 Subject: [PATCH] Better application exceptions --- bin/phpstan | 8 +------- src/Command/AnalyseCommand.php | 7 +++++++ 2 files changed, 8 insertions(+), 7 deletions(-) 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;