Skip to content

Commit c6e2e46

Browse files
Merge branch '9.2'
2 parents 71acd36 + 1e4c868 commit c6e2e46

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

ChangeLog-10.1.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt
44

55
## [10.1.3] - 2023-MM-DD
66

7+
### Changed
8+
9+
* The result of `CodeCoverage::getReport()` is now cached
10+
711
### Fixed
812

913
* Static analysis cache keys do not include configuration settings that affect source code parsing

src/CodeCoverage.php

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ final class CodeCoverage
7272
private array $parentClassesExcludedFromUnintentionallyCoveredCodeCheck = [];
7373
private ?FileAnalyser $analyser = null;
7474
private ?string $cacheDirectory = null;
75+
private ?Directory $cachedReport = null;
7576

7677
public function __construct(Driver $driver, Filter $filter)
7778
{
@@ -86,18 +87,23 @@ public function __construct(Driver $driver, Filter $filter)
8687
*/
8788
public function getReport(): Directory
8889
{
89-
return (new Builder($this->analyser()))->build($this);
90+
if ($this->cachedReport === null) {
91+
$this->cachedReport = (new Builder($this->analyser()))->build($this);
92+
}
93+
94+
return $this->cachedReport;
9095
}
9196

9297
/**
9398
* Clears collected code coverage data.
9499
*/
95100
public function clear(): void
96101
{
97-
$this->currentId = null;
98-
$this->currentSize = null;
99-
$this->data = new ProcessedCodeCoverageData;
100-
$this->tests = [];
102+
$this->currentId = null;
103+
$this->currentSize = null;
104+
$this->data = new ProcessedCodeCoverageData;
105+
$this->tests = [];
106+
$this->cachedReport = null;
101107
}
102108

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

158164
$this->driver->start();
165+
166+
$this->cachedReport = null;
159167
}
160168

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

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

175-
$this->currentId = null;
176-
$this->currentSize = null;
183+
$this->currentId = null;
184+
$this->currentSize = null;
185+
$this->cachedReport = null;
177186

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

207+
$this->cachedReport = null;
208+
198209
if ($status === null) {
199210
$status = TestStatus::unknown();
200211
}
@@ -254,6 +265,8 @@ public function merge(self $that): void
254265
$this->data->merge($that->data);
255266

256267
$this->tests = array_merge($this->tests, $that->getTests());
268+
269+
$this->cachedReport = null;
257270
}
258271

259272
public function enableCheckForUnintentionallyCoveredCode(): void

0 commit comments

Comments
 (0)