Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/Command/AnalyseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing a default

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't set a default on an input option which has no value.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right, haven't realized that 👍

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'),
Expand Down Expand Up @@ -102,6 +103,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$generateBaselineFile = 'phpstan-baseline.neon';
}

$allowEmptyBaseline = (bool) $input->getOption('allow-empty-baseline');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This set to true should result in an error if $generateBaselineFile is null.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I'm not very satisfied with the error message, if you have a better idea...


if (
!is_array($paths)
|| (!is_string($memoryLimit) && $memoryLimit !== null)
Expand Down Expand Up @@ -132,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') {
Expand Down Expand Up @@ -239,7 +247,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);
Expand Down