@@ -29,9 +29,13 @@ class BadgeComposer
29
29
private string $ outputFile ;
30
30
private string $ coverageName ;
31
31
private string $ badgeTemplate = __DIR__ . '/../template/badge.svg ' ;
32
- private int $ totalCoverage = 0 ;
33
- private int $ totalElements = 0 ;
34
- private int $ checkedElements = 0 ;
32
+ private array $ totalCoverage = [];
33
+ private int $ totalConditionals = 0 ;
34
+ private int $ coveredConditionals = 0 ;
35
+ private int $ totalStatements = 0 ;
36
+ private int $ coveredStatements = 0 ;
37
+ private int $ totalMethods = 0 ;
38
+ private int $ coveredMethods = 0 ;
35
39
36
40
/**
37
41
* @throws Exception
@@ -52,7 +56,7 @@ public function __construct(string $inputFiles, string $outputFile, string $cove
52
56
*/
53
57
public function getTotalCoverage (): int
54
58
{
55
- return $ this ->totalCoverage ;
59
+ return array_sum ( $ this ->totalCoverage ) ;
56
60
}
57
61
58
62
/**
@@ -112,12 +116,18 @@ private function processFile(string $inputFile): void
112
116
$ xml = new SimpleXMLElement ($ content );
113
117
$ metrics = $ xml ->xpath ('//metrics ' );
114
118
foreach ($ metrics as $ metric ) {
115
- $ this ->totalElements += (int ) $ metric ['elements ' ];
116
- $ this ->checkedElements += (int ) $ metric ['coveredelements ' ];
119
+ $ this ->totalConditionals += (int ) $ metric ['conditionals ' ];
120
+ $ this ->coveredConditionals += (int ) $ metric ['coveredconditionals ' ];
121
+ $ this ->totalStatements += (int ) $ metric ['statements ' ];
122
+ $ this ->coveredStatements += (int ) $ metric ['coveredstatements ' ];
123
+ $ this ->totalMethods += (int ) $ metric ['methods ' ];
124
+ $ this ->coveredMethods += (int ) $ metric ['coveredmethods ' ];
117
125
}
118
126
119
- $ coverageRatio = $ this ->totalElements ? $ this ->checkedElements / $ this ->totalElements : 0 ;
120
- $ this ->totalCoverage += (int ) round ($ coverageRatio * 100 );
127
+ $ totalElements = $ this ->totalConditionals + $ this ->totalStatements + $ this ->totalMethods ;
128
+ $ coveredElements = $ this ->coveredConditionals + $ this ->coveredStatements + $ this ->coveredMethods ;
129
+ $ coverageRatio = $ totalElements ? $ coveredElements / $ totalElements : 0 ;
130
+ $ this ->totalCoverage [] = (int ) round ($ coverageRatio * 100 );
121
131
122
132
} catch (Throwable $ e ) {
123
133
throw new Exception ($ e ->getMessage ());
@@ -131,7 +141,7 @@ private function processFile(string $inputFile): void
131
141
*/
132
142
private function finalizeCoverage (): void
133
143
{
134
- $ totalCoverage = $ this ->totalCoverage / count ($ this ->inputFiles ); // Average coverage across all files
144
+ $ totalCoverage = $ this ->getTotalCoverage () / count ($ this ->inputFiles ); // Average coverage across all files
135
145
$ template = file_get_contents ($ this ->badgeTemplate );
136
146
137
147
if ($ template === false ) {
0 commit comments