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 | 1203 | 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 | 128 | 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>(Immutable) Return this Arrayy object, with the appended values.</p> |
||
227 | * |
||
228 | * @psalm-param T $value |
||
229 | * @psalm-return static<TKey,T> |
||
230 | * |
||
231 | * @psalm-mutation-free |
||
232 | */ |
||
233 | 13 | public function add($value, $key = null) |
|
251 | |||
252 | /** |
||
253 | * Append a (key) + value to the current array. |
||
254 | * |
||
255 | * EXAMPLE: <code> |
||
256 | * a(['fòô' => 'bàř'])->append('foo'); // Arrayy['fòô' => 'bàř', 0 => 'foo'] |
||
257 | * </code> |
||
258 | * |
||
259 | * @param mixed $value |
||
260 | * @param mixed $key |
||
261 | * |
||
262 | * @return $this |
||
263 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
264 | * |
||
265 | * @psalm-return static<TKey,T> |
||
266 | */ |
||
267 | 20 | public function append($value, $key = null): self |
|
291 | |||
292 | /** |
||
293 | * Append a (key) + value to the current array. |
||
294 | * |
||
295 | * EXAMPLE: <code> |
||
296 | * a(['fòô' => 'bàř'])->appendImmutable('foo')->getArray(); // ['fòô' => 'bàř', 0 => 'foo'] |
||
297 | * </code> |
||
298 | * |
||
299 | * @param mixed $value |
||
300 | * @param mixed $key |
||
301 | * |
||
302 | * @return $this |
||
303 | * <p>(Immutable) Return this Arrayy object, with the appended values.</p> |
||
304 | * |
||
305 | * @psalm-return static<TKey,T> |
||
306 | * @psalm-mutation-free |
||
307 | */ |
||
308 | 1 | View Code Duplication | public function appendImmutable($value, $key = null): self |
333 | |||
334 | /** |
||
335 | * Sort the entries by value. |
||
336 | * |
||
337 | * @param int $sort_flags [optional] <p> |
||
338 | * You may modify the behavior of the sort using the optional |
||
339 | * parameter sort_flags, for details |
||
340 | * see sort. |
||
341 | * </p> |
||
342 | * |
||
343 | * @return $this |
||
344 | * <p>(Mutable) Return this Arrayy object.</p> |
||
345 | * |
||
346 | * @psalm-return static<TKey,T> |
||
347 | */ |
||
348 | 4 | public function asort(int $sort_flags = 0): self |
|
356 | |||
357 | /** |
||
358 | * Sort the entries by value. |
||
359 | * |
||
360 | * @param int $sort_flags [optional] <p> |
||
361 | * You may modify the behavior of the sort using the optional |
||
362 | * parameter sort_flags, for details |
||
363 | * see sort. |
||
364 | * </p> |
||
365 | * |
||
366 | * @return $this |
||
367 | * <p>(Immutable) Return this Arrayy object.</p> |
||
368 | * |
||
369 | * @psalm-return static<TKey,T> |
||
370 | * @psalm-mutation-free |
||
371 | */ |
||
372 | 4 | public function asortImmutable(int $sort_flags = 0): self |
|
383 | |||
384 | /** |
||
385 | * Counts all elements in an array, or something in an object. |
||
386 | * |
||
387 | * <p> |
||
388 | * For objects, if you have SPL installed, you can hook into count() by implementing interface {@see Countable}. |
||
389 | * The interface has exactly one method, {@see Countable::count()}, which returns the return value for the count() |
||
390 | * function. Please see the {@see Array} section of the manual for a detailed explanation of how arrays are |
||
391 | * implemented and used in PHP. |
||
392 | * </p> |
||
393 | * |
||
394 | * @see http://php.net/manual/en/function.count.php |
||
395 | * |
||
396 | * @param int $mode [optional] If the optional mode parameter is set to |
||
397 | * COUNT_RECURSIVE (or 1), count |
||
398 | * will recursively count the array. This is particularly useful for |
||
399 | * counting all the elements of a multidimensional array. count does not detect infinite recursion. |
||
400 | * |
||
401 | * @return int |
||
402 | * <p> |
||
403 | * The number of elements in var, which is |
||
404 | * typically an array, since anything else will have one |
||
405 | * element. |
||
406 | * </p> |
||
407 | * <p> |
||
408 | * If var is not an array or an object with |
||
409 | * implemented Countable interface, |
||
410 | * 1 will be returned. |
||
411 | * There is one exception, if var is &null;, |
||
412 | * 0 will be returned. |
||
413 | * </p> |
||
414 | * <p> |
||
415 | * Caution: count may return 0 for a variable that isn't set, |
||
416 | * but it may also return 0 for a variable that has been initialized with an |
||
417 | * empty array. Use isset to test if a variable is set. |
||
418 | * </p> |
||
419 | * @psalm-mutation-free |
||
420 | */ |
||
421 | 148 | public function count(int $mode = \COUNT_NORMAL): int |
|
433 | |||
434 | /** |
||
435 | * Exchange the array for another one. |
||
436 | * |
||
437 | * @param array|static $data |
||
438 | * |
||
439 | * @return array |
||
440 | * |
||
441 | * @psalm-param array<TKey,T>|self<TKey,T> $data |
||
442 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
443 | */ |
||
444 | 1 | public function exchangeArray($data): array |
|
450 | |||
451 | /** |
||
452 | * Creates a copy of the ArrayyObject. |
||
453 | * |
||
454 | * @return array |
||
455 | * |
||
456 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
457 | */ |
||
458 | 6 | public function getArrayCopy(): array |
|
464 | |||
465 | /** |
||
466 | * Returns a new iterator, thus implementing the \Iterator interface. |
||
467 | * |
||
468 | * @return \Iterator<mixed, mixed> |
||
469 | * <p>An iterator for the values in the array.</p> |
||
470 | * @psalm-return \Iterator<array-key|TKey, mixed|T> |
||
471 | */ |
||
472 | 27 | public function getIterator(): \Iterator |
|
489 | |||
490 | /** |
||
491 | * Gets the iterator classname for the ArrayObject. |
||
492 | * |
||
493 | * @return string |
||
494 | * |
||
495 | * @psalm-return class-string |
||
496 | */ |
||
497 | 26 | public function getIteratorClass(): string |
|
501 | |||
502 | /** |
||
503 | * Sort the entries by key. |
||
504 | * |
||
505 | * @param int $sort_flags [optional] <p> |
||
506 | * You may modify the behavior of the sort using the optional |
||
507 | * parameter sort_flags, for details |
||
508 | * see sort. |
||
509 | * </p> |
||
510 | * |
||
511 | * @return $this |
||
512 | * <p>(Mutable) Return this Arrayy object.</p> |
||
513 | * |
||
514 | * @psalm-return static<TKey,T> |
||
515 | */ |
||
516 | 4 | public function ksort(int $sort_flags = 0): self |
|
524 | |||
525 | /** |
||
526 | * Sort the entries by key. |
||
527 | * |
||
528 | * @param int $sort_flags [optional] <p> |
||
529 | * You may modify the behavior of the sort using the optional |
||
530 | * parameter sort_flags, for details |
||
531 | * see sort. |
||
532 | * </p> |
||
533 | * |
||
534 | * @return $this |
||
535 | * <p>(Immutable) Return this Arrayy object.</p> |
||
536 | * |
||
537 | * @psalm-return static<TKey,T> |
||
538 | */ |
||
539 | 4 | public function ksortImmutable(int $sort_flags = 0): self |
|
550 | |||
551 | /** |
||
552 | * Sort an array using a case insensitive "natural order" algorithm. |
||
553 | * |
||
554 | * @return $this |
||
555 | * <p>(Mutable) Return this Arrayy object.</p> |
||
556 | * |
||
557 | * @psalm-return static<TKey,T> |
||
558 | */ |
||
559 | 8 | public function natcasesort(): self |
|
567 | |||
568 | /** |
||
569 | * Sort an array using a case insensitive "natural order" algorithm. |
||
570 | * |
||
571 | * @return $this |
||
572 | * <p>(Immutable) Return this Arrayy object.</p> |
||
573 | * |
||
574 | * @psalm-return static<TKey,T> |
||
575 | * @psalm-mutation-free |
||
576 | */ |
||
577 | 4 | public function natcasesortImmutable(): self |
|
588 | |||
589 | /** |
||
590 | * Sort entries using a "natural order" algorithm. |
||
591 | * |
||
592 | * @return $this |
||
593 | * <p>(Mutable) Return this Arrayy object.</p> |
||
594 | * |
||
595 | * @psalm-return static<TKey,T> |
||
596 | */ |
||
597 | 10 | public function natsort(): self |
|
605 | |||
606 | /** |
||
607 | * Sort entries using a "natural order" algorithm. |
||
608 | * |
||
609 | * @return $this |
||
610 | * <p>(Immutable) Return this Arrayy object.</p> |
||
611 | * |
||
612 | * @psalm-return static<TKey,T> |
||
613 | * @psalm-mutation-free |
||
614 | */ |
||
615 | 4 | public function natsortImmutable(): self |
|
626 | |||
627 | /** |
||
628 | * Whether or not an offset exists. |
||
629 | * |
||
630 | * @param bool|int|string $offset |
||
631 | * |
||
632 | * @return bool |
||
633 | * |
||
634 | * @noinspection PhpSillyAssignmentInspection |
||
635 | * |
||
636 | * @psalm-mutation-free |
||
637 | */ |
||
638 | 159 | public function offsetExists($offset): bool |
|
700 | |||
701 | /** |
||
702 | * Returns the value at specified offset. |
||
703 | * |
||
704 | * @param int|string $offset |
||
705 | * |
||
706 | * @return mixed |
||
707 | * <p>Will return null if the offset did not exists.</p> |
||
708 | */ |
||
709 | 128 | public function &offsetGet($offset) |
|
720 | |||
721 | /** |
||
722 | * Assigns a value to the specified offset + check the type. |
||
723 | * |
||
724 | * @param int|string|null $offset |
||
725 | * @param mixed $value |
||
726 | * |
||
727 | * @return void |
||
728 | */ |
||
729 | 28 | public function offsetSet($offset, $value) |
|
747 | |||
748 | /** |
||
749 | * Unset an offset. |
||
750 | * |
||
751 | * @param int|string $offset |
||
752 | * |
||
753 | * @return void |
||
754 | * <p>(Mutable) Return nothing.</p> |
||
755 | */ |
||
756 | 25 | public function offsetUnset($offset) |
|
807 | |||
808 | /** |
||
809 | * Serialize the current "Arrayy"-object. |
||
810 | * |
||
811 | * @return string |
||
812 | */ |
||
813 | 2 | public function serialize(): string |
|
823 | |||
824 | /** |
||
825 | * Sets the iterator classname for the current "Arrayy"-object. |
||
826 | * |
||
827 | * @param string $iteratorClass |
||
828 | * |
||
829 | * @throws \InvalidArgumentException |
||
830 | * |
||
831 | * @return void |
||
832 | * |
||
833 | * @psalm-param class-string<\Arrayy\ArrayyIterator> $iteratorClass |
||
834 | */ |
||
835 | 1193 | public function setIteratorClass($iteratorClass) |
|
857 | |||
858 | /** |
||
859 | * Sort the entries with a user-defined comparison function and maintain key association. |
||
860 | * |
||
861 | * @param callable $function |
||
862 | * |
||
863 | * @throws \InvalidArgumentException |
||
864 | * |
||
865 | * @return $this |
||
866 | * <p>(Mutable) Return this Arrayy object.</p> |
||
867 | * |
||
868 | * @psalm-return static<TKey,T> |
||
869 | */ |
||
870 | 8 | View Code Duplication | public function uasort($function): self |
882 | |||
883 | /** |
||
884 | * Sort the entries with a user-defined comparison function and maintain key association. |
||
885 | * |
||
886 | * @param callable $function |
||
887 | * |
||
888 | * @throws \InvalidArgumentException |
||
889 | * |
||
890 | * @return $this |
||
891 | * <p>(Immutable) Return this Arrayy object.</p> |
||
892 | * |
||
893 | * @psalm-return static<TKey,T> |
||
894 | * @psalm-mutation-free |
||
895 | */ |
||
896 | 4 | public function uasortImmutable($function): self |
|
907 | |||
908 | /** |
||
909 | * Sort the entries by keys using a user-defined comparison function. |
||
910 | * |
||
911 | * @param callable $function |
||
912 | * |
||
913 | * @throws \InvalidArgumentException |
||
914 | * |
||
915 | * @return static |
||
916 | * <p>(Mutable) Return this Arrayy object.</p> |
||
917 | * |
||
918 | * @psalm-return static<TKey,T> |
||
919 | */ |
||
920 | 5 | public function uksort($function): self |
|
924 | |||
925 | /** |
||
926 | * Sort the entries by keys using a user-defined comparison function. |
||
927 | * |
||
928 | * @param callable $function |
||
929 | * |
||
930 | * @throws \InvalidArgumentException |
||
931 | * |
||
932 | * @return static |
||
933 | * <p>(Immutable) Return this Arrayy object.</p> |
||
934 | * |
||
935 | * @psalm-return static<TKey,T> |
||
936 | * @psalm-mutation-free |
||
937 | */ |
||
938 | 1 | public function uksortImmutable($function): self |
|
942 | |||
943 | /** |
||
944 | * Unserialize an string and return the instance of the "Arrayy"-class. |
||
945 | * |
||
946 | * @param string $string |
||
947 | * |
||
948 | * @return $this |
||
949 | * |
||
950 | * @psalm-return static<TKey,T> |
||
951 | */ |
||
952 | 2 | public function unserialize($string): self |
|
962 | |||
963 | /** |
||
964 | * Append a (key) + values to the current array. |
||
965 | * |
||
966 | * EXAMPLE: <code> |
||
967 | * a(['fòô' => ['bàř']])->appendArrayValues(['foo1', 'foo2'], 'fòô'); // Arrayy['fòô' => ['bàř', 'foo1', 'foo2']] |
||
968 | * </code> |
||
969 | * |
||
970 | * @param array $values |
||
971 | * @param mixed $key |
||
972 | * |
||
973 | * @return $this |
||
974 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
975 | * |
||
976 | * @psalm-param array<mixed,T> $values |
||
977 | * @psalm-param TKey|null $key |
||
978 | * @psalm-return static<TKey,T> |
||
979 | */ |
||
980 | 1 | public function appendArrayValues(array $values, $key = null) |
|
1006 | |||
1007 | /** |
||
1008 | * Add a suffix to each key. |
||
1009 | * |
||
1010 | * @param mixed $prefix |
||
1011 | * |
||
1012 | * @return static |
||
1013 | * <p>(Immutable) Return an Arrayy object, with the prefixed keys.</p> |
||
1014 | * |
||
1015 | * @psalm-return static<TKey,T> |
||
1016 | * @psalm-mutation-free |
||
1017 | */ |
||
1018 | 10 | View Code Duplication | public function appendToEachKey($prefix): self |
1037 | |||
1038 | /** |
||
1039 | * Add a prefix to each value. |
||
1040 | * |
||
1041 | * @param mixed $prefix |
||
1042 | * |
||
1043 | * @return static |
||
1044 | * <p>(Immutable) Return an Arrayy object, with the prefixed values.</p> |
||
1045 | * |
||
1046 | * @psalm-return static<TKey,T> |
||
1047 | * @psalm-mutation-free |
||
1048 | */ |
||
1049 | 10 | View Code Duplication | public function appendToEachValue($prefix): self |
1068 | |||
1069 | /** |
||
1070 | * Sort an array in reverse order and maintain index association. |
||
1071 | * |
||
1072 | * @return $this |
||
1073 | * <p>(Mutable) Return this Arrayy object.</p> |
||
1074 | * |
||
1075 | * @psalm-return static<TKey,T> |
||
1076 | */ |
||
1077 | 4 | public function arsort(): self |
|
1085 | |||
1086 | /** |
||
1087 | * Sort an array in reverse order and maintain index association. |
||
1088 | * |
||
1089 | * @return $this |
||
1090 | * <p>(Immutable) Return this Arrayy object.</p> |
||
1091 | * |
||
1092 | * @psalm-return static<TKey,T> |
||
1093 | * @psalm-mutation-free |
||
1094 | */ |
||
1095 | 10 | public function arsortImmutable(): self |
|
1105 | |||
1106 | /** |
||
1107 | * Iterate over the current array and execute a callback for each loop. |
||
1108 | * |
||
1109 | * EXAMPLE: <code> |
||
1110 | * $result = A::create(); |
||
1111 | * $closure = function ($value, $key) use ($result) { |
||
1112 | * $result[$key] = ':' . $value . ':'; |
||
1113 | * }; |
||
1114 | * a(['foo', 'bar' => 'bis'])->at($closure); // Arrayy[':foo:', 'bar' => ':bis:'] |
||
1115 | * </code> |
||
1116 | * |
||
1117 | * @param \Closure $closure |
||
1118 | * |
||
1119 | * @return static |
||
1120 | * <p>(Immutable)</p> |
||
1121 | * |
||
1122 | * @psalm-return static<TKey,T> |
||
1123 | * @psalm-mutation-free |
||
1124 | */ |
||
1125 | 3 | public function at(\Closure $closure): self |
|
1139 | |||
1140 | /** |
||
1141 | * Returns the average value of the current array. |
||
1142 | * |
||
1143 | * EXAMPLE: <code> |
||
1144 | * a([-9, -8, -7, 1.32])->average(2); // -5.67 |
||
1145 | * </code> |
||
1146 | * |
||
1147 | * @param int $decimals <p>The number of decimal-numbers to return.</p> |
||
1148 | * |
||
1149 | * @return float|int |
||
1150 | * <p>The average value.</p> |
||
1151 | * @psalm-mutation-free |
||
1152 | */ |
||
1153 | 10 | public function average($decimals = 0) |
|
1167 | |||
1168 | /** |
||
1169 | * Changes all keys in an array. |
||
1170 | * |
||
1171 | * @param int $case [optional] <p> Either <strong>CASE_UPPER</strong><br /> |
||
1172 | * or <strong>CASE_LOWER</strong> (default)</p> |
||
1173 | * |
||
1174 | * @return static |
||
1175 | * <p>(Immutable)</p> |
||
1176 | * |
||
1177 | * @psalm-return static<TKey,T> |
||
1178 | * @psalm-mutation-free |
||
1179 | */ |
||
1180 | 1 | public function changeKeyCase(int $case = \CASE_LOWER): self |
|
1209 | |||
1210 | /** |
||
1211 | * Change the path separator of the array wrapper. |
||
1212 | * |
||
1213 | * By default, the separator is: "." |
||
1214 | * |
||
1215 | * @param string $separator <p>Separator to set.</p> |
||
1216 | * |
||
1217 | * @return $this |
||
1218 | * <p>(Mutable) Return this Arrayy object.</p> |
||
1219 | * |
||
1220 | * @psalm-return static<TKey,T> |
||
1221 | */ |
||
1222 | 11 | public function changeSeparator($separator): self |
|
1228 | |||
1229 | /** |
||
1230 | * Create a chunked version of the current array. |
||
1231 | * |
||
1232 | * EXAMPLE: <code> |
||
1233 | * a([-9, -8, -7, 1.32])->chunk(2); // Arrayy[[-9, -8], [-7, 1.32]] |
||
1234 | * </code> |
||
1235 | * |
||
1236 | * @param int $size <p>Size of each chunk.</p> |
||
1237 | * @param bool $preserveKeys <p>Whether array keys are preserved or no.</p> |
||
1238 | * |
||
1239 | * @return static |
||
1240 | * <p>(Immutable) A new array of chunks from the original array.</p> |
||
1241 | * |
||
1242 | * @psalm-return static<TKey,T> |
||
1243 | * @psalm-mutation-free |
||
1244 | */ |
||
1245 | 5 | public function chunk($size, $preserveKeys = false): self |
|
1253 | |||
1254 | /** |
||
1255 | * Clean all falsy values from the current array. |
||
1256 | * |
||
1257 | * EXAMPLE: <code> |
||
1258 | * a([-8 => -9, 1, 2 => false])->clean(); // Arrayy[-8 => -9, 1] |
||
1259 | * </code> |
||
1260 | * |
||
1261 | * @return static |
||
1262 | * <p>(Immutable)</p> |
||
1263 | * |
||
1264 | * @psalm-return static<TKey,T> |
||
1265 | * @psalm-mutation-free |
||
1266 | */ |
||
1267 | 8 | public function clean(): self |
|
1275 | |||
1276 | /** |
||
1277 | * WARNING!!! -> Clear the current full array or a $key of it. |
||
1278 | * |
||
1279 | * EXAMPLE: <code> |
||
1280 | * a([-8 => -9, 1, 2 => false])->clear(); // Arrayy[] |
||
1281 | * </code> |
||
1282 | * |
||
1283 | * @param int|int[]|string|string[]|null $key |
||
1284 | * |
||
1285 | * @return $this |
||
1286 | * <p>(Mutable) Return this Arrayy object, with an empty array.</p> |
||
1287 | * |
||
1288 | * @psalm-return static<TKey,T> |
||
1289 | */ |
||
1290 | 10 | public function clear($key = null): self |
|
1309 | |||
1310 | /** |
||
1311 | * Check if an item is in the current array. |
||
1312 | * |
||
1313 | * EXAMPLE: <code> |
||
1314 | * a([1, true])->contains(true); // true |
||
1315 | * </code> |
||
1316 | * |
||
1317 | * @param float|int|string $value |
||
1318 | * @param bool $recursive |
||
1319 | * @param bool $strict |
||
1320 | * |
||
1321 | * @return bool |
||
1322 | * @psalm-mutation-free |
||
1323 | */ |
||
1324 | 24 | public function contains($value, bool $recursive = false, bool $strict = true): bool |
|
1325 | { |
||
1326 | 24 | if ($recursive === true) { |
|
1327 | 19 | return $this->in_array_recursive($value, $this->toArray(), $strict); |
|
1328 | } |
||
1329 | |||
1330 | /** @noinspection PhpParameterByRefIsNotUsedAsReferenceInspection */ |
||
1331 | 14 | foreach ($this->getGeneratorByReference() as &$valueFromArray) { |
|
1332 | 11 | if ($strict) { |
|
1333 | 11 | if ($value === $valueFromArray) { |
|
1334 | 11 | return true; |
|
1335 | } |
||
1336 | } else { |
||
1337 | /** @noinspection NestedPositiveIfStatementsInspection */ |
||
1338 | if ($value == $valueFromArray) { |
||
1339 | return true; |
||
1340 | } |
||
1341 | } |
||
1342 | } |
||
1343 | |||
1344 | 7 | return false; |
|
1345 | } |
||
1346 | |||
1347 | /** |
||
1348 | * Check if an (case-insensitive) string is in the current array. |
||
1349 | * |
||
1350 | * EXAMPLE: <code> |
||
1351 | * a(['E', 'é'])->containsCaseInsensitive('É'); // true |
||
1352 | * </code> |
||
1353 | * |
||
1354 | * @param mixed $value |
||
1355 | * @param bool $recursive |
||
1356 | * |
||
1357 | * @return bool |
||
1358 | * @psalm-mutation-free |
||
1359 | * |
||
1360 | * @psalm-suppress InvalidCast - hack for int|float|bool support |
||
1361 | */ |
||
1362 | 26 | public function containsCaseInsensitive($value, $recursive = false): bool |
|
1393 | |||
1394 | /** |
||
1395 | * Check if the given key/index exists in the array. |
||
1396 | * |
||
1397 | * EXAMPLE: <code> |
||
1398 | * a([1 => true])->containsKey(1); // true |
||
1399 | * </code> |
||
1400 | * |
||
1401 | * @param int|string $key <p>key/index to search for</p> |
||
1402 | * |
||
1403 | * @return bool |
||
1404 | * <p>Returns true if the given key/index exists in the array, false otherwise.</p> |
||
1405 | * |
||
1406 | * @psalm-mutation-free |
||
1407 | */ |
||
1408 | 4 | public function containsKey($key): bool |
|
1412 | |||
1413 | /** |
||
1414 | * Check if all given needles are present in the array as key/index. |
||
1415 | * |
||
1416 | * EXAMPLE: <code> |
||
1417 | * a([1 => true])->containsKeys(array(1 => 0)); // true |
||
1418 | * </code> |
||
1419 | * |
||
1420 | * @param array $needles <p>The keys you are searching for.</p> |
||
1421 | * @param bool $recursive |
||
1422 | * |
||
1423 | * @return bool |
||
1424 | * <p>Returns true if all the given keys/indexes exists in the array, false otherwise.</p> |
||
1425 | * |
||
1426 | * @psalm-param array<mixed,mixed>|array<TKey> $needles |
||
1427 | * @psalm-mutation-free |
||
1428 | */ |
||
1429 | 2 | public function containsKeys(array $needles, $recursive = false): bool |
|
1457 | |||
1458 | /** |
||
1459 | * Check if all given needles are present in the array as key/index. |
||
1460 | * |
||
1461 | * @param array $needles <p>The keys you are searching for.</p> |
||
1462 | * |
||
1463 | * @return bool |
||
1464 | * <p>Returns true if all the given keys/indexes exists in the array, false otherwise.</p> |
||
1465 | * |
||
1466 | * @psalm-param array<mixed,mixed>|array<TKey> $needles |
||
1467 | * @psalm-mutation-free |
||
1468 | */ |
||
1469 | 1 | public function containsKeysRecursive(array $needles): bool |
|
1473 | |||
1474 | /** |
||
1475 | * alias: for "Arrayy->contains()" |
||
1476 | * |
||
1477 | * @param float|int|string $value |
||
1478 | * |
||
1479 | * @return bool |
||
1480 | * |
||
1481 | * @see Arrayy::contains() |
||
1482 | * @psalm-mutation-free |
||
1483 | */ |
||
1484 | 9 | public function containsValue($value): bool |
|
1488 | |||
1489 | /** |
||
1490 | * alias: for "Arrayy->contains($value, true)" |
||
1491 | * |
||
1492 | * @param float|int|string $value |
||
1493 | * |
||
1494 | * @return bool |
||
1495 | * |
||
1496 | * @see Arrayy::contains() |
||
1497 | * @psalm-mutation-free |
||
1498 | */ |
||
1499 | 18 | public function containsValueRecursive($value): bool |
|
1503 | |||
1504 | /** |
||
1505 | * Check if all given needles are present in the array. |
||
1506 | * |
||
1507 | * EXAMPLE: <code> |
||
1508 | * a([1, true])->containsValues(array(1, true)); // true |
||
1509 | * </code> |
||
1510 | * |
||
1511 | * @param array $needles |
||
1512 | * |
||
1513 | * @return bool |
||
1514 | * <p>Returns true if all the given values exists in the array, false otherwise.</p> |
||
1515 | * |
||
1516 | * @psalm-param array<mixed>|array<T> $needles |
||
1517 | * @psalm-mutation-free |
||
1518 | */ |
||
1519 | 1 | public function containsValues(array $needles): bool |
|
1534 | |||
1535 | /** |
||
1536 | * Counts all the values of an array |
||
1537 | * |
||
1538 | * @see http://php.net/manual/en/function.array-count-values.php |
||
1539 | * |
||
1540 | * @return static |
||
1541 | * <p> |
||
1542 | * (Immutable) |
||
1543 | * An associative Arrayy-object of values from input as |
||
1544 | * keys and their count as value. |
||
1545 | * </p> |
||
1546 | * |
||
1547 | * @psalm-return static<TKey,T> |
||
1548 | * @psalm-mutation-free |
||
1549 | */ |
||
1550 | 7 | public function countValues(): self |
|
1554 | |||
1555 | /** |
||
1556 | * Creates an Arrayy object. |
||
1557 | * |
||
1558 | * @param mixed $data |
||
1559 | * @param string $iteratorClass |
||
1560 | * @param bool $checkPropertiesInConstructor |
||
1561 | * |
||
1562 | * @return static |
||
1563 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1564 | * |
||
1565 | * @psalm-param class-string<\Arrayy\ArrayyIterator> $iteratorClass |
||
1566 | * |
||
1567 | * @psalm-mutation-free |
||
1568 | */ |
||
1569 | 720 | public static function create( |
|
1580 | |||
1581 | /** |
||
1582 | * Flatten an array with the given character as a key delimiter |
||
1583 | * |
||
1584 | * @param string $delimiter |
||
1585 | * @param string $prepend |
||
1586 | * @param array|null $items |
||
1587 | * |
||
1588 | * @return array |
||
1589 | */ |
||
1590 | 2 | public function flatten($delimiter = '.', $prepend = '', $items = null) |
|
1613 | |||
1614 | /** |
||
1615 | * WARNING: Creates an Arrayy object by reference. |
||
1616 | * |
||
1617 | * @param array $array |
||
1618 | * |
||
1619 | * @return $this |
||
1620 | * <p>(Mutable) Return this Arrayy object.</p> |
||
1621 | * |
||
1622 | * @psalm-param array<mixed,mixed>|array<array-key,mixed> $array |
||
1623 | */ |
||
1624 | 28 | public function createByReference(array &$array = []): self |
|
1632 | |||
1633 | /** |
||
1634 | * Create an new instance from a callable function which will return an Generator. |
||
1635 | * |
||
1636 | * @param callable $generatorFunction |
||
1637 | * |
||
1638 | * @return static |
||
1639 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1640 | * |
||
1641 | * @psalm-param callable():\Generator<array-key,mixed> $generatorFunction |
||
1642 | * |
||
1643 | * @psalm-mutation-free |
||
1644 | */ |
||
1645 | 7 | public static function createFromGeneratorFunction(callable $generatorFunction): self |
|
1649 | |||
1650 | /** |
||
1651 | * Create an new instance filled with a copy of values from a "Generator"-object. |
||
1652 | * |
||
1653 | * @param \Generator $generator |
||
1654 | * |
||
1655 | * @return static |
||
1656 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1657 | * |
||
1658 | * @psalm-param \Generator<array-key,mixed> $generator |
||
1659 | * |
||
1660 | * @psalm-mutation-free |
||
1661 | */ |
||
1662 | 4 | public static function createFromGeneratorImmutable(\Generator $generator): self |
|
1666 | |||
1667 | /** |
||
1668 | * Create an new Arrayy object via JSON. |
||
1669 | * |
||
1670 | * @param string $json |
||
1671 | * |
||
1672 | * @return static |
||
1673 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1674 | * |
||
1675 | * @psalm-mutation-free |
||
1676 | */ |
||
1677 | 5 | public static function createFromJson(string $json): self |
|
1681 | |||
1682 | /** |
||
1683 | * Create an new Arrayy object via JSON. |
||
1684 | * |
||
1685 | * @param array $array |
||
1686 | * |
||
1687 | * @return static |
||
1688 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1689 | * |
||
1690 | * @psalm-mutation-free |
||
1691 | */ |
||
1692 | 1 | public static function createFromArray(array $array): self |
|
1696 | |||
1697 | /** |
||
1698 | * Create an new instance filled with values from an object that is iterable. |
||
1699 | * |
||
1700 | * @param \Traversable $object <p>iterable object</p> |
||
1701 | * |
||
1702 | * @return static |
||
1703 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1704 | * |
||
1705 | * @psalm-param \Traversable<array-key,mixed> $object |
||
1706 | * |
||
1707 | * @psalm-mutation-free |
||
1708 | */ |
||
1709 | 4 | public static function createFromObject(\Traversable $object): self |
|
1729 | |||
1730 | /** |
||
1731 | * Create an new instance filled with values from an object. |
||
1732 | * |
||
1733 | * @param object $object |
||
1734 | * |
||
1735 | * @return static |
||
1736 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1737 | * |
||
1738 | * @psalm-mutation-free |
||
1739 | */ |
||
1740 | 5 | public static function createFromObjectVars($object): self |
|
1744 | |||
1745 | /** |
||
1746 | * Create an new Arrayy object via string. |
||
1747 | * |
||
1748 | * @param string $str <p>The input string.</p> |
||
1749 | * @param string|null $delimiter <p>The boundary string.</p> |
||
1750 | * @param string|null $regEx <p>Use the $delimiter or the $regEx, so if $pattern is null, $delimiter will be |
||
1751 | * used.</p> |
||
1752 | * |
||
1753 | * @return static |
||
1754 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1755 | * |
||
1756 | * @psalm-mutation-free |
||
1757 | */ |
||
1758 | 10 | public static function createFromString(string $str, string $delimiter = null, string $regEx = null): self |
|
1790 | |||
1791 | /** |
||
1792 | * Create an new instance filled with a copy of values from a "Traversable"-object. |
||
1793 | * |
||
1794 | * @param \Traversable $traversable |
||
1795 | * |
||
1796 | * @return static |
||
1797 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1798 | * |
||
1799 | * @psalm-param \Traversable<array-key,mixed> $traversable |
||
1800 | * |
||
1801 | * @psalm-mutation-free |
||
1802 | */ |
||
1803 | 1 | public static function createFromTraversableImmutable(\Traversable $traversable): self |
|
1807 | |||
1808 | /** |
||
1809 | * Create an new instance containing a range of elements. |
||
1810 | * |
||
1811 | * @param float|int|string $low <p>First value of the sequence.</p> |
||
1812 | * @param float|int|string $high <p>The sequence is ended upon reaching the end value.</p> |
||
1813 | * @param float|int $step <p>Used as the increment between elements in the sequence.</p> |
||
1814 | * |
||
1815 | * @return static |
||
1816 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1817 | * |
||
1818 | * @psalm-mutation-free |
||
1819 | */ |
||
1820 | 2 | public static function createWithRange($low, $high, $step = 1): self |
|
1824 | |||
1825 | /** |
||
1826 | * Gets the element of the array at the current internal iterator position. |
||
1827 | * |
||
1828 | * @return false|mixed |
||
1829 | */ |
||
1830 | public function current() |
||
1834 | |||
1835 | /** |
||
1836 | * Custom sort by index via "uksort". |
||
1837 | * |
||
1838 | * EXAMPLE: <code> |
||
1839 | * $callable = function ($a, $b) { |
||
1840 | * if ($a == $b) { |
||
1841 | * return 0; |
||
1842 | * } |
||
1843 | * return ($a > $b) ? 1 : -1; |
||
1844 | * }; |
||
1845 | * $arrayy = a(['three' => 3, 'one' => 1, 'two' => 2]); |
||
1846 | * $resultArrayy = $arrayy->customSortKeys($callable); // Arrayy['one' => 1, 'three' => 3, 'two' => 2] |
||
1847 | * </code> |
||
1848 | * |
||
1849 | * @see http://php.net/manual/en/function.uksort.php |
||
1850 | * |
||
1851 | * @param callable $function |
||
1852 | * |
||
1853 | * @throws \InvalidArgumentException |
||
1854 | * |
||
1855 | * @return $this |
||
1856 | * <p>(Mutable) Return this Arrayy object.</p> |
||
1857 | * |
||
1858 | * @psalm-return static<TKey,T> |
||
1859 | */ |
||
1860 | 5 | public function customSortKeys(callable $function): self |
|
1868 | |||
1869 | /** |
||
1870 | * Custom sort by index via "uksort". |
||
1871 | * |
||
1872 | * @see http://php.net/manual/en/function.uksort.php |
||
1873 | * |
||
1874 | * @param callable $function |
||
1875 | * |
||
1876 | * @throws \InvalidArgumentException |
||
1877 | * |
||
1878 | * @return $this |
||
1879 | * <p>(Immutable) Return this Arrayy object.</p> |
||
1880 | * |
||
1881 | * @psalm-return static<TKey,T> |
||
1882 | * @psalm-mutation-free |
||
1883 | */ |
||
1884 | 1 | public function customSortKeysImmutable(callable $function): self |
|
1897 | |||
1898 | /** |
||
1899 | * Custom sort by value via "usort". |
||
1900 | * |
||
1901 | * EXAMPLE: <code> |
||
1902 | * $callable = function ($a, $b) { |
||
1903 | * if ($a == $b) { |
||
1904 | * return 0; |
||
1905 | * } |
||
1906 | * return ($a > $b) ? 1 : -1; |
||
1907 | * }; |
||
1908 | * $arrayy = a(['three' => 3, 'one' => 1, 'two' => 2]); |
||
1909 | * $resultArrayy = $arrayy->customSortValues($callable); // Arrayy['one' => 1, 'two' => 2, 'three' => 3] |
||
1910 | * </code> |
||
1911 | * |
||
1912 | * @see http://php.net/manual/en/function.usort.php |
||
1913 | * |
||
1914 | * @param callable $function |
||
1915 | * |
||
1916 | * @throws \InvalidArgumentException |
||
1917 | * |
||
1918 | * @return $this |
||
1919 | * <p>(Mutable) Return this Arrayy object.</p> |
||
1920 | * |
||
1921 | * @psalm-return static<TKey,T> |
||
1922 | */ |
||
1923 | 10 | View Code Duplication | public function customSortValues($function): self |
1935 | |||
1936 | /** |
||
1937 | * Custom sort by value via "usort". |
||
1938 | * |
||
1939 | * @see http://php.net/manual/en/function.usort.php |
||
1940 | * |
||
1941 | * @param callable $function |
||
1942 | * |
||
1943 | * @throws \InvalidArgumentException |
||
1944 | * |
||
1945 | * @return $this |
||
1946 | * <p>(Immutable) Return this Arrayy object.</p> |
||
1947 | * |
||
1948 | * @psalm-return static<TKey,T> |
||
1949 | * @psalm-mutation-free |
||
1950 | */ |
||
1951 | 4 | public function customSortValuesImmutable($function): self |
|
1962 | |||
1963 | /** |
||
1964 | * Delete the given key or keys. |
||
1965 | * |
||
1966 | * @param int|int[]|string|string[] $keyOrKeys |
||
1967 | * |
||
1968 | * @return void |
||
1969 | */ |
||
1970 | 9 | public function delete($keyOrKeys) |
|
1978 | |||
1979 | /** |
||
1980 | * Return values that are only in the current array. |
||
1981 | * |
||
1982 | * EXAMPLE: <code> |
||
1983 | * a([1 => 1, 2 => 2])->diff([1 => 1]); // Arrayy[2 => 2] |
||
1984 | * </code> |
||
1985 | * |
||
1986 | * @param array ...$array |
||
1987 | * |
||
1988 | * @return static |
||
1989 | * <p>(Immutable)</p> |
||
1990 | * |
||
1991 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$array |
||
1992 | * @psalm-return static<TKey,T> |
||
1993 | * @psalm-mutation-free |
||
1994 | */ |
||
1995 | 13 | public function diff(...$array): self |
|
2003 | |||
2004 | /** |
||
2005 | * Return values that are only in the current array. |
||
2006 | * |
||
2007 | * @param array ...$array |
||
2008 | * |
||
2009 | * @return static |
||
2010 | * <p>(Immutable)</p> |
||
2011 | * |
||
2012 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$array |
||
2013 | * @psalm-return static<TKey,T> |
||
2014 | * @psalm-mutation-free |
||
2015 | */ |
||
2016 | 8 | public function diffKey(...$array): self |
|
2024 | |||
2025 | /** |
||
2026 | * Return values and Keys that are only in the current array. |
||
2027 | * |
||
2028 | * @param array $array |
||
2029 | * |
||
2030 | * @return static |
||
2031 | * <p>(Immutable)</p> |
||
2032 | * |
||
2033 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
2034 | * @psalm-return static<TKey,T> |
||
2035 | * @psalm-mutation-free |
||
2036 | */ |
||
2037 | 8 | public function diffKeyAndValue(array $array = []): self |
|
2045 | |||
2046 | /** |
||
2047 | * Return values that are only in the current multi-dimensional array. |
||
2048 | * |
||
2049 | * @param array $array |
||
2050 | * @param array|\Generator|null $helperVariableForRecursion <p>(only for internal usage)</p> |
||
2051 | * |
||
2052 | * @return static |
||
2053 | * <p>(Immutable)</p> |
||
2054 | * |
||
2055 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
2056 | * @psalm-param null|array<TKey,T>|\Generator<TKey,T> $helperVariableForRecursion |
||
2057 | * @psalm-return static<TKey,T> |
||
2058 | * @psalm-mutation-free |
||
2059 | */ |
||
2060 | 1 | public function diffRecursive(array $array = [], $helperVariableForRecursion = null): self |
|
2095 | |||
2096 | /** |
||
2097 | * Return values that are only in the new $array. |
||
2098 | * |
||
2099 | * @param array $array |
||
2100 | * |
||
2101 | * @return static |
||
2102 | * <p>(Immutable)</p> |
||
2103 | * |
||
2104 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
2105 | * @psalm-return static<TKey,T> |
||
2106 | * @psalm-mutation-free |
||
2107 | */ |
||
2108 | 8 | public function diffReverse(array $array = []): self |
|
2116 | |||
2117 | /** |
||
2118 | * Divide an array into two arrays. One with keys and the other with values. |
||
2119 | * |
||
2120 | * @return static |
||
2121 | * <p>(Immutable)</p> |
||
2122 | * |
||
2123 | * @psalm-return static<TKey,T> |
||
2124 | * @psalm-mutation-free |
||
2125 | */ |
||
2126 | 1 | public function divide(): self |
|
2137 | |||
2138 | /** |
||
2139 | * Iterate over the current array and modify the array's value. |
||
2140 | * |
||
2141 | * @param \Closure $closure |
||
2142 | * |
||
2143 | * @return static |
||
2144 | * <p>(Immutable)</p> |
||
2145 | * |
||
2146 | * @psalm-return static<TKey,T> |
||
2147 | * @psalm-mutation-free |
||
2148 | */ |
||
2149 | 5 | View Code Duplication | public function each(\Closure $closure): self |
2164 | |||
2165 | /** |
||
2166 | * Sets the internal iterator to the last element in the array and returns this element. |
||
2167 | * |
||
2168 | * @return mixed |
||
2169 | */ |
||
2170 | public function end() |
||
2174 | |||
2175 | /** |
||
2176 | * Check if a value is in the current array using a closure. |
||
2177 | * |
||
2178 | * @param \Closure $closure |
||
2179 | * |
||
2180 | * @return bool |
||
2181 | * <p>Returns true if the given value is found, false otherwise.</p> |
||
2182 | */ |
||
2183 | 4 | public function exists(\Closure $closure): bool |
|
2198 | |||
2199 | /** |
||
2200 | * Fill the array until "$num" with "$default" values. |
||
2201 | * |
||
2202 | * @param int $num |
||
2203 | * @param mixed $default |
||
2204 | * |
||
2205 | * @return static |
||
2206 | * <p>(Immutable)</p> |
||
2207 | * |
||
2208 | * @psalm-return static<TKey,T> |
||
2209 | * @psalm-mutation-free |
||
2210 | */ |
||
2211 | 8 | public function fillWithDefaults(int $num, $default = null): self |
|
2234 | |||
2235 | /** |
||
2236 | * Find all items in an array that pass the truth test. |
||
2237 | * |
||
2238 | * @param \Closure|null $closure [optional] <p> |
||
2239 | * The callback function to use |
||
2240 | * </p> |
||
2241 | * <p> |
||
2242 | * If no callback is supplied, all entries of |
||
2243 | * input equal to false (see |
||
2244 | * converting to |
||
2245 | * boolean) will be removed. |
||
2246 | * </p> |
||
2247 | * @param int $flag [optional] <p> |
||
2248 | * Flag determining what arguments are sent to <i>callback</i>: |
||
2249 | * </p><ul> |
||
2250 | * <li> |
||
2251 | * <b>ARRAY_FILTER_USE_KEY</b> [1] - pass key as the only argument |
||
2252 | * to <i>callback</i> instead of the value</span> |
||
2253 | * </li> |
||
2254 | * <li> |
||
2255 | * <b>ARRAY_FILTER_USE_BOTH</b> [2] - pass both value and key as |
||
2256 | * arguments to <i>callback</i> instead of the value</span> |
||
2257 | * </li> |
||
2258 | * </ul> |
||
2259 | * |
||
2260 | * @return static |
||
2261 | * <p>(Immutable)</p> |
||
2262 | * |
||
2263 | * @psalm-param \Closure(T=,TKey=):bool|\Closure(T=):bool $closure |
||
2264 | * @psalm-return static<TKey,T> |
||
2265 | * @psalm-mutation-free |
||
2266 | */ |
||
2267 | 12 | public function filter($closure = null, int $flag = \ARRAY_FILTER_USE_BOTH) |
|
2279 | |||
2280 | /** |
||
2281 | * Filters an array of objects (or a numeric array of associative arrays) based on the value of a particular |
||
2282 | * property within that. |
||
2283 | * |
||
2284 | * @param string $property |
||
2285 | * @param string|string[] $value |
||
2286 | * @param string $comparisonOp |
||
2287 | * <p> |
||
2288 | * 'eq' (equals),<br /> |
||
2289 | * 'gt' (greater),<br /> |
||
2290 | * 'gte' || 'ge' (greater or equals),<br /> |
||
2291 | * 'lt' (less),<br /> |
||
2292 | * 'lte' || 'le' (less or equals),<br /> |
||
2293 | * 'ne' (not equals),<br /> |
||
2294 | * 'contains',<br /> |
||
2295 | * 'notContains',<br /> |
||
2296 | * 'newer' (via strtotime),<br /> |
||
2297 | * 'older' (via strtotime),<br /> |
||
2298 | * </p> |
||
2299 | * |
||
2300 | * @return static |
||
2301 | * <p>(Immutable)</p> |
||
2302 | * |
||
2303 | * @psalm-return static<TKey,T> |
||
2304 | * @psalm-mutation-free |
||
2305 | * |
||
2306 | * @psalm-suppress MissingClosureReturnType |
||
2307 | * @psalm-suppress MissingClosureParamType |
||
2308 | */ |
||
2309 | 1 | public function filterBy( |
|
2381 | |||
2382 | /** |
||
2383 | * Find the first item in an array that passes the truth test, |
||
2384 | * otherwise return false |
||
2385 | * |
||
2386 | * @param \Closure $closure |
||
2387 | * |
||
2388 | * @return false|mixed |
||
2389 | * <p>Return false if we did not find the value.</p> |
||
2390 | */ |
||
2391 | 8 | View Code Duplication | public function find(\Closure $closure) |
2401 | |||
2402 | /** |
||
2403 | * find by ... |
||
2404 | * |
||
2405 | * @param string $property |
||
2406 | * @param string|string[] $value |
||
2407 | * @param string $comparisonOp |
||
2408 | * |
||
2409 | * @return static |
||
2410 | * <p>(Immutable)</p> |
||
2411 | * |
||
2412 | * @psalm-return static<TKey,T> |
||
2413 | * @psalm-mutation-free |
||
2414 | */ |
||
2415 | 1 | public function findBy(string $property, $value, string $comparisonOp = 'eq'): self |
|
2419 | |||
2420 | /** |
||
2421 | * Get the first value from the current array. |
||
2422 | * |
||
2423 | * @return mixed |
||
2424 | * <p>Return null if there wasn't a element.</p> |
||
2425 | */ |
||
2426 | 23 | public function first() |
|
2435 | |||
2436 | /** |
||
2437 | * Get the first key from the current array. |
||
2438 | * |
||
2439 | * @return mixed |
||
2440 | * <p>Return null if there wasn't a element.</p> |
||
2441 | * @psalm-mutation-free |
||
2442 | */ |
||
2443 | 30 | public function firstKey() |
|
2449 | |||
2450 | /** |
||
2451 | * Get the first value(s) from the current array. |
||
2452 | * And will return an empty array if there was no first entry. |
||
2453 | * |
||
2454 | * @param int|null $number <p>How many values you will take?</p> |
||
2455 | * |
||
2456 | * @return static |
||
2457 | * <p>(Immutable)</p> |
||
2458 | * |
||
2459 | * @psalm-return static<TKey,T> |
||
2460 | * @psalm-mutation-free |
||
2461 | */ |
||
2462 | 37 | View Code Duplication | public function firstsImmutable(int $number = null): self |
2478 | |||
2479 | /** |
||
2480 | * Get the first value(s) from the current array. |
||
2481 | * And will return an empty array if there was no first entry. |
||
2482 | * |
||
2483 | * @param int|null $number <p>How many values you will take?</p> |
||
2484 | * |
||
2485 | * @return static |
||
2486 | * <p>(Immutable)</p> |
||
2487 | * |
||
2488 | * @psalm-return static<TKey,T> |
||
2489 | * @psalm-mutation-free |
||
2490 | */ |
||
2491 | 3 | View Code Duplication | public function firstsKeys(int $number = null): self |
2507 | |||
2508 | /** |
||
2509 | * Get and rmove the first value(s) from the current array. |
||
2510 | * And will return an empty array if there was no first entry. |
||
2511 | * |
||
2512 | * @param int|null $number <p>How many values you will take?</p> |
||
2513 | * |
||
2514 | * @return $this |
||
2515 | * <p>(Mutable)</p> |
||
2516 | * |
||
2517 | * @psalm-return static<TKey,T> |
||
2518 | */ |
||
2519 | 34 | public function firstsMutable(int $number = null): self |
|
2531 | |||
2532 | /** |
||
2533 | * Exchanges all keys with their associated values in an array. |
||
2534 | * |
||
2535 | * @return static |
||
2536 | * <p>(Immutable)</p> |
||
2537 | * |
||
2538 | * @psalm-return static<array-key,TKey> |
||
2539 | * @psalm-mutation-free |
||
2540 | */ |
||
2541 | 1 | public function flip(): self |
|
2555 | |||
2556 | /** |
||
2557 | * Get a value from an array (optional using dot-notation). |
||
2558 | * |
||
2559 | * @param mixed $key <p>The key to look for.</p> |
||
2560 | * @param mixed $fallback <p>Value to fallback to.</p> |
||
2561 | * @param array $array <p>The array to get from, if it's set to "null" we use the current array from the |
||
2562 | * class.</p> |
||
2563 | * @param bool $useByReference |
||
2564 | * |
||
2565 | * @return mixed|static |
||
2566 | * |
||
2567 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
2568 | * @psalm-mutation-free |
||
2569 | */ |
||
2570 | 244 | public function get( |
|
2734 | |||
2735 | /** |
||
2736 | * alias: for "Arrayy->toArray()" |
||
2737 | * |
||
2738 | * @return array |
||
2739 | * |
||
2740 | * @see Arrayy::getArray() |
||
2741 | * |
||
2742 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
2743 | */ |
||
2744 | 15 | public function getAll(): array |
|
2748 | |||
2749 | /** |
||
2750 | * Get the current array from the "Arrayy"-object. |
||
2751 | * |
||
2752 | * alias for "toArray()" |
||
2753 | * |
||
2754 | * @param bool $convertAllArrayyElements <p> |
||
2755 | * Convert all Child-"Arrayy" objects also to arrays. |
||
2756 | * </p> |
||
2757 | * @param bool $preserveKeys <p> |
||
2758 | * e.g.: A generator maybe return the same key more then once, |
||
2759 | * so maybe you will ignore the keys. |
||
2760 | * </p> |
||
2761 | * |
||
2762 | * @return array |
||
2763 | * |
||
2764 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
2765 | * @psalm-mutation-free |
||
2766 | * |
||
2767 | * @see Arrayy::toArray() |
||
2768 | */ |
||
2769 | 500 | public function getArray( |
|
2778 | |||
2779 | /** |
||
2780 | * @param string $json |
||
2781 | * |
||
2782 | * @return $this |
||
2783 | */ |
||
2784 | 3 | public static function createFromJsonMapper(string $json) |
|
2800 | |||
2801 | /** |
||
2802 | * @return array<int|string,TypeCheckInterface>|mixed|TypeCheckArray<int|string,TypeCheckInterface>|TypeInterface |
||
2803 | * |
||
2804 | * @internal |
||
2805 | */ |
||
2806 | 6 | public function getPhpDocPropertiesFromClass() |
|
2814 | |||
2815 | /** |
||
2816 | * Get the current array from the "Arrayy"-object as list. |
||
2817 | * |
||
2818 | * alias for "toList()" |
||
2819 | * |
||
2820 | * @param bool $convertAllArrayyElements <p> |
||
2821 | * Convert all Child-"Arrayy" objects also to arrays. |
||
2822 | * </p> |
||
2823 | * |
||
2824 | * @return array |
||
2825 | * |
||
2826 | * @psalm-return array<int,mixed>|array<int,T> |
||
2827 | * @psalm-mutation-free |
||
2828 | * |
||
2829 | * @see Arrayy::toList() |
||
2830 | */ |
||
2831 | 1 | public function getList(bool $convertAllArrayyElements = false): array |
|
2835 | |||
2836 | /** |
||
2837 | * Returns the values from a single column of the input array, identified by |
||
2838 | * the $columnKey, can be used to extract data-columns from multi-arrays. |
||
2839 | * |
||
2840 | * Info: Optionally, you may provide an $indexKey to index the values in the returned |
||
2841 | * array by the values from the $indexKey column in the input array. |
||
2842 | * |
||
2843 | * @param mixed $columnKey |
||
2844 | * @param mixed $indexKey |
||
2845 | * |
||
2846 | * @return static |
||
2847 | * <p>(Immutable)</p> |
||
2848 | * |
||
2849 | * @psalm-return static<TKey,T> |
||
2850 | * @psalm-mutation-free |
||
2851 | */ |
||
2852 | 1 | public function getColumn($columnKey = null, $indexKey = null): self |
|
2860 | |||
2861 | /** |
||
2862 | * Get the current array from the "Arrayy"-object as generator by reference. |
||
2863 | * |
||
2864 | * @return \Generator |
||
2865 | * |
||
2866 | * @psalm-return \Generator<mixed,T>|\Generator<TKey,T> |
||
2867 | */ |
||
2868 | 75 | public function &getGeneratorByReference(): \Generator |
|
2887 | |||
2888 | /** |
||
2889 | * Get the current array from the "Arrayy"-object as generator. |
||
2890 | * |
||
2891 | * @return \Generator |
||
2892 | * |
||
2893 | * @psalm-return \Generator<mixed,T>|\Generator<TKey,T> |
||
2894 | * @psalm-mutation-free |
||
2895 | */ |
||
2896 | 998 | public function getGenerator(): \Generator |
|
2906 | |||
2907 | /** |
||
2908 | * alias: for "Arrayy->keys()" |
||
2909 | * |
||
2910 | * @return static |
||
2911 | * <p>(Immutable)</p> |
||
2912 | * |
||
2913 | * @see Arrayy::keys() |
||
2914 | * |
||
2915 | * @psalm-return static<array-key,TKey> |
||
2916 | * @psalm-mutation-free |
||
2917 | */ |
||
2918 | 2 | public function getKeys() |
|
2922 | |||
2923 | /** |
||
2924 | * Get the current array from the "Arrayy"-object as object. |
||
2925 | * |
||
2926 | * @return \stdClass |
||
2927 | */ |
||
2928 | 4 | public function getObject(): \stdClass |
|
2932 | |||
2933 | /** |
||
2934 | * alias: for "Arrayy->randomImmutable()" |
||
2935 | * |
||
2936 | * @return static |
||
2937 | * <p>(Immutable)</p> |
||
2938 | * |
||
2939 | * @see Arrayy::randomImmutable() |
||
2940 | * |
||
2941 | * @psalm-return static<int|array-key,T> |
||
2942 | */ |
||
2943 | 4 | public function getRandom(): self |
|
2947 | |||
2948 | /** |
||
2949 | * alias: for "Arrayy->randomKey()" |
||
2950 | * |
||
2951 | * @return mixed |
||
2952 | * <p>Get a key/index or null if there wasn't a key/index.</p> |
||
2953 | * |
||
2954 | * @see Arrayy::randomKey() |
||
2955 | */ |
||
2956 | 3 | public function getRandomKey() |
|
2960 | |||
2961 | /** |
||
2962 | * alias: for "Arrayy->randomKeys()" |
||
2963 | * |
||
2964 | * @param int $number |
||
2965 | * |
||
2966 | * @return static |
||
2967 | * <p>(Immutable)</p> |
||
2968 | * |
||
2969 | * @see Arrayy::randomKeys() |
||
2970 | * |
||
2971 | * @psalm-return static<TKey,T> |
||
2972 | */ |
||
2973 | 8 | public function getRandomKeys(int $number): self |
|
2977 | |||
2978 | /** |
||
2979 | * alias: for "Arrayy->randomValue()" |
||
2980 | * |
||
2981 | * @return mixed |
||
2982 | * <p>Get a random value or null if there wasn't a value.</p> |
||
2983 | * |
||
2984 | * @see Arrayy::randomValue() |
||
2985 | */ |
||
2986 | 3 | public function getRandomValue() |
|
2990 | |||
2991 | /** |
||
2992 | * alias: for "Arrayy->randomValues()" |
||
2993 | * |
||
2994 | * @param int $number |
||
2995 | * |
||
2996 | * @return static |
||
2997 | * <p>(Immutable)</p> |
||
2998 | * |
||
2999 | * @see Arrayy::randomValues() |
||
3000 | * |
||
3001 | * @psalm-return static<TKey,T> |
||
3002 | */ |
||
3003 | 6 | public function getRandomValues(int $number): self |
|
3007 | |||
3008 | /** |
||
3009 | * Gets all values. |
||
3010 | * |
||
3011 | * @return static |
||
3012 | * <p>The values of all elements in this array, in the order they |
||
3013 | * appear in the array.</p> |
||
3014 | * |
||
3015 | * @psalm-return static<TKey,T> |
||
3016 | */ |
||
3017 | 4 | public function getValues() |
|
3027 | |||
3028 | /** |
||
3029 | * Gets all values via Generator. |
||
3030 | * |
||
3031 | * @return \Generator |
||
3032 | * <p>The values of all elements in this array, in the order they |
||
3033 | * appear in the array as Generator.</p> |
||
3034 | * |
||
3035 | * @psalm-return \Generator<TKey,T> |
||
3036 | */ |
||
3037 | 4 | public function getValuesYield(): \Generator |
|
3041 | |||
3042 | /** |
||
3043 | * Group values from a array according to the results of a closure. |
||
3044 | * |
||
3045 | * @param callable|string $grouper <p>A callable function name.</p> |
||
3046 | * @param bool $saveKeys |
||
3047 | * |
||
3048 | * @return static |
||
3049 | * <p>(Immutable)</p> |
||
3050 | * |
||
3051 | * @psalm-return static<TKey,T> |
||
3052 | * @psalm-mutation-free |
||
3053 | */ |
||
3054 | 4 | public function group($grouper, bool $saveKeys = false): self |
|
3095 | |||
3096 | /** |
||
3097 | * Check if an array has a given key. |
||
3098 | * |
||
3099 | * @param mixed $key |
||
3100 | * |
||
3101 | * @return bool |
||
3102 | */ |
||
3103 | 30 | public function has($key): bool |
|
3129 | |||
3130 | /** |
||
3131 | * Check if an array has a given value. |
||
3132 | * |
||
3133 | * INFO: if you need to search recursive please use ```contains()``` |
||
3134 | * |
||
3135 | * @param mixed $value |
||
3136 | * |
||
3137 | * @return bool |
||
3138 | */ |
||
3139 | 1 | public function hasValue($value): bool |
|
3143 | |||
3144 | /** |
||
3145 | * Implodes the values of this array. |
||
3146 | * |
||
3147 | * @param string $glue |
||
3148 | * @param string $prefix |
||
3149 | * |
||
3150 | * @return string |
||
3151 | * @psalm-mutation-free |
||
3152 | */ |
||
3153 | 28 | public function implode(string $glue = '', string $prefix = ''): string |
|
3157 | |||
3158 | /** |
||
3159 | * Implodes the keys of this array. |
||
3160 | * |
||
3161 | * @param string $glue |
||
3162 | * |
||
3163 | * @return string |
||
3164 | * @psalm-mutation-free |
||
3165 | */ |
||
3166 | 8 | public function implodeKeys(string $glue = ''): string |
|
3170 | |||
3171 | /** |
||
3172 | * Given a list and an iterate-function that returns |
||
3173 | * a key for each element in the list (or a property name), |
||
3174 | * returns an object with an index of each item. |
||
3175 | * |
||
3176 | * @param mixed $key |
||
3177 | * |
||
3178 | * @return static |
||
3179 | * <p>(Immutable)</p> |
||
3180 | * |
||
3181 | * @psalm-return static<TKey,T> |
||
3182 | * @psalm-mutation-free |
||
3183 | */ |
||
3184 | 4 | View Code Duplication | public function indexBy($key): self |
3201 | |||
3202 | /** |
||
3203 | * alias: for "Arrayy->searchIndex()" |
||
3204 | * |
||
3205 | * @param mixed $value <p>The value to search for.</p> |
||
3206 | * |
||
3207 | * @return false|mixed |
||
3208 | * |
||
3209 | * @see Arrayy::searchIndex() |
||
3210 | */ |
||
3211 | 4 | public function indexOf($value) |
|
3215 | |||
3216 | /** |
||
3217 | * Get everything but the last..$to items. |
||
3218 | * |
||
3219 | * @param int $to |
||
3220 | * |
||
3221 | * @return static |
||
3222 | * <p>(Immutable)</p> |
||
3223 | * |
||
3224 | * @psalm-return static<TKey,T> |
||
3225 | * @psalm-mutation-free |
||
3226 | */ |
||
3227 | 12 | public function initial(int $to = 1): self |
|
3231 | |||
3232 | /** |
||
3233 | * Return an array with all elements found in input array. |
||
3234 | * |
||
3235 | * @param array $search |
||
3236 | * @param bool $keepKeys |
||
3237 | * |
||
3238 | * @return static |
||
3239 | * <p>(Immutable)</p> |
||
3240 | * |
||
3241 | * @psalm-param array<mixed,mixed>|array<TKey,T> $search |
||
3242 | * @psalm-return static<TKey,T> |
||
3243 | * @psalm-mutation-free |
||
3244 | */ |
||
3245 | 4 | public function intersection(array $search, bool $keepKeys = false): self |
|
3271 | |||
3272 | /** |
||
3273 | * Return an array with all elements found in input array. |
||
3274 | * |
||
3275 | * @param array ...$array |
||
3276 | * |
||
3277 | * @return static |
||
3278 | * <p>(Immutable)</p> |
||
3279 | * |
||
3280 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$array |
||
3281 | * @psalm-return static<TKey,T> |
||
3282 | * @psalm-mutation-free |
||
3283 | */ |
||
3284 | 1 | public function intersectionMulti(...$array): self |
|
3292 | |||
3293 | /** |
||
3294 | * Return a boolean flag which indicates whether the two input arrays have any common elements. |
||
3295 | * |
||
3296 | * @param array $search |
||
3297 | * |
||
3298 | * @return bool |
||
3299 | * |
||
3300 | * @psalm-param array<mixed,mixed>|array<TKey,T> $search |
||
3301 | */ |
||
3302 | 1 | public function intersects(array $search): bool |
|
3306 | |||
3307 | /** |
||
3308 | * Invoke a function on all of an array's values. |
||
3309 | * |
||
3310 | * @param callable $callable |
||
3311 | * @param mixed $arguments |
||
3312 | * |
||
3313 | * @return static |
||
3314 | * <p>(Immutable)</p> |
||
3315 | * |
||
3316 | * @psalm-param callable(T=,mixed):mixed $callable |
||
3317 | * @psalm-return static<TKey,T> |
||
3318 | * @psalm-mutation-free |
||
3319 | */ |
||
3320 | 1 | View Code Duplication | public function invoke($callable, $arguments = []): self |
3344 | |||
3345 | /** |
||
3346 | * Check whether array is associative or not. |
||
3347 | * |
||
3348 | * @param bool $recursive |
||
3349 | * |
||
3350 | * @return bool |
||
3351 | * <p>Returns true if associative, false otherwise.</p> |
||
3352 | */ |
||
3353 | 15 | View Code Duplication | public function isAssoc(bool $recursive = false): bool |
3368 | |||
3369 | /** |
||
3370 | * Check if a given key or keys are empty. |
||
3371 | * |
||
3372 | * @param int|int[]|string|string[]|null $keys |
||
3373 | * |
||
3374 | * @return bool |
||
3375 | * <p>Returns true if empty, false otherwise.</p> |
||
3376 | * @psalm-mutation-free |
||
3377 | */ |
||
3378 | 45 | public function isEmpty($keys = null): bool |
|
3396 | |||
3397 | /** |
||
3398 | * Check if the current array is equal to the given "$array" or not. |
||
3399 | * |
||
3400 | * @param array $array |
||
3401 | * |
||
3402 | * @return bool |
||
3403 | * |
||
3404 | * @psalm-param array<mixed,mixed> $array |
||
3405 | */ |
||
3406 | 1 | public function isEqual(array $array): bool |
|
3410 | |||
3411 | /** |
||
3412 | * Check if the current array is a multi-array. |
||
3413 | * |
||
3414 | * @return bool |
||
3415 | */ |
||
3416 | 22 | public function isMultiArray(): bool |
|
3424 | |||
3425 | /** |
||
3426 | * Check whether array is numeric or not. |
||
3427 | * |
||
3428 | * @return bool |
||
3429 | * <p>Returns true if numeric, false otherwise.</p> |
||
3430 | */ |
||
3431 | 5 | View Code Duplication | public function isNumeric(): bool |
3446 | |||
3447 | /** |
||
3448 | * Check if the current array is sequential [0, 1, 2, 3, 4, 5 ...] or not. |
||
3449 | * |
||
3450 | * @param bool $recursive |
||
3451 | * |
||
3452 | * @return bool |
||
3453 | * @psalm-mutation-free |
||
3454 | */ |
||
3455 | 9 | public function isSequential(bool $recursive = false): bool |
|
3472 | |||
3473 | /** |
||
3474 | * @return array |
||
3475 | * |
||
3476 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
3477 | */ |
||
3478 | 2 | public function jsonSerialize(): array |
|
3482 | |||
3483 | /** |
||
3484 | * Gets the key/index of the element at the current internal iterator position. |
||
3485 | * |
||
3486 | * @return int|string|null |
||
3487 | */ |
||
3488 | public function key() |
||
3492 | |||
3493 | /** |
||
3494 | * Checks if the given key exists in the provided array. |
||
3495 | * |
||
3496 | * INFO: This method only use "array_key_exists()" if you want to use "dot"-notation, |
||
3497 | * then you need to use "Arrayy->offsetExists()". |
||
3498 | * |
||
3499 | * @param int|string $key the key to look for |
||
3500 | * |
||
3501 | * @return bool |
||
3502 | * @psalm-mutation-free |
||
3503 | */ |
||
3504 | 164 | public function keyExists($key): bool |
|
3508 | |||
3509 | /** |
||
3510 | * Get all keys from the current array. |
||
3511 | * |
||
3512 | * @param bool $recursive [optional] <p> |
||
3513 | * Get all keys, also from all sub-arrays from an multi-dimensional array. |
||
3514 | * </p> |
||
3515 | * @param mixed|null $search_values [optional] <p> |
||
3516 | * If specified, then only keys containing these values are returned. |
||
3517 | * </p> |
||
3518 | * @param bool $strict [optional] <p> |
||
3519 | * Determines if strict comparison (===) should be used during the search. |
||
3520 | * </p> |
||
3521 | * |
||
3522 | * @return static |
||
3523 | * <p>(Immutable) An array of all the keys in input.</p> |
||
3524 | * |
||
3525 | * @psalm-return static<array-key,TKey> |
||
3526 | * @psalm-mutation-free |
||
3527 | */ |
||
3528 | 29 | public function keys( |
|
3599 | |||
3600 | /** |
||
3601 | * Sort an array by key in reverse order. |
||
3602 | * |
||
3603 | * @param int $sort_flags [optional] <p> |
||
3604 | * You may modify the behavior of the sort using the optional |
||
3605 | * parameter sort_flags, for details |
||
3606 | * see sort. |
||
3607 | * </p> |
||
3608 | * |
||
3609 | * @return $this |
||
3610 | * <p>(Mutable) Return this Arrayy object.</p> |
||
3611 | * |
||
3612 | * @psalm-return static<TKey,T> |
||
3613 | */ |
||
3614 | 4 | public function krsort(int $sort_flags = 0): self |
|
3622 | |||
3623 | /** |
||
3624 | * Sort an array by key in reverse order. |
||
3625 | * |
||
3626 | * @param int $sort_flags [optional] <p> |
||
3627 | * You may modify the behavior of the sort using the optional |
||
3628 | * parameter sort_flags, for details |
||
3629 | * see sort. |
||
3630 | * </p> |
||
3631 | * |
||
3632 | * @return $this |
||
3633 | * <p>(Immutable) Return this Arrayy object.</p> |
||
3634 | * |
||
3635 | * @psalm-return static<TKey,T> |
||
3636 | * @psalm-mutation-free |
||
3637 | */ |
||
3638 | 4 | public function krsortImmutable(int $sort_flags = 0): self |
|
3649 | |||
3650 | /** |
||
3651 | * Get the last value from the current array. |
||
3652 | * |
||
3653 | * @return mixed|null |
||
3654 | * <p>Return null if there wasn't a element.</p> |
||
3655 | * @psalm-mutation-free |
||
3656 | */ |
||
3657 | 17 | public function last() |
|
3666 | |||
3667 | /** |
||
3668 | * Get the last key from the current array. |
||
3669 | * |
||
3670 | * @return mixed|null |
||
3671 | * <p>Return null if there wasn't a element.</p> |
||
3672 | * @psalm-mutation-free |
||
3673 | */ |
||
3674 | 21 | public function lastKey() |
|
3680 | |||
3681 | /** |
||
3682 | * Get the last value(s) from the current array. |
||
3683 | * |
||
3684 | * @param int|null $number |
||
3685 | * |
||
3686 | * @return static |
||
3687 | * <p>(Immutable)</p> |
||
3688 | * |
||
3689 | * @psalm-return static<TKey,T> |
||
3690 | * @psalm-mutation-free |
||
3691 | */ |
||
3692 | 13 | public function lastsImmutable(int $number = null): self |
|
3722 | |||
3723 | /** |
||
3724 | * Get the last value(s) from the current array. |
||
3725 | * |
||
3726 | * @param int|null $number |
||
3727 | * |
||
3728 | * @return $this |
||
3729 | * <p>(Mutable)</p> |
||
3730 | * |
||
3731 | * @psalm-return static<TKey,T> |
||
3732 | */ |
||
3733 | 13 | public function lastsMutable(int $number = null): self |
|
3761 | |||
3762 | /** |
||
3763 | * Count the values from the current array. |
||
3764 | * |
||
3765 | * alias: for "Arrayy->count()" |
||
3766 | * |
||
3767 | * @param int $mode |
||
3768 | * |
||
3769 | * @return int |
||
3770 | * |
||
3771 | * @see Arrayy::count() |
||
3772 | */ |
||
3773 | 20 | public function length(int $mode = \COUNT_NORMAL): int |
|
3777 | |||
3778 | /** |
||
3779 | * Apply the given function to the every element of the array, |
||
3780 | * collecting the results. |
||
3781 | * |
||
3782 | * @param callable $callable |
||
3783 | * @param bool $useKeyAsSecondParameter |
||
3784 | * @param mixed ...$arguments |
||
3785 | * |
||
3786 | * @return static |
||
3787 | * <p>(Immutable) Arrayy object with modified elements.</p> |
||
3788 | * |
||
3789 | * @psalm-param callable(T,TKey=,mixed=):mixed $callable |
||
3790 | * @psalm-return static<TKey,T> |
||
3791 | * @psalm-mutation-free |
||
3792 | */ |
||
3793 | 5 | public function map( |
|
3826 | |||
3827 | /** |
||
3828 | * Check if all items in current array match a truth test. |
||
3829 | * |
||
3830 | * @param \Closure $closure |
||
3831 | * |
||
3832 | * @return bool |
||
3833 | */ |
||
3834 | 15 | View Code Duplication | public function matches(\Closure $closure): bool |
3850 | |||
3851 | /** |
||
3852 | * Check if any item in the current array matches a truth test. |
||
3853 | * |
||
3854 | * @param \Closure $closure |
||
3855 | * |
||
3856 | * @return bool |
||
3857 | */ |
||
3858 | 14 | View Code Duplication | public function matchesAny(\Closure $closure): bool |
3874 | |||
3875 | /** |
||
3876 | * Get the max value from an array. |
||
3877 | * |
||
3878 | * @return false|mixed |
||
3879 | * <p>Will return false if there are no values.</p> |
||
3880 | */ |
||
3881 | 10 | View Code Duplication | public function max() |
3901 | |||
3902 | /** |
||
3903 | * Merge the new $array into the current array. |
||
3904 | * |
||
3905 | * - keep key,value from the current array, also if the index is in the new $array |
||
3906 | * |
||
3907 | * @param array $array |
||
3908 | * @param bool $recursive |
||
3909 | * |
||
3910 | * @return static |
||
3911 | * <p>(Immutable)</p> |
||
3912 | * |
||
3913 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
3914 | * @psalm-return static<int|TKey,T> |
||
3915 | * @psalm-mutation-free |
||
3916 | */ |
||
3917 | 32 | View Code Duplication | public function mergeAppendKeepIndex(array $array = [], bool $recursive = false): self |
3932 | |||
3933 | /** |
||
3934 | * Merge the new $array into the current array. |
||
3935 | * |
||
3936 | * - replace duplicate assoc-keys from the current array with the key,values from the new $array |
||
3937 | * - create new indexes |
||
3938 | * |
||
3939 | * @param array $array |
||
3940 | * @param bool $recursive |
||
3941 | * |
||
3942 | * @return static |
||
3943 | * <p>(Immutable)</p> |
||
3944 | * |
||
3945 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
3946 | * @psalm-return static<TKey,T> |
||
3947 | * @psalm-mutation-free |
||
3948 | */ |
||
3949 | 19 | View Code Duplication | public function mergeAppendNewIndex(array $array = [], bool $recursive = false): self |
3964 | |||
3965 | /** |
||
3966 | * Merge the the current array into the $array. |
||
3967 | * |
||
3968 | * - use key,value from the new $array, also if the index is in the current array |
||
3969 | * |
||
3970 | * @param array $array |
||
3971 | * @param bool $recursive |
||
3972 | * |
||
3973 | * @return static |
||
3974 | * <p>(Immutable)</p> |
||
3975 | * |
||
3976 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
3977 | * @psalm-return static<TKey,T> |
||
3978 | * @psalm-mutation-free |
||
3979 | */ |
||
3980 | 16 | View Code Duplication | public function mergePrependKeepIndex(array $array = [], bool $recursive = false): self |
3995 | |||
3996 | /** |
||
3997 | * Merge the current array into the new $array. |
||
3998 | * |
||
3999 | * - replace duplicate assoc-keys from new $array with the key,values from the current array |
||
4000 | * - create new indexes |
||
4001 | * |
||
4002 | * @param array $array |
||
4003 | * @param bool $recursive |
||
4004 | * |
||
4005 | * @return static |
||
4006 | * <p>(Immutable)</p> |
||
4007 | * |
||
4008 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
4009 | * @psalm-return static<TKey,T> |
||
4010 | * @psalm-mutation-free |
||
4011 | */ |
||
4012 | 20 | View Code Duplication | public function mergePrependNewIndex(array $array = [], bool $recursive = false): self |
4027 | |||
4028 | /** |
||
4029 | * @return ArrayyMeta|static |
||
4030 | */ |
||
4031 | 18 | public static function meta() |
|
4035 | |||
4036 | /** |
||
4037 | * Get the min value from an array. |
||
4038 | * |
||
4039 | * @return false|mixed |
||
4040 | * <p>Will return false if there are no values.</p> |
||
4041 | */ |
||
4042 | 10 | View Code Duplication | public function min() |
4062 | |||
4063 | /** |
||
4064 | * Get the most used value from the array. |
||
4065 | * |
||
4066 | * @return mixed|null |
||
4067 | * <p>(Immutable) Return null if there wasn't a element.</p> |
||
4068 | * @psalm-mutation-free |
||
4069 | */ |
||
4070 | 3 | public function mostUsedValue() |
|
4074 | |||
4075 | /** |
||
4076 | * Get the most used value from the array. |
||
4077 | * |
||
4078 | * @param int|null $number <p>How many values you will take?</p> |
||
4079 | * |
||
4080 | * @return static |
||
4081 | * <p>(Immutable)</p> |
||
4082 | * |
||
4083 | * @psalm-return static<TKey,T> |
||
4084 | * @psalm-mutation-free |
||
4085 | */ |
||
4086 | 3 | public function mostUsedValues(int $number = null): self |
|
4090 | |||
4091 | /** |
||
4092 | * Move an array element to a new index. |
||
4093 | * |
||
4094 | * cherry-picked from: http://stackoverflow.com/questions/12624153/move-an-array-element-to-a-new-index-in-php |
||
4095 | * |
||
4096 | * @param int|string $from |
||
4097 | * @param int $to |
||
4098 | * |
||
4099 | * @return static |
||
4100 | * <p>(Immutable)</p> |
||
4101 | * |
||
4102 | * @psalm-return static<TKey,T> |
||
4103 | * @psalm-mutation-free |
||
4104 | */ |
||
4105 | 1 | public function moveElement($from, $to): self |
|
4138 | |||
4139 | /** |
||
4140 | * Move an array element to the first place. |
||
4141 | * |
||
4142 | * INFO: Instead of "Arrayy->moveElement()" this method will NOT |
||
4143 | * loss the keys of an indexed array. |
||
4144 | * |
||
4145 | * @param int|string $key |
||
4146 | * |
||
4147 | * @return static |
||
4148 | * <p>(Immutable)</p> |
||
4149 | * |
||
4150 | * @psalm-return static<TKey,T> |
||
4151 | * @psalm-mutation-free |
||
4152 | */ |
||
4153 | 1 | View Code Duplication | public function moveElementToFirstPlace($key): self |
4169 | |||
4170 | /** |
||
4171 | * Move an array element to the last place. |
||
4172 | * |
||
4173 | * INFO: Instead of "Arrayy->moveElement()" this method will NOT |
||
4174 | * loss the keys of an indexed array. |
||
4175 | * |
||
4176 | * @param int|string $key |
||
4177 | * |
||
4178 | * @return static |
||
4179 | * <p>(Immutable)</p> |
||
4180 | * |
||
4181 | * @psalm-return static<TKey,T> |
||
4182 | * @psalm-mutation-free |
||
4183 | */ |
||
4184 | 1 | View Code Duplication | public function moveElementToLastPlace($key): self |
4200 | |||
4201 | /** |
||
4202 | * Moves the internal iterator position to the next element and returns this element. |
||
4203 | * |
||
4204 | * @return false|mixed |
||
4205 | * <p>(Mutable) Will return false if there are no values.</p> |
||
4206 | */ |
||
4207 | public function next() |
||
4211 | |||
4212 | /** |
||
4213 | * Get the next nth keys and values from the array. |
||
4214 | * |
||
4215 | * @param int $step |
||
4216 | * @param int $offset |
||
4217 | * |
||
4218 | * @return static |
||
4219 | * <p>(Immutable)</p> |
||
4220 | * |
||
4221 | * @psalm-return static<TKey,T> |
||
4222 | * @psalm-mutation-free |
||
4223 | */ |
||
4224 | 1 | public function nth(int $step, int $offset = 0): self |
|
4243 | |||
4244 | /** |
||
4245 | * Get a subset of the items from the given array. |
||
4246 | * |
||
4247 | * @param int[]|string[] $keys |
||
4248 | * |
||
4249 | * @return static |
||
4250 | * <p>(Immutable)</p> |
||
4251 | * |
||
4252 | * @psalm-param array-key[] $keys |
||
4253 | * @psalm-return static<TKey,T> |
||
4254 | * @psalm-mutation-free |
||
4255 | */ |
||
4256 | 1 | View Code Duplication | public function only(array $keys): self |
4274 | |||
4275 | /** |
||
4276 | * Pad array to the specified size with a given value. |
||
4277 | * |
||
4278 | * @param int $size <p>Size of the result array.</p> |
||
4279 | * @param mixed $value <p>Empty value by default.</p> |
||
4280 | * |
||
4281 | * @return static |
||
4282 | * <p>(Immutable) Arrayy object padded to $size with $value.</p> |
||
4283 | * |
||
4284 | * @psalm-return static<TKey,T> |
||
4285 | * @psalm-mutation-free |
||
4286 | */ |
||
4287 | 5 | public function pad(int $size, $value): self |
|
4295 | |||
4296 | /** |
||
4297 | * Partitions this array in two array according to a predicate. |
||
4298 | * Keys are preserved in the resulting array. |
||
4299 | * |
||
4300 | * @param \Closure $closure |
||
4301 | * <p>The predicate on which to partition.</p> |
||
4302 | * |
||
4303 | * @return array<int, static> |
||
4304 | * <p>An array with two elements. The first element contains the array |
||
4305 | * of elements where the predicate returned TRUE, the second element |
||
4306 | * contains the array of elements where the predicate returned FALSE.</p> |
||
4307 | * |
||
4308 | * @psalm-return array<int, static<TKey,T>> |
||
4309 | */ |
||
4310 | 1 | public function partition(\Closure $closure): array |
|
4326 | |||
4327 | /** |
||
4328 | * Pop a specified value off the end of the current array. |
||
4329 | * |
||
4330 | * @return mixed|null |
||
4331 | * <p>(Mutable) The popped element from the current array or null if the array is e.g. empty.</p> |
||
4332 | */ |
||
4333 | 5 | public function pop() |
|
4339 | |||
4340 | /** |
||
4341 | * Prepend a (key) + value to the current array. |
||
4342 | * |
||
4343 | * EXAMPLE: <code> |
||
4344 | * a(['fòô' => 'bàř'])->prepend('foo'); // Arrayy[0 => 'foo', 'fòô' => 'bàř'] |
||
4345 | * </code> |
||
4346 | * |
||
4347 | * @param mixed $value |
||
4348 | * @param mixed $key |
||
4349 | * |
||
4350 | * @return $this |
||
4351 | * <p>(Mutable) Return this Arrayy object, with the prepended value.</p> |
||
4352 | * |
||
4353 | * @psalm-return static<TKey,T> |
||
4354 | */ |
||
4355 | 11 | public function prepend($value, $key = null) |
|
4371 | |||
4372 | /** |
||
4373 | * Prepend a (key) + value to the current array. |
||
4374 | * |
||
4375 | * EXAMPLE: <code> |
||
4376 | * a(['fòô' => 'bàř'])->prependImmutable('foo')->getArray(); // [0 => 'foo', 'fòô' => 'bàř'] |
||
4377 | * </code> |
||
4378 | * |
||
4379 | * @param mixed $value |
||
4380 | * @param mixed $key |
||
4381 | * |
||
4382 | * @return $this |
||
4383 | * <p>(Immutable) Return this Arrayy object, with the prepended value.</p> |
||
4384 | * |
||
4385 | * @psalm-return static<TKey,T> |
||
4386 | * @psalm-mutation-free |
||
4387 | */ |
||
4388 | 1 | View Code Duplication | public function prependImmutable($value, $key = null) |
4413 | |||
4414 | /** |
||
4415 | * Add a suffix to each key. |
||
4416 | * |
||
4417 | * @param mixed $suffix |
||
4418 | * |
||
4419 | * @return static |
||
4420 | * <p>(Immutable) Return an Arrayy object, with the prepended keys.</p> |
||
4421 | * |
||
4422 | * @psalm-return static<TKey,T> |
||
4423 | * @psalm-mutation-free |
||
4424 | */ |
||
4425 | 10 | View Code Duplication | public function prependToEachKey($suffix): self |
4451 | |||
4452 | /** |
||
4453 | * Add a suffix to each value. |
||
4454 | * |
||
4455 | * @param mixed $suffix |
||
4456 | * |
||
4457 | * @return static |
||
4458 | * <p>(Immutable) Return an Arrayy object, with the prepended values.</p> |
||
4459 | * |
||
4460 | * @psalm-return static<TKey,T> |
||
4461 | * @psalm-mutation-free |
||
4462 | */ |
||
4463 | 10 | View Code Duplication | public function prependToEachValue($suffix): self |
4491 | |||
4492 | /** |
||
4493 | * Return the value of a given key and |
||
4494 | * delete the key. |
||
4495 | * |
||
4496 | * @param int|int[]|string|string[]|null $keyOrKeys |
||
4497 | * @param mixed $fallback |
||
4498 | * |
||
4499 | * @return mixed |
||
4500 | */ |
||
4501 | 5 | public function pull($keyOrKeys = null, $fallback = null) |
|
4523 | |||
4524 | /** |
||
4525 | * Push one or more values onto the end of array at once. |
||
4526 | * |
||
4527 | * @param array ...$args |
||
4528 | * |
||
4529 | * @return $this |
||
4530 | * <p>(Mutable) Return this Arrayy object, with pushed elements to the end of array.</p> |
||
4531 | * |
||
4532 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
4533 | * |
||
4534 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$args |
||
4535 | * @psalm-return static<TKey,T> |
||
4536 | */ |
||
4537 | 7 | public function push(...$args) |
|
4555 | |||
4556 | /** |
||
4557 | * Get a random value from the current array. |
||
4558 | * |
||
4559 | * @param int|null $number <p>How many values you will take?</p> |
||
4560 | * |
||
4561 | * @return static |
||
4562 | * <p>(Immutable)</p> |
||
4563 | * |
||
4564 | * @psalm-return static<int|array-key,T> |
||
4565 | */ |
||
4566 | 19 | public function randomImmutable(int $number = null): self |
|
4599 | |||
4600 | /** |
||
4601 | * Pick a random key/index from the keys of this array. |
||
4602 | * |
||
4603 | * @throws \RangeException If array is empty |
||
4604 | * |
||
4605 | * @return mixed |
||
4606 | * <p>Get a key/index or null if there wasn't a key/index.</p> |
||
4607 | */ |
||
4608 | 4 | public function randomKey() |
|
4618 | |||
4619 | /** |
||
4620 | * Pick a given number of random keys/indexes out of this array. |
||
4621 | * |
||
4622 | * @param int $number <p>The number of keys/indexes (should be <= \count($this->array))</p> |
||
4623 | * |
||
4624 | * @throws \RangeException If array is empty |
||
4625 | * |
||
4626 | * @return static |
||
4627 | * <p>(Immutable)</p> |
||
4628 | * |
||
4629 | * @psalm-return static<TKey,T> |
||
4630 | */ |
||
4631 | 13 | public function randomKeys(int $number): self |
|
4659 | |||
4660 | /** |
||
4661 | * Get a random value from the current array. |
||
4662 | * |
||
4663 | * @param int|null $number <p>How many values you will take?</p> |
||
4664 | * |
||
4665 | * @return $this |
||
4666 | * <p>(Mutable) Return this Arrayy object.</p> |
||
4667 | * |
||
4668 | * @psalm-return static<TKey,T> |
||
4669 | */ |
||
4670 | 17 | public function randomMutable(int $number = null): self |
|
4695 | |||
4696 | /** |
||
4697 | * Pick a random value from the values of this array. |
||
4698 | * |
||
4699 | * @return mixed |
||
4700 | * <p>Get a random value or null if there wasn't a value.</p> |
||
4701 | */ |
||
4702 | 4 | public function randomValue() |
|
4712 | |||
4713 | /** |
||
4714 | * Pick a given number of random values out of this array. |
||
4715 | * |
||
4716 | * @param int $number |
||
4717 | * |
||
4718 | * @return static |
||
4719 | * <p>(Mutable)</p> |
||
4720 | * |
||
4721 | * @psalm-return static<TKey,T> |
||
4722 | */ |
||
4723 | 7 | public function randomValues(int $number): self |
|
4727 | |||
4728 | /** |
||
4729 | * Get a random value from an array, with the ability to skew the results. |
||
4730 | * |
||
4731 | * Example: randomWeighted(['foo' => 1, 'bar' => 2]) has a 66% chance of returning bar. |
||
4732 | * |
||
4733 | * @param array $array |
||
4734 | * @param int|null $number <p>How many values you will take?</p> |
||
4735 | * |
||
4736 | * @return static<int,mixed> |
||
4737 | * <p>(Immutable)</p> |
||
4738 | * |
||
4739 | * @psalm-param array<mixed,mixed> $array |
||
4740 | * @psalm-return static<int|array-key,T> |
||
4741 | */ |
||
4742 | 9 | public function randomWeighted(array $array, int $number = null): self |
|
4757 | |||
4758 | /** |
||
4759 | * Reduce the current array via callable e.g. anonymous-function. |
||
4760 | * |
||
4761 | * @param callable $callable |
||
4762 | * @param mixed $init |
||
4763 | * |
||
4764 | * @return static |
||
4765 | * <p>(Immutable)</p> |
||
4766 | * |
||
4767 | * @psalm-return static<TKey,T> |
||
4768 | * @psalm-mutation-free |
||
4769 | */ |
||
4770 | 18 | public function reduce($callable, $init = []): self |
|
4800 | |||
4801 | /** |
||
4802 | * @param bool $unique |
||
4803 | * |
||
4804 | * @return static |
||
4805 | * <p>(Immutable)</p> |
||
4806 | * |
||
4807 | * @psalm-return static<TKey,T> |
||
4808 | * @psalm-mutation-free |
||
4809 | */ |
||
4810 | 14 | public function reduce_dimension(bool $unique = true): self |
|
4833 | |||
4834 | /** |
||
4835 | * Create a numerically re-indexed Arrayy object. |
||
4836 | * |
||
4837 | * @return $this |
||
4838 | * <p>(Mutable) Return this Arrayy object, with re-indexed array-elements.</p> |
||
4839 | * |
||
4840 | * @psalm-return static<TKey,T> |
||
4841 | */ |
||
4842 | 9 | public function reindex(): self |
|
4850 | |||
4851 | /** |
||
4852 | * Return all items that fail the truth test. |
||
4853 | * |
||
4854 | * @param \Closure $closure |
||
4855 | * |
||
4856 | * @return static |
||
4857 | * <p>(Immutable)</p> |
||
4858 | * |
||
4859 | * @psalm-return static<TKey,T> |
||
4860 | * @psalm-mutation-free |
||
4861 | */ |
||
4862 | 1 | View Code Duplication | public function reject(\Closure $closure): self |
4879 | |||
4880 | /** |
||
4881 | * Remove a value from the current array (optional using dot-notation). |
||
4882 | * |
||
4883 | * @param mixed $key |
||
4884 | * |
||
4885 | * @return static |
||
4886 | * <p>(Mutable)</p> |
||
4887 | * |
||
4888 | * @psalm-param TKey $key |
||
4889 | * @psalm-return static<TKey,T> |
||
4890 | */ |
||
4891 | 21 | public function remove($key) |
|
4914 | |||
4915 | /** |
||
4916 | * alias: for "Arrayy->removeValue()" |
||
4917 | * |
||
4918 | * @param mixed $element |
||
4919 | * |
||
4920 | * @return static |
||
4921 | * <p>(Immutable)</p> |
||
4922 | * |
||
4923 | * @psalm-param T $element |
||
4924 | * @psalm-return static<TKey,T> |
||
4925 | * @psalm-mutation-free |
||
4926 | */ |
||
4927 | 8 | public function removeElement($element) |
|
4931 | |||
4932 | /** |
||
4933 | * Remove the first value from the current array. |
||
4934 | * |
||
4935 | * @return static |
||
4936 | * <p>(Immutable)</p> |
||
4937 | * |
||
4938 | * @psalm-return static<TKey,T> |
||
4939 | * @psalm-mutation-free |
||
4940 | */ |
||
4941 | 7 | View Code Duplication | public function removeFirst(): self |
4953 | |||
4954 | /** |
||
4955 | * Remove the last value from the current array. |
||
4956 | * |
||
4957 | * @return static |
||
4958 | * <p>(Immutable)</p> |
||
4959 | * |
||
4960 | * @psalm-return static<TKey,T> |
||
4961 | * @psalm-mutation-free |
||
4962 | */ |
||
4963 | 7 | View Code Duplication | public function removeLast(): self |
4975 | |||
4976 | /** |
||
4977 | * Removes a particular value from an array (numeric or associative). |
||
4978 | * |
||
4979 | * @param mixed $value |
||
4980 | * |
||
4981 | * @return static |
||
4982 | * <p>(Immutable)</p> |
||
4983 | * |
||
4984 | * @psalm-param T $value |
||
4985 | * @psalm-return static<TKey,T> |
||
4986 | * @psalm-mutation-free |
||
4987 | */ |
||
4988 | 8 | public function removeValue($value): self |
|
5011 | |||
5012 | /** |
||
5013 | * Generate array of repeated arrays. |
||
5014 | * |
||
5015 | * @param int $times <p>How many times has to be repeated.</p> |
||
5016 | * |
||
5017 | * @return static |
||
5018 | * <p>(Immutable)</p> |
||
5019 | * |
||
5020 | * @psalm-return static<TKey,T> |
||
5021 | * @psalm-mutation-free |
||
5022 | */ |
||
5023 | 1 | public function repeat($times): self |
|
5035 | |||
5036 | /** |
||
5037 | * Replace a key with a new key/value pair. |
||
5038 | * |
||
5039 | * @param mixed $oldKey |
||
5040 | * @param mixed $newKey |
||
5041 | * @param mixed $newValue |
||
5042 | * |
||
5043 | * @return static |
||
5044 | * <p>(Immutable)</p> |
||
5045 | * |
||
5046 | * @psalm-return static<TKey,T> |
||
5047 | * @psalm-mutation-free |
||
5048 | */ |
||
5049 | 5 | public function replace($oldKey, $newKey, $newValue): self |
|
5059 | |||
5060 | /** |
||
5061 | * Create an array using the current array as values and the other array as keys. |
||
5062 | * |
||
5063 | * @param array $keys <p>An array of keys.</p> |
||
5064 | * |
||
5065 | * @return static |
||
5066 | * <p>(Immutable) Arrayy object with keys from the other array.</p> |
||
5067 | * |
||
5068 | * @psalm-param array<mixed,mixed>|array<mixed,TKey> $keys |
||
5069 | * @psalm-return static<TKey,T> |
||
5070 | * @psalm-mutation-free |
||
5071 | */ |
||
5072 | 2 | public function replaceAllKeys(array $keys): self |
|
5080 | |||
5081 | /** |
||
5082 | * Create an array using the current array as keys and the other array as values. |
||
5083 | * |
||
5084 | * @param array $array <p>An array o values.</p> |
||
5085 | * |
||
5086 | * @return static |
||
5087 | * <p>(Immutable) Arrayy object with values from the other array.</p> |
||
5088 | * |
||
5089 | * @psalm-param array<mixed,T> $array |
||
5090 | * @psalm-return static<TKey,T> |
||
5091 | * @psalm-mutation-free |
||
5092 | */ |
||
5093 | 2 | public function replaceAllValues(array $array): self |
|
5101 | |||
5102 | /** |
||
5103 | * Replace the keys in an array with another set. |
||
5104 | * |
||
5105 | * @param array $keys <p>An array of keys matching the array's size</p> |
||
5106 | * |
||
5107 | * @return static |
||
5108 | * <p>(Immutable)</p> |
||
5109 | * |
||
5110 | * @psalm-param array<mixed,mixed>|array<mixed,TKey> $keys |
||
5111 | * @psalm-return static<TKey,T> |
||
5112 | * @psalm-mutation-free |
||
5113 | */ |
||
5114 | 1 | public function replaceKeys(array $keys): self |
|
5125 | |||
5126 | /** |
||
5127 | * Replace the first matched value in an array. |
||
5128 | * |
||
5129 | * @param mixed $search <p>The value to replace.</p> |
||
5130 | * @param mixed $replacement <p>The value to replace.</p> |
||
5131 | * |
||
5132 | * @return static |
||
5133 | * <p>(Immutable)</p> |
||
5134 | * |
||
5135 | * @psalm-return static<TKey,T> |
||
5136 | * @psalm-mutation-free |
||
5137 | */ |
||
5138 | 3 | View Code Duplication | public function replaceOneValue($search, $replacement = ''): self |
5153 | |||
5154 | /** |
||
5155 | * Replace values in the current array. |
||
5156 | * |
||
5157 | * @param mixed $search <p>The value to replace.</p> |
||
5158 | * @param mixed $replacement <p>What to replace it with.</p> |
||
5159 | * |
||
5160 | * @return static |
||
5161 | * <p>(Immutable)</p> |
||
5162 | * |
||
5163 | * @psalm-return static<TKey,T> |
||
5164 | * @psalm-mutation-free |
||
5165 | */ |
||
5166 | 1 | public function replaceValues($search, $replacement = ''): self |
|
5178 | |||
5179 | /** |
||
5180 | * Get the last elements from index $from until the end of this array. |
||
5181 | * |
||
5182 | * @param int $from |
||
5183 | * |
||
5184 | * @return static |
||
5185 | * <p>(Immutable)</p> |
||
5186 | * |
||
5187 | * @psalm-return static<TKey,T> |
||
5188 | * @psalm-mutation-free |
||
5189 | */ |
||
5190 | 15 | View Code Duplication | public function rest(int $from = 1): self |
5200 | |||
5201 | /** |
||
5202 | * Return the array in the reverse order. |
||
5203 | * |
||
5204 | * @return $this |
||
5205 | * <p>(Mutable) Return this Arrayy object.</p> |
||
5206 | * |
||
5207 | * @psalm-return static<TKey,T> |
||
5208 | */ |
||
5209 | 9 | public function reverse(): self |
|
5217 | |||
5218 | /** |
||
5219 | * Sort an array in reverse order. |
||
5220 | * |
||
5221 | * @param int $sort_flags [optional] <p> |
||
5222 | * You may modify the behavior of the sort using the optional |
||
5223 | * parameter sort_flags, for details |
||
5224 | * see sort. |
||
5225 | * </p> |
||
5226 | * |
||
5227 | * @return $this |
||
5228 | * <p>(Mutable) Return this Arrayy object.</p> |
||
5229 | * |
||
5230 | * @psalm-return static<TKey,T> |
||
5231 | */ |
||
5232 | 4 | public function rsort(int $sort_flags = 0): self |
|
5240 | |||
5241 | /** |
||
5242 | * Sort an array in reverse order. |
||
5243 | * |
||
5244 | * @param int $sort_flags [optional] <p> |
||
5245 | * You may modify the behavior of the sort using the optional |
||
5246 | * parameter sort_flags, for details |
||
5247 | * see sort. |
||
5248 | * </p> |
||
5249 | * |
||
5250 | * @return $this |
||
5251 | * <p>(Immutable) Return this Arrayy object.</p> |
||
5252 | * |
||
5253 | * @psalm-return static<TKey,T> |
||
5254 | * @psalm-mutation-free |
||
5255 | */ |
||
5256 | 4 | public function rsortImmutable(int $sort_flags = 0): self |
|
5267 | |||
5268 | /** |
||
5269 | * Search for the first index of the current array via $value. |
||
5270 | * |
||
5271 | * @param mixed $value |
||
5272 | * |
||
5273 | * @return false|float|int|string |
||
5274 | * <p>Will return <b>FALSE</b> if the value can't be found.</p> |
||
5275 | * @psalm-mutation-free |
||
5276 | */ |
||
5277 | 21 | public function searchIndex($value) |
|
5287 | |||
5288 | /** |
||
5289 | * Search for the value of the current array via $index. |
||
5290 | * |
||
5291 | * @param mixed $index |
||
5292 | * |
||
5293 | * @return static |
||
5294 | * <p>(Immutable) Will return a empty Arrayy if the value wasn't found.</p> |
||
5295 | * |
||
5296 | * @psalm-return static<TKey,T> |
||
5297 | * @psalm-mutation-free |
||
5298 | */ |
||
5299 | 9 | public function searchValue($index): self |
|
5329 | |||
5330 | /** |
||
5331 | * Set a value for the current array (optional using dot-notation). |
||
5332 | * |
||
5333 | * @param string $key <p>The key to set.</p> |
||
5334 | * @param mixed $value <p>Its value.</p> |
||
5335 | * |
||
5336 | * @return $this |
||
5337 | * <p>(Mutable) Return this Arrayy object.</p> |
||
5338 | * |
||
5339 | * @psalm-param TKey $key |
||
5340 | * @psalm-param T $value |
||
5341 | * @psalm-return static<TKey,T> |
||
5342 | */ |
||
5343 | 28 | public function set($key, $value): self |
|
5349 | |||
5350 | /** |
||
5351 | * Get a value from a array and set it if it was not. |
||
5352 | * |
||
5353 | * WARNING: this method only set the value, if the $key is not already set |
||
5354 | * |
||
5355 | * @param mixed $key <p>The key</p> |
||
5356 | * @param mixed $fallback <p>The default value to set if it isn't.</p> |
||
5357 | * |
||
5358 | * @return mixed |
||
5359 | * <p>(Mutable)</p> |
||
5360 | */ |
||
5361 | 11 | public function setAndGet($key, $fallback = null) |
|
5372 | |||
5373 | /** |
||
5374 | * Shifts a specified value off the beginning of array. |
||
5375 | * |
||
5376 | * @return mixed |
||
5377 | * <p>(Mutable) A shifted element from the current array.</p> |
||
5378 | */ |
||
5379 | 5 | public function shift() |
|
5385 | |||
5386 | /** |
||
5387 | * Shuffle the current array. |
||
5388 | * |
||
5389 | * @param bool $secure <p>using a CSPRNG | @link https://paragonie.com/b/JvICXzh_jhLyt4y3</p> |
||
5390 | * @param array $array [optional] |
||
5391 | * |
||
5392 | * @return static |
||
5393 | * <p>(Immutable)</p> |
||
5394 | * |
||
5395 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
5396 | * @psalm-return static<TKey,T> |
||
5397 | * |
||
5398 | * @noinspection BadExceptionsProcessingInspection |
||
5399 | * @noinspection RandomApiMigrationInspection |
||
5400 | * @noinspection NonSecureShuffleUsageInspection |
||
5401 | */ |
||
5402 | 2 | public function shuffle(bool $secure = false, array $array = null): self |
|
5403 | { |
||
5404 | 2 | if ($array === null) { |
|
5405 | 2 | $array = $this->toArray(false); |
|
5406 | } |
||
5407 | |||
5408 | 2 | if ($secure !== true) { |
|
5409 | 2 | \shuffle($array); |
|
5410 | } else { |
||
5411 | 1 | $size = \count($array, \COUNT_NORMAL); |
|
5412 | 1 | $keys = \array_keys($array); |
|
5413 | 1 | for ($i = $size - 1; $i > 0; --$i) { |
|
5414 | try { |
||
5415 | 1 | $r = \random_int(0, $i); |
|
5416 | } catch (\Exception $e) { |
||
5417 | $r = \mt_rand(0, $i); |
||
5418 | } |
||
5419 | 1 | if ($r !== $i) { |
|
5420 | 1 | $temp = $array[$keys[$r]]; |
|
5421 | 1 | $array[$keys[$r]] = $array[$keys[$i]]; |
|
5422 | 1 | $array[$keys[$i]] = $temp; |
|
5423 | } |
||
5424 | } |
||
5425 | } |
||
5426 | |||
5427 | 2 | foreach ($array as $key => $value) { |
|
5428 | // check if recursive is needed |
||
5429 | 2 | if (\is_array($value) === true) { |
|
5430 | $array[$key] = $this->shuffle($secure, $value); |
||
5431 | } |
||
5432 | } |
||
5433 | |||
5434 | 2 | return static::create( |
|
5435 | 2 | $array, |
|
5436 | 2 | $this->iteratorClass, |
|
5437 | 2 | false |
|
5438 | ); |
||
5439 | } |
||
5440 | |||
5441 | /** |
||
5442 | * Count the values from the current array. |
||
5443 | * |
||
5444 | * alias: for "Arrayy->count()" |
||
5445 | * |
||
5446 | * @param int $mode |
||
5447 | * |
||
5448 | * @return int |
||
5449 | */ |
||
5450 | 20 | public function size(int $mode = \COUNT_NORMAL): int |
|
5454 | |||
5455 | /** |
||
5456 | * Checks whether array has exactly $size items. |
||
5457 | * |
||
5458 | * @param int $size |
||
5459 | * |
||
5460 | * @return bool |
||
5461 | */ |
||
5462 | 1 | public function sizeIs(int $size): bool |
|
5478 | |||
5479 | /** |
||
5480 | * Checks whether array has between $fromSize to $toSize items. $toSize can be |
||
5481 | * smaller than $fromSize. |
||
5482 | * |
||
5483 | * @param int $fromSize |
||
5484 | * @param int $toSize |
||
5485 | * |
||
5486 | * @return bool |
||
5487 | */ |
||
5488 | 1 | public function sizeIsBetween(int $fromSize, int $toSize): bool |
|
5508 | |||
5509 | /** |
||
5510 | * Checks whether array has more than $size items. |
||
5511 | * |
||
5512 | * @param int $size |
||
5513 | * |
||
5514 | * @return bool |
||
5515 | */ |
||
5516 | 1 | View Code Duplication | public function sizeIsGreaterThan(int $size): bool |
5530 | |||
5531 | /** |
||
5532 | * Checks whether array has less than $size items. |
||
5533 | * |
||
5534 | * @param int $size |
||
5535 | * |
||
5536 | * @return bool |
||
5537 | */ |
||
5538 | 1 | View Code Duplication | public function sizeIsLessThan(int $size): bool |
5552 | |||
5553 | /** |
||
5554 | * Counts all elements in an array, or something in an object. |
||
5555 | * |
||
5556 | * <p> |
||
5557 | * For objects, if you have SPL installed, you can hook into count() by implementing interface {@see Countable}. |
||
5558 | * The interface has exactly one method, {@see Countable::count()}, which returns the return value for the count() |
||
5559 | * function. Please see the {@see Array} section of the manual for a detailed explanation of how arrays are |
||
5560 | * implemented and used in PHP. |
||
5561 | * </p> |
||
5562 | * |
||
5563 | * @return int |
||
5564 | * <p> |
||
5565 | * The number of elements in var, which is |
||
5566 | * typically an array, since anything else will have one |
||
5567 | * element. |
||
5568 | * </p> |
||
5569 | * <p> |
||
5570 | * If var is not an array or an object with |
||
5571 | * implemented Countable interface, |
||
5572 | * 1 will be returned. |
||
5573 | * There is one exception, if var is &null;, |
||
5574 | * 0 will be returned. |
||
5575 | * </p> |
||
5576 | * <p> |
||
5577 | * Caution: count may return 0 for a variable that isn't set, |
||
5578 | * but it may also return 0 for a variable that has been initialized with an |
||
5579 | * empty array. Use isset to test if a variable is set. |
||
5580 | * </p> |
||
5581 | */ |
||
5582 | 10 | public function sizeRecursive(): int |
|
5586 | |||
5587 | /** |
||
5588 | * Extract a slice of the array. |
||
5589 | * |
||
5590 | * @param int $offset <p>Slice begin index.</p> |
||
5591 | * @param int|null $length <p>Length of the slice.</p> |
||
5592 | * @param bool $preserveKeys <p>Whether array keys are preserved or no.</p> |
||
5593 | * |
||
5594 | * @return static |
||
5595 | * <p>(Immutable) A slice of the original array with length $length.</p> |
||
5596 | * |
||
5597 | * @psalm-return static<TKey,T> |
||
5598 | * @psalm-mutation-free |
||
5599 | */ |
||
5600 | 5 | public function slice(int $offset, int $length = null, bool $preserveKeys = false) |
|
5613 | |||
5614 | /** |
||
5615 | * Sort the current array and optional you can keep the keys. |
||
5616 | * |
||
5617 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
5618 | * @param int $strategy <p>sort_flags => use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
5619 | * <strong>SORT_NATURAL</strong></p> |
||
5620 | * @param bool $keepKeys |
||
5621 | * |
||
5622 | * @return static |
||
5623 | * <p>(Mutable) Return this Arrayy object.</p> |
||
5624 | * |
||
5625 | * @psalm-return static<TKey,T> |
||
5626 | */ |
||
5627 | 20 | public function sort( |
|
5641 | |||
5642 | /** |
||
5643 | * Sort the current array and optional you can keep the keys. |
||
5644 | * |
||
5645 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
5646 | * @param int $strategy <p>sort_flags => use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
5647 | * <strong>SORT_NATURAL</strong></p> |
||
5648 | * @param bool $keepKeys |
||
5649 | * |
||
5650 | * @return static |
||
5651 | * <p>(Immutable) Return this Arrayy object.</p> |
||
5652 | * |
||
5653 | * @psalm-return static<TKey,T> |
||
5654 | */ |
||
5655 | 12 | public function sortImmutable( |
|
5671 | |||
5672 | /** |
||
5673 | * Sort the current array by key. |
||
5674 | * |
||
5675 | * @see http://php.net/manual/en/function.ksort.php |
||
5676 | * @see http://php.net/manual/en/function.krsort.php |
||
5677 | * |
||
5678 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
5679 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
5680 | * <strong>SORT_NATURAL</strong></p> |
||
5681 | * |
||
5682 | * @return $this |
||
5683 | * <p>(Mutable) Return this Arrayy object.</p> |
||
5684 | * |
||
5685 | * @psalm-return static<TKey,T> |
||
5686 | */ |
||
5687 | 18 | public function sortKeys( |
|
5697 | |||
5698 | /** |
||
5699 | * Sort the current array by key. |
||
5700 | * |
||
5701 | * @see http://php.net/manual/en/function.ksort.php |
||
5702 | * @see http://php.net/manual/en/function.krsort.php |
||
5703 | * |
||
5704 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
5705 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
5706 | * <strong>SORT_NATURAL</strong></p> |
||
5707 | * |
||
5708 | * @return $this |
||
5709 | * <p>(Immutable) Return this Arrayy object.</p> |
||
5710 | * |
||
5711 | * @psalm-return static<TKey,T> |
||
5712 | * @psalm-mutation-free |
||
5713 | */ |
||
5714 | 8 | public function sortKeysImmutable( |
|
5727 | |||
5728 | /** |
||
5729 | * Sort the current array by value. |
||
5730 | * |
||
5731 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
5732 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
5733 | * <strong>SORT_NATURAL</strong></p> |
||
5734 | * |
||
5735 | * @return static |
||
5736 | * <p>(Mutable)</p> |
||
5737 | * |
||
5738 | * @psalm-return static<TKey,T> |
||
5739 | */ |
||
5740 | 1 | public function sortValueKeepIndex( |
|
5746 | |||
5747 | /** |
||
5748 | * Sort the current array by value. |
||
5749 | * |
||
5750 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
5751 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
5752 | * <strong>SORT_NATURAL</strong></p> |
||
5753 | * |
||
5754 | * @return static |
||
5755 | * <p>(Mutable)</p> |
||
5756 | * |
||
5757 | * @psalm-return static<TKey,T> |
||
5758 | */ |
||
5759 | 1 | public function sortValueNewIndex($direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
5763 | |||
5764 | /** |
||
5765 | * Sort a array by value, by a closure or by a property. |
||
5766 | * |
||
5767 | * - If the sorter is null, the array is sorted naturally. |
||
5768 | * - Associative (string) keys will be maintained, but numeric keys will be re-indexed. |
||
5769 | * |
||
5770 | * @param callable|string|null $sorter |
||
5771 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or |
||
5772 | * <strong>SORT_DESC</strong></p> |
||
5773 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
5774 | * <strong>SORT_NATURAL</strong></p> |
||
5775 | * |
||
5776 | * @return static |
||
5777 | * <p>(Immutable)</p> |
||
5778 | * |
||
5779 | * @psalm-return static<TKey,T> |
||
5780 | * @psalm-mutation-free |
||
5781 | */ |
||
5782 | 1 | public function sorter($sorter = null, $direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
5823 | |||
5824 | /** |
||
5825 | * @param int $offset |
||
5826 | * @param int|null $length |
||
5827 | * @param array $replacement |
||
5828 | * |
||
5829 | * @return static |
||
5830 | * <p>(Immutable)</p> |
||
5831 | * |
||
5832 | * @psalm-param array<mixed,mixed>|array<mixed,T> $replacement |
||
5833 | * @psalm-return static<TKey,T> |
||
5834 | * @psalm-mutation-free |
||
5835 | */ |
||
5836 | 1 | public function splice(int $offset, int $length = null, $replacement = []): self |
|
5853 | |||
5854 | /** |
||
5855 | * Split an array in the given amount of pieces. |
||
5856 | * |
||
5857 | * @param int $numberOfPieces |
||
5858 | * @param bool $keepKeys |
||
5859 | * |
||
5860 | * @return static |
||
5861 | * <p>(Immutable)</p> |
||
5862 | * |
||
5863 | * @psalm-return static<TKey,T> |
||
5864 | * @psalm-mutation-free |
||
5865 | */ |
||
5866 | 1 | public function split(int $numberOfPieces = 2, bool $keepKeys = false): self |
|
5885 | |||
5886 | /** |
||
5887 | * Stripe all empty items. |
||
5888 | * |
||
5889 | * @return static |
||
5890 | * <p>(Immutable)</p> |
||
5891 | * |
||
5892 | * @psalm-return static<TKey,T> |
||
5893 | * @psalm-mutation-free |
||
5894 | */ |
||
5895 | 1 | public function stripEmpty(): self |
|
5907 | |||
5908 | /** |
||
5909 | * Swap two values between positions by key. |
||
5910 | * |
||
5911 | * @param int|string $swapA <p>a key in the array</p> |
||
5912 | * @param int|string $swapB <p>a key in the array</p> |
||
5913 | * |
||
5914 | * @return static |
||
5915 | * <p>(Immutable)</p> |
||
5916 | * |
||
5917 | * @psalm-return static<TKey,T> |
||
5918 | * @psalm-mutation-free |
||
5919 | */ |
||
5920 | 1 | public function swap($swapA, $swapB): self |
|
5932 | |||
5933 | /** |
||
5934 | * Get the current array from the "Arrayy"-object. |
||
5935 | * alias for "getArray()" |
||
5936 | * |
||
5937 | * @param bool $convertAllArrayyElements <p> |
||
5938 | * Convert all Child-"Arrayy" objects also to arrays. |
||
5939 | * </p> |
||
5940 | * @param bool $preserveKeys <p> |
||
5941 | * e.g.: A generator maybe return the same key more then once, |
||
5942 | * so maybe you will ignore the keys. |
||
5943 | * </p> |
||
5944 | * |
||
5945 | * @return array |
||
5946 | * |
||
5947 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
5948 | * @psalm-mutation-free |
||
5949 | */ |
||
5950 | 947 | public function toArray( |
|
5978 | |||
5979 | /** |
||
5980 | * Get the current array from the "Arrayy"-object as list. |
||
5981 | * |
||
5982 | * @param bool $convertAllArrayyElements <p> |
||
5983 | * Convert all Child-"Arrayy" objects also to arrays. |
||
5984 | * </p> |
||
5985 | * |
||
5986 | * @return array |
||
5987 | * |
||
5988 | * @psalm-return list<array<TKey,T>> |
||
5989 | * @psalm-mutation-free |
||
5990 | */ |
||
5991 | 1 | public function toList(bool $convertAllArrayyElements = false): array |
|
5998 | |||
5999 | /** |
||
6000 | * Convert the current array to JSON. |
||
6001 | * |
||
6002 | * @param int $options [optional] <p>e.g. JSON_PRETTY_PRINT</p> |
||
6003 | * @param int $depth [optional] <p>Set the maximum depth. Must be greater than zero.</p> |
||
6004 | * |
||
6005 | * @return string |
||
6006 | */ |
||
6007 | 12 | public function toJson(int $options = 0, int $depth = 512): string |
|
6016 | |||
6017 | /** |
||
6018 | * @param string[]|null $items [optional] |
||
6019 | * @param string[] $helper [optional] |
||
6020 | * |
||
6021 | * @return static|static[] |
||
6022 | * |
||
6023 | * @psalm-return static<int, static<TKey,T>> |
||
6024 | */ |
||
6025 | 1 | public function toPermutation(array $items = null, array $helper = []): self |
|
6059 | |||
6060 | /** |
||
6061 | * Implodes array to a string with specified separator. |
||
6062 | * |
||
6063 | * @param string $separator [optional] <p>The element's separator.</p> |
||
6064 | * |
||
6065 | * @return string |
||
6066 | * <p>The string representation of array, separated by ",".</p> |
||
6067 | */ |
||
6068 | 19 | public function toString(string $separator = ','): string |
|
6072 | |||
6073 | /** |
||
6074 | * Return a duplicate free copy of the current array. |
||
6075 | * |
||
6076 | * @return $this |
||
6077 | * <p>(Mutable)</p> |
||
6078 | * |
||
6079 | * @psalm-return static<TKey,T> |
||
6080 | */ |
||
6081 | 13 | public function unique(): self |
|
6103 | |||
6104 | /** |
||
6105 | * Return a duplicate free copy of the current array. (with the old keys) |
||
6106 | * |
||
6107 | * @return $this |
||
6108 | * <p>(Mutable)</p> |
||
6109 | * |
||
6110 | * @psalm-return static<TKey,T> |
||
6111 | */ |
||
6112 | 11 | public function uniqueKeepIndex(): self |
|
6138 | |||
6139 | /** |
||
6140 | * alias: for "Arrayy->unique()" |
||
6141 | * |
||
6142 | * @return static |
||
6143 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
6144 | * |
||
6145 | * @see Arrayy::unique() |
||
6146 | * |
||
6147 | * @psalm-return static<TKey,T> |
||
6148 | */ |
||
6149 | 10 | public function uniqueNewIndex(): self |
|
6153 | |||
6154 | /** |
||
6155 | * Prepends one or more values to the beginning of array at once. |
||
6156 | * |
||
6157 | * @param array ...$args |
||
6158 | * |
||
6159 | * @return $this |
||
6160 | * <p>(Mutable) Return this Arrayy object, with prepended elements to the beginning of array.</p> |
||
6161 | * |
||
6162 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$args |
||
6163 | * @psalm-return static<TKey,T> |
||
6164 | */ |
||
6165 | 4 | public function unshift(...$args): self |
|
6173 | |||
6174 | /** |
||
6175 | * Tests whether the given closure return something valid for all elements of this array. |
||
6176 | * |
||
6177 | * @param \Closure $closure the predicate |
||
6178 | * |
||
6179 | * @return bool |
||
6180 | * <p>TRUE, if the predicate yields TRUE for all elements, FALSE otherwise.</p> |
||
6181 | */ |
||
6182 | 1 | View Code Duplication | public function validate(\Closure $closure): bool |
6192 | |||
6193 | /** |
||
6194 | * Get all values from a array. |
||
6195 | * |
||
6196 | * @return static |
||
6197 | * <p>(Immutable)</p> |
||
6198 | * |
||
6199 | * @psalm-return static<TKey,T> |
||
6200 | * @psalm-mutation-free |
||
6201 | */ |
||
6202 | 2 | public function values(): self |
|
6215 | |||
6216 | /** |
||
6217 | * Apply the given function to every element in the array, discarding the results. |
||
6218 | * |
||
6219 | * @param callable $callable |
||
6220 | * @param bool $recursive [optional] <p>Whether array will be walked recursively or no</p> |
||
6221 | * @param mixed $userData [optional] <p> |
||
6222 | * If the optional $userData parameter is supplied, |
||
6223 | * it will be passed as the third parameter to the $callable. |
||
6224 | * </p> |
||
6225 | * |
||
6226 | * @return $this |
||
6227 | * <p>(Mutable) Return this Arrayy object, with modified elements.</p> |
||
6228 | * |
||
6229 | * @psalm-return static<TKey,T> |
||
6230 | */ |
||
6231 | 12 | public function walk($callable, bool $recursive = false, $userData = self::ARRAYY_HELPER_WALK): self |
|
6254 | |||
6255 | /** |
||
6256 | * Returns a collection of matching items. |
||
6257 | * |
||
6258 | * @param string $keyOrPropertyOrMethod the property or method to evaluate |
||
6259 | * @param mixed $value the value to match |
||
6260 | * |
||
6261 | * @throws \InvalidArgumentException if property or method is not defined |
||
6262 | * |
||
6263 | * @return static |
||
6264 | * |
||
6265 | * @psalm-param T $value |
||
6266 | * @psalm-return static<TKey,T> |
||
6267 | */ |
||
6268 | 1 | public function where(string $keyOrPropertyOrMethod, $value): self |
|
6281 | |||
6282 | /** |
||
6283 | * Convert an array into a object. |
||
6284 | * |
||
6285 | * @param array $array |
||
6286 | * |
||
6287 | * @return \stdClass |
||
6288 | * |
||
6289 | * @psalm-param array<mixed,mixed> $array |
||
6290 | */ |
||
6291 | 4 | final protected static function arrayToObject(array $array = []): \stdClass |
|
6310 | |||
6311 | /** |
||
6312 | * @param array|\Generator|null $input <p> |
||
6313 | * An array containing keys to return. |
||
6314 | * </p> |
||
6315 | * @param mixed|null $search_values [optional] <p> |
||
6316 | * If specified, then only keys containing these values are returned. |
||
6317 | * </p> |
||
6318 | * @param bool $strict [optional] <p> |
||
6319 | * Determines if strict comparison (===) should be used during the |
||
6320 | * search. |
||
6321 | * </p> |
||
6322 | * |
||
6323 | * @return array |
||
6324 | * <p>an array of all the keys in input</p> |
||
6325 | * |
||
6326 | * @psalm-param array<mixed,mixed>|\Generator<TKey,T>|null $input |
||
6327 | * @psalm-return array<TKey|mixed> |
||
6328 | * @psalm-mutation-free |
||
6329 | */ |
||
6330 | 11 | protected function array_keys_recursive( |
|
6391 | |||
6392 | /** |
||
6393 | * @param mixed $path |
||
6394 | * @param callable $callable |
||
6395 | * @param array|null $currentOffset |
||
6396 | * |
||
6397 | * @return void |
||
6398 | * |
||
6399 | * @psalm-param array<mixed,mixed>|array<TKey,T>|null $currentOffset |
||
6400 | * @psalm-mutation-free |
||
6401 | */ |
||
6402 | 10 | protected function callAtPath($path, $callable, &$currentOffset = null) |
|
6431 | |||
6432 | /** |
||
6433 | * Extracts the value of the given property or method from the object. |
||
6434 | * |
||
6435 | * @param static $object <p>The object to extract the value from.</p> |
||
6436 | * @param string $keyOrPropertyOrMethod <p>The property or method for which the |
||
6437 | * value should be extracted.</p> |
||
6438 | * |
||
6439 | * @throws \InvalidArgumentException if the method or property is not defined |
||
6440 | * |
||
6441 | * @return mixed |
||
6442 | * <p>The value extracted from the specified property or method.</p> |
||
6443 | * |
||
6444 | * @psalm-param self<TKey,T> $object |
||
6445 | */ |
||
6446 | 2 | final protected function extractValue(self $object, string $keyOrPropertyOrMethod) |
|
6468 | |||
6469 | /** |
||
6470 | * create a fallback for array |
||
6471 | * |
||
6472 | * 1. use the current array, if it's a array |
||
6473 | * 2. fallback to empty array, if there is nothing |
||
6474 | * 3. call "getArray()" on object, if there is a "Arrayy"-object |
||
6475 | * 4. call "createFromObject()" on object, if there is a "\Traversable"-object |
||
6476 | * 5. call "__toArray()" on object, if the method exists |
||
6477 | * 6. cast a string or object with "__toString()" into an array |
||
6478 | * 7. throw a "InvalidArgumentException"-Exception |
||
6479 | * |
||
6480 | * @param mixed $data |
||
6481 | * |
||
6482 | * @throws \InvalidArgumentException |
||
6483 | * |
||
6484 | * @return array |
||
6485 | * |
||
6486 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
6487 | */ |
||
6488 | 1203 | protected function fallbackForArray(&$data): array |
|
6498 | |||
6499 | /** |
||
6500 | * @param bool $preserveKeys <p> |
||
6501 | * e.g.: A generator maybe return the same key more then once, |
||
6502 | * so maybe you will ignore the keys. |
||
6503 | * </p> |
||
6504 | * |
||
6505 | * @return bool |
||
6506 | * |
||
6507 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
6508 | * @psalm-mutation-free :/ |
||
6509 | */ |
||
6510 | 1115 | protected function generatorToArray(bool $preserveKeys = true) |
|
6521 | |||
6522 | /** |
||
6523 | * Get correct PHP constant for direction. |
||
6524 | * |
||
6525 | * @param int|string $direction |
||
6526 | * |
||
6527 | * @return int |
||
6528 | * @psalm-mutation-free |
||
6529 | */ |
||
6530 | 43 | protected function getDirection($direction): int |
|
6552 | |||
6553 | /** |
||
6554 | * @return TypeCheckInterface[] |
||
6555 | * |
||
6556 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
6557 | */ |
||
6558 | 24 | protected function getPropertiesFromPhpDoc() |
|
6613 | |||
6614 | /** |
||
6615 | * @param mixed $glue |
||
6616 | * @param mixed $pieces |
||
6617 | * @param bool $useKeys |
||
6618 | * |
||
6619 | * @return string |
||
6620 | * @psalm-mutation-free |
||
6621 | */ |
||
6622 | 36 | protected function implode_recursive( |
|
6655 | |||
6656 | /** |
||
6657 | * @param mixed $needle <p> |
||
6658 | * The searched value. |
||
6659 | * </p> |
||
6660 | * <p> |
||
6661 | * If needle is a string, the comparison is done |
||
6662 | * in a case-sensitive manner. |
||
6663 | * </p> |
||
6664 | * @param array|\Generator|null $haystack <p> |
||
6665 | * The array. |
||
6666 | * </p> |
||
6667 | * @param bool $strict [optional] <p> |
||
6668 | * If the third parameter strict is set to true |
||
6669 | * then the in_array function will also check the |
||
6670 | * types of the |
||
6671 | * needle in the haystack. |
||
6672 | * </p> |
||
6673 | * |
||
6674 | * @return bool |
||
6675 | * <p>true if needle is found in the array, false otherwise</p> |
||
6676 | * |
||
6677 | * @psalm-param array<mixed,mixed>|\Generator<TKey,T>|null $haystack |
||
6678 | * @psalm-mutation-free |
||
6679 | */ |
||
6680 | 19 | protected function in_array_recursive($needle, $haystack = null, $strict = true): bool |
|
6705 | |||
6706 | /** |
||
6707 | * @param mixed $data |
||
6708 | * |
||
6709 | * @return array|null |
||
6710 | * |
||
6711 | * @psalm-return array<mixed,mixed>|array<TKey,T>|null |
||
6712 | */ |
||
6713 | 1203 | protected function internalGetArray(&$data) |
|
6764 | |||
6765 | /** |
||
6766 | * Internal mechanics of remove method. |
||
6767 | * |
||
6768 | * @param mixed $key |
||
6769 | * |
||
6770 | * @return bool |
||
6771 | */ |
||
6772 | 21 | protected function internalRemove($key): bool |
|
6805 | |||
6806 | /** |
||
6807 | * Internal mechanic of set method. |
||
6808 | * |
||
6809 | * @param int|string|null $key |
||
6810 | * @param mixed $value |
||
6811 | * @param bool $checkProperties |
||
6812 | * |
||
6813 | * @return bool |
||
6814 | */ |
||
6815 | 1053 | protected function internalSet( |
|
6874 | |||
6875 | /** |
||
6876 | * Convert a object into an array. |
||
6877 | * |
||
6878 | * @param mixed|object $object |
||
6879 | * |
||
6880 | * @return array|mixed |
||
6881 | * |
||
6882 | * @psalm-mutation-free |
||
6883 | */ |
||
6884 | 5 | protected static function objectToArray($object) |
|
6897 | |||
6898 | /** |
||
6899 | * @param array $data |
||
6900 | * @param bool $checkPropertiesInConstructor |
||
6901 | * |
||
6902 | * @return void |
||
6903 | * |
||
6904 | * @psalm-param array<mixed,T> $data |
||
6905 | */ |
||
6906 | 1201 | protected function setInitialValuesAndProperties(array &$data, bool $checkPropertiesInConstructor) |
|
6951 | |||
6952 | /** |
||
6953 | * sorting keys |
||
6954 | * |
||
6955 | * @param array $elements |
||
6956 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
6957 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
6958 | * <strong>SORT_NATURAL</strong></p> |
||
6959 | * |
||
6960 | * @return $this |
||
6961 | * <p>(Mutable) Return this Arrayy object.</p> |
||
6962 | * |
||
6963 | * @psalm-param array<mixed,mixed>|array<mixed|TKey,T> $elements |
||
6964 | * @psalm-return static<TKey,T> |
||
6965 | */ |
||
6966 | 18 | protected function sorterKeys( |
|
6987 | |||
6988 | /** |
||
6989 | * @param array $elements <p>Warning: used as reference</p> |
||
6990 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
6991 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
6992 | * <strong>SORT_NATURAL</strong></p> |
||
6993 | * @param bool $keepKeys |
||
6994 | * |
||
6995 | * @return $this |
||
6996 | * <p>(Mutable) Return this Arrayy object.</p> |
||
6997 | * |
||
6998 | * @psalm-param array<mixed,mixed>|array<mixed|TKey,T> $elements |
||
6999 | * @psalm-return static<TKey,T> |
||
7000 | */ |
||
7001 | 24 | protected function sorting(array &$elements, $direction = \SORT_ASC, int $strategy = \SORT_REGULAR, bool $keepKeys = false): self |
|
7031 | |||
7032 | /** |
||
7033 | * @param array $array |
||
7034 | * |
||
7035 | * @return array |
||
7036 | * |
||
7037 | * @psalm-mutation-free |
||
7038 | */ |
||
7039 | 25 | private function getArrayRecursiveHelperArrayy(array $array) |
|
7061 | |||
7062 | /** |
||
7063 | * @param int|string|null $key |
||
7064 | * @param mixed $value |
||
7065 | * |
||
7066 | * @return void |
||
7067 | */ |
||
7068 | 112 | private function checkType($key, $value) |
|
7086 | } |
||
7087 |
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..