@@ -29,9 +29,13 @@ class BadgeComposer
2929 private string $ outputFile ;
3030 private string $ coverageName ;
3131 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 ;
3539
3640 /**
3741 * @throws Exception
@@ -52,7 +56,7 @@ public function __construct(string $inputFiles, string $outputFile, string $cove
5256 */
5357 public function getTotalCoverage (): int
5458 {
55- return $ this ->totalCoverage ;
59+ return array_sum ( $ this ->totalCoverage ) ;
5660 }
5761
5862 /**
@@ -112,12 +116,18 @@ private function processFile(string $inputFile): void
112116 $ xml = new SimpleXMLElement ($ content );
113117 $ metrics = $ xml ->xpath ('//metrics ' );
114118 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 ' ];
117125 }
118126
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 );
121131
122132 } catch (Throwable $ e ) {
123133 throw new Exception ($ e ->getMessage ());
@@ -131,7 +141,7 @@ private function processFile(string $inputFile): void
131141 */
132142 private function finalizeCoverage (): void
133143 {
134- $ totalCoverage = $ this ->totalCoverage / count ($ this ->inputFiles ); // Average coverage across all files
144+ $ totalCoverage = $ this ->getTotalCoverage () / count ($ this ->inputFiles ); // Average coverage across all files
135145 $ template = file_get_contents ($ this ->badgeTemplate );
136146
137147 if ($ template === false ) {
0 commit comments