三叶草 XML 报告 - 类 和性状覆盖公式

Clover XML Report - Classes and Trait coverage formula

我正在开发一个自定义应用程序来解析 clover.xml 报告。 只是想知道是否有人知道哪个是获得 Classes and Traits 总覆盖率的正确公式。

这是我为 LinesFunctions&Methods 覆盖率找到的公式:

// TPC = (coveredconditionals + coveredstatements + coveredmethods) / (conditionals + statements + methods)
phpMetric.project = (((phpMetric.coveredconditionals + phpMetric.coveredstatements + phpMetric.coveredmethods) / (phpMetric.conditionals + phpMetric.statements + phpMetric.methods))) * 100;
// Lines coverage formula - LTPC = (coveredstatements / statements) * 100
phpMetric.lines =  ((phpMetric.coveredstatements / phpMetric.statements)* 100);
// Functions and Methods coverage formula - FMTPC = (coveredmethods / methods) * 100
phpMetric.functions =  ((phpMetric.coveredmethods / phpMetric.methods)* 100);

这是来自 clover.xml

metrics
<metrics files="10070" loc="1354443" ncloc="1110810" classes="8575" methods="46082" coveredmethods="31707" conditionals="0" coveredconditionals="0" statements="561696" coveredstatements="371009" elements="607778" coveredelements="402716"/>

更新: 我想从报告中提取的信息是 Classes and Traits 列,总覆盖率百分比。

谢谢!

我对三叶草一无所知,但是 - 如果我理解正确 - 你可以使用 php (在你的问题中标记)做如下的事情。显然,您可以根据需要修改它:

$cloverstr = <<<SOMEXML
<root>
   <metrics files="10070" loc="1354443" ncloc="1110810" classes="8575" methods="46082" coveredmethods="31707" conditionals="0" coveredconditionals="0" statements="561696" coveredstatements="371009" elements="607778" coveredelements="402716" />
</root>    
SOMEXML;
$xml  = simplexml_load_string ($cloverstr);

$coveredmethods = $xml->xpath("//metrics/@coveredmethods");
$methods = $xml->xpath("//metrics/@methods");

$coveredstatements = $xml->xpath("//metrics/@coveredstatements");
$statements = $xml->xpath("//metrics/@statements");

$coveredelements = $xml->xpath("//metrics/@coveredelements");
$elements = $xml->xpath("//metrics/@elements");

$TCP = ($coveredmethods[0] / $methods[0]) * 100;
$LTPC = ($coveredstatements[0] / $statements[0]) * 100;
$XYZ = ($coveredelements[0] / $elements[0]) * 100;

echo ("TCP: " . $TCP . ' </br> ');
echo ("LTPC: " . $LTPC . ' </br> ');
echo ("XYZ: " . $XYZ);

输出:

TCP: 68.805607395512 
 LTPC: 66.0515652595 
 XYZ: 66.260377966955