From 1ee4b4aefac8ad198ee4a919d34f11af9c0b0ceb Mon Sep 17 00:00:00 2001 From: kkmuffme <11071985+kkmuffme@users.noreply.github.com> Date: Wed, 7 Dec 2022 11:47:59 +0100 Subject: [PATCH 1/2] remove file_get_contents that was incorrectly put in v5 --- src/Psalm/Internal/Provider/ParserCacheProvider.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Psalm/Internal/Provider/ParserCacheProvider.php b/src/Psalm/Internal/Provider/ParserCacheProvider.php index 559a11ecf63..4670623c8a7 100644 --- a/src/Psalm/Internal/Provider/ParserCacheProvider.php +++ b/src/Psalm/Internal/Provider/ParserCacheProvider.php @@ -12,7 +12,6 @@ use function clearstatcache; use function error_log; -use function file_get_contents; use function file_put_contents; use function filemtime; use function gettype; @@ -170,7 +169,7 @@ private function getExistingFileContentHashes(): array throw new UnexpectedValueException('No cache directory defined'); } if (is_readable($file_hashes_path)) { - $hashes_encoded = (string) file_get_contents($file_hashes_path); + $hashes_encoded = Providers::safeFileGetContents($file_hashes_path); if (!$hashes_encoded) { error_log('Unexpected value when loading from file content hashes'); From d3ec89417538a60a3beba9e79bb78ad9662c7e49 Mon Sep 17 00:00:00 2001 From: kkmuffme <11071985+kkmuffme@users.noreply.github.com> Date: Wed, 7 Dec 2022 19:53:28 +0100 Subject: [PATCH 2/2] use safeFileGetContents in ProjectCacheProvider too --- src/Psalm/Internal/Provider/ProjectCacheProvider.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Psalm/Internal/Provider/ProjectCacheProvider.php b/src/Psalm/Internal/Provider/ProjectCacheProvider.php index f8c868d6f2c..6dcb295d111 100644 --- a/src/Psalm/Internal/Provider/ProjectCacheProvider.php +++ b/src/Psalm/Internal/Provider/ProjectCacheProvider.php @@ -3,9 +3,9 @@ namespace Psalm\Internal\Provider; use Psalm\Config; +use Psalm\Internal\Provider\Providers; use function file_exists; -use function file_get_contents; use function file_put_contents; use function filemtime; use function hash; @@ -72,7 +72,8 @@ public function getLastRun(string $psalm_version): int $run_cache_location = $cache_directory . DIRECTORY_SEPARATOR . self::GOOD_RUN_NAME; - if (file_exists($run_cache_location) && file_get_contents($run_cache_location) === $psalm_version) { + if (file_exists($run_cache_location) + && Providers::safeFileGetContents($run_cache_location) === $psalm_version) { $this->last_run = filemtime($run_cache_location); } else { $this->last_run = 0; @@ -88,7 +89,7 @@ public function hasLockfileChanged(): bool return true; } - $lockfile_contents = file_get_contents($this->composer_lock_location); + $lockfile_contents = Providers::safeFileGetContents($this->composer_lock_location); if (!$lockfile_contents) { return true; @@ -132,7 +133,7 @@ protected function getComposerLockHash(): string $lock_hash_location = $cache_directory . DIRECTORY_SEPARATOR . self::COMPOSER_LOCK_HASH; if (file_exists($lock_hash_location)) { - $this->composer_lock_hash = file_get_contents($lock_hash_location) ?: ''; + $this->composer_lock_hash = Providers::safeFileGetContents($lock_hash_location) ?: ''; } else { $this->composer_lock_hash = ''; }