Skip to content

Commit

Permalink
Remove functionality that is no longer needed for PHPUnit
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Dec 7, 2024
1 parent 6fbbff5 commit 6fd234d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 32 deletions.
1 change: 1 addition & 0 deletions ChangeLog-12.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt

### Removed

* Optional argument `$linesToBeUsed` of `CodeCoverage::stop()` and `CodeCoverage::append()` methods
* This component is no longer supported on PHP 8.2

[12.0.0]: https://github.com/sebastianbergmann/php-code-coverage/compare/11.0...main
37 changes: 5 additions & 32 deletions src/CodeCoverage.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use function array_flip;
use function array_keys;
use function array_merge;
use function array_merge_recursive;
use function array_unique;
use function count;
use function explode;
Expand Down Expand Up @@ -56,11 +55,6 @@ final class CodeCoverage
private ProcessedCodeCoverageData $data;
private bool $useAnnotationsForIgnoringCode = true;

/**
* @var array<string,list<int>>
*/
private array $linesToBeIgnored = [];

/**
* @var array<string, TestType>
*/
Expand Down Expand Up @@ -174,19 +168,11 @@ public function start(string $id, ?TestSize $size = null, bool $clear = false):
$this->cachedReport = null;
}

/**
* @param array<string,list<int>> $linesToBeIgnored
*/
public function stop(bool $append = true, ?TestStatus $status = null, array|false $linesToBeCovered = [], array $linesToBeUsed = [], array $linesToBeIgnored = []): RawCodeCoverageData
public function stop(bool $append = true, ?TestStatus $status = null, array|false $linesToBeCovered = [], array $linesToBeUsed = []): RawCodeCoverageData
{
$data = $this->driver->stop();

$this->linesToBeIgnored = array_merge_recursive(
$this->linesToBeIgnored,
$linesToBeIgnored,
);

$this->append($data, null, $append, $status, $linesToBeCovered, $linesToBeUsed, $linesToBeIgnored);
$this->append($data, null, $append, $status, $linesToBeCovered, $linesToBeUsed);

$this->currentId = null;
$this->currentSize = null;
Expand All @@ -196,13 +182,11 @@ public function stop(bool $append = true, ?TestStatus $status = null, array|fals
}

/**
* @param array<string,list<int>> $linesToBeIgnored
*
* @throws ReflectionException
* @throws TestIdMissingException
* @throws UnintentionallyCoveredCodeException
*/
public function append(RawCodeCoverageData $rawData, ?string $id = null, bool $append = true, ?TestStatus $status = null, array|false $linesToBeCovered = [], array $linesToBeUsed = [], array $linesToBeIgnored = []): void
public function append(RawCodeCoverageData $rawData, ?string $id = null, bool $append = true, ?TestStatus $status = null, array|false $linesToBeCovered = [], array $linesToBeUsed = []): void
{
if ($id === null) {
$id = $this->currentId;
Expand All @@ -229,7 +213,7 @@ public function append(RawCodeCoverageData $rawData, ?string $id = null, bool $a
$this->applyExecutableLinesFilter($rawData);

if ($this->useAnnotationsForIgnoringCode) {
$this->applyIgnoredLinesFilter($rawData, $linesToBeIgnored);
$this->applyIgnoredLinesFilter($rawData);
}

$this->data->initializeUnseenData($rawData);
Expand Down Expand Up @@ -452,23 +436,13 @@ private function applyExecutableLinesFilter(RawCodeCoverageData $data): void
}
}

/**
* @param array<string,list<int>> $linesToBeIgnored
*/
private function applyIgnoredLinesFilter(RawCodeCoverageData $data, array $linesToBeIgnored): void
private function applyIgnoredLinesFilter(RawCodeCoverageData $data): void
{
foreach (array_keys($data->lineCoverage()) as $filename) {
if (!$this->filter->isFile($filename)) {
continue;
}

if (isset($linesToBeIgnored[$filename])) {
$data->removeCoverageDataForLines(
$filename,
$linesToBeIgnored[$filename],
);
}

$data->removeCoverageDataForLines(
$filename,
$this->analyser()->ignoredLinesFor($filename),
Expand All @@ -494,7 +468,6 @@ private function addUncoveredFilesFromFilter(): void
$this->analyser(),
),
self::UNCOVERED_FILES,
linesToBeIgnored: $this->linesToBeIgnored,
);
}
}
Expand Down

0 comments on commit 6fd234d

Please sign in to comment.