@@ -72,6 +72,7 @@ final class CodeCoverage
72
72
private array $ parentClassesExcludedFromUnintentionallyCoveredCodeCheck = [];
73
73
private ?FileAnalyser $ analyser = null ;
74
74
private ?string $ cacheDirectory = null ;
75
+ private ?Directory $ cachedReport = null ;
75
76
76
77
public function __construct (Driver $ driver , Filter $ filter )
77
78
{
@@ -86,18 +87,23 @@ public function __construct(Driver $driver, Filter $filter)
86
87
*/
87
88
public function getReport (): Directory
88
89
{
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 ;
90
95
}
91
96
92
97
/**
93
98
* Clears collected code coverage data.
94
99
*/
95
100
public function clear (): void
96
101
{
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 ;
101
107
}
102
108
103
109
/**
@@ -156,6 +162,8 @@ public function start(string $id, TestSize $size = null, bool $clear = false): v
156
162
$ this ->currentSize = $ size ;
157
163
158
164
$ this ->driver ->start ();
165
+
166
+ $ this ->cachedReport = null ;
159
167
}
160
168
161
169
/**
@@ -172,8 +180,9 @@ public function stop(bool $append = true, TestStatus $status = null, array|false
172
180
173
181
$ this ->append ($ data , null , $ append , $ status , $ linesToBeCovered , $ linesToBeUsed , $ linesToBeIgnored );
174
182
175
- $ this ->currentId = null ;
176
- $ this ->currentSize = null ;
183
+ $ this ->currentId = null ;
184
+ $ this ->currentSize = null ;
185
+ $ this ->cachedReport = null ;
177
186
178
187
return $ data ;
179
188
}
@@ -195,6 +204,8 @@ public function append(RawCodeCoverageData $rawData, string $id = null, bool $ap
195
204
throw new TestIdMissingException ;
196
205
}
197
206
207
+ $ this ->cachedReport = null ;
208
+
198
209
if ($ status === null ) {
199
210
$ status = TestStatus::unknown ();
200
211
}
@@ -254,6 +265,8 @@ public function merge(self $that): void
254
265
$ this ->data ->merge ($ that ->data );
255
266
256
267
$ this ->tests = array_merge ($ this ->tests , $ that ->getTests ());
268
+
269
+ $ this ->cachedReport = null ;
257
270
}
258
271
259
272
public function enableCheckForUnintentionallyCoveredCode (): void
0 commit comments