@@ -34,12 +34,6 @@ class BadgeComposer
34
34
* @var int[]
35
35
*/
36
36
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
37
44
38
/**
45
39
* @throws Exception
@@ -119,17 +113,25 @@ private function processFile(string $inputFile): void
119
113
}
120
114
$ xml = new SimpleXMLElement ($ content );
121
115
$ metrics = $ xml ->xpath ('//metrics ' );
116
+
117
+ $ totalConditionals = 0 ;
118
+ $ totalStatements = 0 ;
119
+ $ totalMethods = 0 ;
120
+ $ coveredStatements = 0 ;
121
+ $ coveredConditionals = 0 ;
122
+ $ coveredMethods = 0 ;
123
+
122
124
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 ' ];
125
+ $ totalConditionals = (int ) $ metric ['conditionals ' ];
126
+ $ coveredConditionals = (int ) $ metric ['coveredconditionals ' ];
127
+ $ totalStatements = (int ) $ metric ['statements ' ];
128
+ $ coveredStatements = (int ) $ metric ['coveredstatements ' ];
129
+ $ totalMethods = (int ) $ metric ['methods ' ];
130
+ $ coveredMethods = (int ) $ metric ['coveredmethods ' ];
129
131
}
130
132
131
- $ totalElements = $ this -> totalConditionals + $ this -> totalStatements + $ this -> totalMethods ;
132
- $ coveredElements = $ this -> coveredConditionals + $ this -> coveredStatements + $ this -> coveredMethods ;
133
+ $ totalElements = $ totalConditionals + $ totalStatements + $ totalMethods ;
134
+ $ coveredElements = $ coveredConditionals + $ coveredStatements + $ coveredMethods ;
133
135
$ coverageRatio = $ totalElements ? $ coveredElements / $ totalElements : 0 ;
134
136
$ this ->totalCoverage [] = (int ) round ($ coverageRatio * 100 );
135
137
@@ -152,7 +154,7 @@ private function finalizeCoverage(): void
152
154
throw new Exception ('Error reading badge template file ' );
153
155
}
154
156
155
- $ template = str_replace ('{{ total }} ' , (string ) $ totalCoverage , $ template );
157
+ $ template = str_replace ('{{ total }} ' , (string ) round ( $ totalCoverage) , $ template );
156
158
157
159
$ template = str_replace ('{{ coverage }} ' , $ this ->coverageName , $ template );
158
160
0 commit comments