Skip to content

Commit bdf954e

Browse files
lookymanondrejmirtes
authored andcommitted
Better application exceptions
1 parent 8264094 commit bdf954e

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

bin/phpstan

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
use Composer\XdebugHandler\XdebugHandler;
55
use PHPStan\Command\AnalyseCommand;
6-
use Symfony\Component\Console\Exception\CommandNotFoundException;
76

87
gc_disable(); // performance boost
98

@@ -36,10 +35,5 @@ $application = new \Symfony\Component\Console\Application(
3635
'PHPStan - PHP Static Analysis Tool',
3736
$version
3837
);
39-
$application->setCatchExceptions(false);
4038
$application->add(new AnalyseCommand());
41-
try {
42-
$application->run();
43-
} catch (CommandNotFoundException $exception) {
44-
echo $exception->getMessage()."\n";
45-
}
39+
$application->run();

src/Command/AnalyseCommand.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ public function getAliases(): array
4747
return ['analyze'];
4848
}
4949

50+
protected function initialize(InputInterface $input, OutputInterface $output): void
51+
{
52+
if ((bool) $input->getOption('debug')) {
53+
$this->getApplication()->setCatchExceptions(false);
54+
}
55+
}
56+
5057
protected function execute(InputInterface $input, OutputInterface $output): int
5158
{
5259
$errOutput = $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output;

0 commit comments

Comments
 (0)