@@ -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 }
0 commit comments