@@ -55,6 +55,7 @@ protected function configure(): void
55
55
new InputOption ('autoload-file ' , 'a ' , InputOption::VALUE_REQUIRED , 'Project \'s additional autoload file path ' ),
56
56
new InputOption ('error-format ' , null , InputOption::VALUE_REQUIRED , 'Format in which to print the result of the analysis ' , null ),
57
57
new InputOption ('generate-baseline ' , null , InputOption::VALUE_OPTIONAL , 'Path to a file where the baseline should be saved ' , false ),
58
+ new InputOption ('allow-empty-baseline ' , null , InputOption::VALUE_NONE , 'Do not error out when the generated baseline is empty ' ),
58
59
new InputOption ('memory-limit ' , null , InputOption::VALUE_REQUIRED , 'Memory limit for analysis ' ),
59
60
new InputOption ('xdebug ' , null , InputOption::VALUE_NONE , 'Allow running with XDebug for debugging purposes ' ),
60
61
new InputOption ('fix ' , null , InputOption::VALUE_NONE , 'Launch PHPStan Pro ' ),
@@ -102,6 +103,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
102
103
$ generateBaselineFile = 'phpstan-baseline.neon ' ;
103
104
}
104
105
106
+ $ allowEmptyBaseline = (bool ) $ input ->getOption ('allow-empty-baseline ' );
107
+
105
108
if (
106
109
!is_array ($ paths )
107
110
|| (!is_string ($ memoryLimit ) && $ memoryLimit !== null )
@@ -132,6 +135,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
132
135
return 1 ;
133
136
}
134
137
138
+ if ($ generateBaselineFile === null && $ allowEmptyBaseline ) {
139
+ $ inceptionResult ->getStdOutput ()->getStyle ()->error ('You must pass the --generate-baseline option alongside --allow-empty-baseline. ' );
140
+ return $ inceptionResult ->handleReturn (1 );
141
+ }
142
+
135
143
$ errorOutput = $ inceptionResult ->getErrorOutput ();
136
144
$ obsoleteDockerImage = $ _SERVER ['PHPSTAN_OBSOLETE_DOCKER_IMAGE ' ] ?? 'false ' ;
137
145
if ($ obsoleteDockerImage === 'true ' ) {
@@ -239,7 +247,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
239
247
}
240
248
241
249
if ($ generateBaselineFile !== null ) {
242
- if (!$ analysisResult ->hasErrors ()) {
250
+ if (!$ allowEmptyBaseline && ! $ analysisResult ->hasErrors ()) {
243
251
$ inceptionResult ->getStdOutput ()->getStyle ()->error ('No errors were found during the analysis. Baseline could not be generated. ' );
244
252
245
253
return $ inceptionResult ->handleReturn (1 );
0 commit comments