Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Arrayy often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Arrayy, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
27 | class Arrayy extends \ArrayObject implements \IteratorAggregate, \ArrayAccess, \Serializable, \JsonSerializable, \Countable |
||
28 | { |
||
29 | const ARRAYY_HELPER_TYPES_FOR_ALL_PROPERTIES = '!!!!Arrayy_Helper_Types_For_All_Properties!!!!'; |
||
30 | |||
31 | const ARRAYY_HELPER_WALK = '!!!!Arrayy_Helper_Walk!!!!'; |
||
32 | |||
33 | /** |
||
34 | * @var array |
||
35 | * |
||
36 | * @psalm-var array<mixed,mixed>|array<TKey,T> |
||
37 | */ |
||
38 | protected $array = []; |
||
39 | |||
40 | /** |
||
41 | * @var \Arrayy\ArrayyRewindableGenerator|null |
||
42 | * |
||
43 | * @psalm-var \Arrayy\ArrayyRewindableGenerator<TKey,T>|null |
||
44 | */ |
||
45 | protected $generator; |
||
46 | |||
47 | /** |
||
48 | * @var string |
||
49 | * |
||
50 | * @psalm-var class-string<\Arrayy\ArrayyIterator> |
||
51 | */ |
||
52 | protected $iteratorClass = ArrayyIterator::class; |
||
53 | |||
54 | /** |
||
55 | * @var string |
||
56 | */ |
||
57 | protected $pathSeparator = '.'; |
||
58 | |||
59 | /** |
||
60 | * @var bool |
||
61 | */ |
||
62 | protected $checkPropertyTypes = false; |
||
63 | |||
64 | /** |
||
65 | * @var bool |
||
66 | */ |
||
67 | protected $checkForMissingPropertiesInConstructor = false; |
||
68 | |||
69 | /** |
||
70 | * @var bool |
||
71 | */ |
||
72 | protected $checkPropertiesMismatchInConstructor = false; |
||
73 | |||
74 | /** |
||
75 | * @var bool |
||
76 | */ |
||
77 | protected $checkPropertiesMismatch = true; |
||
78 | |||
79 | /** |
||
80 | * @var array<int|string,TypeCheckInterface>|mixed|TypeCheckArray<int|string,TypeCheckInterface>|TypeInterface |
||
81 | */ |
||
82 | protected $properties = []; |
||
83 | |||
84 | /** |
||
85 | * Initializes |
||
86 | * |
||
87 | * @param mixed $data <p> |
||
88 | * Should be an array or a generator, otherwise it will try |
||
89 | * to convert it into an array. |
||
90 | * </p> |
||
91 | * @param string $iteratorClass optional <p> |
||
92 | * You can overwrite the ArrayyIterator, but mostly you don't |
||
93 | * need this option. |
||
94 | * </p> |
||
95 | * @param bool $checkPropertiesInConstructor optional <p> |
||
96 | * You need to extend the "Arrayy"-class and you need to set |
||
97 | * the $checkPropertiesMismatchInConstructor class property |
||
98 | * to |
||
99 | * true, otherwise this option didn't not work anyway. |
||
100 | * </p> |
||
101 | * |
||
102 | * @psalm-param class-string<\Arrayy\ArrayyIterator> $iteratorClass |
||
103 | */ |
||
104 | 1198 | public function __construct( |
|
121 | |||
122 | /** |
||
123 | * @return void |
||
124 | */ |
||
125 | 51 | public function __clone() |
|
135 | |||
136 | /** |
||
137 | * Call object as function. |
||
138 | * |
||
139 | * @param mixed $key |
||
140 | * |
||
141 | * @return mixed |
||
142 | */ |
||
143 | 1 | public function __invoke($key = null) |
|
153 | |||
154 | /** |
||
155 | * Whether or not an element exists by key. |
||
156 | * |
||
157 | * @param mixed $key |
||
158 | * |
||
159 | * @return bool |
||
160 | * <p>True is the key/index exists, otherwise false.</p> |
||
161 | */ |
||
162 | public function __isset($key): bool |
||
166 | |||
167 | /** |
||
168 | * Assigns a value to the specified element. |
||
169 | * |
||
170 | * @param mixed $key |
||
171 | * @param mixed $value |
||
172 | * |
||
173 | * @return void |
||
174 | */ |
||
175 | 3 | public function __set($key, $value) |
|
179 | |||
180 | /** |
||
181 | * magic to string |
||
182 | * |
||
183 | * @return string |
||
184 | */ |
||
185 | 15 | public function __toString(): string |
|
189 | |||
190 | /** |
||
191 | * Unset element by key. |
||
192 | * |
||
193 | * @param mixed $key |
||
194 | */ |
||
195 | public function __unset($key) |
||
199 | |||
200 | /** |
||
201 | * Get a value by key. |
||
202 | * |
||
203 | * @param mixed $key |
||
204 | * |
||
205 | * @return mixed |
||
206 | * <p>Get a Value from the current array.</p> |
||
207 | */ |
||
208 | 126 | public function &__get($key) |
|
218 | |||
219 | /** |
||
220 | * Add new values (optional using dot-notation). |
||
221 | * |
||
222 | * @param mixed $value |
||
223 | * @param int|string|null $key |
||
224 | * |
||
225 | * @return static |
||
226 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
227 | * |
||
228 | * @psalm-param T $value |
||
229 | * @psalm-return static<TKey,T> |
||
230 | */ |
||
231 | 13 | public function add($value, $key = null) |
|
232 | { |
||
233 | 13 | if ($key !== null) { |
|
234 | 5 | $get = $this->get($key); |
|
235 | 5 | if ($get !== null) { |
|
236 | 1 | $value = \array_merge_recursive( |
|
237 | 1 | !$get instanceof self ? [$get] : $get->getArray(), |
|
238 | 1 | !\is_array($value) ? [$value] : $value |
|
239 | ); |
||
240 | } |
||
241 | |||
242 | 5 | $this->internalSet($key, $value); |
|
243 | |||
244 | 4 | return $this; |
|
245 | } |
||
246 | |||
247 | 8 | return $this->append($value); |
|
248 | } |
||
249 | |||
250 | /** |
||
251 | * Append a (key) + value to the current array. |
||
252 | * |
||
253 | * EXAMPLE: <code> |
||
254 | * a(['fòô' => 'bàř'])->append('foo'); // Arrayy['fòô' => 'bàř', 0 => 'foo'] |
||
255 | * </code> |
||
256 | * |
||
257 | * @param mixed $value |
||
258 | * @param mixed $key |
||
259 | * |
||
260 | * @return $this |
||
261 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
262 | * |
||
263 | * @psalm-return static<TKey,T> |
||
264 | */ |
||
265 | 20 | public function append($value, $key = null): self |
|
289 | |||
290 | /** |
||
291 | * Sort the entries by value. |
||
292 | * |
||
293 | * @param int $sort_flags [optional] <p> |
||
294 | * You may modify the behavior of the sort using the optional |
||
295 | * parameter sort_flags, for details |
||
296 | * see sort. |
||
297 | * </p> |
||
298 | * |
||
299 | * @return $this |
||
300 | * <p>(Mutable) Return this Arrayy object.</p> |
||
301 | * |
||
302 | * @psalm-return static<TKey,T> |
||
303 | */ |
||
304 | 4 | public function asort(int $sort_flags = 0): self |
|
312 | |||
313 | /** |
||
314 | * Sort the entries by value. |
||
315 | * |
||
316 | * @param int $sort_flags [optional] <p> |
||
317 | * You may modify the behavior of the sort using the optional |
||
318 | * parameter sort_flags, for details |
||
319 | * see sort. |
||
320 | * </p> |
||
321 | * |
||
322 | * @return $this |
||
323 | * <p>(Immutable) Return this Arrayy object.</p> |
||
324 | * |
||
325 | * @psalm-return static<TKey,T> |
||
326 | * @psalm-mutation-free |
||
327 | */ |
||
328 | 4 | public function asortImmutable(int $sort_flags = 0): self |
|
339 | |||
340 | /** |
||
341 | * Counts all elements in an array, or something in an object. |
||
342 | * |
||
343 | * <p> |
||
344 | * For objects, if you have SPL installed, you can hook into count() by implementing interface {@see Countable}. |
||
345 | * The interface has exactly one method, {@see Countable::count()}, which returns the return value for the count() |
||
346 | * function. Please see the {@see Array} section of the manual for a detailed explanation of how arrays are |
||
347 | * implemented and used in PHP. |
||
348 | * </p> |
||
349 | * |
||
350 | * @see http://php.net/manual/en/function.count.php |
||
351 | * |
||
352 | * @param int $mode [optional] If the optional mode parameter is set to |
||
353 | * COUNT_RECURSIVE (or 1), count |
||
354 | * will recursively count the array. This is particularly useful for |
||
355 | * counting all the elements of a multidimensional array. count does not detect infinite recursion. |
||
356 | * |
||
357 | * @return int |
||
358 | * <p> |
||
359 | * The number of elements in var, which is |
||
360 | * typically an array, since anything else will have one |
||
361 | * element. |
||
362 | * </p> |
||
363 | * <p> |
||
364 | * If var is not an array or an object with |
||
365 | * implemented Countable interface, |
||
366 | * 1 will be returned. |
||
367 | * There is one exception, if var is &null;, |
||
368 | * 0 will be returned. |
||
369 | * </p> |
||
370 | * <p> |
||
371 | * Caution: count may return 0 for a variable that isn't set, |
||
372 | * but it may also return 0 for a variable that has been initialized with an |
||
373 | * empty array. Use isset to test if a variable is set. |
||
374 | * </p> |
||
375 | * @psalm-mutation-free |
||
376 | */ |
||
377 | 148 | public function count(int $mode = \COUNT_NORMAL): int |
|
389 | |||
390 | /** |
||
391 | * Exchange the array for another one. |
||
392 | * |
||
393 | * @param array|static $data |
||
394 | * |
||
395 | * @return array |
||
396 | * |
||
397 | * @psalm-param array<TKey,T>|self<TKey,T> $data |
||
398 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
399 | */ |
||
400 | 1 | public function exchangeArray($data): array |
|
406 | |||
407 | /** |
||
408 | * Creates a copy of the ArrayyObject. |
||
409 | * |
||
410 | * @return array |
||
411 | * |
||
412 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
413 | */ |
||
414 | 6 | public function getArrayCopy(): array |
|
420 | |||
421 | /** |
||
422 | * Returns a new iterator, thus implementing the \Iterator interface. |
||
423 | * |
||
424 | * @return \Iterator<mixed, mixed> |
||
425 | * <p>An iterator for the values in the array.</p> |
||
426 | * @psalm-return \Iterator<array-key|TKey, mixed|T> |
||
427 | */ |
||
428 | 27 | public function getIterator(): \Iterator |
|
445 | |||
446 | /** |
||
447 | * Gets the iterator classname for the ArrayObject. |
||
448 | * |
||
449 | * @return string |
||
450 | * |
||
451 | * @psalm-return class-string |
||
452 | */ |
||
453 | 26 | public function getIteratorClass(): string |
|
457 | |||
458 | /** |
||
459 | * Sort the entries by key. |
||
460 | * |
||
461 | * @param int $sort_flags [optional] <p> |
||
462 | * You may modify the behavior of the sort using the optional |
||
463 | * parameter sort_flags, for details |
||
464 | * see sort. |
||
465 | * </p> |
||
466 | * |
||
467 | * @return $this |
||
468 | * <p>(Mutable) Return this Arrayy object.</p> |
||
469 | * |
||
470 | * @psalm-return static<TKey,T> |
||
471 | */ |
||
472 | 4 | public function ksort(int $sort_flags = 0): self |
|
480 | |||
481 | /** |
||
482 | * Sort the entries by key. |
||
483 | * |
||
484 | * @param int $sort_flags [optional] <p> |
||
485 | * You may modify the behavior of the sort using the optional |
||
486 | * parameter sort_flags, for details |
||
487 | * see sort. |
||
488 | * </p> |
||
489 | * |
||
490 | * @return $this |
||
491 | * <p>(Immutable) Return this Arrayy object.</p> |
||
492 | * |
||
493 | * @psalm-return static<TKey,T> |
||
494 | */ |
||
495 | 4 | public function ksortImmutable(int $sort_flags = 0): self |
|
506 | |||
507 | /** |
||
508 | * Sort an array using a case insensitive "natural order" algorithm. |
||
509 | * |
||
510 | * @return $this |
||
511 | * <p>(Mutable) Return this Arrayy object.</p> |
||
512 | * |
||
513 | * @psalm-return static<TKey,T> |
||
514 | */ |
||
515 | 8 | public function natcasesort(): self |
|
523 | |||
524 | /** |
||
525 | * Sort an array using a case insensitive "natural order" algorithm. |
||
526 | * |
||
527 | * @return $this |
||
528 | * <p>(Immutable) Return this Arrayy object.</p> |
||
529 | * |
||
530 | * @psalm-return static<TKey,T> |
||
531 | * @psalm-mutation-free |
||
532 | */ |
||
533 | 4 | public function natcasesortImmutable(): self |
|
544 | |||
545 | /** |
||
546 | * Sort entries using a "natural order" algorithm. |
||
547 | * |
||
548 | * @return $this |
||
549 | * <p>(Mutable) Return this Arrayy object.</p> |
||
550 | * |
||
551 | * @psalm-return static<TKey,T> |
||
552 | */ |
||
553 | 10 | public function natsort(): self |
|
561 | |||
562 | /** |
||
563 | * Sort entries using a "natural order" algorithm. |
||
564 | * |
||
565 | * @return $this |
||
566 | * <p>(Immutable) Return this Arrayy object.</p> |
||
567 | * |
||
568 | * @psalm-return static<TKey,T> |
||
569 | * @psalm-mutation-free |
||
570 | */ |
||
571 | 4 | public function natsortImmutable(): self |
|
582 | |||
583 | /** |
||
584 | * Whether or not an offset exists. |
||
585 | * |
||
586 | * @param bool|int|string $offset |
||
587 | * |
||
588 | * @return bool |
||
589 | * |
||
590 | * @noinspection PhpSillyAssignmentInspection |
||
591 | * |
||
592 | * @psalm-mutation-free |
||
593 | */ |
||
594 | 157 | public function offsetExists($offset): bool |
|
656 | |||
657 | /** |
||
658 | * Returns the value at specified offset. |
||
659 | * |
||
660 | * @param int|string $offset |
||
661 | * |
||
662 | * @return mixed |
||
663 | * <p>Will return null if the offset did not exists.</p> |
||
664 | */ |
||
665 | 126 | public function &offsetGet($offset) |
|
676 | |||
677 | /** |
||
678 | * Assigns a value to the specified offset + check the type. |
||
679 | * |
||
680 | * @param int|string|null $offset |
||
681 | * @param mixed $value |
||
682 | * |
||
683 | * @return void |
||
684 | */ |
||
685 | 27 | public function offsetSet($offset, $value) |
|
703 | |||
704 | /** |
||
705 | * Unset an offset. |
||
706 | * |
||
707 | * @param int|string $offset |
||
708 | * |
||
709 | * @return void |
||
710 | * <p>(Mutable) Return nothing.</p> |
||
711 | */ |
||
712 | 25 | public function offsetUnset($offset) |
|
763 | |||
764 | /** |
||
765 | * Serialize the current "Arrayy"-object. |
||
766 | * |
||
767 | * @return string |
||
768 | */ |
||
769 | 2 | public function serialize(): string |
|
779 | |||
780 | /** |
||
781 | * Sets the iterator classname for the current "Arrayy"-object. |
||
782 | * |
||
783 | * @param string $iteratorClass |
||
784 | * |
||
785 | * @throws \InvalidArgumentException |
||
786 | * |
||
787 | * @return void |
||
788 | * |
||
789 | * @psalm-param class-string<\Arrayy\ArrayyIterator> $iteratorClass |
||
790 | */ |
||
791 | 1189 | public function setIteratorClass($iteratorClass) |
|
813 | |||
814 | /** |
||
815 | * Sort the entries with a user-defined comparison function and maintain key association. |
||
816 | * |
||
817 | * @param callable $function |
||
818 | * |
||
819 | * @throws \InvalidArgumentException |
||
820 | * |
||
821 | * @return $this |
||
822 | * <p>(Mutable) Return this Arrayy object.</p> |
||
823 | * |
||
824 | * @psalm-return static<TKey,T> |
||
825 | */ |
||
826 | 8 | View Code Duplication | public function uasort($function): self |
838 | |||
839 | /** |
||
840 | * Sort the entries with a user-defined comparison function and maintain key association. |
||
841 | * |
||
842 | * @param callable $function |
||
843 | * |
||
844 | * @throws \InvalidArgumentException |
||
845 | * |
||
846 | * @return $this |
||
847 | * <p>(Immutable) Return this Arrayy object.</p> |
||
848 | * |
||
849 | * @psalm-return static<TKey,T> |
||
850 | * @psalm-mutation-free |
||
851 | */ |
||
852 | 4 | public function uasortImmutable($function): self |
|
863 | |||
864 | /** |
||
865 | * Sort the entries by keys using a user-defined comparison function. |
||
866 | * |
||
867 | * @param callable $function |
||
868 | * |
||
869 | * @throws \InvalidArgumentException |
||
870 | * |
||
871 | * @return static |
||
872 | * <p>(Mutable) Return this Arrayy object.</p> |
||
873 | * |
||
874 | * @psalm-return static<TKey,T> |
||
875 | */ |
||
876 | 5 | public function uksort($function): self |
|
880 | |||
881 | /** |
||
882 | * Sort the entries by keys using a user-defined comparison function. |
||
883 | * |
||
884 | * @param callable $function |
||
885 | * |
||
886 | * @throws \InvalidArgumentException |
||
887 | * |
||
888 | * @return static |
||
889 | * <p>(Immutable) Return this Arrayy object.</p> |
||
890 | * |
||
891 | * @psalm-return static<TKey,T> |
||
892 | * @psalm-mutation-free |
||
893 | */ |
||
894 | 1 | public function uksortImmutable($function): self |
|
898 | |||
899 | /** |
||
900 | * Unserialize an string and return the instance of the "Arrayy"-class. |
||
901 | * |
||
902 | * @param string $string |
||
903 | * |
||
904 | * @return $this |
||
905 | * |
||
906 | * @psalm-return static<TKey,T> |
||
907 | */ |
||
908 | 2 | public function unserialize($string): self |
|
918 | |||
919 | /** |
||
920 | * Append a (key) + values to the current array. |
||
921 | * |
||
922 | * EXAMPLE: <code> |
||
923 | * a(['fòô' => ['bàř']])->appendArrayValues(['foo1', 'foo2'], 'fòô'); // Arrayy['fòô' => ['bàř', 'foo1', 'foo2']] |
||
924 | * </code> |
||
925 | * |
||
926 | * @param array $values |
||
927 | * @param mixed $key |
||
928 | * |
||
929 | * @return $this |
||
930 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
931 | * |
||
932 | * @psalm-param array<mixed,T> $values |
||
933 | * @psalm-param TKey|null $key |
||
934 | * @psalm-return static<TKey,T> |
||
935 | */ |
||
936 | 1 | public function appendArrayValues(array $values, $key = null) |
|
962 | |||
963 | /** |
||
964 | * Add a suffix to each key. |
||
965 | * |
||
966 | * @param mixed $prefix |
||
967 | * |
||
968 | * @return static |
||
969 | * <p>(Immutable) Return an Arrayy object, with the prefixed keys.</p> |
||
970 | * |
||
971 | * @psalm-return static<TKey,T> |
||
972 | * @psalm-mutation-free |
||
973 | */ |
||
974 | 10 | View Code Duplication | public function appendToEachKey($prefix): self |
993 | |||
994 | /** |
||
995 | * Add a prefix to each value. |
||
996 | * |
||
997 | * @param mixed $prefix |
||
998 | * |
||
999 | * @return static |
||
1000 | * <p>(Immutable) Return an Arrayy object, with the prefixed values.</p> |
||
1001 | * |
||
1002 | * @psalm-return static<TKey,T> |
||
1003 | * @psalm-mutation-free |
||
1004 | */ |
||
1005 | 10 | View Code Duplication | public function appendToEachValue($prefix): self |
1024 | |||
1025 | /** |
||
1026 | * Sort an array in reverse order and maintain index association. |
||
1027 | * |
||
1028 | * @return $this |
||
1029 | * <p>(Mutable) Return this Arrayy object.</p> |
||
1030 | * |
||
1031 | * @psalm-return static<TKey,T> |
||
1032 | */ |
||
1033 | 4 | public function arsort(): self |
|
1041 | |||
1042 | /** |
||
1043 | * Sort an array in reverse order and maintain index association. |
||
1044 | * |
||
1045 | * @return $this |
||
1046 | * <p>(Immutable) Return this Arrayy object.</p> |
||
1047 | * |
||
1048 | * @psalm-return static<TKey,T> |
||
1049 | * @psalm-mutation-free |
||
1050 | */ |
||
1051 | 10 | public function arsortImmutable(): self |
|
1061 | |||
1062 | /** |
||
1063 | * Iterate over the current array and execute a callback for each loop. |
||
1064 | * |
||
1065 | * EXAMPLE: <code> |
||
1066 | * $result = A::create(); |
||
1067 | * $closure = function ($value, $key) use ($result) { |
||
1068 | * $result[$key] = ':' . $value . ':'; |
||
1069 | * }; |
||
1070 | * a(['foo', 'bar' => 'bis'])->at($closure); // Arrayy[':foo:', 'bar' => ':bis:'] |
||
1071 | * </code> |
||
1072 | * |
||
1073 | * @param \Closure $closure |
||
1074 | * |
||
1075 | * @return static |
||
1076 | * <p>(Immutable)</p> |
||
1077 | * |
||
1078 | * @psalm-return static<TKey,T> |
||
1079 | * @psalm-mutation-free |
||
1080 | */ |
||
1081 | 3 | public function at(\Closure $closure): self |
|
1095 | |||
1096 | /** |
||
1097 | * Returns the average value of the current array. |
||
1098 | * |
||
1099 | * EXAMPLE: <code> |
||
1100 | * a([-9, -8, -7, 1.32])->average(2); // -5.67 |
||
1101 | * </code> |
||
1102 | * |
||
1103 | * @param int $decimals <p>The number of decimal-numbers to return.</p> |
||
1104 | * |
||
1105 | * @return float|int |
||
1106 | * <p>The average value.</p> |
||
1107 | * @psalm-mutation-free |
||
1108 | */ |
||
1109 | 10 | public function average($decimals = 0) |
|
1123 | |||
1124 | /** |
||
1125 | * Changes all keys in an array. |
||
1126 | * |
||
1127 | * @param int $case [optional] <p> Either <strong>CASE_UPPER</strong><br /> |
||
1128 | * or <strong>CASE_LOWER</strong> (default)</p> |
||
1129 | * |
||
1130 | * @return static |
||
1131 | * <p>(Immutable)</p> |
||
1132 | * |
||
1133 | * @psalm-return static<TKey,T> |
||
1134 | * @psalm-mutation-free |
||
1135 | */ |
||
1136 | 1 | public function changeKeyCase(int $case = \CASE_LOWER): self |
|
1165 | |||
1166 | /** |
||
1167 | * Change the path separator of the array wrapper. |
||
1168 | * |
||
1169 | * By default, the separator is: "." |
||
1170 | * |
||
1171 | * @param string $separator <p>Separator to set.</p> |
||
1172 | * |
||
1173 | * @return $this |
||
1174 | * <p>(Mutable) Return this Arrayy object.</p> |
||
1175 | * |
||
1176 | * @psalm-return static<TKey,T> |
||
1177 | */ |
||
1178 | 11 | public function changeSeparator($separator): self |
|
1184 | |||
1185 | /** |
||
1186 | * Create a chunked version of the current array. |
||
1187 | * |
||
1188 | * EXAMPLE: <code> |
||
1189 | * a([-9, -8, -7, 1.32])->chunk(2); // Arrayy[[-9, -8], [-7, 1.32]] |
||
1190 | * </code> |
||
1191 | * |
||
1192 | * @param int $size <p>Size of each chunk.</p> |
||
1193 | * @param bool $preserveKeys <p>Whether array keys are preserved or no.</p> |
||
1194 | * |
||
1195 | * @return static |
||
1196 | * <p>(Immutable) A new array of chunks from the original array.</p> |
||
1197 | * |
||
1198 | * @psalm-return static<TKey,T> |
||
1199 | * @psalm-mutation-free |
||
1200 | */ |
||
1201 | 5 | public function chunk($size, $preserveKeys = false): self |
|
1209 | |||
1210 | /** |
||
1211 | * Clean all falsy values from the current array. |
||
1212 | * |
||
1213 | * EXAMPLE: <code> |
||
1214 | * a([-8 => -9, 1, 2 => false])->clean(); // Arrayy[-8 => -9, 1] |
||
1215 | * </code> |
||
1216 | * |
||
1217 | * @return static |
||
1218 | * <p>(Immutable)</p> |
||
1219 | * |
||
1220 | * @psalm-return static<TKey,T> |
||
1221 | * @psalm-mutation-free |
||
1222 | */ |
||
1223 | 8 | public function clean(): self |
|
1231 | |||
1232 | /** |
||
1233 | * WARNING!!! -> Clear the current full array or a $key of it. |
||
1234 | * |
||
1235 | * EXAMPLE: <code> |
||
1236 | * a([-8 => -9, 1, 2 => false])->clear(); // Arrayy[] |
||
1237 | * </code> |
||
1238 | * |
||
1239 | * @param int|int[]|string|string[]|null $key |
||
1240 | * |
||
1241 | * @return $this |
||
1242 | * <p>(Mutable) Return this Arrayy object, with an empty array.</p> |
||
1243 | * |
||
1244 | * @psalm-return static<TKey,T> |
||
1245 | */ |
||
1246 | 10 | public function clear($key = null): self |
|
1265 | |||
1266 | /** |
||
1267 | * Check if an item is in the current array. |
||
1268 | * |
||
1269 | * EXAMPLE: <code> |
||
1270 | * a([1, true])->contains(true); // true |
||
1271 | * </code> |
||
1272 | * |
||
1273 | * @param float|int|string $value |
||
1274 | * @param bool $recursive |
||
1275 | * @param bool $strict |
||
1276 | * |
||
1277 | * @return bool |
||
1278 | * @psalm-mutation-free |
||
1279 | */ |
||
1280 | 23 | public function contains($value, bool $recursive = false, bool $strict = true): bool |
|
1302 | |||
1303 | /** |
||
1304 | * Check if an (case-insensitive) string is in the current array. |
||
1305 | * |
||
1306 | * EXAMPLE: <code> |
||
1307 | * a(['E', 'é'])->containsCaseInsensitive('É'); // true |
||
1308 | * </code> |
||
1309 | * |
||
1310 | * @param mixed $value |
||
1311 | * @param bool $recursive |
||
1312 | * |
||
1313 | * @return bool |
||
1314 | * @psalm-mutation-free |
||
1315 | * |
||
1316 | * @psalm-suppress InvalidCast - hack for int|float|bool support |
||
1317 | */ |
||
1318 | 26 | public function containsCaseInsensitive($value, $recursive = false): bool |
|
1349 | |||
1350 | /** |
||
1351 | * Check if the given key/index exists in the array. |
||
1352 | * |
||
1353 | * EXAMPLE: <code> |
||
1354 | * a([1 => true])->containsKey(1); // true |
||
1355 | * </code> |
||
1356 | * |
||
1357 | * @param int|string $key <p>key/index to search for</p> |
||
1358 | * |
||
1359 | * @return bool |
||
1360 | * <p>Returns true if the given key/index exists in the array, false otherwise.</p> |
||
1361 | * |
||
1362 | * @psalm-mutation-free |
||
1363 | */ |
||
1364 | 4 | public function containsKey($key): bool |
|
1368 | |||
1369 | /** |
||
1370 | * Check if all given needles are present in the array as key/index. |
||
1371 | * |
||
1372 | * EXAMPLE: <code> |
||
1373 | * a([1 => true])->containsKeys(array(1 => 0)); // true |
||
1374 | * </code> |
||
1375 | * |
||
1376 | * @param array $needles <p>The keys you are searching for.</p> |
||
1377 | * @param bool $recursive |
||
1378 | * |
||
1379 | * @return bool |
||
1380 | * <p>Returns true if all the given keys/indexes exists in the array, false otherwise.</p> |
||
1381 | * |
||
1382 | * @psalm-param array<mixed,mixed>|array<TKey> $needles |
||
1383 | * @psalm-mutation-free |
||
1384 | */ |
||
1385 | 2 | public function containsKeys(array $needles, $recursive = false): bool |
|
1413 | |||
1414 | /** |
||
1415 | * Check if all given needles are present in the array as key/index. |
||
1416 | * |
||
1417 | * @param array $needles <p>The keys you are searching for.</p> |
||
1418 | * |
||
1419 | * @return bool |
||
1420 | * <p>Returns true if all the given keys/indexes exists in the array, false otherwise.</p> |
||
1421 | * |
||
1422 | * @psalm-param array<mixed,mixed>|array<TKey> $needles |
||
1423 | * @psalm-mutation-free |
||
1424 | */ |
||
1425 | 1 | public function containsKeysRecursive(array $needles): bool |
|
1429 | |||
1430 | /** |
||
1431 | * alias: for "Arrayy->contains()" |
||
1432 | * |
||
1433 | * @param float|int|string $value |
||
1434 | * |
||
1435 | * @return bool |
||
1436 | * |
||
1437 | * @see Arrayy::contains() |
||
1438 | * @psalm-mutation-free |
||
1439 | */ |
||
1440 | 9 | public function containsValue($value): bool |
|
1444 | |||
1445 | /** |
||
1446 | * alias: for "Arrayy->contains($value, true)" |
||
1447 | * |
||
1448 | * @param float|int|string $value |
||
1449 | * |
||
1450 | * @return bool |
||
1451 | * |
||
1452 | * @see Arrayy::contains() |
||
1453 | * @psalm-mutation-free |
||
1454 | */ |
||
1455 | 18 | public function containsValueRecursive($value): bool |
|
1459 | |||
1460 | /** |
||
1461 | * Check if all given needles are present in the array. |
||
1462 | * |
||
1463 | * EXAMPLE: <code> |
||
1464 | * a([1, true])->containsValues(array(1, true)); // true |
||
1465 | * </code> |
||
1466 | * |
||
1467 | * @param array $needles |
||
1468 | * |
||
1469 | * @return bool |
||
1470 | * <p>Returns true if all the given values exists in the array, false otherwise.</p> |
||
1471 | * |
||
1472 | * @psalm-param array<mixed>|array<T> $needles |
||
1473 | * @psalm-mutation-free |
||
1474 | */ |
||
1475 | 1 | public function containsValues(array $needles): bool |
|
1481 | |||
1482 | /** |
||
1483 | * Counts all the values of an array |
||
1484 | * |
||
1485 | * @see http://php.net/manual/en/function.array-count-values.php |
||
1486 | * |
||
1487 | * @return static |
||
1488 | * <p> |
||
1489 | * (Immutable) |
||
1490 | * An associative Arrayy-object of values from input as |
||
1491 | * keys and their count as value. |
||
1492 | * </p> |
||
1493 | * |
||
1494 | * @psalm-return static<TKey,T> |
||
1495 | * @psalm-mutation-free |
||
1496 | */ |
||
1497 | 7 | public function countValues(): self |
|
1501 | |||
1502 | /** |
||
1503 | * Creates an Arrayy object. |
||
1504 | * |
||
1505 | * @param mixed $data |
||
1506 | * @param string $iteratorClass |
||
1507 | * @param bool $checkPropertiesInConstructor |
||
1508 | * |
||
1509 | * @return static |
||
1510 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1511 | * |
||
1512 | * @psalm-param class-string<\Arrayy\ArrayyIterator> $iteratorClass |
||
1513 | * |
||
1514 | * @psalm-mutation-free |
||
1515 | */ |
||
1516 | 717 | public static function create( |
|
1527 | |||
1528 | /** |
||
1529 | * Flatten an array with the given character as a key delimiter |
||
1530 | * |
||
1531 | * @param string $delimiter |
||
1532 | * @param string $prepend |
||
1533 | * @param array|null $items |
||
1534 | * |
||
1535 | * @return array |
||
1536 | */ |
||
1537 | 2 | public function flatten($delimiter = '.', $prepend = '', $items = null) |
|
1560 | |||
1561 | /** |
||
1562 | * WARNING: Creates an Arrayy object by reference. |
||
1563 | * |
||
1564 | * @param array $array |
||
1565 | * |
||
1566 | * @return $this |
||
1567 | * <p>(Mutable) Return this Arrayy object.</p> |
||
1568 | * |
||
1569 | * @psalm-param array<mixed,mixed>|array<array-key,mixed> $array |
||
1570 | */ |
||
1571 | 27 | public function createByReference(array &$array = []): self |
|
1579 | |||
1580 | /** |
||
1581 | * Create an new instance from a callable function which will return an Generator. |
||
1582 | * |
||
1583 | * @param callable $generatorFunction |
||
1584 | * |
||
1585 | * @return static |
||
1586 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1587 | * |
||
1588 | * @psalm-param callable():\Generator<array-key,mixed> $generatorFunction |
||
1589 | * |
||
1590 | * @psalm-mutation-free |
||
1591 | */ |
||
1592 | 7 | public static function createFromGeneratorFunction(callable $generatorFunction): self |
|
1596 | |||
1597 | /** |
||
1598 | * Create an new instance filled with a copy of values from a "Generator"-object. |
||
1599 | * |
||
1600 | * @param \Generator $generator |
||
1601 | * |
||
1602 | * @return static |
||
1603 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1604 | * |
||
1605 | * @psalm-param \Generator<array-key,mixed> $generator |
||
1606 | * |
||
1607 | * @psalm-mutation-free |
||
1608 | */ |
||
1609 | 4 | public static function createFromGeneratorImmutable(\Generator $generator): self |
|
1613 | |||
1614 | /** |
||
1615 | * Create an new Arrayy object via JSON. |
||
1616 | * |
||
1617 | * @param string $json |
||
1618 | * |
||
1619 | * @return static |
||
1620 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1621 | * |
||
1622 | * @psalm-mutation-free |
||
1623 | */ |
||
1624 | 5 | public static function createFromJson(string $json): self |
|
1628 | |||
1629 | /** |
||
1630 | * Create an new Arrayy object via JSON. |
||
1631 | * |
||
1632 | * @param array $array |
||
1633 | * |
||
1634 | * @return static |
||
1635 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1636 | * |
||
1637 | * @psalm-mutation-free |
||
1638 | */ |
||
1639 | 1 | public static function createFromArray(array $array): self |
|
1643 | |||
1644 | /** |
||
1645 | * Create an new instance filled with values from an object that is iterable. |
||
1646 | * |
||
1647 | * @param \Traversable $object <p>iterable object</p> |
||
1648 | * |
||
1649 | * @return static |
||
1650 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1651 | * |
||
1652 | * @psalm-param \Traversable<array-key,mixed> $object |
||
1653 | * |
||
1654 | * @psalm-mutation-free |
||
1655 | */ |
||
1656 | 4 | public static function createFromObject(\Traversable $object): self |
|
1676 | |||
1677 | /** |
||
1678 | * Create an new instance filled with values from an object. |
||
1679 | * |
||
1680 | * @param object $object |
||
1681 | * |
||
1682 | * @return static |
||
1683 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1684 | * |
||
1685 | * @psalm-mutation-free |
||
1686 | */ |
||
1687 | 5 | public static function createFromObjectVars($object): self |
|
1691 | |||
1692 | /** |
||
1693 | * Create an new Arrayy object via string. |
||
1694 | * |
||
1695 | * @param string $str <p>The input string.</p> |
||
1696 | * @param string|null $delimiter <p>The boundary string.</p> |
||
1697 | * @param string|null $regEx <p>Use the $delimiter or the $regEx, so if $pattern is null, $delimiter will be |
||
1698 | * used.</p> |
||
1699 | * |
||
1700 | * @return static |
||
1701 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1702 | * |
||
1703 | * @psalm-mutation-free |
||
1704 | */ |
||
1705 | 10 | public static function createFromString(string $str, string $delimiter = null, string $regEx = null): self |
|
1737 | |||
1738 | /** |
||
1739 | * Create an new instance filled with a copy of values from a "Traversable"-object. |
||
1740 | * |
||
1741 | * @param \Traversable $traversable |
||
1742 | * |
||
1743 | * @return static |
||
1744 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1745 | * |
||
1746 | * @psalm-param \Traversable<array-key,mixed> $traversable |
||
1747 | * |
||
1748 | * @psalm-mutation-free |
||
1749 | */ |
||
1750 | 1 | public static function createFromTraversableImmutable(\Traversable $traversable): self |
|
1754 | |||
1755 | /** |
||
1756 | * Create an new instance containing a range of elements. |
||
1757 | * |
||
1758 | * @param float|int|string $low <p>First value of the sequence.</p> |
||
1759 | * @param float|int|string $high <p>The sequence is ended upon reaching the end value.</p> |
||
1760 | * @param float|int $step <p>Used as the increment between elements in the sequence.</p> |
||
1761 | * |
||
1762 | * @return static |
||
1763 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1764 | * |
||
1765 | * @psalm-mutation-free |
||
1766 | */ |
||
1767 | 2 | public static function createWithRange($low, $high, $step = 1): self |
|
1771 | |||
1772 | /** |
||
1773 | * Gets the element of the array at the current internal iterator position. |
||
1774 | * |
||
1775 | * @return false|mixed |
||
1776 | */ |
||
1777 | public function current() |
||
1781 | |||
1782 | /** |
||
1783 | * Custom sort by index via "uksort". |
||
1784 | * |
||
1785 | * EXAMPLE: <code> |
||
1786 | * $callable = function ($a, $b) { |
||
1787 | * if ($a == $b) { |
||
1788 | * return 0; |
||
1789 | * } |
||
1790 | * return ($a > $b) ? 1 : -1; |
||
1791 | * }; |
||
1792 | * $arrayy = a(['three' => 3, 'one' => 1, 'two' => 2]); |
||
1793 | * $resultArrayy = $arrayy->customSortKeys($callable); // Arrayy['one' => 1, 'three' => 3, 'two' => 2] |
||
1794 | * </code> |
||
1795 | * |
||
1796 | * @see http://php.net/manual/en/function.uksort.php |
||
1797 | * |
||
1798 | * @param callable $function |
||
1799 | * |
||
1800 | * @throws \InvalidArgumentException |
||
1801 | * |
||
1802 | * @return $this |
||
1803 | * <p>(Mutable) Return this Arrayy object.</p> |
||
1804 | * |
||
1805 | * @psalm-return static<TKey,T> |
||
1806 | */ |
||
1807 | 5 | public function customSortKeys(callable $function): self |
|
1815 | |||
1816 | /** |
||
1817 | * Custom sort by index via "uksort". |
||
1818 | * |
||
1819 | * @see http://php.net/manual/en/function.uksort.php |
||
1820 | * |
||
1821 | * @param callable $function |
||
1822 | * |
||
1823 | * @throws \InvalidArgumentException |
||
1824 | * |
||
1825 | * @return $this |
||
1826 | * <p>(Immutable) Return this Arrayy object.</p> |
||
1827 | * |
||
1828 | * @psalm-return static<TKey,T> |
||
1829 | * @psalm-mutation-free |
||
1830 | */ |
||
1831 | 1 | public function customSortKeysImmutable(callable $function): self |
|
1844 | |||
1845 | /** |
||
1846 | * Custom sort by value via "usort". |
||
1847 | * |
||
1848 | * EXAMPLE: <code> |
||
1849 | * $callable = function ($a, $b) { |
||
1850 | * if ($a == $b) { |
||
1851 | * return 0; |
||
1852 | * } |
||
1853 | * return ($a > $b) ? 1 : -1; |
||
1854 | * }; |
||
1855 | * $arrayy = a(['three' => 3, 'one' => 1, 'two' => 2]); |
||
1856 | * $resultArrayy = $arrayy->customSortValues($callable); // Arrayy['one' => 1, 'two' => 2, 'three' => 3] |
||
1857 | * </code> |
||
1858 | * |
||
1859 | * @see http://php.net/manual/en/function.usort.php |
||
1860 | * |
||
1861 | * @param callable $function |
||
1862 | * |
||
1863 | * @throws \InvalidArgumentException |
||
1864 | * |
||
1865 | * @return $this |
||
1866 | * <p>(Mutable) Return this Arrayy object.</p> |
||
1867 | * |
||
1868 | * @psalm-return static<TKey,T> |
||
1869 | */ |
||
1870 | 10 | View Code Duplication | public function customSortValues($function): self |
1882 | |||
1883 | /** |
||
1884 | * Custom sort by value via "usort". |
||
1885 | * |
||
1886 | * @see http://php.net/manual/en/function.usort.php |
||
1887 | * |
||
1888 | * @param callable $function |
||
1889 | * |
||
1890 | * @throws \InvalidArgumentException |
||
1891 | * |
||
1892 | * @return $this |
||
1893 | * <p>(Immutable) Return this Arrayy object.</p> |
||
1894 | * |
||
1895 | * @psalm-return static<TKey,T> |
||
1896 | * @psalm-mutation-free |
||
1897 | */ |
||
1898 | 4 | public function customSortValuesImmutable($function): self |
|
1909 | |||
1910 | /** |
||
1911 | * Delete the given key or keys. |
||
1912 | * |
||
1913 | * @param int|int[]|string|string[] $keyOrKeys |
||
1914 | * |
||
1915 | * @return void |
||
1916 | */ |
||
1917 | 9 | public function delete($keyOrKeys) |
|
1925 | |||
1926 | /** |
||
1927 | * Return values that are only in the current array. |
||
1928 | * |
||
1929 | * EXAMPLE: <code> |
||
1930 | * a([1 => 1, 2 => 2])->diff([1 => 1]); // Arrayy[2 => 2] |
||
1931 | * </code> |
||
1932 | * |
||
1933 | * @param array ...$array |
||
1934 | * |
||
1935 | * @return static |
||
1936 | * <p>(Immutable)</p> |
||
1937 | * |
||
1938 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$array |
||
1939 | * @psalm-return static<TKey,T> |
||
1940 | * @psalm-mutation-free |
||
1941 | */ |
||
1942 | 13 | public function diff(...$array): self |
|
1950 | |||
1951 | /** |
||
1952 | * Return values that are only in the current array. |
||
1953 | * |
||
1954 | * @param array ...$array |
||
1955 | * |
||
1956 | * @return static |
||
1957 | * <p>(Immutable)</p> |
||
1958 | * |
||
1959 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$array |
||
1960 | * @psalm-return static<TKey,T> |
||
1961 | * @psalm-mutation-free |
||
1962 | */ |
||
1963 | 8 | public function diffKey(...$array): self |
|
1971 | |||
1972 | /** |
||
1973 | * Return values and Keys that are only in the current array. |
||
1974 | * |
||
1975 | * @param array $array |
||
1976 | * |
||
1977 | * @return static |
||
1978 | * <p>(Immutable)</p> |
||
1979 | * |
||
1980 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
1981 | * @psalm-return static<TKey,T> |
||
1982 | * @psalm-mutation-free |
||
1983 | */ |
||
1984 | 8 | public function diffKeyAndValue(array $array = []): self |
|
1992 | |||
1993 | /** |
||
1994 | * Return values that are only in the current multi-dimensional array. |
||
1995 | * |
||
1996 | * @param array $array |
||
1997 | * @param array|\Generator|null $helperVariableForRecursion <p>(only for internal usage)</p> |
||
1998 | * |
||
1999 | * @return static |
||
2000 | * <p>(Immutable)</p> |
||
2001 | * |
||
2002 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
2003 | * @psalm-param null|array<TKey,T>|\Generator<TKey,T> $helperVariableForRecursion |
||
2004 | * @psalm-return static<TKey,T> |
||
2005 | * @psalm-mutation-free |
||
2006 | */ |
||
2007 | 1 | public function diffRecursive(array $array = [], $helperVariableForRecursion = null): self |
|
2042 | |||
2043 | /** |
||
2044 | * Return values that are only in the new $array. |
||
2045 | * |
||
2046 | * @param array $array |
||
2047 | * |
||
2048 | * @return static |
||
2049 | * <p>(Immutable)</p> |
||
2050 | * |
||
2051 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
2052 | * @psalm-return static<TKey,T> |
||
2053 | * @psalm-mutation-free |
||
2054 | */ |
||
2055 | 8 | public function diffReverse(array $array = []): self |
|
2063 | |||
2064 | /** |
||
2065 | * Divide an array into two arrays. One with keys and the other with values. |
||
2066 | * |
||
2067 | * @return static |
||
2068 | * <p>(Immutable)</p> |
||
2069 | * |
||
2070 | * @psalm-return static<TKey,T> |
||
2071 | * @psalm-mutation-free |
||
2072 | */ |
||
2073 | 1 | public function divide(): self |
|
2084 | |||
2085 | /** |
||
2086 | * Iterate over the current array and modify the array's value. |
||
2087 | * |
||
2088 | * @param \Closure $closure |
||
2089 | * |
||
2090 | * @return static |
||
2091 | * <p>(Immutable)</p> |
||
2092 | * |
||
2093 | * @psalm-return static<TKey,T> |
||
2094 | * @psalm-mutation-free |
||
2095 | */ |
||
2096 | 5 | View Code Duplication | public function each(\Closure $closure): self |
2111 | |||
2112 | /** |
||
2113 | * Sets the internal iterator to the last element in the array and returns this element. |
||
2114 | * |
||
2115 | * @return mixed |
||
2116 | */ |
||
2117 | public function end() |
||
2121 | |||
2122 | /** |
||
2123 | * Check if a value is in the current array using a closure. |
||
2124 | * |
||
2125 | * @param \Closure $closure |
||
2126 | * |
||
2127 | * @return bool |
||
2128 | * <p>Returns true if the given value is found, false otherwise.</p> |
||
2129 | */ |
||
2130 | 4 | public function exists(\Closure $closure): bool |
|
2145 | |||
2146 | /** |
||
2147 | * Fill the array until "$num" with "$default" values. |
||
2148 | * |
||
2149 | * @param int $num |
||
2150 | * @param mixed $default |
||
2151 | * |
||
2152 | * @return static |
||
2153 | * <p>(Immutable)</p> |
||
2154 | * |
||
2155 | * @psalm-return static<TKey,T> |
||
2156 | * @psalm-mutation-free |
||
2157 | */ |
||
2158 | 8 | public function fillWithDefaults(int $num, $default = null): self |
|
2181 | |||
2182 | /** |
||
2183 | * Find all items in an array that pass the truth test. |
||
2184 | * |
||
2185 | * @param \Closure|null $closure [optional] <p> |
||
2186 | * The callback function to use |
||
2187 | * </p> |
||
2188 | * <p> |
||
2189 | * If no callback is supplied, all entries of |
||
2190 | * input equal to false (see |
||
2191 | * converting to |
||
2192 | * boolean) will be removed. |
||
2193 | * </p> |
||
2194 | * @param int $flag [optional] <p> |
||
2195 | * Flag determining what arguments are sent to <i>callback</i>: |
||
2196 | * </p><ul> |
||
2197 | * <li> |
||
2198 | * <b>ARRAY_FILTER_USE_KEY</b> [1] - pass key as the only argument |
||
2199 | * to <i>callback</i> instead of the value</span> |
||
2200 | * </li> |
||
2201 | * <li> |
||
2202 | * <b>ARRAY_FILTER_USE_BOTH</b> [2] - pass both value and key as |
||
2203 | * arguments to <i>callback</i> instead of the value</span> |
||
2204 | * </li> |
||
2205 | * </ul> |
||
2206 | * |
||
2207 | * @return static |
||
2208 | * <p>(Immutable)</p> |
||
2209 | * |
||
2210 | * @psalm-param \Closure(T=,TKey=):bool|\Closure(T=):bool $closure |
||
2211 | * @psalm-return static<TKey,T> |
||
2212 | * @psalm-mutation-free |
||
2213 | */ |
||
2214 | 12 | public function filter($closure = null, int $flag = \ARRAY_FILTER_USE_BOTH) |
|
2226 | |||
2227 | /** |
||
2228 | * Filters an array of objects (or a numeric array of associative arrays) based on the value of a particular |
||
2229 | * property within that. |
||
2230 | * |
||
2231 | * @param string $property |
||
2232 | * @param string|string[] $value |
||
2233 | * @param string $comparisonOp |
||
2234 | * <p> |
||
2235 | * 'eq' (equals),<br /> |
||
2236 | * 'gt' (greater),<br /> |
||
2237 | * 'gte' || 'ge' (greater or equals),<br /> |
||
2238 | * 'lt' (less),<br /> |
||
2239 | * 'lte' || 'le' (less or equals),<br /> |
||
2240 | * 'ne' (not equals),<br /> |
||
2241 | * 'contains',<br /> |
||
2242 | * 'notContains',<br /> |
||
2243 | * 'newer' (via strtotime),<br /> |
||
2244 | * 'older' (via strtotime),<br /> |
||
2245 | * </p> |
||
2246 | * |
||
2247 | * @return static |
||
2248 | * <p>(Immutable)</p> |
||
2249 | * |
||
2250 | * @psalm-return static<TKey,T> |
||
2251 | * @psalm-mutation-free |
||
2252 | * |
||
2253 | * @psalm-suppress MissingClosureReturnType |
||
2254 | * @psalm-suppress MissingClosureParamType |
||
2255 | */ |
||
2256 | 1 | public function filterBy( |
|
2328 | |||
2329 | /** |
||
2330 | * Find the first item in an array that passes the truth test, |
||
2331 | * otherwise return false |
||
2332 | * |
||
2333 | * @param \Closure $closure |
||
2334 | * |
||
2335 | * @return false|mixed |
||
2336 | * <p>Return false if we did not find the value.</p> |
||
2337 | */ |
||
2338 | 8 | View Code Duplication | public function find(\Closure $closure) |
2348 | |||
2349 | /** |
||
2350 | * find by ... |
||
2351 | * |
||
2352 | * @param string $property |
||
2353 | * @param string|string[] $value |
||
2354 | * @param string $comparisonOp |
||
2355 | * |
||
2356 | * @return static |
||
2357 | * <p>(Immutable)</p> |
||
2358 | * |
||
2359 | * @psalm-return static<TKey,T> |
||
2360 | * @psalm-mutation-free |
||
2361 | */ |
||
2362 | 1 | public function findBy(string $property, $value, string $comparisonOp = 'eq'): self |
|
2366 | |||
2367 | /** |
||
2368 | * Get the first value from the current array. |
||
2369 | * |
||
2370 | * @return mixed |
||
2371 | * <p>Return null if there wasn't a element.</p> |
||
2372 | */ |
||
2373 | 22 | public function first() |
|
2382 | |||
2383 | /** |
||
2384 | * Get the first key from the current array. |
||
2385 | * |
||
2386 | * @return mixed |
||
2387 | * <p>Return null if there wasn't a element.</p> |
||
2388 | * @psalm-mutation-free |
||
2389 | */ |
||
2390 | 29 | public function firstKey() |
|
2396 | |||
2397 | /** |
||
2398 | * Get the first value(s) from the current array. |
||
2399 | * And will return an empty array if there was no first entry. |
||
2400 | * |
||
2401 | * @param int|null $number <p>How many values you will take?</p> |
||
2402 | * |
||
2403 | * @return static |
||
2404 | * <p>(Immutable)</p> |
||
2405 | * |
||
2406 | * @psalm-return static<TKey,T> |
||
2407 | * @psalm-mutation-free |
||
2408 | */ |
||
2409 | 37 | View Code Duplication | public function firstsImmutable(int $number = null): self |
2425 | |||
2426 | /** |
||
2427 | * Get the first value(s) from the current array. |
||
2428 | * And will return an empty array if there was no first entry. |
||
2429 | * |
||
2430 | * @param int|null $number <p>How many values you will take?</p> |
||
2431 | * |
||
2432 | * @return static |
||
2433 | * <p>(Immutable)</p> |
||
2434 | * |
||
2435 | * @psalm-return static<TKey,T> |
||
2436 | * @psalm-mutation-free |
||
2437 | */ |
||
2438 | 3 | View Code Duplication | public function firstsKeys(int $number = null): self |
2454 | |||
2455 | /** |
||
2456 | * Get and rmove the first value(s) from the current array. |
||
2457 | * And will return an empty array if there was no first entry. |
||
2458 | * |
||
2459 | * @param int|null $number <p>How many values you will take?</p> |
||
2460 | * |
||
2461 | * @return $this |
||
2462 | * <p>(Mutable)</p> |
||
2463 | * |
||
2464 | * @psalm-return static<TKey,T> |
||
2465 | */ |
||
2466 | 34 | public function firstsMutable(int $number = null): self |
|
2478 | |||
2479 | /** |
||
2480 | * Exchanges all keys with their associated values in an array. |
||
2481 | * |
||
2482 | * @return static |
||
2483 | * <p>(Immutable)</p> |
||
2484 | * |
||
2485 | * @psalm-return static<TKey,T> |
||
2486 | * @psalm-mutation-free |
||
2487 | */ |
||
2488 | 1 | public function flip(): self |
|
2496 | |||
2497 | /** |
||
2498 | * Get a value from an array (optional using dot-notation). |
||
2499 | * |
||
2500 | * @param mixed $key <p>The key to look for.</p> |
||
2501 | * @param mixed $fallback <p>Value to fallback to.</p> |
||
2502 | * @param array $array <p>The array to get from, if it's set to "null" we use the current array from the |
||
2503 | * class.</p> |
||
2504 | * @param bool $useByReference |
||
2505 | * |
||
2506 | * @return mixed|static |
||
2507 | * |
||
2508 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
2509 | * @psalm-mutation-free |
||
2510 | */ |
||
2511 | 242 | public function get( |
|
2675 | |||
2676 | /** |
||
2677 | * alias: for "Arrayy->toArray()" |
||
2678 | * |
||
2679 | * @return array |
||
2680 | * |
||
2681 | * @see Arrayy::getArray() |
||
2682 | * |
||
2683 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
2684 | */ |
||
2685 | 15 | public function getAll(): array |
|
2689 | |||
2690 | /** |
||
2691 | * Get the current array from the "Arrayy"-object. |
||
2692 | * |
||
2693 | * alias for "toArray()" |
||
2694 | * |
||
2695 | * @param bool $convertAllArrayyElements <p> |
||
2696 | * Convert all Child-"Arrayy" objects also to arrays. |
||
2697 | * </p> |
||
2698 | * @param bool $preserveKeys <p> |
||
2699 | * e.g.: A generator maybe return the same key more then once, |
||
2700 | * so maybe you will ignore the keys. |
||
2701 | * </p> |
||
2702 | * |
||
2703 | * @return array |
||
2704 | * |
||
2705 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
2706 | * @psalm-mutation-free |
||
2707 | * |
||
2708 | * @see Arrayy::toArray() |
||
2709 | */ |
||
2710 | 500 | public function getArray( |
|
2719 | |||
2720 | /** |
||
2721 | * @param string $json |
||
2722 | * |
||
2723 | * @return $this |
||
2724 | */ |
||
2725 | 3 | public static function createFromJsonMapper(string $json) |
|
2741 | |||
2742 | /** |
||
2743 | * @return array<int|string,TypeCheckInterface>|mixed|TypeCheckArray<int|string,TypeCheckInterface>|TypeInterface |
||
2744 | * |
||
2745 | * @internal |
||
2746 | */ |
||
2747 | 6 | public function getPhpDocPropertiesFromClass() |
|
2755 | |||
2756 | /** |
||
2757 | * Get the current array from the "Arrayy"-object as list. |
||
2758 | * |
||
2759 | * alias for "toList()" |
||
2760 | * |
||
2761 | * @param bool $convertAllArrayyElements <p> |
||
2762 | * Convert all Child-"Arrayy" objects also to arrays. |
||
2763 | * </p> |
||
2764 | * |
||
2765 | * @return array |
||
2766 | * |
||
2767 | * @psalm-return array<int,mixed>|array<int,T> |
||
2768 | * @psalm-mutation-free |
||
2769 | * |
||
2770 | * @see Arrayy::toList() |
||
2771 | */ |
||
2772 | 1 | public function getList(bool $convertAllArrayyElements = false): array |
|
2776 | |||
2777 | /** |
||
2778 | * Returns the values from a single column of the input array, identified by |
||
2779 | * the $columnKey, can be used to extract data-columns from multi-arrays. |
||
2780 | * |
||
2781 | * Info: Optionally, you may provide an $indexKey to index the values in the returned |
||
2782 | * array by the values from the $indexKey column in the input array. |
||
2783 | * |
||
2784 | * @param mixed $columnKey |
||
2785 | * @param mixed $indexKey |
||
2786 | * |
||
2787 | * @return static |
||
2788 | * <p>(Immutable)</p> |
||
2789 | * |
||
2790 | * @psalm-return static<TKey,T> |
||
2791 | * @psalm-mutation-free |
||
2792 | */ |
||
2793 | 1 | public function getColumn($columnKey = null, $indexKey = null): self |
|
2801 | |||
2802 | /** |
||
2803 | * Get the current array from the "Arrayy"-object as generator by reference. |
||
2804 | * |
||
2805 | * @return \Generator |
||
2806 | * |
||
2807 | * @psalm-return \Generator<mixed,T>|\Generator<TKey,T> |
||
2808 | */ |
||
2809 | 75 | public function &getGeneratorByReference(): \Generator |
|
2828 | |||
2829 | /** |
||
2830 | * Get the current array from the "Arrayy"-object as generator. |
||
2831 | * |
||
2832 | * @return \Generator |
||
2833 | * |
||
2834 | * @psalm-return \Generator<mixed,T>|\Generator<TKey,T> |
||
2835 | * @psalm-mutation-free |
||
2836 | */ |
||
2837 | 996 | public function getGenerator(): \Generator |
|
2847 | |||
2848 | /** |
||
2849 | * alias: for "Arrayy->keys()" |
||
2850 | * |
||
2851 | * @return static |
||
2852 | * <p>(Immutable)</p> |
||
2853 | * |
||
2854 | * @see Arrayy::keys() |
||
2855 | * |
||
2856 | * @psalm-return static<array-key,TKey> |
||
2857 | * @psalm-mutation-free |
||
2858 | */ |
||
2859 | 2 | public function getKeys() |
|
2863 | |||
2864 | /** |
||
2865 | * Get the current array from the "Arrayy"-object as object. |
||
2866 | * |
||
2867 | * @return \stdClass |
||
2868 | */ |
||
2869 | 4 | public function getObject(): \stdClass |
|
2873 | |||
2874 | /** |
||
2875 | * alias: for "Arrayy->randomImmutable()" |
||
2876 | * |
||
2877 | * @return static |
||
2878 | * <p>(Immutable)</p> |
||
2879 | * |
||
2880 | * @see Arrayy::randomImmutable() |
||
2881 | * |
||
2882 | * @psalm-return static<int|array-key,T> |
||
2883 | */ |
||
2884 | 4 | public function getRandom(): self |
|
2888 | |||
2889 | /** |
||
2890 | * alias: for "Arrayy->randomKey()" |
||
2891 | * |
||
2892 | * @return mixed |
||
2893 | * <p>Get a key/index or null if there wasn't a key/index.</p> |
||
2894 | * |
||
2895 | * @see Arrayy::randomKey() |
||
2896 | */ |
||
2897 | 3 | public function getRandomKey() |
|
2901 | |||
2902 | /** |
||
2903 | * alias: for "Arrayy->randomKeys()" |
||
2904 | * |
||
2905 | * @param int $number |
||
2906 | * |
||
2907 | * @return static |
||
2908 | * <p>(Immutable)</p> |
||
2909 | * |
||
2910 | * @see Arrayy::randomKeys() |
||
2911 | * |
||
2912 | * @psalm-return static<TKey,T> |
||
2913 | */ |
||
2914 | 8 | public function getRandomKeys(int $number): self |
|
2918 | |||
2919 | /** |
||
2920 | * alias: for "Arrayy->randomValue()" |
||
2921 | * |
||
2922 | * @return mixed |
||
2923 | * <p>Get a random value or null if there wasn't a value.</p> |
||
2924 | * |
||
2925 | * @see Arrayy::randomValue() |
||
2926 | */ |
||
2927 | 3 | public function getRandomValue() |
|
2931 | |||
2932 | /** |
||
2933 | * alias: for "Arrayy->randomValues()" |
||
2934 | * |
||
2935 | * @param int $number |
||
2936 | * |
||
2937 | * @return static |
||
2938 | * <p>(Immutable)</p> |
||
2939 | * |
||
2940 | * @see Arrayy::randomValues() |
||
2941 | * |
||
2942 | * @psalm-return static<TKey,T> |
||
2943 | */ |
||
2944 | 6 | public function getRandomValues(int $number): self |
|
2948 | |||
2949 | /** |
||
2950 | * Gets all values. |
||
2951 | * |
||
2952 | * @return static |
||
2953 | * <p>The values of all elements in this array, in the order they |
||
2954 | * appear in the array.</p> |
||
2955 | * |
||
2956 | * @psalm-return static<TKey,T> |
||
2957 | */ |
||
2958 | 4 | public function getValues() |
|
2968 | |||
2969 | /** |
||
2970 | * Gets all values via Generator. |
||
2971 | * |
||
2972 | * @return \Generator |
||
2973 | * <p>The values of all elements in this array, in the order they |
||
2974 | * appear in the array as Generator.</p> |
||
2975 | * |
||
2976 | * @psalm-return \Generator<TKey,T> |
||
2977 | */ |
||
2978 | 4 | public function getValuesYield(): \Generator |
|
2982 | |||
2983 | /** |
||
2984 | * Group values from a array according to the results of a closure. |
||
2985 | * |
||
2986 | * @param callable|string $grouper <p>A callable function name.</p> |
||
2987 | * @param bool $saveKeys |
||
2988 | * |
||
2989 | * @return static |
||
2990 | * <p>(Immutable)</p> |
||
2991 | * |
||
2992 | * @psalm-return static<TKey,T> |
||
2993 | * @psalm-mutation-free |
||
2994 | */ |
||
2995 | 4 | public function group($grouper, bool $saveKeys = false): self |
|
3036 | |||
3037 | /** |
||
3038 | * Check if an array has a given key. |
||
3039 | * |
||
3040 | * @param mixed $key |
||
3041 | * |
||
3042 | * @return bool |
||
3043 | */ |
||
3044 | 30 | public function has($key): bool |
|
3070 | |||
3071 | /** |
||
3072 | * Check if an array has a given value. |
||
3073 | * |
||
3074 | * INFO: if you need to search recursive please use ```contains()``` |
||
3075 | * |
||
3076 | * @param mixed $value |
||
3077 | * |
||
3078 | * @return bool |
||
3079 | */ |
||
3080 | 1 | public function hasValue($value): bool |
|
3084 | |||
3085 | /** |
||
3086 | * Implodes the values of this array. |
||
3087 | * |
||
3088 | * @param string $glue |
||
3089 | * |
||
3090 | * @return string |
||
3091 | * @psalm-mutation-free |
||
3092 | */ |
||
3093 | 28 | public function implode(string $glue = ''): string |
|
3097 | |||
3098 | /** |
||
3099 | * Implodes the keys of this array. |
||
3100 | * |
||
3101 | * @param string $glue |
||
3102 | * |
||
3103 | * @return string |
||
3104 | * @psalm-mutation-free |
||
3105 | */ |
||
3106 | 8 | public function implodeKeys(string $glue = ''): string |
|
3110 | |||
3111 | /** |
||
3112 | * Given a list and an iterate-function that returns |
||
3113 | * a key for each element in the list (or a property name), |
||
3114 | * returns an object with an index of each item. |
||
3115 | * |
||
3116 | * @param mixed $key |
||
3117 | * |
||
3118 | * @return static |
||
3119 | * <p>(Immutable)</p> |
||
3120 | * |
||
3121 | * @psalm-return static<TKey,T> |
||
3122 | * @psalm-mutation-free |
||
3123 | */ |
||
3124 | 4 | public function indexBy($key): self |
|
3141 | |||
3142 | /** |
||
3143 | * alias: for "Arrayy->searchIndex()" |
||
3144 | * |
||
3145 | * @param mixed $value <p>The value to search for.</p> |
||
3146 | * |
||
3147 | * @return false|mixed |
||
3148 | * |
||
3149 | * @see Arrayy::searchIndex() |
||
3150 | */ |
||
3151 | 4 | public function indexOf($value) |
|
3155 | |||
3156 | /** |
||
3157 | * Get everything but the last..$to items. |
||
3158 | * |
||
3159 | * @param int $to |
||
3160 | * |
||
3161 | * @return static |
||
3162 | * <p>(Immutable)</p> |
||
3163 | * |
||
3164 | * @psalm-return static<TKey,T> |
||
3165 | * @psalm-mutation-free |
||
3166 | */ |
||
3167 | 12 | public function initial(int $to = 1): self |
|
3171 | |||
3172 | /** |
||
3173 | * Return an array with all elements found in input array. |
||
3174 | * |
||
3175 | * @param array $search |
||
3176 | * @param bool $keepKeys |
||
3177 | * |
||
3178 | * @return static |
||
3179 | * <p>(Immutable)</p> |
||
3180 | * |
||
3181 | * @psalm-param array<mixed,mixed>|array<TKey,T> $search |
||
3182 | * @psalm-return static<TKey,T> |
||
3183 | * @psalm-mutation-free |
||
3184 | */ |
||
3185 | 4 | public function intersection(array $search, bool $keepKeys = false): self |
|
3211 | |||
3212 | /** |
||
3213 | * Return an array with all elements found in input array. |
||
3214 | * |
||
3215 | * @param array ...$array |
||
3216 | * |
||
3217 | * @return static |
||
3218 | * <p>(Immutable)</p> |
||
3219 | * |
||
3220 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$array |
||
3221 | * @psalm-return static<TKey,T> |
||
3222 | * @psalm-mutation-free |
||
3223 | */ |
||
3224 | 1 | public function intersectionMulti(...$array): self |
|
3232 | |||
3233 | /** |
||
3234 | * Return a boolean flag which indicates whether the two input arrays have any common elements. |
||
3235 | * |
||
3236 | * @param array $search |
||
3237 | * |
||
3238 | * @return bool |
||
3239 | * |
||
3240 | * @psalm-param array<mixed,mixed>|array<TKey,T> $search |
||
3241 | */ |
||
3242 | 1 | public function intersects(array $search): bool |
|
3246 | |||
3247 | /** |
||
3248 | * Invoke a function on all of an array's values. |
||
3249 | * |
||
3250 | * @param callable $callable |
||
3251 | * @param mixed $arguments |
||
3252 | * |
||
3253 | * @return static |
||
3254 | * <p>(Immutable)</p> |
||
3255 | * |
||
3256 | * @psalm-param callable(T=,mixed):mixed $callable |
||
3257 | * @psalm-return static<TKey,T> |
||
3258 | * @psalm-mutation-free |
||
3259 | */ |
||
3260 | 1 | View Code Duplication | public function invoke($callable, $arguments = []): self |
3284 | |||
3285 | /** |
||
3286 | * Check whether array is associative or not. |
||
3287 | * |
||
3288 | * @param bool $recursive |
||
3289 | * |
||
3290 | * @return bool |
||
3291 | * <p>Returns true if associative, false otherwise.</p> |
||
3292 | */ |
||
3293 | 15 | View Code Duplication | public function isAssoc(bool $recursive = false): bool |
3308 | |||
3309 | /** |
||
3310 | * Check if a given key or keys are empty. |
||
3311 | * |
||
3312 | * @param int|int[]|string|string[]|null $keys |
||
3313 | * |
||
3314 | * @return bool |
||
3315 | * <p>Returns true if empty, false otherwise.</p> |
||
3316 | * @psalm-mutation-free |
||
3317 | */ |
||
3318 | 45 | public function isEmpty($keys = null): bool |
|
3336 | |||
3337 | /** |
||
3338 | * Check if the current array is equal to the given "$array" or not. |
||
3339 | * |
||
3340 | * @param array $array |
||
3341 | * |
||
3342 | * @return bool |
||
3343 | * |
||
3344 | * @psalm-param array<mixed,mixed> $array |
||
3345 | */ |
||
3346 | 1 | public function isEqual(array $array): bool |
|
3350 | |||
3351 | /** |
||
3352 | * Check if the current array is a multi-array. |
||
3353 | * |
||
3354 | * @return bool |
||
3355 | */ |
||
3356 | 22 | public function isMultiArray(): bool |
|
3364 | |||
3365 | /** |
||
3366 | * Check whether array is numeric or not. |
||
3367 | * |
||
3368 | * @return bool |
||
3369 | * <p>Returns true if numeric, false otherwise.</p> |
||
3370 | */ |
||
3371 | 5 | View Code Duplication | public function isNumeric(): bool |
3386 | |||
3387 | /** |
||
3388 | * Check if the current array is sequential [0, 1, 2, 3, 4, 5 ...] or not. |
||
3389 | * |
||
3390 | * @param bool $recursive |
||
3391 | * |
||
3392 | * @return bool |
||
3393 | * @psalm-mutation-free |
||
3394 | */ |
||
3395 | 9 | public function isSequential(bool $recursive = false): bool |
|
3412 | |||
3413 | /** |
||
3414 | * @return array |
||
3415 | * |
||
3416 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
3417 | */ |
||
3418 | 2 | public function jsonSerialize(): array |
|
3422 | |||
3423 | /** |
||
3424 | * Gets the key/index of the element at the current internal iterator position. |
||
3425 | * |
||
3426 | * @return int|string|null |
||
3427 | */ |
||
3428 | public function key() |
||
3432 | |||
3433 | /** |
||
3434 | * Checks if the given key exists in the provided array. |
||
3435 | * |
||
3436 | * INFO: This method only use "array_key_exists()" if you want to use "dot"-notation, |
||
3437 | * then you need to use "Arrayy->offsetExists()". |
||
3438 | * |
||
3439 | * @param int|string $key the key to look for |
||
3440 | * |
||
3441 | * @return bool |
||
3442 | * @psalm-mutation-free |
||
3443 | */ |
||
3444 | 162 | public function keyExists($key): bool |
|
3448 | |||
3449 | /** |
||
3450 | * Get all keys from the current array. |
||
3451 | * |
||
3452 | * @param bool $recursive [optional] <p> |
||
3453 | * Get all keys, also from all sub-arrays from an multi-dimensional array. |
||
3454 | * </p> |
||
3455 | * @param mixed|null $search_values [optional] <p> |
||
3456 | * If specified, then only keys containing these values are returned. |
||
3457 | * </p> |
||
3458 | * @param bool $strict [optional] <p> |
||
3459 | * Determines if strict comparison (===) should be used during the search. |
||
3460 | * </p> |
||
3461 | * |
||
3462 | * @return static |
||
3463 | * <p>(Immutable) An array of all the keys in input.</p> |
||
3464 | * |
||
3465 | * @psalm-return static<array-key,TKey> |
||
3466 | * @psalm-mutation-free |
||
3467 | */ |
||
3468 | 29 | public function keys( |
|
3539 | |||
3540 | /** |
||
3541 | * Sort an array by key in reverse order. |
||
3542 | * |
||
3543 | * @param int $sort_flags [optional] <p> |
||
3544 | * You may modify the behavior of the sort using the optional |
||
3545 | * parameter sort_flags, for details |
||
3546 | * see sort. |
||
3547 | * </p> |
||
3548 | * |
||
3549 | * @return $this |
||
3550 | * <p>(Mutable) Return this Arrayy object.</p> |
||
3551 | * |
||
3552 | * @psalm-return static<TKey,T> |
||
3553 | */ |
||
3554 | 4 | public function krsort(int $sort_flags = 0): self |
|
3562 | |||
3563 | /** |
||
3564 | * Sort an array by key in reverse order. |
||
3565 | * |
||
3566 | * @param int $sort_flags [optional] <p> |
||
3567 | * You may modify the behavior of the sort using the optional |
||
3568 | * parameter sort_flags, for details |
||
3569 | * see sort. |
||
3570 | * </p> |
||
3571 | * |
||
3572 | * @return $this |
||
3573 | * <p>(Immutable) Return this Arrayy object.</p> |
||
3574 | * |
||
3575 | * @psalm-return static<TKey,T> |
||
3576 | * @psalm-mutation-free |
||
3577 | */ |
||
3578 | 4 | public function krsortImmutable(int $sort_flags = 0): self |
|
3589 | |||
3590 | /** |
||
3591 | * Get the last value from the current array. |
||
3592 | * |
||
3593 | * @return mixed|null |
||
3594 | * <p>Return null if there wasn't a element.</p> |
||
3595 | * @psalm-mutation-free |
||
3596 | */ |
||
3597 | 17 | public function last() |
|
3606 | |||
3607 | /** |
||
3608 | * Get the last key from the current array. |
||
3609 | * |
||
3610 | * @return mixed|null |
||
3611 | * <p>Return null if there wasn't a element.</p> |
||
3612 | * @psalm-mutation-free |
||
3613 | */ |
||
3614 | 21 | public function lastKey() |
|
3620 | |||
3621 | /** |
||
3622 | * Get the last value(s) from the current array. |
||
3623 | * |
||
3624 | * @param int|null $number |
||
3625 | * |
||
3626 | * @return static |
||
3627 | * <p>(Immutable)</p> |
||
3628 | * |
||
3629 | * @psalm-return static<TKey,T> |
||
3630 | * @psalm-mutation-free |
||
3631 | */ |
||
3632 | 13 | public function lastsImmutable(int $number = null): self |
|
3662 | |||
3663 | /** |
||
3664 | * Get the last value(s) from the current array. |
||
3665 | * |
||
3666 | * @param int|null $number |
||
3667 | * |
||
3668 | * @return $this |
||
3669 | * <p>(Mutable)</p> |
||
3670 | * |
||
3671 | * @psalm-return static<TKey,T> |
||
3672 | */ |
||
3673 | 13 | public function lastsMutable(int $number = null): self |
|
3701 | |||
3702 | /** |
||
3703 | * Count the values from the current array. |
||
3704 | * |
||
3705 | * alias: for "Arrayy->count()" |
||
3706 | * |
||
3707 | * @param int $mode |
||
3708 | * |
||
3709 | * @return int |
||
3710 | * |
||
3711 | * @see Arrayy::count() |
||
3712 | */ |
||
3713 | 20 | public function length(int $mode = \COUNT_NORMAL): int |
|
3717 | |||
3718 | /** |
||
3719 | * Apply the given function to the every element of the array, |
||
3720 | * collecting the results. |
||
3721 | * |
||
3722 | * @param callable $callable |
||
3723 | * @param bool $useKeyAsSecondParameter |
||
3724 | * @param mixed ...$arguments |
||
3725 | * |
||
3726 | * @return static |
||
3727 | * <p>(Immutable) Arrayy object with modified elements.</p> |
||
3728 | * |
||
3729 | * @psalm-param callable(T,TKey=,mixed=):mixed $callable |
||
3730 | * @psalm-return static<TKey,T> |
||
3731 | * @psalm-mutation-free |
||
3732 | */ |
||
3733 | 5 | public function map( |
|
3766 | |||
3767 | /** |
||
3768 | * Check if all items in current array match a truth test. |
||
3769 | * |
||
3770 | * @param \Closure $closure |
||
3771 | * |
||
3772 | * @return bool |
||
3773 | */ |
||
3774 | 15 | View Code Duplication | public function matches(\Closure $closure): bool |
3790 | |||
3791 | /** |
||
3792 | * Check if any item in the current array matches a truth test. |
||
3793 | * |
||
3794 | * @param \Closure $closure |
||
3795 | * |
||
3796 | * @return bool |
||
3797 | */ |
||
3798 | 14 | View Code Duplication | public function matchesAny(\Closure $closure): bool |
3814 | |||
3815 | /** |
||
3816 | * Get the max value from an array. |
||
3817 | * |
||
3818 | * @return false|mixed |
||
3819 | * <p>Will return false if there are no values.</p> |
||
3820 | */ |
||
3821 | 10 | View Code Duplication | public function max() |
3841 | |||
3842 | /** |
||
3843 | * Merge the new $array into the current array. |
||
3844 | * |
||
3845 | * - keep key,value from the current array, also if the index is in the new $array |
||
3846 | * |
||
3847 | * @param array $array |
||
3848 | * @param bool $recursive |
||
3849 | * |
||
3850 | * @return static |
||
3851 | * <p>(Immutable)</p> |
||
3852 | * |
||
3853 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
3854 | * @psalm-return static<int|TKey,T> |
||
3855 | * @psalm-mutation-free |
||
3856 | */ |
||
3857 | 32 | View Code Duplication | public function mergeAppendKeepIndex(array $array = [], bool $recursive = false): self |
3872 | |||
3873 | /** |
||
3874 | * Merge the new $array into the current array. |
||
3875 | * |
||
3876 | * - replace duplicate assoc-keys from the current array with the key,values from the new $array |
||
3877 | * - create new indexes |
||
3878 | * |
||
3879 | * @param array $array |
||
3880 | * @param bool $recursive |
||
3881 | * |
||
3882 | * @return static |
||
3883 | * <p>(Immutable)</p> |
||
3884 | * |
||
3885 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
3886 | * @psalm-return static<TKey,T> |
||
3887 | * @psalm-mutation-free |
||
3888 | */ |
||
3889 | 19 | View Code Duplication | public function mergeAppendNewIndex(array $array = [], bool $recursive = false): self |
3904 | |||
3905 | /** |
||
3906 | * Merge the the current array into the $array. |
||
3907 | * |
||
3908 | * - use key,value from the new $array, also if the index is in the current array |
||
3909 | * |
||
3910 | * @param array $array |
||
3911 | * @param bool $recursive |
||
3912 | * |
||
3913 | * @return static |
||
3914 | * <p>(Immutable)</p> |
||
3915 | * |
||
3916 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
3917 | * @psalm-return static<TKey,T> |
||
3918 | * @psalm-mutation-free |
||
3919 | */ |
||
3920 | 16 | View Code Duplication | public function mergePrependKeepIndex(array $array = [], bool $recursive = false): self |
3935 | |||
3936 | /** |
||
3937 | * Merge the current array into the new $array. |
||
3938 | * |
||
3939 | * - replace duplicate assoc-keys from new $array with the key,values from the current array |
||
3940 | * - create new indexes |
||
3941 | * |
||
3942 | * @param array $array |
||
3943 | * @param bool $recursive |
||
3944 | * |
||
3945 | * @return static |
||
3946 | * <p>(Immutable)</p> |
||
3947 | * |
||
3948 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
3949 | * @psalm-return static<TKey,T> |
||
3950 | * @psalm-mutation-free |
||
3951 | */ |
||
3952 | 20 | View Code Duplication | public function mergePrependNewIndex(array $array = [], bool $recursive = false): self |
3967 | |||
3968 | /** |
||
3969 | * @return ArrayyMeta|static |
||
3970 | */ |
||
3971 | 16 | public static function meta() |
|
3975 | |||
3976 | /** |
||
3977 | * Get the min value from an array. |
||
3978 | * |
||
3979 | * @return false|mixed |
||
3980 | * <p>Will return false if there are no values.</p> |
||
3981 | */ |
||
3982 | 10 | View Code Duplication | public function min() |
4002 | |||
4003 | /** |
||
4004 | * Get the most used value from the array. |
||
4005 | * |
||
4006 | * @return mixed|null |
||
4007 | * <p>(Immutable) Return null if there wasn't a element.</p> |
||
4008 | * @psalm-mutation-free |
||
4009 | */ |
||
4010 | 3 | public function mostUsedValue() |
|
4014 | |||
4015 | /** |
||
4016 | * Get the most used value from the array. |
||
4017 | * |
||
4018 | * @param int|null $number <p>How many values you will take?</p> |
||
4019 | * |
||
4020 | * @return static |
||
4021 | * <p>(Immutable)</p> |
||
4022 | * |
||
4023 | * @psalm-return static<TKey,T> |
||
4024 | * @psalm-mutation-free |
||
4025 | */ |
||
4026 | 3 | public function mostUsedValues(int $number = null): self |
|
4030 | |||
4031 | /** |
||
4032 | * Move an array element to a new index. |
||
4033 | * |
||
4034 | * cherry-picked from: http://stackoverflow.com/questions/12624153/move-an-array-element-to-a-new-index-in-php |
||
4035 | * |
||
4036 | * @param int|string $from |
||
4037 | * @param int $to |
||
4038 | * |
||
4039 | * @return static |
||
4040 | * <p>(Immutable)</p> |
||
4041 | * |
||
4042 | * @psalm-return static<TKey,T> |
||
4043 | * @psalm-mutation-free |
||
4044 | */ |
||
4045 | 1 | public function moveElement($from, $to): self |
|
4078 | |||
4079 | /** |
||
4080 | * Move an array element to the first place. |
||
4081 | * |
||
4082 | * INFO: Instead of "Arrayy->moveElement()" this method will NOT |
||
4083 | * loss the keys of an indexed array. |
||
4084 | * |
||
4085 | * @param int|string $key |
||
4086 | * |
||
4087 | * @return static |
||
4088 | * <p>(Immutable)</p> |
||
4089 | * |
||
4090 | * @psalm-return static<TKey,T> |
||
4091 | * @psalm-mutation-free |
||
4092 | */ |
||
4093 | 1 | View Code Duplication | public function moveElementToFirstPlace($key): self |
4109 | |||
4110 | /** |
||
4111 | * Move an array element to the last place. |
||
4112 | * |
||
4113 | * INFO: Instead of "Arrayy->moveElement()" this method will NOT |
||
4114 | * loss the keys of an indexed array. |
||
4115 | * |
||
4116 | * @param int|string $key |
||
4117 | * |
||
4118 | * @return static |
||
4119 | * <p>(Immutable)</p> |
||
4120 | * |
||
4121 | * @psalm-return static<TKey,T> |
||
4122 | * @psalm-mutation-free |
||
4123 | */ |
||
4124 | 1 | View Code Duplication | public function moveElementToLastPlace($key): self |
4140 | |||
4141 | /** |
||
4142 | * Moves the internal iterator position to the next element and returns this element. |
||
4143 | * |
||
4144 | * @return false|mixed |
||
4145 | * <p>(Mutable) Will return false if there are no values.</p> |
||
4146 | */ |
||
4147 | public function next() |
||
4151 | |||
4152 | /** |
||
4153 | * Get the next nth keys and values from the array. |
||
4154 | * |
||
4155 | * @param int $step |
||
4156 | * @param int $offset |
||
4157 | * |
||
4158 | * @return static |
||
4159 | * <p>(Immutable)</p> |
||
4160 | * |
||
4161 | * @psalm-return static<TKey,T> |
||
4162 | * @psalm-mutation-free |
||
4163 | */ |
||
4164 | 1 | public function nth(int $step, int $offset = 0): self |
|
4183 | |||
4184 | /** |
||
4185 | * Get a subset of the items from the given array. |
||
4186 | * |
||
4187 | * @param mixed[] $keys |
||
4188 | * |
||
4189 | * @return static |
||
4190 | * <p>(Immutable)</p> |
||
4191 | * |
||
4192 | * @psalm-return static<TKey,T> |
||
4193 | * @psalm-mutation-free |
||
4194 | */ |
||
4195 | 1 | public function only(array $keys): self |
|
4205 | |||
4206 | /** |
||
4207 | * Pad array to the specified size with a given value. |
||
4208 | * |
||
4209 | * @param int $size <p>Size of the result array.</p> |
||
4210 | * @param mixed $value <p>Empty value by default.</p> |
||
4211 | * |
||
4212 | * @return static |
||
4213 | * <p>(Immutable) Arrayy object padded to $size with $value.</p> |
||
4214 | * |
||
4215 | * @psalm-return static<TKey,T> |
||
4216 | * @psalm-mutation-free |
||
4217 | */ |
||
4218 | 5 | public function pad(int $size, $value): self |
|
4226 | |||
4227 | /** |
||
4228 | * Partitions this array in two array according to a predicate. |
||
4229 | * Keys are preserved in the resulting array. |
||
4230 | * |
||
4231 | * @param \Closure $closure |
||
4232 | * <p>The predicate on which to partition.</p> |
||
4233 | * |
||
4234 | * @return array<int, static> |
||
4235 | * <p>An array with two elements. The first element contains the array |
||
4236 | * of elements where the predicate returned TRUE, the second element |
||
4237 | * contains the array of elements where the predicate returned FALSE.</p> |
||
4238 | * |
||
4239 | * @psalm-return array<int, static<TKey,T>> |
||
4240 | */ |
||
4241 | 1 | public function partition(\Closure $closure): array |
|
4257 | |||
4258 | /** |
||
4259 | * Pop a specified value off the end of the current array. |
||
4260 | * |
||
4261 | * @return mixed|null |
||
4262 | * <p>(Mutable) The popped element from the current array or null if the array is e.g. empty.</p> |
||
4263 | */ |
||
4264 | 5 | public function pop() |
|
4270 | |||
4271 | /** |
||
4272 | * Prepend a (key) + value to the current array. |
||
4273 | * |
||
4274 | * EXAMPLE: <code> |
||
4275 | * a(['fòô' => 'bàř'])->prepend('foo'); // Arrayy[0 => 'foo', 'fòô' => 'bàř'] |
||
4276 | * </code> |
||
4277 | * |
||
4278 | * @param mixed $value |
||
4279 | * @param mixed $key |
||
4280 | * |
||
4281 | * @return $this |
||
4282 | * <p>(Mutable) Return this Arrayy object, with the prepended value.</p> |
||
4283 | * |
||
4284 | * @psalm-return static<TKey,T> |
||
4285 | */ |
||
4286 | 11 | public function prepend($value, $key = null) |
|
4302 | |||
4303 | /** |
||
4304 | * Add a suffix to each key. |
||
4305 | * |
||
4306 | * @param mixed $suffix |
||
4307 | * |
||
4308 | * @return static |
||
4309 | * <p>(Immutable) Return an Arrayy object, with the prepended keys.</p> |
||
4310 | * |
||
4311 | * @psalm-return static<TKey,T> |
||
4312 | * @psalm-mutation-free |
||
4313 | */ |
||
4314 | 10 | View Code Duplication | public function prependToEachKey($suffix): self |
4340 | |||
4341 | /** |
||
4342 | * Add a suffix to each value. |
||
4343 | * |
||
4344 | * @param mixed $suffix |
||
4345 | * |
||
4346 | * @return static |
||
4347 | * <p>(Immutable) Return an Arrayy object, with the prepended values.</p> |
||
4348 | * |
||
4349 | * @psalm-return static<TKey,T> |
||
4350 | * @psalm-mutation-free |
||
4351 | */ |
||
4352 | 10 | View Code Duplication | public function prependToEachValue($suffix): self |
4380 | |||
4381 | /** |
||
4382 | * Return the value of a given key and |
||
4383 | * delete the key. |
||
4384 | * |
||
4385 | * @param int|int[]|string|string[]|null $keyOrKeys |
||
4386 | * @param mixed $fallback |
||
4387 | * |
||
4388 | * @return mixed |
||
4389 | */ |
||
4390 | 5 | public function pull($keyOrKeys = null, $fallback = null) |
|
4412 | |||
4413 | /** |
||
4414 | * Push one or more values onto the end of array at once. |
||
4415 | * |
||
4416 | * @param array ...$args |
||
4417 | * |
||
4418 | * @return $this |
||
4419 | * <p>(Mutable) Return this Arrayy object, with pushed elements to the end of array.</p> |
||
4420 | * |
||
4421 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
4422 | * |
||
4423 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$args |
||
4424 | * @psalm-return static<TKey,T> |
||
4425 | */ |
||
4426 | 7 | public function push(...$args) |
|
4444 | |||
4445 | /** |
||
4446 | * Get a random value from the current array. |
||
4447 | * |
||
4448 | * @param int|null $number <p>How many values you will take?</p> |
||
4449 | * |
||
4450 | * @return static |
||
4451 | * <p>(Immutable)</p> |
||
4452 | * |
||
4453 | * @psalm-return static<int|array-key,T> |
||
4454 | */ |
||
4455 | 19 | public function randomImmutable(int $number = null): self |
|
4488 | |||
4489 | /** |
||
4490 | * Pick a random key/index from the keys of this array. |
||
4491 | * |
||
4492 | * @throws \RangeException If array is empty |
||
4493 | * |
||
4494 | * @return mixed |
||
4495 | * <p>Get a key/index or null if there wasn't a key/index.</p> |
||
4496 | */ |
||
4497 | 4 | public function randomKey() |
|
4507 | |||
4508 | /** |
||
4509 | * Pick a given number of random keys/indexes out of this array. |
||
4510 | * |
||
4511 | * @param int $number <p>The number of keys/indexes (should be <= \count($this->array))</p> |
||
4512 | * |
||
4513 | * @throws \RangeException If array is empty |
||
4514 | * |
||
4515 | * @return static |
||
4516 | * <p>(Immutable)</p> |
||
4517 | * |
||
4518 | * @psalm-return static<TKey,T> |
||
4519 | */ |
||
4520 | 13 | public function randomKeys(int $number): self |
|
4548 | |||
4549 | /** |
||
4550 | * Get a random value from the current array. |
||
4551 | * |
||
4552 | * @param int|null $number <p>How many values you will take?</p> |
||
4553 | * |
||
4554 | * @return $this |
||
4555 | * <p>(Mutable) Return this Arrayy object.</p> |
||
4556 | * |
||
4557 | * @psalm-return static<TKey,T> |
||
4558 | */ |
||
4559 | 17 | public function randomMutable(int $number = null): self |
|
4584 | |||
4585 | /** |
||
4586 | * Pick a random value from the values of this array. |
||
4587 | * |
||
4588 | * @return mixed |
||
4589 | * <p>Get a random value or null if there wasn't a value.</p> |
||
4590 | */ |
||
4591 | 4 | public function randomValue() |
|
4601 | |||
4602 | /** |
||
4603 | * Pick a given number of random values out of this array. |
||
4604 | * |
||
4605 | * @param int $number |
||
4606 | * |
||
4607 | * @return static |
||
4608 | * <p>(Mutable)</p> |
||
4609 | * |
||
4610 | * @psalm-return static<TKey,T> |
||
4611 | */ |
||
4612 | 7 | public function randomValues(int $number): self |
|
4616 | |||
4617 | /** |
||
4618 | * Get a random value from an array, with the ability to skew the results. |
||
4619 | * |
||
4620 | * Example: randomWeighted(['foo' => 1, 'bar' => 2]) has a 66% chance of returning bar. |
||
4621 | * |
||
4622 | * @param array $array |
||
4623 | * @param int|null $number <p>How many values you will take?</p> |
||
4624 | * |
||
4625 | * @return static<int,mixed> |
||
4626 | * <p>(Immutable)</p> |
||
4627 | * |
||
4628 | * @psalm-param array<mixed,mixed> $array |
||
4629 | * @psalm-return static<int|array-key,T> |
||
4630 | */ |
||
4631 | 9 | public function randomWeighted(array $array, int $number = null): self |
|
4646 | |||
4647 | /** |
||
4648 | * Reduce the current array via callable e.g. anonymous-function. |
||
4649 | * |
||
4650 | * @param callable $callable |
||
4651 | * @param mixed $init |
||
4652 | * |
||
4653 | * @return static |
||
4654 | * <p>(Immutable)</p> |
||
4655 | * |
||
4656 | * @psalm-return static<TKey,T> |
||
4657 | * @psalm-mutation-free |
||
4658 | */ |
||
4659 | 18 | public function reduce($callable, $init = []): self |
|
4689 | |||
4690 | /** |
||
4691 | * @param bool $unique |
||
4692 | * |
||
4693 | * @return static |
||
4694 | * <p>(Immutable)</p> |
||
4695 | * |
||
4696 | * @psalm-return static<TKey,T> |
||
4697 | * @psalm-mutation-free |
||
4698 | */ |
||
4699 | 14 | public function reduce_dimension(bool $unique = true): self |
|
4722 | |||
4723 | /** |
||
4724 | * Create a numerically re-indexed Arrayy object. |
||
4725 | * |
||
4726 | * @return $this |
||
4727 | * <p>(Mutable) Return this Arrayy object, with re-indexed array-elements.</p> |
||
4728 | * |
||
4729 | * @psalm-return static<TKey,T> |
||
4730 | */ |
||
4731 | 9 | public function reindex(): self |
|
4739 | |||
4740 | /** |
||
4741 | * Return all items that fail the truth test. |
||
4742 | * |
||
4743 | * @param \Closure $closure |
||
4744 | * |
||
4745 | * @return static |
||
4746 | * <p>(Immutable)</p> |
||
4747 | * |
||
4748 | * @psalm-return static<TKey,T> |
||
4749 | * @psalm-mutation-free |
||
4750 | */ |
||
4751 | 1 | View Code Duplication | public function reject(\Closure $closure): self |
4768 | |||
4769 | /** |
||
4770 | * Remove a value from the current array (optional using dot-notation). |
||
4771 | * |
||
4772 | * @param mixed $key |
||
4773 | * |
||
4774 | * @return static |
||
4775 | * <p>(Mutable)</p> |
||
4776 | * |
||
4777 | * @psalm-param TKey $key |
||
4778 | * @psalm-return static<TKey,T> |
||
4779 | */ |
||
4780 | 21 | public function remove($key) |
|
4803 | |||
4804 | /** |
||
4805 | * alias: for "Arrayy->removeValue()" |
||
4806 | * |
||
4807 | * @param mixed $element |
||
4808 | * |
||
4809 | * @return static |
||
4810 | * <p>(Immutable)</p> |
||
4811 | * |
||
4812 | * @psalm-param T $element |
||
4813 | * @psalm-return static<TKey,T> |
||
4814 | * @psalm-mutation-free |
||
4815 | */ |
||
4816 | 8 | public function removeElement($element) |
|
4820 | |||
4821 | /** |
||
4822 | * Remove the first value from the current array. |
||
4823 | * |
||
4824 | * @return static |
||
4825 | * <p>(Immutable)</p> |
||
4826 | * |
||
4827 | * @psalm-return static<TKey,T> |
||
4828 | * @psalm-mutation-free |
||
4829 | */ |
||
4830 | 7 | View Code Duplication | public function removeFirst(): self |
4842 | |||
4843 | /** |
||
4844 | * Remove the last value from the current array. |
||
4845 | * |
||
4846 | * @return static |
||
4847 | * <p>(Immutable)</p> |
||
4848 | * |
||
4849 | * @psalm-return static<TKey,T> |
||
4850 | * @psalm-mutation-free |
||
4851 | */ |
||
4852 | 7 | View Code Duplication | public function removeLast(): self |
4864 | |||
4865 | /** |
||
4866 | * Removes a particular value from an array (numeric or associative). |
||
4867 | * |
||
4868 | * @param mixed $value |
||
4869 | * |
||
4870 | * @return static |
||
4871 | * <p>(Immutable)</p> |
||
4872 | * |
||
4873 | * @psalm-param T $value |
||
4874 | * @psalm-return static<TKey,T> |
||
4875 | * @psalm-mutation-free |
||
4876 | */ |
||
4877 | 8 | public function removeValue($value): self |
|
4900 | |||
4901 | /** |
||
4902 | * Generate array of repeated arrays. |
||
4903 | * |
||
4904 | * @param int $times <p>How many times has to be repeated.</p> |
||
4905 | * |
||
4906 | * @return static |
||
4907 | * <p>(Immutable)</p> |
||
4908 | * |
||
4909 | * @psalm-return static<TKey,T> |
||
4910 | * @psalm-mutation-free |
||
4911 | */ |
||
4912 | 1 | public function repeat($times): self |
|
4924 | |||
4925 | /** |
||
4926 | * Replace a key with a new key/value pair. |
||
4927 | * |
||
4928 | * @param mixed $oldKey |
||
4929 | * @param mixed $newKey |
||
4930 | * @param mixed $newValue |
||
4931 | * |
||
4932 | * @return static |
||
4933 | * <p>(Immutable)</p> |
||
4934 | * |
||
4935 | * @psalm-return static<TKey,T> |
||
4936 | * @psalm-mutation-free |
||
4937 | */ |
||
4938 | 5 | public function replace($oldKey, $newKey, $newValue): self |
|
4948 | |||
4949 | /** |
||
4950 | * Create an array using the current array as values and the other array as keys. |
||
4951 | * |
||
4952 | * @param array $keys <p>An array of keys.</p> |
||
4953 | * |
||
4954 | * @return static |
||
4955 | * <p>(Immutable) Arrayy object with keys from the other array.</p> |
||
4956 | * |
||
4957 | * @psalm-param array<mixed,mixed>|array<mixed,TKey> $keys |
||
4958 | * @psalm-return static<TKey,T> |
||
4959 | * @psalm-mutation-free |
||
4960 | */ |
||
4961 | 2 | public function replaceAllKeys(array $keys): self |
|
4969 | |||
4970 | /** |
||
4971 | * Create an array using the current array as keys and the other array as values. |
||
4972 | * |
||
4973 | * @param array $array <p>An array o values.</p> |
||
4974 | * |
||
4975 | * @return static |
||
4976 | * <p>(Immutable) Arrayy object with values from the other array.</p> |
||
4977 | * |
||
4978 | * @psalm-param array<mixed,T> $array |
||
4979 | * @psalm-return static<TKey,T> |
||
4980 | * @psalm-mutation-free |
||
4981 | */ |
||
4982 | 2 | public function replaceAllValues(array $array): self |
|
4990 | |||
4991 | /** |
||
4992 | * Replace the keys in an array with another set. |
||
4993 | * |
||
4994 | * @param array $keys <p>An array of keys matching the array's size</p> |
||
4995 | * |
||
4996 | * @return static |
||
4997 | * <p>(Immutable)</p> |
||
4998 | * |
||
4999 | * @psalm-param array<mixed,mixed>|array<mixed,TKey> $keys |
||
5000 | * @psalm-return static<TKey,T> |
||
5001 | * @psalm-mutation-free |
||
5002 | */ |
||
5003 | 1 | public function replaceKeys(array $keys): self |
|
5014 | |||
5015 | /** |
||
5016 | * Replace the first matched value in an array. |
||
5017 | * |
||
5018 | * @param mixed $search <p>The value to replace.</p> |
||
5019 | * @param mixed $replacement <p>The value to replace.</p> |
||
5020 | * |
||
5021 | * @return static |
||
5022 | * <p>(Immutable)</p> |
||
5023 | * |
||
5024 | * @psalm-return static<TKey,T> |
||
5025 | * @psalm-mutation-free |
||
5026 | */ |
||
5027 | 3 | View Code Duplication | public function replaceOneValue($search, $replacement = ''): self |
5042 | |||
5043 | /** |
||
5044 | * Replace values in the current array. |
||
5045 | * |
||
5046 | * @param mixed $search <p>The value to replace.</p> |
||
5047 | * @param mixed $replacement <p>What to replace it with.</p> |
||
5048 | * |
||
5049 | * @return static |
||
5050 | * <p>(Immutable)</p> |
||
5051 | * |
||
5052 | * @psalm-return static<TKey,T> |
||
5053 | * @psalm-mutation-free |
||
5054 | */ |
||
5055 | 1 | public function replaceValues($search, $replacement = ''): self |
|
5067 | |||
5068 | /** |
||
5069 | * Get the last elements from index $from until the end of this array. |
||
5070 | * |
||
5071 | * @param int $from |
||
5072 | * |
||
5073 | * @return static |
||
5074 | * <p>(Immutable)</p> |
||
5075 | * |
||
5076 | * @psalm-return static<TKey,T> |
||
5077 | * @psalm-mutation-free |
||
5078 | */ |
||
5079 | 15 | View Code Duplication | public function rest(int $from = 1): self |
5089 | |||
5090 | /** |
||
5091 | * Return the array in the reverse order. |
||
5092 | * |
||
5093 | * @return $this |
||
5094 | * <p>(Mutable) Return this Arrayy object.</p> |
||
5095 | * |
||
5096 | * @psalm-return static<TKey,T> |
||
5097 | */ |
||
5098 | 9 | public function reverse(): self |
|
5106 | |||
5107 | /** |
||
5108 | * Sort an array in reverse order. |
||
5109 | * |
||
5110 | * @param int $sort_flags [optional] <p> |
||
5111 | * You may modify the behavior of the sort using the optional |
||
5112 | * parameter sort_flags, for details |
||
5113 | * see sort. |
||
5114 | * </p> |
||
5115 | * |
||
5116 | * @return $this |
||
5117 | * <p>(Mutable) Return this Arrayy object.</p> |
||
5118 | * |
||
5119 | * @psalm-return static<TKey,T> |
||
5120 | */ |
||
5121 | 4 | public function rsort(int $sort_flags = 0): self |
|
5129 | |||
5130 | /** |
||
5131 | * Sort an array in reverse order. |
||
5132 | * |
||
5133 | * @param int $sort_flags [optional] <p> |
||
5134 | * You may modify the behavior of the sort using the optional |
||
5135 | * parameter sort_flags, for details |
||
5136 | * see sort. |
||
5137 | * </p> |
||
5138 | * |
||
5139 | * @return $this |
||
5140 | * <p>(Immutable) Return this Arrayy object.</p> |
||
5141 | * |
||
5142 | * @psalm-return static<TKey,T> |
||
5143 | * @psalm-mutation-free |
||
5144 | */ |
||
5145 | 4 | public function rsortImmutable(int $sort_flags = 0): self |
|
5156 | |||
5157 | /** |
||
5158 | * Search for the first index of the current array via $value. |
||
5159 | * |
||
5160 | * @param mixed $value |
||
5161 | * |
||
5162 | * @return false|float|int|string |
||
5163 | * <p>Will return <b>FALSE</b> if the value can't be found.</p> |
||
5164 | * @psalm-mutation-free |
||
5165 | */ |
||
5166 | 21 | public function searchIndex($value) |
|
5176 | |||
5177 | /** |
||
5178 | * Search for the value of the current array via $index. |
||
5179 | * |
||
5180 | * @param mixed $index |
||
5181 | * |
||
5182 | * @return static |
||
5183 | * <p>(Immutable) Will return a empty Arrayy if the value wasn't found.</p> |
||
5184 | * |
||
5185 | * @psalm-return static<TKey,T> |
||
5186 | * @psalm-mutation-free |
||
5187 | */ |
||
5188 | 9 | public function searchValue($index): self |
|
5218 | |||
5219 | /** |
||
5220 | * Set a value for the current array (optional using dot-notation). |
||
5221 | * |
||
5222 | * @param string $key <p>The key to set.</p> |
||
5223 | * @param mixed $value <p>Its value.</p> |
||
5224 | * |
||
5225 | * @return $this |
||
5226 | * <p>(Mutable) Return this Arrayy object.</p> |
||
5227 | * |
||
5228 | * @psalm-param TKey $key |
||
5229 | * @psalm-param T $value |
||
5230 | * @psalm-return static<TKey,T> |
||
5231 | */ |
||
5232 | 28 | public function set($key, $value): self |
|
5238 | |||
5239 | /** |
||
5240 | * Get a value from a array and set it if it was not. |
||
5241 | * |
||
5242 | * WARNING: this method only set the value, if the $key is not already set |
||
5243 | * |
||
5244 | * @param mixed $key <p>The key</p> |
||
5245 | * @param mixed $fallback <p>The default value to set if it isn't.</p> |
||
5246 | * |
||
5247 | * @return mixed |
||
5248 | * <p>(Mutable)</p> |
||
5249 | */ |
||
5250 | 11 | public function setAndGet($key, $fallback = null) |
|
5261 | |||
5262 | /** |
||
5263 | * Shifts a specified value off the beginning of array. |
||
5264 | * |
||
5265 | * @return mixed |
||
5266 | * <p>(Mutable) A shifted element from the current array.</p> |
||
5267 | */ |
||
5268 | 5 | public function shift() |
|
5274 | |||
5275 | /** |
||
5276 | * Shuffle the current array. |
||
5277 | * |
||
5278 | * @param bool $secure <p>using a CSPRNG | @link https://paragonie.com/b/JvICXzh_jhLyt4y3</p> |
||
5279 | * @param array $array [optional] |
||
5280 | * |
||
5281 | * @return static |
||
5282 | * <p>(Immutable)</p> |
||
5283 | * |
||
5284 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
5285 | * @psalm-return static<TKey,T> |
||
5286 | * |
||
5287 | * @noinspection BadExceptionsProcessingInspection |
||
5288 | * @noinspection RandomApiMigrationInspection |
||
5289 | * @noinspection NonSecureShuffleUsageInspection |
||
5290 | */ |
||
5291 | 2 | public function shuffle(bool $secure = false, array $array = null): self |
|
5329 | |||
5330 | /** |
||
5331 | * Count the values from the current array. |
||
5332 | * |
||
5333 | * alias: for "Arrayy->count()" |
||
5334 | * |
||
5335 | * @param int $mode |
||
5336 | * |
||
5337 | * @return int |
||
5338 | */ |
||
5339 | 20 | public function size(int $mode = \COUNT_NORMAL): int |
|
5343 | |||
5344 | /** |
||
5345 | * Checks whether array has exactly $size items. |
||
5346 | * |
||
5347 | * @param int $size |
||
5348 | * |
||
5349 | * @return bool |
||
5350 | */ |
||
5351 | 1 | public function sizeIs(int $size): bool |
|
5367 | |||
5368 | /** |
||
5369 | * Checks whether array has between $fromSize to $toSize items. $toSize can be |
||
5370 | * smaller than $fromSize. |
||
5371 | * |
||
5372 | * @param int $fromSize |
||
5373 | * @param int $toSize |
||
5374 | * |
||
5375 | * @return bool |
||
5376 | */ |
||
5377 | 1 | public function sizeIsBetween(int $fromSize, int $toSize): bool |
|
5397 | |||
5398 | /** |
||
5399 | * Checks whether array has more than $size items. |
||
5400 | * |
||
5401 | * @param int $size |
||
5402 | * |
||
5403 | * @return bool |
||
5404 | */ |
||
5405 | 1 | View Code Duplication | public function sizeIsGreaterThan(int $size): bool |
5419 | |||
5420 | /** |
||
5421 | * Checks whether array has less than $size items. |
||
5422 | * |
||
5423 | * @param int $size |
||
5424 | * |
||
5425 | * @return bool |
||
5426 | */ |
||
5427 | 1 | View Code Duplication | public function sizeIsLessThan(int $size): bool |
5441 | |||
5442 | /** |
||
5443 | * Counts all elements in an array, or something in an object. |
||
5444 | * |
||
5445 | * <p> |
||
5446 | * For objects, if you have SPL installed, you can hook into count() by implementing interface {@see Countable}. |
||
5447 | * The interface has exactly one method, {@see Countable::count()}, which returns the return value for the count() |
||
5448 | * function. Please see the {@see Array} section of the manual for a detailed explanation of how arrays are |
||
5449 | * implemented and used in PHP. |
||
5450 | * </p> |
||
5451 | * |
||
5452 | * @return int |
||
5453 | * <p> |
||
5454 | * The number of elements in var, which is |
||
5455 | * typically an array, since anything else will have one |
||
5456 | * element. |
||
5457 | * </p> |
||
5458 | * <p> |
||
5459 | * If var is not an array or an object with |
||
5460 | * implemented Countable interface, |
||
5461 | * 1 will be returned. |
||
5462 | * There is one exception, if var is &null;, |
||
5463 | * 0 will be returned. |
||
5464 | * </p> |
||
5465 | * <p> |
||
5466 | * Caution: count may return 0 for a variable that isn't set, |
||
5467 | * but it may also return 0 for a variable that has been initialized with an |
||
5468 | * empty array. Use isset to test if a variable is set. |
||
5469 | * </p> |
||
5470 | */ |
||
5471 | 10 | public function sizeRecursive(): int |
|
5475 | |||
5476 | /** |
||
5477 | * Extract a slice of the array. |
||
5478 | * |
||
5479 | * @param int $offset <p>Slice begin index.</p> |
||
5480 | * @param int|null $length <p>Length of the slice.</p> |
||
5481 | * @param bool $preserveKeys <p>Whether array keys are preserved or no.</p> |
||
5482 | * |
||
5483 | * @return static |
||
5484 | * <p>(Immutable) A slice of the original array with length $length.</p> |
||
5485 | * |
||
5486 | * @psalm-return static<TKey,T> |
||
5487 | * @psalm-mutation-free |
||
5488 | */ |
||
5489 | 5 | public function slice(int $offset, int $length = null, bool $preserveKeys = false) |
|
5502 | |||
5503 | /** |
||
5504 | * Sort the current array and optional you can keep the keys. |
||
5505 | * |
||
5506 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
5507 | * @param int $strategy <p>sort_flags => use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
5508 | * <strong>SORT_NATURAL</strong></p> |
||
5509 | * @param bool $keepKeys |
||
5510 | * |
||
5511 | * @return static |
||
5512 | * <p>(Mutable) Return this Arrayy object.</p> |
||
5513 | * |
||
5514 | * @psalm-return static<TKey,T> |
||
5515 | */ |
||
5516 | 20 | public function sort( |
|
5530 | |||
5531 | /** |
||
5532 | * Sort the current array and optional you can keep the keys. |
||
5533 | * |
||
5534 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
5535 | * @param int $strategy <p>sort_flags => use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
5536 | * <strong>SORT_NATURAL</strong></p> |
||
5537 | * @param bool $keepKeys |
||
5538 | * |
||
5539 | * @return static |
||
5540 | * <p>(Immutable) Return this Arrayy object.</p> |
||
5541 | * |
||
5542 | * @psalm-return static<TKey,T> |
||
5543 | */ |
||
5544 | 12 | public function sortImmutable( |
|
5560 | |||
5561 | /** |
||
5562 | * Sort the current array by key. |
||
5563 | * |
||
5564 | * @see http://php.net/manual/en/function.ksort.php |
||
5565 | * @see http://php.net/manual/en/function.krsort.php |
||
5566 | * |
||
5567 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
5568 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
5569 | * <strong>SORT_NATURAL</strong></p> |
||
5570 | * |
||
5571 | * @return $this |
||
5572 | * <p>(Mutable) Return this Arrayy object.</p> |
||
5573 | * |
||
5574 | * @psalm-return static<TKey,T> |
||
5575 | */ |
||
5576 | 18 | public function sortKeys( |
|
5586 | |||
5587 | /** |
||
5588 | * Sort the current array by key. |
||
5589 | * |
||
5590 | * @see http://php.net/manual/en/function.ksort.php |
||
5591 | * @see http://php.net/manual/en/function.krsort.php |
||
5592 | * |
||
5593 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
5594 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
5595 | * <strong>SORT_NATURAL</strong></p> |
||
5596 | * |
||
5597 | * @return $this |
||
5598 | * <p>(Immutable) Return this Arrayy object.</p> |
||
5599 | * |
||
5600 | * @psalm-return static<TKey,T> |
||
5601 | * @psalm-mutation-free |
||
5602 | */ |
||
5603 | 8 | public function sortKeysImmutable( |
|
5616 | |||
5617 | /** |
||
5618 | * Sort the current array by value. |
||
5619 | * |
||
5620 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
5621 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
5622 | * <strong>SORT_NATURAL</strong></p> |
||
5623 | * |
||
5624 | * @return static |
||
5625 | * <p>(Mutable)</p> |
||
5626 | * |
||
5627 | * @psalm-return static<TKey,T> |
||
5628 | */ |
||
5629 | 1 | public function sortValueKeepIndex( |
|
5635 | |||
5636 | /** |
||
5637 | * Sort the current array by value. |
||
5638 | * |
||
5639 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
5640 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
5641 | * <strong>SORT_NATURAL</strong></p> |
||
5642 | * |
||
5643 | * @return static |
||
5644 | * <p>(Mutable)</p> |
||
5645 | * |
||
5646 | * @psalm-return static<TKey,T> |
||
5647 | */ |
||
5648 | 1 | public function sortValueNewIndex($direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
5652 | |||
5653 | /** |
||
5654 | * Sort a array by value, by a closure or by a property. |
||
5655 | * |
||
5656 | * - If the sorter is null, the array is sorted naturally. |
||
5657 | * - Associative (string) keys will be maintained, but numeric keys will be re-indexed. |
||
5658 | * |
||
5659 | * @param callable|string|null $sorter |
||
5660 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or |
||
5661 | * <strong>SORT_DESC</strong></p> |
||
5662 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
5663 | * <strong>SORT_NATURAL</strong></p> |
||
5664 | * |
||
5665 | * @return static |
||
5666 | * <p>(Immutable)</p> |
||
5667 | * |
||
5668 | * @psalm-return static<TKey,T> |
||
5669 | * @psalm-mutation-free |
||
5670 | */ |
||
5671 | 1 | public function sorter($sorter = null, $direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
5712 | |||
5713 | /** |
||
5714 | * @param int $offset |
||
5715 | * @param int|null $length |
||
5716 | * @param array $replacement |
||
5717 | * |
||
5718 | * @return static |
||
5719 | * <p>(Immutable)</p> |
||
5720 | * |
||
5721 | * @psalm-param array<mixed,mixed>|array<mixed,T> $replacement |
||
5722 | * @psalm-return static<TKey,T> |
||
5723 | * @psalm-mutation-free |
||
5724 | */ |
||
5725 | 1 | public function splice(int $offset, int $length = null, $replacement = []): self |
|
5742 | |||
5743 | /** |
||
5744 | * Split an array in the given amount of pieces. |
||
5745 | * |
||
5746 | * @param int $numberOfPieces |
||
5747 | * @param bool $keepKeys |
||
5748 | * |
||
5749 | * @return static |
||
5750 | * <p>(Immutable)</p> |
||
5751 | * |
||
5752 | * @psalm-return static<TKey,T> |
||
5753 | * @psalm-mutation-free |
||
5754 | */ |
||
5755 | 1 | public function split(int $numberOfPieces = 2, bool $keepKeys = false): self |
|
5774 | |||
5775 | /** |
||
5776 | * Stripe all empty items. |
||
5777 | * |
||
5778 | * @return static |
||
5779 | * <p>(Immutable)</p> |
||
5780 | * |
||
5781 | * @psalm-return static<TKey,T> |
||
5782 | * @psalm-mutation-free |
||
5783 | */ |
||
5784 | 1 | public function stripEmpty(): self |
|
5796 | |||
5797 | /** |
||
5798 | * Swap two values between positions by key. |
||
5799 | * |
||
5800 | * @param int|string $swapA <p>a key in the array</p> |
||
5801 | * @param int|string $swapB <p>a key in the array</p> |
||
5802 | * |
||
5803 | * @return static |
||
5804 | * <p>(Immutable)</p> |
||
5805 | * |
||
5806 | * @psalm-return static<TKey,T> |
||
5807 | * @psalm-mutation-free |
||
5808 | */ |
||
5809 | 1 | public function swap($swapA, $swapB): self |
|
5821 | |||
5822 | /** |
||
5823 | * Get the current array from the "Arrayy"-object. |
||
5824 | * alias for "getArray()" |
||
5825 | * |
||
5826 | * @param bool $convertAllArrayyElements <p> |
||
5827 | * Convert all Child-"Arrayy" objects also to arrays. |
||
5828 | * </p> |
||
5829 | * @param bool $preserveKeys <p> |
||
5830 | * e.g.: A generator maybe return the same key more then once, |
||
5831 | * so maybe you will ignore the keys. |
||
5832 | * </p> |
||
5833 | * |
||
5834 | * @return array |
||
5835 | * |
||
5836 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
5837 | * @psalm-mutation-free |
||
5838 | */ |
||
5839 | 945 | public function toArray( |
|
5864 | |||
5865 | /** |
||
5866 | * Get the current array from the "Arrayy"-object as list. |
||
5867 | * |
||
5868 | * @param bool $convertAllArrayyElements <p> |
||
5869 | * Convert all Child-"Arrayy" objects also to arrays. |
||
5870 | * </p> |
||
5871 | * |
||
5872 | * @return array |
||
5873 | * |
||
5874 | * @psalm-return list<array<TKey,T>> |
||
5875 | * @psalm-mutation-free |
||
5876 | */ |
||
5877 | 1 | public function toList(bool $convertAllArrayyElements = false): array |
|
5884 | |||
5885 | /** |
||
5886 | * Convert the current array to JSON. |
||
5887 | * |
||
5888 | * @param int $options [optional] <p>e.g. JSON_PRETTY_PRINT</p> |
||
5889 | * @param int $depth [optional] <p>Set the maximum depth. Must be greater than zero.</p> |
||
5890 | * |
||
5891 | * @return string |
||
5892 | */ |
||
5893 | 12 | public function toJson(int $options = 0, int $depth = 512): string |
|
5902 | |||
5903 | /** |
||
5904 | * @param string[]|null $items [optional] |
||
5905 | * @param string[] $helper [optional] |
||
5906 | * |
||
5907 | * @return static|static[] |
||
5908 | * |
||
5909 | * @psalm-return static<int, static<TKey,T>> |
||
5910 | */ |
||
5911 | 1 | public function toPermutation(array $items = null, array $helper = []): self |
|
5945 | |||
5946 | /** |
||
5947 | * Implodes array to a string with specified separator. |
||
5948 | * |
||
5949 | * @param string $separator [optional] <p>The element's separator.</p> |
||
5950 | * |
||
5951 | * @return string |
||
5952 | * <p>The string representation of array, separated by ",".</p> |
||
5953 | */ |
||
5954 | 19 | public function toString(string $separator = ','): string |
|
5958 | |||
5959 | /** |
||
5960 | * Return a duplicate free copy of the current array. |
||
5961 | * |
||
5962 | * @return $this |
||
5963 | * <p>(Mutable)</p> |
||
5964 | * |
||
5965 | * @psalm-return static<TKey,T> |
||
5966 | */ |
||
5967 | 13 | public function unique(): self |
|
5989 | |||
5990 | /** |
||
5991 | * Return a duplicate free copy of the current array. (with the old keys) |
||
5992 | * |
||
5993 | * @return $this |
||
5994 | * <p>(Mutable)</p> |
||
5995 | * |
||
5996 | * @psalm-return static<TKey,T> |
||
5997 | */ |
||
5998 | 11 | public function uniqueKeepIndex(): self |
|
6024 | |||
6025 | /** |
||
6026 | * alias: for "Arrayy->unique()" |
||
6027 | * |
||
6028 | * @return static |
||
6029 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
6030 | * |
||
6031 | * @see Arrayy::unique() |
||
6032 | * |
||
6033 | * @psalm-return static<TKey,T> |
||
6034 | */ |
||
6035 | 10 | public function uniqueNewIndex(): self |
|
6039 | |||
6040 | /** |
||
6041 | * Prepends one or more values to the beginning of array at once. |
||
6042 | * |
||
6043 | * @param array ...$args |
||
6044 | * |
||
6045 | * @return $this |
||
6046 | * <p>(Mutable) Return this Arrayy object, with prepended elements to the beginning of array.</p> |
||
6047 | * |
||
6048 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$args |
||
6049 | * @psalm-return static<TKey,T> |
||
6050 | */ |
||
6051 | 4 | public function unshift(...$args): self |
|
6059 | |||
6060 | /** |
||
6061 | * Tests whether the given closure return something valid for all elements of this array. |
||
6062 | * |
||
6063 | * @param \Closure $closure the predicate |
||
6064 | * |
||
6065 | * @return bool |
||
6066 | * <p>TRUE, if the predicate yields TRUE for all elements, FALSE otherwise.</p> |
||
6067 | */ |
||
6068 | 1 | View Code Duplication | public function validate(\Closure $closure): bool |
6078 | |||
6079 | /** |
||
6080 | * Get all values from a array. |
||
6081 | * |
||
6082 | * @return static |
||
6083 | * <p>(Immutable)</p> |
||
6084 | * |
||
6085 | * @psalm-return static<TKey,T> |
||
6086 | * @psalm-mutation-free |
||
6087 | */ |
||
6088 | 2 | public function values(): self |
|
6101 | |||
6102 | /** |
||
6103 | * Apply the given function to every element in the array, discarding the results. |
||
6104 | * |
||
6105 | * @param callable $callable |
||
6106 | * @param bool $recursive [optional] <p>Whether array will be walked recursively or no</p> |
||
6107 | * @param mixed $userData [optional] <p> |
||
6108 | * If the optional $userData parameter is supplied, |
||
6109 | * it will be passed as the third parameter to the $callable. |
||
6110 | * </p> |
||
6111 | * |
||
6112 | * @return $this |
||
6113 | * <p>(Mutable) Return this Arrayy object, with modified elements.</p> |
||
6114 | * |
||
6115 | * @psalm-return static<TKey,T> |
||
6116 | */ |
||
6117 | 12 | public function walk($callable, bool $recursive = false, $userData = self::ARRAYY_HELPER_WALK): self |
|
6139 | |||
6140 | /** |
||
6141 | * Returns a collection of matching items. |
||
6142 | * |
||
6143 | * @param string $keyOrPropertyOrMethod the property or method to evaluate |
||
6144 | * @param mixed $value the value to match |
||
6145 | * |
||
6146 | * @throws \InvalidArgumentException if property or method is not defined |
||
6147 | * |
||
6148 | * @return static |
||
6149 | * |
||
6150 | * @psalm-param T $value |
||
6151 | * @psalm-return static<TKey,T> |
||
6152 | */ |
||
6153 | 1 | public function where(string $keyOrPropertyOrMethod, $value): self |
|
6166 | |||
6167 | /** |
||
6168 | * Convert an array into a object. |
||
6169 | * |
||
6170 | * @param array $array |
||
6171 | * |
||
6172 | * @return \stdClass |
||
6173 | * |
||
6174 | * @psalm-param array<mixed,mixed> $array |
||
6175 | */ |
||
6176 | 4 | final protected static function arrayToObject(array $array = []): \stdClass |
|
6195 | |||
6196 | /** |
||
6197 | * @param array|\Generator|null $input <p> |
||
6198 | * An array containing keys to return. |
||
6199 | * </p> |
||
6200 | * @param mixed|null $search_values [optional] <p> |
||
6201 | * If specified, then only keys containing these values are returned. |
||
6202 | * </p> |
||
6203 | * @param bool $strict [optional] <p> |
||
6204 | * Determines if strict comparison (===) should be used during the |
||
6205 | * search. |
||
6206 | * </p> |
||
6207 | * |
||
6208 | * @return array |
||
6209 | * <p>an array of all the keys in input</p> |
||
6210 | * |
||
6211 | * @psalm-param array<mixed,mixed>|\Generator<TKey,T>|null $input |
||
6212 | * @psalm-return array<TKey|mixed> |
||
6213 | * @psalm-mutation-free |
||
6214 | */ |
||
6215 | 11 | protected function array_keys_recursive( |
|
6276 | |||
6277 | /** |
||
6278 | * @param mixed $path |
||
6279 | * @param callable $callable |
||
6280 | * @param array|null $currentOffset |
||
6281 | * |
||
6282 | * @return void |
||
6283 | * |
||
6284 | * @psalm-param array<mixed,mixed>|array<TKey,T>|null $currentOffset |
||
6285 | * @psalm-mutation-free |
||
6286 | */ |
||
6287 | 10 | protected function callAtPath($path, $callable, &$currentOffset = null) |
|
6316 | |||
6317 | /** |
||
6318 | * Extracts the value of the given property or method from the object. |
||
6319 | * |
||
6320 | * @param static $object <p>The object to extract the value from.</p> |
||
6321 | * @param string $keyOrPropertyOrMethod <p>The property or method for which the |
||
6322 | * value should be extracted.</p> |
||
6323 | * |
||
6324 | * @throws \InvalidArgumentException if the method or property is not defined |
||
6325 | * |
||
6326 | * @return mixed |
||
6327 | * <p>The value extracted from the specified property or method.</p> |
||
6328 | * |
||
6329 | * @psalm-param self<TKey,T> $object |
||
6330 | */ |
||
6331 | 2 | final protected function extractValue(self $object, string $keyOrPropertyOrMethod) |
|
6353 | |||
6354 | /** |
||
6355 | * create a fallback for array |
||
6356 | * |
||
6357 | * 1. use the current array, if it's a array |
||
6358 | * 2. fallback to empty array, if there is nothing |
||
6359 | * 3. call "getArray()" on object, if there is a "Arrayy"-object |
||
6360 | * 4. call "createFromObject()" on object, if there is a "\Traversable"-object |
||
6361 | * 5. call "__toArray()" on object, if the method exists |
||
6362 | * 6. cast a string or object with "__toString()" into an array |
||
6363 | * 7. throw a "InvalidArgumentException"-Exception |
||
6364 | * |
||
6365 | * @param mixed $data |
||
6366 | * |
||
6367 | * @throws \InvalidArgumentException |
||
6368 | * |
||
6369 | * @return array |
||
6370 | * |
||
6371 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
6372 | */ |
||
6373 | 1198 | protected function fallbackForArray(&$data): array |
|
6383 | |||
6384 | /** |
||
6385 | * @param bool $preserveKeys <p> |
||
6386 | * e.g.: A generator maybe return the same key more then once, |
||
6387 | * so maybe you will ignore the keys. |
||
6388 | * </p> |
||
6389 | * |
||
6390 | * @return bool |
||
6391 | * |
||
6392 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
6393 | * @psalm-mutation-free :/ |
||
6394 | */ |
||
6395 | 1110 | protected function generatorToArray(bool $preserveKeys = true) |
|
6406 | |||
6407 | /** |
||
6408 | * Get correct PHP constant for direction. |
||
6409 | * |
||
6410 | * @param int|string $direction |
||
6411 | * |
||
6412 | * @return int |
||
6413 | * @psalm-mutation-free |
||
6414 | */ |
||
6415 | 43 | protected function getDirection($direction): int |
|
6437 | |||
6438 | /** |
||
6439 | * @return TypeCheckInterface[] |
||
6440 | * |
||
6441 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
6442 | */ |
||
6443 | 22 | protected function getPropertiesFromPhpDoc() |
|
6474 | |||
6475 | /** |
||
6476 | * @param mixed $glue |
||
6477 | * @param mixed $pieces |
||
6478 | * @param bool $useKeys |
||
6479 | * |
||
6480 | * @return string |
||
6481 | * @psalm-mutation-free |
||
6482 | */ |
||
6483 | 36 | protected function implode_recursive( |
|
6516 | |||
6517 | /** |
||
6518 | * @param mixed $needle <p> |
||
6519 | * The searched value. |
||
6520 | * </p> |
||
6521 | * <p> |
||
6522 | * If needle is a string, the comparison is done |
||
6523 | * in a case-sensitive manner. |
||
6524 | * </p> |
||
6525 | * @param array|\Generator|null $haystack <p> |
||
6526 | * The array. |
||
6527 | * </p> |
||
6528 | * @param bool $strict [optional] <p> |
||
6529 | * If the third parameter strict is set to true |
||
6530 | * then the in_array function will also check the |
||
6531 | * types of the |
||
6532 | * needle in the haystack. |
||
6533 | * </p> |
||
6534 | * |
||
6535 | * @return bool |
||
6536 | * <p>true if needle is found in the array, false otherwise</p> |
||
6537 | * |
||
6538 | * @psalm-param array<mixed,mixed>|\Generator<TKey,T>|null $haystack |
||
6539 | * @psalm-mutation-free |
||
6540 | */ |
||
6541 | 18 | protected function in_array_recursive($needle, $haystack = null, $strict = true): bool |
|
6566 | |||
6567 | /** |
||
6568 | * @param mixed $data |
||
6569 | * |
||
6570 | * @return array|null |
||
6571 | * |
||
6572 | * @psalm-return array<mixed,mixed>|array<TKey,T>|null |
||
6573 | */ |
||
6574 | 1198 | protected function internalGetArray(&$data) |
|
6625 | |||
6626 | /** |
||
6627 | * Internal mechanics of remove method. |
||
6628 | * |
||
6629 | * @param mixed $key |
||
6630 | * |
||
6631 | * @return bool |
||
6632 | */ |
||
6633 | 21 | protected function internalRemove($key): bool |
|
6666 | |||
6667 | /** |
||
6668 | * Internal mechanic of set method. |
||
6669 | * |
||
6670 | * @param int|string|null $key |
||
6671 | * @param mixed $value |
||
6672 | * @param bool $checkProperties |
||
6673 | * |
||
6674 | * @return bool |
||
6675 | */ |
||
6676 | 1048 | protected function internalSet( |
|
6735 | |||
6736 | /** |
||
6737 | * Convert a object into an array. |
||
6738 | * |
||
6739 | * @param mixed|object $object |
||
6740 | * |
||
6741 | * @return array|mixed |
||
6742 | * |
||
6743 | * @psalm-mutation-free |
||
6744 | */ |
||
6745 | 5 | protected static function objectToArray($object) |
|
6758 | |||
6759 | /** |
||
6760 | * @param array $data |
||
6761 | * @param bool $checkPropertiesInConstructor |
||
6762 | * |
||
6763 | * @return void |
||
6764 | * |
||
6765 | * @psalm-param array<mixed,T> $data |
||
6766 | */ |
||
6767 | 1196 | protected function setInitialValuesAndProperties(array &$data, bool $checkPropertiesInConstructor) |
|
6812 | |||
6813 | /** |
||
6814 | * sorting keys |
||
6815 | * |
||
6816 | * @param array $elements |
||
6817 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
6818 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
6819 | * <strong>SORT_NATURAL</strong></p> |
||
6820 | * |
||
6821 | * @return $this |
||
6822 | * <p>(Mutable) Return this Arrayy object.</p> |
||
6823 | * |
||
6824 | * @psalm-param array<mixed,mixed>|array<mixed|TKey,T> $elements |
||
6825 | * @psalm-return static<TKey,T> |
||
6826 | */ |
||
6827 | 18 | protected function sorterKeys( |
|
6848 | |||
6849 | /** |
||
6850 | * @param array $elements <p>Warning: used as reference</p> |
||
6851 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
6852 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
6853 | * <strong>SORT_NATURAL</strong></p> |
||
6854 | * @param bool $keepKeys |
||
6855 | * |
||
6856 | * @return $this |
||
6857 | * <p>(Mutable) Return this Arrayy object.</p> |
||
6858 | * |
||
6859 | * @psalm-param array<mixed,mixed>|array<mixed|TKey,T> $elements |
||
6860 | * @psalm-return static<TKey,T> |
||
6861 | */ |
||
6862 | 24 | protected function sorting(array &$elements, $direction = \SORT_ASC, int $strategy = \SORT_REGULAR, bool $keepKeys = false): self |
|
6892 | |||
6893 | /** |
||
6894 | * @param array $array |
||
6895 | * |
||
6896 | * @return array |
||
6897 | * |
||
6898 | * @psalm-mutation-free |
||
6899 | */ |
||
6900 | 25 | private function getArrayRecursiveHelperArrayy(array $array) |
|
6922 | |||
6923 | /** |
||
6924 | * @param int|string|null $key |
||
6925 | * @param mixed $value |
||
6926 | * |
||
6927 | * @return void |
||
6928 | */ |
||
6929 | 109 | private function checkType($key, $value) |
|
6947 | } |
||
6948 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..