|
10 | 10 | use PHPStan\Reflection\ConstantNameHelper; |
11 | 11 | use function array_key_exists; |
12 | 12 | use function count; |
| 13 | +use function implode; |
13 | 14 | use function in_array; |
14 | 15 | use function ltrim; |
15 | 16 | use function php_strip_whitespace; |
16 | 17 | use function preg_match_all; |
17 | 18 | use function preg_replace; |
| 19 | +use function sha1; |
18 | 20 | use function sha1_file; |
19 | 21 | use function sprintf; |
20 | 22 | use function strtolower; |
@@ -52,6 +54,11 @@ public function createByDirectory(string $directory): OptimizedDirectorySourceLo |
52 | 54 | } |
53 | 55 |
|
54 | 56 | $cacheKey = sprintf('odsl-%s', $directory); |
| 57 | + return $this->createCachedDirectorySourceLocator($fileHashes, $cacheKey); |
| 58 | + } |
| 59 | + |
| 60 | + public function createCachedDirectorySourceLocator(array $fileHashes, string $cacheKey): OptimizedDirectorySourceLocator |
| 61 | + { |
55 | 62 | $variableCacheKey = 'v1'; |
56 | 63 |
|
57 | 64 | /** @var array<string, array{string, string[], string[], string[]}>|null $cached */ |
@@ -96,20 +103,17 @@ public function createByDirectory(string $directory): OptimizedDirectorySourceLo |
96 | 103 | */ |
97 | 104 | public function createByFiles(array $files): OptimizedDirectorySourceLocator |
98 | 105 | { |
99 | | - $symbols = []; |
| 106 | + $fileHashes = []; |
100 | 107 | foreach ($files as $file) { |
101 | | - [$newClasses, $newFunctions, $newConstants] = $this->findSymbols($file); |
102 | | - $symbols[$file] = ['', $newClasses, $newFunctions, $newConstants]; |
| 108 | + $hash = sha1_file($file); |
| 109 | + if ($hash === false) { |
| 110 | + continue; |
| 111 | + } |
| 112 | + $fileHashes[$file] = $hash; |
103 | 113 | } |
104 | 114 |
|
105 | | - [$classToFile, $functionToFiles, $constantToFile] = $this->changeStructure($symbols); |
106 | | - |
107 | | - return new OptimizedDirectorySourceLocator( |
108 | | - $this->fileNodesFetcher, |
109 | | - $classToFile, |
110 | | - $functionToFiles, |
111 | | - $constantToFile, |
112 | | - ); |
| 115 | + $cacheKey = sprintf('odsl-files-%s', sha1(implode(',', $files))); |
| 116 | + return $this->createCachedDirectorySourceLocator($fileHashes, $cacheKey); |
113 | 117 | } |
114 | 118 |
|
115 | 119 | /** |
|
0 commit comments