Skip to content

Commit 9088b84

Browse files
committed
Result cache for everyone!
1 parent 9c56b39 commit 9088b84

File tree

12 files changed

+48
-29
lines changed

12 files changed

+48
-29
lines changed

build.xml

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,18 @@
259259
destFile="${phpstan.config}"
260260
text=" ]"
261261
></append>
262+
<exec
263+
executable="php"
264+
logoutput="true"
265+
passthru="true"
266+
checkreturn="true"
267+
>
268+
<arg path="bin/phpstan"/>
269+
<arg value="clear-result-cache"/>
270+
<arg value="-c"/>
271+
<arg path="${phpstan.config}"/>
272+
<arg value="-q"/>
273+
</exec>
262274
<exec
263275
executable="php"
264276
logoutput="true"
@@ -300,6 +312,18 @@
300312
destFile="${phpstan.config}"
301313
text=" ]"
302314
></append>
315+
<exec
316+
executable="php"
317+
logoutput="true"
318+
passthru="true"
319+
checkreturn="true"
320+
>
321+
<arg path="bin/phpstan"/>
322+
<arg value="clear-result-cache"/>
323+
<arg value="-c"/>
324+
<arg path="${phpstan.config}"/>
325+
<arg value="-q"/>
326+
</exec>
303327
<exec
304328
executable="php"
305329
logoutput="true"
@@ -337,10 +361,6 @@
337361
></append>
338362
</then>
339363
</if>
340-
<append
341-
destFile="${phpstan.config}"
342-
text=", result-cache.neon"
343-
></append>
344364
<append
345365
destFile="${phpstan.config}"
346366
text=" ]"

build/phpstan.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ parameters:
1818
- %rootDir%/tests/PHPStan/Generics/functions.php
1919
featureToggles:
2020
staticReflectionForPhpParser: false
21-
resultCache: false
2221
ignoreErrors:
2322
- '#^Dynamic call to static method PHPUnit\\Framework\\\S+\(\)\.$#'
2423
- '#should be contravariant with parameter \$node \(PhpParser\\Node\) of method PHPStan\\Rules\\Rule<PhpParser\\Node>::processNode\(\)$#'

build/result-cache.neon

Lines changed: 0 additions & 3 deletions
This file was deleted.

conf/bleedingEdge.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ parameters:
22
featureToggles:
33
closureUsesThis: true
44
randomIntParameters: true
5-
resultCache: true
65
nullCoalesce: true

conf/config.neon

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ parameters:
1010
staticReflectionForPhpParser: true
1111
disableRuntimeReflectionProvider: false
1212
enableScanningPaths: false
13-
resultCache: false
1413
closureUsesThis: false
1514
randomIntParameters: false
1615
nullCoalesce: false
@@ -134,7 +133,6 @@ parametersSchema:
134133
staticReflectionForPhpParser: bool(),
135134
disableRuntimeReflectionProvider: bool(),
136135
enableScanningPaths: bool(),
137-
resultCache: bool(),
138136
closureUsesThis: bool(),
139137
randomIntParameters: bool(),
140138
nullCoalesce: bool()
@@ -333,7 +331,6 @@ services:
333331
-
334332
class: PHPStan\Analyser\ResultCache\ResultCacheManager
335333
arguments:
336-
enabled: %featureToggles.resultCache%
337334
cacheFilePath: %tmpDir%/resultCache.php
338335
allCustomConfigFiles: %allCustomConfigFiles%
339336
analysedPaths: %analysedPaths%

src/Analyser/ResultCache/ResultCacheManager.php

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ class ResultCacheManager
1414

1515
private const CACHE_VERSION = 'v1';
1616

17-
/** @var bool */
18-
private $enabled;
19-
2017
/** @var string */
2118
private $cacheFilePath;
2219

@@ -36,7 +33,6 @@ class ResultCacheManager
3633
private $usedLevel;
3734

