Skip to content

Commit

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

Check warning on line 178 in src/StaticAnalysis/CachingFileAnalyser.php

View check run for this annotation

Codecov / codecov/patch

src/StaticAnalysis/CachingFileAnalyser.php#L178

Added line #L178 was not covered by tests
[
'allowed_classes' => [
Class_::class,
Expand Down

0 comments on commit f452724

Please sign in to comment.