| Total Complexity | 6 |
| Total Lines | 107 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 24 | class DataIterator implements \Iterator |
||
| 25 | { |
||
| 26 | /** |
||
| 27 | * |
||
| 28 | * The data over which we are iterating. |
||
| 29 | * |
||
| 30 | * @var ArrayAccess<int|string, mixed> |
||
| 31 | * |
||
| 32 | */ |
||
| 33 | protected $data; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * |
||
| 37 | * The keys to iterate over in the Data object. |
||
| 38 | * |
||
| 39 | * @var array<int|string> |
||
| 40 | * |
||
| 41 | */ |
||
| 42 | protected $keys; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * |
||
| 46 | * Is the current iterator position valid? |
||
| 47 | * |
||
| 48 | * @var bool |
||
| 49 | * |
||
| 50 | */ |
||
| 51 | protected $valid; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * |
||
| 55 | * Constructor. |
||
| 56 | * |
||
| 57 | * @param ArrayAccess<int|string, mixed> $data The Data object over which to iterate. |
||
| 58 | * |
||
| 59 | * @param array<int|string> $keys The keys in the Data object. |
||
| 60 | * |
||
| 61 | */ |
||
| 62 | public function __construct(ArrayAccess $data, array $keys = []) |
||
| 66 | } |
||
| 67 | |||
| 68 | /** |
||
| 69 | * |
||
| 70 | * Returns the value at the current iterator position. |
||
| 71 | * |
||
| 72 | * @return mixed |
||
| 73 | * |
||
| 74 | */ |
||
| 75 | #[\ReturnTypeWillChange] |
||
| 76 | public function current() |
||
| 77 | { |
||
| 78 | return $this->data->offsetGet($this->key()); |
||
| 79 | } |
||
| 80 | |||
| 81 | /** |
||
| 82 | * |
||
| 83 | * Returns the current iterator position. |
||
| 84 | * |
||
| 85 | * @return mixed |
||
| 86 | * |
||
| 87 | */ |
||
| 88 | #[\ReturnTypeWillChange] |
||
| 89 | public function key() |
||
| 90 | { |
||
| 91 | return current($this->keys); |
||
| 92 | } |
||
| 93 | |||
| 94 | /** |
||
| 95 | * |
||
| 96 | * Moves the iterator to the next position. |
||
| 97 | * |
||
| 98 | * @return void |
||
| 99 | * |
||
| 100 | */ |
||
| 101 | #[\ReturnTypeWillChange] |
||
| 102 | public function next() |
||
| 103 | { |
||
| 104 | $this->valid = (next($this->keys) !== false); |
||
| 105 | } |
||
| 106 | |||
| 107 | /** |
||
| 108 | * |
||
| 109 | * Moves the iterator to the first position. |
||
| 110 | * |
||
| 111 | * @return void |
||
| 112 | * |
||
| 113 | */ |
||
| 114 | #[\ReturnTypeWillChange] |
||
| 115 | public function rewind() |
||
| 116 | { |
||
| 117 | $this->valid = (reset($this->keys) !== false); |
||
| 118 | } |
||
| 119 | |||
| 120 | /** |
||
| 121 | * |
||
| 122 | * Is the current iterator position valid? |
||
| 123 | * |
||
| 124 | * @return bool |
||
| 125 | * |
||
| 126 | */ |
||
| 127 | #[\ReturnTypeWillChange] |
||
| 131 | } |
||
| 132 | } |
||
| 133 |