3835
/**
39-
* @param bool $enabled
4036
* @param string $cacheFilePath
4137
* @param string[] $allCustomConfigFiles
4238
* @param string[] $analysedPaths
@@ -45,7 +41,6 @@ class ResultCacheManager
4541
* @param string $usedLevel
4642
*/
4743
public function __construct(
48-
bool $enabled,
4944
string $cacheFilePath,
5045
array $allCustomConfigFiles,
5146
array $analysedPaths,
@@ -54,7 +49,6 @@ public function __construct(
5449
string $usedLevel
5550
)
5651
{
57-
$this->enabled = $enabled;
5852
$this->cacheFilePath = $cacheFilePath;
5953
$this->allCustomConfigFiles = $allCustomConfigFiles;
6054
$this->analysedPaths = $analysedPaths;
@@ -70,10 +64,6 @@ public function __construct(
7064
*/
7165
public function restore(array $allAnalysedFiles, bool $debug): ResultCache
7266
{
73-
if (!$this->enabled) {
74-
return new ResultCache($allAnalysedFiles, true, time(), [], []);
75-
}
76-
7767
if ($debug) {
7868
return new ResultCache($allAnalysedFiles, true, time(), [], []);
7969
}
@@ -407,16 +397,14 @@ private function getStubFiles(): array
407397

408398
public function clear(): string
409399
{
400+
$dir = dirname($this->cacheFilePath);
410401
if (!is_file($this->cacheFilePath)) {
411-
return dirname($this->cacheFilePath);
402+
return $dir;
412403
}
413404

414405
@unlink($this->cacheFilePath);
415-
if (is_file($this->cacheFilePath)) {
416-
throw new \PHPStan\ShouldNotHappenException('File still exists.');
417-
}
418406

419-
return dirname($this->cacheFilePath);
407+
return $dir;
420408
}
421409

422410
}

src/Testing/LevelsTestCase.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ public function testLevels(
4242

4343
foreach (range(0, 8) as $level) {
4444
unset($outputLines);
45+
exec(sprintf('%s %s clear-result-cache %s 2>&1', escapeshellarg(PHP_BINARY), $command, $configPath !== null ? '--configuration ' . escapeshellarg($configPath) : ''), $clearResultCacheOutputLines, $clearResultCacheExitCode);
46+
if ($clearResultCacheExitCode !== 0) {
47+
throw new \PHPStan\ShouldNotHappenException('Could not clear result cache: ' . implode("\n", $clearResultCacheOutputLines));
48+
}
4549
exec(sprintf('%s %s analyse --no-progress --error-format=prettyJson --level=%d %s --autoload-file %s %s', escapeshellarg(PHP_BINARY), $command, $level, $configPath !== null ? '--configuration ' . escapeshellarg($configPath) : '', escapeshellarg($file), escapeshellarg($file)), $outputLines);
4650

4751
$output = implode("\n", $outputLines);

tests/PHPStan/Analyser/traitsCachingIssue/TraitsCachingIssueIntegrationTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ public function testCachingIssue(
111111
private function runPhpStan(): array
112112
{
113113
$phpstanBinPath = __DIR__ . '/../../../../bin/phpstan';
114+
exec(sprintf('%s %s clear-result-cache --configuration %s', escapeshellarg(PHP_BINARY), $phpstanBinPath, escapeshellarg(__DIR__ . '/phpstan.neon')), $clearResultCacheOutputLines, $clearResultCacheExitCode);
115+
if ($clearResultCacheExitCode !== 0) {
116+
throw new \PHPStan\ShouldNotHappenException('Could not clear result cache.');
117+
}
118+
114119
exec(
115120
sprintf(
116121
'%s %s analyse --no-progress --level 8 --configuration %s --error-format json %s',

tests/PHPStan/Command/AnalyseApplicationIntegrationTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace PHPStan\Command;
44

5+
use PHPStan\Analyser\ResultCache\ResultCacheManager;
56
use PHPStan\Command\ErrorFormatter\TableErrorFormatter;
67
use PHPStan\Command\Symfony\SymfonyOutput;
78
use PHPStan\File\FuzzyRelativePathHelper;
@@ -37,6 +38,7 @@ public function testExecuteOnAFileWithErrors(): void
3738

3839
private function runPath(string $path, int $expectedStatusCode): string
3940
{
41+
self::getContainer()->getByType(ResultCacheManager::class)->clear();
4042
$analyserApplication = self::getContainer()->getByType(AnalyseApplication::class);
4143
$resource = fopen('php://memory', 'w', false);
4244
if ($resource === false) {

tests/PHPStan/Command/ErrorFormatter/BaselineNeonErrorFormatterIntegrationTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ private function runPhpStan(
5959
throw new \PHPStan\ShouldNotHappenException();
6060
}
6161
chdir(__DIR__ . '/../../../..');
62+
exec(sprintf('%s %s clear-result-cache %s', escapeshellarg(PHP_BINARY), 'bin/phpstan', $configFile !== null ? '--configuration ' . escapeshellarg($configFile) : ''), $clearResultCacheOutputLines, $clearResultCacheExitCode);
63+
if ($clearResultCacheExitCode !== 0) {
64+
throw new \PHPStan\ShouldNotHappenException('Could not clear result cache.');
65+
}
66+
6267
exec(sprintf('%s %s analyse --no-progress --error-format=%s --level=7 %s %s', escapeshellarg(PHP_BINARY), 'bin/phpstan', $errorFormatter, $configFile !== null ? '--configuration ' . escapeshellarg($configFile) : '', escapeshellarg($analysedPath)), $outputLines);
6368
chdir($originalDir);
6469

tests/PHPStan/Parallel/ParallelAnalyserIntegrationTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ public function dataRun(): array
2222
*/
2323
public function testRun(string $command): void
2424
{
25+
exec(sprintf('%s %s clear-result-cache --configuration %s', escapeshellarg(PHP_BINARY), escapeshellarg(__DIR__ . '/../../../bin/phpstan'), escapeshellarg(__DIR__ . '/parallel-analyser.neon')), $clearResultCacheOutputLines, $clearResultCacheExitCode);
26+
if ($clearResultCacheExitCode !== 0) {
27+
throw new \PHPStan\ShouldNotHappenException('Could not clear result cache.');
28+
}
29+
2530
exec(sprintf(
2631
'%s %s %s -l 8 -c %s --error-format json %s',
2732
escapeshellarg(PHP_BINARY),

tests/e2e/phpstan.neon

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,4 @@ includes:
22
- baseline.neon
33

44
parameters:
5-
featureToggles:
6-
resultCache: true
75
tmpDir: tmp

0 commit comments

Comments
 (0)