Skip to content

Commit 40455c3

Browse files
committed
ResultCacheClearer
1 parent 4e71e79 commit 40455c3

File tree

5 files changed

+52
-27
lines changed

5 files changed

+52
-27
lines changed

conf/config.neon

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,12 @@ services:
404404
usedLevel: %usedLevel%
405405
cliAutoloadFile: %cliAutoloadFile%
406406

407+
-
408+
class: PHPStan\Analyser\ResultCache\ResultCacheClearer
409+
arguments:
410+
cacheFilePath: %tmpDir%/resultCache.php
411+
tempResultCachePath: %tempResultCachePath%
412+
407413
-
408414
class: PHPStan\Cache\Cache
409415
arguments:
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Analyser\ResultCache;
4+
5+
use Symfony\Component\Finder\Finder;
6+
7+
class ResultCacheClearer
8+
{
9+
10+
private string $cacheFilePath;
11+
12+
private string $tempResultCachePath;
13+
14+
public function __construct(string $cacheFilePath, string $tempResultCachePath)
15+
{
16+
$this->cacheFilePath = $cacheFilePath;
17+
$this->tempResultCachePath = $tempResultCachePath;
18+
}
19+
20+
public function clear(): string
21+
{
22+
$dir = dirname($this->cacheFilePath);
23+
if (!is_file($this->cacheFilePath)) {
24+
return $dir;
25+
}
26+
27+
@unlink($this->cacheFilePath);
28+
29+
return $dir;
30+
}
31+
32+
public function clearTemporaryCaches(): void
33+
{
34+
$finder = new Finder();
35+
foreach ($finder->files()->name('*.php')->in($this->tempResultCachePath) as $tmpResultCacheFile) {
36+
@unlink($tmpResultCacheFile->getPathname());
37+
}
38+
}
39+
40+
}

src/Analyser/ResultCache/ResultCacheManager.php

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use PHPStan\Dependency\ExportedNodeFetcher;
1010
use PHPStan\File\FileReader;
1111
use PHPStan\File\FileWriter;
12-
use Symfony\Component\Finder\Finder;
1312
use function array_fill_keys;
1413
use function array_key_exists;
1514

@@ -577,24 +576,4 @@ private function getStubFiles(): array
577576
return $stubFiles;
578577
}
579578

580-
public function clear(): string
581-
{
582-
$dir = dirname($this->cacheFilePath);
583-
if (!is_file($this->cacheFilePath)) {
584-
return $dir;
585-
}
586-
587-
@unlink($this->cacheFilePath);
588-
589-
return $dir;
590-
}
591-
592-
public function clearTemporaryCaches(): void
593-
{
594-
$finder = new Finder();
595-
foreach ($finder->files()->name('*.php')->in($this->tempResultCachePath) as $tmpResultCacheFile) {
596-
@unlink($tmpResultCacheFile->getPathname());
597-
}
598-
}
599-
600579
}

src/Command/ClearResultCacheCommand.php

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

33
namespace PHPStan\Command;
44

5-
use PHPStan\Analyser\ResultCache\ResultCacheManagerFactory;
5+
use PHPStan\Analyser\ResultCache\ResultCacheClearer;
66
use Symfony\Component\Console\Command\Command;
77
use Symfony\Component\Console\Input\InputInterface;
88
use Symfony\Component\Console\Input\InputOption;
@@ -70,9 +70,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7070

7171
$container = $inceptionResult->getContainer();
7272

73-
/** @var ResultCacheManagerFactory $resultCacheManagerFactory */
74-
$resultCacheManagerFactory = $container->getByType(ResultCacheManagerFactory::class);
75-
$path = $resultCacheManagerFactory->create([])->clear();
73+
/** @var ResultCacheClearer $resultCacheClearer */
74+
$resultCacheClearer = $container->getByType(ResultCacheClearer::class);
75+
$path = $resultCacheClearer->clear();
7676

7777
$output->writeln('<info>Result cache cleared from directory:</info>');
7878
$output->writeln($path);

tests/PHPStan/Command/AnalyseApplicationIntegrationTest.php

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

33
namespace PHPStan\Command;
44

5-
use PHPStan\Analyser\ResultCache\ResultCacheManagerFactory;
5+
use PHPStan\Analyser\ResultCache\ResultCacheClearer;
66
use PHPStan\Command\ErrorFormatter\TableErrorFormatter;
77
use PHPStan\Command\Symfony\SymfonyOutput;
88
use PHPStan\File\FuzzyRelativePathHelper;
@@ -41,7 +41,7 @@ private function runPath(string $path, int $expectedStatusCode): string
4141
if (PHP_VERSION_ID >= 80000 && DIRECTORY_SEPARATOR === '\\') {
4242
$this->markTestSkipped('Skipped because of https://github.com/symfony/symfony/issues/37508');
4343
}
44-
self::getContainer()->getByType(ResultCacheManagerFactory::class)->create([])->clear();
44+
self::getContainer()->getByType(ResultCacheClearer::class)->clear();
4545
$analyserApplication = self::getContainer()->getByType(AnalyseApplication::class);
4646
$resource = fopen('php://memory', 'w', false);
4747
if ($resource === false) {

0 commit comments

Comments
 (0)