44
55use SimpleXMLElement ;
66
7+ /**
8+ * Calculation reference https://confluence.atlassian.com/pages/viewpage.action?pageId=79986990
9+ * So in order to calculate the Total Percentage Coverage metric using data from an XML report
10+ * you have to use the following equation:
11+ *
12+ * TPC = (coveredconditionals + coveredstatements + coveredmethods) / (conditionals + statements + methods)
13+ *
14+ * Using elements is incorrect as according to that page notes, "elements" is conditionals + statements,
15+ * which means including them in the calculation would double-count statements.
16+ */
717class CloverParser
818{
919 /** @var array<string> */
@@ -52,14 +62,12 @@ protected function reset(): void
5262 'methods ' => 0 ,
5363 'conditionals ' => 0 ,
5464 'statements ' => 0 ,
55- 'elements ' => 0 ,
5665 ];
5766
5867 $ this ->coveredTotals = [
5968 'coveredmethods ' => 0 ,
6069 'coveredconditionals ' => 0 ,
6170 'coveredstatements ' => 0 ,
62- 'coveredelements ' => 0 ,
6371 ];
6472
6573 $ this ->hasCalculatedTotals = false ;
@@ -77,13 +85,6 @@ public function calculateTotals(): self
7785
7886 continue ;
7987 }
80-
81- foreach ($ project ->xpath ('//file ' ) as $ file ) {
82- // no other way of seeing if the element exists?
83- if ($ file ->metrics ->count () > 0 ) {
84- $ this ->incrementTotalsWithMetrics ($ file ->metrics );
85- }
86- }
8788 }
8889 }
8990
@@ -105,8 +106,6 @@ protected function incrementTotalsWithMetrics(SimpleXMLElement $metrics): void
105106 $ this ->coveredTotals ['coveredconditionals ' ] += (int ) $ metrics ['coveredconditionals ' ];
106107 $ this ->totals ['statements ' ] += (int ) $ metrics ['statements ' ];
107108 $ this ->coveredTotals ['coveredstatements ' ] += (int ) $ metrics ['coveredstatements ' ];
108- $ this ->totals ['elements ' ] += (int ) $ metrics ['elements ' ];
109- $ this ->coveredTotals ['coveredelements ' ] += (int ) $ metrics ['coveredelements ' ];
110109 }
111110
112111 public function getPercentage (): float
0 commit comments