Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce unnecessary IO #1059

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
{
$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
Loading