Skip to content

Commit

Permalink
Merge branch '9.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Jul 15, 2023
2 parents 71acd36 + 1e4c868 commit c6e2e46
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
4 changes: 4 additions & 0 deletions ChangeLog-10.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt

## [10.1.3] - 2023-MM-DD

### Changed

* The result of `CodeCoverage::getReport()` is now cached

### Fixed

* Static analysis cache keys do not include configuration settings that affect source code parsing
Expand Down
27 changes: 20 additions & 7 deletions src/CodeCoverage.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ final class CodeCoverage
private array $parentClassesExcludedFromUnintentionallyCoveredCodeCheck = [];
private ?FileAnalyser $analyser = null;
private ?string $cacheDirectory = null;
private ?Directory $cachedReport = null;

public function __construct(Driver $driver, Filter $filter)
{
Expand All @@ -86,18 +87,23 @@ public function __construct(Driver $driver, Filter $filter)
*/
public function getReport(): Directory
{
return (new Builder($this->analyser()))->build($this);
if ($this->cachedReport === null) {
$this->cachedReport = (new Builder($this->analyser()))->build($this);
}

return $this->cachedReport;
}

/**
* Clears collected code coverage data.
*/
public function clear(): void
{
$this->currentId = null;
$this->currentSize = null;
$this->data = new ProcessedCodeCoverageData;
$this->tests = [];
$this->currentId = null;
$this->currentSize = null;
$this->data = new ProcessedCodeCoverageData;
$this->tests = [];
$this->cachedReport = null;
}

/**
Expand Down Expand Up @@ -156,6 +162,8 @@ public function start(string $id, TestSize $size = null, bool $clear = false): v
$this->currentSize = $size;

$this->driver->start();

$this->cachedReport = null;
}

/**
Expand All @@ -172,8 +180,9 @@ public function stop(bool $append = true, TestStatus $status = null, array|false

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

$this->currentId = null;
$this->currentSize = null;
$this->currentId = null;
$this->currentSize = null;
$this->cachedReport = null;

return $data;
}
Expand All @@ -195,6 +204,8 @@ public function append(RawCodeCoverageData $rawData, string $id = null, bool $ap
throw new TestIdMissingException;
}

$this->cachedReport = null;

if ($status === null) {
$status = TestStatus::unknown();
}
Expand Down Expand Up @@ -254,6 +265,8 @@ public function merge(self $that): void
$this->data->merge($that->data);

$this->tests = array_merge($this->tests, $that->getTests());

$this->cachedReport = null;
}

public function enableCheckForUnintentionallyCoveredCode(): void
Expand Down

0 comments on commit c6e2e46

Please sign in to comment.