This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Weew\Collections; |
||
4 | |||
5 | use ArrayIterator; |
||
6 | use Weew\Contracts\IArrayable; |
||
7 | |||
8 | class Dictionary implements IDictionary { |
||
9 | /** |
||
10 | * @var array |
||
11 | */ |
||
12 | protected $items; |
||
13 | |||
14 | /** |
||
15 | * @param array $items |
||
16 | */ |
||
17 | public function __construct(array $items = []) { |
||
18 | $this->setItems($items); |
||
19 | } |
||
20 | |||
21 | /** |
||
22 | * @param $key |
||
23 | * @param null $default |
||
24 | * |
||
25 | * @return mixed |
||
26 | */ |
||
27 | public function get($key, $default = null) { |
||
28 | return array_get($this->items, $key, $default); |
||
29 | } |
||
30 | |||
31 | /** |
||
32 | * @param $key |
||
33 | * @param mixed $value |
||
34 | */ |
||
35 | public function set($key, $value) { |
||
36 | array_set($this->items, $key, $value); |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * @param $key |
||
41 | */ |
||
42 | public function remove($key) { |
||
43 | array_remove($this->items, $key); |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * @param $key |
||
48 | * |
||
49 | * @return bool |
||
50 | */ |
||
51 | public function has($key) { |
||
52 | return array_has($this->items, $key); |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * @param $key |
||
57 | * @param null $default |
||
58 | * |
||
59 | * @return mixed |
||
60 | */ |
||
61 | public function take($key, $default = null) { |
||
62 | return array_take($this->items, $key, $default); |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * @param $key |
||
67 | * @param $value |
||
68 | */ |
||
69 | public function add($key, $value) { |
||
70 | array_add($this->items, $key, $value); |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * @param array $items |
||
75 | */ |
||
76 | public function merge(array $items) { |
||
77 | foreach ($items as $key => $value) { |
||
78 | $this->set($key, $value); |
||
79 | } |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * @param IDictionary $items |
||
84 | */ |
||
85 | public function extend(IDictionary $items) { |
||
86 | foreach ($items->getItems() as $key => $value) { |
||
87 | $this->set($key, $value); |
||
88 | } |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * @return array |
||
93 | */ |
||
94 | public function getItems() { |
||
95 | return $this->items; |
||
96 | } |
||
97 | |||
98 | /** |
||
99 | * @param array $items |
||
100 | */ |
||
101 | public function setItems(array $items) { |
||
102 | $this->items = $items; |
||
103 | } |
||
104 | |||
105 | /** |
||
106 | * @return array |
||
107 | */ |
||
108 | View Code Duplication | public function toArray() { |
|
0 ignored issues
–
show
|
|||
109 | $array = []; |
||
110 | |||
111 | foreach ($this->items as $key => $value) { |
||
112 | if ($value instanceof IArrayable) { |
||
113 | $value = $value->toArray(); |
||
114 | } |
||
115 | |||
116 | $array[$key] = $value; |
||
117 | } |
||
118 | |||
119 | return $array; |
||
120 | } |
||
121 | |||
122 | /** |
||
123 | * @return int |
||
124 | */ |
||
125 | public function count() { |
||
126 | return count($this->items); |
||
127 | } |
||
128 | |||
129 | /** |
||
130 | * @param mixed $key |
||
131 | * |
||
132 | * @return mixed |
||
133 | */ |
||
134 | public function offsetGet($key) { |
||
135 | return $this->items[$key]; |
||
136 | } |
||
137 | |||
138 | /** |
||
139 | * @param mixed $key |
||
140 | * @param mixed $value |
||
141 | */ |
||
142 | public function offsetSet($key, $value) { |
||
143 | $this->items[$key] = $value; |
||
144 | } |
||
145 | |||
146 | /** |
||
147 | * @param mixed $key |
||
148 | * |
||
149 | * @return bool |
||
150 | */ |
||
151 | public function offsetExists($key) { |
||
152 | return array_key_exists($key, $this->items); |
||
153 | } |
||
154 | |||
155 | /** |
||
156 | * @param mixed $key |
||
157 | */ |
||
158 | public function offsetUnset($key) { |
||
159 | if ($this->offsetExists($key)) { |
||
160 | unset($this->items[$key]); |
||
161 | } |
||
162 | } |
||
163 | |||
164 | /** |
||
165 | * @return ArrayIterator |
||
166 | */ |
||
167 | public function getIterator() { |
||
168 | return new ArrayIterator($this->items); |
||
169 | } |
||
170 | } |
||
171 |
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.