diff --git a/src/Command/AnalyseCommand.php b/src/Command/AnalyseCommand.php index dbcbc5d6d4..433492a2cc 100644 --- a/src/Command/AnalyseCommand.php +++ b/src/Command/AnalyseCommand.php @@ -7,9 +7,7 @@ use PHPStan\Analyser\ResultCache\ResultCacheClearer; use PHPStan\Command\ErrorFormatter\BaselineNeonErrorFormatter; use PHPStan\Command\ErrorFormatter\ErrorFormatter; -use PHPStan\Command\ErrorFormatter\GithubErrorFormatter; use PHPStan\Command\ErrorFormatter\TableErrorFormatter; -use PHPStan\Command\ErrorFormatter\TeamcityErrorFormatter; use PHPStan\Command\Symfony\SymfonyOutput; use PHPStan\Command\Symfony\SymfonyStyle; use PHPStan\File\CouldNotWriteFileException; @@ -185,6 +183,18 @@ protected function execute(InputInterface $input, OutputInterface $output): int if ($errorFormat === null) { $errorFormat = 'table'; + $ciDetector = new CiDetector(); + + try { + $ci = $ciDetector->detect(); + if ($ci->getCiName() === CiDetector::CI_GITHUB_ACTIONS) { + $errorFormat = 'github'; + } elseif ($ci->getCiName() === CiDetector::CI_TEAMCITY) { + $errorFormat = 'teamcity'; + } + } catch (CiNotDetectedException) { + // pass + } } $container = $inceptionResult->getContainer(); @@ -198,27 +208,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int return 1; } - /** @var ErrorFormatter $errorFormatter */ - $errorFormatter = $container->getService($errorFormatterServiceName); - - $ciDetector = new CiDetector(); - - try { - $ci = $ciDetector->detect(); - if ($ci->getCiName() === CiDetector::CI_GITHUB_ACTIONS) { - $errorFormatter = new GithubErrorFormatter( - $container->getService('simpleRelativePathHelper'), - $errorFormatter, - ); - } elseif ($ci->getCiName() === CiDetector::CI_TEAMCITY) { - $errorFormatter = new TeamcityErrorFormatter( - $container->getService('simpleRelativePathHelper'), - ); - } - } catch (CiNotDetectedException) { - // pass - } - $generateBaselineFile = $inceptionResult->getGenerateBaselineFile(); if ($generateBaselineFile !== null) { $baselineExtension = pathinfo($generateBaselineFile, PATHINFO_EXTENSION); @@ -444,6 +433,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int ); } + /** @var ErrorFormatter $errorFormatter */ + $errorFormatter = $container->getService($errorFormatterServiceName); + return $inceptionResult->handleReturn( $errorFormatter->formatErrors($analysisResult, $inceptionResult->getStdOutput()), );