upgrade zend (#1559)
[openemr.git] / vendor / phpunit / php-code-coverage / src / Node / Directory.php
blob6a9f28db58649733a4067b43e7ef370396c86ace
1 <?php
2 /*
3 * This file is part of the php-code-coverage 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.
9 */
11 namespace SebastianBergmann\CodeCoverage\Node;
13 use SebastianBergmann\CodeCoverage\InvalidArgumentException;
15 /**
16 * Represents a directory in the code coverage information tree.
18 class Directory extends AbstractNode implements \IteratorAggregate
20 /**
21 * @var AbstractNode[]
23 private $children = [];
25 /**
26 * @var Directory[]
28 private $directories = [];
30 /**
31 * @var File[]
33 private $files = [];
35 /**
36 * @var array
38 private $classes;
40 /**
41 * @var array
43 private $traits;
45 /**
46 * @var array
48 private $functions;
50 /**
51 * @var array
53 private $linesOfCode = null;
55 /**
56 * @var int
58 private $numFiles = -1;
60 /**
61 * @var int
63 private $numExecutableLines = -1;
65 /**
66 * @var int
68 private $numExecutedLines = -1;
70 /**
71 * @var int
73 private $numClasses = -1;
75 /**
76 * @var int
78 private $numTestedClasses = -1;
80 /**
81 * @var int
83 private $numTraits = -1;
85 /**
86 * @var int
88 private $numTestedTraits = -1;
90 /**
91 * @var int
93 private $numMethods = -1;
95 /**
96 * @var int
98 private $numTestedMethods = -1;
101 * @var int
103 private $numFunctions = -1;
106 * @var int
108 private $numTestedFunctions = -1;
111 * Returns the number of files in/under this node.
113 * @return int
115 public function count()
117 if ($this->numFiles == -1) {
118 $this->numFiles = 0;
120 foreach ($this->children as $child) {
121 $this->numFiles += count($child);
125 return $this->numFiles;
129 * Returns an iterator for this node.
131 * @return \RecursiveIteratorIterator
133 public function getIterator()
135 return new \RecursiveIteratorIterator(
136 new Iterator($this),
137 \RecursiveIteratorIterator::SELF_FIRST
142 * Adds a new directory.
144 * @param string $name
146 * @return Directory
148 public function addDirectory($name)
150 $directory = new self($name, $this);
152 $this->children[] = $directory;
153 $this->directories[] = &$this->children[count($this->children) - 1];
155 return $directory;
159 * Adds a new file.
161 * @param string $name
162 * @param array $coverageData
163 * @param array $testData
164 * @param bool $cacheTokens
166 * @return File
168 * @throws InvalidArgumentException
170 public function addFile($name, array $coverageData, array $testData, $cacheTokens)
172 $file = new File(
173 $name,
174 $this,
175 $coverageData,
176 $testData,
177 $cacheTokens
180 $this->children[] = $file;
181 $this->files[] = &$this->children[count($this->children) - 1];
183 $this->numExecutableLines = -1;
184 $this->numExecutedLines = -1;
186 return $file;
190 * Returns the directories in this directory.
192 * @return array
194 public function getDirectories()
196 return $this->directories;
200 * Returns the files in this directory.
202 * @return array
204 public function getFiles()
206 return $this->files;
210 * Returns the child nodes of this node.
212 * @return array
214 public function getChildNodes()
216 return $this->children;
220 * Returns the classes of this node.
222 * @return array
224 public function getClasses()
226 if ($this->classes === null) {
227 $this->classes = [];
229 foreach ($this->children as $child) {
230 $this->classes = array_merge(
231 $this->classes,
232 $child->getClasses()
237 return $this->classes;
241 * Returns the traits of this node.
243 * @return array
245 public function getTraits()
247 if ($this->traits === null) {
248 $this->traits = [];
250 foreach ($this->children as $child) {
251 $this->traits = array_merge(
252 $this->traits,
253 $child->getTraits()
258 return $this->traits;
262 * Returns the functions of this node.
264 * @return array
266 public function getFunctions()
268 if ($this->functions === null) {
269 $this->functions = [];
271 foreach ($this->children as $child) {
272 $this->functions = array_merge(
273 $this->functions,
274 $child->getFunctions()
279 return $this->functions;
283 * Returns the LOC/CLOC/NCLOC of this node.
285 * @return array
287 public function getLinesOfCode()
289 if ($this->linesOfCode === null) {
290 $this->linesOfCode = ['loc' => 0, 'cloc' => 0, 'ncloc' => 0];
292 foreach ($this->children as $child) {
293 $linesOfCode = $child->getLinesOfCode();
295 $this->linesOfCode['loc'] += $linesOfCode['loc'];
296 $this->linesOfCode['cloc'] += $linesOfCode['cloc'];
297 $this->linesOfCode['ncloc'] += $linesOfCode['ncloc'];
301 return $this->linesOfCode;
305 * Returns the number of executable lines.
307 * @return int
309 public function getNumExecutableLines()
311 if ($this->numExecutableLines == -1) {
312 $this->numExecutableLines = 0;
314 foreach ($this->children as $child) {
315 $this->numExecutableLines += $child->getNumExecutableLines();
319 return $this->numExecutableLines;
323 * Returns the number of executed lines.
325 * @return int
327 public function getNumExecutedLines()
329 if ($this->numExecutedLines == -1) {
330 $this->numExecutedLines = 0;
332 foreach ($this->children as $child) {
333 $this->numExecutedLines += $child->getNumExecutedLines();
337 return $this->numExecutedLines;
341 * Returns the number of classes.
343 * @return int
345 public function getNumClasses()
347 if ($this->numClasses == -1) {
348 $this->numClasses = 0;
350 foreach ($this->children as $child) {
351 $this->numClasses += $child->getNumClasses();
355 return $this->numClasses;
359 * Returns the number of tested classes.
361 * @return int
363 public function getNumTestedClasses()
365 if ($this->numTestedClasses == -1) {
366 $this->numTestedClasses = 0;
368 foreach ($this->children as $child) {
369 $this->numTestedClasses += $child->getNumTestedClasses();
373 return $this->numTestedClasses;
377 * Returns the number of traits.
379 * @return int
381 public function getNumTraits()
383 if ($this->numTraits == -1) {
384 $this->numTraits = 0;
386 foreach ($this->children as $child) {
387 $this->numTraits += $child->getNumTraits();
391 return $this->numTraits;
395 * Returns the number of tested traits.
397 * @return int
399 public function getNumTestedTraits()
401 if ($this->numTestedTraits == -1) {
402 $this->numTestedTraits = 0;
404 foreach ($this->children as $child) {
405 $this->numTestedTraits += $child->getNumTestedTraits();
409 return $this->numTestedTraits;
413 * Returns the number of methods.
415 * @return int
417 public function getNumMethods()
419 if ($this->numMethods == -1) {
420 $this->numMethods = 0;
422 foreach ($this->children as $child) {
423 $this->numMethods += $child->getNumMethods();
427 return $this->numMethods;
431 * Returns the number of tested methods.
433 * @return int
435 public function getNumTestedMethods()
437 if ($this->numTestedMethods == -1) {
438 $this->numTestedMethods = 0;
440 foreach ($this->children as $child) {
441 $this->numTestedMethods += $child->getNumTestedMethods();
445 return $this->numTestedMethods;
449 * Returns the number of functions.
451 * @return int
453 public function getNumFunctions()
455 if ($this->numFunctions == -1) {
456 $this->numFunctions = 0;
458 foreach ($this->children as $child) {
459 $this->numFunctions += $child->getNumFunctions();
463 return $this->numFunctions;
467 * Returns the number of tested functions.
469 * @return int
471 public function getNumTestedFunctions()
473 if ($this->numTestedFunctions == -1) {
474 $this->numTestedFunctions = 0;
476 foreach ($this->children as $child) {
477 $this->numTestedFunctions += $child->getNumTestedFunctions();
481 return $this->numTestedFunctions;