diff --git a/src/Data/RawCodeCoverageData.php b/src/Data/RawCodeCoverageData.php index 058ec199..a16aef8e 100644 --- a/src/Data/RawCodeCoverageData.php +++ b/src/Data/RawCodeCoverageData.php @@ -16,10 +16,8 @@ use function array_intersect_key; use function array_map; use function count; -use function explode; -use function file_get_contents; +use function file; use function in_array; -use function is_file; use function preg_replace; use function range; use function str_ends_with; @@ -269,13 +267,11 @@ private function getEmptyLinesForFile(string $filename): array if (!isset(self::$emptyLineCache[$filename])) { self::$emptyLineCache[$filename] = []; - if (is_file($filename)) { - $sourceLines = explode("\n", file_get_contents($filename)); + $sourceLines = @file($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 f9acc2d6..d455310d 100644 --- a/src/StaticAnalysis/CachingFileAnalyser.php +++ b/src/StaticAnalysis/CachingFileAnalyser.php @@ -13,7 +13,6 @@ 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; @@ -169,12 +168,14 @@ private function read(string $filename): array|false { $cacheFile = $this->cacheFile($filename); - if (!is_file($cacheFile)) { + $contents = @file_get_contents($cacheFile); + + if ($contents === false) { return false; } return unserialize( - file_get_contents($cacheFile), + $contents, [ 'allowed_classes' => [ Class_::class,