From e797e0ed28f03caf4e519cb9dce2dfb30aa2e087 Mon Sep 17 00:00:00 2001 From: Lctrs Date: Thu, 18 Nov 2021 17:41:27 +0100 Subject: [PATCH 1/2] feat(analyze): add an option to allow generating empty baseline --- src/Command/AnalyseCommand.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Command/AnalyseCommand.php b/src/Command/AnalyseCommand.php index 0fab3d7261..62ccef3e52 100644 --- a/src/Command/AnalyseCommand.php +++ b/src/Command/AnalyseCommand.php @@ -55,6 +55,7 @@ protected function configure(): void new InputOption('autoload-file', 'a', InputOption::VALUE_REQUIRED, 'Project\'s additional autoload file path'), new InputOption('error-format', null, InputOption::VALUE_REQUIRED, 'Format in which to print the result of the analysis', null), new InputOption('generate-baseline', null, InputOption::VALUE_OPTIONAL, 'Path to a file where the baseline should be saved', false), + new InputOption('allow-empty-baseline', null, InputOption::VALUE_NONE, 'Do not error out when the generated baseline is empty'), new InputOption('memory-limit', null, InputOption::VALUE_REQUIRED, 'Memory limit for analysis'), new InputOption('xdebug', null, InputOption::VALUE_NONE, 'Allow running with XDebug for debugging purposes'), new InputOption('fix', null, InputOption::VALUE_NONE, 'Launch PHPStan Pro'), @@ -102,6 +103,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int $generateBaselineFile = 'phpstan-baseline.neon'; } + $allowEmptyBaseline = (bool) $input->getOption('allow-empty-baseline'); + if ( !is_array($paths) || (!is_string($memoryLimit) && $memoryLimit !== null) @@ -239,7 +242,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int } if ($generateBaselineFile !== null) { - if (!$analysisResult->hasErrors()) { + if (!$allowEmptyBaseline && !$analysisResult->hasErrors()) { $inceptionResult->getStdOutput()->getStyle()->error('No errors were found during the analysis. Baseline could not be generated.'); return $inceptionResult->handleReturn(1); From 8b897a3ef6f74b27c1b1d08a03d359026db87f4d Mon Sep 17 00:00:00 2001 From: Lctrs Date: Fri, 19 Nov 2021 11:35:52 +0100 Subject: [PATCH 2/2] chore(review): error out when allow-empty-baseline option is given without generate baseline --- src/Command/AnalyseCommand.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Command/AnalyseCommand.php b/src/Command/AnalyseCommand.php index 62ccef3e52..9a987bf5ae 100644 --- a/src/Command/AnalyseCommand.php +++ b/src/Command/AnalyseCommand.php @@ -135,6 +135,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int return 1; } + if ($generateBaselineFile === null && $allowEmptyBaseline) { + $inceptionResult->getStdOutput()->getStyle()->error('You must pass the --generate-baseline option alongside --allow-empty-baseline.'); + return $inceptionResult->handleReturn(1); + } + $errorOutput = $inceptionResult->getErrorOutput(); $obsoleteDockerImage = $_SERVER['PHPSTAN_OBSOLETE_DOCKER_IMAGE'] ?? 'false'; if ($obsoleteDockerImage === 'true') {