| Total Complexity | 7 |
| Total Lines | 42 |
| Duplicated Lines | 0 % |
| Coverage | 68.75% |
| Changes | 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 | 45 | public function current() |
|
| 33 | { |
||
| 34 | 45 | return $this->data[$this->position]; |
|
| 35 | } |
||
| 36 | |||
| 37 | 45 | public function next() |
|
| 38 | { |
||
| 39 | 45 | $this->position++; |
|
| 40 | 45 | } |
|
| 41 | |||
| 42 | 44 | public function key() |
|
| 45 | } |
||
| 46 | |||
| 47 | 45 | public function valid() |
|
| 48 | { |
||
| 49 | 45 | return array_key_exists($this->position, $this->data); |
|
| 50 | } |
||
| 51 | |||
| 52 | 45 | public function rewind() |
|
| 55 | 45 | } |
|
| 56 | } |
||
| 57 |