@@ -21,30 +21,43 @@ final class RawCodeCoverageData
21
21
*/
22
22
private $ lineCoverage = [];
23
23
24
+ /**
25
+ * @var array
26
+ *
27
+ * @see https://xdebug.org/docs/code_coverage for format
28
+ */
29
+ private $ functionCoverage = [];
30
+
24
31
public static function fromXdebugWithoutPathCoverage (array $ rawCoverage ): self
25
32
{
26
- return new self ($ rawCoverage );
33
+ return new self ($ rawCoverage, [] );
27
34
}
28
35
29
36
public static function fromXdebugWithPathCoverage (array $ rawCoverage ): self
30
37
{
31
- $ lineCoverage = [];
38
+ $ lineCoverage = $ functionCoverage = [];
32
39
33
40
foreach ($ rawCoverage as $ file => $ fileCoverageData ) {
34
- $ lineCoverage [$ file ] = $ fileCoverageData ['lines ' ];
41
+ if (isset ($ fileCoverageData ['functions ' ])) {
42
+ $ lineCoverage [$ file ] = $ fileCoverageData ['lines ' ];
43
+ $ functionCoverage [$ file ] = $ fileCoverageData ['functions ' ];
44
+ } else { // not every file has functions, Xdebug outputs just line data for these
45
+ $ lineCoverage [$ file ] = $ fileCoverageData ;
46
+ }
35
47
}
36
48
37
- return new self ($ lineCoverage );
49
+ return new self ($ lineCoverage, $ functionCoverage );
38
50
}
39
51
40
- private function __construct (array $ lineCoverage )
52
+ private function __construct (array $ lineCoverage, array $ functionCoverage )
41
53
{
42
- $ this ->lineCoverage = $ lineCoverage ;
54
+ $ this ->lineCoverage = $ lineCoverage ;
55
+ $ this ->functionCoverage = $ functionCoverage ;
43
56
}
44
57
45
58
public function clear (): void
46
59
{
47
- $ this ->lineCoverage = [];
60
+ $ this ->lineCoverage = $ this -> functionCoverage = [];
48
61
}
49
62
50
63
public function getLineCoverage (): array
@@ -54,7 +67,7 @@ public function getLineCoverage(): array
54
67
55
68
public function removeCoverageDataForFile (string $ filename ): void
56
69
{
57
- unset($ this ->lineCoverage [$ filename ]);
70
+ unset($ this ->lineCoverage [$ filename ], $ this -> functionCoverage [ $ filename ] );
58
71
}
59
72
60
73
/**
0 commit comments