Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: /** Chris@0: * Base class for nodes in the code coverage information tree. Chris@0: * Chris@0: * @since Class available since Release 1.1.0 Chris@0: */ Chris@0: abstract class PHP_CodeCoverage_Report_Node implements Countable Chris@0: { Chris@0: /** Chris@0: * @var string Chris@0: */ Chris@0: protected $name; Chris@0: Chris@0: /** Chris@0: * @var string Chris@0: */ Chris@0: protected $path; Chris@0: Chris@0: /** Chris@0: * @var array Chris@0: */ Chris@0: protected $pathArray; Chris@0: Chris@0: /** Chris@0: * @var PHP_CodeCoverage_Report_Node Chris@0: */ Chris@0: protected $parent; Chris@0: Chris@0: /** Chris@0: * @var string Chris@0: */ Chris@0: protected $id; Chris@0: Chris@0: /** Chris@0: * Constructor. Chris@0: * Chris@0: * @param string $name Chris@0: * @param PHP_CodeCoverage_Report_Node $parent Chris@0: */ Chris@0: public function __construct($name, PHP_CodeCoverage_Report_Node $parent = null) Chris@0: { Chris@0: if (substr($name, -1) == '/') { Chris@0: $name = substr($name, 0, -1); Chris@0: } Chris@0: Chris@0: $this->name = $name; Chris@0: $this->parent = $parent; Chris@0: } Chris@0: Chris@0: /** Chris@0: * @return string Chris@0: */ Chris@0: public function getName() Chris@0: { Chris@0: return $this->name; Chris@0: } Chris@0: Chris@0: /** Chris@0: * @return string Chris@0: */ Chris@0: public function getId() Chris@0: { Chris@0: if ($this->id === null) { Chris@0: $parent = $this->getParent(); Chris@0: Chris@0: if ($parent === null) { Chris@0: $this->id = 'index'; Chris@0: } else { Chris@0: $parentId = $parent->getId(); Chris@0: Chris@0: if ($parentId == 'index') { Chris@0: $this->id = str_replace(':', '_', $this->name); Chris@0: } else { Chris@0: $this->id = $parentId . '/' . $this->name; Chris@0: } Chris@0: } Chris@0: } Chris@0: Chris@0: return $this->id; Chris@0: } Chris@0: Chris@0: /** Chris@0: * @return string Chris@0: */ Chris@0: public function getPath() Chris@0: { Chris@0: if ($this->path === null) { Chris@0: if ($this->parent === null || $this->parent->getPath() === null || $this->parent->getPath() === false) { Chris@0: $this->path = $this->name; Chris@0: } else { Chris@0: $this->path = $this->parent->getPath() . '/' . $this->name; Chris@0: } Chris@0: } Chris@0: Chris@0: return $this->path; Chris@0: } Chris@0: Chris@0: /** Chris@0: * @return array Chris@0: */ Chris@0: public function getPathAsArray() Chris@0: { Chris@0: if ($this->pathArray === null) { Chris@0: if ($this->parent === null) { Chris@0: $this->pathArray = array(); Chris@0: } else { Chris@0: $this->pathArray = $this->parent->getPathAsArray(); Chris@0: } Chris@0: Chris@0: $this->pathArray[] = $this; Chris@0: } Chris@0: Chris@0: return $this->pathArray; Chris@0: } Chris@0: Chris@0: /** Chris@0: * @return PHP_CodeCoverage_Report_Node Chris@0: */ Chris@0: public function getParent() Chris@0: { Chris@0: return $this->parent; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the percentage of classes that has been tested. Chris@0: * Chris@0: * @param bool $asString Chris@0: * @return int Chris@0: */ Chris@0: public function getTestedClassesPercent($asString = true) Chris@0: { Chris@0: return PHP_CodeCoverage_Util::percent( Chris@0: $this->getNumTestedClasses(), Chris@0: $this->getNumClasses(), Chris@0: $asString Chris@0: ); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the percentage of traits that has been tested. Chris@0: * Chris@0: * @param bool $asString Chris@0: * @return int Chris@0: */ Chris@0: public function getTestedTraitsPercent($asString = true) Chris@0: { Chris@0: return PHP_CodeCoverage_Util::percent( Chris@0: $this->getNumTestedTraits(), Chris@0: $this->getNumTraits(), Chris@0: $asString Chris@0: ); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the percentage of traits that has been tested. Chris@0: * Chris@0: * @param bool $asString Chris@0: * @return int Chris@0: * @since Method available since Release 1.2.0 Chris@0: */ Chris@0: public function getTestedClassesAndTraitsPercent($asString = true) Chris@0: { Chris@0: return PHP_CodeCoverage_Util::percent( Chris@0: $this->getNumTestedClassesAndTraits(), Chris@0: $this->getNumClassesAndTraits(), Chris@0: $asString Chris@0: ); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the percentage of methods that has been tested. Chris@0: * Chris@0: * @param bool $asString Chris@0: * @return int Chris@0: */ Chris@0: public function getTestedMethodsPercent($asString = true) Chris@0: { Chris@0: return PHP_CodeCoverage_Util::percent( Chris@0: $this->getNumTestedMethods(), Chris@0: $this->getNumMethods(), Chris@0: $asString Chris@0: ); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the percentage of executed lines. Chris@0: * Chris@0: * @param bool $asString Chris@0: * @return int Chris@0: */ Chris@0: public function getLineExecutedPercent($asString = true) Chris@0: { Chris@0: return PHP_CodeCoverage_Util::percent( Chris@0: $this->getNumExecutedLines(), Chris@0: $this->getNumExecutableLines(), Chris@0: $asString Chris@0: ); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the number of classes and traits. Chris@0: * Chris@0: * @return int Chris@0: * @since Method available since Release 1.2.0 Chris@0: */ Chris@0: public function getNumClassesAndTraits() Chris@0: { Chris@0: return $this->getNumClasses() + $this->getNumTraits(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the number of tested classes and traits. Chris@0: * Chris@0: * @return int Chris@0: * @since Method available since Release 1.2.0 Chris@0: */ Chris@0: public function getNumTestedClassesAndTraits() Chris@0: { Chris@0: return $this->getNumTestedClasses() + $this->getNumTestedTraits(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the classes and traits of this node. Chris@0: * Chris@0: * @return array Chris@0: * @since Method available since Release 1.2.0 Chris@0: */ Chris@0: public function getClassesAndTraits() Chris@0: { Chris@0: return array_merge($this->getClasses(), $this->getTraits()); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the classes of this node. Chris@0: * Chris@0: * @return array Chris@0: */ Chris@0: abstract public function getClasses(); Chris@0: Chris@0: /** Chris@0: * Returns the traits of this node. Chris@0: * Chris@0: * @return array Chris@0: */ Chris@0: abstract public function getTraits(); Chris@0: Chris@0: /** Chris@0: * Returns the functions of this node. Chris@0: * Chris@0: * @return array Chris@0: */ Chris@0: abstract public function getFunctions(); Chris@0: Chris@0: /** Chris@0: * Returns the LOC/CLOC/NCLOC of this node. Chris@0: * Chris@0: * @return array Chris@0: */ Chris@0: abstract public function getLinesOfCode(); Chris@0: Chris@0: /** Chris@0: * Returns the number of executable lines. Chris@0: * Chris@0: * @return int Chris@0: */ Chris@0: abstract public function getNumExecutableLines(); Chris@0: Chris@0: /** Chris@0: * Returns the number of executed lines. Chris@0: * Chris@0: * @return int Chris@0: */ Chris@0: abstract public function getNumExecutedLines(); Chris@0: Chris@0: /** Chris@0: * Returns the number of classes. Chris@0: * Chris@0: * @return int Chris@0: */ Chris@0: abstract public function getNumClasses(); Chris@0: Chris@0: /** Chris@0: * Returns the number of tested classes. Chris@0: * Chris@0: * @return int Chris@0: */ Chris@0: abstract public function getNumTestedClasses(); Chris@0: Chris@0: /** Chris@0: * Returns the number of traits. Chris@0: * Chris@0: * @return int Chris@0: */ Chris@0: abstract public function getNumTraits(); Chris@0: Chris@0: /** Chris@0: * Returns the number of tested traits. Chris@0: * Chris@0: * @return int Chris@0: */ Chris@0: abstract public function getNumTestedTraits(); Chris@0: Chris@0: /** Chris@0: * Returns the number of methods. Chris@0: * Chris@0: * @return int Chris@0: */ Chris@0: abstract public function getNumMethods(); Chris@0: Chris@0: /** Chris@0: * Returns the number of tested methods. Chris@0: * Chris@0: * @return int Chris@0: */ Chris@0: abstract public function getNumTestedMethods(); Chris@0: Chris@0: /** Chris@0: * Returns the number of functions. Chris@0: * Chris@0: * @return int Chris@0: */ Chris@0: abstract public function getNumFunctions(); Chris@0: Chris@0: /** Chris@0: * Returns the number of tested functions. Chris@0: * Chris@0: * @return int Chris@0: */ Chris@0: abstract public function getNumTestedFunctions(); Chris@0: }