Skip to content

Move result cache output from debug to very verbose mode #3345

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
32 changes: 16 additions & 16 deletions src/Analyser/ResultCache/ResultCacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,21 @@ public function restore(array $allAnalysedFiles, bool $debug, bool $onlyFiles, ?
{
$startTime = microtime(true);
if ($debug) {
if ($output->isDebug()) {
if ($output->isVeryVerbose()) {
$output->writeLineFormatted('Result cache not used because of debug mode.');
}
return new ResultCache($allAnalysedFiles, true, time(), $this->getMeta($allAnalysedFiles, $projectConfigArray), [], [], [], [], [], [], [], []);
}
if ($onlyFiles) {
if ($output->isDebug()) {
if ($output->isVeryVerbose()) {
$output->writeLineFormatted('Result cache not used because only files were passed as analysed paths.');
}
return new ResultCache($allAnalysedFiles, true, time(), $this->getMeta($allAnalysedFiles, $projectConfigArray), [], [], [], [], [], [], [], []);
}

$cacheFilePath = $this->cacheFilePath;
if (!is_file($cacheFilePath)) {
if ($output->isDebug()) {
if ($output->isVeryVerbose()) {
$output->writeLineFormatted('Result cache not used because the cache file does not exist.');
}
return new ResultCache($allAnalysedFiles, true, time(), $this->getMeta($allAnalysedFiles, $projectConfigArray), [], [], [], [], [], [], [], []);
Expand All @@ -115,7 +115,7 @@ public function restore(array $allAnalysedFiles, bool $debug, bool $onlyFiles, ?
try {
$data = require $cacheFilePath;
} catch (Throwable $e) {
if ($output->isDebug()) {
if ($output->isVeryVerbose()) {
$output->writeLineFormatted(sprintf('Result cache not used because an error occurred while loading the cache file: %s', $e->getMessage()));
}

Expand All @@ -126,7 +126,7 @@ public function restore(array $allAnalysedFiles, bool $debug, bool $onlyFiles, ?

if (!is_array($data)) {
@unlink($cacheFilePath);
if ($output->isDebug()) {
if ($output->isVeryVerbose()) {
$output->writeLineFormatted('Result cache not used because the cache file is corrupted.');
}

Expand All @@ -135,15 +135,15 @@ public function restore(array $allAnalysedFiles, bool $debug, bool $onlyFiles, ?

$meta = $this->getMeta($allAnalysedFiles, $projectConfigArray);
if ($this->isMetaDifferent($data['meta'], $meta)) {
if ($output->isDebug()) {
if ($output->isVeryVerbose()) {
$diffs = $this->getMetaKeyDifferences($data['meta'], $meta);
$output->writeLineFormatted('Result cache not used because the metadata do not match: ' . implode(', ', $diffs));
}
return new ResultCache($allAnalysedFiles, true, time(), $meta, [], [], [], [], [], [], [], []);
}

if (time() - $data['lastFullAnalysisTime'] >= 60 * 60 * 24 * 7) {
if ($output->isDebug()) {
if ($output->isVeryVerbose()) {
$output->writeLineFormatted('Result cache not used because it\'s more than 7 days since last full analysis.');
}
// run full analysis if the result cache is older than 7 days
Expand All @@ -159,7 +159,7 @@ public function restore(array $allAnalysedFiles, bool $debug, bool $onlyFiles, ?
continue;
}
if (!is_file($extensionFile)) {
if ($output->isDebug()) {
if ($output->isVeryVerbose()) {
$output->writeLineFormatted(sprintf('Result cache not used because extension file %s was not found.', $extensionFile));
}
return new ResultCache($allAnalysedFiles, true, time(), $meta, [], [], [], [], [], [], [], []);
Expand All @@ -169,7 +169,7 @@ public function restore(array $allAnalysedFiles, bool $debug, bool $onlyFiles, ?
continue;
}

if ($output->isDebug()) {
if ($output->isVeryVerbose()) {
$output->writeLineFormatted(sprintf('Result cache not used because extension file %s hash does not match.', $extensionFile));
}

Expand Down Expand Up @@ -287,7 +287,7 @@ public function restore(array $allAnalysedFiles, bool $debug, bool $onlyFiles, ?
$filesToAnalyse = array_unique($filesToAnalyse);
$filesToAnalyseCount = count($filesToAnalyse);

if ($output->isDebug()) {
if ($output->isVerbose()) {
$elapsed = microtime(true) - $startTime;
$elapsedString = $elapsed > 5
? sprintf(' in %f seconds', round($elapsed, 1))
Expand Down Expand Up @@ -412,20 +412,20 @@ public function process(AnalyserResult $analyserResult, ResultCache $resultCache
}
$doSave = function (array $errorsByFile, $locallyIgnoredErrorsByFile, $linesToIgnore, $unmatchedLineIgnores, $collectedDataByFile, ?array $dependencies, array $exportedNodes, array $projectExtensionFiles) use ($internalErrors, $resultCache, $output, $onlyFiles, $meta): bool {
if ($onlyFiles) {
if ($output->isDebug()) {
if ($output->isVeryVerbose()) {
$output->writeLineFormatted('Result cache was not saved because only files were passed as analysed paths.');
}
return false;
}
if ($dependencies === null) {
if ($output->isDebug()) {
if ($output->isVeryVerbose()) {
$output->writeLineFormatted('Result cache was not saved because of error in dependencies.');
}
return false;
}

if (count($internalErrors) > 0) {
if ($output->isDebug()) {
if ($output->isVeryVerbose()) {
$output->writeLineFormatted('Result cache was not saved because of internal errors.');
}
return false;
Expand All @@ -437,7 +437,7 @@ public function process(AnalyserResult $analyserResult, ResultCache $resultCache
continue;
}

if ($output->isDebug()) {
if ($output->isVeryVerbose()) {
$output->writeLineFormatted(sprintf('Result cache was not saved because of non-ignorable exception: %s', $error->getMessage()));
}

Expand All @@ -447,7 +447,7 @@ public function process(AnalyserResult $analyserResult, ResultCache $resultCache

$this->save($resultCache->getLastFullAnalysisTime(), $errorsByFile, $locallyIgnoredErrorsByFile, $linesToIgnore, $unmatchedLineIgnores, $collectedDataByFile, $dependencies, $exportedNodes, $projectExtensionFiles, $meta);

if ($output->isDebug()) {
if ($output->isVeryVerbose()) {
$output->writeLineFormatted('Result cache is saved.');
}

Expand All @@ -463,7 +463,7 @@ public function process(AnalyserResult $analyserResult, ResultCache $resultCache
}
$saved = $doSave($freshErrorsByFile, $freshLocallyIgnoredErrorsByFile, $analyserResult->getLinesToIgnore(), $analyserResult->getUnmatchedLineIgnores(), $freshCollectedDataByFile, $analyserResult->getDependencies(), $analyserResult->getExportedNodes(), $projectExtensionFiles);
} else {
if ($output->isDebug()) {
if ($output->isVeryVerbose()) {
$output->writeLineFormatted('Result cache was not saved because it was not requested.');
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Command/AnalyseApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function analyse(
$collectedData = [];
$savedResultCache = false;
$memoryUsageBytes = memory_get_peak_usage(true);
if ($errorOutput->isDebug()) {
if ($errorOutput->isVeryVerbose()) {
$errorOutput->writeLineFormatted('Result cache was not saved because of ignoredErrorHelperResult errors.');
}
$changedProjectExtensionFilesOutsideOfAnalysedPaths = [];
Expand Down
Loading