From 402fe2d86f555470adc1677c7831a5572fb05d64 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 23 Oct 2021 23:17:25 +0100 Subject: [PATCH] AnalyseApplication: Do not re-analyse stubs on every run 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. --- .../ResultCache/ResultCacheManager.php | 9 ++++++++ src/Command/AnalyseApplication.php | 23 +++++++++++++------ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/Analyser/ResultCache/ResultCacheManager.php b/src/Analyser/ResultCache/ResultCacheManager.php index 71ae46d78c..1d3c8a5952 100644 --- a/src/Analyser/ResultCache/ResultCacheManager.php +++ b/src/Analyser/ResultCache/ResultCacheManager.php @@ -216,6 +216,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]; diff --git a/src/Command/AnalyseApplication.php b/src/Command/AnalyseApplication.php index 4d1656b0c6..1427d2905d 100644 --- a/src/Command/AnalyseApplication.php +++ b/src/Command/AnalyseApplication.php @@ -65,11 +65,6 @@ public function analyse( ): AnalysisResult { $this->updateMemoryLimitFile(); - $projectStubFiles = []; - if ($projectConfigArray !== null) { - $projectStubFiles = $projectConfigArray['parameters']['stubFiles'] ?? []; - } - $stubErrors = $this->stubValidator->validate($projectStubFiles, $debug); register_shutdown_function(function (): void { $error = error_get_last(); @@ -109,6 +104,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(); @@ -121,8 +132,6 @@ public function analyse( $errors = array_merge($errors, $internalErrors); } - $errors = array_merge($stubErrors, $errors); - $fileSpecificErrors = []; $notFileSpecificErrors = []; foreach ($errors as $error) {