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 Recca0120\LoDash\JArray; |
||
4 | |||
5 | use Recca0120\LoDash\JString; |
||
6 | |||
7 | trait Javascript |
||
8 | { |
||
9 | /** |
||
10 | * The concat() method is used to merge two or more arrays. |
||
11 | * This method does not change the existing arrays, but instead returns a new array. |
||
12 | * |
||
13 | * @return static |
||
14 | */ |
||
15 | 4 | public function concat() |
|
16 | { |
||
17 | 4 | $array = $this->getArrayCopy(); |
|
18 | 4 | foreach (func_get_args() as $value) { |
|
19 | 4 | $array = array_merge($array, (array) $value); |
|
20 | 4 | } |
|
21 | |||
22 | 4 | return new static($array); |
|
23 | } |
||
24 | |||
25 | /** |
||
26 | * The copyWithin() method shallow copies part of an array to another location in the same array and returns it, |
||
27 | * without modifying its size. |
||
28 | * |
||
29 | * @param int $target |
||
30 | * @param int $start |
||
31 | * @param int $end |
||
32 | * @return static |
||
33 | */ |
||
34 | public function copyWithin($target, $start, $end) |
||
35 | { |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * The entries() method returns a new Array Iterator object that contains the key/value pairs for each index in the array. |
||
40 | * |
||
41 | * @return ArrayIterator |
||
42 | */ |
||
43 | 3 | public function entries() |
|
44 | { |
||
45 | 3 | return $this->getIterator(); |
|
46 | } |
||
47 | |||
48 | /** |
||
49 | * The every() method tests whether all elements in the array pass the test implemented by the provided function. |
||
50 | * |
||
51 | * @param callable $callback |
||
52 | * @return bool |
||
53 | */ |
||
54 | 1 | View Code Duplication | public function every(callable $callback) |
55 | { |
||
56 | 1 | $array = $this->getArrayCopy(); |
|
1 ignored issue
–
show
|
|||
57 | 1 | foreach ($array as $key => $value) { |
|
58 | 1 | if ($callback($value, $key, $array) === false) { |
|
59 | 1 | return false; |
|
60 | } |
||
61 | 1 | } |
|
62 | |||
63 | 1 | return true; |
|
64 | } |
||
65 | |||
66 | /** |
||
67 | * The fill() method fills all the elements of an array from a start index to an end index with a static value. |
||
68 | * |
||
69 | * @param $value |
||
70 | * @param $start |
||
71 | * @param $end |
||
72 | * @return static |
||
73 | */ |
||
74 | 1 | public function fill($value, $start = null, $end = null) |
|
75 | { |
||
76 | 1 | $array = $this->getArrayCopy(); |
|
1 ignored issue
–
show
It seems like
getArrayCopy() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the
Loading history...
|
|||
77 | 1 | $length = $this->length(); |
|
78 | |||
79 | 1 | if ($end <= 0) { |
|
80 | 1 | $end = $length - $end; |
|
81 | 1 | } |
|
82 | |||
83 | 1 | if (is_null($start) === true) { |
|
84 | 1 | $i = $end ?: $length; |
|
85 | |||
86 | 1 | while ($i--) { |
|
87 | 1 | $array[$i] = $value; |
|
88 | 1 | } |
|
89 | 1 | } |
|
90 | |||
91 | 1 | if ($start <= 0) { |
|
92 | 1 | $start = $length - $start; |
|
93 | 1 | } |
|
94 | |||
95 | 1 | $end = $end ?: $length; |
|
96 | 1 | $i = $start; |
|
97 | |||
98 | 1 | while ($i !== $end) { |
|
99 | 1 | $array[$i] = $value; |
|
100 | 1 | ++$i; |
|
101 | 1 | } |
|
102 | |||
103 | 1 | return new static($array); |
|
104 | } |
||
105 | |||
106 | /** |
||
107 | * The filter() method creates a new array with all elements that pass the test implemented by the provided function. |
||
108 | * |
||
109 | * @param callable $callback |
||
110 | * @return static |
||
111 | */ |
||
112 | 1 | public function filter(callable $callback) |
|
113 | { |
||
114 | 1 | return new static(array_filter($this->getArrayCopy(), $callback)); |
|
115 | } |
||
116 | |||
117 | /** |
||
118 | * The find() method returns a value of the first element in the array that satisfies the provided testing function. Otherwise undefined is returned. |
||
119 | * |
||
120 | * @param callable $callback |
||
121 | * @return mix |
||
122 | */ |
||
123 | 1 | View Code Duplication | public function find(callable $callback) |
124 | { |
||
125 | 1 | $array = $this->getArrayCopy(); |
|
1 ignored issue
–
show
It seems like
getArrayCopy() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the
Loading history...
|
|||
126 | 1 | foreach ($array as $key => $value) { |
|
127 | 1 | if ($callback($value, $key, $array) === true) { |
|
128 | 1 | return $value; |
|
129 | } |
||
130 | 1 | } |
|
131 | } |
||
132 | |||
133 | /** |
||
134 | * The findIndex() method returns an index of the first element in the array that satisfies the provided testing function. |
||
135 | * Otherwise -1 is returned. |
||
136 | * |
||
137 | * @param callable $callback |
||
138 | * @return int|string |
||
139 | */ |
||
140 | 1 | View Code Duplication | public function findIndex(callable $callback) |
141 | { |
||
142 | 1 | $array = $this->getArrayCopy(); |
|
1 ignored issue
–
show
It seems like
getArrayCopy() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the
Loading history...
|
|||
143 | 1 | foreach ($array as $key => $value) { |
|
144 | 1 | if ($callback($value, $key, $array) === true) { |
|
145 | 1 | return $key; |
|
146 | } |
||
147 | 1 | } |
|
148 | |||
149 | 1 | return -1; |
|
150 | } |
||
151 | |||
152 | /** |
||
153 | * The forEach() method executes a provided function once for each array element. |
||
154 | * php < 7 not allow forEach. |
||
155 | * |
||
156 | * @param callable $callback |
||
157 | */ |
||
158 | 1 | public function each(callable $callback) |
|
159 | { |
||
160 | 1 | $array = $this->getArrayCopy(); |
|
1 ignored issue
–
show
It seems like
getArrayCopy() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the
Loading history...
|
|||
161 | 1 | foreach ($array as $key => $value) { |
|
162 | 1 | $callback($value, $key, $array); |
|
163 | 1 | } |
|
164 | 1 | } |
|
165 | |||
166 | /** |
||
167 | * The includes() method determines whether an array includes a certain element, returning true or false as appropriate. |
||
168 | * |
||
169 | * @param mix $searchElement |
||
170 | * @param int $fromIndex |
||
171 | * @return bool |
||
172 | */ |
||
173 | 1 | public function includes($searchElement, $fromIndex = 0) |
|
174 | { |
||
175 | 1 | return in_array($searchElement, $this->slice($fromIndex)->getArrayCopy(), true); |
|
176 | } |
||
177 | |||
178 | /** |
||
179 | * The indexOf() method returns the first index at which a given element can be found in the array, or -1 if it is not present. |
||
180 | * |
||
181 | * @param mix $searchElement |
||
182 | * @param int $fromIndex |
||
183 | * @return int|string |
||
184 | */ |
||
185 | 1 | View Code Duplication | public function indexOf($searchElement, $fromIndex = 0) |
186 | { |
||
187 | 1 | $result = array_search($searchElement, $this->getArrayCopy(), true); |
|
188 | |||
189 | 1 | return $result === false ? -1 : $result + $fromIndex; |
|
190 | |||
191 | // if ($fromIndex < 0) { |
||
192 | // $fromIndex = $this->length() + $fromIndex; |
||
193 | // } |
||
194 | // $result = array_search($searchElement, $this->slice($fromIndex)->getArrayCopy(), true); |
||
195 | |||
196 | // return $result === false ? -1 : $result + $fromIndex; |
||
197 | } |
||
198 | |||
199 | /** |
||
200 | * The join() method joins all elements of an array into a string. |
||
201 | * |
||
202 | * @param string $separator [description] |
||
203 | * @return \Recca0120\LoDash\Str; |
||
204 | */ |
||
205 | 4 | public function join($separator = ',') |
|
206 | { |
||
207 | 4 | return new JString(implode($separator, $this->getArrayCopy())); |
|
208 | } |
||
209 | |||
210 | /** |
||
211 | * The keys() method returns a new Array Iterator that contains the keys for each index in the array. |
||
212 | * |
||
213 | * @return \ArrayIterator |
||
214 | */ |
||
215 | 1 | public function keys() |
|
216 | { |
||
217 | 1 | return (new static(array_keys($this->getArrayCopy())))->entries(); |
|
218 | } |
||
219 | |||
220 | /** |
||
221 | * The lastIndexOf() method returns the last index at which a given element can be found in the array, or -1 if it is not present. The array is searched backwards, starting at fromIndex. |
||
222 | * |
||
223 | * @param mix $searchElement |
||
224 | * @param int $fromIndex |
||
225 | * @return int|string |
||
226 | */ |
||
227 | 1 | View Code Duplication | public function lastIndexOf($searchElement, $fromIndex = 0) |
228 | { |
||
229 | 1 | $result = array_search($searchElement, array_reverse($this->getArrayCopy(), true)); |
|
230 | |||
231 | 1 | return $result === false ? -1 : $result; |
|
232 | // $result = array_search($searchElement, array_reverse($this->slice($fromIndex)->getArrayCopy(), true)); |
||
233 | |||
234 | // return ($result === false) ? -1 : $result + $fromIndex; |
||
235 | } |
||
236 | |||
237 | /** |
||
238 | * The map() method creates a new array with the results of calling a provided function on every element in this array. |
||
239 | * |
||
240 | * @param callable $callback |
||
241 | * @return static |
||
242 | */ |
||
243 | 2 | public function map(callable $callback) |
|
244 | { |
||
245 | 2 | return new static(array_map($callback, $this->getArrayCopy())); |
|
246 | } |
||
247 | |||
248 | /** |
||
249 | * The pop() method removes the last element from an array and returns that element. This method changes the length of the array. |
||
250 | * |
||
251 | * @return static |
||
252 | */ |
||
253 | 1 | public function pop() |
|
254 | { |
||
255 | 1 | $array = $this->getArrayCopy(); |
|
1 ignored issue
–
show
It seems like
getArrayCopy() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the
Loading history...
|
|||
256 | 1 | $pop = array_pop($array); |
|
257 | 1 | $this->exchangeArray($array); |
|
258 | |||
259 | 1 | return $pop; |
|
260 | } |
||
261 | |||
262 | /** |
||
263 | * The push() method adds one or more elements to the end of an array and returns the new length of the array. |
||
264 | * |
||
265 | * @return int |
||
266 | */ |
||
267 | 1 | public function push() |
|
268 | { |
||
269 | 1 | $array = $this->getArrayCopy(); |
|
1 ignored issue
–
show
It seems like
getArrayCopy() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the
Loading history...
|
|||
270 | 1 | foreach (func_get_args() as $parameter) { |
|
271 | 1 | array_push($array, $parameter); |
|
272 | 1 | } |
|
273 | 1 | $this->exchangeArray($array); |
|
274 | |||
275 | 1 | return $this->count(); |
|
276 | } |
||
277 | |||
278 | /** |
||
279 | * The reduce() method applies a function against an accumulator and each value of the array (from left-to-right) to reduce it to a single value. |
||
280 | * |
||
281 | * @param callable $callback |
||
282 | * @param mix $initialValue |
||
283 | * @return mix |
||
284 | */ |
||
285 | 2 | public function reduce(callable $callback, $initialValue = null) |
|
286 | { |
||
287 | 2 | return array_reduce($this->getArrayCopy(), $callback, $initialValue); |
|
288 | } |
||
289 | |||
290 | /** |
||
291 | * The reduceRight() method applies a function against an accumulator and each value of the array (from right-to-left) has to reduce it to a single value. |
||
292 | * |
||
293 | * @param callable $callback |
||
294 | * @param mix $initialValue |
||
295 | * @return mix |
||
296 | */ |
||
297 | 1 | public function reduceRight(callable $callback, $initialValue = null) |
|
298 | { |
||
299 | 1 | return $this->reverse(true)->reduce($callback, $initialValue); |
|
300 | } |
||
301 | |||
302 | /** |
||
303 | * The reverse() method reverses an array in place. The first array element becomes the last, and the last array element becomes the first. |
||
304 | * |
||
305 | * @param bool $preservekeys |
||
306 | * @return static |
||
307 | */ |
||
308 | 2 | public function reverse($preservekeys = false) |
|
309 | { |
||
310 | 2 | $array = $this->getArrayCopy(); |
|
1 ignored issue
–
show
It seems like
getArrayCopy() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the
Loading history...
|
|||
311 | 2 | $array = array_reverse($array, $preservekeys); |
|
312 | 2 | $this->exchangeArray($array); |
|
313 | |||
314 | 2 | return new static($array); |
|
315 | } |
||
316 | |||
317 | /** |
||
318 | * The shift() method removes the first element from an array and returns that element. This method changes the length of the array. |
||
319 | * |
||
320 | * @return mix |
||
321 | */ |
||
322 | 1 | public function shift() |
|
323 | { |
||
324 | 1 | $array = $this->getArrayCopy(); |
|
1 ignored issue
–
show
It seems like
getArrayCopy() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the
Loading history...
|
|||
325 | 1 | $result = array_shift($array); |
|
326 | 1 | $this->exchangeArray($array); |
|
327 | |||
328 | 1 | return $result; |
|
329 | } |
||
330 | |||
331 | /** |
||
332 | * The slice() method returns a shallow copy of a portion of an array |
||
333 | * into a new array object selected from begin to end (end not included). The original array will not be modified. |
||
334 | * |
||
335 | * @param int $begin |
||
336 | * @param int $end |
||
337 | * @return static |
||
338 | */ |
||
339 | 2 | public function slice($begin, $end = null) |
|
340 | { |
||
341 | 2 | $array = $this->getArrayCopy(); |
|
1 ignored issue
–
show
It seems like
getArrayCopy() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the
Loading history...
|
|||
342 | 2 | $length = $this->length(); |
|
343 | 2 | $begin = $begin < 0 ? $length + $begin : $begin; |
|
344 | |||
345 | 2 | if (is_null($end) === true) { |
|
346 | 1 | return new static(array_slice($array, $begin, $length - $begin)); |
|
347 | } |
||
348 | |||
349 | 1 | $end = $end < 0 ? $length + $end : $end; |
|
350 | 1 | $end -= $begin; |
|
351 | |||
352 | 1 | return new static(array_slice($array, $begin, $end)); |
|
353 | } |
||
354 | |||
355 | /** |
||
356 | * The some() method tests whether some element in the array passes the test implemented by the provided function. |
||
357 | * |
||
358 | * @param callable $callback |
||
359 | * @return bool |
||
360 | */ |
||
361 | 1 | View Code Duplication | public function some(callable $callback) |
362 | { |
||
363 | 1 | $array = $this->getArrayCopy(); |
|
1 ignored issue
–
show
It seems like
getArrayCopy() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the
Loading history...
|
|||
364 | 1 | foreach ($array as $key => $value) { |
|
365 | 1 | if ($callback($value, $key, $array) === true) { |
|
366 | 1 | return true; |
|
367 | } |
||
368 | 1 | } |
|
369 | |||
370 | 1 | return false; |
|
371 | } |
||
372 | |||
373 | /** |
||
374 | * The sort() method sorts the elements of an array in place and returns the array. The sort is not necessarily stable. The default sort order is according to string Unicode code points. |
||
375 | * |
||
376 | * @param callable|null $compareFunction |
||
377 | * @return static |
||
378 | */ |
||
379 | 1 | public function sort(callable $compareFunction = null) |
|
380 | { |
||
381 | 1 | if (is_null($compareFunction) === true) { |
|
382 | 1 | $compareFunction = function ($a, $b) { |
|
383 | 1 | return $a > $b; |
|
384 | 1 | }; |
|
385 | 1 | } |
|
386 | 1 | $array = $this->getArrayCopy(); |
|
1 ignored issue
–
show
It seems like
getArrayCopy() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the
Loading history...
|
|||
387 | 1 | usort($array, $compareFunction); |
|
388 | 1 | $this->exchangeArray($array); |
|
389 | |||
390 | 1 | return $this; |
|
391 | } |
||
392 | |||
393 | /** |
||
394 | * The splice() method changes the content of an array by removing existing elements and/or adding new elements. |
||
395 | * |
||
396 | * @return static |
||
397 | */ |
||
398 | 1 | View Code Duplication | public function splice() |
399 | { |
||
400 | 1 | $array = $this->getArrayCopy(); |
|
1 ignored issue
–
show
It seems like
getArrayCopy() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the
Loading history...
|
|||
401 | 1 | call_user_func_array('array_splice', array_merge([&$array], func_get_args())); |
|
402 | 1 | $this->exchangeArray($array); |
|
403 | |||
404 | 1 | return $this; |
|
405 | } |
||
406 | |||
407 | public function toLocaleString() |
||
408 | { |
||
409 | } |
||
410 | |||
411 | /** |
||
412 | * The toString() method returns a string representing the specified array and its elements. |
||
413 | * |
||
414 | * @return string |
||
415 | */ |
||
416 | 1 | public function toString() |
|
417 | { |
||
418 | 1 | return (string) $this->join(','); |
|
419 | } |
||
420 | |||
421 | /** |
||
422 | * The toString() method returns a string representing the specified array and its elements. |
||
423 | * |
||
424 | * @return string |
||
425 | */ |
||
426 | 1 | public function __toString() |
|
427 | { |
||
428 | 1 | return $this->toString(); |
|
429 | } |
||
430 | |||
431 | /** |
||
432 | * The unshift() method adds one or more elements to the beginning of an array and returns the new length of the array. |
||
433 | * |
||
434 | * @return static |
||
435 | */ |
||
436 | 1 | View Code Duplication | public function unshift() |
437 | { |
||
438 | 1 | $array = $this->getArrayCopy(); |
|
1 ignored issue
–
show
It seems like
getArrayCopy() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the
Loading history...
|
|||
439 | 1 | call_user_func_array('array_unshift', array_merge([&$array], func_get_args())); |
|
440 | 1 | $this->exchangeArray($array); |
|
441 | |||
442 | 1 | return $this; |
|
443 | } |
||
444 | |||
445 | /** |
||
446 | * The values() method returns a new Array Iterator object that contains the values for each index in the array. |
||
447 | * |
||
448 | * @return \ArrayIterator |
||
449 | */ |
||
450 | 1 | public function values() |
|
451 | { |
||
452 | 1 | return (new static(array_values($this->getArrayCopy())))->entries(); |
|
453 | } |
||
454 | |||
455 | /** |
||
456 | * length. |
||
457 | * |
||
458 | * @return int |
||
459 | */ |
||
460 | 3 | public function length() |
|
461 | { |
||
462 | 3 | return $this->count(); |
|
463 | } |
||
464 | } |
||
465 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.