Skip to content

Commit 0c7c545

Browse files
committed
fix float rounding
1 parent b188700 commit 0c7c545

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

PHP/CodeCoverage/Report/Crap4j.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ public function process(PHP_CodeCoverage $coverage, $target = NULL, $name = NULL
106106
$methodNode->appendChild($document->createElement('methodName', $methodName));
107107
$methodNode->appendChild($document->createElement('methodSignature', htmlspecialchars($method['signature'])));
108108
$methodNode->appendChild($document->createElement('fullMethod', htmlspecialchars($method['signature'])));
109-
$methodNode->appendChild($document->createElement('crap', $crap));
109+
$methodNode->appendChild($document->createElement('crap', $this->roundValue($crap)));
110110
$methodNode->appendChild($document->createElement('complexity', $method['ccn']));
111-
$methodNode->appendChild($document->createElement('coverage', $coveragePercent));
112-
$methodNode->appendChild($document->createElement('crapLoad', $crapLoad));
111+
$methodNode->appendChild($document->createElement('coverage', $this->roundValue($coveragePercent)));
112+
$methodNode->appendChild($document->createElement('crapLoad', round($crapLoad)));
113113

114114
$methodsNode->appendChild($methodNode);
115115

@@ -127,9 +127,9 @@ public function process(PHP_CodeCoverage $coverage, $target = NULL, $name = NULL
127127

128128
$stats->appendChild($document->createElement('methodCount', $fullMethodCount));
129129
$stats->appendChild($document->createElement('crapMethodCount', $fullCrapMethodCount));
130-
$stats->appendChild($document->createElement('crapLoad', $fullCrapLoad));
130+
$stats->appendChild($document->createElement('crapLoad', round($fullCrapLoad)));
131131
$stats->appendChild($document->createElement('totalCrap', $fullCrap));
132-
$stats->appendChild($document->createElement('crapMethodPercent', 100 * $fullCrapMethodCount / $fullMethodCount));
132+
$stats->appendChild($document->createElement('crapMethodPercent', $this->roundValue(100 * $fullCrapMethodCount / $fullMethodCount)));
133133

134134
$root->appendChild($stats);
135135
$root->appendChild($methodsNode);
@@ -196,4 +196,9 @@ public function getCrapLoad($crapValue, $cyclomaticComplexity, $coveragePercent)
196196
}
197197
return $crapLoad;
198198
}
199+
200+
private function roundValue($value)
201+
{
202+
return round($value, 2);
203+
}
199204
}

0 commit comments

Comments
 (0)