| Total Complexity | 8 |
| Total Lines | 75 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 11 | class BaseCollection implements ArrayAccess, \IteratorAggregate, \Countable |
||
| 12 | { |
||
| 13 | protected $items = []; |
||
| 14 | |||
| 15 | public function __construct(array $items = []) |
||
| 16 | { |
||
| 17 | $this->items = $items; |
||
| 18 | } |
||
| 19 | |||
| 20 | public function getIterator() |
||
| 21 | { |
||
| 22 | return new ArrayIterator($this->items); |
||
| 23 | } |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Count the number of items in the collection. |
||
| 27 | * |
||
| 28 | * @return int |
||
| 29 | */ |
||
| 30 | public function count() |
||
| 31 | { |
||
| 32 | return count($this->items); |
||
| 33 | } |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Determine if an item exists at an offset. |
||
| 37 | * |
||
| 38 | * @param mixed $key |
||
| 39 | * |
||
| 40 | * @return bool |
||
| 41 | */ |
||
| 42 | public function offsetExists($key) |
||
| 43 | { |
||
| 44 | return array_key_exists($key, $this->items); |
||
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Get an item at a given offset. |
||
| 49 | * |
||
| 50 | * @param mixed $key |
||
| 51 | * |
||
| 52 | * @return mixed |
||
| 53 | */ |
||
| 54 | public function offsetGet($key) |
||
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Set the item at a given offset. |
||
| 61 | * |
||
| 62 | * @param mixed $key |
||
| 63 | * @param mixed $value |
||
| 64 | * |
||
| 65 | * @return void |
||
| 66 | */ |
||
| 67 | public function offsetSet($key, $value) |
||
| 68 | { |
||
| 69 | if (is_null($key)) { |
||
| 70 | $this->items[] = $value; |
||
| 71 | } else { |
||
| 72 | $this->items[$key] = $value; |
||
| 73 | } |
||
| 74 | } |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Unset the item at a given offset. |
||
| 78 | * |
||
| 79 | * @param string $key |
||
| 80 | * |
||
| 81 | * @return void |
||
| 82 | */ |
||
| 83 | public function offsetUnset($key) |
||
| 86 | } |
||
| 87 | |||
| 88 | } |
||
| 89 |