diff --git a/src/Node/AbstractNode.php b/src/Node/AbstractNode.php index f3608058e..2c2e2b689 100644 --- a/src/Node/AbstractNode.php +++ b/src/Node/AbstractNode.php @@ -165,7 +165,7 @@ public function getTestedTraitsPercent($asString = true) } /** - * Returns the percentage of traits that has been tested. + * Returns the percentage of classes and traits that has been tested. * * @param bool $asString * @@ -180,6 +180,22 @@ public function getTestedClassesAndTraitsPercent($asString = true) ); } + /** + * Returns the percentage of functions that has been tested. + * + * @param bool $asString + * + * @return int + */ + public function getTestedFunctionsPercent($asString = true) + { + return Util::percent( + $this->getNumTestedFunctions(), + $this->getNumFunctions(), + $asString + ); + } + /** * Returns the percentage of methods that has been tested. * @@ -196,6 +212,22 @@ public function getTestedMethodsPercent($asString = true) ); } + /** + * Returns the percentage of functions and methods that has been tested. + * + * @param bool $asString + * + * @return int + */ + public function getTestedFunctionsAndMethodsPercent($asString = true) + { + return Util::percent( + $this->getNumTestedFunctionsAndMethods(), + $this->getNumFunctionsAndMethods(), + $asString + ); + } + /** * Returns the percentage of executed lines. * @@ -242,6 +274,36 @@ public function getClassesAndTraits() return array_merge($this->getClasses(), $this->getTraits()); } + /** + * Returns the number of functions and methods. + * + * @return int + */ + public function getNumFunctionsAndMethods() + { + return $this->getNumFunctions() + $this->getNumMethods(); + } + + /** + * Returns the number of tested functions and methods. + * + * @return int + */ + public function getNumTestedFunctionsAndMethods() + { + return $this->getNumTestedFunctions() + $this->getNumTestedMethods(); + } + + /** + * Returns the functions and methods of this node. + * + * @return array + */ + public function getFunctionsAndMethods() + { + return array_merge($this->getFunctions(), $this->getMethods()); + } + /** * Returns the classes of this node. * diff --git a/src/Node/File.php b/src/Node/File.php index b94f20765..fca9c4556 100644 --- a/src/Node/File.php +++ b/src/Node/File.php @@ -531,6 +531,24 @@ protected function calculateStatistics() $class['coverage'] ); } + + foreach ($this->functions as &$function) { + if ($function['executableLines'] > 0) { + $function['coverage'] = ($function['executedLines'] / + $function['executableLines']) * 100; + } else { + $function['coverage'] = 100; + } + + if ($function['coverage'] == 100) { + $this->numTestedFunctions++; + } + + $function['crap'] = $this->crap( + $function['ccn'], + $function['coverage'] + ); + } } /** diff --git a/src/Report/Html/Renderer/Directory.php b/src/Report/Html/Renderer/Directory.php index a4b1b96f4..05595493b 100644 --- a/src/Report/Html/Renderer/Directory.php +++ b/src/Report/Html/Renderer/Directory.php @@ -59,14 +59,14 @@ protected function renderItem(Node $node, $total = false) $data = [ 'numClasses' => $node->getNumClassesAndTraits(), 'numTestedClasses' => $node->getNumTestedClassesAndTraits(), - 'numMethods' => $node->getNumMethods(), - 'numTestedMethods' => $node->getNumTestedMethods(), + 'numMethods' => $node->getNumFunctionsAndMethods(), + 'numTestedMethods' => $node->getNumTestedFunctionsAndMethods(), 'linesExecutedPercent' => $node->getLineExecutedPercent(false), 'linesExecutedPercentAsString' => $node->getLineExecutedPercent(), 'numExecutedLines' => $node->getNumExecutedLines(), 'numExecutableLines' => $node->getNumExecutableLines(), - 'testedMethodsPercent' => $node->getTestedMethodsPercent(false), - 'testedMethodsPercentAsString' => $node->getTestedMethodsPercent(), + 'testedMethodsPercent' => $node->getTestedFunctionsAndMethodsPercent(false), + 'testedMethodsPercentAsString' => $node->getTestedFunctionsAndMethodsPercent(), 'testedClassesPercent' => $node->getTestedClassesAndTraitsPercent(false), 'testedClassesPercentAsString' => $node->getTestedClassesAndTraitsPercent() ]; diff --git a/src/Report/Html/Renderer/File.php b/src/Report/Html/Renderer/File.php index e6b11ef03..254a39ded 100644 --- a/src/Report/Html/Renderer/File.php +++ b/src/Report/Html/Renderer/File.php @@ -88,14 +88,14 @@ protected function renderItems(FileNode $node) 'name' => 'Total', 'numClasses' => $node->getNumClassesAndTraits(), 'numTestedClasses' => $node->getNumTestedClassesAndTraits(), - 'numMethods' => $node->getNumMethods(), - 'numTestedMethods' => $node->getNumTestedMethods(), + 'numMethods' => $node->getNumFunctionsAndMethods(), + 'numTestedMethods' => $node->getNumTestedFunctionsAndMethods(), 'linesExecutedPercent' => $node->getLineExecutedPercent(false), 'linesExecutedPercentAsString' => $node->getLineExecutedPercent(), 'numExecutedLines' => $node->getNumExecutedLines(), 'numExecutableLines' => $node->getNumExecutableLines(), - 'testedMethodsPercent' => $node->getTestedMethodsPercent(false), - 'testedMethodsPercentAsString' => $node->getTestedMethodsPercent(), + 'testedMethodsPercent' => $node->getTestedFunctionsAndMethodsPercent(false), + 'testedMethodsPercentAsString' => $node->getTestedFunctionsAndMethodsPercent(), 'testedClassesPercent' => $node->getTestedClassesAndTraitsPercent(false), 'testedClassesPercentAsString' => $node->getTestedClassesAndTraitsPercent(), 'crap' => 'CRAP'