Skip to content

Commit

Permalink
AnalyseApplication: Do not re-analyse stubs on every run
Browse files Browse the repository at this point in the history
Instead, only analyse them on full runs. Since a change in any stub already invalidates the whole result cache, this means we only need to analyse them on full runs and then remember their errors for later.
  • Loading branch information
dktapps authored and ondrejmirtes committed Jan 31, 2022
1 parent c17a331 commit d96e8f0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
9 changes: 9 additions & 0 deletions src/Analyser/ResultCache/ResultCacheManager.php
Expand Up @@ -179,6 +179,15 @@ public function restore(array $allAnalysedFiles, bool $debug, bool $onlyFiles, ?
$filteredErrors = [];
$filteredExportedNodes = [];
$newFileAppeared = false;

foreach ($this->stubFiles as $stubFile) {
if (!array_key_exists($stubFile, $errors)) {
continue;
}

$filteredErrors[$stubFile] = $errors[$stubFile];
}

foreach ($allAnalysedFiles as $analysedFile) {
if (array_key_exists($analysedFile, $errors)) {
$filteredErrors[$analysedFile] = $errors[$analysedFile];
Expand Down
24 changes: 16 additions & 8 deletions src/Command/AnalyseApplication.php
Expand Up @@ -43,12 +43,6 @@ public function analyse(
InputInterface $input,
): AnalysisResult
{
$projectStubFiles = [];
if ($projectConfigArray !== null) {
$projectStubFiles = $projectConfigArray['parameters']['stubFiles'] ?? [];
}
$stubErrors = $this->stubValidator->validate($projectStubFiles, $debug);

$resultCacheManager = $this->resultCacheManagerFactory->create([]);

$ignoredErrorHelperResult = $this->ignoredErrorHelper->initialize();
Expand All @@ -70,6 +64,22 @@ public function analyse(
$errorOutput,
$input,
);

$projectStubFiles = [];
if ($projectConfigArray !== null) {
$projectStubFiles = $projectConfigArray['parameters']['stubFiles'] ?? [];
}
if ($resultCache->isFullAnalysis() && count($projectStubFiles) !== 0) {
$stubErrors = $this->stubValidator->validate($projectStubFiles, $debug);
$intermediateAnalyserResult = new AnalyserResult(
array_merge($intermediateAnalyserResult->getErrors(), $stubErrors),
$intermediateAnalyserResult->getInternalErrors(),
$intermediateAnalyserResult->getDependencies(),
$intermediateAnalyserResult->getExportedNodes(),
$intermediateAnalyserResult->hasReachedInternalErrorsCountLimit(),
);
}

$resultCacheResult = $resultCacheManager->process($intermediateAnalyserResult, $resultCache, $errorOutput, $onlyFiles, true);
$analyserResult = $resultCacheResult->getAnalyserResult();
$internalErrors = $analyserResult->getInternalErrors();
Expand All @@ -81,8 +91,6 @@ public function analyse(
$errors = array_merge($errors, $internalErrors);
}

$errors = array_merge($stubErrors, $errors);

$fileSpecificErrors = [];
$notFileSpecificErrors = [];
foreach ($errors as $error) {
Expand Down

0 comments on commit d96e8f0

Please sign in to comment.