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 * Represents a directory in the code coverage information tree.
14 * @since Class available since Release 1.1.0
16 class PHP_CodeCoverage_Report_Node_Directory extends PHP_CodeCoverage_Report_Node implements IteratorAggregate
19 * @var PHP_CodeCoverage_Report_Node[]
21 protected $children = array();
24 * @var PHP_CodeCoverage_Report_Node_Directory[]
26 protected $directories = array();
29 * @var PHP_CodeCoverage_Report_Node_File[]
31 protected $files = array();
51 protected $linesOfCode = null;
56 protected $numFiles = -1;
61 protected $numExecutableLines = -1;
66 protected $numExecutedLines = -1;
71 protected $numClasses = -1;
76 protected $numTestedClasses = -1;
81 protected $numTraits = -1;
86 protected $numTestedTraits = -1;
91 protected $numMethods = -1;
96 protected $numTestedMethods = -1;
101 protected $numFunctions = -1;
106 protected $numTestedFunctions = -1;
109 * Returns the number of files in/under this node.
113 public function count()
115 if ($this->numFiles == -1) {
118 foreach ($this->children as $child) {
119 $this->numFiles += count($child);
123 return $this->numFiles;
127 * Returns an iterator for this node.
129 * @return RecursiveIteratorIterator
131 public function getIterator()
133 return new RecursiveIteratorIterator(
134 new PHP_CodeCoverage_Report_Node_Iterator($this),
135 RecursiveIteratorIterator::SELF_FIRST
140 * Adds a new directory.
142 * @param string $name
143 * @return PHP_CodeCoverage_Report_Node_Directory
145 public function addDirectory($name)
147 $directory = new self($name, $this);
149 $this->children[] = $directory;
150 $this->directories[] = &$this->children[count($this->children) - 1];
158 * @param string $name
159 * @param array $coverageData
160 * @param array $testData
161 * @param bool $cacheTokens
162 * @return PHP_CodeCoverage_Report_Node_File
163 * @throws PHP_CodeCoverage_Exception
165 public function addFile($name, array $coverageData, array $testData, $cacheTokens)
167 $file = new PHP_CodeCoverage_Report_Node_File(
175 $this->children[] = $file;
176 $this->files[] = &$this->children[count($this->children) - 1];
178 $this->numExecutableLines = -1;
179 $this->numExecutedLines = -1;
185 * Returns the directories in this directory.
189 public function getDirectories()
191 return $this->directories;
195 * Returns the files in this directory.
199 public function getFiles()
205 * Returns the child nodes of this node.
209 public function getChildNodes()
211 return $this->children;
215 * Returns the classes of this node.
219 public function getClasses()
221 if ($this->classes === null) {
222 $this->classes = array();
224 foreach ($this->children as $child) {
225 $this->classes = array_merge(
232 return $this->classes;
236 * Returns the traits of this node.
240 public function getTraits()
242 if ($this->traits === null) {
243 $this->traits = array();
245 foreach ($this->children as $child) {
246 $this->traits = array_merge(
253 return $this->traits;
257 * Returns the functions of this node.
261 public function getFunctions()
263 if ($this->functions === null) {
264 $this->functions = array();
266 foreach ($this->children as $child) {
267 $this->functions = array_merge(
269 $child->getFunctions()
274 return $this->functions;
278 * Returns the LOC/CLOC/NCLOC of this node.
282 public function getLinesOfCode()
284 if ($this->linesOfCode === null) {
285 $this->linesOfCode = array('loc' => 0, 'cloc' => 0, 'ncloc' => 0);
287 foreach ($this->children as $child) {
288 $linesOfCode = $child->getLinesOfCode();
290 $this->linesOfCode['loc'] += $linesOfCode['loc'];
291 $this->linesOfCode['cloc'] += $linesOfCode['cloc'];
292 $this->linesOfCode['ncloc'] += $linesOfCode['ncloc'];
296 return $this->linesOfCode;
300 * Returns the number of executable lines.
304 public function getNumExecutableLines()
306 if ($this->numExecutableLines == -1) {
307 $this->numExecutableLines = 0;
309 foreach ($this->children as $child) {
310 $this->numExecutableLines += $child->getNumExecutableLines();
314 return $this->numExecutableLines;
318 * Returns the number of executed lines.
322 public function getNumExecutedLines()
324 if ($this->numExecutedLines == -1) {
325 $this->numExecutedLines = 0;
327 foreach ($this->children as $child) {
328 $this->numExecutedLines += $child->getNumExecutedLines();
332 return $this->numExecutedLines;
336 * Returns the number of classes.
340 public function getNumClasses()
342 if ($this->numClasses == -1) {
343 $this->numClasses = 0;
345 foreach ($this->children as $child) {
346 $this->numClasses += $child->getNumClasses();
350 return $this->numClasses;
354 * Returns the number of tested classes.
358 public function getNumTestedClasses()
360 if ($this->numTestedClasses == -1) {
361 $this->numTestedClasses = 0;
363 foreach ($this->children as $child) {
364 $this->numTestedClasses += $child->getNumTestedClasses();
368 return $this->numTestedClasses;
372 * Returns the number of traits.
376 public function getNumTraits()
378 if ($this->numTraits == -1) {
379 $this->numTraits = 0;
381 foreach ($this->children as $child) {
382 $this->numTraits += $child->getNumTraits();
386 return $this->numTraits;
390 * Returns the number of tested traits.
394 public function getNumTestedTraits()
396 if ($this->numTestedTraits == -1) {
397 $this->numTestedTraits = 0;
399 foreach ($this->children as $child) {
400 $this->numTestedTraits += $child->getNumTestedTraits();
404 return $this->numTestedTraits;
408 * Returns the number of methods.
412 public function getNumMethods()
414 if ($this->numMethods == -1) {
415 $this->numMethods = 0;
417 foreach ($this->children as $child) {
418 $this->numMethods += $child->getNumMethods();
422 return $this->numMethods;
426 * Returns the number of tested methods.
430 public function getNumTestedMethods()
432 if ($this->numTestedMethods == -1) {
433 $this->numTestedMethods = 0;
435 foreach ($this->children as $child) {
436 $this->numTestedMethods += $child->getNumTestedMethods();
440 return $this->numTestedMethods;
444 * Returns the number of functions.
448 public function getNumFunctions()
450 if ($this->numFunctions == -1) {
451 $this->numFunctions = 0;
453 foreach ($this->children as $child) {
454 $this->numFunctions += $child->getNumFunctions();
458 return $this->numFunctions;
462 * Returns the number of tested functions.
466 public function getNumTestedFunctions()
468 if ($this->numTestedFunctions == -1) {
469 $this->numTestedFunctions = 0;
471 foreach ($this->children as $child) {
472 $this->numTestedFunctions += $child->getNumTestedFunctions();
476 return $this->numTestedFunctions;