| Total Complexity | 7 |
| Total Lines | 42 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 13 | class TraversableObject implements \Iterator, \Countable |
||
| 14 | { |
||
| 15 | protected array $data = []; |
||
| 16 | |||
| 17 | private int $position = 0; |
||
| 18 | |||
| 19 | public function __construct(array $array) |
||
| 20 | { |
||
| 21 | $this->data = $array; |
||
| 22 | } |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @throws \Exception |
||
| 26 | */ |
||
| 27 | public function count() |
||
| 28 | { |
||
| 29 | throw new \Exception('Count called on object that should only be traversed.'); |
||
| 30 | } |
||
| 31 | |||
| 32 | public function current() |
||
| 33 | { |
||
| 34 | return $this->data[$this->position]; |
||
| 35 | } |
||
| 36 | |||
| 37 | public function next() |
||
| 38 | { |
||
| 39 | $this->position++; |
||
| 40 | } |
||
| 41 | |||
| 42 | public function key() |
||
| 45 | } |
||
| 46 | |||
| 47 | public function valid() |
||
| 48 | { |
||
| 49 | return array_key_exists($this->position, $this->data); |
||
| 50 | } |
||
| 51 | |||
| 52 | public function rewind() |
||
| 55 | } |
||
| 56 | } |
||
| 57 |