Skip to content

Commit

Permalink
Reduce unnecessary IO
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm authored and sebastianbergmann committed Dec 16, 2024
1 parent fd75e48 commit c41f730
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,
[
'allowed_classes' => [
Class_::class,
Expand Down

4 comments on commit c41f730

@sebastianbergmann
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@staabm Not entirely sure, but I suspect this change broke something: https://github.com/sebastianbergmann/phpunit/actions/runs/12426606434/job/34695291633

@staabm
Copy link
Contributor Author

@staabm staabm commented on c41f730 Dec 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you are right that the problem is triggered from this code here.

the root cause seems to be some error handler which turns warnings into exceptions
(and does not respect the @ operator)

@sebastianbergmann
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@staabm
Copy link
Contributor Author

@staabm staabm commented on c41f730 Dec 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh.. the stacktrace of your first link makes the problem obvious. working on a fix

Please sign in to comment.