From 2c52441e0a9543fe5d064310a0b84fb5c816ff4b Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Fri, 20 Dec 2024 17:22:19 +0100 Subject: [PATCH] Revert "Reduce unnecessary IO" This reverts commit c41f7301aeb5b4ecdf073ed3809086781734237a. --- src/Data/RawCodeCoverageData.php | 14 +++++++++----- src/StaticAnalysis/CachingFileAnalyser.php | 7 +++---- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Data/RawCodeCoverageData.php b/src/Data/RawCodeCoverageData.php index a16aef8e..058ec199 100644 --- a/src/Data/RawCodeCoverageData.php +++ b/src/Data/RawCodeCoverageData.php @@ -16,8 +16,10 @@ use function array_intersect_key; use function array_map; use function count; -use function file; +use function explode; +use function file_get_contents; use function in_array; +use function is_file; use function preg_replace; use function range; use function str_ends_with; @@ -267,11 +269,13 @@ private function getEmptyLinesForFile(string $filename): array if (!isset(self::$emptyLineCache[$filename])) { self::$emptyLineCache[$filename] = []; - $sourceLines = @file($filename) ?: []; + if (is_file($filename)) { + $sourceLines = explode("\n", file_get_contents($filename)); - foreach ($sourceLines as $line => $source) { - if (trim($source) === '') { - self::$emptyLineCache[$filename][] = ($line + 1); + foreach ($sourceLines as $line => $source) { + if (trim($source) === '') { + self::$emptyLineCache[$filename][] = ($line + 1); + } } } } diff --git a/src/StaticAnalysis/CachingFileAnalyser.php b/src/StaticAnalysis/CachingFileAnalyser.php index d455310d..f9acc2d6 100644 --- a/src/StaticAnalysis/CachingFileAnalyser.php +++ b/src/StaticAnalysis/CachingFileAnalyser.php @@ -13,6 +13,7 @@ use function file_get_contents; use function file_put_contents; use function implode; +use function is_file; use function md5; use function serialize; use function unserialize; @@ -168,14 +169,12 @@ private function read(string $filename): array|false { $cacheFile = $this->cacheFile($filename); - $contents = @file_get_contents($cacheFile); - - if ($contents === false) { + if (!is_file($cacheFile)) { return false; } return unserialize( - $contents, + file_get_contents($cacheFile), [ 'allowed_classes' => [ Class_::class,