dd71ecb57b41377973855813db1a07e36118b40b
[yaffs-website] / vendor / phpunit / php-code-coverage / src / CodeCoverage / Report / Node / Directory.php
1 <?php
2 /*
3  * This file is part of the PHP_CodeCoverage package.
4  *
5  * (c) Sebastian Bergmann <sebastian@phpunit.de>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 /**
12  * Represents a directory in the code coverage information tree.
13  *
14  * @since Class available since Release 1.1.0
15  */
16 class PHP_CodeCoverage_Report_Node_Directory extends PHP_CodeCoverage_Report_Node implements IteratorAggregate
17 {
18     /**
19      * @var PHP_CodeCoverage_Report_Node[]
20      */
21     protected $children = array();
22
23     /**
24      * @var PHP_CodeCoverage_Report_Node_Directory[]
25      */
26     protected $directories = array();
27
28     /**
29      * @var PHP_CodeCoverage_Report_Node_File[]
30      */
31     protected $files = array();
32
33     /**
34      * @var array
35      */
36     protected $classes;
37
38     /**
39      * @var array
40      */
41     protected $traits;
42
43     /**
44      * @var array
45      */
46     protected $functions;
47
48     /**
49      * @var array
50      */
51     protected $linesOfCode = null;
52
53     /**
54      * @var int
55      */
56     protected $numFiles = -1;
57
58     /**
59      * @var int
60      */
61     protected $numExecutableLines = -1;
62
63     /**
64      * @var int
65      */
66     protected $numExecutedLines = -1;
67
68     /**
69      * @var int
70      */
71     protected $numClasses = -1;
72
73     /**
74      * @var int
75      */
76     protected $numTestedClasses = -1;
77
78     /**
79      * @var int
80      */
81     protected $numTraits = -1;
82
83     /**
84      * @var int
85      */
86     protected $numTestedTraits = -1;
87
88     /**
89      * @var int
90      */
91     protected $numMethods = -1;
92
93     /**
94      * @var int
95      */
96     protected $numTestedMethods = -1;
97
98     /**
99      * @var int
100      */
101     protected $numFunctions = -1;
102
103     /**
104      * @var int
105      */
106     protected $numTestedFunctions = -1;
107
108     /**
109      * Returns the number of files in/under this node.
110      *
111      * @return int
112      */
113     public function count()
114     {
115         if ($this->numFiles == -1) {
116             $this->numFiles = 0;
117
118             foreach ($this->children as $child) {
119                 $this->numFiles += count($child);
120             }
121         }
122
123         return $this->numFiles;
124     }
125
126     /**
127      * Returns an iterator for this node.
128      *
129      * @return RecursiveIteratorIterator
130      */
131     public function getIterator()
132     {
133         return new RecursiveIteratorIterator(
134             new PHP_CodeCoverage_Report_Node_Iterator($this),
135             RecursiveIteratorIterator::SELF_FIRST
136         );
137     }
138
139     /**
140      * Adds a new directory.
141      *
142      * @param  string                                 $name
143      * @return PHP_CodeCoverage_Report_Node_Directory
144      */
145     public function addDirectory($name)
146     {
147         $directory = new self($name, $this);
148
149         $this->children[]    = $directory;
150         $this->directories[] = &$this->children[count($this->children) - 1];
151
152         return $directory;
153     }
154
155     /**
156      * Adds a new file.
157      *
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
164      */
165     public function addFile($name, array $coverageData, array $testData, $cacheTokens)
166     {
167         $file = new PHP_CodeCoverage_Report_Node_File(
168             $name,
169             $this,
170             $coverageData,
171             $testData,
172             $cacheTokens
173         );
174
175         $this->children[] = $file;
176         $this->files[]    = &$this->children[count($this->children) - 1];
177
178         $this->numExecutableLines = -1;
179         $this->numExecutedLines   = -1;
180
181         return $file;
182     }
183
184     /**
185      * Returns the directories in this directory.
186      *
187      * @return array
188      */
189     public function getDirectories()
190     {
191         return $this->directories;
192     }
193
194     /**
195      * Returns the files in this directory.
196      *
197      * @return array
198      */
199     public function getFiles()
200     {
201         return $this->files;
202     }
203
204     /**
205      * Returns the child nodes of this node.
206      *
207      * @return array
208      */
209     public function getChildNodes()
210     {
211         return $this->children;
212     }
213
214     /**
215      * Returns the classes of this node.
216      *
217      * @return array
218      */
219     public function getClasses()
220     {
221         if ($this->classes === null) {
222             $this->classes = array();
223
224             foreach ($this->children as $child) {
225                 $this->classes = array_merge(
226                     $this->classes,
227                     $child->getClasses()
228                 );
229             }
230         }
231
232         return $this->classes;
233     }
234
235     /**
236      * Returns the traits of this node.
237      *
238      * @return array
239      */
240     public function getTraits()
241     {
242         if ($this->traits === null) {
243             $this->traits = array();
244
245             foreach ($this->children as $child) {
246                 $this->traits = array_merge(
247                     $this->traits,
248                     $child->getTraits()
249                 );
250             }
251         }
252
253         return $this->traits;
254     }
255
256     /**
257      * Returns the functions of this node.
258      *
259      * @return array
260      */
261     public function getFunctions()
262     {
263         if ($this->functions === null) {
264             $this->functions = array();
265
266             foreach ($this->children as $child) {
267                 $this->functions = array_merge(
268                     $this->functions,
269                     $child->getFunctions()
270                 );
271             }
272         }
273
274         return $this->functions;
275     }
276
277     /**
278      * Returns the LOC/CLOC/NCLOC of this node.
279      *
280      * @return array
281      */
282     public function getLinesOfCode()
283     {
284         if ($this->linesOfCode === null) {
285             $this->linesOfCode = array('loc' => 0, 'cloc' => 0, 'ncloc' => 0);
286
287             foreach ($this->children as $child) {
288                 $linesOfCode = $child->getLinesOfCode();
289
290                 $this->linesOfCode['loc']   += $linesOfCode['loc'];
291                 $this->linesOfCode['cloc']  += $linesOfCode['cloc'];
292                 $this->linesOfCode['ncloc'] += $linesOfCode['ncloc'];
293             }
294         }
295
296         return $this->linesOfCode;
297     }
298
299     /**
300      * Returns the number of executable lines.
301      *
302      * @return int
303      */
304     public function getNumExecutableLines()
305     {
306         if ($this->numExecutableLines == -1) {
307             $this->numExecutableLines = 0;
308
309             foreach ($this->children as $child) {
310                 $this->numExecutableLines += $child->getNumExecutableLines();
311             }
312         }
313
314         return $this->numExecutableLines;
315     }
316
317     /**
318      * Returns the number of executed lines.
319      *
320      * @return int
321      */
322     public function getNumExecutedLines()
323     {
324         if ($this->numExecutedLines == -1) {
325             $this->numExecutedLines = 0;
326
327             foreach ($this->children as $child) {
328                 $this->numExecutedLines += $child->getNumExecutedLines();
329             }
330         }
331
332         return $this->numExecutedLines;
333     }
334
335     /**
336      * Returns the number of classes.
337      *
338      * @return int
339      */
340     public function getNumClasses()
341     {
342         if ($this->numClasses == -1) {
343             $this->numClasses = 0;
344
345             foreach ($this->children as $child) {
346                 $this->numClasses += $child->getNumClasses();
347             }
348         }
349
350         return $this->numClasses;
351     }
352
353     /**
354      * Returns the number of tested classes.
355      *
356      * @return int
357      */
358     public function getNumTestedClasses()
359     {
360         if ($this->numTestedClasses == -1) {
361             $this->numTestedClasses = 0;
362
363             foreach ($this->children as $child) {
364                 $this->numTestedClasses += $child->getNumTestedClasses();
365             }
366         }
367
368         return $this->numTestedClasses;
369     }
370
371     /**
372      * Returns the number of traits.
373      *
374      * @return int
375      */
376     public function getNumTraits()
377     {
378         if ($this->numTraits == -1) {
379             $this->numTraits = 0;
380
381             foreach ($this->children as $child) {
382                 $this->numTraits += $child->getNumTraits();
383             }
384         }
385
386         return $this->numTraits;
387     }
388
389     /**
390      * Returns the number of tested traits.
391      *
392      * @return int
393      */
394     public function getNumTestedTraits()
395     {
396         if ($this->numTestedTraits == -1) {
397             $this->numTestedTraits = 0;
398
399             foreach ($this->children as $child) {
400                 $this->numTestedTraits += $child->getNumTestedTraits();
401             }
402         }
403
404         return $this->numTestedTraits;
405     }
406
407     /**
408      * Returns the number of methods.
409      *
410      * @return int
411      */
412     public function getNumMethods()
413     {
414         if ($this->numMethods == -1) {
415             $this->numMethods = 0;
416
417             foreach ($this->children as $child) {
418                 $this->numMethods += $child->getNumMethods();
419             }
420         }
421
422         return $this->numMethods;
423     }
424
425     /**
426      * Returns the number of tested methods.
427      *
428      * @return int
429      */
430     public function getNumTestedMethods()
431     {
432         if ($this->numTestedMethods == -1) {
433             $this->numTestedMethods = 0;
434
435             foreach ($this->children as $child) {
436                 $this->numTestedMethods += $child->getNumTestedMethods();
437             }
438         }
439
440         return $this->numTestedMethods;
441     }
442
443     /**
444      * Returns the number of functions.
445      *
446      * @return int
447      */
448     public function getNumFunctions()
449     {
450         if ($this->numFunctions == -1) {
451             $this->numFunctions = 0;
452
453             foreach ($this->children as $child) {
454                 $this->numFunctions += $child->getNumFunctions();
455             }
456         }
457
458         return $this->numFunctions;
459     }
460
461     /**
462      * Returns the number of tested functions.
463      *
464      * @return int
465      */
466     public function getNumTestedFunctions()
467     {
468         if ($this->numTestedFunctions == -1) {
469             $this->numTestedFunctions = 0;
470
471             foreach ($this->children as $child) {
472                 $this->numTestedFunctions += $child->getNumTestedFunctions();
473             }
474         }
475
476         return $this->numTestedFunctions;
477     }
478 }