From 2e94d0330fcadc702935571289b4b8940cf0e599 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Tue, 30 Aug 2022 10:01:23 +0200 Subject: [PATCH] Refactor --- src/StaticAnalysis/CachingFileAnalyser.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/StaticAnalysis/CachingFileAnalyser.php b/src/StaticAnalysis/CachingFileAnalyser.php index 3241a3af5..f16a10fc9 100644 --- a/src/StaticAnalysis/CachingFileAnalyser.php +++ b/src/StaticAnalysis/CachingFileAnalyser.php @@ -48,10 +48,6 @@ public function __construct(string $directory, FileAnalyser $analyser) $this->analyser = $analyser; $this->directory = $directory; - - if (self::$cacheVersion === null) { - $this->calculateCacheVersion(); - } } public function classesIn(string $filename): array @@ -163,11 +159,15 @@ private function write(string $filename, $data): void private function cacheFile(string $filename): string { - return $this->directory . DIRECTORY_SEPARATOR . hash('sha256', $filename . crc32(file_get_contents($filename)) . self::$cacheVersion); + return $this->directory . DIRECTORY_SEPARATOR . hash('sha256', $filename . crc32(file_get_contents($filename)) . self::cacheVersion()); } - private function calculateCacheVersion(): void + private static function cacheVersion(): string { + if (self::$cacheVersion !== null) { + return self::$cacheVersion; + } + $buffer = ''; foreach ((new FileIteratorFacade)->getFilesAsArray(__DIR__, '.php') as $file) { @@ -175,5 +175,7 @@ private function calculateCacheVersion(): void } self::$cacheVersion = (string) crc32($buffer); + + return self::$cacheVersion; } }