| Total Complexity | 13 |
| Total Lines | 114 |
| Duplicated Lines | 0 % |
| Coverage | 7.14% |
| Changes | 0 | ||
| 1 | <?php |
||
| 5 | abstract class Bag implements \Countable, \SeekableIterator, \Serializable, \JsonSerializable |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * |
||
| 9 | * @var array |
||
| 10 | */ |
||
| 11 | protected $data = []; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * |
||
| 15 | * @return int |
||
| 16 | */ |
||
| 17 | public function count(): int |
||
| 20 | } |
||
| 21 | |||
| 22 | |||
| 23 | /** |
||
| 24 | * |
||
| 25 | * @param int $key |
||
| 26 | * @return int |
||
| 27 | */ |
||
| 28 | public function seek($key) |
||
| 29 | { |
||
| 30 | if ($key >= count($this->data)) { |
||
| 31 | throw new \OutOfBoundsException; |
||
| 32 | } |
||
| 33 | |||
| 34 | $this->rewind(); |
||
| 35 | for ($i=0; $i<$key; $i++) { |
||
| 36 | $this->next(); |
||
| 37 | } |
||
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * |
||
| 42 | * @return mixed |
||
| 43 | */ |
||
| 44 | public function current() |
||
| 45 | { |
||
| 46 | return current($this->data); |
||
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * |
||
| 51 | * @return mixed |
||
| 52 | */ |
||
| 53 | public function next() |
||
| 54 | { |
||
| 55 | return next($this->data); |
||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * |
||
| 60 | * @return mixed |
||
| 61 | */ |
||
| 62 | public function key() |
||
| 65 | } |
||
| 66 | |||
| 67 | /** |
||
| 68 | * |
||
| 69 | * @return bool |
||
| 70 | */ |
||
| 71 | public function valid(): bool |
||
| 72 | { |
||
| 73 | return null !== key($this->data); |
||
| 74 | } |
||
| 75 | |||
| 76 | /** |
||
| 77 | * |
||
| 78 | * @return mixed |
||
| 79 | */ |
||
| 80 | public function rewind() |
||
| 81 | { |
||
| 82 | return reset($this->data); |
||
| 83 | } |
||
| 84 | |||
| 85 | /** |
||
| 86 | * |
||
| 87 | * @return string |
||
| 88 | */ |
||
| 89 | public function serialize(): string |
||
| 90 | { |
||
| 91 | return serialize($this->data); |
||
| 92 | } |
||
| 93 | |||
| 94 | /** |
||
| 95 | * |
||
| 96 | * @param string $serialized |
||
| 97 | */ |
||
| 98 | public function unserialize($serialized) |
||
| 101 | } |
||
| 102 | |||
| 103 | /** |
||
| 104 | * |
||
| 105 | * @return array |
||
| 106 | */ |
||
| 107 | public function jsonSerialize(): array |
||
| 108 | { |
||
| 109 | return $this->data; |
||
| 110 | } |
||
| 111 | |||
| 112 | /** |
||
| 113 | * |
||
| 114 | * @return array |
||
| 115 | */ |
||
| 116 | 18 | public function __toArray(): array |
|
| 119 | } |
||
| 120 | } |
||
| 121 |