Skip to content

Commit

Permalink
Result cache - use lazy callback for errors array in case older PHPSt…
Browse files Browse the repository at this point in the history
…an gets handed newer result cache
  • Loading branch information
ondrejmirtes committed Mar 16, 2020
1 parent af7a5ca commit 5a032f6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ jobs:
uses: actions/cache@v1
with:
path: ./tmp
key: "result-cache-v3"
key: "result-cache-v4"

- name: "PHPStan with result cache"
if: matrix.operating-system == 'ubuntu-latest'
Expand Down
1 change: 1 addition & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<exclude name="Consistence.Exceptions.ExceptionDeclaration"/>
<exclude name="Squiz.Commenting.FunctionComment.MissingParamTag"/>
<exclude name="Squiz.Commenting.FunctionComment.ParamNameNoMatch"/>
<exclude name="Squiz.PHP.Heredoc.NotAllowed"/>
</rule>
<rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses">
<properties>
Expand Down
27 changes: 18 additions & 9 deletions src/Analyser/ResultCache/ResultCacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class ResultCacheManager
{

private const CACHE_VERSION = 'v3-all-errors';
private const CACHE_VERSION = 'v4-callback';

/** @var string */
private $cacheFilePath;
Expand Down Expand Up @@ -98,7 +98,7 @@ public function restore(array $allAnalysedFiles, bool $debug): ResultCache
$deletedFiles = array_fill_keys(array_keys($invertedDependencies), true);
$filesToAnalyse = [];
$invertedDependenciesToReturn = [];
$errors = $data['errors'];
$errors = $data['errorsCallback']();
$filteredErrors = [];
$newFileAppeared = false;
foreach ($allAnalysedFiles as $analysedFile) {
Expand Down Expand Up @@ -325,16 +325,25 @@ private function save(
$invertedDependencies[$file]['dependentFiles'] = $dependentFiles;
}

$template = <<<'php'
<?php declare(strict_types = 1);
return [
'lastFullAnalysisTime' => %s,
'meta' => %s,
'errorsCallback' => static function (): array { return %s; },
'dependencies' => %s,
];
php;

$tmpSuccess = @file_put_contents(
$this->cacheFilePath,
sprintf(
"<?php declare(strict_types = 1);\n\nreturn %s;",
var_export([
'lastFullAnalysisTime' => $lastFullAnalysisTime,
'meta' => $this->getMeta(),
'errors' => $errors,
'dependencies' => $invertedDependencies,
], true)
$template,
var_export($lastFullAnalysisTime, true),
var_export($this->getMeta(), true),
var_export($errors, true),
var_export($invertedDependencies, true)
)
);
if ($tmpSuccess === false) {
Expand Down

0 comments on commit 5a032f6

Please sign in to comment.