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 |
|
1281 | { |
||
1282 | 23 | if ($recursive === true) { |
|
1283 | 18 | return $this->in_array_recursive($value, $this->toArray(), $strict); |
|
1284 | } |
||
1285 | |||
1286 | /** @noinspection PhpParameterByRefIsNotUsedAsReferenceInspection */ |
||
1287 | 14 | foreach ($this->getGeneratorByReference() as &$valueFromArray) { |
|
1288 | 11 | if ($strict) { |
|
1289 | 11 | if ($value === $valueFromArray) { |
|
1290 | 11 | return true; |
|
1291 | } |
||
1292 | } else { |
||
1293 | /** @noinspection NestedPositiveIfStatementsInspection */ |
||
1294 | if ($value == $valueFromArray) { |
||
1295 | return true; |
||
1296 | } |
||
1297 | } |
||
1298 | } |
||
1299 | |||
1300 | 7 | return false; |
|
1301 | } |
||
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 | 718 | 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( |
|
2662 | |||
2663 | /** |
||
2664 | * alias: for "Arrayy->toArray()" |
||
2665 | * |
||
2666 | * @return array |
||
2667 | * |
||
2668 | * @see Arrayy::getArray() |
||
2669 | * |
||
2670 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
2671 | */ |
||
2672 | 15 | public function getAll(): array |
|
2676 | |||
2677 | /** |
||
2678 | * Get the current array from the "Arrayy"-object. |
||
2679 | * |
||
2680 | * alias for "toArray()" |
||
2681 | * |
||
2682 | * @param bool $convertAllArrayyElements <p> |
||
2683 | * Convert all Child-"Arrayy" objects also to arrays. |
||
2684 | * </p> |
||
2685 | * @param bool $preserveKeys <p> |
||
2686 | * e.g.: A generator maybe return the same key more then once, |
||
2687 | * so maybe you will ignore the keys. |
||
2688 | * </p> |
||
2689 | * |
||
2690 | * @return array |
||
2691 | * |
||
2692 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
2693 | * @psalm-mutation-free |
||
2694 | * |
||
2695 | * @see Arrayy::toArray() |
||
2696 | */ |
||
2697 | 500 | public function getArray( |
|
2706 | |||
2707 | /** |
||
2708 | * @param string $json |
||
2709 | * |
||
2710 | * @return $this |
||
2711 | */ |
||
2712 | 3 | public static function createFromJsonMapper(string $json) |
|
2728 | |||
2729 | /** |
||
2730 | * @return array<int|string,TypeCheckInterface>|mixed|TypeCheckArray<int|string,TypeCheckInterface>|TypeInterface |
||
2731 | * |
||
2732 | * @internal |
||
2733 | */ |
||
2734 | 6 | public function getPhpDocPropertiesFromClass() |
|
2742 | |||
2743 | /** |
||
2744 | * Get the current array from the "Arrayy"-object as list. |
||
2745 | * |
||
2746 | * alias for "toList()" |
||
2747 | * |
||
2748 | * @param bool $convertAllArrayyElements <p> |
||
2749 | * Convert all Child-"Arrayy" objects also to arrays. |
||
2750 | * </p> |
||
2751 | * |
||
2752 | * @return array |
||
2753 | * |
||
2754 | * @psalm-return array<int,mixed>|array<int,T> |
||
2755 | * @psalm-mutation-free |
||
2756 | * |
||
2757 | * @see Arrayy::toList() |
||
2758 | */ |
||
2759 | 1 | public function getList(bool $convertAllArrayyElements = false): array |
|
2763 | |||
2764 | /** |
||
2765 | * Returns the values from a single column of the input array, identified by |
||
2766 | * the $columnKey, can be used to extract data-columns from multi-arrays. |
||
2767 | * |
||
2768 | * Info: Optionally, you may provide an $indexKey to index the values in the returned |
||
2769 | * array by the values from the $indexKey column in the input array. |
||
2770 | * |
||
2771 | * @param mixed $columnKey |
||
2772 | * @param mixed $indexKey |
||
2773 | * |
||
2774 | * @return static |
||
2775 | * <p>(Immutable)</p> |
||
2776 | * |
||
2777 | * @psalm-return static<TKey,T> |
||
2778 | * @psalm-mutation-free |
||
2779 | */ |
||
2780 | 1 | public function getColumn($columnKey = null, $indexKey = null): self |
|
2788 | |||
2789 | /** |
||
2790 | * Get the current array from the "Arrayy"-object as generator by reference. |
||
2791 | * |
||
2792 | * @return \Generator |
||
2793 | * |
||
2794 | * @psalm-return \Generator<mixed,T>|\Generator<TKey,T> |
||
2795 | */ |
||
2796 | 75 | public function &getGeneratorByReference(): \Generator |
|
2815 | |||
2816 | /** |
||
2817 | * Get the current array from the "Arrayy"-object as generator. |
||
2818 | * |
||
2819 | * @return \Generator |
||
2820 | * |
||
2821 | * @psalm-return \Generator<mixed,T>|\Generator<TKey,T> |
||
2822 | * @psalm-mutation-free |
||
2823 | */ |
||
2824 | 996 | public function getGenerator(): \Generator |
|
2834 | |||
2835 | /** |
||
2836 | * alias: for "Arrayy->keys()" |
||
2837 | * |
||
2838 | * @return static |
||
2839 | * <p>(Immutable)</p> |
||
2840 | * |
||
2841 | * @see Arrayy::keys() |
||
2842 | * |
||
2843 | * @psalm-return static<array-key,TKey> |
||
2844 | * @psalm-mutation-free |
||
2845 | */ |
||
2846 | 2 | public function getKeys() |
|
2850 | |||
2851 | /** |
||
2852 | * Get the current array from the "Arrayy"-object as object. |
||
2853 | * |
||
2854 | * @return \stdClass |
||
2855 | */ |
||
2856 | 4 | public function getObject(): \stdClass |
|
2860 | |||
2861 | /** |
||
2862 | * alias: for "Arrayy->randomImmutable()" |
||
2863 | * |
||
2864 | * @return static |
||
2865 | * <p>(Immutable)</p> |
||
2866 | * |
||
2867 | * @see Arrayy::randomImmutable() |
||
2868 | * |
||
2869 | * @psalm-return static<int|array-key,T> |
||
2870 | */ |
||
2871 | 4 | public function getRandom(): self |
|
2875 | |||
2876 | /** |
||
2877 | * alias: for "Arrayy->randomKey()" |
||
2878 | * |
||
2879 | * @return mixed |
||
2880 | * <p>Get a key/index or null if there wasn't a key/index.</p> |
||
2881 | * |
||
2882 | * @see Arrayy::randomKey() |
||
2883 | */ |
||
2884 | 3 | public function getRandomKey() |
|
2888 | |||
2889 | /** |
||
2890 | * alias: for "Arrayy->randomKeys()" |
||
2891 | * |
||
2892 | * @param int $number |
||
2893 | * |
||
2894 | * @return static |
||
2895 | * <p>(Immutable)</p> |
||
2896 | * |
||
2897 | * @see Arrayy::randomKeys() |
||
2898 | * |
||
2899 | * @psalm-return static<TKey,T> |
||
2900 | */ |
||
2901 | 8 | public function getRandomKeys(int $number): self |
|
2905 | |||
2906 | /** |
||
2907 | * alias: for "Arrayy->randomValue()" |
||
2908 | * |
||
2909 | * @return mixed |
||
2910 | * <p>Get a random value or null if there wasn't a value.</p> |
||
2911 | * |
||
2912 | * @see Arrayy::randomValue() |
||
2913 | */ |
||
2914 | 3 | public function getRandomValue() |
|
2918 | |||
2919 | /** |
||
2920 | * alias: for "Arrayy->randomValues()" |
||
2921 | * |
||
2922 | * @param int $number |
||
2923 | * |
||
2924 | * @return static |
||
2925 | * <p>(Immutable)</p> |
||
2926 | * |
||
2927 | * @see Arrayy::randomValues() |
||
2928 | * |
||
2929 | * @psalm-return static<TKey,T> |
||
2930 | */ |
||
2931 | 6 | public function getRandomValues(int $number): self |
|
2935 | |||
2936 | /** |
||
2937 | * Gets all values. |
||
2938 | * |
||
2939 | * @return static |
||
2940 | * <p>The values of all elements in this array, in the order they |
||
2941 | * appear in the array.</p> |
||
2942 | * |
||
2943 | * @psalm-return static<TKey,T> |
||
2944 | */ |
||
2945 | 4 | public function getValues() |
|
2955 | |||
2956 | /** |
||
2957 | * Gets all values via Generator. |
||
2958 | * |
||
2959 | * @return \Generator |
||
2960 | * <p>The values of all elements in this array, in the order they |
||
2961 | * appear in the array as Generator.</p> |
||
2962 | * |
||
2963 | * @psalm-return \Generator<TKey,T> |
||
2964 | */ |
||
2965 | 4 | public function getValuesYield(): \Generator |
|
2969 | |||
2970 | /** |
||
2971 | * Group values from a array according to the results of a closure. |
||
2972 | * |
||
2973 | * @param callable|string $grouper <p>A callable function name.</p> |
||
2974 | * @param bool $saveKeys |
||
2975 | * |
||
2976 | * @return static |
||
2977 | * <p>(Immutable)</p> |
||
2978 | * |
||
2979 | * @psalm-return static<TKey,T> |
||
2980 | * @psalm-mutation-free |
||
2981 | */ |
||
2982 | 4 | public function group($grouper, bool $saveKeys = false): self |
|
3023 | |||
3024 | /** |
||
3025 | * Check if an array has a given key. |
||
3026 | * |
||
3027 | * @param mixed $key |
||
3028 | * |
||
3029 | * @return bool |
||
3030 | */ |
||
3031 | 30 | public function has($key): bool |
|
3057 | |||
3058 | /** |
||
3059 | * Check if an array has a given value. |
||
3060 | * |
||
3061 | * INFO: if you need to search recursive please use ```contains()``` |
||
3062 | * |
||
3063 | * @param mixed $value |
||
3064 | * |
||
3065 | * @return bool |
||
3066 | */ |
||
3067 | 1 | public function hasValue($value): bool |
|
3071 | |||
3072 | /** |
||
3073 | * Implodes the values of this array. |
||
3074 | * |
||
3075 | * @param string $glue |
||
3076 | * |
||
3077 | * @return string |
||
3078 | * @psalm-mutation-free |
||
3079 | */ |
||
3080 | 28 | public function implode(string $glue = ''): string |
|
3084 | |||
3085 | /** |
||
3086 | * Implodes the keys of this array. |
||
3087 | * |
||
3088 | * @param string $glue |
||
3089 | * |
||
3090 | * @return string |
||
3091 | * @psalm-mutation-free |
||
3092 | */ |
||
3093 | 8 | public function implodeKeys(string $glue = ''): string |
|
3097 | |||
3098 | /** |
||
3099 | * Given a list and an iterate-function that returns |
||
3100 | * a key for each element in the list (or a property name), |
||
3101 | * returns an object with an index of each item. |
||
3102 | * |
||
3103 | * @param mixed $key |
||
3104 | * |
||
3105 | * @return static |
||
3106 | * <p>(Immutable)</p> |
||
3107 | * |
||
3108 | * @psalm-return static<TKey,T> |
||
3109 | * @psalm-mutation-free |
||
3110 | */ |
||
3111 | 4 | public function indexBy($key): self |
|
3128 | |||
3129 | /** |
||
3130 | * alias: for "Arrayy->searchIndex()" |
||
3131 | * |
||
3132 | * @param mixed $value <p>The value to search for.</p> |
||
3133 | * |
||
3134 | * @return false|mixed |
||
3135 | * |
||
3136 | * @see Arrayy::searchIndex() |
||
3137 | */ |
||
3138 | 4 | public function indexOf($value) |
|
3142 | |||
3143 | /** |
||
3144 | * Get everything but the last..$to items. |
||
3145 | * |
||
3146 | * @param int $to |
||
3147 | * |
||
3148 | * @return static |
||
3149 | * <p>(Immutable)</p> |
||
3150 | * |
||
3151 | * @psalm-return static<TKey,T> |
||
3152 | * @psalm-mutation-free |
||
3153 | */ |
||
3154 | 12 | public function initial(int $to = 1): self |
|
3158 | |||
3159 | /** |
||
3160 | * Return an array with all elements found in input array. |
||
3161 | * |
||
3162 | * @param array $search |
||
3163 | * @param bool $keepKeys |
||
3164 | * |
||
3165 | * @return static |
||
3166 | * <p>(Immutable)</p> |
||
3167 | * |
||
3168 | * @psalm-param array<mixed,mixed>|array<TKey,T> $search |
||
3169 | * @psalm-return static<TKey,T> |
||
3170 | * @psalm-mutation-free |
||
3171 | */ |
||
3172 | 4 | public function intersection(array $search, bool $keepKeys = false): self |
|
3198 | |||
3199 | /** |
||
3200 | * Return an array with all elements found in input array. |
||
3201 | * |
||
3202 | * @param array ...$array |
||
3203 | * |
||
3204 | * @return static |
||
3205 | * <p>(Immutable)</p> |
||
3206 | * |
||
3207 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$array |
||
3208 | * @psalm-return static<TKey,T> |
||
3209 | * @psalm-mutation-free |
||
3210 | */ |
||
3211 | 1 | public function intersectionMulti(...$array): self |
|
3219 | |||
3220 | /** |
||
3221 | * Return a boolean flag which indicates whether the two input arrays have any common elements. |
||
3222 | * |
||
3223 | * @param array $search |
||
3224 | * |
||
3225 | * @return bool |
||
3226 | * |
||
3227 | * @psalm-param array<mixed,mixed>|array<TKey,T> $search |
||
3228 | */ |
||
3229 | 1 | public function intersects(array $search): bool |
|
3233 | |||
3234 | /** |
||
3235 | * Invoke a function on all of an array's values. |
||
3236 | * |
||
3237 | * @param callable $callable |
||
3238 | * @param mixed $arguments |
||
3239 | * |
||
3240 | * @return static |
||
3241 | * <p>(Immutable)</p> |
||
3242 | * |
||
3243 | * @psalm-param callable(T=,mixed):mixed $callable |
||
3244 | * @psalm-return static<TKey,T> |
||
3245 | * @psalm-mutation-free |
||
3246 | */ |
||
3247 | 1 | View Code Duplication | public function invoke($callable, $arguments = []): self |
3271 | |||
3272 | /** |
||
3273 | * Check whether array is associative or not. |
||
3274 | * |
||
3275 | * @param bool $recursive |
||
3276 | * |
||
3277 | * @return bool |
||
3278 | * <p>Returns true if associative, false otherwise.</p> |
||
3279 | */ |
||
3280 | 15 | View Code Duplication | public function isAssoc(bool $recursive = false): bool |
3295 | |||
3296 | /** |
||
3297 | * Check if a given key or keys are empty. |
||
3298 | * |
||
3299 | * @param int|int[]|string|string[]|null $keys |
||
3300 | * |
||
3301 | * @return bool |
||
3302 | * <p>Returns true if empty, false otherwise.</p> |
||
3303 | * @psalm-mutation-free |
||
3304 | */ |
||
3305 | 45 | public function isEmpty($keys = null): bool |
|
3323 | |||
3324 | /** |
||
3325 | * Check if the current array is equal to the given "$array" or not. |
||
3326 | * |
||
3327 | * @param array $array |
||
3328 | * |
||
3329 | * @return bool |
||
3330 | * |
||
3331 | * @psalm-param array<mixed,mixed> $array |
||
3332 | */ |
||
3333 | 1 | public function isEqual(array $array): bool |
|
3337 | |||
3338 | /** |
||
3339 | * Check if the current array is a multi-array. |
||
3340 | * |
||
3341 | * @return bool |
||
3342 | */ |
||
3343 | 22 | public function isMultiArray(): bool |
|
3351 | |||
3352 | /** |
||
3353 | * Check whether array is numeric or not. |
||
3354 | * |
||
3355 | * @return bool |
||
3356 | * <p>Returns true if numeric, false otherwise.</p> |
||
3357 | */ |
||
3358 | 5 | View Code Duplication | public function isNumeric(): bool |
3373 | |||
3374 | /** |
||
3375 | * Check if the current array is sequential [0, 1, 2, 3, 4, 5 ...] or not. |
||
3376 | * |
||
3377 | * @param bool $recursive |
||
3378 | * |
||
3379 | * @return bool |
||
3380 | * @psalm-mutation-free |
||
3381 | */ |
||
3382 | 9 | public function isSequential(bool $recursive = false): bool |
|
3399 | |||
3400 | /** |
||
3401 | * @return array |
||
3402 | * |
||
3403 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
3404 | */ |
||
3405 | 2 | public function jsonSerialize(): array |
|
3409 | |||
3410 | /** |
||
3411 | * Gets the key/index of the element at the current internal iterator position. |
||
3412 | * |
||
3413 | * @return int|string|null |
||
3414 | */ |
||
3415 | public function key() |
||
3419 | |||
3420 | /** |
||
3421 | * Checks if the given key exists in the provided array. |
||
3422 | * |
||
3423 | * INFO: This method only use "array_key_exists()" if you want to use "dot"-notation, |
||
3424 | * then you need to use "Arrayy->offsetExists()". |
||
3425 | * |
||
3426 | * @param int|string $key the key to look for |
||
3427 | * |
||
3428 | * @return bool |
||
3429 | * @psalm-mutation-free |
||
3430 | */ |
||
3431 | 162 | public function keyExists($key): bool |
|
3435 | |||
3436 | /** |
||
3437 | * Get all keys from the current array. |
||
3438 | * |
||
3439 | * @param bool $recursive [optional] <p> |
||
3440 | * Get all keys, also from all sub-arrays from an multi-dimensional array. |
||
3441 | * </p> |
||
3442 | * @param mixed|null $search_values [optional] <p> |
||
3443 | * If specified, then only keys containing these values are returned. |
||
3444 | * </p> |
||
3445 | * @param bool $strict [optional] <p> |
||
3446 | * Determines if strict comparison (===) should be used during the search. |
||
3447 | * </p> |
||
3448 | * |
||
3449 | * @return static |
||
3450 | * <p>(Immutable) An array of all the keys in input.</p> |
||
3451 | * |
||
3452 | * @psalm-return static<array-key,TKey> |
||
3453 | * @psalm-mutation-free |
||
3454 | */ |
||
3455 | 29 | public function keys( |
|
3526 | |||
3527 | /** |
||
3528 | * Sort an array by key in reverse order. |
||
3529 | * |
||
3530 | * @param int $sort_flags [optional] <p> |
||
3531 | * You may modify the behavior of the sort using the optional |
||
3532 | * parameter sort_flags, for details |
||
3533 | * see sort. |
||
3534 | * </p> |
||
3535 | * |
||
3536 | * @return $this |
||
3537 | * <p>(Mutable) Return this Arrayy object.</p> |
||
3538 | * |
||
3539 | * @psalm-return static<TKey,T> |
||
3540 | */ |
||
3541 | 4 | public function krsort(int $sort_flags = 0): self |
|
3549 | |||
3550 | /** |
||
3551 | * Sort an array by key in reverse order. |
||
3552 | * |
||
3553 | * @param int $sort_flags [optional] <p> |
||
3554 | * You may modify the behavior of the sort using the optional |
||
3555 | * parameter sort_flags, for details |
||
3556 | * see sort. |
||
3557 | * </p> |
||
3558 | * |
||
3559 | * @return $this |
||
3560 | * <p>(Immutable) Return this Arrayy object.</p> |
||
3561 | * |
||
3562 | * @psalm-return static<TKey,T> |
||
3563 | * @psalm-mutation-free |
||
3564 | */ |
||
3565 | 4 | public function krsortImmutable(int $sort_flags = 0): self |
|
3576 | |||
3577 | /** |
||
3578 | * Get the last value from the current array. |
||
3579 | * |
||
3580 | * @return mixed|null |
||
3581 | * <p>Return null if there wasn't a element.</p> |
||
3582 | * @psalm-mutation-free |
||
3583 | */ |
||
3584 | 17 | public function last() |
|
3593 | |||
3594 | /** |
||
3595 | * Get the last key from the current array. |
||
3596 | * |
||
3597 | * @return mixed|null |
||
3598 | * <p>Return null if there wasn't a element.</p> |
||
3599 | * @psalm-mutation-free |
||
3600 | */ |
||
3601 | 21 | public function lastKey() |
|
3607 | |||
3608 | /** |
||
3609 | * Get the last value(s) from the current array. |
||
3610 | * |
||
3611 | * @param int|null $number |
||
3612 | * |
||
3613 | * @return static |
||
3614 | * <p>(Immutable)</p> |
||
3615 | * |
||
3616 | * @psalm-return static<TKey,T> |
||
3617 | * @psalm-mutation-free |
||
3618 | */ |
||
3619 | 13 | public function lastsImmutable(int $number = null): self |
|
3649 | |||
3650 | /** |
||
3651 | * Get the last value(s) from the current array. |
||
3652 | * |
||
3653 | * @param int|null $number |
||
3654 | * |
||
3655 | * @return $this |
||
3656 | * <p>(Mutable)</p> |
||
3657 | * |
||
3658 | * @psalm-return static<TKey,T> |
||
3659 | */ |
||
3660 | 13 | public function lastsMutable(int $number = null): self |
|
3688 | |||
3689 | /** |
||
3690 | * Count the values from the current array. |
||
3691 | * |
||
3692 | * alias: for "Arrayy->count()" |
||
3693 | * |
||
3694 | * @param int $mode |
||
3695 | * |
||
3696 | * @return int |
||
3697 | * |
||
3698 | * @see Arrayy::count() |
||
3699 | */ |
||
3700 | 20 | public function length(int $mode = \COUNT_NORMAL): int |
|
3704 | |||
3705 | /** |
||
3706 | * Apply the given function to the every element of the array, |
||
3707 | * collecting the results. |
||
3708 | * |
||
3709 | * @param callable $callable |
||
3710 | * @param bool $useKeyAsSecondParameter |
||
3711 | * @param mixed ...$arguments |
||
3712 | * |
||
3713 | * @return static |
||
3714 | * <p>(Immutable) Arrayy object with modified elements.</p> |
||
3715 | * |
||
3716 | * @psalm-param callable(T,TKey=,mixed=):mixed $callable |
||
3717 | * @psalm-return static<TKey,T> |
||
3718 | * @psalm-mutation-free |
||
3719 | */ |
||
3720 | 5 | public function map( |
|
3753 | |||
3754 | /** |
||
3755 | * Check if all items in current array match a truth test. |
||
3756 | * |
||
3757 | * @param \Closure $closure |
||
3758 | * |
||
3759 | * @return bool |
||
3760 | */ |
||
3761 | 15 | View Code Duplication | public function matches(\Closure $closure): bool |
3777 | |||
3778 | /** |
||
3779 | * Check if any item in the current array matches a truth test. |
||
3780 | * |
||
3781 | * @param \Closure $closure |
||
3782 | * |
||
3783 | * @return bool |
||
3784 | */ |
||
3785 | 14 | View Code Duplication | public function matchesAny(\Closure $closure): bool |
3801 | |||
3802 | /** |
||
3803 | * Get the max value from an array. |
||
3804 | * |
||
3805 | * @return false|mixed |
||
3806 | * <p>Will return false if there are no values.</p> |
||
3807 | */ |
||
3808 | 10 | View Code Duplication | public function max() |
3828 | |||
3829 | /** |
||
3830 | * Merge the new $array into the current array. |
||
3831 | * |
||
3832 | * - keep key,value from the current array, also if the index is in the new $array |
||
3833 | * |
||
3834 | * @param array $array |
||
3835 | * @param bool $recursive |
||
3836 | * |
||
3837 | * @return static |
||
3838 | * <p>(Immutable)</p> |
||
3839 | * |
||
3840 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
3841 | * @psalm-return static<int|TKey,T> |
||
3842 | * @psalm-mutation-free |
||
3843 | */ |
||
3844 | 32 | View Code Duplication | public function mergeAppendKeepIndex(array $array = [], bool $recursive = false): self |
3859 | |||
3860 | /** |
||
3861 | * Merge the new $array into the current array. |
||
3862 | * |
||
3863 | * - replace duplicate assoc-keys from the current array with the key,values from the new $array |
||
3864 | * - create new indexes |
||
3865 | * |
||
3866 | * @param array $array |
||
3867 | * @param bool $recursive |
||
3868 | * |
||
3869 | * @return static |
||
3870 | * <p>(Immutable)</p> |
||
3871 | * |
||
3872 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
3873 | * @psalm-return static<TKey,T> |
||
3874 | * @psalm-mutation-free |
||
3875 | */ |
||
3876 | 19 | View Code Duplication | public function mergeAppendNewIndex(array $array = [], bool $recursive = false): self |
3891 | |||
3892 | /** |
||
3893 | * Merge the the current array into the $array. |
||
3894 | * |
||
3895 | * - use key,value from the new $array, also if the index is in the current array |
||
3896 | * |
||
3897 | * @param array $array |
||
3898 | * @param bool $recursive |
||
3899 | * |
||
3900 | * @return static |
||
3901 | * <p>(Immutable)</p> |
||
3902 | * |
||
3903 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
3904 | * @psalm-return static<TKey,T> |
||
3905 | * @psalm-mutation-free |
||
3906 | */ |
||
3907 | 16 | View Code Duplication | public function mergePrependKeepIndex(array $array = [], bool $recursive = false): self |
3922 | |||
3923 | /** |
||
3924 | * Merge the current array into the new $array. |
||
3925 | * |
||
3926 | * - replace duplicate assoc-keys from new $array with the key,values from the current array |
||
3927 | * - create new indexes |
||
3928 | * |
||
3929 | * @param array $array |
||
3930 | * @param bool $recursive |
||
3931 | * |
||
3932 | * @return static |
||
3933 | * <p>(Immutable)</p> |
||
3934 | * |
||
3935 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
3936 | * @psalm-return static<TKey,T> |
||
3937 | * @psalm-mutation-free |
||
3938 | */ |
||
3939 | 20 | View Code Duplication | public function mergePrependNewIndex(array $array = [], bool $recursive = false): self |
3954 | |||
3955 | /** |
||
3956 | * @return ArrayyMeta|static |
||
3957 | */ |
||
3958 | 16 | public static function meta() |
|
3962 | |||
3963 | /** |
||
3964 | * Get the min value from an array. |
||
3965 | * |
||
3966 | * @return false|mixed |
||
3967 | * <p>Will return false if there are no values.</p> |
||
3968 | */ |
||
3969 | 10 | View Code Duplication | public function min() |
3989 | |||
3990 | /** |
||
3991 | * Get the most used value from the array. |
||
3992 | * |
||
3993 | * @return mixed|null |
||
3994 | * <p>(Immutable) Return null if there wasn't a element.</p> |
||
3995 | * @psalm-mutation-free |
||
3996 | */ |
||
3997 | 3 | public function mostUsedValue() |
|
4001 | |||
4002 | /** |
||
4003 | * Get the most used value from the array. |
||
4004 | * |
||
4005 | * @param int|null $number <p>How many values you will take?</p> |
||
4006 | * |
||
4007 | * @return static |
||
4008 | * <p>(Immutable)</p> |
||
4009 | * |
||
4010 | * @psalm-return static<TKey,T> |
||
4011 | * @psalm-mutation-free |
||
4012 | */ |
||
4013 | 3 | public function mostUsedValues(int $number = null): self |
|
4017 | |||
4018 | /** |
||
4019 | * Move an array element to a new index. |
||
4020 | * |
||
4021 | * cherry-picked from: http://stackoverflow.com/questions/12624153/move-an-array-element-to-a-new-index-in-php |
||
4022 | * |
||
4023 | * @param int|string $from |
||
4024 | * @param int $to |
||
4025 | * |
||
4026 | * @return static |
||
4027 | * <p>(Immutable)</p> |
||
4028 | * |
||
4029 | * @psalm-return static<TKey,T> |
||
4030 | * @psalm-mutation-free |
||
4031 | */ |
||
4032 | 1 | public function moveElement($from, $to): self |
|
4065 | |||
4066 | /** |
||
4067 | * Move an array element to the first place. |
||
4068 | * |
||
4069 | * INFO: Instead of "Arrayy->moveElement()" this method will NOT |
||
4070 | * loss the keys of an indexed array. |
||
4071 | * |
||
4072 | * @param int|string $key |
||
4073 | * |
||
4074 | * @return static |
||
4075 | * <p>(Immutable)</p> |
||
4076 | * |
||
4077 | * @psalm-return static<TKey,T> |
||
4078 | * @psalm-mutation-free |
||
4079 | */ |
||
4080 | 1 | View Code Duplication | public function moveElementToFirstPlace($key): self |
4096 | |||
4097 | /** |
||
4098 | * Move an array element to the last place. |
||
4099 | * |
||
4100 | * INFO: Instead of "Arrayy->moveElement()" this method will NOT |
||
4101 | * loss the keys of an indexed array. |
||
4102 | * |
||
4103 | * @param int|string $key |
||
4104 | * |
||
4105 | * @return static |
||
4106 | * <p>(Immutable)</p> |
||
4107 | * |
||
4108 | * @psalm-return static<TKey,T> |
||
4109 | * @psalm-mutation-free |
||
4110 | */ |
||
4111 | 1 | View Code Duplication | public function moveElementToLastPlace($key): self |
4127 | |||
4128 | /** |
||
4129 | * Moves the internal iterator position to the next element and returns this element. |
||
4130 | * |
||
4131 | * @return false|mixed |
||
4132 | * <p>(Mutable) Will return false if there are no values.</p> |
||
4133 | */ |
||
4134 | public function next() |
||
4138 | |||
4139 | /** |
||
4140 | * Get the next nth keys and values from the array. |
||
4141 | * |
||
4142 | * @param int $step |
||
4143 | * @param int $offset |
||
4144 | * |
||
4145 | * @return static |
||
4146 | * <p>(Immutable)</p> |
||
4147 | * |
||
4148 | * @psalm-return static<TKey,T> |
||
4149 | * @psalm-mutation-free |
||
4150 | */ |
||
4151 | 1 | public function nth(int $step, int $offset = 0): self |
|
4170 | |||
4171 | /** |
||
4172 | * Get a subset of the items from the given array. |
||
4173 | * |
||
4174 | * @param mixed[] $keys |
||
4175 | * |
||
4176 | * @return static |
||
4177 | * <p>(Immutable)</p> |
||
4178 | * |
||
4179 | * @psalm-return static<TKey,T> |
||
4180 | * @psalm-mutation-free |
||
4181 | */ |
||
4182 | 1 | public function only(array $keys): self |
|
4192 | |||
4193 | /** |
||
4194 | * Pad array to the specified size with a given value. |
||
4195 | * |
||
4196 | * @param int $size <p>Size of the result array.</p> |
||
4197 | * @param mixed $value <p>Empty value by default.</p> |
||
4198 | * |
||
4199 | * @return static |
||
4200 | * <p>(Immutable) Arrayy object padded to $size with $value.</p> |
||
4201 | * |
||
4202 | * @psalm-return static<TKey,T> |
||
4203 | * @psalm-mutation-free |
||
4204 | */ |
||
4205 | 5 | public function pad(int $size, $value): self |
|
4213 | |||
4214 | /** |
||
4215 | * Partitions this array in two array according to a predicate. |
||
4216 | * Keys are preserved in the resulting array. |
||
4217 | * |
||
4218 | * @param \Closure $closure |
||
4219 | * <p>The predicate on which to partition.</p> |
||
4220 | * |
||
4221 | * @return array<int, static> |
||
4222 | * <p>An array with two elements. The first element contains the array |
||
4223 | * of elements where the predicate returned TRUE, the second element |
||
4224 | * contains the array of elements where the predicate returned FALSE.</p> |
||
4225 | * |
||
4226 | * @psalm-return array<int, static<TKey,T>> |
||
4227 | */ |
||
4228 | 1 | public function partition(\Closure $closure): array |
|
4244 | |||
4245 | /** |
||
4246 | * Pop a specified value off the end of the current array. |
||
4247 | * |
||
4248 | * @return mixed|null |
||
4249 | * <p>(Mutable) The popped element from the current array or null if the array is e.g. empty.</p> |
||
4250 | */ |
||
4251 | 5 | public function pop() |
|
4257 | |||
4258 | /** |
||
4259 | * Prepend a (key) + value to the current array. |
||
4260 | * |
||
4261 | * EXAMPLE: <code> |
||
4262 | * a(['fòô' => 'bàř'])->prepend('foo'); // Arrayy[0 => 'foo', 'fòô' => 'bàř'] |
||
4263 | * </code> |
||
4264 | * |
||
4265 | * @param mixed $value |
||
4266 | * @param mixed $key |
||
4267 | * |
||
4268 | * @return $this |
||
4269 | * <p>(Mutable) Return this Arrayy object, with the prepended value.</p> |
||
4270 | * |
||
4271 | * @psalm-return static<TKey,T> |
||
4272 | */ |
||
4273 | 11 | public function prepend($value, $key = null) |
|
4289 | |||
4290 | /** |
||
4291 | * Add a suffix to each key. |
||
4292 | * |
||
4293 | * @param mixed $suffix |
||
4294 | * |
||
4295 | * @return static |
||
4296 | * <p>(Immutable) Return an Arrayy object, with the prepended keys.</p> |
||
4297 | * |
||
4298 | * @psalm-return static<TKey,T> |
||
4299 | * @psalm-mutation-free |
||
4300 | */ |
||
4301 | 10 | View Code Duplication | public function prependToEachKey($suffix): self |
4327 | |||
4328 | /** |
||
4329 | * Add a suffix to each value. |
||
4330 | * |
||
4331 | * @param mixed $suffix |
||
4332 | * |
||
4333 | * @return static |
||
4334 | * <p>(Immutable) Return an Arrayy object, with the prepended values.</p> |
||
4335 | * |
||
4336 | * @psalm-return static<TKey,T> |
||
4337 | * @psalm-mutation-free |
||
4338 | */ |
||
4339 | 10 | View Code Duplication | public function prependToEachValue($suffix): self |
4367 | |||
4368 | /** |
||
4369 | * Return the value of a given key and |
||
4370 | * delete the key. |
||
4371 | * |
||
4372 | * @param int|int[]|string|string[]|null $keyOrKeys |
||
4373 | * @param mixed $fallback |
||
4374 | * |
||
4375 | * @return mixed |
||
4376 | */ |
||
4377 | 5 | public function pull($keyOrKeys = null, $fallback = null) |
|
4399 | |||
4400 | /** |
||
4401 | * Push one or more values onto the end of array at once. |
||
4402 | * |
||
4403 | * @param array ...$args |
||
4404 | * |
||
4405 | * @return $this |
||
4406 | * <p>(Mutable) Return this Arrayy object, with pushed elements to the end of array.</p> |
||
4407 | * |
||
4408 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
4409 | * |
||
4410 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$args |
||
4411 | * @psalm-return static<TKey,T> |
||
4412 | */ |
||
4413 | 7 | public function push(...$args) |
|
4431 | |||
4432 | /** |
||
4433 | * Get a random value from the current array. |
||
4434 | * |
||
4435 | * @param int|null $number <p>How many values you will take?</p> |
||
4436 | * |
||
4437 | * @return static |
||
4438 | * <p>(Immutable)</p> |
||
4439 | * |
||
4440 | * @psalm-return static<int|array-key,T> |
||
4441 | */ |
||
4442 | 19 | public function randomImmutable(int $number = null): self |
|
4475 | |||
4476 | /** |
||
4477 | * Pick a random key/index from the keys of this array. |
||
4478 | * |
||
4479 | * @throws \RangeException If array is empty |
||
4480 | * |
||
4481 | * @return mixed |
||
4482 | * <p>Get a key/index or null if there wasn't a key/index.</p> |
||
4483 | */ |
||
4484 | 4 | public function randomKey() |
|
4494 | |||
4495 | /** |
||
4496 | * Pick a given number of random keys/indexes out of this array. |
||
4497 | * |
||
4498 | * @param int $number <p>The number of keys/indexes (should be <= \count($this->array))</p> |
||
4499 | * |
||
4500 | * @throws \RangeException If array is empty |
||
4501 | * |
||
4502 | * @return static |
||
4503 | * <p>(Immutable)</p> |
||
4504 | * |
||
4505 | * @psalm-return static<TKey,T> |
||
4506 | */ |
||
4507 | 13 | public function randomKeys(int $number): self |
|
4535 | |||
4536 | /** |
||
4537 | * Get a random value from the current array. |
||
4538 | * |
||
4539 | * @param int|null $number <p>How many values you will take?</p> |
||
4540 | * |
||
4541 | * @return $this |
||
4542 | * <p>(Mutable) Return this Arrayy object.</p> |
||
4543 | * |
||
4544 | * @psalm-return static<TKey,T> |
||
4545 | */ |
||
4546 | 17 | public function randomMutable(int $number = null): self |
|
4571 | |||
4572 | /** |
||
4573 | * Pick a random value from the values of this array. |
||
4574 | * |
||
4575 | * @return mixed |
||
4576 | * <p>Get a random value or null if there wasn't a value.</p> |
||
4577 | */ |
||
4578 | 4 | public function randomValue() |
|
4588 | |||
4589 | /** |
||
4590 | * Pick a given number of random values out of this array. |
||
4591 | * |
||
4592 | * @param int $number |
||
4593 | * |
||
4594 | * @return static |
||
4595 | * <p>(Mutable)</p> |
||
4596 | * |
||
4597 | * @psalm-return static<TKey,T> |
||
4598 | */ |
||
4599 | 7 | public function randomValues(int $number): self |
|
4603 | |||
4604 | /** |
||
4605 | * Get a random value from an array, with the ability to skew the results. |
||
4606 | * |
||
4607 | * Example: randomWeighted(['foo' => 1, 'bar' => 2]) has a 66% chance of returning bar. |
||
4608 | * |
||
4609 | * @param array $array |
||
4610 | * @param int|null $number <p>How many values you will take?</p> |
||
4611 | * |
||
4612 | * @return static<int,mixed> |
||
4613 | * <p>(Immutable)</p> |
||
4614 | * |
||
4615 | * @psalm-param array<mixed,mixed> $array |
||
4616 | * @psalm-return static<int|array-key,T> |
||
4617 | */ |
||
4618 | 9 | public function randomWeighted(array $array, int $number = null): self |
|
4633 | |||
4634 | /** |
||
4635 | * Reduce the current array via callable e.g. anonymous-function. |
||
4636 | * |
||
4637 | * @param callable $callable |
||
4638 | * @param mixed $init |
||
4639 | * |
||
4640 | * @return static |
||
4641 | * <p>(Immutable)</p> |
||
4642 | * |
||
4643 | * @psalm-return static<TKey,T> |
||
4644 | * @psalm-mutation-free |
||
4645 | */ |
||
4646 | 18 | public function reduce($callable, $init = []): self |
|
4676 | |||
4677 | /** |
||
4678 | * @param bool $unique |
||
4679 | * |
||
4680 | * @return static |
||
4681 | * <p>(Immutable)</p> |
||
4682 | * |
||
4683 | * @psalm-return static<TKey,T> |
||
4684 | * @psalm-mutation-free |
||
4685 | */ |
||
4686 | 14 | public function reduce_dimension(bool $unique = true): self |
|
4709 | |||
4710 | /** |
||
4711 | * Create a numerically re-indexed Arrayy object. |
||
4712 | * |
||
4713 | * @return $this |
||
4714 | * <p>(Mutable) Return this Arrayy object, with re-indexed array-elements.</p> |
||
4715 | * |
||
4716 | * @psalm-return static<TKey,T> |
||
4717 | */ |
||
4718 | 9 | public function reindex(): self |
|
4726 | |||
4727 | /** |
||
4728 | * Return all items that fail the truth test. |
||
4729 | * |
||
4730 | * @param \Closure $closure |
||
4731 | * |
||
4732 | * @return static |
||
4733 | * <p>(Immutable)</p> |
||
4734 | * |
||
4735 | * @psalm-return static<TKey,T> |
||
4736 | * @psalm-mutation-free |
||
4737 | */ |
||
4738 | 1 | View Code Duplication | public function reject(\Closure $closure): self |
4755 | |||
4756 | /** |
||
4757 | * Remove a value from the current array (optional using dot-notation). |
||
4758 | * |
||
4759 | * @param mixed $key |
||
4760 | * |
||
4761 | * @return static |
||
4762 | * <p>(Mutable)</p> |
||
4763 | * |
||
4764 | * @psalm-param TKey $key |
||
4765 | * @psalm-return static<TKey,T> |
||
4766 | */ |
||
4767 | 21 | public function remove($key) |
|
4790 | |||
4791 | /** |
||
4792 | * alias: for "Arrayy->removeValue()" |
||
4793 | * |
||
4794 | * @param mixed $element |
||
4795 | * |
||
4796 | * @return static |
||
4797 | * <p>(Immutable)</p> |
||
4798 | * |
||
4799 | * @psalm-param T $element |
||
4800 | * @psalm-return static<TKey,T> |
||
4801 | * @psalm-mutation-free |
||
4802 | */ |
||
4803 | 8 | public function removeElement($element) |
|
4807 | |||
4808 | /** |
||
4809 | * Remove the first value from the current array. |
||
4810 | * |
||
4811 | * @return static |
||
4812 | * <p>(Immutable)</p> |
||
4813 | * |
||
4814 | * @psalm-return static<TKey,T> |
||
4815 | * @psalm-mutation-free |
||
4816 | */ |
||
4817 | 7 | View Code Duplication | public function removeFirst(): self |
4829 | |||
4830 | /** |
||
4831 | * Remove the last value from the current array. |
||
4832 | * |
||
4833 | * @return static |
||
4834 | * <p>(Immutable)</p> |
||
4835 | * |
||
4836 | * @psalm-return static<TKey,T> |
||
4837 | * @psalm-mutation-free |
||
4838 | */ |
||
4839 | 7 | View Code Duplication | public function removeLast(): self |
4851 | |||
4852 | /** |
||
4853 | * Removes a particular value from an array (numeric or associative). |
||
4854 | * |
||
4855 | * @param mixed $value |
||
4856 | * |
||
4857 | * @return static |
||
4858 | * <p>(Immutable)</p> |
||
4859 | * |
||
4860 | * @psalm-param T $value |
||
4861 | * @psalm-return static<TKey,T> |
||
4862 | * @psalm-mutation-free |
||
4863 | */ |
||
4864 | 8 | public function removeValue($value): self |
|
4887 | |||
4888 | /** |
||
4889 | * Generate array of repeated arrays. |
||
4890 | * |
||
4891 | * @param int $times <p>How many times has to be repeated.</p> |
||
4892 | * |
||
4893 | * @return static |
||
4894 | * <p>(Immutable)</p> |
||
4895 | * |
||
4896 | * @psalm-return static<TKey,T> |
||
4897 | * @psalm-mutation-free |
||
4898 | */ |
||
4899 | 1 | public function repeat($times): self |
|
4911 | |||
4912 | /** |
||
4913 | * Replace a key with a new key/value pair. |
||
4914 | * |
||
4915 | * @param mixed $oldKey |
||
4916 | * @param mixed $newKey |
||
4917 | * @param mixed $newValue |
||
4918 | * |
||
4919 | * @return static |
||
4920 | * <p>(Immutable)</p> |
||
4921 | * |
||
4922 | * @psalm-return static<TKey,T> |
||
4923 | * @psalm-mutation-free |
||
4924 | */ |
||
4925 | 5 | public function replace($oldKey, $newKey, $newValue): self |
|
4935 | |||
4936 | /** |
||
4937 | * Create an array using the current array as values and the other array as keys. |
||
4938 | * |
||
4939 | * @param array $keys <p>An array of keys.</p> |
||
4940 | * |
||
4941 | * @return static |
||
4942 | * <p>(Immutable) Arrayy object with keys from the other array.</p> |
||
4943 | * |
||
4944 | * @psalm-param array<mixed,mixed>|array<mixed,TKey> $keys |
||
4945 | * @psalm-return static<TKey,T> |
||
4946 | * @psalm-mutation-free |
||
4947 | */ |
||
4948 | 2 | public function replaceAllKeys(array $keys): self |
|
4956 | |||
4957 | /** |
||
4958 | * Create an array using the current array as keys and the other array as values. |
||
4959 | * |
||
4960 | * @param array $array <p>An array o values.</p> |
||
4961 | * |
||
4962 | * @return static |
||
4963 | * <p>(Immutable) Arrayy object with values from the other array.</p> |
||
4964 | * |
||
4965 | * @psalm-param array<mixed,T> $array |
||
4966 | * @psalm-return static<TKey,T> |
||
4967 | * @psalm-mutation-free |
||
4968 | */ |
||
4969 | 2 | public function replaceAllValues(array $array): self |
|
4977 | |||
4978 | /** |
||
4979 | * Replace the keys in an array with another set. |
||
4980 | * |
||
4981 | * @param array $keys <p>An array of keys matching the array's size</p> |
||
4982 | * |
||
4983 | * @return static |
||
4984 | * <p>(Immutable)</p> |
||
4985 | * |
||
4986 | * @psalm-param array<mixed,mixed>|array<mixed,TKey> $keys |
||
4987 | * @psalm-return static<TKey,T> |
||
4988 | * @psalm-mutation-free |
||
4989 | */ |
||
4990 | 1 | public function replaceKeys(array $keys): self |
|
5001 | |||
5002 | /** |
||
5003 | * Replace the first matched value in an array. |
||
5004 | * |
||
5005 | * @param mixed $search <p>The value to replace.</p> |
||
5006 | * @param mixed $replacement <p>The value to replace.</p> |
||
5007 | * |
||
5008 | * @return static |
||
5009 | * <p>(Immutable)</p> |
||
5010 | * |
||
5011 | * @psalm-return static<TKey,T> |
||
5012 | * @psalm-mutation-free |
||
5013 | */ |
||
5014 | 3 | View Code Duplication | public function replaceOneValue($search, $replacement = ''): self |
5029 | |||
5030 | /** |
||
5031 | * Replace values in the current array. |
||
5032 | * |
||
5033 | * @param mixed $search <p>The value to replace.</p> |
||
5034 | * @param mixed $replacement <p>What to replace it with.</p> |
||
5035 | * |
||
5036 | * @return static |
||
5037 | * <p>(Immutable)</p> |
||
5038 | * |
||
5039 | * @psalm-return static<TKey,T> |
||
5040 | * @psalm-mutation-free |
||
5041 | */ |
||
5042 | 1 | public function replaceValues($search, $replacement = ''): self |
|
5054 | |||
5055 | /** |
||
5056 | * Get the last elements from index $from until the end of this array. |
||
5057 | * |
||
5058 | * @param int $from |
||
5059 | * |
||
5060 | * @return static |
||
5061 | * <p>(Immutable)</p> |
||
5062 | * |
||
5063 | * @psalm-return static<TKey,T> |
||
5064 | * @psalm-mutation-free |
||
5065 | */ |
||
5066 | 15 | View Code Duplication | public function rest(int $from = 1): self |
5076 | |||
5077 | /** |
||
5078 | * Return the array in the reverse order. |
||
5079 | * |
||
5080 | * @return $this |
||
5081 | * <p>(Mutable) Return this Arrayy object.</p> |
||
5082 | * |
||
5083 | * @psalm-return static<TKey,T> |
||
5084 | */ |
||
5085 | 9 | public function reverse(): self |
|
5093 | |||
5094 | /** |
||
5095 | * Sort an array in reverse order. |
||
5096 | * |
||
5097 | * @param int $sort_flags [optional] <p> |
||
5098 | * You may modify the behavior of the sort using the optional |
||
5099 | * parameter sort_flags, for details |
||
5100 | * see sort. |
||
5101 | * </p> |
||
5102 | * |
||
5103 | * @return $this |
||
5104 | * <p>(Mutable) Return this Arrayy object.</p> |
||
5105 | * |
||
5106 | * @psalm-return static<TKey,T> |
||
5107 | */ |
||
5108 | 4 | public function rsort(int $sort_flags = 0): self |
|
5116 | |||
5117 | /** |
||
5118 | * Sort an array in reverse order. |
||
5119 | * |
||
5120 | * @param int $sort_flags [optional] <p> |
||
5121 | * You may modify the behavior of the sort using the optional |
||
5122 | * parameter sort_flags, for details |
||
5123 | * see sort. |
||
5124 | * </p> |
||
5125 | * |
||
5126 | * @return $this |
||
5127 | * <p>(Immutable) Return this Arrayy object.</p> |
||
5128 | * |
||
5129 | * @psalm-return static<TKey,T> |
||
5130 | * @psalm-mutation-free |
||
5131 | */ |
||
5132 | 4 | public function rsortImmutable(int $sort_flags = 0): self |
|
5143 | |||
5144 | /** |
||
5145 | * Search for the first index of the current array via $value. |
||
5146 | * |
||
5147 | * @param mixed $value |
||
5148 | * |
||
5149 | * @return false|float|int|string |
||
5150 | * <p>Will return <b>FALSE</b> if the value can't be found.</p> |
||
5151 | * @psalm-mutation-free |
||
5152 | */ |
||
5153 | 21 | public function searchIndex($value) |
|
5163 | |||
5164 | /** |
||
5165 | * Search for the value of the current array via $index. |
||
5166 | * |
||
5167 | * @param mixed $index |
||
5168 | * |
||
5169 | * @return static |
||
5170 | * <p>(Immutable) Will return a empty Arrayy if the value wasn't found.</p> |
||
5171 | * |
||
5172 | * @psalm-return static<TKey,T> |
||
5173 | * @psalm-mutation-free |
||
5174 | */ |
||
5175 | 9 | public function searchValue($index): self |
|
5205 | |||
5206 | /** |
||
5207 | * Set a value for the current array (optional using dot-notation). |
||
5208 | * |
||
5209 | * @param string $key <p>The key to set.</p> |
||
5210 | * @param mixed $value <p>Its value.</p> |
||
5211 | * |
||
5212 | * @return $this |
||
5213 | * <p>(Mutable) Return this Arrayy object.</p> |
||
5214 | * |
||
5215 | * @psalm-param TKey $key |
||
5216 | * @psalm-param T $value |
||
5217 | * @psalm-return static<TKey,T> |
||
5218 | */ |
||
5219 | 28 | public function set($key, $value): self |
|
5225 | |||
5226 | /** |
||
5227 | * Get a value from a array and set it if it was not. |
||
5228 | * |
||
5229 | * WARNING: this method only set the value, if the $key is not already set |
||
5230 | * |
||
5231 | * @param mixed $key <p>The key</p> |
||
5232 | * @param mixed $fallback <p>The default value to set if it isn't.</p> |
||
5233 | * |
||
5234 | * @return mixed |
||
5235 | * <p>(Mutable)</p> |
||
5236 | */ |
||
5237 | 11 | public function setAndGet($key, $fallback = null) |
|
5248 | |||
5249 | /** |
||
5250 | * Shifts a specified value off the beginning of array. |
||
5251 | * |
||
5252 | * @return mixed |
||
5253 | * <p>(Mutable) A shifted element from the current array.</p> |
||
5254 | */ |
||
5255 | 5 | public function shift() |
|
5261 | |||
5262 | /** |
||
5263 | * Shuffle the current array. |
||
5264 | * |
||
5265 | * @param bool $secure <p>using a CSPRNG | @link https://paragonie.com/b/JvICXzh_jhLyt4y3</p> |
||
5266 | * @param array $array [optional] |
||
5267 | * |
||
5268 | * @return static |
||
5269 | * <p>(Immutable)</p> |
||
5270 | * |
||
5271 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
5272 | * @psalm-return static<TKey,T> |
||
5273 | * |
||
5274 | * @noinspection BadExceptionsProcessingInspection |
||
5275 | * @noinspection RandomApiMigrationInspection |
||
5276 | * @noinspection NonSecureShuffleUsageInspection |
||
5277 | */ |
||
5278 | 2 | public function shuffle(bool $secure = false, array $array = null): self |
|
5279 | { |
||
5280 | 2 | if ($array === null) { |
|
5281 | 2 | $array = $this->toArray(false); |
|
5282 | } |
||
5283 | |||
5284 | 2 | if ($secure !== true) { |
|
5285 | 2 | \shuffle($array); |
|
5286 | } else { |
||
5287 | 1 | $size = \count($array, \COUNT_NORMAL); |
|
5288 | 1 | $keys = \array_keys($array); |
|
5289 | 1 | for ($i = $size - 1; $i > 0; --$i) { |
|
5290 | try { |
||
5291 | 1 | $r = \random_int(0, $i); |
|
5292 | } catch (\Exception $e) { |
||
5293 | $r = \mt_rand(0, $i); |
||
5294 | } |
||
5295 | 1 | if ($r !== $i) { |
|
5296 | $temp = $array[$keys[$r]]; |
||
5297 | $array[$keys[$r]] = $array[$keys[$i]]; |
||
5298 | $array[$keys[$i]] = $temp; |
||
5299 | } |
||
5300 | } |
||
5301 | } |
||
5302 | |||
5303 | 2 | foreach ($array as $key => $value) { |
|
5304 | // check if recursive is needed |
||
5305 | 2 | if (\is_array($value) === true) { |
|
5306 | $array[$key] = $this->shuffle($secure, $value); |
||
5307 | } |
||
5308 | } |
||
5309 | |||
5310 | 2 | return static::create( |
|
5311 | 2 | $array, |
|
5312 | 2 | $this->iteratorClass, |
|
5313 | 2 | false |
|
5314 | ); |
||
5315 | } |
||
5316 | |||
5317 | /** |
||
5318 | * Count the values from the current array. |
||
5319 | * |
||
5320 | * alias: for "Arrayy->count()" |
||
5321 | * |
||
5322 | * @param int $mode |
||
5323 | * |
||
5324 | * @return int |
||
5325 | */ |
||
5326 | 20 | public function size(int $mode = \COUNT_NORMAL): int |
|
5330 | |||
5331 | /** |
||
5332 | * Checks whether array has exactly $size items. |
||
5333 | * |
||
5334 | * @param int $size |
||
5335 | * |
||
5336 | * @return bool |
||
5337 | */ |
||
5338 | 1 | public function sizeIs(int $size): bool |
|
5354 | |||
5355 | /** |
||
5356 | * Checks whether array has between $fromSize to $toSize items. $toSize can be |
||
5357 | * smaller than $fromSize. |
||
5358 | * |
||
5359 | * @param int $fromSize |
||
5360 | * @param int $toSize |
||
5361 | * |
||
5362 | * @return bool |
||
5363 | */ |
||
5364 | 1 | public function sizeIsBetween(int $fromSize, int $toSize): bool |
|
5384 | |||
5385 | /** |
||
5386 | * Checks whether array has more than $size items. |
||
5387 | * |
||
5388 | * @param int $size |
||
5389 | * |
||
5390 | * @return bool |
||
5391 | */ |
||
5392 | 1 | View Code Duplication | public function sizeIsGreaterThan(int $size): bool |
5406 | |||
5407 | /** |
||
5408 | * Checks whether array has less than $size items. |
||
5409 | * |
||
5410 | * @param int $size |
||
5411 | * |
||
5412 | * @return bool |
||
5413 | */ |
||
5414 | 1 | View Code Duplication | public function sizeIsLessThan(int $size): bool |
5428 | |||
5429 | /** |
||
5430 | * Counts all elements in an array, or something in an object. |
||
5431 | * |
||
5432 | * <p> |
||
5433 | * For objects, if you have SPL installed, you can hook into count() by implementing interface {@see Countable}. |
||
5434 | * The interface has exactly one method, {@see Countable::count()}, which returns the return value for the count() |
||
5435 | * function. Please see the {@see Array} section of the manual for a detailed explanation of how arrays are |
||
5436 | * implemented and used in PHP. |
||
5437 | * </p> |
||
5438 | * |
||
5439 | * @return int |
||
5440 | * <p> |
||
5441 | * The number of elements in var, which is |
||
5442 | * typically an array, since anything else will have one |
||
5443 | * element. |
||
5444 | * </p> |
||
5445 | * <p> |
||
5446 | * If var is not an array or an object with |
||
5447 | * implemented Countable interface, |
||
5448 | * 1 will be returned. |
||
5449 | * There is one exception, if var is &null;, |
||
5450 | * 0 will be returned. |
||
5451 | * </p> |
||
5452 | * <p> |
||
5453 | * Caution: count may return 0 for a variable that isn't set, |
||
5454 | * but it may also return 0 for a variable that has been initialized with an |
||
5455 | * empty array. Use isset to test if a variable is set. |
||
5456 | * </p> |
||
5457 | */ |
||
5458 | 10 | public function sizeRecursive(): int |
|
5462 | |||
5463 | /** |
||
5464 | * Extract a slice of the array. |
||
5465 | * |
||
5466 | * @param int $offset <p>Slice begin index.</p> |
||
5467 | * @param int|null $length <p>Length of the slice.</p> |
||
5468 | * @param bool $preserveKeys <p>Whether array keys are preserved or no.</p> |
||
5469 | * |
||
5470 | * @return static |
||
5471 | * <p>(Immutable) A slice of the original array with length $length.</p> |
||
5472 | * |
||
5473 | * @psalm-return static<TKey,T> |
||
5474 | * @psalm-mutation-free |
||
5475 | */ |
||
5476 | 5 | public function slice(int $offset, int $length = null, bool $preserveKeys = false) |
|
5489 | |||
5490 | /** |
||
5491 | * Sort the current array and optional you can keep the keys. |
||
5492 | * |
||
5493 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
5494 | * @param int $strategy <p>sort_flags => use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
5495 | * <strong>SORT_NATURAL</strong></p> |
||
5496 | * @param bool $keepKeys |
||
5497 | * |
||
5498 | * @return static |
||
5499 | * <p>(Mutable) Return this Arrayy object.</p> |
||
5500 | * |
||
5501 | * @psalm-return static<TKey,T> |
||
5502 | */ |
||
5503 | 20 | public function sort( |
|
5517 | |||
5518 | /** |
||
5519 | * Sort the current array and optional you can keep the keys. |
||
5520 | * |
||
5521 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
5522 | * @param int $strategy <p>sort_flags => use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
5523 | * <strong>SORT_NATURAL</strong></p> |
||
5524 | * @param bool $keepKeys |
||
5525 | * |
||
5526 | * @return static |
||
5527 | * <p>(Immutable) Return this Arrayy object.</p> |
||
5528 | * |
||
5529 | * @psalm-return static<TKey,T> |
||
5530 | */ |
||
5531 | 12 | public function sortImmutable( |
|
5547 | |||
5548 | /** |
||
5549 | * Sort the current array by key. |
||
5550 | * |
||
5551 | * @see http://php.net/manual/en/function.ksort.php |
||
5552 | * @see http://php.net/manual/en/function.krsort.php |
||
5553 | * |
||
5554 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
5555 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
5556 | * <strong>SORT_NATURAL</strong></p> |
||
5557 | * |
||
5558 | * @return $this |
||
5559 | * <p>(Mutable) Return this Arrayy object.</p> |
||
5560 | * |
||
5561 | * @psalm-return static<TKey,T> |
||
5562 | */ |
||
5563 | 18 | public function sortKeys( |
|
5573 | |||
5574 | /** |
||
5575 | * Sort the current array by key. |
||
5576 | * |
||
5577 | * @see http://php.net/manual/en/function.ksort.php |
||
5578 | * @see http://php.net/manual/en/function.krsort.php |
||
5579 | * |
||
5580 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
5581 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
5582 | * <strong>SORT_NATURAL</strong></p> |
||
5583 | * |
||
5584 | * @return $this |
||
5585 | * <p>(Immutable) Return this Arrayy object.</p> |
||
5586 | * |
||
5587 | * @psalm-return static<TKey,T> |
||
5588 | * @psalm-mutation-free |
||
5589 | */ |
||
5590 | 8 | public function sortKeysImmutable( |
|
5603 | |||
5604 | /** |
||
5605 | * Sort the current array by value. |
||
5606 | * |
||
5607 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
5608 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
5609 | * <strong>SORT_NATURAL</strong></p> |
||
5610 | * |
||
5611 | * @return static |
||
5612 | * <p>(Mutable)</p> |
||
5613 | * |
||
5614 | * @psalm-return static<TKey,T> |
||
5615 | */ |
||
5616 | 1 | public function sortValueKeepIndex( |
|
5622 | |||
5623 | /** |
||
5624 | * Sort the current array by value. |
||
5625 | * |
||
5626 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
5627 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
5628 | * <strong>SORT_NATURAL</strong></p> |
||
5629 | * |
||
5630 | * @return static |
||
5631 | * <p>(Mutable)</p> |
||
5632 | * |
||
5633 | * @psalm-return static<TKey,T> |
||
5634 | */ |
||
5635 | 1 | public function sortValueNewIndex($direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
5639 | |||
5640 | /** |
||
5641 | * Sort a array by value, by a closure or by a property. |
||
5642 | * |
||
5643 | * - If the sorter is null, the array is sorted naturally. |
||
5644 | * - Associative (string) keys will be maintained, but numeric keys will be re-indexed. |
||
5645 | * |
||
5646 | * @param callable|string|null $sorter |
||
5647 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or |
||
5648 | * <strong>SORT_DESC</strong></p> |
||
5649 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
5650 | * <strong>SORT_NATURAL</strong></p> |
||
5651 | * |
||
5652 | * @return static |
||
5653 | * <p>(Immutable)</p> |
||
5654 | * |
||
5655 | * @psalm-return static<TKey,T> |
||
5656 | * @psalm-mutation-free |
||
5657 | */ |
||
5658 | 1 | public function sorter($sorter = null, $direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
5699 | |||
5700 | /** |
||
5701 | * @param int $offset |
||
5702 | * @param int|null $length |
||
5703 | * @param array $replacement |
||
5704 | * |
||
5705 | * @return static |
||
5706 | * <p>(Immutable)</p> |
||
5707 | * |
||
5708 | * @psalm-param array<mixed,mixed>|array<mixed,T> $replacement |
||
5709 | * @psalm-return static<TKey,T> |
||
5710 | * @psalm-mutation-free |
||
5711 | */ |
||
5712 | 1 | public function splice(int $offset, int $length = null, $replacement = []): self |
|
5729 | |||
5730 | /** |
||
5731 | * Split an array in the given amount of pieces. |
||
5732 | * |
||
5733 | * @param int $numberOfPieces |
||
5734 | * @param bool $keepKeys |
||
5735 | * |
||
5736 | * @return static |
||
5737 | * <p>(Immutable)</p> |
||
5738 | * |
||
5739 | * @psalm-return static<TKey,T> |
||
5740 | * @psalm-mutation-free |
||
5741 | */ |
||
5742 | 1 | public function split(int $numberOfPieces = 2, bool $keepKeys = false): self |
|
5761 | |||
5762 | /** |
||
5763 | * Stripe all empty items. |
||
5764 | * |
||
5765 | * @return static |
||
5766 | * <p>(Immutable)</p> |
||
5767 | * |
||
5768 | * @psalm-return static<TKey,T> |
||
5769 | * @psalm-mutation-free |
||
5770 | */ |
||
5771 | 1 | public function stripEmpty(): self |
|
5783 | |||
5784 | /** |
||
5785 | * Swap two values between positions by key. |
||
5786 | * |
||
5787 | * @param int|string $swapA <p>a key in the array</p> |
||
5788 | * @param int|string $swapB <p>a key in the array</p> |
||
5789 | * |
||
5790 | * @return static |
||
5791 | * <p>(Immutable)</p> |
||
5792 | * |
||
5793 | * @psalm-return static<TKey,T> |
||
5794 | * @psalm-mutation-free |
||
5795 | */ |
||
5796 | 1 | public function swap($swapA, $swapB): self |
|
5808 | |||
5809 | /** |
||
5810 | * Get the current array from the "Arrayy"-object. |
||
5811 | * alias for "getArray()" |
||
5812 | * |
||
5813 | * @param bool $convertAllArrayyElements <p> |
||
5814 | * Convert all Child-"Arrayy" objects also to arrays. |
||
5815 | * </p> |
||
5816 | * @param bool $preserveKeys <p> |
||
5817 | * e.g.: A generator maybe return the same key more then once, |
||
5818 | * so maybe you will ignore the keys. |
||
5819 | * </p> |
||
5820 | * |
||
5821 | * @return array |
||
5822 | * |
||
5823 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
5824 | * @psalm-mutation-free |
||
5825 | */ |
||
5826 | 945 | public function toArray( |
|
5851 | |||
5852 | /** |
||
5853 | * Get the current array from the "Arrayy"-object as list. |
||
5854 | * |
||
5855 | * @param bool $convertAllArrayyElements <p> |
||
5856 | * Convert all Child-"Arrayy" objects also to arrays. |
||
5857 | * </p> |
||
5858 | * |
||
5859 | * @return array |
||
5860 | * |
||
5861 | * @psalm-return list<array<TKey,T>> |
||
5862 | * @psalm-mutation-free |
||
5863 | */ |
||
5864 | 1 | public function toList(bool $convertAllArrayyElements = false): array |
|
5871 | |||
5872 | /** |
||
5873 | * Convert the current array to JSON. |
||
5874 | * |
||
5875 | * @param int $options [optional] <p>e.g. JSON_PRETTY_PRINT</p> |
||
5876 | * @param int $depth [optional] <p>Set the maximum depth. Must be greater than zero.</p> |
||
5877 | * |
||
5878 | * @return string |
||
5879 | */ |
||
5880 | 12 | public function toJson(int $options = 0, int $depth = 512): string |
|
5889 | |||
5890 | /** |
||
5891 | * @param string[]|null $items [optional] |
||
5892 | * @param string[] $helper [optional] |
||
5893 | * |
||
5894 | * @return static|static[] |
||
5895 | * |
||
5896 | * @psalm-return static<int, static<TKey,T>> |
||
5897 | */ |
||
5898 | 1 | public function toPermutation(array $items = null, array $helper = []): self |
|
5932 | |||
5933 | /** |
||
5934 | * Implodes array to a string with specified separator. |
||
5935 | * |
||
5936 | * @param string $separator [optional] <p>The element's separator.</p> |
||
5937 | * |
||
5938 | * @return string |
||
5939 | * <p>The string representation of array, separated by ",".</p> |
||
5940 | */ |
||
5941 | 19 | public function toString(string $separator = ','): string |
|
5945 | |||
5946 | /** |
||
5947 | * Return a duplicate free copy of the current array. |
||
5948 | * |
||
5949 | * @return $this |
||
5950 | * <p>(Mutable)</p> |
||
5951 | * |
||
5952 | * @psalm-return static<TKey,T> |
||
5953 | */ |
||
5954 | 13 | public function unique(): self |
|
5976 | |||
5977 | /** |
||
5978 | * Return a duplicate free copy of the current array. (with the old keys) |
||
5979 | * |
||
5980 | * @return $this |
||
5981 | * <p>(Mutable)</p> |
||
5982 | * |
||
5983 | * @psalm-return static<TKey,T> |
||
5984 | */ |
||
5985 | 11 | public function uniqueKeepIndex(): self |
|
6011 | |||
6012 | /** |
||
6013 | * alias: for "Arrayy->unique()" |
||
6014 | * |
||
6015 | * @return static |
||
6016 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
6017 | * |
||
6018 | * @see Arrayy::unique() |
||
6019 | * |
||
6020 | * @psalm-return static<TKey,T> |
||
6021 | */ |
||
6022 | 10 | public function uniqueNewIndex(): self |
|
6026 | |||
6027 | /** |
||
6028 | * Prepends one or more values to the beginning of array at once. |
||
6029 | * |
||
6030 | * @param array ...$args |
||
6031 | * |
||
6032 | * @return $this |
||
6033 | * <p>(Mutable) Return this Arrayy object, with prepended elements to the beginning of array.</p> |
||
6034 | * |
||
6035 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$args |
||
6036 | * @psalm-return static<TKey,T> |
||
6037 | */ |
||
6038 | 4 | public function unshift(...$args): self |
|
6046 | |||
6047 | /** |
||
6048 | * Tests whether the given closure return something valid for all elements of this array. |
||
6049 | * |
||
6050 | * @param \Closure $closure the predicate |
||
6051 | * |
||
6052 | * @return bool |
||
6053 | * <p>TRUE, if the predicate yields TRUE for all elements, FALSE otherwise.</p> |
||
6054 | */ |
||
6055 | 1 | View Code Duplication | public function validate(\Closure $closure): bool |
6065 | |||
6066 | /** |
||
6067 | * Get all values from a array. |
||
6068 | * |
||
6069 | * @return static |
||
6070 | * <p>(Immutable)</p> |
||
6071 | * |
||
6072 | * @psalm-return static<TKey,T> |
||
6073 | * @psalm-mutation-free |
||
6074 | */ |
||
6075 | 2 | public function values(): self |
|
6088 | |||
6089 | /** |
||
6090 | * Apply the given function to every element in the array, discarding the results. |
||
6091 | * |
||
6092 | * @param callable $callable |
||
6093 | * @param bool $recursive [optional] <p>Whether array will be walked recursively or no</p> |
||
6094 | * @param mixed $userData [optional] <p> |
||
6095 | * If the optional $userData parameter is supplied, |
||
6096 | * it will be passed as the third parameter to the $callable. |
||
6097 | * </p> |
||
6098 | * |
||
6099 | * @return $this |
||
6100 | * <p>(Mutable) Return this Arrayy object, with modified elements.</p> |
||
6101 | * |
||
6102 | * @psalm-return static<TKey,T> |
||
6103 | */ |
||
6104 | 12 | public function walk($callable, bool $recursive = false, $userData = self::ARRAYY_HELPER_WALK): self |
|
6126 | |||
6127 | /** |
||
6128 | * Returns a collection of matching items. |
||
6129 | * |
||
6130 | * @param string $keyOrPropertyOrMethod the property or method to evaluate |
||
6131 | * @param mixed $value the value to match |
||
6132 | * |
||
6133 | * @throws \InvalidArgumentException if property or method is not defined |
||
6134 | * |
||
6135 | * @return static |
||
6136 | * |
||
6137 | * @psalm-param T $value |
||
6138 | * @psalm-return static<TKey,T> |
||
6139 | */ |
||
6140 | 1 | public function where(string $keyOrPropertyOrMethod, $value): self |
|
6153 | |||
6154 | /** |
||
6155 | * Convert an array into a object. |
||
6156 | * |
||
6157 | * @param array $array |
||
6158 | * |
||
6159 | * @return \stdClass |
||
6160 | * |
||
6161 | * @psalm-param array<mixed,mixed> $array |
||
6162 | */ |
||
6163 | 4 | final protected static function arrayToObject(array $array = []): \stdClass |
|
6182 | |||
6183 | /** |
||
6184 | * @param array|\Generator|null $input <p> |
||
6185 | * An array containing keys to return. |
||
6186 | * </p> |
||
6187 | * @param mixed|null $search_values [optional] <p> |
||
6188 | * If specified, then only keys containing these values are returned. |
||
6189 | * </p> |
||
6190 | * @param bool $strict [optional] <p> |
||
6191 | * Determines if strict comparison (===) should be used during the |
||
6192 | * search. |
||
6193 | * </p> |
||
6194 | * |
||
6195 | * @return array |
||
6196 | * <p>an array of all the keys in input</p> |
||
6197 | * |
||
6198 | * @psalm-param array<mixed,mixed>|\Generator<TKey,T>|null $input |
||
6199 | * @psalm-return array<TKey|mixed> |
||
6200 | * @psalm-mutation-free |
||
6201 | */ |
||
6202 | 11 | protected function array_keys_recursive( |
|
6263 | |||
6264 | /** |
||
6265 | * @param mixed $path |
||
6266 | * @param callable $callable |
||
6267 | * @param array|null $currentOffset |
||
6268 | * |
||
6269 | * @return void |
||
6270 | * |
||
6271 | * @psalm-param array<mixed,mixed>|array<TKey,T>|null $currentOffset |
||
6272 | * @psalm-mutation-free |
||
6273 | */ |
||
6274 | 9 | protected function callAtPath($path, $callable, &$currentOffset = null) |
|
6275 | { |
||
6276 | 9 | $this->generatorToArray(); |
|
6277 | |||
6278 | 9 | if ($currentOffset === null) { |
|
6279 | 9 | $currentOffset = &$this->array; |
|
6280 | } |
||
6281 | |||
6282 | 9 | $explodedPath = \explode($this->pathSeparator, $path); |
|
6283 | 9 | if ($explodedPath === false) { |
|
6284 | return; |
||
6285 | } |
||
6286 | |||
6287 | 9 | $nextPath = \array_shift($explodedPath); |
|
6288 | |||
6289 | 9 | if (!isset($currentOffset[$nextPath])) { |
|
6290 | 1 | return; |
|
6291 | } |
||
6292 | |||
6293 | 8 | if (!empty($explodedPath)) { |
|
6294 | $this->callAtPath( |
||
6295 | \implode($this->pathSeparator, $explodedPath), |
||
6296 | $callable, |
||
6297 | $currentOffset[$nextPath] |
||
6298 | ); |
||
6299 | } else { |
||
6300 | 8 | $callable($currentOffset[$nextPath]); |
|
6301 | } |
||
6302 | 8 | } |
|
6303 | |||
6304 | /** |
||
6305 | * Extracts the value of the given property or method from the object. |
||
6306 | * |
||
6307 | * @param static $object <p>The object to extract the value from.</p> |
||
6308 | * @param string $keyOrPropertyOrMethod <p>The property or method for which the |
||
6309 | * value should be extracted.</p> |
||
6310 | * |
||
6311 | * @throws \InvalidArgumentException if the method or property is not defined |
||
6312 | * |
||
6313 | * @return mixed |
||
6314 | * <p>The value extracted from the specified property or method.</p> |
||
6315 | * |
||
6316 | * @psalm-param self<TKey,T> $object |
||
6317 | */ |
||
6318 | 2 | final protected function extractValue(self $object, string $keyOrPropertyOrMethod) |
|
6340 | |||
6341 | /** |
||
6342 | * create a fallback for array |
||
6343 | * |
||
6344 | * 1. use the current array, if it's a array |
||
6345 | * 2. fallback to empty array, if there is nothing |
||
6346 | * 3. call "getArray()" on object, if there is a "Arrayy"-object |
||
6347 | * 4. call "createFromObject()" on object, if there is a "\Traversable"-object |
||
6348 | * 5. call "__toArray()" on object, if the method exists |
||
6349 | * 6. cast a string or object with "__toString()" into an array |
||
6350 | * 7. throw a "InvalidArgumentException"-Exception |
||
6351 | * |
||
6352 | * @param mixed $data |
||
6353 | * |
||
6354 | * @throws \InvalidArgumentException |
||
6355 | * |
||
6356 | * @return array |
||
6357 | * |
||
6358 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
6359 | */ |
||
6360 | 1198 | protected function fallbackForArray(&$data): array |
|
6370 | |||
6371 | /** |
||
6372 | * @param bool $preserveKeys <p> |
||
6373 | * e.g.: A generator maybe return the same key more then once, |
||
6374 | * so maybe you will ignore the keys. |
||
6375 | * </p> |
||
6376 | * |
||
6377 | * @return bool |
||
6378 | * |
||
6379 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
6380 | * @psalm-mutation-free :/ |
||
6381 | */ |
||
6382 | 1110 | protected function generatorToArray(bool $preserveKeys = true) |
|
6393 | |||
6394 | /** |
||
6395 | * Get correct PHP constant for direction. |
||
6396 | * |
||
6397 | * @param int|string $direction |
||
6398 | * |
||
6399 | * @return int |
||
6400 | * @psalm-mutation-free |
||
6401 | */ |
||
6402 | 43 | protected function getDirection($direction): int |
|
6424 | |||
6425 | /** |
||
6426 | * @return TypeCheckInterface[] |
||
6427 | * |
||
6428 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
6429 | */ |
||
6430 | 22 | protected function getPropertiesFromPhpDoc() |
|
6461 | |||
6462 | /** |
||
6463 | * @param mixed $glue |
||
6464 | * @param mixed $pieces |
||
6465 | * @param bool $useKeys |
||
6466 | * |
||
6467 | * @return string |
||
6468 | * @psalm-mutation-free |
||
6469 | */ |
||
6470 | 36 | protected function implode_recursive( |
|
6503 | |||
6504 | /** |
||
6505 | * @param mixed $needle <p> |
||
6506 | * The searched value. |
||
6507 | * </p> |
||
6508 | * <p> |
||
6509 | * If needle is a string, the comparison is done |
||
6510 | * in a case-sensitive manner. |
||
6511 | * </p> |
||
6512 | * @param array|\Generator|null $haystack <p> |
||
6513 | * The array. |
||
6514 | * </p> |
||
6515 | * @param bool $strict [optional] <p> |
||
6516 | * If the third parameter strict is set to true |
||
6517 | * then the in_array function will also check the |
||
6518 | * types of the |
||
6519 | * needle in the haystack. |
||
6520 | * </p> |
||
6521 | * |
||
6522 | * @return bool |
||
6523 | * <p>true if needle is found in the array, false otherwise</p> |
||
6524 | * |
||
6525 | * @psalm-param array<mixed,mixed>|\Generator<TKey,T>|null $haystack |
||
6526 | * @psalm-mutation-free |
||
6527 | */ |
||
6528 | 18 | protected function in_array_recursive($needle, $haystack = null, $strict = true): bool |
|
6553 | |||
6554 | /** |
||
6555 | * @param mixed $data |
||
6556 | * |
||
6557 | * @return array|null |
||
6558 | * |
||
6559 | * @psalm-return array<mixed,mixed>|array<TKey,T>|null |
||
6560 | */ |
||
6561 | 1198 | protected function internalGetArray(&$data) |
|
6612 | |||
6613 | /** |
||
6614 | * Internal mechanics of remove method. |
||
6615 | * |
||
6616 | * @param mixed $key |
||
6617 | * |
||
6618 | * @return bool |
||
6619 | */ |
||
6620 | 21 | protected function internalRemove($key): bool |
|
6653 | |||
6654 | /** |
||
6655 | * Internal mechanic of set method. |
||
6656 | * |
||
6657 | * @param int|string|null $key |
||
6658 | * @param mixed $value |
||
6659 | * @param bool $checkProperties |
||
6660 | * |
||
6661 | * @return bool |
||
6662 | */ |
||
6663 | 1048 | protected function internalSet( |
|
6724 | |||
6725 | /** |
||
6726 | * Convert a object into an array. |
||
6727 | * |
||
6728 | * @param mixed|object $object |
||
6729 | * |
||
6730 | * @return array|mixed |
||
6731 | * |
||
6732 | * @psalm-mutation-free |
||
6733 | */ |
||
6734 | 5 | protected static function objectToArray($object) |
|
6747 | |||
6748 | /** |
||
6749 | * @param array $data |
||
6750 | * @param bool $checkPropertiesInConstructor |
||
6751 | * |
||
6752 | * @return void |
||
6753 | * |
||
6754 | * @psalm-param array<mixed,T> $data |
||
6755 | */ |
||
6756 | 1196 | protected function setInitialValuesAndProperties(array &$data, bool $checkPropertiesInConstructor) |
|
6801 | |||
6802 | /** |
||
6803 | * sorting keys |
||
6804 | * |
||
6805 | * @param array $elements |
||
6806 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
6807 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
6808 | * <strong>SORT_NATURAL</strong></p> |
||
6809 | * |
||
6810 | * @return $this |
||
6811 | * <p>(Mutable) Return this Arrayy object.</p> |
||
6812 | * |
||
6813 | * @psalm-param array<mixed,mixed>|array<mixed|TKey,T> $elements |
||
6814 | * @psalm-return static<TKey,T> |
||
6815 | */ |
||
6816 | 18 | protected function sorterKeys( |
|
6837 | |||
6838 | /** |
||
6839 | * @param array $elements <p>Warning: used as reference</p> |
||
6840 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
6841 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
6842 | * <strong>SORT_NATURAL</strong></p> |
||
6843 | * @param bool $keepKeys |
||
6844 | * |
||
6845 | * @return $this |
||
6846 | * <p>(Mutable) Return this Arrayy object.</p> |
||
6847 | * |
||
6848 | * @psalm-param array<mixed,mixed>|array<mixed|TKey,T> $elements |
||
6849 | * @psalm-return static<TKey,T> |
||
6850 | */ |
||
6851 | 24 | protected function sorting(array &$elements, $direction = \SORT_ASC, int $strategy = \SORT_REGULAR, bool $keepKeys = false): self |
|
6881 | |||
6882 | /** |
||
6883 | * @param array $array |
||
6884 | * |
||
6885 | * @return array |
||
6886 | * |
||
6887 | * @psalm-mutation-free |
||
6888 | */ |
||
6889 | 25 | private function getArrayRecursiveHelperArrayy(array $array) |
|
6911 | |||
6912 | /** |
||
6913 | * @param int|string|null $key |
||
6914 | * @param mixed $value |
||
6915 | * |
||
6916 | * @return void |
||
6917 | */ |
||
6918 | 109 | private function checkType($key, $value) |
|
6936 | } |
||
6937 |
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..