Skip to content

Commit 2cb2f07

Browse files
authored
Added --fail-without-result-cache CLI option
1 parent a44f10c commit 2cb2f07

4 files changed

Lines changed: 17 additions & 119 deletions

File tree

‎conf/config.neon‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1955,9 +1955,6 @@ services:
19551955
editorUrl: %editorUrl%
19561956
editorUrlTitle: %editorUrlTitle%
19571957

1958-
errorFormatter.failWithoutResultCache:
1959-
class: PHPStan\Command\ErrorFormatter\FailWithoutResultCacheErrorFormatter
1960-
19611958
errorFormatter.checkstyle:
19621959
class: PHPStan\Command\ErrorFormatter\CheckstyleErrorFormatter
19631960
arguments:

‎src/Command/AnalyseCommand.php‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ protected function configure(): void
8787
new InputOption('fix', null, InputOption::VALUE_NONE, 'Launch PHPStan Pro'),
8888
new InputOption('watch', null, InputOption::VALUE_NONE, 'Launch PHPStan Pro'),
8989
new InputOption('pro', null, InputOption::VALUE_NONE, 'Launch PHPStan Pro'),
90+
new InputOption('fail-without-result-cache', null, InputOption::VALUE_NONE, 'Return non-zero exit code when result cache is not used'),
9091
]);
9192
}
9293

@@ -120,6 +121,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
120121
$allowXdebug = $input->getOption('xdebug');
121122
$debugEnabled = (bool) $input->getOption('debug');
122123
$fix = (bool) $input->getOption('fix') || (bool) $input->getOption('watch') || (bool) $input->getOption('pro');
124+
$failWithoutResultCache = (bool) $input->getOption('fail-without-result-cache');
123125

124126
/** @var string|false|null $generateBaselineFile */
125127
$generateBaselineFile = $input->getOption('generate-baseline');
@@ -393,7 +395,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int
393395
$inceptionResult->getStdOutput()->getStyle()->warning($message . "\nSome errors could not be put into baseline. Re-run PHPStan and fix them.");
394396
}
395397

396-
return $inceptionResult->handleReturn(0, $analysisResult->getPeakMemoryUsageBytes());
398+
$exitCode = 0;
399+
if ($failWithoutResultCache && !$analysisResult->isResultCacheUsed()) {
400+
$exitCode = 2;
401+
}
402+
403+
return $inceptionResult->handleReturn(
404+
$exitCode,
405+
$analysisResult->getPeakMemoryUsageBytes(),
406+
);
397407
}
398408

399409
if ($fix) {
@@ -486,8 +496,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
486496
/** @var ErrorFormatter $errorFormatter */
487497
$errorFormatter = $container->getService($errorFormatterServiceName);
488498

499+
$exitCode = $errorFormatter->formatErrors($analysisResult, $inceptionResult->getStdOutput());
500+
if ($failWithoutResultCache && !$analysisResult->isResultCacheUsed()) {
501+
$exitCode = 2;
502+
}
503+
489504
return $inceptionResult->handleReturn(
490-
$errorFormatter->formatErrors($analysisResult, $inceptionResult->getStdOutput()),
505+
$exitCode,
491506
$analysisResult->getPeakMemoryUsageBytes(),
492507
);
493508
}

‎src/Command/ErrorFormatter/FailWithoutResultCacheErrorFormatter.php‎

Lines changed: 0 additions & 26 deletions
This file was deleted.

‎tests/PHPStan/Command/ErrorFormatter/FailWithoutResultCacheErrorFormatterTest.php‎

Lines changed: 0 additions & 88 deletions
This file was deleted.

0 commit comments

Comments
 (0)