|
10 | 10 | use PHPStan\Command\Symfony\SymfonyOutput;
|
11 | 11 | use PHPStan\Command\Symfony\SymfonyStyle;
|
12 | 12 | use PHPStan\DependencyInjection\Container;
|
| 13 | +use PHPStan\Diagnose\DiagnoseExtension; |
| 14 | +use PHPStan\Diagnose\PHPStanDiagnoseExtension; |
13 | 15 | use PHPStan\File\CouldNotWriteFileException;
|
14 | 16 | use PHPStan\File\FileReader;
|
15 | 17 | use PHPStan\File\FileWriter;
|
@@ -225,14 +227,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int
|
225 | 227 | try {
|
226 | 228 | [$files, $onlyFiles] = $inceptionResult->getFiles();
|
227 | 229 | } catch (PathNotFoundException $e) {
|
| 230 | + $this->runDiagnoseExtensions($container, $inceptionResult->getErrorOutput()); |
228 | 231 | $inceptionResult->getErrorOutput()->writeLineFormatted(sprintf('<error>%s</error>', $e->getMessage()));
|
229 | 232 | return 1;
|
230 | 233 | } catch (InceptionNotSuccessfulException) {
|
| 234 | + $this->runDiagnoseExtensions($container, $inceptionResult->getErrorOutput()); |
231 | 235 | return 1;
|
232 | 236 | }
|
233 | 237 |
|
234 | 238 | if (count($files) === 0) {
|
235 | 239 | $bleedingEdge = (bool) $container->getParameter('featureToggles')['zeroFiles'];
|
| 240 | + |
| 241 | + $this->runDiagnoseExtensions($container, $inceptionResult->getErrorOutput()); |
| 242 | + |
236 | 243 | if (!$bleedingEdge) {
|
237 | 244 | $inceptionResult->getErrorOutput()->getStyle()->note('No files found to analyse.');
|
238 | 245 | $inceptionResult->getErrorOutput()->getStyle()->warning('This will cause a non-zero exit code in PHPStan 2.0.');
|
@@ -422,6 +429,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
|
422 | 429 | }
|
423 | 430 |
|
424 | 431 | if ($generateBaselineFile !== null) {
|
| 432 | + $this->runDiagnoseExtensions($container, $inceptionResult->getErrorOutput()); |
425 | 433 | if (count($internalErrorsTuples) > 0) {
|
426 | 434 | foreach ($internalErrorsTuples as [$internalError]) {
|
427 | 435 | $inceptionResult->getStdOutput()->writeLineFormatted($internalError->getMessage());
|
@@ -459,6 +467,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
|
459 | 467 |
|
460 | 468 | $exitCode = $errorFormatter->formatErrors($analysisResult, $inceptionResult->getStdOutput());
|
461 | 469 |
|
| 470 | + $this->runDiagnoseExtensions($container, $inceptionResult->getErrorOutput()); |
| 471 | + |
462 | 472 | $errorOutput->writeLineFormatted('⚠️ Result is incomplete because of severe errors. ⚠️');
|
463 | 473 | $errorOutput->writeLineFormatted(' Fix these errors first and then re-run PHPStan');
|
464 | 474 | $errorOutput->writeLineFormatted(' to get all reported errors.');
|
@@ -525,6 +535,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
|
525 | 535 | }
|
526 | 536 | }
|
527 | 537 |
|
| 538 | + $this->runDiagnoseExtensions($container, $inceptionResult->getErrorOutput()); |
| 539 | + |
528 | 540 | return $inceptionResult->handleReturn(
|
529 | 541 | $exitCode,
|
530 | 542 | $analysisResult->getPeakMemoryUsageBytes(),
|
@@ -647,4 +659,22 @@ private function runFixer(InceptionResult $inceptionResult, Container $container
|
647 | 659 | );
|
648 | 660 | }
|
649 | 661 |
|
| 662 | + private function runDiagnoseExtensions(Container $container, Output $errorOutput): void |
| 663 | + { |
| 664 | + if (!$errorOutput->isDebug()) { |
| 665 | + return; |
| 666 | + } |
| 667 | + |
| 668 | + /** @var PHPStanDiagnoseExtension $phpstanDiagnoseExtension */ |
| 669 | + $phpstanDiagnoseExtension = $container->getService('phpstanDiagnoseExtension'); |
| 670 | + |
| 671 | + // not using tag for this extension to make sure it's always first |
| 672 | + $phpstanDiagnoseExtension->print($errorOutput); |
| 673 | + |
| 674 | + /** @var DiagnoseExtension $extension */ |
| 675 | + foreach ($container->getServicesByTag(DiagnoseExtension::EXTENSION_TAG) as $extension) { |
| 676 | + $extension->print($errorOutput); |
| 677 | + } |
| 678 | + } |
| 679 | + |
650 | 680 | }
|
0 commit comments