13
13
use function file_put_contents ;
14
14
use function round ;
15
15
use function str_replace ;
16
+ use function var_dump ;
16
17
17
18
/**
18
19
* Class BadgeComposer
@@ -34,12 +35,6 @@ class BadgeComposer
34
35
* @var int[]
35
36
*/
36
37
private array $ totalCoverage = [];
37
- private int $ totalConditionals = 0 ;
38
- private int $ coveredConditionals = 0 ;
39
- private int $ totalStatements = 0 ;
40
- private int $ coveredStatements = 0 ;
41
- private int $ totalMethods = 0 ;
42
- private int $ coveredMethods = 0 ;
43
38
44
39
/**
45
40
* @throws Exception
@@ -119,17 +114,25 @@ private function processFile(string $inputFile): void
119
114
}
120
115
$ xml = new SimpleXMLElement ($ content );
121
116
$ metrics = $ xml ->xpath ('//metrics ' );
117
+
118
+ $ totalConditionals = 0 ;
119
+ $ totalStatements = 0 ;
120
+ $ totalMethods = 0 ;
121
+ $ coveredStatements = 0 ;
122
+ $ coveredConditionals = 0 ;
123
+ $ coveredMethods = 0 ;
124
+
122
125
foreach ($ metrics as $ metric ) {
123
- $ this -> totalConditionals + = (int ) $ metric ['conditionals ' ];
124
- $ this -> coveredConditionals + = (int ) $ metric ['coveredconditionals ' ];
125
- $ this -> totalStatements + = (int ) $ metric ['statements ' ];
126
- $ this -> coveredStatements + = (int ) $ metric ['coveredstatements ' ];
127
- $ this -> totalMethods + = (int ) $ metric ['methods ' ];
128
- $ this -> coveredMethods + = (int ) $ metric ['coveredmethods ' ];
126
+ $ totalConditionals = (int ) $ metric ['conditionals ' ];
127
+ $ coveredConditionals = (int ) $ metric ['coveredconditionals ' ];
128
+ $ totalStatements = (int ) $ metric ['statements ' ];
129
+ $ coveredStatements = (int ) $ metric ['coveredstatements ' ];
130
+ $ totalMethods = (int ) $ metric ['methods ' ];
131
+ $ coveredMethods = (int ) $ metric ['coveredmethods ' ];
129
132
}
130
133
131
- $ totalElements = $ this -> totalConditionals + $ this -> totalStatements + $ this -> totalMethods ;
132
- $ coveredElements = $ this -> coveredConditionals + $ this -> coveredStatements + $ this -> coveredMethods ;
134
+ $ totalElements = $ totalConditionals + $ totalStatements + $ totalMethods ;
135
+ $ coveredElements = $ coveredConditionals + $ coveredStatements + $ coveredMethods ;
133
136
$ coverageRatio = $ totalElements ? $ coveredElements / $ totalElements : 0 ;
134
137
$ this ->totalCoverage [] = (int ) round ($ coverageRatio * 100 );
135
138
@@ -145,14 +148,15 @@ private function processFile(string $inputFile): void
145
148
*/
146
149
private function finalizeCoverage (): void
147
150
{
151
+ var_dump ($ this ->totalCoverage );
148
152
$ totalCoverage = $ this ->getTotalCoverage () / count ($ this ->inputFiles ); // Average coverage across all files
149
153
$ template = file_get_contents ($ this ->badgeTemplate );
150
154
151
155
if ($ template === false ) {
152
156
throw new Exception ('Error reading badge template file ' );
153
157
}
154
158
155
- $ template = str_replace ('{{ total }} ' , (string ) $ totalCoverage , $ template );
159
+ $ template = str_replace ('{{ total }} ' , (string ) round ( $ totalCoverage) , $ template );
156
160
157
161
$ template = str_replace ('{{ coverage }} ' , $ this ->coverageName , $ template );
158
162
0 commit comments