@@ -34,12 +34,6 @@ class BadgeComposer
3434 * @var int[]
3535 */
3636 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 ;
4337
4438 /**
4539 * @throws Exception
@@ -119,17 +113,25 @@ private function processFile(string $inputFile): void
119113 }
120114 $ xml = new SimpleXMLElement ($ content );
121115 $ metrics = $ xml ->xpath ('//metrics ' );
116+
117+ $ totalConditionals = 0 ;
118+ $ totalStatements = 0 ;
119+ $ totalMethods = 0 ;
120+ $ coveredStatements = 0 ;
121+ $ coveredConditionals = 0 ;
122+ $ coveredMethods = 0 ;
123+
122124 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 ' ];
129131 }
130132
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 ;
133135 $ coverageRatio = $ totalElements ? $ coveredElements / $ totalElements : 0 ;
134136 $ this ->totalCoverage [] = (int ) round ($ coverageRatio * 100 );
135137
@@ -152,7 +154,7 @@ private function finalizeCoverage(): void
152154 throw new Exception ('Error reading badge template file ' );
153155 }
154156
155- $ template = str_replace ('{{ total }} ' , (string ) $ totalCoverage , $ template );
157+ $ template = str_replace ('{{ total }} ' , (string ) round ( $ totalCoverage) , $ template );
156158
157159 $ template = str_replace ('{{ coverage }} ' , $ this ->coverageName , $ template );
158160
0 commit comments