Skip to content

Commit bf94fac

Browse files
committed
Do not generate baseline when internal errors occured
1 parent 64618be commit bf94fac

File tree

7 files changed

+28
-6
lines changed

7 files changed

+28
-6
lines changed

src/Command/AnalyseApplication.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public function analyse(
9696
if (count($ignoredErrorHelperResult->getErrors()) > 0) {
9797
$errors = $ignoredErrorHelperResult->getErrors();
9898
$warnings = [];
99+
$hasInternalErrors = false;
99100
} else {
100101
$resultCache = $this->resultCacheManager->restore($files, $debug);
101102
$intermediateAnalyserResult = $this->runAnalyser(
@@ -111,6 +112,7 @@ public function analyse(
111112
$internalErrors = $analyserResult->getInternalErrors();
112113
$errors = $ignoredErrorHelperResult->process($analyserResult->getErrors(), $onlyFiles, $files, count($internalErrors) > 0 || $analyserResult->hasReachedInternalErrorsCountLimit());
113114
$warnings = $ignoredErrorHelperResult->getWarnings();
115+
$hasInternalErrors = count($internalErrors) > 0;
114116
if ($analyserResult->hasReachedInternalErrorsCountLimit()) {
115117
$errors[] = sprintf('Reached internal errors count limit of %d, exiting...', $this->internalErrorsCountLimit);
116118
}
@@ -135,7 +137,8 @@ public function analyse(
135137
$notFileSpecificErrors,
136138
$warnings,
137139
$defaultLevelUsed,
138-
$projectConfigFile
140+
$projectConfigFile,
141+
$hasInternalErrors
139142
);
140143
}
141144

src/Command/AnalyseCommand.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
205205

206206
return $inceptionResult->handleReturn(1);
207207
}
208+
if ($analysisResult->hasInternalErrors()) {
209+
$inceptionResult->getStdOutput()->getStyle()->error('An internal error occurred. Baseline could not be generated. Re-run PHPStan without --generate-baseline to see what\'s going on.');
210+
211+
return $inceptionResult->handleReturn(1);
212+
}
208213

209214
$baselineFileDirectory = dirname($generateBaselineFile);
210215
$baselineErrorFormatter = new BaselineNeonErrorFormatter(new ParentDirectoryRelativePathHelper($baselineFileDirectory));

src/Command/AnalysisResult.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,23 @@ class AnalysisResult
2020

2121
private ?string $projectConfigFile;
2222

23+
private bool $hasInternalErrors;
24+
2325
/**
2426
* @param \PHPStan\Analyser\Error[] $fileSpecificErrors
2527
* @param string[] $notFileSpecificErrors
2628
* @param string[] $warnings
2729
* @param bool $defaultLevelUsed
2830
* @param string|null $projectConfigFile
31+
* @param bool $hasInternalErrors
2932
*/
3033
public function __construct(
3134
array $fileSpecificErrors,
3235
array $notFileSpecificErrors,
3336
array $warnings,
3437
bool $defaultLevelUsed,
35-
?string $projectConfigFile
38+
?string $projectConfigFile,
39+
bool $hasInternalErrors
3640
)
3741
{
3842
usort(
@@ -55,6 +59,7 @@ static function (Error $a, Error $b): int {
5559
$this->warnings = $warnings;
5660
$this->defaultLevelUsed = $defaultLevelUsed;
5761
$this->projectConfigFile = $projectConfigFile;
62+
$this->hasInternalErrors = $hasInternalErrors;
5863
}
5964

6065
public function hasErrors(): bool
@@ -106,4 +111,9 @@ public function getProjectConfigFile(): ?string
106111
return $this->projectConfigFile;
107112
}
108113

114+
public function hasInternalErrors(): bool
115+
{
116+
return $this->hasInternalErrors;
117+
}
118+
109119
}

src/Testing/ErrorFormatterTestCase.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ protected function getAnalysisResult(int $numFileErrors, int $numGenericErrors):
7878
$genericErrors,
7979
[],
8080
false,
81-
null
81+
null,
82+
false
8283
);
8384
}
8485

tests/PHPStan/Command/AnalysisResultTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ public function testErrorsAreSortedByFileNameAndLine(): void
3939
[],
4040
[],
4141
false,
42-
null
42+
null,
43+
false
4344
))->getFileSpecificErrors()
4445
);
4546
}

tests/PHPStan/Command/ErrorFormatter/BaselineNeonErrorFormatterTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ public function testFormatErrorMessagesRegexEscape(): void
131131
['Escape Regex without file # ~ <> \' ()'],
132132
[],
133133
false,
134-
null
134+
null,
135+
false
135136
);
136137
$formatter->formatErrors(
137138
$result,

tests/PHPStan/Command/ErrorFormatter/CheckstyleErrorFormatterTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ public function testTraitPath(): void
154154
[],
155155
[],
156156
false,
157-
null
157+
null,
158+
false
158159
), $this->getOutput());
159160
$this->assertXmlStringEqualsXmlString('<checkstyle>
160161
<file name="FooTrait.php">

0 commit comments

Comments
 (0)