diff --git a/src/Analyser/ResultCache/ResultCacheManager.php b/src/Analyser/ResultCache/ResultCacheManager.php index 9592efea39..afab2d748b 100644 --- a/src/Analyser/ResultCache/ResultCacheManager.php +++ b/src/Analyser/ResultCache/ResultCacheManager.php @@ -38,13 +38,13 @@ use function explode; use function get_loaded_extensions; use function getenv; +use function hash_file; use function implode; use function is_array; use function is_dir; use function is_file; use function ksort; use function microtime; -use function sha1_file; use function sort; use function sprintf; use function str_starts_with; @@ -1055,7 +1055,7 @@ private function getFileHash(string $path): string return $this->fileHashes[$path]; } - $hash = sha1_file($path); + $hash = hash_file('sha256', $path); if ($hash === false) { throw new CouldNotReadFileException($path); } diff --git a/src/Analyser/RuleErrorTransformer.php b/src/Analyser/RuleErrorTransformer.php index 2cbdc7db26..12ad504320 100644 --- a/src/Analyser/RuleErrorTransformer.php +++ b/src/Analyser/RuleErrorTransformer.php @@ -27,7 +27,7 @@ use SebastianBergmann\Diff\Differ; use SebastianBergmann\Diff\Output\UnifiedDiffOutputBuilder; use function get_class; -use function sha1; +use function hash; use function str_contains; use function str_repeat; @@ -114,7 +114,7 @@ public function transform( $oldCode = FileReader::read($fixingFile); $this->parser->parse($oldCode); - $hash = sha1($oldCode); + $hash = hash('sha256', $oldCode); $oldTokens = $this->parser->getTokens(); $indentTraverser = new NodeTraverser(); diff --git a/src/Cache/FileCacheStorage.php b/src/Cache/FileCacheStorage.php index efe681a95f..b1c4c56174 100644 --- a/src/Cache/FileCacheStorage.php +++ b/src/Cache/FileCacheStorage.php @@ -17,13 +17,13 @@ use function closedir; use function dirname; use function error_get_last; +use function hash; use function is_dir; use function is_file; use function opendir; use function readdir; use function rename; use function rmdir; -use function sha1; use function sprintf; use function str_starts_with; use function strlen; @@ -107,7 +107,7 @@ public function save(string $key, string $variableKey, $data): void */ private function getFilePaths(string $key): array { - $keyHash = sha1($key); + $keyHash = hash('sha256', $key); $firstDirectory = sprintf('%s/%s', $this->directory, substr($keyHash, 0, 2)); $secondDirectory = sprintf('%s/%s', $firstDirectory, substr($keyHash, 2, 2)); $filePath = sprintf('%s/%s.php', $secondDirectory, $keyHash); diff --git a/src/Command/AnalyseApplication.php b/src/Command/AnalyseApplication.php index 53168f8edd..b6bd362122 100644 --- a/src/Command/AnalyseApplication.php +++ b/src/Command/AnalyseApplication.php @@ -17,10 +17,10 @@ use Symfony\Component\Console\Input\InputInterface; use function array_merge; use function count; +use function hash_file; use function is_file; use function memory_get_peak_usage; use function microtime; -use function sha1_file; use function sprintf; /** @@ -151,7 +151,7 @@ public function analyse( continue; } - $newHash = sha1_file($file); + $newHash = hash_file('sha256', $file); if ($newHash === $hash) { continue; } diff --git a/src/DependencyInjection/Configurator.php b/src/DependencyInjection/Configurator.php index 81452dc969..e1bf8194e2 100644 --- a/src/DependencyInjection/Configurator.php +++ b/src/DependencyInjection/Configurator.php @@ -15,6 +15,7 @@ use function count; use function error_reporting; use function explode; +use function hash_file; use function implode; use function in_array; use function is_dir; @@ -22,7 +23,6 @@ use function ksort; use function restore_error_handler; use function set_error_handler; -use function sha1_file; use function sprintf; use function str_ends_with; use function substr; @@ -94,7 +94,7 @@ public function loadContainer(): string array_keys($this->dynamicParameters), $this->configs, PHP_VERSION_ID - PHP_RELEASE_VERSION, - is_file($attributesPhp) ? sha1_file($attributesPhp) : 'attributes-missing', + is_file($attributesPhp) ? hash_file('sha256', $attributesPhp) : 'attributes-missing', NeonAdapter::CACHE_KEY, $this->getAllConfigFilesHashes(), ], ); @@ -224,7 +224,7 @@ private function getAllConfigFilesHashes(): array { $hashes = []; foreach ($this->allConfigFiles as $file) { - $hash = sha1_file($file); + $hash = hash_file('sha256', $file); if ($hash === false) { throw new CouldNotReadFileException($file); diff --git a/src/File/FileMonitor.php b/src/File/FileMonitor.php index 0da0270215..0778fd0c64 100644 --- a/src/File/FileMonitor.php +++ b/src/File/FileMonitor.php @@ -10,9 +10,9 @@ use function array_keys; use function array_merge; use function array_unique; +use function hash_file; use function is_dir; use function is_file; -use function sha1_file; #[AutowiredService] final class FileMonitor @@ -107,7 +107,7 @@ public function getChanges(): FileMonitorResult private function getFileHash(string $filePath): string { - $hash = sha1_file($filePath); + $hash = hash_file('sha256', $filePath); if ($hash === false) { throw new CouldNotReadFileException($filePath); diff --git a/src/Fixable/Patcher.php b/src/Fixable/Patcher.php index 7f126361a4..46fdb8fcee 100644 --- a/src/Fixable/Patcher.php +++ b/src/Fixable/Patcher.php @@ -15,8 +15,8 @@ use SebastianBergmann\Diff\Output\UnifiedDiffOutputBuilder; use function array_map; use function count; +use function hash; use function implode; -use function sha1; use function str_starts_with; use function substr; use const PHP_VERSION_ID; @@ -42,7 +42,7 @@ public function __construct() public function applyDiffs(string $fileName, array $diffs): string { $fileContents = FileReader::read($fileName); - $fileHash = sha1($fileContents); + $fileHash = hash('sha256', $fileContents); $diffHunks = []; foreach ($diffs as $diff) { if ($diff->originalHash !== $fileHash) { diff --git a/src/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocatorFactory.php b/src/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocatorFactory.php index c64ff2dd2b..0ffc7ff90f 100644 --- a/src/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocatorFactory.php +++ b/src/Reflection/BetterReflection/SourceLocator/OptimizedDirectorySourceLocatorFactory.php @@ -10,12 +10,12 @@ use PHPStan\Reflection\ConstantNameHelper; use function array_key_exists; use function count; +use function hash_file; use function in_array; use function ltrim; use function php_strip_whitespace; use function preg_match_all; use function preg_replace; -use function sha1_file; use function sprintf; use function strtolower; @@ -44,7 +44,7 @@ public function createByDirectory(string $directory): OptimizedDirectorySourceLo $files = $this->fileFinder->findFiles([$directory])->getFiles(); $fileHashes = []; foreach ($files as $file) { - $hash = sha1_file($file); + $hash = hash_file('sha256', $file); if ($hash === false) { continue; } @@ -108,7 +108,7 @@ public function createByFiles(array $files, string $uniqueCacheIdentifier): Opti { $fileHashes = []; foreach ($files as $file) { - $hash = sha1_file($file); + $hash = hash_file('sha256', $file); if ($hash === false) { continue; } diff --git a/src/Testing/PHPStanTestCase.php b/src/Testing/PHPStanTestCase.php index b3fed9b4e7..89ee716a19 100644 --- a/src/Testing/PHPStanTestCase.php +++ b/src/Testing/PHPStanTestCase.php @@ -37,9 +37,9 @@ use PHPUnit\Framework\TestCase; use function array_merge; use function count; +use function hash; use function implode; use function rtrim; -use function sha1; use function sprintf; use function sys_get_temp_dir; use const DIRECTORY_SEPARATOR; @@ -59,7 +59,7 @@ public static function getContainer(): Container foreach (static::getAdditionalConfigFiles() as $configFile) { $additionalConfigFiles[] = $configFile; } - $cacheKey = sha1(implode("\n", $additionalConfigFiles)); + $cacheKey = hash('sha256', implode("\n", $additionalConfigFiles)); if (!isset(self::$containers[$cacheKey])) { $tmpDir = sys_get_temp_dir() . '/phpstan-tests'; diff --git a/src/Testing/TestCaseSourceLocatorFactory.php b/src/Testing/TestCaseSourceLocatorFactory.php index 8fe494fee4..7e39d04139 100644 --- a/src/Testing/TestCaseSourceLocatorFactory.php +++ b/src/Testing/TestCaseSourceLocatorFactory.php @@ -21,9 +21,9 @@ use PHPStan\Reflection\BetterReflection\SourceLocator\SkipPolyfillSourceLocator; use ReflectionClass; use function dirname; +use function hash; use function is_file; use function serialize; -use function sha1; use const PHP_VERSION_ID; final class TestCaseSourceLocatorFactory @@ -55,7 +55,7 @@ public function create(): SourceLocator { $classLoaders = ClassLoader::getRegisteredLoaders(); $classLoaderReflection = new ReflectionClass(ClassLoader::class); - $cacheKey = sha1(serialize([ + $cacheKey = hash('sha256', serialize([ $this->phpVersion->getVersionId(), $this->fileExtensions, $this->excludePaths,