1 | <?php |
||||
2 | |||||
3 | namespace Zurbaev\ApiClient\Traits; |
||||
4 | |||||
5 | /** |
||||
6 | * Trait LazyArrayAccess |
||||
7 | * |
||||
8 | * @property array $items |
||||
9 | * @property array $keys |
||||
10 | */ |
||||
11 | trait LazyArrayAccess |
||||
12 | { |
||||
13 | /** |
||||
14 | * Determines if given offset exists in current collection. |
||||
15 | * |
||||
16 | * @param mixed $offset |
||||
17 | * |
||||
18 | * @return bool |
||||
19 | */ |
||||
20 | public function offsetExists($offset) |
||||
21 | { |
||||
22 | $this->checkLazyLoad(); |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
23 | |||||
24 | return isset($this->items[$offset]); |
||||
25 | } |
||||
26 | |||||
27 | /** |
||||
28 | * Puts value to given offset or appends it to current collection. |
||||
29 | * |
||||
30 | * @param mixed $offset |
||||
31 | * @param mixed $value |
||||
32 | */ |
||||
33 | View Code Duplication | public function offsetSet($offset, $value) |
|||
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||||
34 | { |
||||
35 | $this->checkLazyLoad(); |
||||
0 ignored issues
–
show
It seems like
checkLazyLoad() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
36 | |||||
37 | if (is_null($offset)) { |
||||
38 | $this->items[] = $value; |
||||
39 | } else { |
||||
40 | $this->items[$offset] = $value; |
||||
41 | } |
||||
42 | |||||
43 | $this->keys = array_keys($this->items); |
||||
44 | } |
||||
45 | |||||
46 | /** |
||||
47 | * Retrieves given offset from current collection. |
||||
48 | * Returns NULL if no value found. |
||||
49 | * |
||||
50 | * @param mixed $offset |
||||
51 | * |
||||
52 | * @return mixed|null |
||||
53 | */ |
||||
54 | public function offsetGet($offset) |
||||
55 | { |
||||
56 | $this->checkLazyLoad(); |
||||
0 ignored issues
–
show
It seems like
checkLazyLoad() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
57 | |||||
58 | return isset($this->items[$offset]) ? $this->items[$offset] : null; |
||||
59 | } |
||||
60 | |||||
61 | /** |
||||
62 | * Drops given offset from current collection. |
||||
63 | * |
||||
64 | * @param mixed $offset |
||||
65 | */ |
||||
66 | public function offsetUnset($offset) |
||||
67 | { |
||||
68 | $this->checkLazyLoad(); |
||||
0 ignored issues
–
show
It seems like
checkLazyLoad() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
69 | |||||
70 | unset($this->items[$offset]); |
||||
71 | |||||
72 | $this->keys = array_keys($this->items); |
||||
73 | } |
||||
74 | } |
||||
75 |