Skip to content

Commit 5a032f6

Browse files
committed
Result cache - use lazy callback for errors array in case older PHPStan gets handed newer result cache
1 parent af7a5ca commit 5a032f6

3 files changed

Lines changed: 20 additions & 10 deletions

File tree

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ jobs:
309309
uses: actions/cache@v1
310310
with:
311311
path: ./tmp
312-
key: "result-cache-v3"
312+
key: "result-cache-v4"
313313

314314
- name: "PHPStan with result cache"
315315
if: matrix.operating-system == 'ubuntu-latest'

phpcs.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<exclude name="Consistence.Exceptions.ExceptionDeclaration"/>
99
<exclude name="Squiz.Commenting.FunctionComment.MissingParamTag"/>
1010
<exclude name="Squiz.Commenting.FunctionComment.ParamNameNoMatch"/>
11+
<exclude name="Squiz.PHP.Heredoc.NotAllowed"/>
1112
</rule>
1213
<rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses">
1314
<properties>

src/Analyser/ResultCache/ResultCacheManager.php

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
class ResultCacheManager
1212
{
1313

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

1616
/** @var string */
1717
private $cacheFilePath;
@@ -98,7 +98,7 @@ public function restore(array $allAnalysedFiles, bool $debug): ResultCache
9898
$deletedFiles = array_fill_keys(array_keys($invertedDependencies), true);
9999
$filesToAnalyse = [];
100100
$invertedDependenciesToReturn = [];
101-
$errors = $data['errors'];
101+
$errors = $data['errorsCallback']();
102102
$filteredErrors = [];
103103
$newFileAppeared = false;
104104
foreach ($allAnalysedFiles as $analysedFile) {
@@ -325,16 +325,25 @@ private function save(
325325
$invertedDependencies[$file]['dependentFiles'] = $dependentFiles;
326326
}
327327

328+
$template = <<<'php'
329+
<?php declare(strict_types = 1);
330+
331+
return [
332+
'lastFullAnalysisTime' => %s,
333+
'meta' => %s,
334+
'errorsCallback' => static function (): array { return %s; },
335+
'dependencies' => %s,
336+
];
337+
php;
338+
328339
$tmpSuccess = @file_put_contents(
329340
$this->cacheFilePath,
330341
sprintf(
331-
"<?php declare(strict_types = 1);\n\nreturn %s;",
332-
var_export([
333-
'lastFullAnalysisTime' => $lastFullAnalysisTime,
334-
'meta' => $this->getMeta(),
335-
'errors' => $errors,
336-
'dependencies' => $invertedDependencies,
337-
], true)
342+
$template,
343+
var_export($lastFullAnalysisTime, true),
344+
var_export($this->getMeta(), true),
345+
var_export($errors, true),
346+
var_export($invertedDependencies, true)
338347
)
339348
);
340349
if ($tmpSuccess === false) {

0 commit comments

Comments
 (0)