Skip to content

Commit

Permalink
Revert "Reduce unnecessary IO"
Browse files Browse the repository at this point in the history
This reverts commit c41f730.
  • Loading branch information
sebastianbergmann committed Dec 20, 2024
1 parent 0f46512 commit 2c52441
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
14 changes: 9 additions & 5 deletions src/Data/RawCodeCoverageData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/StaticAnalysis/CachingFileAnalyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 2c52441

Please sign in to comment.