Skip to content

Commit 96a169d

Browse files
committed
use call-site cache identifier
1 parent 3d87e3e commit 96a169d

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

src/Reflection/BetterReflection/SourceLocator/ComposerJsonAndInstalledJsonSourceLocatorMaker.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public function create(string $projectInstallationPath): ?SourceLocator
129129
}
130130

131131
if (count($files) > 0) {
132-
$locators[] = $this->optimizedDirectorySourceLocatorFactory->createByFiles($files);
132+
$locators[] = $this->optimizedDirectorySourceLocatorFactory->createByFiles($files, 'odsl-installed-files');
133133
}
134134

135135
$binDir = ComposerHelper::getBinDirFromComposerConfig($projectInstallationPath, $composer);

src/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocatorFactory.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@
1010
use PHPStan\Reflection\ConstantNameHelper;
1111
use function array_key_exists;
1212
use function count;
13-
use function implode;
1413
use function in_array;
1514
use function ltrim;
1615
use function php_strip_whitespace;
1716
use function preg_match_all;
1817
use function preg_replace;
19-
use function sha1;
2018
use function sha1_file;
2119
use function sprintf;
2220
use function strtolower;
@@ -104,8 +102,9 @@ private function createCachedDirectorySourceLocator(array $fileHashes, string $c
104102

105103
/**
106104
* @param string[] $files
105+
* @param non-empty-string&literal-string $uniqueCacheIdentifier
107106
*/
108-
public function createByFiles(array $files): OptimizedDirectorySourceLocator
107+
public function createByFiles(array $files, string $uniqueCacheIdentifier): OptimizedDirectorySourceLocator
109108
{
110109
$fileHashes = [];
111110
foreach ($files as $file) {
@@ -116,8 +115,7 @@ public function createByFiles(array $files): OptimizedDirectorySourceLocator
116115
$fileHashes[$file] = $hash;
117116
}
118117

119-
$cacheKey = sprintf('odsl-files-%s', sha1(implode(',', $files)));
120-
return $this->createCachedDirectorySourceLocator($fileHashes, $cacheKey);
118+
return $this->createCachedDirectorySourceLocator($fileHashes, $uniqueCacheIdentifier);
121119
}
122120

123121
/**

tests/PHPStan/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ public function testFunctionDoesNotExist(string $functionName): void
307307
public function testBug5525(): void
308308
{
309309
$factory = self::getContainer()->getByType(OptimizedDirectorySourceLocatorFactory::class);
310-
$locator = $factory->createByFiles([__DIR__ . '/data/bug-5525.php']);
310+
$locator = $factory->createByFiles([__DIR__ . '/data/bug-5525.php'], 'bug5525-odsl-installed-files');
311311
$reflector = new DefaultReflector($locator);
312312

313313
$class = $reflector->reflectClass('Faker\\Provider\\nl_BE\\Text');

0 commit comments

Comments
 (0)