3 * This file is part of the PHP_CodeCoverage package.
5 * (c) Sebastian Bergmann <sebastian@phpunit.de>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
12 * Base class for nodes in the code coverage information tree.
14 * @since Class available since Release 1.1.0
16 abstract class PHP_CodeCoverage_Report_Node implements Countable
34 * @var PHP_CodeCoverage_Report_Node
47 * @param PHP_CodeCoverage_Report_Node $parent
49 public function __construct($name, PHP_CodeCoverage_Report_Node $parent = null)
51 if (substr($name, -1) == '/') {
52 $name = substr($name, 0, -1);
56 $this->parent = $parent;
62 public function getName()
70 public function getId()
72 if ($this->id === null) {
73 $parent = $this->getParent();
75 if ($parent === null) {
78 $parentId = $parent->getId();
80 if ($parentId == 'index') {
81 $this->id = str_replace(':', '_', $this->name);
83 $this->id = $parentId . '/' . $this->name;
94 public function getPath()
96 if ($this->path === null) {
97 if ($this->parent === null || $this->parent->getPath() === null || $this->parent->getPath() === false) {
98 $this->path = $this->name;
100 $this->path = $this->parent->getPath() . '/' . $this->name;
110 public function getPathAsArray()
112 if ($this->pathArray === null) {
113 if ($this->parent === null) {
114 $this->pathArray = array();
116 $this->pathArray = $this->parent->getPathAsArray();
119 $this->pathArray[] = $this;
122 return $this->pathArray;
126 * @return PHP_CodeCoverage_Report_Node
128 public function getParent()
130 return $this->parent;
134 * Returns the percentage of classes that has been tested.
136 * @param bool $asString
139 public function getTestedClassesPercent($asString = true)
141 return PHP_CodeCoverage_Util::percent(
142 $this->getNumTestedClasses(),
143 $this->getNumClasses(),
149 * Returns the percentage of traits that has been tested.
151 * @param bool $asString
154 public function getTestedTraitsPercent($asString = true)
156 return PHP_CodeCoverage_Util::percent(
157 $this->getNumTestedTraits(),
158 $this->getNumTraits(),
164 * Returns the percentage of traits that has been tested.
166 * @param bool $asString
168 * @since Method available since Release 1.2.0
170 public function getTestedClassesAndTraitsPercent($asString = true)
172 return PHP_CodeCoverage_Util::percent(
173 $this->getNumTestedClassesAndTraits(),
174 $this->getNumClassesAndTraits(),
180 * Returns the percentage of methods that has been tested.
182 * @param bool $asString
185 public function getTestedMethodsPercent($asString = true)
187 return PHP_CodeCoverage_Util::percent(
188 $this->getNumTestedMethods(),
189 $this->getNumMethods(),
195 * Returns the percentage of executed lines.
197 * @param bool $asString
200 public function getLineExecutedPercent($asString = true)
202 return PHP_CodeCoverage_Util::percent(
203 $this->getNumExecutedLines(),
204 $this->getNumExecutableLines(),
210 * Returns the number of classes and traits.
213 * @since Method available since Release 1.2.0
215 public function getNumClassesAndTraits()
217 return $this->getNumClasses() + $this->getNumTraits();
221 * Returns the number of tested classes and traits.
224 * @since Method available since Release 1.2.0
226 public function getNumTestedClassesAndTraits()
228 return $this->getNumTestedClasses() + $this->getNumTestedTraits();
232 * Returns the classes and traits of this node.
235 * @since Method available since Release 1.2.0
237 public function getClassesAndTraits()
239 return array_merge($this->getClasses(), $this->getTraits());
243 * Returns the classes of this node.
247 abstract public function getClasses();
250 * Returns the traits of this node.
254 abstract public function getTraits();
257 * Returns the functions of this node.
261 abstract public function getFunctions();
264 * Returns the LOC/CLOC/NCLOC of this node.
268 abstract public function getLinesOfCode();
271 * Returns the number of executable lines.
275 abstract public function getNumExecutableLines();
278 * Returns the number of executed lines.
282 abstract public function getNumExecutedLines();
285 * Returns the number of classes.
289 abstract public function getNumClasses();
292 * Returns the number of tested classes.
296 abstract public function getNumTestedClasses();
299 * Returns the number of traits.
303 abstract public function getNumTraits();
306 * Returns the number of tested traits.
310 abstract public function getNumTestedTraits();
313 * Returns the number of methods.
317 abstract public function getNumMethods();
320 * Returns the number of tested methods.
324 abstract public function getNumTestedMethods();
327 * Returns the number of functions.
331 abstract public function getNumFunctions();
334 * Returns the number of tested functions.
338 abstract public function getNumTestedFunctions();