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 | 1206 | 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 | * EXAMPLE: <code> |
||
388 | * a([-9, -8, -7, 1.32])->count(); // 4 |
||
389 | * </code> |
||
390 | * |
||
391 | * <p> |
||
392 | * For objects, if you have SPL installed, you can hook into count() by implementing interface {@see Countable}. |
||
393 | * The interface has exactly one method, {@see Countable::count()}, which returns the return value for the count() |
||
394 | * function. Please see the {@see Array} section of the manual for a detailed explanation of how arrays are |
||
395 | * implemented and used in PHP. |
||
396 | * </p> |
||
397 | * |
||
398 | * @see http://php.net/manual/en/function.count.php |
||
399 | * |
||
400 | * @param int $mode [optional] If the optional mode parameter is set to |
||
401 | * COUNT_RECURSIVE (or 1), count |
||
402 | * will recursively count the array. This is particularly useful for |
||
403 | * counting all the elements of a multidimensional array. count does not detect infinite recursion. |
||
404 | * |
||
405 | * @return int |
||
406 | * <p> |
||
407 | * The number of elements in var, which is |
||
408 | * typically an array, since anything else will have one |
||
409 | * element. |
||
410 | * </p> |
||
411 | * <p> |
||
412 | * If var is not an array or an object with |
||
413 | * implemented Countable interface, |
||
414 | * 1 will be returned. |
||
415 | * There is one exception, if var is &null;, |
||
416 | * 0 will be returned. |
||
417 | * </p> |
||
418 | * <p> |
||
419 | * Caution: count may return 0 for a variable that isn't set, |
||
420 | * but it may also return 0 for a variable that has been initialized with an |
||
421 | * empty array. Use isset to test if a variable is set. |
||
422 | * </p> |
||
423 | * @psalm-mutation-free |
||
424 | */ |
||
425 | 147 | public function count(int $mode = \COUNT_NORMAL): int |
|
437 | |||
438 | /** |
||
439 | * Exchange the array for another one. |
||
440 | * |
||
441 | * @param array|static $data |
||
442 | * |
||
443 | * @return array |
||
444 | * |
||
445 | * @psalm-param array<TKey,T>|self<TKey,T> $data |
||
446 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
447 | */ |
||
448 | 1 | public function exchangeArray($data): array |
|
454 | |||
455 | /** |
||
456 | * Creates a copy of the ArrayyObject. |
||
457 | * |
||
458 | * @return array |
||
459 | * |
||
460 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
461 | */ |
||
462 | 6 | public function getArrayCopy(): array |
|
468 | |||
469 | /** |
||
470 | * Returns a new iterator, thus implementing the \Iterator interface. |
||
471 | * |
||
472 | * EXAMPLE: <code> |
||
473 | * a(['foo', 'bar'])->getIterator(); // ArrayyIterator['foo', 'bar'] |
||
474 | * </code> |
||
475 | * |
||
476 | * @return \Iterator<mixed, mixed> |
||
477 | * <p>An iterator for the values in the array.</p> |
||
478 | * @psalm-return \Iterator<array-key|TKey, mixed|T> |
||
479 | */ |
||
480 | 27 | public function getIterator(): \Iterator |
|
497 | |||
498 | /** |
||
499 | * Gets the iterator classname for the ArrayObject. |
||
500 | * |
||
501 | * @return string |
||
502 | * |
||
503 | * @psalm-return class-string |
||
504 | */ |
||
505 | 26 | public function getIteratorClass(): string |
|
509 | |||
510 | /** |
||
511 | * Sort the entries by key. |
||
512 | * |
||
513 | * @param int $sort_flags [optional] <p> |
||
514 | * You may modify the behavior of the sort using the optional |
||
515 | * parameter sort_flags, for details |
||
516 | * see sort. |
||
517 | * </p> |
||
518 | * |
||
519 | * @return $this |
||
520 | * <p>(Mutable) Return this Arrayy object.</p> |
||
521 | * |
||
522 | * @psalm-return static<TKey,T> |
||
523 | */ |
||
524 | 4 | public function ksort(int $sort_flags = 0): self |
|
532 | |||
533 | /** |
||
534 | * Sort the entries by key. |
||
535 | * |
||
536 | * @param int $sort_flags [optional] <p> |
||
537 | * You may modify the behavior of the sort using the optional |
||
538 | * parameter sort_flags, for details |
||
539 | * see sort. |
||
540 | * </p> |
||
541 | * |
||
542 | * @return $this |
||
543 | * <p>(Immutable) Return this Arrayy object.</p> |
||
544 | * |
||
545 | * @psalm-return static<TKey,T> |
||
546 | */ |
||
547 | 4 | public function ksortImmutable(int $sort_flags = 0): self |
|
558 | |||
559 | /** |
||
560 | * Sort an array using a case insensitive "natural order" algorithm. |
||
561 | * |
||
562 | * @return $this |
||
563 | * <p>(Mutable) Return this Arrayy object.</p> |
||
564 | * |
||
565 | * @psalm-return static<TKey,T> |
||
566 | */ |
||
567 | 8 | public function natcasesort(): self |
|
575 | |||
576 | /** |
||
577 | * Sort an array using a case insensitive "natural order" algorithm. |
||
578 | * |
||
579 | * @return $this |
||
580 | * <p>(Immutable) Return this Arrayy object.</p> |
||
581 | * |
||
582 | * @psalm-return static<TKey,T> |
||
583 | * @psalm-mutation-free |
||
584 | */ |
||
585 | 4 | public function natcasesortImmutable(): self |
|
596 | |||
597 | /** |
||
598 | * Sort entries using a "natural order" algorithm. |
||
599 | * |
||
600 | * @return $this |
||
601 | * <p>(Mutable) Return this Arrayy object.</p> |
||
602 | * |
||
603 | * @psalm-return static<TKey,T> |
||
604 | */ |
||
605 | 10 | public function natsort(): self |
|
613 | |||
614 | /** |
||
615 | * Sort entries using a "natural order" algorithm. |
||
616 | * |
||
617 | * @return $this |
||
618 | * <p>(Immutable) Return this Arrayy object.</p> |
||
619 | * |
||
620 | * @psalm-return static<TKey,T> |
||
621 | * @psalm-mutation-free |
||
622 | */ |
||
623 | 4 | public function natsortImmutable(): self |
|
634 | |||
635 | /** |
||
636 | * Whether or not an offset exists. |
||
637 | * |
||
638 | * @param bool|int|string $offset |
||
639 | * |
||
640 | * @return bool |
||
641 | * |
||
642 | * @noinspection PhpSillyAssignmentInspection |
||
643 | * |
||
644 | * @psalm-mutation-free |
||
645 | */ |
||
646 | 159 | public function offsetExists($offset): bool |
|
708 | |||
709 | /** |
||
710 | * Returns the value at specified offset. |
||
711 | * |
||
712 | * @param int|string $offset |
||
713 | * |
||
714 | * @return mixed |
||
715 | * <p>Will return null if the offset did not exists.</p> |
||
716 | */ |
||
717 | 128 | public function &offsetGet($offset) |
|
728 | |||
729 | /** |
||
730 | * Assigns a value to the specified offset + check the type. |
||
731 | * |
||
732 | * @param int|string|null $offset |
||
733 | * @param mixed $value |
||
734 | * |
||
735 | * @return void |
||
736 | */ |
||
737 | 28 | public function offsetSet($offset, $value) |
|
755 | |||
756 | /** |
||
757 | * Unset an offset. |
||
758 | * |
||
759 | * @param int|string $offset |
||
760 | * |
||
761 | * @return void |
||
762 | * <p>(Mutable) Return nothing.</p> |
||
763 | */ |
||
764 | 25 | public function offsetUnset($offset) |
|
815 | |||
816 | /** |
||
817 | * Serialize the current "Arrayy"-object. |
||
818 | * |
||
819 | * EXAMPLE: <code> |
||
820 | * a([1, 4, 7])->serialize(); |
||
821 | * </code> |
||
822 | * |
||
823 | * @return string |
||
824 | */ |
||
825 | 2 | public function serialize(): string |
|
835 | |||
836 | /** |
||
837 | * Sets the iterator classname for the current "Arrayy"-object. |
||
838 | * |
||
839 | * @param string $iteratorClass |
||
840 | * |
||
841 | * @throws \InvalidArgumentException |
||
842 | * |
||
843 | * @return void |
||
844 | * |
||
845 | * @psalm-param class-string<\Arrayy\ArrayyIterator> $iteratorClass |
||
846 | */ |
||
847 | 1196 | public function setIteratorClass($iteratorClass) |
|
869 | |||
870 | /** |
||
871 | * Sort the entries with a user-defined comparison function and maintain key association. |
||
872 | * |
||
873 | * @param callable $function |
||
874 | * |
||
875 | * @throws \InvalidArgumentException |
||
876 | * |
||
877 | * @return $this |
||
878 | * <p>(Mutable) Return this Arrayy object.</p> |
||
879 | * |
||
880 | * @psalm-return static<TKey,T> |
||
881 | */ |
||
882 | 8 | View Code Duplication | public function uasort($function): self |
894 | |||
895 | /** |
||
896 | * Sort the entries with a user-defined comparison function and maintain key association. |
||
897 | * |
||
898 | * @param callable $function |
||
899 | * |
||
900 | * @throws \InvalidArgumentException |
||
901 | * |
||
902 | * @return $this |
||
903 | * <p>(Immutable) Return this Arrayy object.</p> |
||
904 | * |
||
905 | * @psalm-return static<TKey,T> |
||
906 | * @psalm-mutation-free |
||
907 | */ |
||
908 | 4 | public function uasortImmutable($function): self |
|
919 | |||
920 | /** |
||
921 | * Sort the entries by keys using a user-defined comparison function. |
||
922 | * |
||
923 | * @param callable $function |
||
924 | * |
||
925 | * @throws \InvalidArgumentException |
||
926 | * |
||
927 | * @return static |
||
928 | * <p>(Mutable) Return this Arrayy object.</p> |
||
929 | * |
||
930 | * @psalm-return static<TKey,T> |
||
931 | */ |
||
932 | 5 | public function uksort($function): self |
|
936 | |||
937 | /** |
||
938 | * Sort the entries by keys using a user-defined comparison function. |
||
939 | * |
||
940 | * @param callable $function |
||
941 | * |
||
942 | * @throws \InvalidArgumentException |
||
943 | * |
||
944 | * @return static |
||
945 | * <p>(Immutable) Return this Arrayy object.</p> |
||
946 | * |
||
947 | * @psalm-return static<TKey,T> |
||
948 | * @psalm-mutation-free |
||
949 | */ |
||
950 | 1 | public function uksortImmutable($function): self |
|
954 | |||
955 | /** |
||
956 | * Unserialize an string and return the instance of the "Arrayy"-class. |
||
957 | * |
||
958 | * EXAMPLE: <code> |
||
959 | * $serialized = a([1, 4, 7])->serialize(); |
||
960 | * a()->unserialize($serialized); |
||
961 | * </code> |
||
962 | * |
||
963 | * @param string $string |
||
964 | * |
||
965 | * @return $this |
||
966 | * |
||
967 | * @psalm-return static<TKey,T> |
||
968 | */ |
||
969 | 2 | public function unserialize($string): self |
|
979 | |||
980 | /** |
||
981 | * Append a (key) + values to the current array. |
||
982 | * |
||
983 | * EXAMPLE: <code> |
||
984 | * a(['fòô' => ['bàř']])->appendArrayValues(['foo1', 'foo2'], 'fòô'); // Arrayy['fòô' => ['bàř', 'foo1', 'foo2']] |
||
985 | * </code> |
||
986 | * |
||
987 | * @param array $values |
||
988 | * @param mixed $key |
||
989 | * |
||
990 | * @return $this |
||
991 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
992 | * |
||
993 | * @psalm-param array<mixed,T> $values |
||
994 | * @psalm-param TKey|null $key |
||
995 | * @psalm-return static<TKey,T> |
||
996 | */ |
||
997 | 1 | public function appendArrayValues(array $values, $key = null) |
|
1023 | |||
1024 | /** |
||
1025 | * Add a suffix to each key. |
||
1026 | * |
||
1027 | * @param mixed $prefix |
||
1028 | * |
||
1029 | * @return static |
||
1030 | * <p>(Immutable) Return an Arrayy object, with the prefixed keys.</p> |
||
1031 | * |
||
1032 | * @psalm-return static<TKey,T> |
||
1033 | * @psalm-mutation-free |
||
1034 | */ |
||
1035 | 10 | View Code Duplication | public function appendToEachKey($prefix): self |
1054 | |||
1055 | /** |
||
1056 | * Add a prefix to each value. |
||
1057 | * |
||
1058 | * @param mixed $prefix |
||
1059 | * |
||
1060 | * @return static |
||
1061 | * <p>(Immutable) Return an Arrayy object, with the prefixed values.</p> |
||
1062 | * |
||
1063 | * @psalm-return static<TKey,T> |
||
1064 | * @psalm-mutation-free |
||
1065 | */ |
||
1066 | 10 | View Code Duplication | public function appendToEachValue($prefix): self |
1085 | |||
1086 | /** |
||
1087 | * Sort an array in reverse order and maintain index association. |
||
1088 | * |
||
1089 | * @return $this |
||
1090 | * <p>(Mutable) Return this Arrayy object.</p> |
||
1091 | * |
||
1092 | * @psalm-return static<TKey,T> |
||
1093 | */ |
||
1094 | 4 | public function arsort(): self |
|
1102 | |||
1103 | /** |
||
1104 | * Sort an array in reverse order and maintain index association. |
||
1105 | * |
||
1106 | * @return $this |
||
1107 | * <p>(Immutable) Return this Arrayy object.</p> |
||
1108 | * |
||
1109 | * @psalm-return static<TKey,T> |
||
1110 | * @psalm-mutation-free |
||
1111 | */ |
||
1112 | 10 | public function arsortImmutable(): self |
|
1122 | |||
1123 | /** |
||
1124 | * Iterate over the current array and execute a callback for each loop. |
||
1125 | * |
||
1126 | * EXAMPLE: <code> |
||
1127 | * $result = A::create(); |
||
1128 | * $closure = function ($value, $key) use ($result) { |
||
1129 | * $result[$key] = ':' . $value . ':'; |
||
1130 | * }; |
||
1131 | * a(['foo', 'bar' => 'bis'])->at($closure); // Arrayy[':foo:', 'bar' => ':bis:'] |
||
1132 | * </code> |
||
1133 | * |
||
1134 | * @param \Closure $closure |
||
1135 | * |
||
1136 | * @return static |
||
1137 | * <p>(Immutable)</p> |
||
1138 | * |
||
1139 | * @psalm-return static<TKey,T> |
||
1140 | * @psalm-mutation-free |
||
1141 | */ |
||
1142 | 3 | public function at(\Closure $closure): self |
|
1156 | |||
1157 | /** |
||
1158 | * Returns the average value of the current array. |
||
1159 | * |
||
1160 | * EXAMPLE: <code> |
||
1161 | * a([-9, -8, -7, 1.32])->average(2); // -5.67 |
||
1162 | * </code> |
||
1163 | * |
||
1164 | * @param int $decimals <p>The number of decimal-numbers to return.</p> |
||
1165 | * |
||
1166 | * @return float|int |
||
1167 | * <p>The average value.</p> |
||
1168 | * @psalm-mutation-free |
||
1169 | */ |
||
1170 | 10 | public function average($decimals = 0) |
|
1184 | |||
1185 | /** |
||
1186 | * Changes all keys in an array. |
||
1187 | * |
||
1188 | * @param int $case [optional] <p> Either <strong>CASE_UPPER</strong><br /> |
||
1189 | * or <strong>CASE_LOWER</strong> (default)</p> |
||
1190 | * |
||
1191 | * @return static |
||
1192 | * <p>(Immutable)</p> |
||
1193 | * |
||
1194 | * @psalm-return static<TKey,T> |
||
1195 | * @psalm-mutation-free |
||
1196 | */ |
||
1197 | 1 | public function changeKeyCase(int $case = \CASE_LOWER): self |
|
1226 | |||
1227 | /** |
||
1228 | * Change the path separator of the array wrapper. |
||
1229 | * |
||
1230 | * By default, the separator is: "." |
||
1231 | * |
||
1232 | * @param string $separator <p>Separator to set.</p> |
||
1233 | * |
||
1234 | * @return $this |
||
1235 | * <p>(Mutable) Return this Arrayy object.</p> |
||
1236 | * |
||
1237 | * @psalm-return static<TKey,T> |
||
1238 | */ |
||
1239 | 11 | public function changeSeparator($separator): self |
|
1245 | |||
1246 | /** |
||
1247 | * Create a chunked version of the current array. |
||
1248 | * |
||
1249 | * EXAMPLE: <code> |
||
1250 | * a([-9, -8, -7, 1.32])->chunk(2); // Arrayy[[-9, -8], [-7, 1.32]] |
||
1251 | * </code> |
||
1252 | * |
||
1253 | * @param int $size <p>Size of each chunk.</p> |
||
1254 | * @param bool $preserveKeys <p>Whether array keys are preserved or no.</p> |
||
1255 | * |
||
1256 | * @return static |
||
1257 | * <p>(Immutable) A new array of chunks from the original array.</p> |
||
1258 | * |
||
1259 | * @psalm-return static<TKey,T> |
||
1260 | * @psalm-mutation-free |
||
1261 | */ |
||
1262 | 5 | public function chunk($size, $preserveKeys = false): self |
|
1270 | |||
1271 | /** |
||
1272 | * Clean all falsy values from the current array. |
||
1273 | * |
||
1274 | * EXAMPLE: <code> |
||
1275 | * a([-8 => -9, 1, 2 => false])->clean(); // Arrayy[-8 => -9, 1] |
||
1276 | * </code> |
||
1277 | * |
||
1278 | * @return static |
||
1279 | * <p>(Immutable)</p> |
||
1280 | * |
||
1281 | * @psalm-return static<TKey,T> |
||
1282 | * @psalm-mutation-free |
||
1283 | */ |
||
1284 | 8 | public function clean(): self |
|
1292 | |||
1293 | /** |
||
1294 | * WARNING!!! -> Clear the current full array or a $key of it. |
||
1295 | * |
||
1296 | * EXAMPLE: <code> |
||
1297 | * a([-8 => -9, 1, 2 => false])->clear(); // Arrayy[] |
||
1298 | * </code> |
||
1299 | * |
||
1300 | * @param int|int[]|string|string[]|null $key |
||
1301 | * |
||
1302 | * @return $this |
||
1303 | * <p>(Mutable) Return this Arrayy object, with an empty array.</p> |
||
1304 | * |
||
1305 | * @psalm-return static<TKey,T> |
||
1306 | */ |
||
1307 | 10 | public function clear($key = null): self |
|
1326 | |||
1327 | /** |
||
1328 | * Check if an item is in the current array. |
||
1329 | * |
||
1330 | * EXAMPLE: <code> |
||
1331 | * a([1, true])->contains(true); // true |
||
1332 | * </code> |
||
1333 | * |
||
1334 | * @param float|int|string $value |
||
1335 | * @param bool $recursive |
||
1336 | * @param bool $strict |
||
1337 | * |
||
1338 | * @return bool |
||
1339 | * @psalm-mutation-free |
||
1340 | */ |
||
1341 | 23 | public function contains($value, bool $recursive = false, bool $strict = true): bool |
|
1342 | { |
||
1343 | 23 | if ($recursive === true) { |
|
1344 | 18 | return $this->in_array_recursive($value, $this->toArray(), $strict); |
|
1345 | } |
||
1346 | |||
1347 | /** @noinspection PhpParameterByRefIsNotUsedAsReferenceInspection */ |
||
1348 | 14 | foreach ($this->getGeneratorByReference() as &$valueFromArray) { |
|
1349 | 11 | if ($strict) { |
|
1350 | 11 | if ($value === $valueFromArray) { |
|
1351 | 11 | return true; |
|
1352 | } |
||
1353 | } else { |
||
1354 | /** @noinspection NestedPositiveIfStatementsInspection */ |
||
1355 | if ($value == $valueFromArray) { |
||
1356 | 7 | return true; |
|
1357 | } |
||
1358 | } |
||
1359 | } |
||
1360 | |||
1361 | 7 | return false; |
|
1362 | } |
||
1363 | |||
1364 | /** |
||
1365 | * Check if an (case-insensitive) string is in the current array. |
||
1366 | * |
||
1367 | * EXAMPLE: <code> |
||
1368 | * a(['E', 'é'])->containsCaseInsensitive('É'); // true |
||
1369 | * </code> |
||
1370 | * |
||
1371 | * @param mixed $value |
||
1372 | * @param bool $recursive |
||
1373 | * |
||
1374 | * @return bool |
||
1375 | * @psalm-mutation-free |
||
1376 | * |
||
1377 | * @psalm-suppress InvalidCast - hack for int|float|bool support |
||
1378 | */ |
||
1379 | 26 | public function containsCaseInsensitive($value, $recursive = false): bool |
|
1410 | |||
1411 | /** |
||
1412 | * Check if the given key/index exists in the array. |
||
1413 | * |
||
1414 | * EXAMPLE: <code> |
||
1415 | * a([1 => true])->containsKey(1); // true |
||
1416 | * </code> |
||
1417 | * |
||
1418 | * @param int|string $key <p>key/index to search for</p> |
||
1419 | * |
||
1420 | * @return bool |
||
1421 | * <p>Returns true if the given key/index exists in the array, false otherwise.</p> |
||
1422 | * |
||
1423 | * @psalm-mutation-free |
||
1424 | */ |
||
1425 | 4 | public function containsKey($key): bool |
|
1429 | |||
1430 | /** |
||
1431 | * Check if all given needles are present in the array as key/index. |
||
1432 | * |
||
1433 | * EXAMPLE: <code> |
||
1434 | * a([1 => true])->containsKeys(array(1 => 0)); // true |
||
1435 | * </code> |
||
1436 | * |
||
1437 | * @param array $needles <p>The keys you are searching for.</p> |
||
1438 | * @param bool $recursive |
||
1439 | * |
||
1440 | * @return bool |
||
1441 | * <p>Returns true if all the given keys/indexes exists in the array, false otherwise.</p> |
||
1442 | * |
||
1443 | * @psalm-param array<mixed,mixed>|array<TKey> $needles |
||
1444 | * @psalm-mutation-free |
||
1445 | */ |
||
1446 | 2 | public function containsKeys(array $needles, $recursive = false): bool |
|
1474 | |||
1475 | /** |
||
1476 | * Check if all given needles are present in the array as key/index. |
||
1477 | * |
||
1478 | * @param array $needles <p>The keys you are searching for.</p> |
||
1479 | * |
||
1480 | * @return bool |
||
1481 | * <p>Returns true if all the given keys/indexes exists in the array, false otherwise.</p> |
||
1482 | * |
||
1483 | * @psalm-param array<mixed,mixed>|array<TKey> $needles |
||
1484 | * @psalm-mutation-free |
||
1485 | */ |
||
1486 | 1 | public function containsKeysRecursive(array $needles): bool |
|
1490 | |||
1491 | /** |
||
1492 | * alias: for "Arrayy->contains()" |
||
1493 | * |
||
1494 | * @param float|int|string $value |
||
1495 | * |
||
1496 | * @return bool |
||
1497 | * |
||
1498 | * @see Arrayy::contains() |
||
1499 | * @psalm-mutation-free |
||
1500 | */ |
||
1501 | 9 | public function containsValue($value): bool |
|
1505 | |||
1506 | /** |
||
1507 | * alias: for "Arrayy->contains($value, true)" |
||
1508 | * |
||
1509 | * @param float|int|string $value |
||
1510 | * |
||
1511 | * @return bool |
||
1512 | * |
||
1513 | * @see Arrayy::contains() |
||
1514 | * @psalm-mutation-free |
||
1515 | */ |
||
1516 | 18 | public function containsValueRecursive($value): bool |
|
1520 | |||
1521 | /** |
||
1522 | * Check if all given needles are present in the array. |
||
1523 | * |
||
1524 | * EXAMPLE: <code> |
||
1525 | * a([1, true])->containsValues(array(1, true)); // true |
||
1526 | * </code> |
||
1527 | * |
||
1528 | * @param array $needles |
||
1529 | * |
||
1530 | * @return bool |
||
1531 | * <p>Returns true if all the given values exists in the array, false otherwise.</p> |
||
1532 | * |
||
1533 | * @psalm-param array<mixed>|array<T> $needles |
||
1534 | * @psalm-mutation-free |
||
1535 | */ |
||
1536 | 1 | public function containsValues(array $needles): bool |
|
1551 | |||
1552 | /** |
||
1553 | * Counts all the values of an array |
||
1554 | * |
||
1555 | * @see http://php.net/manual/en/function.array-count-values.php |
||
1556 | * |
||
1557 | * @return static |
||
1558 | * <p> |
||
1559 | * (Immutable) |
||
1560 | * An associative Arrayy-object of values from input as |
||
1561 | * keys and their count as value. |
||
1562 | * </p> |
||
1563 | * |
||
1564 | * @psalm-return static<TKey,T> |
||
1565 | * @psalm-mutation-free |
||
1566 | */ |
||
1567 | 7 | public function countValues(): self |
|
1571 | |||
1572 | /** |
||
1573 | * Creates an Arrayy object. |
||
1574 | * |
||
1575 | * @param mixed $data |
||
1576 | * @param string $iteratorClass |
||
1577 | * @param bool $checkPropertiesInConstructor |
||
1578 | * |
||
1579 | * @return static |
||
1580 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1581 | * |
||
1582 | * @psalm-param class-string<\Arrayy\ArrayyIterator> $iteratorClass |
||
1583 | * |
||
1584 | * @psalm-mutation-free |
||
1585 | */ |
||
1586 | 724 | public static function create( |
|
1597 | |||
1598 | /** |
||
1599 | * Flatten an array with the given character as a key delimiter |
||
1600 | * |
||
1601 | * @param string $delimiter |
||
1602 | * @param string $prepend |
||
1603 | * @param array|null $items |
||
1604 | * |
||
1605 | * @return array |
||
1606 | */ |
||
1607 | 2 | public function flatten($delimiter = '.', $prepend = '', $items = null) |
|
1630 | |||
1631 | /** |
||
1632 | * WARNING: Creates an Arrayy object by reference. |
||
1633 | * |
||
1634 | * @param array $array |
||
1635 | * |
||
1636 | * @return $this |
||
1637 | * <p>(Mutable) Return this Arrayy object.</p> |
||
1638 | * |
||
1639 | * @psalm-param array<mixed,mixed>|array<array-key,mixed> $array |
||
1640 | */ |
||
1641 | 26 | public function createByReference(array &$array = []): self |
|
1649 | |||
1650 | /** |
||
1651 | * Create an new instance from a callable function which will return an Generator. |
||
1652 | * |
||
1653 | * @param callable $generatorFunction |
||
1654 | * |
||
1655 | * @return static |
||
1656 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1657 | * |
||
1658 | * @psalm-param callable():\Generator<array-key,mixed> $generatorFunction |
||
1659 | * |
||
1660 | * @psalm-mutation-free |
||
1661 | */ |
||
1662 | 7 | public static function createFromGeneratorFunction(callable $generatorFunction): self |
|
1666 | |||
1667 | /** |
||
1668 | * Create an new instance filled with a copy of values from a "Generator"-object. |
||
1669 | * |
||
1670 | * @param \Generator $generator |
||
1671 | * |
||
1672 | * @return static |
||
1673 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1674 | * |
||
1675 | * @psalm-param \Generator<array-key,mixed> $generator |
||
1676 | * |
||
1677 | * @psalm-mutation-free |
||
1678 | */ |
||
1679 | 4 | public static function createFromGeneratorImmutable(\Generator $generator): self |
|
1683 | |||
1684 | /** |
||
1685 | * Create an new Arrayy object via JSON. |
||
1686 | * |
||
1687 | * @param string $json |
||
1688 | * |
||
1689 | * @return static |
||
1690 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1691 | * |
||
1692 | * @psalm-mutation-free |
||
1693 | */ |
||
1694 | 5 | public static function createFromJson(string $json): self |
|
1698 | |||
1699 | /** |
||
1700 | * Create an new Arrayy object via JSON. |
||
1701 | * |
||
1702 | * @param array $array |
||
1703 | * |
||
1704 | * @return static |
||
1705 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1706 | * |
||
1707 | * @psalm-mutation-free |
||
1708 | */ |
||
1709 | 1 | public static function createFromArray(array $array): self |
|
1713 | |||
1714 | /** |
||
1715 | * Create an new instance filled with values from an object that is iterable. |
||
1716 | * |
||
1717 | * @param \Traversable $object <p>iterable object</p> |
||
1718 | * |
||
1719 | * @return static |
||
1720 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1721 | * |
||
1722 | * @psalm-param \Traversable<array-key,mixed> $object |
||
1723 | * |
||
1724 | * @psalm-mutation-free |
||
1725 | */ |
||
1726 | 4 | public static function createFromObject(\Traversable $object): self |
|
1746 | |||
1747 | /** |
||
1748 | * Create an new instance filled with values from an object. |
||
1749 | * |
||
1750 | * @param object $object |
||
1751 | * |
||
1752 | * @return static |
||
1753 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1754 | * |
||
1755 | * @psalm-mutation-free |
||
1756 | */ |
||
1757 | 5 | public static function createFromObjectVars($object): self |
|
1761 | |||
1762 | /** |
||
1763 | * Create an new Arrayy object via string. |
||
1764 | * |
||
1765 | * @param string $str <p>The input string.</p> |
||
1766 | * @param string|null $delimiter <p>The boundary string.</p> |
||
1767 | * @param string|null $regEx <p>Use the $delimiter or the $regEx, so if $pattern is null, $delimiter will be |
||
1768 | * used.</p> |
||
1769 | * |
||
1770 | * @return static |
||
1771 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1772 | * |
||
1773 | * @psalm-mutation-free |
||
1774 | */ |
||
1775 | 10 | public static function createFromString(string $str, string $delimiter = null, string $regEx = null): self |
|
1807 | |||
1808 | /** |
||
1809 | * Create an new instance filled with a copy of values from a "Traversable"-object. |
||
1810 | * |
||
1811 | * @param \Traversable $traversable |
||
1812 | * |
||
1813 | * @return static |
||
1814 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1815 | * |
||
1816 | * @psalm-param \Traversable<array-key,mixed> $traversable |
||
1817 | * |
||
1818 | * @psalm-mutation-free |
||
1819 | */ |
||
1820 | 1 | public static function createFromTraversableImmutable(\Traversable $traversable): self |
|
1824 | |||
1825 | /** |
||
1826 | * Create an new instance containing a range of elements. |
||
1827 | * |
||
1828 | * @param float|int|string $low <p>First value of the sequence.</p> |
||
1829 | * @param float|int|string $high <p>The sequence is ended upon reaching the end value.</p> |
||
1830 | * @param float|int $step <p>Used as the increment between elements in the sequence.</p> |
||
1831 | * |
||
1832 | * @return static |
||
1833 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1834 | * |
||
1835 | * @psalm-mutation-free |
||
1836 | */ |
||
1837 | 2 | public static function createWithRange($low, $high, $step = 1): self |
|
1841 | |||
1842 | /** |
||
1843 | * Gets the element of the array at the current internal iterator position. |
||
1844 | * |
||
1845 | * @return false|mixed |
||
1846 | */ |
||
1847 | public function current() |
||
1851 | |||
1852 | /** |
||
1853 | * Custom sort by index via "uksort". |
||
1854 | * |
||
1855 | * EXAMPLE: <code> |
||
1856 | * $callable = function ($a, $b) { |
||
1857 | * if ($a == $b) { |
||
1858 | * return 0; |
||
1859 | * } |
||
1860 | * return ($a > $b) ? 1 : -1; |
||
1861 | * }; |
||
1862 | * $arrayy = a(['three' => 3, 'one' => 1, 'two' => 2]); |
||
1863 | * $resultArrayy = $arrayy->customSortKeys($callable); // Arrayy['one' => 1, 'three' => 3, 'two' => 2] |
||
1864 | * </code> |
||
1865 | * |
||
1866 | * @see http://php.net/manual/en/function.uksort.php |
||
1867 | * |
||
1868 | * @param callable $function |
||
1869 | * |
||
1870 | * @throws \InvalidArgumentException |
||
1871 | * |
||
1872 | * @return $this |
||
1873 | * <p>(Mutable) Return this Arrayy object.</p> |
||
1874 | * |
||
1875 | * @psalm-return static<TKey,T> |
||
1876 | */ |
||
1877 | 5 | public function customSortKeys(callable $function): self |
|
1885 | |||
1886 | /** |
||
1887 | * Custom sort by index via "uksort". |
||
1888 | * |
||
1889 | * @see http://php.net/manual/en/function.uksort.php |
||
1890 | * |
||
1891 | * @param callable $function |
||
1892 | * |
||
1893 | * @throws \InvalidArgumentException |
||
1894 | * |
||
1895 | * @return $this |
||
1896 | * <p>(Immutable) Return this Arrayy object.</p> |
||
1897 | * |
||
1898 | * @psalm-return static<TKey,T> |
||
1899 | * @psalm-mutation-free |
||
1900 | */ |
||
1901 | 1 | public function customSortKeysImmutable(callable $function): self |
|
1914 | |||
1915 | /** |
||
1916 | * Custom sort by value via "usort". |
||
1917 | * |
||
1918 | * EXAMPLE: <code> |
||
1919 | * $callable = function ($a, $b) { |
||
1920 | * if ($a == $b) { |
||
1921 | * return 0; |
||
1922 | * } |
||
1923 | * return ($a > $b) ? 1 : -1; |
||
1924 | * }; |
||
1925 | * $arrayy = a(['three' => 3, 'one' => 1, 'two' => 2]); |
||
1926 | * $resultArrayy = $arrayy->customSortValues($callable); // Arrayy['one' => 1, 'two' => 2, 'three' => 3] |
||
1927 | * </code> |
||
1928 | * |
||
1929 | * @see http://php.net/manual/en/function.usort.php |
||
1930 | * |
||
1931 | * @param callable $function |
||
1932 | * |
||
1933 | * @throws \InvalidArgumentException |
||
1934 | * |
||
1935 | * @return $this |
||
1936 | * <p>(Mutable) Return this Arrayy object.</p> |
||
1937 | * |
||
1938 | * @psalm-return static<TKey,T> |
||
1939 | */ |
||
1940 | 10 | View Code Duplication | public function customSortValues($function): self |
1952 | |||
1953 | /** |
||
1954 | * Custom sort by value via "usort". |
||
1955 | * |
||
1956 | * @see http://php.net/manual/en/function.usort.php |
||
1957 | * |
||
1958 | * @param callable $function |
||
1959 | * |
||
1960 | * @throws \InvalidArgumentException |
||
1961 | * |
||
1962 | * @return $this |
||
1963 | * <p>(Immutable) Return this Arrayy object.</p> |
||
1964 | * |
||
1965 | * @psalm-return static<TKey,T> |
||
1966 | * @psalm-mutation-free |
||
1967 | */ |
||
1968 | 4 | public function customSortValuesImmutable($function): self |
|
1979 | |||
1980 | /** |
||
1981 | * Delete the given key or keys. |
||
1982 | * |
||
1983 | * @param int|int[]|string|string[] $keyOrKeys |
||
1984 | * |
||
1985 | * @return void |
||
1986 | */ |
||
1987 | 9 | public function delete($keyOrKeys) |
|
1995 | |||
1996 | /** |
||
1997 | * Return values that are only in the current array. |
||
1998 | * |
||
1999 | * EXAMPLE: <code> |
||
2000 | * a([1 => 1, 2 => 2])->diff([1 => 1]); // Arrayy[2 => 2] |
||
2001 | * </code> |
||
2002 | * |
||
2003 | * @param array ...$array |
||
2004 | * |
||
2005 | * @return static |
||
2006 | * <p>(Immutable)</p> |
||
2007 | * |
||
2008 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$array |
||
2009 | * @psalm-return static<TKey,T> |
||
2010 | * @psalm-mutation-free |
||
2011 | */ |
||
2012 | 13 | public function diff(...$array): self |
|
2020 | |||
2021 | /** |
||
2022 | * Return values that are only in the current array. |
||
2023 | * |
||
2024 | * @param array ...$array |
||
2025 | * |
||
2026 | * @return static |
||
2027 | * <p>(Immutable)</p> |
||
2028 | * |
||
2029 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$array |
||
2030 | * @psalm-return static<TKey,T> |
||
2031 | * @psalm-mutation-free |
||
2032 | */ |
||
2033 | 8 | public function diffKey(...$array): self |
|
2041 | |||
2042 | /** |
||
2043 | * Return values and Keys that are only in the current array. |
||
2044 | * |
||
2045 | * @param array $array |
||
2046 | * |
||
2047 | * @return static |
||
2048 | * <p>(Immutable)</p> |
||
2049 | * |
||
2050 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
2051 | * @psalm-return static<TKey,T> |
||
2052 | * @psalm-mutation-free |
||
2053 | */ |
||
2054 | 8 | public function diffKeyAndValue(array $array = []): self |
|
2062 | |||
2063 | /** |
||
2064 | * Return values that are only in the current multi-dimensional array. |
||
2065 | * |
||
2066 | * EXAMPLE: <code> |
||
2067 | * a([1 => [1 => 1], 2 => [2 => 2]])->diffRecursive([1 => [1 => 1]]); // Arrayy[2 => [2 => 2]] |
||
2068 | * </code> |
||
2069 | * |
||
2070 | * @param array $array |
||
2071 | * @param array|\Generator|null $helperVariableForRecursion <p>(only for internal usage)</p> |
||
2072 | * |
||
2073 | * @return static |
||
2074 | * <p>(Immutable)</p> |
||
2075 | * |
||
2076 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
2077 | * @psalm-param null|array<TKey,T>|\Generator<TKey,T> $helperVariableForRecursion |
||
2078 | * @psalm-return static<TKey,T> |
||
2079 | * @psalm-mutation-free |
||
2080 | */ |
||
2081 | 1 | public function diffRecursive(array $array = [], $helperVariableForRecursion = null): self |
|
2116 | |||
2117 | /** |
||
2118 | * Return values that are only in the new $array. |
||
2119 | * |
||
2120 | * EXAMPLE: <code> |
||
2121 | * a([1 => 1])->diffReverse([1 => 1, 2 => 2]); // Arrayy[2 => 2] |
||
2122 | * </code> |
||
2123 | * |
||
2124 | * @param array $array |
||
2125 | * |
||
2126 | * @return static |
||
2127 | * <p>(Immutable)</p> |
||
2128 | * |
||
2129 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
2130 | * @psalm-return static<TKey,T> |
||
2131 | * @psalm-mutation-free |
||
2132 | */ |
||
2133 | 8 | public function diffReverse(array $array = []): self |
|
2141 | |||
2142 | /** |
||
2143 | * Divide an array into two arrays. One with keys and the other with values. |
||
2144 | * |
||
2145 | * EXAMPLE: <code> |
||
2146 | * a(['a' => 1, 'b' => ''])->divide(); // Arrayy[Arrayy['a', 'b'], Arrayy[1, '']] |
||
2147 | * </code> |
||
2148 | * |
||
2149 | * @return static |
||
2150 | * <p>(Immutable)</p> |
||
2151 | * |
||
2152 | * @psalm-return static<TKey,T> |
||
2153 | * @psalm-mutation-free |
||
2154 | */ |
||
2155 | 1 | public function divide(): self |
|
2166 | |||
2167 | /** |
||
2168 | * Iterate over the current array and modify the array's value. |
||
2169 | * |
||
2170 | * EXAMPLE: <code> |
||
2171 | * $result = A::create(); |
||
2172 | * $closure = function ($value) { |
||
2173 | * return ':' . $value . ':'; |
||
2174 | * }; |
||
2175 | * a(['foo', 'bar' => 'bis'])->each($closure); // Arrayy[':foo:', 'bar' => ':bis:'] |
||
2176 | * </code> |
||
2177 | * |
||
2178 | * @param \Closure $closure |
||
2179 | * |
||
2180 | * @return static |
||
2181 | * <p>(Immutable)</p> |
||
2182 | * |
||
2183 | * @psalm-return static<TKey,T> |
||
2184 | * @psalm-mutation-free |
||
2185 | */ |
||
2186 | 5 | View Code Duplication | public function each(\Closure $closure): self |
2201 | |||
2202 | /** |
||
2203 | * Sets the internal iterator to the last element in the array and returns this element. |
||
2204 | * |
||
2205 | * @return mixed |
||
2206 | */ |
||
2207 | public function end() |
||
2211 | |||
2212 | /** |
||
2213 | * Check if a value is in the current array using a closure. |
||
2214 | * |
||
2215 | * EXAMPLE: <code> |
||
2216 | * $callable = function ($value, $key) { |
||
2217 | * return 2 === $key and 'two' === $value; |
||
2218 | * }; |
||
2219 | * a(['foo', 2 => 'two'])->exists($callable); // true |
||
2220 | * </code> |
||
2221 | * |
||
2222 | * @param \Closure $closure |
||
2223 | * |
||
2224 | * @return bool |
||
2225 | * <p>Returns true if the given value is found, false otherwise.</p> |
||
2226 | */ |
||
2227 | 4 | public function exists(\Closure $closure): bool |
|
2242 | |||
2243 | /** |
||
2244 | * Fill the array until "$num" with "$default" values. |
||
2245 | * |
||
2246 | * EXAMPLE: <code> |
||
2247 | * a(['bar'])->fillWithDefaults(3, 'foo'); // Arrayy['bar', 'foo', 'foo'] |
||
2248 | * </code> |
||
2249 | * |
||
2250 | * @param int $num |
||
2251 | * @param mixed $default |
||
2252 | * |
||
2253 | * @return static |
||
2254 | * <p>(Immutable)</p> |
||
2255 | * |
||
2256 | * @psalm-return static<TKey,T> |
||
2257 | * @psalm-mutation-free |
||
2258 | */ |
||
2259 | 8 | public function fillWithDefaults(int $num, $default = null): self |
|
2282 | |||
2283 | /** |
||
2284 | * Find all items in an array that pass the truth test. |
||
2285 | * |
||
2286 | * EXAMPLE: <code> |
||
2287 | * $closure = function ($value) { |
||
2288 | * return $value % 2 !== 0; |
||
2289 | * } |
||
2290 | * a([1, 2, 3, 4])->filter($closure); // Arrayy[0 => 1, 2 => 3] |
||
2291 | * </code> |
||
2292 | * |
||
2293 | * @param \Closure|null $closure [optional] <p> |
||
2294 | * The callback function to use |
||
2295 | * </p> |
||
2296 | * <p> |
||
2297 | * If no callback is supplied, all entries of |
||
2298 | * input equal to false (see |
||
2299 | * converting to |
||
2300 | * boolean) will be removed. |
||
2301 | * </p> |
||
2302 | * @param int $flag [optional] <p> |
||
2303 | * Flag determining what arguments are sent to <i>callback</i>: |
||
2304 | * </p> |
||
2305 | * <ul> |
||
2306 | * <li> |
||
2307 | * <b>ARRAY_FILTER_USE_KEY</b> (1) - pass key as the only argument |
||
2308 | * to <i>callback</i> instead of the value |
||
2309 | * </li> |
||
2310 | * <li> |
||
2311 | * <b>ARRAY_FILTER_USE_BOTH</b> (2) - pass both value and key as |
||
2312 | * arguments to <i>callback</i> instead of the value |
||
2313 | * </li> |
||
2314 | * </ul> |
||
2315 | * |
||
2316 | * @return static |
||
2317 | * <p>(Immutable)</p> |
||
2318 | * |
||
2319 | * @psalm-param null|\Closure(T=,TKey=):bool|\Closure(T=):bool||\Closure(TKey=):bool $closure |
||
2320 | * @psalm-return static<TKey,T> |
||
2321 | * @psalm-mutation-free |
||
2322 | */ |
||
2323 | 12 | public function filter($closure = null, int $flag = \ARRAY_FILTER_USE_BOTH) |
|
2361 | |||
2362 | /** |
||
2363 | * Filters an array of objects (or a numeric array of associative arrays) based on the value of a particular |
||
2364 | * property within that. |
||
2365 | * |
||
2366 | * @param string $property |
||
2367 | * @param string|string[] $value |
||
2368 | * @param string $comparisonOp |
||
2369 | * <p> |
||
2370 | * 'eq' (equals),<br /> |
||
2371 | * 'gt' (greater),<br /> |
||
2372 | * 'gte' || 'ge' (greater or equals),<br /> |
||
2373 | * 'lt' (less),<br /> |
||
2374 | * 'lte' || 'le' (less or equals),<br /> |
||
2375 | * 'ne' (not equals),<br /> |
||
2376 | * 'contains',<br /> |
||
2377 | * 'notContains',<br /> |
||
2378 | * 'newer' (via strtotime),<br /> |
||
2379 | * 'older' (via strtotime),<br /> |
||
2380 | * </p> |
||
2381 | * |
||
2382 | * @return static |
||
2383 | * <p>(Immutable)</p> |
||
2384 | * |
||
2385 | * @psalm-return static<TKey,T> |
||
2386 | * @psalm-mutation-free |
||
2387 | * |
||
2388 | * @psalm-suppress MissingClosureReturnType |
||
2389 | * @psalm-suppress MissingClosureParamType |
||
2390 | */ |
||
2391 | 1 | public function filterBy( |
|
2463 | |||
2464 | /** |
||
2465 | * Find the first item in an array that passes the truth test, otherwise return false. |
||
2466 | * |
||
2467 | * EXAMPLE: <code> |
||
2468 | * $search = 'foo'; |
||
2469 | * $closure = function ($value, $key) use ($search) { |
||
2470 | * return $value === $search; |
||
2471 | * }; |
||
2472 | * a(['foo', 'bar', 'lall'])->find($closure); // 'foo' |
||
2473 | * </code> |
||
2474 | * |
||
2475 | * @param \Closure $closure |
||
2476 | * |
||
2477 | * @return false|mixed |
||
2478 | * <p>Return false if we did not find the value.</p> |
||
2479 | */ |
||
2480 | 8 | View Code Duplication | public function find(\Closure $closure) |
2490 | |||
2491 | /** |
||
2492 | * find by ... |
||
2493 | * |
||
2494 | * EXAMPLE: <code> |
||
2495 | * $array = [ |
||
2496 | * 0 => ['id' => 123, 'name' => 'foo', 'group' => 'primary', 'value' => 123456, 'when' => '2014-01-01'], |
||
2497 | * 1 => ['id' => 456, 'name' => 'bar', 'group' => 'primary', 'value' => 1468, 'when' => '2014-07-15'], |
||
2498 | * ]; |
||
2499 | * a($array)->filterBy('name', 'foo'); // Arrayy[0 => ['id' => 123, 'name' => 'foo', 'group' => 'primary', 'value' => 123456, 'when' => '2014-01-01']] |
||
2500 | * </code> |
||
2501 | * |
||
2502 | * @param string $property |
||
2503 | * @param string|string[] $value |
||
2504 | * @param string $comparisonOp |
||
2505 | * |
||
2506 | * @return static |
||
2507 | * <p>(Immutable)</p> |
||
2508 | * |
||
2509 | * @psalm-return static<TKey,T> |
||
2510 | * @psalm-mutation-free |
||
2511 | */ |
||
2512 | 1 | public function findBy(string $property, $value, string $comparisonOp = 'eq'): self |
|
2516 | |||
2517 | /** |
||
2518 | * Get the first value from the current array. |
||
2519 | * |
||
2520 | * EXAMPLE: <code> |
||
2521 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->first(); // 'foo' |
||
2522 | * </code> |
||
2523 | * |
||
2524 | * @return mixed |
||
2525 | * <p>Return null if there wasn't a element.</p> |
||
2526 | */ |
||
2527 | 22 | public function first() |
|
2536 | |||
2537 | /** |
||
2538 | * Get the first key from the current array. |
||
2539 | * |
||
2540 | * @return mixed |
||
2541 | * <p>Return null if there wasn't a element.</p> |
||
2542 | * @psalm-mutation-free |
||
2543 | */ |
||
2544 | 29 | public function firstKey() |
|
2550 | |||
2551 | /** |
||
2552 | * Get the first value(s) from the current array. |
||
2553 | * And will return an empty array if there was no first entry. |
||
2554 | * |
||
2555 | * EXAMPLE: <code> |
||
2556 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->firstsImmutable(2); // Arrayy[0 => 'foo', 1 => 'bar'] |
||
2557 | * </code> |
||
2558 | * |
||
2559 | * @param int|null $number <p>How many values you will take?</p> |
||
2560 | * |
||
2561 | * @return static |
||
2562 | * <p>(Immutable)</p> |
||
2563 | * |
||
2564 | * @psalm-return static<TKey,T> |
||
2565 | * @psalm-mutation-free |
||
2566 | */ |
||
2567 | 37 | View Code Duplication | public function firstsImmutable(int $number = null): self |
2583 | |||
2584 | /** |
||
2585 | * Get the first value(s) from the current array. |
||
2586 | * And will return an empty array if there was no first entry. |
||
2587 | * |
||
2588 | * @param int|null $number <p>How many values you will take?</p> |
||
2589 | * |
||
2590 | * @return static |
||
2591 | * <p>(Immutable)</p> |
||
2592 | * |
||
2593 | * @psalm-return static<TKey,T> |
||
2594 | * @psalm-mutation-free |
||
2595 | */ |
||
2596 | 3 | View Code Duplication | public function firstsKeys(int $number = null): self |
2612 | |||
2613 | /** |
||
2614 | * Get and remove the first value(s) from the current array. |
||
2615 | * And will return an empty array if there was no first entry. |
||
2616 | * |
||
2617 | * EXAMPLE: <code> |
||
2618 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->firstsMutable(); // 'foo' |
||
2619 | * </code> |
||
2620 | * |
||
2621 | * @param int|null $number <p>How many values you will take?</p> |
||
2622 | * |
||
2623 | * @return $this |
||
2624 | * <p>(Mutable)</p> |
||
2625 | * |
||
2626 | * @psalm-return static<TKey,T> |
||
2627 | */ |
||
2628 | 34 | public function firstsMutable(int $number = null): self |
|
2640 | |||
2641 | /** |
||
2642 | * Exchanges all keys with their associated values in an array. |
||
2643 | * |
||
2644 | * EXAMPLE: <code> |
||
2645 | * a([0 => 'foo', 1 => 'bar'])->flip(); // Arrayy['foo' => 0, 'bar' => 1] |
||
2646 | * </code> |
||
2647 | * |
||
2648 | * @return static |
||
2649 | * <p>(Immutable)</p> |
||
2650 | * |
||
2651 | * @psalm-return static<array-key,TKey> |
||
2652 | * @psalm-mutation-free |
||
2653 | */ |
||
2654 | 1 | public function flip(): self |
|
2668 | |||
2669 | /** |
||
2670 | * Get a value from an array (optional using dot-notation). |
||
2671 | * |
||
2672 | * EXAMPLE: <code> |
||
2673 | * $arrayy = a(['user' => ['lastname' => 'Moelleken']]); |
||
2674 | * $arrayy->get('user.lastname'); // 'Moelleken' |
||
2675 | * // --- |
||
2676 | * $arrayy = new A(); |
||
2677 | * $arrayy['user'] = ['lastname' => 'Moelleken']; |
||
2678 | * $arrayy['user.firstname'] = 'Lars'; |
||
2679 | * $arrayy['user']['lastname']; // Moelleken |
||
2680 | * $arrayy['user.lastname']; // Moelleken |
||
2681 | * $arrayy['user.firstname']; // Lars |
||
2682 | * </code> |
||
2683 | * |
||
2684 | * @param mixed $key <p>The key to look for.</p> |
||
2685 | * @param mixed $fallback <p>Value to fallback to.</p> |
||
2686 | * @param array $array <p>The array to get from, if it's set to "null" we use the current array from the |
||
2687 | * class.</p> |
||
2688 | * @param bool $useByReference |
||
2689 | * |
||
2690 | * @return mixed|static |
||
2691 | * |
||
2692 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
2693 | * @psalm-mutation-free |
||
2694 | */ |
||
2695 | 243 | public function get( |
|
2859 | |||
2860 | /** |
||
2861 | * alias: for "Arrayy->toArray()" |
||
2862 | * |
||
2863 | * @return array |
||
2864 | * |
||
2865 | * @see Arrayy::getArray() |
||
2866 | * |
||
2867 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
2868 | */ |
||
2869 | 15 | public function getAll(): array |
|
2873 | |||
2874 | /** |
||
2875 | * Get the current array from the "Arrayy"-object. |
||
2876 | * |
||
2877 | * alias for "toArray()" |
||
2878 | * |
||
2879 | * @param bool $convertAllArrayyElements <p> |
||
2880 | * Convert all Child-"Arrayy" objects also to arrays. |
||
2881 | * </p> |
||
2882 | * @param bool $preserveKeys <p> |
||
2883 | * e.g.: A generator maybe return the same key more then once, |
||
2884 | * so maybe you will ignore the keys. |
||
2885 | * </p> |
||
2886 | * |
||
2887 | * @return array |
||
2888 | * |
||
2889 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
2890 | * @psalm-mutation-free |
||
2891 | * |
||
2892 | * @see Arrayy::toArray() |
||
2893 | */ |
||
2894 | 501 | public function getArray( |
|
2903 | |||
2904 | /** |
||
2905 | * @param string $json |
||
2906 | * |
||
2907 | * @return $this |
||
2908 | */ |
||
2909 | 3 | public static function createFromJsonMapper(string $json) |
|
2925 | |||
2926 | /** |
||
2927 | * @return array<int|string,TypeCheckInterface>|mixed|TypeCheckArray<int|string,TypeCheckInterface>|TypeInterface |
||
2928 | * |
||
2929 | * @internal |
||
2930 | */ |
||
2931 | 6 | public function getPhpDocPropertiesFromClass() |
|
2939 | |||
2940 | /** |
||
2941 | * Get the current array from the "Arrayy"-object as list. |
||
2942 | * |
||
2943 | * alias for "toList()" |
||
2944 | * |
||
2945 | * @param bool $convertAllArrayyElements <p> |
||
2946 | * Convert all Child-"Arrayy" objects also to arrays. |
||
2947 | * </p> |
||
2948 | * |
||
2949 | * @return array |
||
2950 | * |
||
2951 | * @psalm-return array<int,mixed>|array<int,T> |
||
2952 | * @psalm-mutation-free |
||
2953 | * |
||
2954 | * @see Arrayy::toList() |
||
2955 | */ |
||
2956 | 1 | public function getList(bool $convertAllArrayyElements = false): array |
|
2960 | |||
2961 | /** |
||
2962 | * Returns the values from a single column of the input array, identified by |
||
2963 | * the $columnKey, can be used to extract data-columns from multi-arrays. |
||
2964 | * |
||
2965 | * EXAMPLE: <code> |
||
2966 | * a([['foo' => 'bar', 'id' => 1], ['foo => 'lall', 'id' => 2]])->getColumn('foo', 'id'); // Arrayy[1 => 'bar', 2 => 'lall'] |
||
2967 | * </code> |
||
2968 | * |
||
2969 | * INFO: Optionally, you may provide an $indexKey to index the values in the returned |
||
2970 | * array by the values from the $indexKey column in the input array. |
||
2971 | * |
||
2972 | * @param mixed $columnKey |
||
2973 | * @param mixed $indexKey |
||
2974 | * |
||
2975 | * @return static |
||
2976 | * <p>(Immutable)</p> |
||
2977 | * |
||
2978 | * @psalm-return static<TKey,T> |
||
2979 | * @psalm-mutation-free |
||
2980 | */ |
||
2981 | 1 | public function getColumn($columnKey = null, $indexKey = null): self |
|
2989 | |||
2990 | /** |
||
2991 | * Get the current array from the "Arrayy"-object as generator by reference. |
||
2992 | * |
||
2993 | * @return \Generator |
||
2994 | * |
||
2995 | * @psalm-return \Generator<mixed,T>|\Generator<TKey,T> |
||
2996 | */ |
||
2997 | 75 | public function &getGeneratorByReference(): \Generator |
|
3016 | |||
3017 | /** |
||
3018 | * Get the current array from the "Arrayy"-object as generator. |
||
3019 | * |
||
3020 | * @return \Generator |
||
3021 | * |
||
3022 | * @psalm-return \Generator<mixed,T>|\Generator<TKey,T> |
||
3023 | * @psalm-mutation-free |
||
3024 | */ |
||
3025 | 1000 | public function getGenerator(): \Generator |
|
3035 | |||
3036 | /** |
||
3037 | * alias: for "Arrayy->keys()" |
||
3038 | * |
||
3039 | * @return static |
||
3040 | * <p>(Immutable)</p> |
||
3041 | * |
||
3042 | * @see Arrayy::keys() |
||
3043 | * |
||
3044 | * @psalm-return static<array-key,TKey> |
||
3045 | * @psalm-mutation-free |
||
3046 | */ |
||
3047 | 2 | public function getKeys() |
|
3051 | |||
3052 | /** |
||
3053 | * Get the current array from the "Arrayy"-object as object. |
||
3054 | * |
||
3055 | * @return \stdClass |
||
3056 | */ |
||
3057 | 4 | public function getObject(): \stdClass |
|
3061 | |||
3062 | /** |
||
3063 | * alias: for "Arrayy->randomImmutable()" |
||
3064 | * |
||
3065 | * @return static |
||
3066 | * <p>(Immutable)</p> |
||
3067 | * |
||
3068 | * @see Arrayy::randomImmutable() |
||
3069 | * |
||
3070 | * @psalm-return static<int|array-key,T> |
||
3071 | */ |
||
3072 | 4 | public function getRandom(): self |
|
3076 | |||
3077 | /** |
||
3078 | * alias: for "Arrayy->randomKey()" |
||
3079 | * |
||
3080 | * @return mixed |
||
3081 | * <p>Get a key/index or null if there wasn't a key/index.</p> |
||
3082 | * |
||
3083 | * @see Arrayy::randomKey() |
||
3084 | */ |
||
3085 | 3 | public function getRandomKey() |
|
3089 | |||
3090 | /** |
||
3091 | * alias: for "Arrayy->randomKeys()" |
||
3092 | * |
||
3093 | * @param int $number |
||
3094 | * |
||
3095 | * @return static |
||
3096 | * <p>(Immutable)</p> |
||
3097 | * |
||
3098 | * @see Arrayy::randomKeys() |
||
3099 | * |
||
3100 | * @psalm-return static<TKey,T> |
||
3101 | */ |
||
3102 | 8 | public function getRandomKeys(int $number): self |
|
3106 | |||
3107 | /** |
||
3108 | * alias: for "Arrayy->randomValue()" |
||
3109 | * |
||
3110 | * @return mixed |
||
3111 | * <p>Get a random value or null if there wasn't a value.</p> |
||
3112 | * |
||
3113 | * @see Arrayy::randomValue() |
||
3114 | */ |
||
3115 | 3 | public function getRandomValue() |
|
3119 | |||
3120 | /** |
||
3121 | * alias: for "Arrayy->randomValues()" |
||
3122 | * |
||
3123 | * @param int $number |
||
3124 | * |
||
3125 | * @return static |
||
3126 | * <p>(Immutable)</p> |
||
3127 | * |
||
3128 | * @see Arrayy::randomValues() |
||
3129 | * |
||
3130 | * @psalm-return static<TKey,T> |
||
3131 | */ |
||
3132 | 6 | public function getRandomValues(int $number): self |
|
3136 | |||
3137 | /** |
||
3138 | * Gets all values. |
||
3139 | * |
||
3140 | * @return static |
||
3141 | * <p>The values of all elements in this array, in the order they |
||
3142 | * appear in the array.</p> |
||
3143 | * |
||
3144 | * @psalm-return static<TKey,T> |
||
3145 | */ |
||
3146 | 4 | public function getValues() |
|
3156 | |||
3157 | /** |
||
3158 | * Gets all values via Generator. |
||
3159 | * |
||
3160 | * @return \Generator |
||
3161 | * <p>The values of all elements in this array, in the order they |
||
3162 | * appear in the array as Generator.</p> |
||
3163 | * |
||
3164 | * @psalm-return \Generator<TKey,T> |
||
3165 | */ |
||
3166 | 4 | public function getValuesYield(): \Generator |
|
3170 | |||
3171 | /** |
||
3172 | * Group values from a array according to the results of a closure. |
||
3173 | * |
||
3174 | * @param callable|string $grouper <p>A callable function name.</p> |
||
3175 | * @param bool $saveKeys |
||
3176 | * |
||
3177 | * @return static |
||
3178 | * <p>(Immutable)</p> |
||
3179 | * |
||
3180 | * @psalm-return static<TKey,T> |
||
3181 | * @psalm-mutation-free |
||
3182 | */ |
||
3183 | 4 | public function group($grouper, bool $saveKeys = false): self |
|
3224 | |||
3225 | /** |
||
3226 | * Check if an array has a given key. |
||
3227 | * |
||
3228 | * @param mixed $key |
||
3229 | * |
||
3230 | * @return bool |
||
3231 | */ |
||
3232 | 30 | public function has($key): bool |
|
3258 | |||
3259 | /** |
||
3260 | * Check if an array has a given value. |
||
3261 | * |
||
3262 | * INFO: If you need to search recursive please use ```contains($value, true)```. |
||
3263 | * |
||
3264 | * @param mixed $value |
||
3265 | * |
||
3266 | * @return bool |
||
3267 | */ |
||
3268 | 1 | public function hasValue($value): bool |
|
3272 | |||
3273 | /** |
||
3274 | * Implodes the values of this array. |
||
3275 | * |
||
3276 | * EXAMPLE: <code> |
||
3277 | * a([0 => -9, 1, 2])->implode('|'); // '-9|1|2' |
||
3278 | * </code> |
||
3279 | * |
||
3280 | * @param string $glue |
||
3281 | * @param string $prefix |
||
3282 | * |
||
3283 | * @return string |
||
3284 | * @psalm-mutation-free |
||
3285 | */ |
||
3286 | 28 | public function implode(string $glue = '', string $prefix = ''): string |
|
3290 | |||
3291 | /** |
||
3292 | * Implodes the keys of this array. |
||
3293 | * |
||
3294 | * @param string $glue |
||
3295 | * |
||
3296 | * @return string |
||
3297 | * @psalm-mutation-free |
||
3298 | */ |
||
3299 | 8 | public function implodeKeys(string $glue = ''): string |
|
3303 | |||
3304 | /** |
||
3305 | * Given a list and an iterate-function that returns |
||
3306 | * a key for each element in the list (or a property name), |
||
3307 | * returns an object with an index of each item. |
||
3308 | * |
||
3309 | * @param mixed $key |
||
3310 | * |
||
3311 | * @return static |
||
3312 | * <p>(Immutable)</p> |
||
3313 | * |
||
3314 | * @psalm-return static<TKey,T> |
||
3315 | * @psalm-mutation-free |
||
3316 | */ |
||
3317 | 4 | View Code Duplication | public function indexBy($key): self |
3334 | |||
3335 | /** |
||
3336 | * alias: for "Arrayy->searchIndex()" |
||
3337 | * |
||
3338 | * @param mixed $value <p>The value to search for.</p> |
||
3339 | * |
||
3340 | * @return false|mixed |
||
3341 | * |
||
3342 | * @see Arrayy::searchIndex() |
||
3343 | */ |
||
3344 | 4 | public function indexOf($value) |
|
3348 | |||
3349 | /** |
||
3350 | * Get everything but the last..$to items. |
||
3351 | * |
||
3352 | * EXAMPLE: <code> |
||
3353 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->initial(2); // Arrayy[0 => 'foo'] |
||
3354 | * </code> |
||
3355 | * |
||
3356 | * @param int $to |
||
3357 | * |
||
3358 | * @return static |
||
3359 | * <p>(Immutable)</p> |
||
3360 | * |
||
3361 | * @psalm-return static<TKey,T> |
||
3362 | * @psalm-mutation-free |
||
3363 | */ |
||
3364 | 12 | public function initial(int $to = 1): self |
|
3368 | |||
3369 | /** |
||
3370 | * Return an array with all elements found in input array. |
||
3371 | * |
||
3372 | * EXAMPLE: <code> |
||
3373 | * a(['foo', 'bar'])->intersection(['bar', 'baz']); // Arrayy['bar'] |
||
3374 | * </code> |
||
3375 | * |
||
3376 | * @param array $search |
||
3377 | * @param bool $keepKeys |
||
3378 | * |
||
3379 | * @return static |
||
3380 | * <p>(Immutable)</p> |
||
3381 | * |
||
3382 | * @psalm-param array<mixed,mixed>|array<TKey,T> $search |
||
3383 | * @psalm-return static<TKey,T> |
||
3384 | * @psalm-mutation-free |
||
3385 | */ |
||
3386 | 4 | public function intersection(array $search, bool $keepKeys = false): self |
|
3412 | |||
3413 | /** |
||
3414 | * Return an array with all elements found in input array. |
||
3415 | * |
||
3416 | * @param array ...$array |
||
3417 | * |
||
3418 | * @return static |
||
3419 | * <p>(Immutable)</p> |
||
3420 | * |
||
3421 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$array |
||
3422 | * @psalm-return static<TKey,T> |
||
3423 | * @psalm-mutation-free |
||
3424 | */ |
||
3425 | 1 | public function intersectionMulti(...$array): self |
|
3433 | |||
3434 | /** |
||
3435 | * Return a boolean flag which indicates whether the two input arrays have any common elements. |
||
3436 | * |
||
3437 | * EXAMPLE: <code> |
||
3438 | * a(['foo', 'bar'])->intersects(['föö', 'bär']); // false |
||
3439 | * </code> |
||
3440 | * |
||
3441 | * @param array $search |
||
3442 | * |
||
3443 | * @return bool |
||
3444 | * |
||
3445 | * @psalm-param array<mixed,mixed>|array<TKey,T> $search |
||
3446 | */ |
||
3447 | 1 | public function intersects(array $search): bool |
|
3451 | |||
3452 | /** |
||
3453 | * Invoke a function on all of an array's values. |
||
3454 | * |
||
3455 | * @param callable $callable |
||
3456 | * @param mixed $arguments |
||
3457 | * |
||
3458 | * @return static |
||
3459 | * <p>(Immutable)</p> |
||
3460 | * |
||
3461 | * @psalm-param callable(T=,mixed):mixed $callable |
||
3462 | * @psalm-return static<TKey,T> |
||
3463 | * @psalm-mutation-free |
||
3464 | */ |
||
3465 | 1 | public function invoke($callable, $arguments = []): self |
|
3489 | |||
3490 | /** |
||
3491 | * Check whether array is associative or not. |
||
3492 | * |
||
3493 | * EXAMPLE: <code> |
||
3494 | * a(['foo' => 'bar', 2, 3])->isAssoc(); // true |
||
3495 | * </code> |
||
3496 | * |
||
3497 | * @param bool $recursive |
||
3498 | * |
||
3499 | * @return bool |
||
3500 | * <p>Returns true if associative, false otherwise.</p> |
||
3501 | */ |
||
3502 | 15 | View Code Duplication | public function isAssoc(bool $recursive = false): bool |
3517 | |||
3518 | /** |
||
3519 | * Check if a given key or keys are empty. |
||
3520 | * |
||
3521 | * @param int|int[]|string|string[]|null $keys |
||
3522 | * |
||
3523 | * @return bool |
||
3524 | * <p>Returns true if empty, false otherwise.</p> |
||
3525 | * @psalm-mutation-free |
||
3526 | */ |
||
3527 | 45 | public function isEmpty($keys = null): bool |
|
3545 | |||
3546 | /** |
||
3547 | * Check if the current array is equal to the given "$array" or not. |
||
3548 | * |
||
3549 | * EXAMPLE: <code> |
||
3550 | * a(['💩'])->isEqual(['💩']); // true |
||
3551 | * </code> |
||
3552 | * |
||
3553 | * @param array $array |
||
3554 | * |
||
3555 | * @return bool |
||
3556 | * |
||
3557 | * @psalm-param array<mixed,mixed> $array |
||
3558 | */ |
||
3559 | 1 | public function isEqual(array $array): bool |
|
3563 | |||
3564 | /** |
||
3565 | * Check if the current array is a multi-array. |
||
3566 | * |
||
3567 | * EXAMPLE: <code> |
||
3568 | * a(['foo' => [1, 2 , 3]])->isMultiArray(); // true |
||
3569 | * </code> |
||
3570 | * |
||
3571 | * @return bool |
||
3572 | */ |
||
3573 | 22 | public function isMultiArray(): bool |
|
3583 | |||
3584 | /** |
||
3585 | * Check whether array is numeric or not. |
||
3586 | * |
||
3587 | * @return bool |
||
3588 | * <p>Returns true if numeric, false otherwise.</p> |
||
3589 | */ |
||
3590 | 5 | View Code Duplication | public function isNumeric(): bool |
3605 | |||
3606 | /** |
||
3607 | * Check if the current array is sequential [0, 1, 2, 3, 4, 5 ...] or not. |
||
3608 | * |
||
3609 | * EXAMPLE: <code> |
||
3610 | * a([0 => 'foo', 1 => 'lall', 2 => 'foobar'])->isSequential(); // true |
||
3611 | * </code> |
||
3612 | * |
||
3613 | * INFO: If the array is empty we count it as non-sequential. |
||
3614 | * |
||
3615 | * @param bool $recursive |
||
3616 | * |
||
3617 | * @return bool |
||
3618 | * @psalm-mutation-free |
||
3619 | */ |
||
3620 | 10 | public function isSequential(bool $recursive = false): bool |
|
3648 | |||
3649 | /** |
||
3650 | * @return array |
||
3651 | * |
||
3652 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
3653 | */ |
||
3654 | 2 | public function jsonSerialize(): array |
|
3658 | |||
3659 | /** |
||
3660 | * Gets the key/index of the element at the current internal iterator position. |
||
3661 | * |
||
3662 | * @return int|string|null |
||
3663 | */ |
||
3664 | public function key() |
||
3668 | |||
3669 | /** |
||
3670 | * Checks if the given key exists in the provided array. |
||
3671 | * |
||
3672 | * INFO: This method only use "array_key_exists()" if you want to use "dot"-notation, |
||
3673 | * then you need to use "Arrayy->offsetExists()". |
||
3674 | * |
||
3675 | * @param int|string $key the key to look for |
||
3676 | * |
||
3677 | * @return bool |
||
3678 | * @psalm-mutation-free |
||
3679 | */ |
||
3680 | 164 | public function keyExists($key): bool |
|
3684 | |||
3685 | /** |
||
3686 | * Get all keys from the current array. |
||
3687 | * |
||
3688 | * EXAMPLE: <code> |
||
3689 | * a([1 => 'foo', 2 => 'foo2', 3 => 'bar'])->keys(); // Arrayy[1, 2, 3] |
||
3690 | * </code> |
||
3691 | * |
||
3692 | * @param bool $recursive [optional] <p> |
||
3693 | * Get all keys, also from all sub-arrays from an multi-dimensional array. |
||
3694 | * </p> |
||
3695 | * @param mixed|null $search_values [optional] <p> |
||
3696 | * If specified, then only keys containing these values are returned. |
||
3697 | * </p> |
||
3698 | * @param bool $strict [optional] <p> |
||
3699 | * Determines if strict comparison (===) should be used during the search. |
||
3700 | * </p> |
||
3701 | * |
||
3702 | * @return static |
||
3703 | * <p>(Immutable) An array of all the keys in input.</p> |
||
3704 | * |
||
3705 | * @psalm-return static<array-key,TKey> |
||
3706 | * @psalm-mutation-free |
||
3707 | */ |
||
3708 | 29 | public function keys( |
|
3779 | |||
3780 | /** |
||
3781 | * Sort an array by key in reverse order. |
||
3782 | * |
||
3783 | * @param int $sort_flags [optional] <p> |
||
3784 | * You may modify the behavior of the sort using the optional |
||
3785 | * parameter sort_flags, for details |
||
3786 | * see sort. |
||
3787 | * </p> |
||
3788 | * |
||
3789 | * @return $this |
||
3790 | * <p>(Mutable) Return this Arrayy object.</p> |
||
3791 | * |
||
3792 | * @psalm-return static<TKey,T> |
||
3793 | */ |
||
3794 | 4 | public function krsort(int $sort_flags = 0): self |
|
3802 | |||
3803 | /** |
||
3804 | * Sort an array by key in reverse order. |
||
3805 | * |
||
3806 | * @param int $sort_flags [optional] <p> |
||
3807 | * You may modify the behavior of the sort using the optional |
||
3808 | * parameter sort_flags, for details |
||
3809 | * see sort. |
||
3810 | * </p> |
||
3811 | * |
||
3812 | * @return $this |
||
3813 | * <p>(Immutable) Return this Arrayy object.</p> |
||
3814 | * |
||
3815 | * @psalm-return static<TKey,T> |
||
3816 | * @psalm-mutation-free |
||
3817 | */ |
||
3818 | 4 | public function krsortImmutable(int $sort_flags = 0): self |
|
3829 | |||
3830 | /** |
||
3831 | * Get the last value from the current array. |
||
3832 | * |
||
3833 | * EXAMPLE: <code> |
||
3834 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->last(); // 'lall' |
||
3835 | * </code> |
||
3836 | * |
||
3837 | * @return mixed|null |
||
3838 | * <p>Return null if there wasn't a element.</p> |
||
3839 | * @psalm-mutation-free |
||
3840 | */ |
||
3841 | 17 | public function last() |
|
3850 | |||
3851 | /** |
||
3852 | * Get the last key from the current array. |
||
3853 | * |
||
3854 | * @return mixed|null |
||
3855 | * <p>Return null if there wasn't a element.</p> |
||
3856 | * @psalm-mutation-free |
||
3857 | */ |
||
3858 | 21 | public function lastKey() |
|
3864 | |||
3865 | /** |
||
3866 | * Get the last value(s) from the current array. |
||
3867 | * |
||
3868 | * EXAMPLE: <code> |
||
3869 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->lasts(2); // Arrayy[0 => 'bar', 1 => 'lall'] |
||
3870 | * </code> |
||
3871 | * |
||
3872 | * @param int|null $number |
||
3873 | * |
||
3874 | * @return static |
||
3875 | * <p>(Immutable)</p> |
||
3876 | * |
||
3877 | * @psalm-return static<TKey,T> |
||
3878 | * @psalm-mutation-free |
||
3879 | */ |
||
3880 | 13 | public function lastsImmutable(int $number = null): self |
|
3910 | |||
3911 | /** |
||
3912 | * Get the last value(s) from the current array. |
||
3913 | * |
||
3914 | * EXAMPLE: <code> |
||
3915 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->lasts(2); // Arrayy[0 => 'bar', 1 => 'lall'] |
||
3916 | * </code> |
||
3917 | * |
||
3918 | * @param int|null $number |
||
3919 | * |
||
3920 | * @return $this |
||
3921 | * <p>(Mutable)</p> |
||
3922 | * |
||
3923 | * @psalm-return static<TKey,T> |
||
3924 | */ |
||
3925 | 13 | public function lastsMutable(int $number = null): self |
|
3936 | |||
3937 | /** |
||
3938 | * Count the values from the current array. |
||
3939 | * |
||
3940 | * alias: for "Arrayy->count()" |
||
3941 | * |
||
3942 | * @param int $mode |
||
3943 | * |
||
3944 | * @return int |
||
3945 | * |
||
3946 | * @see Arrayy::count() |
||
3947 | */ |
||
3948 | 20 | public function length(int $mode = \COUNT_NORMAL): int |
|
3952 | |||
3953 | /** |
||
3954 | * Apply the given function to the every element of the array, |
||
3955 | * collecting the results. |
||
3956 | * |
||
3957 | * @param callable $callable |
||
3958 | * @param bool $useKeyAsSecondParameter |
||
3959 | * @param mixed ...$arguments |
||
3960 | * |
||
3961 | * @return static |
||
3962 | * <p>(Immutable) Arrayy object with modified elements.</p> |
||
3963 | * |
||
3964 | * @psalm-param callable(T,TKey=,mixed=):mixed $callable |
||
3965 | * @psalm-return static<TKey,T> |
||
3966 | * @psalm-mutation-free |
||
3967 | */ |
||
3968 | 5 | public function map( |
|
4001 | |||
4002 | /** |
||
4003 | * Check if all items in current array match a truth test. |
||
4004 | * |
||
4005 | * EXAMPLE: <code> |
||
4006 | * $closure = function ($value, $key) { |
||
4007 | * return ($value % 2 === 0); |
||
4008 | * }; |
||
4009 | * a([2, 4, 8])->matches($closure); // true |
||
4010 | * </code> |
||
4011 | * |
||
4012 | * @param \Closure $closure |
||
4013 | * |
||
4014 | * @return bool |
||
4015 | */ |
||
4016 | 15 | View Code Duplication | public function matches(\Closure $closure): bool |
4032 | |||
4033 | /** |
||
4034 | * Check if any item in the current array matches a truth test. |
||
4035 | * |
||
4036 | * EXAMPLE: <code> |
||
4037 | * $closure = function ($value, $key) { |
||
4038 | * return ($value % 2 === 0); |
||
4039 | * }; |
||
4040 | * a([1, 4, 7])->matches($closure); // true |
||
4041 | * </code> |
||
4042 | * |
||
4043 | * @param \Closure $closure |
||
4044 | * |
||
4045 | * @return bool |
||
4046 | */ |
||
4047 | 14 | View Code Duplication | public function matchesAny(\Closure $closure): bool |
4063 | |||
4064 | /** |
||
4065 | * Get the max value from an array. |
||
4066 | * |
||
4067 | * EXAMPLE: <code> |
||
4068 | * a([-9, -8, -7, 1.32])->max(); // 1.32 |
||
4069 | * </code> |
||
4070 | * |
||
4071 | * @return false|mixed |
||
4072 | * <p>Will return false if there are no values.</p> |
||
4073 | */ |
||
4074 | 10 | View Code Duplication | public function max() |
4094 | |||
4095 | /** |
||
4096 | * Merge the new $array into the current array. |
||
4097 | * |
||
4098 | * - keep key,value from the current array, also if the index is in the new $array |
||
4099 | * |
||
4100 | * EXAMPLE: <code> |
||
4101 | * $array1 = [1 => 'one', 'foo' => 'bar1']; |
||
4102 | * $array2 = ['foo' => 'bar2', 3 => 'three']; |
||
4103 | * a($array1)->mergeAppendKeepIndex($array2); // Arrayy[1 => 'one', 'foo' => 'bar2', 3 => 'three'] |
||
4104 | * // --- |
||
4105 | * $array1 = [0 => 'one', 1 => 'foo']; |
||
4106 | * $array2 = [0 => 'foo', 1 => 'bar2']; |
||
4107 | * a($array1)->mergeAppendKeepIndex($array2); // Arrayy[0 => 'foo', 1 => 'bar2'] |
||
4108 | * </code> |
||
4109 | * |
||
4110 | * @param array $array |
||
4111 | * @param bool $recursive |
||
4112 | * |
||
4113 | * @return static |
||
4114 | * <p>(Immutable)</p> |
||
4115 | * |
||
4116 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
4117 | * @psalm-return static<int|TKey,T> |
||
4118 | * @psalm-mutation-free |
||
4119 | */ |
||
4120 | 33 | View Code Duplication | public function mergeAppendKeepIndex(array $array = [], bool $recursive = false): self |
4135 | |||
4136 | /** |
||
4137 | * Merge the new $array into the current array. |
||
4138 | * |
||
4139 | * - replace duplicate assoc-keys from the current array with the key,values from the new $array |
||
4140 | * - create new indexes |
||
4141 | * |
||
4142 | * EXAMPLE: <code> |
||
4143 | * $array1 = [1 => 'one', 'foo' => 'bar1']; |
||
4144 | * $array2 = ['foo' => 'bar2', 3 => 'three']; |
||
4145 | * a($array1)->mergeAppendNewIndex($array2); // Arrayy[0 => 'one', 'foo' => 'bar2', 1 => 'three'] |
||
4146 | * // --- |
||
4147 | * $array1 = [0 => 'one', 1 => 'foo']; |
||
4148 | * $array2 = [0 => 'foo', 1 => 'bar2']; |
||
4149 | * a($array1)->mergeAppendNewIndex($array2); // Arrayy[0 => 'one', 1 => 'foo', 2 => 'foo', 3 => 'bar2'] |
||
4150 | * </code> |
||
4151 | * |
||
4152 | * @param array $array |
||
4153 | * @param bool $recursive |
||
4154 | * |
||
4155 | * @return static |
||
4156 | * <p>(Immutable)</p> |
||
4157 | * |
||
4158 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
4159 | * @psalm-return static<TKey,T> |
||
4160 | * @psalm-mutation-free |
||
4161 | */ |
||
4162 | 20 | View Code Duplication | public function mergeAppendNewIndex(array $array = [], bool $recursive = false): self |
4177 | |||
4178 | /** |
||
4179 | * Merge the the current array into the $array. |
||
4180 | * |
||
4181 | * - use key,value from the new $array, also if the index is in the current array |
||
4182 | * |
||
4183 | * EXAMPLE: <code> |
||
4184 | * $array1 = [1 => 'one', 'foo' => 'bar1']; |
||
4185 | * $array2 = ['foo' => 'bar2', 3 => 'three']; |
||
4186 | * a($array1)->mergePrependKeepIndex($array2); // Arrayy['foo' => 'bar1', 3 => 'three', 1 => 'one'] |
||
4187 | * // --- |
||
4188 | * $array1 = [0 => 'one', 1 => 'foo']; |
||
4189 | * $array2 = [0 => 'foo', 1 => 'bar2']; |
||
4190 | * a($array1)->mergePrependKeepIndex($array2); // Arrayy[0 => 'one', 1 => 'foo'] |
||
4191 | * </code> |
||
4192 | * |
||
4193 | * @param array $array |
||
4194 | * @param bool $recursive |
||
4195 | * |
||
4196 | * @return static |
||
4197 | * <p>(Immutable)</p> |
||
4198 | * |
||
4199 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
4200 | * @psalm-return static<TKey,T> |
||
4201 | * @psalm-mutation-free |
||
4202 | */ |
||
4203 | 17 | View Code Duplication | public function mergePrependKeepIndex(array $array = [], bool $recursive = false): self |
4218 | |||
4219 | /** |
||
4220 | * Merge the current array into the new $array. |
||
4221 | * |
||
4222 | * - replace duplicate assoc-keys from new $array with the key,values from the current array |
||
4223 | * - create new indexes |
||
4224 | * |
||
4225 | * EXAMPLE: <code> |
||
4226 | * $array1 = [1 => 'one', 'foo' => 'bar1']; |
||
4227 | * $array2 = ['foo' => 'bar2', 3 => 'three']; |
||
4228 | * a($array1)->mergePrependNewIndex($array2); // Arrayy['foo' => 'bar1', 0 => 'three', 1 => 'one'] |
||
4229 | * // --- |
||
4230 | * $array1 = [0 => 'one', 1 => 'foo']; |
||
4231 | * $array2 = [0 => 'foo', 1 => 'bar2']; |
||
4232 | * a($array1)->mergePrependNewIndex($array2); // Arrayy[0 => 'foo', 1 => 'bar2', 2 => 'one', 3 => 'foo'] |
||
4233 | * </code> |
||
4234 | * |
||
4235 | * @param array $array |
||
4236 | * @param bool $recursive |
||
4237 | * |
||
4238 | * @return static |
||
4239 | * <p>(Immutable)</p> |
||
4240 | * |
||
4241 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
4242 | * @psalm-return static<TKey,T> |
||
4243 | * @psalm-mutation-free |
||
4244 | */ |
||
4245 | 21 | View Code Duplication | public function mergePrependNewIndex(array $array = [], bool $recursive = false): self |
4260 | |||
4261 | /** |
||
4262 | * @return ArrayyMeta|static |
||
4263 | */ |
||
4264 | 18 | public static function meta() |
|
4268 | |||
4269 | /** |
||
4270 | * Get the min value from an array. |
||
4271 | * |
||
4272 | * EXAMPLE: <code> |
||
4273 | * a([-9, -8, -7, 1.32])->min(); // -9 |
||
4274 | * </code> |
||
4275 | * |
||
4276 | * @return false|mixed |
||
4277 | * <p>Will return false if there are no values.</p> |
||
4278 | */ |
||
4279 | 10 | View Code Duplication | public function min() |
4299 | |||
4300 | /** |
||
4301 | * Get the most used value from the array. |
||
4302 | * |
||
4303 | * @return mixed|null |
||
4304 | * <p>(Immutable) Return null if there wasn't a element.</p> |
||
4305 | * @psalm-mutation-free |
||
4306 | */ |
||
4307 | 3 | public function mostUsedValue() |
|
4311 | |||
4312 | /** |
||
4313 | * Get the most used value from the array. |
||
4314 | * |
||
4315 | * @param int|null $number <p>How many values you will take?</p> |
||
4316 | * |
||
4317 | * @return static |
||
4318 | * <p>(Immutable)</p> |
||
4319 | * |
||
4320 | * @psalm-return static<TKey,T> |
||
4321 | * @psalm-mutation-free |
||
4322 | */ |
||
4323 | 3 | public function mostUsedValues(int $number = null): self |
|
4327 | |||
4328 | /** |
||
4329 | * Move an array element to a new index. |
||
4330 | * |
||
4331 | * EXAMPLE: <code> |
||
4332 | * $arr2 = new A(['A' => 'a', 'B' => 'b', 'C' => 'c', 'D' => 'd', 'E' => 'e']); |
||
4333 | * $newArr2 = $arr2->moveElement('D', 1); // Arrayy['A' => 'a', 'D' => 'd', 'B' => 'b', 'C' => 'c', 'E' => 'e'] |
||
4334 | * </code> |
||
4335 | * |
||
4336 | * @param int|string $from |
||
4337 | * @param int $to |
||
4338 | * |
||
4339 | * @return static |
||
4340 | * <p>(Immutable)</p> |
||
4341 | * |
||
4342 | * @psalm-return static<TKey,T> |
||
4343 | * @psalm-mutation-free |
||
4344 | */ |
||
4345 | 1 | public function moveElement($from, $to): self |
|
4378 | |||
4379 | /** |
||
4380 | * Move an array element to the first place. |
||
4381 | * |
||
4382 | * INFO: Instead of "Arrayy->moveElement()" this method will NOT |
||
4383 | * loss the keys of an indexed array. |
||
4384 | * |
||
4385 | * @param int|string $key |
||
4386 | * |
||
4387 | * @return static |
||
4388 | * <p>(Immutable)</p> |
||
4389 | * |
||
4390 | * @psalm-return static<TKey,T> |
||
4391 | * @psalm-mutation-free |
||
4392 | */ |
||
4393 | 1 | View Code Duplication | public function moveElementToFirstPlace($key): self |
4409 | |||
4410 | /** |
||
4411 | * Move an array element to the last place. |
||
4412 | * |
||
4413 | * INFO: Instead of "Arrayy->moveElement()" this method will NOT |
||
4414 | * loss the keys of an indexed array. |
||
4415 | * |
||
4416 | * @param int|string $key |
||
4417 | * |
||
4418 | * @return static |
||
4419 | * <p>(Immutable)</p> |
||
4420 | * |
||
4421 | * @psalm-return static<TKey,T> |
||
4422 | * @psalm-mutation-free |
||
4423 | */ |
||
4424 | 1 | View Code Duplication | public function moveElementToLastPlace($key): self |
4440 | |||
4441 | /** |
||
4442 | * Moves the internal iterator position to the next element and returns this element. |
||
4443 | * |
||
4444 | * @return false|mixed |
||
4445 | * <p>(Mutable) Will return false if there are no values.</p> |
||
4446 | */ |
||
4447 | public function next() |
||
4451 | |||
4452 | /** |
||
4453 | * Get the next nth keys and values from the array. |
||
4454 | * |
||
4455 | * @param int $step |
||
4456 | * @param int $offset |
||
4457 | * |
||
4458 | * @return static |
||
4459 | * <p>(Immutable)</p> |
||
4460 | * |
||
4461 | * @psalm-return static<TKey,T> |
||
4462 | * @psalm-mutation-free |
||
4463 | */ |
||
4464 | 1 | public function nth(int $step, int $offset = 0): self |
|
4483 | |||
4484 | /** |
||
4485 | * Get a subset of the items from the given array. |
||
4486 | * |
||
4487 | * @param int[]|string[] $keys |
||
4488 | * |
||
4489 | * @return static |
||
4490 | * <p>(Immutable)</p> |
||
4491 | * |
||
4492 | * @psalm-param array-key[] $keys |
||
4493 | * @psalm-return static<TKey,T> |
||
4494 | * @psalm-mutation-free |
||
4495 | */ |
||
4496 | 1 | View Code Duplication | public function only(array $keys): self |
4514 | |||
4515 | /** |
||
4516 | * Pad array to the specified size with a given value. |
||
4517 | * |
||
4518 | * @param int $size <p>Size of the result array.</p> |
||
4519 | * @param mixed $value <p>Empty value by default.</p> |
||
4520 | * |
||
4521 | * @return static |
||
4522 | * <p>(Immutable) Arrayy object padded to $size with $value.</p> |
||
4523 | * |
||
4524 | * @psalm-return static<TKey,T> |
||
4525 | * @psalm-mutation-free |
||
4526 | */ |
||
4527 | 5 | public function pad(int $size, $value): self |
|
4535 | |||
4536 | /** |
||
4537 | * Partitions this array in two array according to a predicate. |
||
4538 | * Keys are preserved in the resulting array. |
||
4539 | * |
||
4540 | * @param \Closure $closure |
||
4541 | * <p>The predicate on which to partition.</p> |
||
4542 | * |
||
4543 | * @return array<int, static> |
||
4544 | * <p>An array with two elements. The first element contains the array |
||
4545 | * of elements where the predicate returned TRUE, the second element |
||
4546 | * contains the array of elements where the predicate returned FALSE.</p> |
||
4547 | * |
||
4548 | * @psalm-return array<int, static<TKey,T>> |
||
4549 | */ |
||
4550 | 1 | public function partition(\Closure $closure): array |
|
4566 | |||
4567 | /** |
||
4568 | * Pop a specified value off the end of the current array. |
||
4569 | * |
||
4570 | * @return mixed|null |
||
4571 | * <p>(Mutable) The popped element from the current array or null if the array is e.g. empty.</p> |
||
4572 | */ |
||
4573 | 5 | public function pop() |
|
4579 | |||
4580 | /** |
||
4581 | * Prepend a (key) + value to the current array. |
||
4582 | * |
||
4583 | * EXAMPLE: <code> |
||
4584 | * a(['fòô' => 'bàř'])->prepend('foo'); // Arrayy[0 => 'foo', 'fòô' => 'bàř'] |
||
4585 | * </code> |
||
4586 | * |
||
4587 | * @param mixed $value |
||
4588 | * @param mixed $key |
||
4589 | * |
||
4590 | * @return $this |
||
4591 | * <p>(Mutable) Return this Arrayy object, with the prepended value.</p> |
||
4592 | * |
||
4593 | * @psalm-return static<TKey,T> |
||
4594 | */ |
||
4595 | 11 | public function prepend($value, $key = null) |
|
4611 | |||
4612 | /** |
||
4613 | * Prepend a (key) + value to the current array. |
||
4614 | * |
||
4615 | * EXAMPLE: <code> |
||
4616 | * a(['fòô' => 'bàř'])->prependImmutable('foo')->getArray(); // [0 => 'foo', 'fòô' => 'bàř'] |
||
4617 | * </code> |
||
4618 | * |
||
4619 | * @param mixed $value |
||
4620 | * @param mixed $key |
||
4621 | * |
||
4622 | * @return $this |
||
4623 | * <p>(Immutable) Return this Arrayy object, with the prepended value.</p> |
||
4624 | * |
||
4625 | * @psalm-return static<TKey,T> |
||
4626 | * @psalm-mutation-free |
||
4627 | */ |
||
4628 | 1 | View Code Duplication | public function prependImmutable($value, $key = null) |
4653 | |||
4654 | /** |
||
4655 | * Add a suffix to each key. |
||
4656 | * |
||
4657 | * @param mixed $suffix |
||
4658 | * |
||
4659 | * @return static |
||
4660 | * <p>(Immutable) Return an Arrayy object, with the prepended keys.</p> |
||
4661 | * |
||
4662 | * @psalm-return static<TKey,T> |
||
4663 | * @psalm-mutation-free |
||
4664 | */ |
||
4665 | 10 | View Code Duplication | public function prependToEachKey($suffix): self |
4691 | |||
4692 | /** |
||
4693 | * Add a suffix to each value. |
||
4694 | * |
||
4695 | * @param mixed $suffix |
||
4696 | * |
||
4697 | * @return static |
||
4698 | * <p>(Immutable) Return an Arrayy object, with the prepended values.</p> |
||
4699 | * |
||
4700 | * @psalm-return static<TKey,T> |
||
4701 | * @psalm-mutation-free |
||
4702 | */ |
||
4703 | 10 | View Code Duplication | public function prependToEachValue($suffix): self |
4731 | |||
4732 | /** |
||
4733 | * Return the value of a given key and |
||
4734 | * delete the key. |
||
4735 | * |
||
4736 | * @param int|int[]|string|string[]|null $keyOrKeys |
||
4737 | * @param mixed $fallback |
||
4738 | * |
||
4739 | * @return mixed |
||
4740 | */ |
||
4741 | 5 | public function pull($keyOrKeys = null, $fallback = null) |
|
4763 | |||
4764 | /** |
||
4765 | * Push one or more values onto the end of array at once. |
||
4766 | * |
||
4767 | * @param array ...$args |
||
4768 | * |
||
4769 | * @return $this |
||
4770 | * <p>(Mutable) Return this Arrayy object, with pushed elements to the end of array.</p> |
||
4771 | * |
||
4772 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
4773 | * |
||
4774 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$args |
||
4775 | * @psalm-return static<TKey,T> |
||
4776 | */ |
||
4777 | 7 | public function push(...$args) |
|
4795 | |||
4796 | /** |
||
4797 | * Get a random value from the current array. |
||
4798 | * |
||
4799 | * EXAMPLE: <code> |
||
4800 | * a([1, 2, 3, 4])->randomImmutable(2); // e.g.: Arrayy[1, 4] |
||
4801 | * </code> |
||
4802 | * |
||
4803 | * @param int|null $number <p>How many values you will take?</p> |
||
4804 | * |
||
4805 | * @return static |
||
4806 | * <p>(Immutable)</p> |
||
4807 | * |
||
4808 | * @psalm-return static<int|array-key,T> |
||
4809 | */ |
||
4810 | 19 | public function randomImmutable(int $number = null): self |
|
4843 | |||
4844 | /** |
||
4845 | * Pick a random key/index from the keys of this array. |
||
4846 | * |
||
4847 | * EXAMPLE: <code> |
||
4848 | * $arrayy = A::create([1 => 'one', 2 => 'two']); |
||
4849 | * $arrayy->randomKey(); // e.g. 2 |
||
4850 | * </code> |
||
4851 | * |
||
4852 | * @throws \RangeException If array is empty |
||
4853 | * |
||
4854 | * @return mixed |
||
4855 | * <p>Get a key/index or null if there wasn't a key/index.</p> |
||
4856 | */ |
||
4857 | 4 | public function randomKey() |
|
4867 | |||
4868 | /** |
||
4869 | * Pick a given number of random keys/indexes out of this array. |
||
4870 | * |
||
4871 | * EXAMPLE: <code> |
||
4872 | * a([1 => 'one', 2 => 'two'])->randomKeys(); // e.g. Arrayy[1, 2] |
||
4873 | * </code> |
||
4874 | * |
||
4875 | * @param int $number <p>The number of keys/indexes (should be <= \count($this->array))</p> |
||
4876 | * |
||
4877 | * @throws \RangeException If array is empty |
||
4878 | * |
||
4879 | * @return static |
||
4880 | * <p>(Immutable)</p> |
||
4881 | * |
||
4882 | * @psalm-return static<TKey,T> |
||
4883 | */ |
||
4884 | 13 | public function randomKeys(int $number): self |
|
4912 | |||
4913 | /** |
||
4914 | * Get a random value from the current array. |
||
4915 | * |
||
4916 | * EXAMPLE: <code> |
||
4917 | * a([1, 2, 3, 4])->randomMutable(2); // e.g.: Arrayy[1, 4] |
||
4918 | * </code> |
||
4919 | * |
||
4920 | * @param int|null $number <p>How many values you will take?</p> |
||
4921 | * |
||
4922 | * @return $this |
||
4923 | * <p>(Mutable) Return this Arrayy object.</p> |
||
4924 | * |
||
4925 | * @psalm-return static<TKey,T> |
||
4926 | */ |
||
4927 | 17 | public function randomMutable(int $number = null): self |
|
4952 | |||
4953 | /** |
||
4954 | * Pick a random value from the values of this array. |
||
4955 | * |
||
4956 | * EXAMPLE: <code> |
||
4957 | * a([1 => 'one', 2 => 'two'])->randomValue(); // e.g. 'one' |
||
4958 | * </code> |
||
4959 | * |
||
4960 | * @return mixed |
||
4961 | * <p>Get a random value or null if there wasn't a value.</p> |
||
4962 | */ |
||
4963 | 4 | public function randomValue() |
|
4973 | |||
4974 | /** |
||
4975 | * Pick a given number of random values out of this array. |
||
4976 | * |
||
4977 | * EXAMPLE: <code> |
||
4978 | * a([1 => 'one', 2 => 'two'])->randomValues(); // e.g. Arrayy['one', 'two'] |
||
4979 | * </code> |
||
4980 | * |
||
4981 | * @param int $number |
||
4982 | * |
||
4983 | * @return static |
||
4984 | * <p>(Mutable)</p> |
||
4985 | * |
||
4986 | * @psalm-return static<TKey,T> |
||
4987 | */ |
||
4988 | 7 | public function randomValues(int $number): self |
|
4992 | |||
4993 | /** |
||
4994 | * Get a random value from an array, with the ability to skew the results. |
||
4995 | * |
||
4996 | * EXAMPLE: <code> |
||
4997 | * a([0 => 3, 1 => 4])->randomWeighted([1 => 4]); // e.g.: Arrayy[4] (has a 66% chance of returning 4) |
||
4998 | * </code> |
||
4999 | * |
||
5000 | * @param array $array |
||
5001 | * @param int|null $number <p>How many values you will take?</p> |
||
5002 | * |
||
5003 | * @return static<int,mixed> |
||
5004 | * <p>(Immutable)</p> |
||
5005 | * |
||
5006 | * @psalm-param array<mixed,mixed> $array |
||
5007 | * @psalm-return static<int|array-key,T> |
||
5008 | */ |
||
5009 | 9 | public function randomWeighted(array $array, int $number = null): self |
|
5024 | |||
5025 | /** |
||
5026 | * Reduce the current array via callable e.g. anonymous-function. |
||
5027 | * |
||
5028 | * EXAMPLE: <code> |
||
5029 | * function myReducer($resultArray, $value) { |
||
5030 | * if ($value == 'foo') { |
||
5031 | * $resultArray[] = $value; |
||
5032 | * } |
||
5033 | * return $resultArray; |
||
5034 | * }; |
||
5035 | * a(['foo', 'bar'])->reduce('myReducer'); // Arrayy['foo'] |
||
5036 | * </cdde> |
||
5037 | * |
||
5038 | * @param callable $callable |
||
5039 | * @param mixed $init |
||
5040 | * |
||
5041 | * @return static |
||
5042 | * <p>(Immutable)</p> |
||
5043 | * |
||
5044 | * @psalm-return static<TKey,T> |
||
5045 | * @psalm-mutation-free |
||
5046 | */ |
||
5047 | 18 | public function reduce($callable, $init = []): self |
|
5077 | |||
5078 | /** |
||
5079 | * @param bool $unique |
||
5080 | * |
||
5081 | * @return static |
||
5082 | * <p>(Immutable)</p> |
||
5083 | * |
||
5084 | * @psalm-return static<TKey,T> |
||
5085 | * @psalm-mutation-free |
||
5086 | */ |
||
5087 | 14 | public function reduce_dimension(bool $unique = true): self |
|
5110 | |||
5111 | /** |
||
5112 | * Create a numerically re-indexed Arrayy object. |
||
5113 | * |
||
5114 | * EXAMPLE: <code> |
||
5115 | * a([2 => 1, 3 => 2])->reindex(); // Arrayy[0 => 1, 1 => 2] |
||
5116 | * </code> |
||
5117 | * |
||
5118 | * @return $this |
||
5119 | * <p>(Mutable) Return this Arrayy object, with re-indexed array-elements.</p> |
||
5120 | * |
||
5121 | * @psalm-return static<TKey,T> |
||
5122 | */ |
||
5123 | 9 | public function reindex(): self |
|
5131 | |||
5132 | /** |
||
5133 | * Return all items that fail the truth test. |
||
5134 | * |
||
5135 | * EXAMPLE: <code> |
||
5136 | * $closure = function ($value) { |
||
5137 | * return $value % 2 !== 0; |
||
5138 | * } |
||
5139 | * a([1, 2, 3, 4])->reject($closure); // Arrayy[1 => 2, 3 => 4] |
||
5140 | * </code> |
||
5141 | * |
||
5142 | * @param \Closure $closure |
||
5143 | * |
||
5144 | * @return static |
||
5145 | * <p>(Immutable)</p> |
||
5146 | * |
||
5147 | * @psalm-return static<TKey,T> |
||
5148 | * @psalm-mutation-free |
||
5149 | */ |
||
5150 | 1 | View Code Duplication | public function reject(\Closure $closure): self |
5167 | |||
5168 | /** |
||
5169 | * Remove a value from the current array (optional using dot-notation). |
||
5170 | * |
||
5171 | * EXAMPLE: <code> |
||
5172 | * a([1 => 'bar', 'foo' => 'foo'])->remove(1); // Arrayy['foo' => 'foo'] |
||
5173 | * </code> |
||
5174 | * |
||
5175 | * @param mixed $key |
||
5176 | * |
||
5177 | * @return static |
||
5178 | * <p>(Mutable)</p> |
||
5179 | * |
||
5180 | * @psalm-param TKey $key |
||
5181 | * @psalm-return static<TKey,T> |
||
5182 | */ |
||
5183 | 22 | public function remove($key) |
|
5206 | |||
5207 | /** |
||
5208 | * alias: for "Arrayy->removeValue()" |
||
5209 | * |
||
5210 | * @param mixed $element |
||
5211 | * |
||
5212 | * @return static |
||
5213 | * <p>(Immutable)</p> |
||
5214 | * |
||
5215 | * @psalm-param T $element |
||
5216 | * @psalm-return static<TKey,T> |
||
5217 | * @psalm-mutation-free |
||
5218 | */ |
||
5219 | 8 | public function removeElement($element) |
|
5223 | |||
5224 | /** |
||
5225 | * Remove the first value from the current array. |
||
5226 | * |
||
5227 | * EXAMPLE: <code> |
||
5228 | * a([1 => 'bar', 'foo' => 'foo'])->removeFirst(); // Arrayy['foo' => 'foo'] |
||
5229 | * </code> |
||
5230 | * |
||
5231 | * @return static |
||
5232 | * <p>(Immutable)</p> |
||
5233 | * |
||
5234 | * @psalm-return static<TKey,T> |
||
5235 | * @psalm-mutation-free |
||
5236 | */ |
||
5237 | 7 | View Code Duplication | public function removeFirst(): self |
5249 | |||
5250 | /** |
||
5251 | * Remove the last value from the current array. |
||
5252 | * |
||
5253 | * EXAMPLE: <code> |
||
5254 | * a([1 => 'bar', 'foo' => 'foo'])->removeLast(); // Arrayy[1 => 'bar'] |
||
5255 | * </code> |
||
5256 | * |
||
5257 | * @return static |
||
5258 | * <p>(Immutable)</p> |
||
5259 | * |
||
5260 | * @psalm-return static<TKey,T> |
||
5261 | * @psalm-mutation-free |
||
5262 | */ |
||
5263 | 7 | View Code Duplication | public function removeLast(): self |
5275 | |||
5276 | /** |
||
5277 | * Removes a particular value from an array (numeric or associative). |
||
5278 | * |
||
5279 | * EXAMPLE: <code> |
||
5280 | * a([1 => 'bar', 'foo' => 'foo'])->removeValue('foo'); // Arrayy[1 => 'bar'] |
||
5281 | * </code> |
||
5282 | * |
||
5283 | * @param mixed $value |
||
5284 | * |
||
5285 | * @return static |
||
5286 | * <p>(Immutable)</p> |
||
5287 | * |
||
5288 | * @psalm-param T $value |
||
5289 | * @psalm-return static<TKey,T> |
||
5290 | * @psalm-mutation-free |
||
5291 | */ |
||
5292 | 8 | public function removeValue($value): self |
|
5315 | |||
5316 | /** |
||
5317 | * Generate array of repeated arrays. |
||
5318 | * |
||
5319 | * @param int $times <p>How many times has to be repeated.</p> |
||
5320 | * |
||
5321 | * @return static |
||
5322 | * <p>(Immutable)</p> |
||
5323 | * |
||
5324 | * @psalm-return static<TKey,T> |
||
5325 | * @psalm-mutation-free |
||
5326 | */ |
||
5327 | 1 | public function repeat($times): self |
|
5339 | |||
5340 | /** |
||
5341 | * Replace a key with a new key/value pair. |
||
5342 | * |
||
5343 | * EXAMPLE: <code> |
||
5344 | * $arrayy = a([1 => 'foo', 2 => 'foo2', 3 => 'bar']); |
||
5345 | * $arrayy->replace(2, 'notfoo', 'notbar'); // Arrayy[1 => 'foo', 'notfoo' => 'notbar', 3 => 'bar'] |
||
5346 | * </code> |
||
5347 | * |
||
5348 | * @param mixed $oldKey |
||
5349 | * @param mixed $newKey |
||
5350 | * @param mixed $newValue |
||
5351 | * |
||
5352 | * @return static |
||
5353 | * <p>(Immutable)</p> |
||
5354 | * |
||
5355 | * @psalm-return static<TKey,T> |
||
5356 | * @psalm-mutation-free |
||
5357 | */ |
||
5358 | 5 | public function replace($oldKey, $newKey, $newValue): self |
|
5368 | |||
5369 | /** |
||
5370 | * Create an array using the current array as values and the other array as keys. |
||
5371 | * |
||
5372 | * EXAMPLE: <code> |
||
5373 | * $firstArray = [ |
||
5374 | * 1 => 'one', |
||
5375 | * 2 => 'two', |
||
5376 | * 3 => 'three', |
||
5377 | * ]; |
||
5378 | * $secondArray = [ |
||
5379 | * 'one' => 1, |
||
5380 | * 1 => 'one', |
||
5381 | * 2 => 2, |
||
5382 | * ]; |
||
5383 | * $arrayy = a($firstArray); |
||
5384 | * $arrayy->replaceAllKeys($secondArray); // Arrayy[1 => "one", 'one' => "two", 2 => "three"] |
||
5385 | * </code> |
||
5386 | * |
||
5387 | * @param array $keys <p>An array of keys.</p> |
||
5388 | * |
||
5389 | * @return static |
||
5390 | * <p>(Immutable) Arrayy object with keys from the other array.</p> |
||
5391 | * |
||
5392 | * @psalm-param array<mixed,mixed>|array<mixed,TKey> $keys |
||
5393 | * @psalm-return static<TKey,T> |
||
5394 | * @psalm-mutation-free |
||
5395 | */ |
||
5396 | 2 | public function replaceAllKeys(array $keys): self |
|
5404 | |||
5405 | /** |
||
5406 | * Create an array using the current array as keys and the other array as values. |
||
5407 | * |
||
5408 | * EXAMPLE: <code> |
||
5409 | * $firstArray = [ |
||
5410 | * 1 => 'one', |
||
5411 | * 2 => 'two', |
||
5412 | * 3 => 'three', |
||
5413 | * ]; |
||
5414 | * $secondArray = [ |
||
5415 | * 'one' => 1, |
||
5416 | * 1 => 'one', |
||
5417 | * 2 => 2, |
||
5418 | * ]; |
||
5419 | * $arrayy = a($firstArray); |
||
5420 | * $arrayy->replaceAllValues($secondArray); // Arrayy['one' => 1, 'two' => 'one', 'three' => 2] |
||
5421 | * </code> |
||
5422 | * |
||
5423 | * @param array $array <p>An array of values.</p> |
||
5424 | * |
||
5425 | * @return static |
||
5426 | * <p>(Immutable) Arrayy object with values from the other array.</p> |
||
5427 | * |
||
5428 | * @psalm-param array<mixed,T> $array |
||
5429 | * @psalm-return static<TKey,T> |
||
5430 | * @psalm-mutation-free |
||
5431 | */ |
||
5432 | 2 | public function replaceAllValues(array $array): self |
|
5440 | |||
5441 | /** |
||
5442 | * Replace the keys in an array with another set. |
||
5443 | * |
||
5444 | * EXAMPLE: <code> |
||
5445 | * a([1 => 'bar', 'foo' => 'foo'])->replaceKeys([1 => 2, 'foo' => 'replaced']); // Arrayy[2 => 'bar', 'replaced' => 'foo'] |
||
5446 | * </code> |
||
5447 | * |
||
5448 | * @param array $keys <p>An array of keys matching the array's size</p> |
||
5449 | * |
||
5450 | * @return static |
||
5451 | * <p>(Immutable)</p> |
||
5452 | * |
||
5453 | * @psalm-param array<mixed,mixed>|array<mixed,TKey> $keys |
||
5454 | * @psalm-return static<TKey,T> |
||
5455 | * @psalm-mutation-free |
||
5456 | */ |
||
5457 | 1 | public function replaceKeys(array $keys): self |
|
5468 | |||
5469 | /** |
||
5470 | * Replace the first matched value in an array. |
||
5471 | * |
||
5472 | * EXAMPLE: <code> |
||
5473 | * $testArray = ['bar', 'foo' => 'foo', 'foobar' => 'foobar']; |
||
5474 | * a($testArray)->replaceOneValue('foo', 'replaced'); // Arrayy['bar', 'foo' => 'replaced', 'foobar' => 'foobar'] |
||
5475 | * </code> |
||
5476 | * |
||
5477 | * @param mixed $search <p>The value to replace.</p> |
||
5478 | * @param mixed $replacement <p>The value to replace.</p> |
||
5479 | * |
||
5480 | * @return static |
||
5481 | * <p>(Immutable)</p> |
||
5482 | * |
||
5483 | * @psalm-return static<TKey,T> |
||
5484 | * @psalm-mutation-free |
||
5485 | */ |
||
5486 | 3 | View Code Duplication | public function replaceOneValue($search, $replacement = ''): self |
5501 | |||
5502 | /** |
||
5503 | * Replace values in the current array. |
||
5504 | * |
||
5505 | * EXAMPLE: <code> |
||
5506 | * $testArray = ['bar', 'foo' => 'foo', 'foobar' => 'foobar']; |
||
5507 | * a($testArray)->replaceValues('foo', 'replaced'); // Arrayy['bar', 'foo' => 'replaced', 'foobar' => 'replacedbar'] |
||
5508 | * </code> |
||
5509 | * |
||
5510 | * @param mixed $search <p>The value to replace.</p> |
||
5511 | * @param mixed $replacement <p>What to replace it with.</p> |
||
5512 | * |
||
5513 | * @return static |
||
5514 | * <p>(Immutable)</p> |
||
5515 | * |
||
5516 | * @psalm-return static<TKey,T> |
||
5517 | * @psalm-mutation-free |
||
5518 | */ |
||
5519 | 1 | public function replaceValues($search, $replacement = ''): self |
|
5531 | |||
5532 | /** |
||
5533 | * Get the last elements from index $from until the end of this array. |
||
5534 | * |
||
5535 | * EXAMPLE: <code> |
||
5536 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->rest(2); // Arrayy[0 => 'lall'] |
||
5537 | * </code> |
||
5538 | * |
||
5539 | * @param int $from |
||
5540 | * |
||
5541 | * @return static |
||
5542 | * <p>(Immutable)</p> |
||
5543 | * |
||
5544 | * @psalm-return static<TKey,T> |
||
5545 | * @psalm-mutation-free |
||
5546 | */ |
||
5547 | 15 | View Code Duplication | public function rest(int $from = 1): self |
5557 | |||
5558 | /** |
||
5559 | * Return the array in the reverse order. |
||
5560 | * |
||
5561 | * EXAMPLE: <code> |
||
5562 | * a([1, 2, 3])->reverse(); // self[3, 2, 1] |
||
5563 | * </code> |
||
5564 | * |
||
5565 | * @return $this |
||
5566 | * <p>(Mutable) Return this Arrayy object.</p> |
||
5567 | * |
||
5568 | * @psalm-return static<TKey,T> |
||
5569 | */ |
||
5570 | 9 | public function reverse(): self |
|
5578 | |||
5579 | /** |
||
5580 | * Sort an array in reverse order. |
||
5581 | * |
||
5582 | * @param int $sort_flags [optional] <p> |
||
5583 | * You may modify the behavior of the sort using the optional |
||
5584 | * parameter sort_flags, for details |
||
5585 | * see sort. |
||
5586 | * </p> |
||
5587 | * |
||
5588 | * @return $this |
||
5589 | * <p>(Mutable) Return this Arrayy object.</p> |
||
5590 | * |
||
5591 | * @psalm-return static<TKey,T> |
||
5592 | */ |
||
5593 | 4 | public function rsort(int $sort_flags = 0): self |
|
5601 | |||
5602 | /** |
||
5603 | * Sort an array in reverse order. |
||
5604 | * |
||
5605 | * @param int $sort_flags [optional] <p> |
||
5606 | * You may modify the behavior of the sort using the optional |
||
5607 | * parameter sort_flags, for details |
||
5608 | * see sort. |
||
5609 | * </p> |
||
5610 | * |
||
5611 | * @return $this |
||
5612 | * <p>(Immutable) Return this Arrayy object.</p> |
||
5613 | * |
||
5614 | * @psalm-return static<TKey,T> |
||
5615 | * @psalm-mutation-free |
||
5616 | */ |
||
5617 | 4 | public function rsortImmutable(int $sort_flags = 0): self |
|
5628 | |||
5629 | /** |
||
5630 | * Search for the first index of the current array via $value. |
||
5631 | * |
||
5632 | * EXAMPLE: <code> |
||
5633 | * a(['fòô' => 'bàř', 'lall' => 'bàř'])->searchIndex('bàř'); // Arrayy[0 => 'fòô'] |
||
5634 | * </code> |
||
5635 | * |
||
5636 | * @param mixed $value |
||
5637 | * |
||
5638 | * @return false|float|int|string |
||
5639 | * <p>Will return <b>FALSE</b> if the value can't be found.</p> |
||
5640 | * @psalm-mutation-free |
||
5641 | */ |
||
5642 | 21 | public function searchIndex($value) |
|
5652 | |||
5653 | /** |
||
5654 | * Search for the value of the current array via $index. |
||
5655 | * |
||
5656 | * EXAMPLE: <code> |
||
5657 | * a(['fòô' => 'bàř'])->searchValue('fòô'); // Arrayy[0 => 'bàř'] |
||
5658 | * </code> |
||
5659 | * |
||
5660 | * @param mixed $index |
||
5661 | * |
||
5662 | * @return static |
||
5663 | * <p>(Immutable) Will return a empty Arrayy if the value wasn't found.</p> |
||
5664 | * |
||
5665 | * @psalm-return static<TKey,T> |
||
5666 | * @psalm-mutation-free |
||
5667 | */ |
||
5668 | 9 | public function searchValue($index): self |
|
5698 | |||
5699 | /** |
||
5700 | * Set a value for the current array (optional using dot-notation). |
||
5701 | * |
||
5702 | * EXAMPLE: <code> |
||
5703 | * $arrayy = a(['Lars' => ['lastname' => 'Moelleken']]); |
||
5704 | * $arrayy->set('Lars.lastname', 'Müller'); // Arrayy['Lars', ['lastname' => 'Müller']]] |
||
5705 | * </code> |
||
5706 | * |
||
5707 | * @param string $key <p>The key to set.</p> |
||
5708 | * @param mixed $value <p>Its value.</p> |
||
5709 | * |
||
5710 | * @return $this |
||
5711 | * <p>(Mutable) Return this Arrayy object.</p> |
||
5712 | * |
||
5713 | * @psalm-param TKey $key |
||
5714 | * @psalm-param T $value |
||
5715 | * @psalm-return static<TKey,T> |
||
5716 | */ |
||
5717 | 28 | public function set($key, $value): self |
|
5723 | |||
5724 | /** |
||
5725 | * Get a value from a array and set it if it was not. |
||
5726 | * |
||
5727 | * WARNING: this method only set the value, if the $key is not already set |
||
5728 | * |
||
5729 | * EXAMPLE: <code> |
||
5730 | * $arrayy = a([1 => 1, 2 => 2, 3 => 3]); |
||
5731 | * $arrayy->setAndGet(1, 4); // 1 |
||
5732 | * $arrayy->setAndGet(0, 4); // 4 |
||
5733 | * </code> |
||
5734 | * |
||
5735 | * @param mixed $key <p>The key</p> |
||
5736 | * @param mixed $fallback <p>The default value to set if it isn't.</p> |
||
5737 | * |
||
5738 | * @return mixed |
||
5739 | * <p>(Mutable)</p> |
||
5740 | */ |
||
5741 | 11 | public function setAndGet($key, $fallback = null) |
|
5752 | |||
5753 | /** |
||
5754 | * Shifts a specified value off the beginning of array. |
||
5755 | * |
||
5756 | * @return mixed |
||
5757 | * <p>(Mutable) A shifted element from the current array.</p> |
||
5758 | */ |
||
5759 | 5 | public function shift() |
|
5765 | |||
5766 | /** |
||
5767 | * Shuffle the current array. |
||
5768 | * |
||
5769 | * EXAMPLE: <code> |
||
5770 | * a([1 => 'bar', 'foo' => 'foo'])->shuffle(); // e.g.: Arrayy[['foo' => 'foo', 1 => 'bar']] |
||
5771 | * </code> |
||
5772 | * |
||
5773 | * @param bool $secure <p>using a CSPRNG | @link https://paragonie.com/b/JvICXzh_jhLyt4y3</p> |
||
5774 | * @param array $array [optional] |
||
5775 | * |
||
5776 | * @return static |
||
5777 | * <p>(Immutable)</p> |
||
5778 | * |
||
5779 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
5780 | * @psalm-return static<TKey,T> |
||
5781 | * |
||
5782 | * @noinspection BadExceptionsProcessingInspection |
||
5783 | * @noinspection RandomApiMigrationInspection |
||
5784 | * @noinspection NonSecureShuffleUsageInspection |
||
5785 | */ |
||
5786 | 2 | public function shuffle(bool $secure = false, array $array = null): self |
|
5824 | |||
5825 | /** |
||
5826 | * Count the values from the current array. |
||
5827 | * |
||
5828 | * alias: for "Arrayy->count()" |
||
5829 | * |
||
5830 | * @param int $mode |
||
5831 | * |
||
5832 | * @return int |
||
5833 | */ |
||
5834 | 20 | public function size(int $mode = \COUNT_NORMAL): int |
|
5838 | |||
5839 | /** |
||
5840 | * Checks whether array has exactly $size items. |
||
5841 | * |
||
5842 | * @param int $size |
||
5843 | * |
||
5844 | * @return bool |
||
5845 | */ |
||
5846 | 1 | public function sizeIs(int $size): bool |
|
5862 | |||
5863 | /** |
||
5864 | * Checks whether array has between $fromSize to $toSize items. $toSize can be |
||
5865 | * smaller than $fromSize. |
||
5866 | * |
||
5867 | * @param int $fromSize |
||
5868 | * @param int $toSize |
||
5869 | * |
||
5870 | * @return bool |
||
5871 | */ |
||
5872 | 1 | public function sizeIsBetween(int $fromSize, int $toSize): bool |
|
5892 | |||
5893 | /** |
||
5894 | * Checks whether array has more than $size items. |
||
5895 | * |
||
5896 | * @param int $size |
||
5897 | * |
||
5898 | * @return bool |
||
5899 | */ |
||
5900 | 1 | View Code Duplication | public function sizeIsGreaterThan(int $size): bool |
5914 | |||
5915 | /** |
||
5916 | * Checks whether array has less than $size items. |
||
5917 | * |
||
5918 | * @param int $size |
||
5919 | * |
||
5920 | * @return bool |
||
5921 | */ |
||
5922 | 1 | View Code Duplication | public function sizeIsLessThan(int $size): bool |
5936 | |||
5937 | /** |
||
5938 | * Counts all elements in an array, or something in an object. |
||
5939 | * |
||
5940 | * <p> |
||
5941 | * For objects, if you have SPL installed, you can hook into count() by implementing interface {@see Countable}. |
||
5942 | * The interface has exactly one method, {@see Countable::count()}, which returns the return value for the count() |
||
5943 | * function. Please see the {@see Array} section of the manual for a detailed explanation of how arrays are |
||
5944 | * implemented and used in PHP. |
||
5945 | * </p> |
||
5946 | * |
||
5947 | * @return int |
||
5948 | * <p> |
||
5949 | * The number of elements in var, which is |
||
5950 | * typically an array, since anything else will have one |
||
5951 | * element. |
||
5952 | * </p> |
||
5953 | * <p> |
||
5954 | * If var is not an array or an object with |
||
5955 | * implemented Countable interface, |
||
5956 | * 1 will be returned. |
||
5957 | * There is one exception, if var is &null;, |
||
5958 | * 0 will be returned. |
||
5959 | * </p> |
||
5960 | * <p> |
||
5961 | * Caution: count may return 0 for a variable that isn't set, |
||
5962 | * but it may also return 0 for a variable that has been initialized with an |
||
5963 | * empty array. Use isset to test if a variable is set. |
||
5964 | * </p> |
||
5965 | */ |
||
5966 | 10 | public function sizeRecursive(): int |
|
5970 | |||
5971 | /** |
||
5972 | * Extract a slice of the array. |
||
5973 | * |
||
5974 | * @param int $offset <p>Slice begin index.</p> |
||
5975 | * @param int|null $length <p>Length of the slice.</p> |
||
5976 | * @param bool $preserveKeys <p>Whether array keys are preserved or no.</p> |
||
5977 | * |
||
5978 | * @return static |
||
5979 | * <p>(Immutable) A slice of the original array with length $length.</p> |
||
5980 | * |
||
5981 | * @psalm-return static<TKey,T> |
||
5982 | * @psalm-mutation-free |
||
5983 | */ |
||
5984 | 5 | public function slice(int $offset, int $length = null, bool $preserveKeys = false) |
|
5997 | |||
5998 | /** |
||
5999 | * Sort the current array and optional you can keep the keys. |
||
6000 | * |
||
6001 | * EXAMPLE: <code> |
||
6002 | * a(3 => 'd', 2 => 'f', 0 => 'a')->sort(SORT_ASC, SORT_NATURAL, false); // Arrayy[0 => 'a', 1 => 'd', 2 => 'f'] |
||
6003 | * </code> |
||
6004 | * |
||
6005 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
6006 | * @param int $strategy <p>sort_flags => use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
6007 | * <strong>SORT_NATURAL</strong></p> |
||
6008 | * @param bool $keepKeys |
||
6009 | * |
||
6010 | * @return static |
||
6011 | * <p>(Mutable) Return this Arrayy object.</p> |
||
6012 | * |
||
6013 | * @psalm-return static<TKey,T> |
||
6014 | */ |
||
6015 | 20 | public function sort( |
|
6029 | |||
6030 | /** |
||
6031 | * Sort the current array and optional you can keep the keys. |
||
6032 | * |
||
6033 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
6034 | * @param int $strategy <p>sort_flags => use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
6035 | * <strong>SORT_NATURAL</strong></p> |
||
6036 | * @param bool $keepKeys |
||
6037 | * |
||
6038 | * @return static |
||
6039 | * <p>(Immutable) Return this Arrayy object.</p> |
||
6040 | * |
||
6041 | * @psalm-return static<TKey,T> |
||
6042 | */ |
||
6043 | 12 | public function sortImmutable( |
|
6059 | |||
6060 | /** |
||
6061 | * Sort the current array by key. |
||
6062 | * |
||
6063 | * EXAMPLE: <code> |
||
6064 | * a([1 => 2, 0 => 1])->sortKeys(\SORT_ASC); // Arrayy[0 => 1, 1 => 2] |
||
6065 | * </code> |
||
6066 | * |
||
6067 | * @see http://php.net/manual/en/function.ksort.php |
||
6068 | * @see http://php.net/manual/en/function.krsort.php |
||
6069 | * |
||
6070 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
6071 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
6072 | * <strong>SORT_NATURAL</strong></p> |
||
6073 | * |
||
6074 | * @return $this |
||
6075 | * <p>(Mutable) Return this Arrayy object.</p> |
||
6076 | * |
||
6077 | * @psalm-return static<TKey,T> |
||
6078 | */ |
||
6079 | 18 | public function sortKeys( |
|
6089 | |||
6090 | /** |
||
6091 | * Sort the current array by key. |
||
6092 | * |
||
6093 | * @see http://php.net/manual/en/function.ksort.php |
||
6094 | * @see http://php.net/manual/en/function.krsort.php |
||
6095 | * |
||
6096 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
6097 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
6098 | * <strong>SORT_NATURAL</strong></p> |
||
6099 | * |
||
6100 | * @return $this |
||
6101 | * <p>(Immutable) Return this Arrayy object.</p> |
||
6102 | * |
||
6103 | * @psalm-return static<TKey,T> |
||
6104 | * @psalm-mutation-free |
||
6105 | */ |
||
6106 | 8 | public function sortKeysImmutable( |
|
6119 | |||
6120 | /** |
||
6121 | * Sort the current array by value. |
||
6122 | * |
||
6123 | * EXAMPLE: <code> |
||
6124 | * a(3 => 'd', 2 => 'f', 0 => 'a')->sortValueKeepIndex(SORT_ASC, SORT_REGULAR); // Arrayy[0 => 'a', 3 => 'd', 2 => 'f'] |
||
6125 | * </code> |
||
6126 | * |
||
6127 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
6128 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
6129 | * <strong>SORT_NATURAL</strong></p> |
||
6130 | * |
||
6131 | * @return static |
||
6132 | * <p>(Mutable)</p> |
||
6133 | * |
||
6134 | * @psalm-return static<TKey,T> |
||
6135 | */ |
||
6136 | 1 | public function sortValueKeepIndex( |
|
6142 | |||
6143 | /** |
||
6144 | * Sort the current array by value. |
||
6145 | * |
||
6146 | * EXAMPLE: <code> |
||
6147 | * a(3 => 'd', 2 => 'f', 0 => 'a')->sortValueNewIndex(SORT_ASC, SORT_NATURAL); // Arrayy[0 => 'a', 1 => 'd', 2 => 'f'] |
||
6148 | * </code> |
||
6149 | * |
||
6150 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
6151 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
6152 | * <strong>SORT_NATURAL</strong></p> |
||
6153 | * |
||
6154 | * @return static |
||
6155 | * <p>(Mutable)</p> |
||
6156 | * |
||
6157 | * @psalm-return static<TKey,T> |
||
6158 | */ |
||
6159 | 1 | public function sortValueNewIndex($direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
6163 | |||
6164 | /** |
||
6165 | * Sort a array by value or by a closure. |
||
6166 | * |
||
6167 | * - If the sorter is null, the array is sorted naturally. |
||
6168 | * - Associative (string) keys will be maintained, but numeric keys will be re-indexed. |
||
6169 | * |
||
6170 | * EXAMPLE: <code> |
||
6171 | * $testArray = range(1, 5); |
||
6172 | * $under = a($testArray)->sorter( |
||
6173 | * function ($value) { |
||
6174 | * return $value % 2 === 0; |
||
6175 | * } |
||
6176 | * ); |
||
6177 | * var_dump($under); // Arrayy[1, 3, 5, 2, 4] |
||
6178 | * </code> |
||
6179 | * |
||
6180 | * @param callable|string|null $sorter |
||
6181 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or |
||
6182 | * <strong>SORT_DESC</strong></p> |
||
6183 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
6184 | * <strong>SORT_NATURAL</strong></p> |
||
6185 | * |
||
6186 | * @return static |
||
6187 | * <p>(Immutable)</p> |
||
6188 | * |
||
6189 | * @psalm-return static<TKey,T> |
||
6190 | * @psalm-mutation-free |
||
6191 | */ |
||
6192 | 1 | public function sorter($sorter = null, $direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
6233 | |||
6234 | /** |
||
6235 | * @param int $offset |
||
6236 | * @param int|null $length |
||
6237 | * @param array $replacement |
||
6238 | * |
||
6239 | * @return static |
||
6240 | * <p>(Immutable)</p> |
||
6241 | * |
||
6242 | * @psalm-param array<mixed,mixed>|array<mixed,T> $replacement |
||
6243 | * @psalm-return static<TKey,T> |
||
6244 | * @psalm-mutation-free |
||
6245 | */ |
||
6246 | 1 | public function splice(int $offset, int $length = null, $replacement = []): self |
|
6263 | |||
6264 | /** |
||
6265 | * Split an array in the given amount of pieces. |
||
6266 | * |
||
6267 | * EXAMPLE: <code> |
||
6268 | * a(['a' => 1, 'b' => 2])->split(2, true); // Arrayy[['a' => 1], ['b' => 2]] |
||
6269 | * </code> |
||
6270 | * |
||
6271 | * @param int $numberOfPieces |
||
6272 | * @param bool $keepKeys |
||
6273 | * |
||
6274 | * @return static |
||
6275 | * <p>(Immutable)</p> |
||
6276 | * |
||
6277 | * @psalm-return static<TKey,T> |
||
6278 | * @psalm-mutation-free |
||
6279 | */ |
||
6280 | 1 | public function split(int $numberOfPieces = 2, bool $keepKeys = false): self |
|
6336 | |||
6337 | /** |
||
6338 | * Strip all empty items from the current array. |
||
6339 | * |
||
6340 | * EXAMPLE: <code> |
||
6341 | * a(['a' => 1, 'b' => ''])->stripEmpty(); // Arrayy[['a' => 1]] |
||
6342 | * </code> |
||
6343 | * |
||
6344 | * @return static |
||
6345 | * <p>(Immutable)</p> |
||
6346 | * |
||
6347 | * @psalm-return static<TKey,T> |
||
6348 | * @psalm-mutation-free |
||
6349 | */ |
||
6350 | 1 | public function stripEmpty(): self |
|
6362 | |||
6363 | /** |
||
6364 | * Swap two values between positions by key. |
||
6365 | * |
||
6366 | * EXAMPLE: <code> |
||
6367 | * a(['a' => 1, 'b' => ''])->swap('a', 'b'); // Arrayy[['a' => '', 'b' => 1]] |
||
6368 | * </code> |
||
6369 | * |
||
6370 | * @param int|string $swapA <p>a key in the array</p> |
||
6371 | * @param int|string $swapB <p>a key in the array</p> |
||
6372 | * |
||
6373 | * @return static |
||
6374 | * <p>(Immutable)</p> |
||
6375 | * |
||
6376 | * @psalm-return static<TKey,T> |
||
6377 | * @psalm-mutation-free |
||
6378 | */ |
||
6379 | 1 | public function swap($swapA, $swapB): self |
|
6391 | |||
6392 | /** |
||
6393 | * Get the current array from the "Arrayy"-object. |
||
6394 | * alias for "getArray()" |
||
6395 | * |
||
6396 | * @param bool $convertAllArrayyElements <p> |
||
6397 | * Convert all Child-"Arrayy" objects also to arrays. |
||
6398 | * </p> |
||
6399 | * @param bool $preserveKeys <p> |
||
6400 | * e.g.: A generator maybe return the same key more then once, |
||
6401 | * so maybe you will ignore the keys. |
||
6402 | * </p> |
||
6403 | * |
||
6404 | * @return array |
||
6405 | * |
||
6406 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
6407 | * @psalm-mutation-free |
||
6408 | */ |
||
6409 | 931 | public function toArray( |
|
6437 | |||
6438 | /** |
||
6439 | * Get the current array from the "Arrayy"-object as list. |
||
6440 | * |
||
6441 | * @param bool $convertAllArrayyElements <p> |
||
6442 | * Convert all Child-"Arrayy" objects also to arrays. |
||
6443 | * </p> |
||
6444 | * |
||
6445 | * @return array |
||
6446 | * |
||
6447 | * @psalm-return list<array<TKey,T>> |
||
6448 | * @psalm-mutation-free |
||
6449 | */ |
||
6450 | 1 | public function toList(bool $convertAllArrayyElements = false): array |
|
6457 | |||
6458 | /** |
||
6459 | * Convert the current array to JSON. |
||
6460 | * |
||
6461 | * EXAMPLE: <code> |
||
6462 | * a(['bar', ['foo']])->toJson(); // '["bar",{"1":"foo"}]' |
||
6463 | * </code> |
||
6464 | * |
||
6465 | * @param int $options [optional] <p>e.g. JSON_PRETTY_PRINT</p> |
||
6466 | * @param int $depth [optional] <p>Set the maximum depth. Must be greater than zero.</p> |
||
6467 | * |
||
6468 | * @return string |
||
6469 | */ |
||
6470 | 12 | public function toJson(int $options = 0, int $depth = 512): string |
|
6479 | |||
6480 | /** |
||
6481 | * @param string[]|null $items [optional] |
||
6482 | * @param string[] $helper [optional] |
||
6483 | * |
||
6484 | * @return static|static[] |
||
6485 | * |
||
6486 | * @psalm-return static<int, static<TKey,T>> |
||
6487 | */ |
||
6488 | 1 | public function toPermutation(array $items = null, array $helper = []): self |
|
6522 | |||
6523 | /** |
||
6524 | * Implodes array to a string with specified separator. |
||
6525 | * |
||
6526 | * @param string $separator [optional] <p>The element's separator.</p> |
||
6527 | * |
||
6528 | * @return string |
||
6529 | * <p>The string representation of array, separated by ",".</p> |
||
6530 | */ |
||
6531 | 19 | public function toString(string $separator = ','): string |
|
6535 | |||
6536 | /** |
||
6537 | * Return a duplicate free copy of the current array. |
||
6538 | * |
||
6539 | * EXAMPLE: <code> |
||
6540 | * a([2 => 1, 3 => 2, 4 => 2])->uniqueNewIndex(); // Arrayy[1, 2] |
||
6541 | * </code> |
||
6542 | * |
||
6543 | * @return $this |
||
6544 | * <p>(Mutable)</p> |
||
6545 | * |
||
6546 | * @psalm-return static<TKey,T> |
||
6547 | */ |
||
6548 | 13 | public function uniqueNewIndex(): self |
|
6570 | |||
6571 | /** |
||
6572 | * Return a duplicate free copy of the current array. (with the old keys) |
||
6573 | * |
||
6574 | * EXAMPLE: <code> |
||
6575 | * a([2 => 1, 3 => 2, 4 => 2])->uniqueNewIndex(); // Arrayy[2 => 1, 3 => 2] |
||
6576 | * </code> |
||
6577 | * |
||
6578 | * @return $this |
||
6579 | * <p>(Mutable)</p> |
||
6580 | * |
||
6581 | * @psalm-return static<TKey,T> |
||
6582 | */ |
||
6583 | 11 | public function uniqueKeepIndex(): self |
|
6609 | |||
6610 | /** |
||
6611 | * alias: for "Arrayy->uniqueNewIndex()" |
||
6612 | * |
||
6613 | * @return static |
||
6614 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
6615 | * |
||
6616 | * @see Arrayy::unique() |
||
6617 | * |
||
6618 | * @psalm-return static<TKey,T> |
||
6619 | */ |
||
6620 | 13 | public function unique(): self |
|
6624 | |||
6625 | /** |
||
6626 | * Prepends one or more values to the beginning of array at once. |
||
6627 | * |
||
6628 | * @param array ...$args |
||
6629 | * |
||
6630 | * @return $this |
||
6631 | * <p>(Mutable) Return this Arrayy object, with prepended elements to the beginning of array.</p> |
||
6632 | * |
||
6633 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$args |
||
6634 | * @psalm-return static<TKey,T> |
||
6635 | */ |
||
6636 | 4 | public function unshift(...$args): self |
|
6644 | |||
6645 | /** |
||
6646 | * Tests whether the given closure return something valid for all elements of this array. |
||
6647 | * |
||
6648 | * @param \Closure $closure the predicate |
||
6649 | * |
||
6650 | * @return bool |
||
6651 | * <p>TRUE, if the predicate yields TRUE for all elements, FALSE otherwise.</p> |
||
6652 | */ |
||
6653 | 1 | View Code Duplication | public function validate(\Closure $closure): bool |
6663 | |||
6664 | /** |
||
6665 | * Get all values from a array. |
||
6666 | * |
||
6667 | * EXAMPLE: <code> |
||
6668 | * $arrayy = a([1 => 'foo', 2 => 'foo2', 3 => 'bar']); |
||
6669 | * $arrayyTmp->values(); // Arrayy[0 => 'foo', 1 => 'foo2', 2 => 'bar'] |
||
6670 | * </code> |
||
6671 | * |
||
6672 | * @return static |
||
6673 | * <p>(Immutable)</p> |
||
6674 | * |
||
6675 | * @psalm-return static<TKey,T> |
||
6676 | * @psalm-mutation-free |
||
6677 | */ |
||
6678 | 2 | public function values(): self |
|
6691 | |||
6692 | /** |
||
6693 | * Apply the given function to every element in the array, discarding the results. |
||
6694 | * |
||
6695 | * EXAMPLE: <code> |
||
6696 | * $callable = function (&$value, $key) { |
||
6697 | * $value = $key; |
||
6698 | * }; |
||
6699 | * $arrayy = a([1, 2, 3]); |
||
6700 | * $arrayy->walk($callable); // Arrayy[0, 1, 2] |
||
6701 | * </code> |
||
6702 | * |
||
6703 | * @param callable $callable |
||
6704 | * @param bool $recursive [optional] <p>Whether array will be walked recursively or no</p> |
||
6705 | * @param mixed $userData [optional] <p> |
||
6706 | * If the optional $userData parameter is supplied, |
||
6707 | * it will be passed as the third parameter to the $callable. |
||
6708 | * </p> |
||
6709 | * |
||
6710 | * @return $this |
||
6711 | * <p>(Mutable) Return this Arrayy object, with modified elements.</p> |
||
6712 | * |
||
6713 | * @psalm-return static<TKey,T> |
||
6714 | */ |
||
6715 | 12 | public function walk( |
|
6741 | |||
6742 | /** |
||
6743 | * Returns a collection of matching items. |
||
6744 | * |
||
6745 | * @param string $keyOrPropertyOrMethod the property or method to evaluate |
||
6746 | * @param mixed $value the value to match |
||
6747 | * |
||
6748 | * @throws \InvalidArgumentException if property or method is not defined |
||
6749 | * |
||
6750 | * @return static |
||
6751 | * |
||
6752 | * @psalm-param T $value |
||
6753 | * @psalm-return static<TKey,T> |
||
6754 | */ |
||
6755 | 1 | public function where(string $keyOrPropertyOrMethod, $value): self |
|
6768 | |||
6769 | /** |
||
6770 | * Convert an array into a object. |
||
6771 | * |
||
6772 | * @param array $array |
||
6773 | * |
||
6774 | * @return \stdClass |
||
6775 | * |
||
6776 | * @psalm-param array<mixed,mixed> $array |
||
6777 | */ |
||
6778 | 4 | final protected static function arrayToObject(array $array = []): \stdClass |
|
6797 | |||
6798 | /** |
||
6799 | * @param array|\Generator|null $input <p> |
||
6800 | * An array containing keys to return. |
||
6801 | * </p> |
||
6802 | * @param mixed|null $search_values [optional] <p> |
||
6803 | * If specified, then only keys containing these values are returned. |
||
6804 | * </p> |
||
6805 | * @param bool $strict [optional] <p> |
||
6806 | * Determines if strict comparison (===) should be used during the |
||
6807 | * search. |
||
6808 | * </p> |
||
6809 | * |
||
6810 | * @return array |
||
6811 | * <p>an array of all the keys in input</p> |
||
6812 | * |
||
6813 | * @psalm-param array<mixed,mixed>|\Generator<TKey,T>|null $input |
||
6814 | * @psalm-return array<TKey|mixed> |
||
6815 | * @psalm-mutation-free |
||
6816 | */ |
||
6817 | 11 | protected function array_keys_recursive( |
|
6878 | |||
6879 | /** |
||
6880 | * @param mixed $path |
||
6881 | * @param callable $callable |
||
6882 | * @param array|null $currentOffset |
||
6883 | * |
||
6884 | * @return void |
||
6885 | * |
||
6886 | * @psalm-param array<mixed,mixed>|array<TKey,T>|null $currentOffset |
||
6887 | * @psalm-mutation-free |
||
6888 | */ |
||
6889 | 10 | protected function callAtPath($path, $callable, &$currentOffset = null) |
|
6918 | |||
6919 | /** |
||
6920 | * Extracts the value of the given property or method from the object. |
||
6921 | * |
||
6922 | * @param static $object <p>The object to extract the value from.</p> |
||
6923 | * @param string $keyOrPropertyOrMethod <p>The property or method for which the |
||
6924 | * value should be extracted.</p> |
||
6925 | * |
||
6926 | * @throws \InvalidArgumentException if the method or property is not defined |
||
6927 | * |
||
6928 | * @return mixed |
||
6929 | * <p>The value extracted from the specified property or method.</p> |
||
6930 | * |
||
6931 | * @psalm-param self<TKey,T> $object |
||
6932 | */ |
||
6933 | 1 | final protected function extractValue(self $object, string $keyOrPropertyOrMethod) |
|
6955 | |||
6956 | /** |
||
6957 | * create a fallback for array |
||
6958 | * |
||
6959 | * 1. use the current array, if it's a array |
||
6960 | * 2. fallback to empty array, if there is nothing |
||
6961 | * 3. call "getArray()" on object, if there is a "Arrayy"-object |
||
6962 | * 4. call "createFromObject()" on object, if there is a "\Traversable"-object |
||
6963 | * 5. call "__toArray()" on object, if the method exists |
||
6964 | * 6. cast a string or object with "__toString()" into an array |
||
6965 | * 7. throw a "InvalidArgumentException"-Exception |
||
6966 | * |
||
6967 | * @param mixed $data |
||
6968 | * |
||
6969 | * @throws \InvalidArgumentException |
||
6970 | * |
||
6971 | * @return array |
||
6972 | * |
||
6973 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
6974 | */ |
||
6975 | 1206 | protected function fallbackForArray(&$data): array |
|
6985 | |||
6986 | /** |
||
6987 | * @param bool $preserveKeys <p> |
||
6988 | * e.g.: A generator maybe return the same key more then once, |
||
6989 | * so maybe you will ignore the keys. |
||
6990 | * </p> |
||
6991 | * |
||
6992 | * @return bool |
||
6993 | * |
||
6994 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
6995 | * @psalm-mutation-free :/ |
||
6996 | */ |
||
6997 | 1118 | protected function generatorToArray(bool $preserveKeys = true) |
|
7008 | |||
7009 | /** |
||
7010 | * Get correct PHP constant for direction. |
||
7011 | * |
||
7012 | * @param int|string $direction |
||
7013 | * |
||
7014 | * @return int |
||
7015 | * @psalm-mutation-free |
||
7016 | */ |
||
7017 | 43 | protected function getDirection($direction): int |
|
7039 | |||
7040 | /** |
||
7041 | * @return TypeCheckInterface[] |
||
7042 | * |
||
7043 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
7044 | */ |
||
7045 | 24 | protected function getPropertiesFromPhpDoc() |
|
7100 | |||
7101 | /** |
||
7102 | * @param mixed $glue |
||
7103 | * @param mixed $pieces |
||
7104 | * @param bool $useKeys |
||
7105 | * |
||
7106 | * @return string |
||
7107 | * @psalm-mutation-free |
||
7108 | */ |
||
7109 | 36 | protected function implode_recursive( |
|
7142 | |||
7143 | /** |
||
7144 | * @param mixed $needle <p> |
||
7145 | * The searched value. |
||
7146 | * </p> |
||
7147 | * <p> |
||
7148 | * If needle is a string, the comparison is done |
||
7149 | * in a case-sensitive manner. |
||
7150 | * </p> |
||
7151 | * @param array|\Generator|null $haystack <p> |
||
7152 | * The array. |
||
7153 | * </p> |
||
7154 | * @param bool $strict [optional] <p> |
||
7155 | * If the third parameter strict is set to true |
||
7156 | * then the in_array function will also check the |
||
7157 | * types of the |
||
7158 | * needle in the haystack. |
||
7159 | * </p> |
||
7160 | * |
||
7161 | * @return bool |
||
7162 | * <p>true if needle is found in the array, false otherwise</p> |
||
7163 | * |
||
7164 | * @psalm-param array<mixed,mixed>|\Generator<TKey,T>|null $haystack |
||
7165 | * @psalm-mutation-free |
||
7166 | */ |
||
7167 | 18 | protected function in_array_recursive($needle, $haystack = null, $strict = true): bool |
|
7192 | |||
7193 | /** |
||
7194 | * @param mixed $data |
||
7195 | * |
||
7196 | * @return array|null |
||
7197 | * |
||
7198 | * @psalm-return array<mixed,mixed>|array<TKey,T>|null |
||
7199 | */ |
||
7200 | 1206 | protected function internalGetArray(&$data) |
|
7251 | |||
7252 | /** |
||
7253 | * Internal mechanics of remove method. |
||
7254 | * |
||
7255 | * @param mixed $key |
||
7256 | * |
||
7257 | * @return bool |
||
7258 | */ |
||
7259 | 22 | protected function internalRemove($key): bool |
|
7292 | |||
7293 | /** |
||
7294 | * Internal mechanic of set method. |
||
7295 | * |
||
7296 | * @param int|string|null $key |
||
7297 | * @param mixed $value |
||
7298 | * @param bool $checkProperties |
||
7299 | * |
||
7300 | * @return bool |
||
7301 | */ |
||
7302 | 1056 | protected function internalSet( |
|
7361 | |||
7362 | /** |
||
7363 | * Convert a object into an array. |
||
7364 | * |
||
7365 | * @param mixed|object $object |
||
7366 | * |
||
7367 | * @return array|mixed |
||
7368 | * |
||
7369 | * @psalm-mutation-free |
||
7370 | */ |
||
7371 | 5 | protected static function objectToArray($object) |
|
7384 | |||
7385 | /** |
||
7386 | * @param array $data |
||
7387 | * @param bool $checkPropertiesInConstructor |
||
7388 | * |
||
7389 | * @return void |
||
7390 | * |
||
7391 | * @psalm-param array<mixed,T> $data |
||
7392 | */ |
||
7393 | 1204 | protected function setInitialValuesAndProperties(array &$data, bool $checkPropertiesInConstructor) |
|
7438 | |||
7439 | /** |
||
7440 | * sorting keys |
||
7441 | * |
||
7442 | * @param array $elements |
||
7443 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
7444 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
7445 | * <strong>SORT_NATURAL</strong></p> |
||
7446 | * |
||
7447 | * @return $this |
||
7448 | * <p>(Mutable) Return this Arrayy object.</p> |
||
7449 | * |
||
7450 | * @psalm-param array<mixed,mixed>|array<mixed|TKey,T> $elements |
||
7451 | * @psalm-return static<TKey,T> |
||
7452 | */ |
||
7453 | 18 | protected function sorterKeys( |
|
7474 | |||
7475 | /** |
||
7476 | * @param array $elements <p>Warning: used as reference</p> |
||
7477 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
7478 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
7479 | * <strong>SORT_NATURAL</strong></p> |
||
7480 | * @param bool $keepKeys |
||
7481 | * |
||
7482 | * @return $this |
||
7483 | * <p>(Mutable) Return this Arrayy object.</p> |
||
7484 | * |
||
7485 | * @psalm-param array<mixed,mixed>|array<mixed|TKey,T> $elements |
||
7486 | * @psalm-return static<TKey,T> |
||
7487 | */ |
||
7488 | 24 | protected function sorting( |
|
7522 | |||
7523 | /** |
||
7524 | * @param array $array |
||
7525 | * |
||
7526 | * @return array |
||
7527 | * |
||
7528 | * @psalm-mutation-free |
||
7529 | */ |
||
7530 | 25 | private function getArrayRecursiveHelperArrayy(array $array) |
|
7552 | |||
7553 | /** |
||
7554 | * @param int|string|null $key |
||
7555 | * @param mixed $value |
||
7556 | * |
||
7557 | * @return void |
||
7558 | */ |
||
7559 | 112 | private function checkType($key, $value) |
|
7577 | } |
||
7578 |
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..