Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
use PHPStan\Reflection\ConstantNameHelper;
use function array_key_exists;
use function count;
use function implode;
use function in_array;
use function ltrim;
use function php_strip_whitespace;
use function preg_match_all;
use function preg_replace;
use function sha1;
use function sha1_file;
use function sprintf;
use function strtolower;
Expand Down Expand Up @@ -52,6 +54,15 @@ public function createByDirectory(string $directory): OptimizedDirectorySourceLo
}

$cacheKey = sprintf('odsl-%s', $directory);
return $this->createCachedDirectorySourceLocator($fileHashes, $cacheKey);
}

/**
* @param array<string, string> $fileHashes
* @param non-empty-string $cacheKey
*/
private function createCachedDirectorySourceLocator(array $fileHashes, string $cacheKey): OptimizedDirectorySourceLocator
{
$variableCacheKey = 'v1';

/** @var array<string, array{string, string[], string[], string[]}>|null $cached */
Expand Down Expand Up @@ -96,20 +107,17 @@ public function createByDirectory(string $directory): OptimizedDirectorySourceLo
*/
public function createByFiles(array $files): OptimizedDirectorySourceLocator
{
$symbols = [];
$fileHashes = [];
foreach ($files as $file) {
[$newClasses, $newFunctions, $newConstants] = $this->findSymbols($file);
$symbols[$file] = ['', $newClasses, $newFunctions, $newConstants];
$hash = sha1_file($file);
if ($hash === false) {
continue;
}
$fileHashes[$file] = $hash;
}

[$classToFile, $functionToFiles, $constantToFile] = $this->changeStructure($symbols);

return new OptimizedDirectorySourceLocator(
$this->fileNodesFetcher,
$classToFile,
$functionToFiles,
$constantToFile,
);
$cacheKey = sprintf('odsl-files-%s', sha1(implode(',', $files)));
return $this->createCachedDirectorySourceLocator($fileHashes, $cacheKey);
}

/**
Expand Down
Loading