]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/PHPUnit/PHP/CodeCoverage/Report/Node/Directory.php
Merge branch 'master' of github.com:sugarcrm/sugarcrm_dev
[Github/sugarcrm.git] / tests / PHPUnit / PHP / CodeCoverage / Report / Node / Directory.php
1 <?php
2 /**
3  * PHP_CodeCoverage
4  *
5  * Copyright (c) 2009-2011, Sebastian Bergmann <sb@sebastian-bergmann.de>.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  *   * Redistributions of source code must retain the above copyright
13  *     notice, this list of conditions and the following disclaimer.
14  *
15  *   * Redistributions in binary form must reproduce the above copyright
16  *     notice, this list of conditions and the following disclaimer in
17  *     the documentation and/or other materials provided with the
18  *     distribution.
19  *
20  *   * Neither the name of Sebastian Bergmann nor the names of his
21  *     contributors may be used to endorse or promote products derived
22  *     from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  *
37  * @category   PHP
38  * @package    CodeCoverage
39  * @author     Sebastian Bergmann <sb@sebastian-bergmann.de>
40  * @copyright  2009-2011 Sebastian Bergmann <sb@sebastian-bergmann.de>
41  * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
42  * @link       http://github.com/sebastianbergmann/php-code-coverage
43  * @since      File available since Release 1.1.0
44  */
45
46 /**
47  * Represents a directory in the code coverage information tree.
48  *
49  * @category   PHP
50  * @package    CodeCoverage
51  * @author     Sebastian Bergmann <sb@sebastian-bergmann.de>
52  * @copyright  2009-2011 Sebastian Bergmann <sb@sebastian-bergmann.de>
53  * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
54  * @version    Release: 1.1.1
55  * @link       http://github.com/sebastianbergmann/php-code-coverage
56  * @since      Class available since Release 1.1.0
57  */
58 class PHP_CodeCoverage_Report_Node_Directory extends PHP_CodeCoverage_Report_Node implements IteratorAggregate
59 {
60     /**
61      * @var PHP_CodeCoverage_Report_Node[]
62      */
63     protected $children = array();
64
65     /**
66      * @var PHP_CodeCoverage_Report_Node_Directory[]
67      */
68     protected $directories = array();
69
70     /**
71      * @var PHP_CodeCoverage_Report_Node_File[]
72      */
73     protected $files = array();
74
75     /**
76      * @var array
77      */
78     protected $classes;
79
80     /**
81      * @var array
82      */
83     protected $traits;
84
85     /**
86      * @var array
87      */
88     protected $functions;
89
90     /**
91      * @var array
92      */
93     protected $linesOfCode = NULL;
94
95     /**
96      * @var integer
97      */
98     protected $numFiles = -1;
99
100     /**
101      * @var integer
102      */
103     protected $numExecutableLines = -1;
104
105     /**
106      * @var integer
107      */
108     protected $numExecutedLines = -1;
109
110     /**
111      * @var integer
112      */
113     protected $numClasses = -1;
114
115     /**
116      * @var integer
117      */
118     protected $numTestedClasses = -1;
119
120     /**
121      * @var integer
122      */
123     protected $numTraits = -1;
124
125     /**
126      * @var integer
127      */
128     protected $numTestedTraits = -1;
129
130     /**
131      * @var integer
132      */
133     protected $numMethods = -1;
134
135     /**
136      * @var integer
137      */
138     protected $numTestedMethods = -1;
139
140     /**
141      * @var integer
142      */
143     protected $numFunctions = -1;
144
145     /**
146      * @var integer
147      */
148     protected $numTestedFunctions = -1;
149
150     /**
151      * Returns the number of files in/under this node.
152      *
153      * @return integer
154      */
155     public function count()
156     {
157         if ($this->numFiles == -1) {
158             $this->numFiles = 0;
159
160             foreach ($this->children as $child) {
161                 $this->numFiles += count($child);
162             }
163         }
164
165         return $this->numFiles;
166     }
167
168     /**
169      * Returns an iterator for this node.
170      *
171      * @return RecursiveIteratorIterator
172      */
173     public function getIterator()
174     {
175         return new RecursiveIteratorIterator(
176           new PHP_CodeCoverage_Report_Node_Iterator($this),
177           RecursiveIteratorIterator::SELF_FIRST
178         );
179     }
180
181     /**
182      * Adds a new directory.
183      *
184      * @param  string $name
185      * @return PHP_CodeCoverage_Report_Node_Directory
186      */
187     public function addDirectory($name)
188     {
189         $directory = new PHP_CodeCoverage_Report_Node_Directory($name, $this);
190
191         $this->children[]    = $directory;
192         $this->directories[] = &$this->children[count($this->children) - 1];
193
194         return $directory;
195     }
196
197     /**
198      * Adds a new file.
199      *
200      * @param  string  $name
201      * @param  array   $coverageData
202      * @param  array   $testData
203      * @param  boolean $cacheTokens
204      * @return PHP_CodeCoverage_Report_Node_File
205      * @throws PHP_CodeCoverage_Exception
206      */
207     public function addFile($name, array $coverageData, array $testData, $cacheTokens)
208     {
209         $file = new PHP_CodeCoverage_Report_Node_File(
210           $name, $this, $coverageData, $testData, $cacheTokens
211         );
212
213         $this->children[] = $file;
214         $this->files[]    = &$this->children[count($this->children) - 1];
215
216         $this->numExecutableLines = -1;
217         $this->numExecutedLines   = -1;
218
219         return $file;
220     }
221
222     /**
223      * Returns the directories in this directory.
224      *
225      * @return array
226      */
227     public function getDirectories()
228     {
229         return $this->directories;
230     }
231
232     /**
233      * Returns the files in this directory.
234      *
235      * @return array
236      */
237     public function getFiles()
238     {
239         return $this->files;
240     }
241
242     /**
243      * Returns the child nodes of this node.
244      *
245      * @return array
246      */
247     public function getChildNodes()
248     {
249         return $this->children;
250     }
251
252     /**
253      * Returns the classes of this node.
254      *
255      * @return array
256      */
257     public function getClasses()
258     {
259         if ($this->classes === NULL) {
260             $this->classes = array();
261
262             foreach ($this->children as $child) {
263                 $this->classes = array_merge(
264                   $this->classes, $child->getClasses()
265                 );
266             }
267         }
268
269         return $this->classes;
270     }
271
272     /**
273      * Returns the traits of this node.
274      *
275      * @return array
276      */
277     public function getTraits()
278     {
279         if ($this->traits === NULL) {
280             $this->traits = array();
281
282             foreach ($this->children as $child) {
283                 $this->traits = array_merge(
284                   $this->traits, $child->getTraits()
285                 );
286             }
287         }
288
289         return $this->traits;
290     }
291
292     /**
293      * Returns the functions of this node.
294      *
295      * @return array
296      */
297     public function getFunctions()
298     {
299         if ($this->functions === NULL) {
300             $this->functions = array();
301
302             foreach ($this->children as $child) {
303                 $this->functions = array_merge(
304                   $this->functions, $child->getFunctions()
305                 );
306             }
307         }
308
309         return $this->functions;
310     }
311
312     /**
313      * Returns the LOC/CLOC/NCLOC of this node.
314      *
315      * @return array
316      */
317     public function getLinesOfCode()
318     {
319         if ($this->linesOfCode === NULL) {
320             $this->linesOfCode = array('loc' => 0, 'cloc' => 0, 'ncloc' => 0);
321
322             foreach ($this->children as $child) {
323                 $linesOfCode = $child->getLinesOfCode();
324
325                 $this->linesOfCode['loc']   += $linesOfCode['loc'];
326                 $this->linesOfCode['cloc']  += $linesOfCode['cloc'];
327                 $this->linesOfCode['ncloc'] += $linesOfCode['ncloc'];
328             }
329         }
330
331         return $this->linesOfCode;
332     }
333
334     /**
335      * Returns the number of executable lines.
336      *
337      * @return integer
338      */
339     public function getNumExecutableLines()
340     {
341         if ($this->numExecutableLines == -1) {
342             $this->numExecutableLines = 0;
343
344             foreach ($this->children as $child) {
345                 $this->numExecutableLines += $child->getNumExecutableLines();
346             }
347         }
348
349         return $this->numExecutableLines;
350     }
351
352     /**
353      * Returns the number of executed lines.
354      *
355      * @return integer
356      */
357     public function getNumExecutedLines()
358     {
359         if ($this->numExecutedLines == -1) {
360             $this->numExecutedLines = 0;
361
362             foreach ($this->children as $child) {
363                 $this->numExecutedLines += $child->getNumExecutedLines();
364             }
365         }
366
367         return $this->numExecutedLines;
368     }
369
370     /**
371      * Returns the number of classes.
372      *
373      * @return integer
374      */
375     public function getNumClasses()
376     {
377         if ($this->numClasses == -1) {
378             $this->numClasses = 0;
379
380             foreach ($this->children as $child) {
381                 $this->numClasses += $child->getNumClasses();
382             }
383         }
384
385         return $this->numClasses;
386     }
387
388     /**
389      * Returns the number of tested classes.
390      *
391      * @return integer
392      */
393     public function getNumTestedClasses()
394     {
395         if ($this->numTestedClasses == -1) {
396             $this->numTestedClasses = 0;
397
398             foreach ($this->children as $child) {
399                 $this->numTestedClasses += $child->getNumTestedClasses();
400             }
401         }
402
403         return $this->numTestedClasses;
404     }
405
406     /**
407      * Returns the number of traits.
408      *
409      * @return integer
410      */
411     public function getNumTraits()
412     {
413         if ($this->numTraits == -1) {
414             $this->numTraits = 0;
415
416             foreach ($this->children as $child) {
417                 $this->numTraits += $child->getNumTraits();
418             }
419         }
420
421         return $this->numTraits;
422     }
423
424     /**
425      * Returns the number of tested traits.
426      *
427      * @return integer
428      */
429     public function getNumTestedTraits()
430     {
431         if ($this->numTestedTraits == -1) {
432             $this->numTestedTraits = 0;
433
434             foreach ($this->children as $child) {
435                 $this->numTestedTraits += $child->getNumTestedTraits();
436             }
437         }
438
439         return $this->numTestedTraits;
440     }
441
442     /**
443      * Returns the number of methods.
444      *
445      * @return integer
446      */
447     public function getNumMethods()
448     {
449         if ($this->numMethods == -1) {
450             $this->numMethods = 0;
451
452             foreach ($this->children as $child) {
453                 $this->numMethods += $child->getNumMethods();
454             }
455         }
456
457         return $this->numMethods;
458     }
459
460     /**
461      * Returns the number of tested methods.
462      *
463      * @return integer
464      */
465     public function getNumTestedMethods()
466     {
467         if ($this->numTestedMethods == -1) {
468             $this->numTestedMethods = 0;
469
470             foreach ($this->children as $child) {
471                 $this->numTestedMethods += $child->getNumTestedMethods();
472             }
473         }
474
475         return $this->numTestedMethods;
476     }
477
478     /**
479      * Returns the number of functions.
480      *
481      * @return integer
482      */
483     public function getNumFunctions()
484     {
485         if ($this->numFunctions == -1) {
486             $this->numFunctions = 0;
487
488             foreach ($this->children as $child) {
489                 $this->numFunctions += $child->getNumFunctions();
490             }
491         }
492
493         return $this->numFunctions;
494     }
495
496     /**
497      * Returns the number of tested functions.
498      *
499      * @return integer
500      */
501     public function getNumTestedFunctions()
502     {
503         if ($this->numTestedFunctions == -1) {
504             $this->numTestedFunctions = 0;
505
506             foreach ($this->children as $child) {
507                 $this->numTestedFunctions += $child->getNumTestedFunctions();
508             }
509         }
510
511         return $this->numTestedFunctions;
512     }
513 }