db backup prior to drupal security update
[yaffs-website] / vendor / phpunit / php-code-coverage / src / CodeCoverage / Report / Node / Iterator.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  * Recursive iterator for PHP_CodeCoverage_Report_Node object graphs.
13  *
14  * @since Class available since Release 1.1.0
15  */
16 class PHP_CodeCoverage_Report_Node_Iterator implements RecursiveIterator
17 {
18     /**
19      * @var int
20      */
21     protected $position;
22
23     /**
24      * @var PHP_CodeCoverage_Report_Node[]
25      */
26     protected $nodes;
27
28     /**
29      * Constructor.
30      *
31      * @param PHP_CodeCoverage_Report_Node_Directory $node
32      */
33     public function __construct(PHP_CodeCoverage_Report_Node_Directory $node)
34     {
35         $this->nodes = $node->getChildNodes();
36     }
37
38     /**
39      * Rewinds the Iterator to the first element.
40      */
41     public function rewind()
42     {
43         $this->position = 0;
44     }
45
46     /**
47      * Checks if there is a current element after calls to rewind() or next().
48      *
49      * @return bool
50      */
51     public function valid()
52     {
53         return $this->position < count($this->nodes);
54     }
55
56     /**
57      * Returns the key of the current element.
58      *
59      * @return int
60      */
61     public function key()
62     {
63         return $this->position;
64     }
65
66     /**
67      * Returns the current element.
68      *
69      * @return PHPUnit_Framework_Test
70      */
71     public function current()
72     {
73         return $this->valid() ? $this->nodes[$this->position] : null;
74     }
75
76     /**
77      * Moves forward to next element.
78      */
79     public function next()
80     {
81         $this->position++;
82     }
83
84     /**
85      * Returns the sub iterator for the current element.
86      *
87      * @return PHP_CodeCoverage_Report_Node_Iterator
88      */
89     public function getChildren()
90     {
91         return new self(
92             $this->nodes[$this->position]
93         );
94     }
95
96     /**
97      * Checks whether the current element has children.
98      *
99      * @return bool
100      */
101     public function hasChildren()
102     {
103         return $this->nodes[$this->position] instanceof PHP_CodeCoverage_Report_Node_Directory;
104     }
105 }