Total Complexity | 10 |
Total Lines | 61 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php namespace Mbh\Collection\Traits\Sequenceable; |
||
14 | trait ArrayAccess |
||
15 | { |
||
16 | protected $sfa = null; |
||
17 | |||
18 | /** |
||
19 | * Create an fixed array |
||
20 | * |
||
21 | * @param Traversable $array data |
||
22 | */ |
||
23 | protected function __construct(Traversable $array) |
||
24 | { |
||
25 | $this->sfa = $array; |
||
26 | $this->checkCapacity(); |
||
|
|||
27 | } |
||
28 | |||
29 | /** |
||
30 | * ArrayAccess |
||
31 | */ |
||
32 | public function offsetExists($offset): bool |
||
33 | { |
||
34 | return is_integer($offset) |
||
35 | && $this->validIndex($offset) |
||
36 | && $this->sfa->offsetExists($offset); |
||
37 | } |
||
38 | |||
39 | public function offsetGet($offset) |
||
40 | { |
||
41 | return $this->sfa->offsetGet($offset); |
||
42 | } |
||
43 | |||
44 | public function offsetSet($offset, $value) |
||
50 | } |
||
51 | } |
||
52 | |||
53 | public function offsetUnset($offset) |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * Adds zero or more values to the end of the sequence. |
||
61 | * |
||
62 | * @param mixed ...$values |
||
63 | */ |
||
64 | abstract public function push(...$values); |
||
65 | |||
66 | /** |
||
67 | * Replaces the value at a given index in the sequence with a new value. |
||
68 | * |
||
69 | * @param int $index |
||
70 | * @param mixed $value |
||
71 | * |
||
72 | * @throws OutOfRangeException if the index is not in the range [0, size-1] |
||
73 | */ |
||
74 | abstract public function set(int $index, $value); |
||
75 | } |
||
76 |