diff --git a/src/CodeCoverage.php b/src/CodeCoverage.php index 9c8853025..d96f5ab2a 100644 --- a/src/CodeCoverage.php +++ b/src/CodeCoverage.php @@ -414,15 +414,15 @@ private function applyCoversAndUsesFilter(RawCodeCoverageData $rawData, array|fa private function applyFilter(RawCodeCoverageData $data): void { - if ($this->filter->isEmpty()) { - return; - } - - foreach (array_keys($data->lineCoverage()) as $filename) { - if ($this->filter->isExcluded($filename)) { - $data->removeCoverageDataForFile($filename); + if (!$this->filter->isEmpty()) { + foreach (array_keys($data->lineCoverage()) as $filename) { + if ($this->filter->isExcluded($filename)) { + $data->removeCoverageDataForFile($filename); + } } } + + $data->skipEmptyLines(); } private function applyExecutableLinesFilter(RawCodeCoverageData $data): void diff --git a/src/Data/RawCodeCoverageData.php b/src/Data/RawCodeCoverageData.php index 444f410a7..9b4304648 100644 --- a/src/Data/RawCodeCoverageData.php +++ b/src/Data/RawCodeCoverageData.php @@ -103,8 +103,6 @@ private function __construct(array $lineCoverage, array $functionCoverage) { $this->lineCoverage = $lineCoverage; $this->functionCoverage = $functionCoverage; - - $this->skipEmptyLines(); } public function clear(): void @@ -251,7 +249,7 @@ public function removeCoverageDataForLines(string $filename, array $lines): void * * @see https://github.com/sebastianbergmann/php-code-coverage/issues/799 */ - private function skipEmptyLines(): void + public function skipEmptyLines(): void { foreach ($this->lineCoverage as $filename => $coverage) { foreach ($this->getEmptyLinesForFile($filename) as $emptyLine) { diff --git a/tests/tests/Data/RawCodeCoverageDataTest.php b/tests/tests/Data/RawCodeCoverageDataTest.php index 98c4f45cb..0d2470dd5 100644 --- a/tests/tests/Data/RawCodeCoverageDataTest.php +++ b/tests/tests/Data/RawCodeCoverageDataTest.php @@ -326,6 +326,7 @@ public function testCoverageForFileWithInlineAnnotations(): void 33, ], ); + $coverage->skipEmptyLines(); $this->assertEquals( [