1 | <?php |
||
2 | declare(strict_types=1); |
||
3 | /* |
||
4 | * Copyright (C) 2018 Sebastian Böttger <[email protected]> |
||
5 | * You may use, distribute and modify this code under the |
||
6 | * terms of the MIT license. |
||
7 | * |
||
8 | * You should have received a copy of the MIT license with |
||
9 | * this file. If not, please visit: https://opensource.org/licenses/mit-license.php |
||
10 | */ |
||
11 | |||
12 | namespace Seboettg\Collection\NativePhp; |
||
13 | |||
14 | /** |
||
15 | * Trait ArrayAccessTrait |
||
16 | * @package Seboettg\Collection\ArrayList |
||
17 | * @property $array Base array of this data structure |
||
18 | */ |
||
0 ignored issues
–
show
Documentation
Bug
introduced
by
![]() |
|||
19 | trait ArrayAccessTrait |
||
20 | { |
||
21 | |||
22 | /** |
||
23 | * Offset to retrieve |
||
24 | * @link http://php.net/manual/en/arrayaccess.offsetget.php |
||
25 | * @param mixed $offset The offset to retrieve. |
||
26 | * |
||
27 | * @return mixed Can return all value types. |
||
28 | */ |
||
29 | #[\ReturnTypeWillChange] |
||
30 | 4 | public function offsetGet($offset) |
|
31 | { |
||
32 | 4 | return $this->array[$offset] ?? null; |
|
33 | } |
||
34 | |||
35 | /** |
||
36 | * Offset to set |
||
37 | * @link http://php.net/manual/en/arrayaccess.offsetset.php |
||
38 | * @param mixed $offset The offset to assign the value to. |
||
39 | * @param mixed $value The value to set. |
||
40 | */ |
||
41 | #[\ReturnTypeWillChange] |
||
42 | 9 | public function offsetSet($offset, $value) |
|
43 | { |
||
44 | 9 | $this->array[$offset] = $value; |
|
0 ignored issues
–
show
|
|||
45 | 9 | } |
|
46 | |||
47 | /** |
||
48 | * Whether a offset exists |
||
49 | * @link http://php.net/manual/en/arrayaccess.offsetexists.php |
||
50 | * |
||
51 | * @param mixed $offset |
||
52 | * @return bool |
||
53 | */ |
||
54 | #[\ReturnTypeWillChange] |
||
55 | 2 | public function offsetExists($offset): bool |
|
56 | { |
||
57 | 2 | return isset($this->array[$offset]); |
|
58 | } |
||
59 | |||
60 | /** |
||
61 | * Offset to unset |
||
62 | * @link http://php.net/manual/en/arrayaccess.offsetunset.php |
||
63 | * @param mixed $offset The offset to unset. |
||
64 | */ |
||
65 | #[\ReturnTypeWillChange] |
||
66 | 1 | public function offsetUnset($offset): void |
|
67 | { |
||
68 | 1 | unset($this->array[$offset]); |
|
69 | 1 | } |
|
70 | } |
||
71 |