1313use function file_put_contents ;
1414use function round ;
1515use function str_replace ;
16+ use function var_dump ;
1617
1718/**
1819 * Class BadgeComposer
@@ -34,12 +35,6 @@ class BadgeComposer
3435 * @var int[]
3536 */
3637 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 ;
4338
4439 /**
4540 * @throws Exception
@@ -119,17 +114,25 @@ private function processFile(string $inputFile): void
119114 }
120115 $ xml = new SimpleXMLElement ($ content );
121116 $ metrics = $ xml ->xpath ('//metrics ' );
117+
118+ $ totalConditionals = 0 ;
119+ $ totalStatements = 0 ;
120+ $ totalMethods = 0 ;
121+ $ coveredStatements = 0 ;
122+ $ coveredConditionals = 0 ;
123+ $ coveredMethods = 0 ;
124+
122125 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 ' ];
129132 }
130133
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 ;
133136 $ coverageRatio = $ totalElements ? $ coveredElements / $ totalElements : 0 ;
134137 $ this ->totalCoverage [] = (int ) round ($ coverageRatio * 100 );
135138
@@ -145,14 +148,15 @@ private function processFile(string $inputFile): void
145148 */
146149 private function finalizeCoverage (): void
147150 {
151+ var_dump ($ this ->totalCoverage );
148152 $ totalCoverage = $ this ->getTotalCoverage () / count ($ this ->inputFiles ); // Average coverage across all files
149153 $ template = file_get_contents ($ this ->badgeTemplate );
150154
151155 if ($ template === false ) {
152156 throw new Exception ('Error reading badge template file ' );
153157 }
154158
155- $ template = str_replace ('{{ total }} ' , (string ) $ totalCoverage , $ template );
159+ $ template = str_replace ('{{ total }} ' , (string ) round ( $ totalCoverage) , $ template );
156160
157161 $ template = str_replace ('{{ coverage }} ' , $ this ->coverageName , $ template );
158162
0 commit comments