| Total Complexity | 9 |
| Total Lines | 75 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 10 | class Circular implements \Iterator |
||
| 11 | { |
||
| 12 | /** @var array */ |
||
| 13 | protected $data; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * Circular constructor. |
||
| 17 | * @param array $data |
||
| 18 | */ |
||
| 19 | 4 | public function __construct(array $data) |
|
| 20 | { |
||
| 21 | 4 | $this->data = $data; |
|
| 22 | 4 | reset($this->data); |
|
| 23 | 4 | } |
|
| 24 | |||
| 25 | /** |
||
| 26 | * @return mixed |
||
| 27 | */ |
||
| 28 | 1 | public function __invoke() |
|
| 29 | { |
||
| 30 | 1 | return $this->getElement(); |
|
| 31 | } |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @return mixed |
||
| 35 | */ |
||
| 36 | 2 | public function getElement() |
|
| 37 | { |
||
| 38 | 2 | if (false === $result = current($this->data)) { |
|
| 39 | 2 | $result = reset($this->data); |
|
| 40 | } |
||
| 41 | 2 | next($this->data); |
|
| 42 | |||
| 43 | 2 | return $result; |
|
| 44 | } |
||
| 45 | |||
| 46 | /** |
||
| 47 | * {@inheritdoc} |
||
| 48 | */ |
||
| 49 | 2 | public function current() |
|
| 50 | { |
||
| 51 | 2 | return current($this->data); |
|
| 52 | } |
||
| 53 | |||
| 54 | /** |
||
| 55 | * {@inheritdoc} |
||
| 56 | */ |
||
| 57 | 2 | public function next(): void |
|
| 58 | { |
||
| 59 | 2 | next($this->data); |
|
| 60 | 2 | } |
|
| 61 | |||
| 62 | /** |
||
| 63 | * {@inheritdoc} |
||
| 64 | */ |
||
| 65 | 2 | public function key() |
|
| 66 | { |
||
| 67 | 2 | return key($this->data); |
|
| 68 | } |
||
| 69 | |||
| 70 | /** |
||
| 71 | * {@inheritdoc} |
||
| 72 | */ |
||
| 73 | 2 | public function valid(): bool |
|
| 74 | { |
||
| 75 | return |
||
| 76 | 2 | false !== current($this->data); |
|
| 77 | } |
||
| 78 | |||
| 79 | /** |
||
| 80 | * {@inheritdoc} |
||
| 81 | */ |
||
| 82 | 2 | public function rewind(): void |
|
| 85 | 2 | } |
|
| 86 | } |
||
| 87 |