Mercurial > hg > isophonics-drupal-site
annotate vendor/phpunit/php-code-coverage/src/Node/Iterator.php @ 19:fa3358dc1485 tip
Add ndrum files
author | Chris Cannam |
---|---|
date | Wed, 28 Aug 2019 13:14:47 +0100 |
parents | 1fec387a4317 |
children |
rev | line source |
---|---|
Chris@14 | 1 <?php |
Chris@14 | 2 /* |
Chris@14 | 3 * This file is part of the php-code-coverage package. |
Chris@14 | 4 * |
Chris@14 | 5 * (c) Sebastian Bergmann <sebastian@phpunit.de> |
Chris@14 | 6 * |
Chris@14 | 7 * For the full copyright and license information, please view the LICENSE |
Chris@14 | 8 * file that was distributed with this source code. |
Chris@14 | 9 */ |
Chris@14 | 10 |
Chris@14 | 11 namespace SebastianBergmann\CodeCoverage\Node; |
Chris@14 | 12 |
Chris@14 | 13 /** |
Chris@14 | 14 * Recursive iterator for node object graphs. |
Chris@14 | 15 */ |
Chris@14 | 16 class Iterator implements \RecursiveIterator |
Chris@14 | 17 { |
Chris@14 | 18 /** |
Chris@14 | 19 * @var int |
Chris@14 | 20 */ |
Chris@14 | 21 private $position; |
Chris@14 | 22 |
Chris@14 | 23 /** |
Chris@14 | 24 * @var AbstractNode[] |
Chris@14 | 25 */ |
Chris@14 | 26 private $nodes; |
Chris@14 | 27 |
Chris@14 | 28 /** |
Chris@14 | 29 * @param Directory $node |
Chris@14 | 30 */ |
Chris@14 | 31 public function __construct(Directory $node) |
Chris@14 | 32 { |
Chris@14 | 33 $this->nodes = $node->getChildNodes(); |
Chris@14 | 34 } |
Chris@14 | 35 |
Chris@14 | 36 /** |
Chris@14 | 37 * Rewinds the Iterator to the first element. |
Chris@14 | 38 */ |
Chris@14 | 39 public function rewind() |
Chris@14 | 40 { |
Chris@14 | 41 $this->position = 0; |
Chris@14 | 42 } |
Chris@14 | 43 |
Chris@14 | 44 /** |
Chris@14 | 45 * Checks if there is a current element after calls to rewind() or next(). |
Chris@14 | 46 * |
Chris@14 | 47 * @return bool |
Chris@14 | 48 */ |
Chris@14 | 49 public function valid() |
Chris@14 | 50 { |
Chris@14 | 51 return $this->position < \count($this->nodes); |
Chris@14 | 52 } |
Chris@14 | 53 |
Chris@14 | 54 /** |
Chris@14 | 55 * Returns the key of the current element. |
Chris@14 | 56 * |
Chris@14 | 57 * @return int |
Chris@14 | 58 */ |
Chris@14 | 59 public function key() |
Chris@14 | 60 { |
Chris@14 | 61 return $this->position; |
Chris@14 | 62 } |
Chris@14 | 63 |
Chris@14 | 64 /** |
Chris@14 | 65 * Returns the current element. |
Chris@14 | 66 * |
Chris@14 | 67 * @return \PHPUnit_Framework_Test |
Chris@14 | 68 */ |
Chris@14 | 69 public function current() |
Chris@14 | 70 { |
Chris@14 | 71 return $this->valid() ? $this->nodes[$this->position] : null; |
Chris@14 | 72 } |
Chris@14 | 73 |
Chris@14 | 74 /** |
Chris@14 | 75 * Moves forward to next element. |
Chris@14 | 76 */ |
Chris@14 | 77 public function next() |
Chris@14 | 78 { |
Chris@14 | 79 $this->position++; |
Chris@14 | 80 } |
Chris@14 | 81 |
Chris@14 | 82 /** |
Chris@14 | 83 * Returns the sub iterator for the current element. |
Chris@14 | 84 * |
Chris@14 | 85 * @return Iterator |
Chris@14 | 86 */ |
Chris@14 | 87 public function getChildren() |
Chris@14 | 88 { |
Chris@14 | 89 return new self( |
Chris@14 | 90 $this->nodes[$this->position] |
Chris@14 | 91 ); |
Chris@14 | 92 } |
Chris@14 | 93 |
Chris@14 | 94 /** |
Chris@14 | 95 * Checks whether the current element has children. |
Chris@14 | 96 * |
Chris@14 | 97 * @return bool |
Chris@14 | 98 */ |
Chris@14 | 99 public function hasChildren() |
Chris@14 | 100 { |
Chris@14 | 101 return $this->nodes[$this->position] instanceof Directory; |
Chris@14 | 102 } |
Chris@14 | 103 } |