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 | /** |
||
32 | * @var array |
||
33 | * |
||
34 | * @psalm-var array<mixed,mixed>|array<TKey,T> |
||
35 | */ |
||
36 | protected $array = []; |
||
37 | |||
38 | /** |
||
39 | * @var \Arrayy\ArrayyRewindableGenerator|null |
||
40 | * |
||
41 | * @psalm-var \Arrayy\ArrayyRewindableGenerator<TKey,T>|null |
||
42 | */ |
||
43 | protected $generator; |
||
44 | |||
45 | /** |
||
46 | * @var string |
||
47 | * |
||
48 | * @psalm-var class-string<\Arrayy\ArrayyIterator> |
||
49 | */ |
||
50 | protected $iteratorClass = ArrayyIterator::class; |
||
51 | |||
52 | /** |
||
53 | * @var string |
||
54 | */ |
||
55 | protected $pathSeparator = '.'; |
||
56 | |||
57 | /** |
||
58 | * @var bool |
||
59 | */ |
||
60 | protected $checkPropertyTypes = false; |
||
61 | |||
62 | /** |
||
63 | * @var bool |
||
64 | */ |
||
65 | protected $checkForMissingPropertiesInConstructor = false; |
||
66 | |||
67 | /** |
||
68 | * @var bool |
||
69 | */ |
||
70 | protected $checkPropertiesMismatchInConstructor = false; |
||
71 | |||
72 | /** |
||
73 | * @var bool |
||
74 | */ |
||
75 | protected $checkPropertiesMismatch = true; |
||
76 | |||
77 | /** |
||
78 | * @var array<int|string,TypeCheckInterface>|mixed|TypeCheckArray<int|string,TypeCheckInterface>|TypeInterface |
||
79 | */ |
||
80 | protected $properties = []; |
||
81 | |||
82 | /** |
||
83 | * Initializes |
||
84 | * |
||
85 | * @param mixed $data <p> |
||
86 | * Should be an array or a generator, otherwise it will try |
||
87 | * to convert it into an array. |
||
88 | * </p> |
||
89 | * @param string $iteratorClass optional <p> |
||
90 | * You can overwrite the ArrayyIterator, but mostly you don't |
||
91 | * need this option. |
||
92 | * </p> |
||
93 | * @param bool $checkPropertiesInConstructor optional <p> |
||
94 | * You need to extend the "Arrayy"-class and you need to set |
||
95 | * the $checkPropertiesMismatchInConstructor class property |
||
96 | * to |
||
97 | * true, otherwise this option didn't not work anyway. |
||
98 | * </p> |
||
99 | * |
||
100 | * @psalm-param class-string<\Arrayy\ArrayyIterator> $iteratorClass |
||
101 | */ |
||
102 | 1196 | public function __construct( |
|
119 | |||
120 | /** |
||
121 | * @return void |
||
122 | */ |
||
123 | 50 | public function __clone() |
|
133 | |||
134 | /** |
||
135 | * Call object as function. |
||
136 | * |
||
137 | * @param mixed $key |
||
138 | * |
||
139 | * @return mixed |
||
140 | */ |
||
141 | 1 | public function __invoke($key = null) |
|
151 | |||
152 | /** |
||
153 | * Whether or not an element exists by key. |
||
154 | * |
||
155 | * @param mixed $key |
||
156 | * |
||
157 | * @return bool |
||
158 | * <p>True is the key/index exists, otherwise false.</p> |
||
159 | */ |
||
160 | public function __isset($key): bool |
||
164 | |||
165 | /** |
||
166 | * Assigns a value to the specified element. |
||
167 | * |
||
168 | * @param mixed $key |
||
169 | * @param mixed $value |
||
170 | * |
||
171 | * @return void |
||
172 | */ |
||
173 | 3 | public function __set($key, $value) |
|
177 | |||
178 | /** |
||
179 | * magic to string |
||
180 | * |
||
181 | * @return string |
||
182 | */ |
||
183 | 15 | public function __toString(): string |
|
187 | |||
188 | /** |
||
189 | * Unset element by key. |
||
190 | * |
||
191 | * @param mixed $key |
||
192 | */ |
||
193 | public function __unset($key) |
||
197 | |||
198 | /** |
||
199 | * Get a value by key. |
||
200 | * |
||
201 | * @param mixed $key |
||
202 | * |
||
203 | * @return mixed |
||
204 | * <p>Get a Value from the current array.</p> |
||
205 | */ |
||
206 | 8 | public function &__get($key) |
|
216 | |||
217 | /** |
||
218 | * Add new values (optional using dot-notation). |
||
219 | * |
||
220 | * @param mixed $value |
||
221 | * @param int|string|null $key |
||
222 | * |
||
223 | * @return static |
||
224 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
225 | * |
||
226 | * @psalm-param T $value |
||
227 | * @psalm-return static<TKey,T> |
||
228 | */ |
||
229 | 12 | public function add($value, $key = null) |
|
247 | |||
248 | /** |
||
249 | * Append a (key) + value to the current array. |
||
250 | * |
||
251 | * @param mixed $value |
||
252 | * @param mixed $key |
||
253 | * |
||
254 | * @return $this |
||
255 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
256 | * |
||
257 | * @psalm-return static<TKey,T> |
||
258 | */ |
||
259 | 19 | public function append($value, $key = null): self |
|
283 | |||
284 | /** |
||
285 | * Sort the entries by value. |
||
286 | * |
||
287 | * @param int $sort_flags [optional] <p> |
||
288 | * You may modify the behavior of the sort using the optional |
||
289 | * parameter sort_flags, for details |
||
290 | * see sort. |
||
291 | * </p> |
||
292 | * |
||
293 | * @return $this |
||
294 | * <p>(Mutable) Return this Arrayy object.</p> |
||
295 | * |
||
296 | * @psalm-return static<TKey,T> |
||
297 | */ |
||
298 | 4 | public function asort(int $sort_flags = 0): self |
|
306 | |||
307 | /** |
||
308 | * Sort the entries by value. |
||
309 | * |
||
310 | * @param int $sort_flags [optional] <p> |
||
311 | * You may modify the behavior of the sort using the optional |
||
312 | * parameter sort_flags, for details |
||
313 | * see sort. |
||
314 | * </p> |
||
315 | * |
||
316 | * @return $this |
||
317 | * <p>(Immutable) Return this Arrayy object.</p> |
||
318 | * |
||
319 | * @psalm-return static<TKey,T> |
||
320 | * @psalm-mutation-free |
||
321 | */ |
||
322 | 4 | public function asortImmutable(int $sort_flags = 0): self |
|
333 | |||
334 | /** |
||
335 | * Counts all elements in an array, or something in an object. |
||
336 | * |
||
337 | * <p> |
||
338 | * For objects, if you have SPL installed, you can hook into count() by implementing interface {@see Countable}. |
||
339 | * The interface has exactly one method, {@see Countable::count()}, which returns the return value for the count() |
||
340 | * function. Please see the {@see Array} section of the manual for a detailed explanation of how arrays are |
||
341 | * implemented and used in PHP. |
||
342 | * </p> |
||
343 | * |
||
344 | * @see http://php.net/manual/en/function.count.php |
||
345 | * |
||
346 | * @param int $mode [optional] If the optional mode parameter is set to |
||
347 | * COUNT_RECURSIVE (or 1), count |
||
348 | * will recursively count the array. This is particularly useful for |
||
349 | * counting all the elements of a multidimensional array. count does not detect infinite recursion. |
||
350 | * |
||
351 | * @return int |
||
352 | * <p> |
||
353 | * The number of elements in var, which is |
||
354 | * typically an array, since anything else will have one |
||
355 | * element. |
||
356 | * </p> |
||
357 | * <p> |
||
358 | * If var is not an array or an object with |
||
359 | * implemented Countable interface, |
||
360 | * 1 will be returned. |
||
361 | * There is one exception, if var is &null;, |
||
362 | * 0 will be returned. |
||
363 | * </p> |
||
364 | * <p> |
||
365 | * Caution: count may return 0 for a variable that isn't set, |
||
366 | * but it may also return 0 for a variable that has been initialized with an |
||
367 | * empty array. Use isset to test if a variable is set. |
||
368 | * </p> |
||
369 | * @psalm-mutation-free |
||
370 | */ |
||
371 | 147 | public function count(int $mode = \COUNT_NORMAL): int |
|
383 | |||
384 | /** |
||
385 | * Exchange the array for another one. |
||
386 | * |
||
387 | * @param array|static $data |
||
388 | * |
||
389 | * @return array |
||
390 | * |
||
391 | * @psalm-param array<TKey,T>|self<TKey,T> $data |
||
392 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
393 | */ |
||
394 | 1 | public function exchangeArray($data): array |
|
400 | |||
401 | /** |
||
402 | * Creates a copy of the ArrayyObject. |
||
403 | * |
||
404 | * @return array |
||
405 | * |
||
406 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
407 | */ |
||
408 | 6 | public function getArrayCopy(): array |
|
414 | |||
415 | /** |
||
416 | * Returns a new iterator, thus implementing the \Iterator interface. |
||
417 | * |
||
418 | * @return \Iterator<mixed, mixed> |
||
419 | * <p>An iterator for the values in the array.</p> |
||
420 | * @psalm-return \Iterator<array-key|TKey, mixed|T> |
||
421 | */ |
||
422 | 27 | public function getIterator(): \Iterator |
|
439 | |||
440 | /** |
||
441 | * Gets the iterator classname for the ArrayObject. |
||
442 | * |
||
443 | * @return string |
||
444 | * |
||
445 | * @psalm-return class-string |
||
446 | */ |
||
447 | 26 | public function getIteratorClass(): string |
|
451 | |||
452 | /** |
||
453 | * Sort the entries by key. |
||
454 | * |
||
455 | * @param int $sort_flags [optional] <p> |
||
456 | * You may modify the behavior of the sort using the optional |
||
457 | * parameter sort_flags, for details |
||
458 | * see sort. |
||
459 | * </p> |
||
460 | * |
||
461 | * @return $this |
||
462 | * <p>(Mutable) Return this Arrayy object.</p> |
||
463 | * |
||
464 | * @psalm-return static<TKey,T> |
||
465 | */ |
||
466 | 4 | public function ksort(int $sort_flags = 0): self |
|
474 | |||
475 | /** |
||
476 | * Sort the entries by key. |
||
477 | * |
||
478 | * @param int $sort_flags [optional] <p> |
||
479 | * You may modify the behavior of the sort using the optional |
||
480 | * parameter sort_flags, for details |
||
481 | * see sort. |
||
482 | * </p> |
||
483 | * |
||
484 | * @return $this |
||
485 | * <p>(Immutable) Return this Arrayy object.</p> |
||
486 | * |
||
487 | * @psalm-return static<TKey,T> |
||
488 | */ |
||
489 | 4 | public function ksortImmutable(int $sort_flags = 0): self |
|
500 | |||
501 | /** |
||
502 | * Sort an array using a case insensitive "natural order" algorithm. |
||
503 | * |
||
504 | * @return $this |
||
505 | * <p>(Mutable) Return this Arrayy object.</p> |
||
506 | * |
||
507 | * @psalm-return static<TKey,T> |
||
508 | */ |
||
509 | 8 | public function natcasesort(): self |
|
517 | |||
518 | /** |
||
519 | * Sort an array using a case insensitive "natural order" algorithm. |
||
520 | * |
||
521 | * @return $this |
||
522 | * <p>(Immutable) Return this Arrayy object.</p> |
||
523 | * |
||
524 | * @psalm-return static<TKey,T> |
||
525 | * @psalm-mutation-free |
||
526 | */ |
||
527 | 4 | public function natcasesortImmutable(): self |
|
538 | |||
539 | /** |
||
540 | * Sort entries using a "natural order" algorithm. |
||
541 | * |
||
542 | * @return $this |
||
543 | * <p>(Mutable) Return this Arrayy object.</p> |
||
544 | * |
||
545 | * @psalm-return static<TKey,T> |
||
546 | */ |
||
547 | 10 | public function natsort(): self |
|
555 | |||
556 | /** |
||
557 | * Sort entries using a "natural order" algorithm. |
||
558 | * |
||
559 | * @return $this |
||
560 | * <p>(Immutable) Return this Arrayy object.</p> |
||
561 | * |
||
562 | * @psalm-return static<TKey,T> |
||
563 | * @psalm-mutation-free |
||
564 | */ |
||
565 | 4 | public function natsortImmutable(): self |
|
576 | |||
577 | /** |
||
578 | * Whether or not an offset exists. |
||
579 | * |
||
580 | * @param bool|int|string $offset |
||
581 | * |
||
582 | * @return bool |
||
583 | * |
||
584 | * @noinspection PhpSillyAssignmentInspection |
||
585 | * |
||
586 | * @psalm-mutation-free |
||
587 | */ |
||
588 | 157 | public function offsetExists($offset): bool |
|
650 | |||
651 | /** |
||
652 | * Returns the value at specified offset. |
||
653 | * |
||
654 | * @param int|string $offset |
||
655 | * |
||
656 | * @return mixed |
||
657 | * <p>Will return null if the offset did not exists.</p> |
||
658 | */ |
||
659 | 126 | public function offsetGet($offset) |
|
663 | |||
664 | /** |
||
665 | * Assigns a value to the specified offset + check the type. |
||
666 | * |
||
667 | * @param int|string|null $offset |
||
668 | * @param mixed $value |
||
669 | * |
||
670 | * @return void |
||
671 | */ |
||
672 | 26 | public function offsetSet($offset, $value) |
|
690 | |||
691 | /** |
||
692 | * Unset an offset. |
||
693 | * |
||
694 | * @param int|string $offset |
||
695 | * |
||
696 | * @return void |
||
697 | * <p>(Mutable) Return nothing.</p> |
||
698 | */ |
||
699 | 25 | public function offsetUnset($offset) |
|
750 | |||
751 | /** |
||
752 | * Serialize the current "Arrayy"-object. |
||
753 | * |
||
754 | * @return string |
||
755 | */ |
||
756 | 2 | public function serialize(): string |
|
766 | |||
767 | /** |
||
768 | * Sets the iterator classname for the current "Arrayy"-object. |
||
769 | * |
||
770 | * @param string $iteratorClass |
||
771 | * |
||
772 | * @throws \InvalidArgumentException |
||
773 | * |
||
774 | * @return void |
||
775 | * |
||
776 | * @psalm-param class-string<\Arrayy\ArrayyIterator> $iteratorClass |
||
777 | */ |
||
778 | 1187 | public function setIteratorClass($iteratorClass) |
|
800 | |||
801 | /** |
||
802 | * Sort the entries with a user-defined comparison function and maintain key association. |
||
803 | * |
||
804 | * @param callable $function |
||
805 | * |
||
806 | * @throws \InvalidArgumentException |
||
807 | * |
||
808 | * @return $this |
||
809 | * <p>(Mutable) Return this Arrayy object.</p> |
||
810 | * |
||
811 | * @psalm-return static<TKey,T> |
||
812 | */ |
||
813 | 8 | View Code Duplication | public function uasort($function): self |
825 | |||
826 | /** |
||
827 | * Sort the entries with a user-defined comparison function and maintain key association. |
||
828 | * |
||
829 | * @param callable $function |
||
830 | * |
||
831 | * @throws \InvalidArgumentException |
||
832 | * |
||
833 | * @return $this |
||
834 | * <p>(Immutable) Return this Arrayy object.</p> |
||
835 | * |
||
836 | * @psalm-return static<TKey,T> |
||
837 | * @psalm-mutation-free |
||
838 | */ |
||
839 | 4 | public function uasortImmutable($function): self |
|
850 | |||
851 | /** |
||
852 | * Sort the entries by keys using a user-defined comparison function. |
||
853 | * |
||
854 | * @param callable $function |
||
855 | * |
||
856 | * @throws \InvalidArgumentException |
||
857 | * |
||
858 | * @return static |
||
859 | * <p>(Mutable) Return this Arrayy object.</p> |
||
860 | * |
||
861 | * @psalm-return static<TKey,T> |
||
862 | */ |
||
863 | 5 | public function uksort($function): self |
|
867 | |||
868 | /** |
||
869 | * Sort the entries by keys using a user-defined comparison function. |
||
870 | * |
||
871 | * @param callable $function |
||
872 | * |
||
873 | * @throws \InvalidArgumentException |
||
874 | * |
||
875 | * @return static |
||
876 | * <p>(Immutable) Return this Arrayy object.</p> |
||
877 | * |
||
878 | * @psalm-return static<TKey,T> |
||
879 | * @psalm-mutation-free |
||
880 | */ |
||
881 | 1 | public function uksortImmutable($function): self |
|
885 | |||
886 | /** |
||
887 | * Unserialize an string and return the instance of the "Arrayy"-class. |
||
888 | * |
||
889 | * @param string $string |
||
890 | * |
||
891 | * @return $this |
||
892 | * |
||
893 | * @psalm-return static<TKey,T> |
||
894 | */ |
||
895 | 2 | public function unserialize($string): self |
|
905 | |||
906 | /** |
||
907 | * Append a (key) + values to the current array. |
||
908 | * |
||
909 | * @param array $values |
||
910 | * @param mixed $key |
||
911 | * |
||
912 | * @return $this |
||
913 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
914 | * |
||
915 | * @psalm-param array<mixed,T> $values |
||
916 | * @psalm-param TKey|null $key |
||
917 | * @psalm-return static<TKey,T> |
||
918 | */ |
||
919 | 1 | public function appendArrayValues(array $values, $key = null) |
|
945 | |||
946 | /** |
||
947 | * Add a suffix to each key. |
||
948 | * |
||
949 | * @param mixed $prefix |
||
950 | * |
||
951 | * @return static |
||
952 | * <p>(Immutable) Return an Arrayy object, with the prefixed keys.</p> |
||
953 | * |
||
954 | * @psalm-return static<TKey,T> |
||
955 | * @psalm-mutation-free |
||
956 | */ |
||
957 | 10 | View Code Duplication | public function appendToEachKey($prefix): self |
976 | |||
977 | /** |
||
978 | * Add a prefix to each value. |
||
979 | * |
||
980 | * @param mixed $prefix |
||
981 | * |
||
982 | * @return static |
||
983 | * <p>(Immutable) Return an Arrayy object, with the prefixed values.</p> |
||
984 | * |
||
985 | * @psalm-return static<TKey,T> |
||
986 | * @psalm-mutation-free |
||
987 | */ |
||
988 | 10 | View Code Duplication | public function appendToEachValue($prefix): self |
1007 | |||
1008 | /** |
||
1009 | * Sort an array in reverse order and maintain index association. |
||
1010 | * |
||
1011 | * @return $this |
||
1012 | * <p>(Mutable) Return this Arrayy object.</p> |
||
1013 | * |
||
1014 | * @psalm-return static<TKey,T> |
||
1015 | */ |
||
1016 | 4 | public function arsort(): self |
|
1024 | |||
1025 | /** |
||
1026 | * Sort an array in reverse order and maintain index association. |
||
1027 | * |
||
1028 | * @return $this |
||
1029 | * <p>(Immutable) Return this Arrayy object.</p> |
||
1030 | * |
||
1031 | * @psalm-return static<TKey,T> |
||
1032 | * @psalm-mutation-free |
||
1033 | */ |
||
1034 | 10 | public function arsortImmutable(): self |
|
1044 | |||
1045 | /** |
||
1046 | * Iterate over the current array and execute a callback for each loop. |
||
1047 | * |
||
1048 | * @param \Closure $closure |
||
1049 | * |
||
1050 | * @return static |
||
1051 | * <p>(Immutable)</p> |
||
1052 | * |
||
1053 | * @psalm-return static<TKey,T> |
||
1054 | * @psalm-mutation-free |
||
1055 | */ |
||
1056 | 2 | public function at(\Closure $closure): self |
|
1070 | |||
1071 | /** |
||
1072 | * Returns the average value of the current array. |
||
1073 | * |
||
1074 | * @param int $decimals <p>The number of decimal-numbers to return.</p> |
||
1075 | * |
||
1076 | * @return float|int |
||
1077 | * <p>The average value.</p> |
||
1078 | * @psalm-mutation-free |
||
1079 | */ |
||
1080 | 10 | public function average($decimals = 0) |
|
1094 | |||
1095 | /** |
||
1096 | * Changes all keys in an array. |
||
1097 | * |
||
1098 | * @param int $case [optional] <p> Either <strong>CASE_UPPER</strong><br /> |
||
1099 | * or <strong>CASE_LOWER</strong> (default)</p> |
||
1100 | * |
||
1101 | * @return static |
||
1102 | * <p>(Immutable)</p> |
||
1103 | * |
||
1104 | * @psalm-return static<TKey,T> |
||
1105 | * @psalm-mutation-free |
||
1106 | */ |
||
1107 | 1 | public function changeKeyCase(int $case = \CASE_LOWER): self |
|
1136 | |||
1137 | /** |
||
1138 | * Change the path separator of the array wrapper. |
||
1139 | * |
||
1140 | * By default, the separator is: "." |
||
1141 | * |
||
1142 | * @param string $separator <p>Separator to set.</p> |
||
1143 | * |
||
1144 | * @return $this |
||
1145 | * <p>(Mutable) Return this Arrayy object.</p> |
||
1146 | * |
||
1147 | * @psalm-return static<TKey,T> |
||
1148 | */ |
||
1149 | 11 | public function changeSeparator($separator): self |
|
1155 | |||
1156 | /** |
||
1157 | * Create a chunked version of the current array. |
||
1158 | * |
||
1159 | * @param int $size <p>Size of each chunk.</p> |
||
1160 | * @param bool $preserveKeys <p>Whether array keys are preserved or no.</p> |
||
1161 | * |
||
1162 | * @return static |
||
1163 | * <p>(Immutable) A new array of chunks from the original array.</p> |
||
1164 | * |
||
1165 | * @psalm-return static<TKey,T> |
||
1166 | * @psalm-mutation-free |
||
1167 | */ |
||
1168 | 5 | public function chunk($size, $preserveKeys = false): self |
|
1176 | |||
1177 | /** |
||
1178 | * Clean all falsy values from the current array. |
||
1179 | * |
||
1180 | * @return static |
||
1181 | * <p>(Immutable)</p> |
||
1182 | * |
||
1183 | * @psalm-return static<TKey,T> |
||
1184 | * @psalm-mutation-free |
||
1185 | */ |
||
1186 | 8 | public function clean(): self |
|
1194 | |||
1195 | /** |
||
1196 | * WARNING!!! -> Clear the current full array or a $key of it. |
||
1197 | * |
||
1198 | * @param int|int[]|string|string[]|null $key |
||
1199 | * |
||
1200 | * @return $this |
||
1201 | * <p>(Mutable) Return this Arrayy object, with an empty array.</p> |
||
1202 | * |
||
1203 | * @psalm-return static<TKey,T> |
||
1204 | */ |
||
1205 | 10 | public function clear($key = null): self |
|
1224 | |||
1225 | /** |
||
1226 | * Check if an item is in the current array. |
||
1227 | * |
||
1228 | * @param float|int|string $value |
||
1229 | * @param bool $recursive |
||
1230 | * @param bool $strict |
||
1231 | * |
||
1232 | * @return bool |
||
1233 | * @psalm-mutation-free |
||
1234 | */ |
||
1235 | 24 | public function contains($value, bool $recursive = false, bool $strict = true): bool |
|
1236 | { |
||
1237 | 24 | if ($recursive === true) { |
|
1238 | 19 | return $this->in_array_recursive($value, $this->toArray(), $strict); |
|
1239 | } |
||
1240 | |||
1241 | 14 | foreach ($this->getGeneratorByReference() as &$valueFromArray) { |
|
1242 | 11 | if ($strict) { |
|
1243 | 11 | if ($value === $valueFromArray) { |
|
1244 | 11 | return true; |
|
1245 | } |
||
1246 | } else { |
||
1247 | /** @noinspection NestedPositiveIfStatementsInspection */ |
||
1248 | if ($value == $valueFromArray) { |
||
1249 | 7 | return true; |
|
1250 | } |
||
1251 | } |
||
1252 | } |
||
1253 | |||
1254 | 7 | return false; |
|
1255 | } |
||
1256 | |||
1257 | /** |
||
1258 | * Check if an (case-insensitive) string is in the current array. |
||
1259 | * |
||
1260 | * @param mixed $value |
||
1261 | * @param bool $recursive |
||
1262 | * |
||
1263 | * @return bool |
||
1264 | * @psalm-mutation-free |
||
1265 | * |
||
1266 | * @psalm-suppress InvalidCast - hack for int|float|bool support |
||
1267 | */ |
||
1268 | 26 | public function containsCaseInsensitive($value, $recursive = false): bool |
|
1297 | |||
1298 | /** |
||
1299 | * Check if the given key/index exists in the array. |
||
1300 | * |
||
1301 | * @param int|string $key <p>key/index to search for</p> |
||
1302 | * |
||
1303 | * @return bool |
||
1304 | * <p>Returns true if the given key/index exists in the array, false otherwise.</p> |
||
1305 | * |
||
1306 | * @psalm-mutation-free |
||
1307 | */ |
||
1308 | 4 | public function containsKey($key): bool |
|
1312 | |||
1313 | /** |
||
1314 | * Check if all given needles are present in the array as key/index. |
||
1315 | * |
||
1316 | * @param array $needles <p>The keys you are searching for.</p> |
||
1317 | * @param bool $recursive |
||
1318 | * |
||
1319 | * @return bool |
||
1320 | * <p>Returns true if all the given keys/indexes exists in the array, false otherwise.</p> |
||
1321 | * |
||
1322 | * @psalm-param array<mixed,mixed>|array<TKey> $needles |
||
1323 | * @psalm-mutation-free |
||
1324 | */ |
||
1325 | 2 | public function containsKeys(array $needles, $recursive = false): bool |
|
1353 | |||
1354 | /** |
||
1355 | * Check if all given needles are present in the array as key/index. |
||
1356 | * |
||
1357 | * @param array $needles <p>The keys you are searching for.</p> |
||
1358 | * |
||
1359 | * @return bool |
||
1360 | * <p>Returns true if all the given keys/indexes exists in the array, false otherwise.</p> |
||
1361 | * |
||
1362 | * @psalm-param array<mixed,mixed>|array<TKey> $needles |
||
1363 | * @psalm-mutation-free |
||
1364 | */ |
||
1365 | 1 | public function containsKeysRecursive(array $needles): bool |
|
1369 | |||
1370 | /** |
||
1371 | * alias: for "Arrayy->contains()" |
||
1372 | * |
||
1373 | * @param float|int|string $value |
||
1374 | * |
||
1375 | * @return bool |
||
1376 | * |
||
1377 | * @see Arrayy::contains() |
||
1378 | * @psalm-mutation-free |
||
1379 | */ |
||
1380 | 9 | public function containsValue($value): bool |
|
1384 | |||
1385 | /** |
||
1386 | * alias: for "Arrayy->contains($value, true)" |
||
1387 | * |
||
1388 | * @param float|int|string $value |
||
1389 | * |
||
1390 | * @return bool |
||
1391 | * |
||
1392 | * @see Arrayy::contains() |
||
1393 | * @psalm-mutation-free |
||
1394 | */ |
||
1395 | 18 | public function containsValueRecursive($value): bool |
|
1399 | |||
1400 | /** |
||
1401 | * Check if all given needles are present in the array. |
||
1402 | * |
||
1403 | * @param array $needles |
||
1404 | * |
||
1405 | * @return bool |
||
1406 | * <p>Returns true if all the given values exists in the array, false otherwise.</p> |
||
1407 | * |
||
1408 | * @psalm-param array<mixed>|array<T> $needles |
||
1409 | * @psalm-mutation-free |
||
1410 | */ |
||
1411 | 1 | public function containsValues(array $needles): bool |
|
1417 | |||
1418 | /** |
||
1419 | * Counts all the values of an array |
||
1420 | * |
||
1421 | * @see http://php.net/manual/en/function.array-count-values.php |
||
1422 | * |
||
1423 | * @return static |
||
1424 | * <p> |
||
1425 | * (Immutable) |
||
1426 | * An associative Arrayy-object of values from input as |
||
1427 | * keys and their count as value. |
||
1428 | * </p> |
||
1429 | * |
||
1430 | * @psalm-return static<TKey,T> |
||
1431 | * @psalm-mutation-free |
||
1432 | */ |
||
1433 | 7 | public function countValues(): self |
|
1437 | |||
1438 | /** |
||
1439 | * Creates an Arrayy object. |
||
1440 | * |
||
1441 | * @param mixed $data |
||
1442 | * @param string $iteratorClass |
||
1443 | * @param bool $checkPropertiesInConstructor |
||
1444 | * |
||
1445 | * @return static |
||
1446 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1447 | * |
||
1448 | * @psalm-param class-string<\Arrayy\ArrayyIterator> $iteratorClass |
||
1449 | * |
||
1450 | * @psalm-mutation-free |
||
1451 | */ |
||
1452 | 716 | public static function create( |
|
1463 | |||
1464 | /** |
||
1465 | * Flatten an array with the given character as a key delimiter |
||
1466 | * |
||
1467 | * @param string $delimiter |
||
1468 | * @param string $prepend |
||
1469 | * @param array|null $items |
||
1470 | * |
||
1471 | * @return array |
||
1472 | */ |
||
1473 | 2 | public function flatten($delimiter = '.', $prepend = '', $items = null) |
|
1496 | |||
1497 | /** |
||
1498 | * WARNING: Creates an Arrayy object by reference. |
||
1499 | * |
||
1500 | * @param array $array |
||
1501 | * |
||
1502 | * @return $this |
||
1503 | * <p>(Mutable) Return this Arrayy object.</p> |
||
1504 | * |
||
1505 | * @psalm-param array<mixed,mixed>|array<array-key,mixed> $array |
||
1506 | */ |
||
1507 | 2 | public function createByReference(array &$array = []): self |
|
1515 | |||
1516 | /** |
||
1517 | * Create an new instance from a callable function which will return an Generator. |
||
1518 | * |
||
1519 | * @param callable $generatorFunction |
||
1520 | * |
||
1521 | * @return static |
||
1522 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1523 | * |
||
1524 | * @psalm-param callable():\Generator<array-key,mixed> $generatorFunction |
||
1525 | * |
||
1526 | * @psalm-mutation-free |
||
1527 | */ |
||
1528 | 7 | public static function createFromGeneratorFunction(callable $generatorFunction): self |
|
1532 | |||
1533 | /** |
||
1534 | * Create an new instance filled with a copy of values from a "Generator"-object. |
||
1535 | * |
||
1536 | * @param \Generator $generator |
||
1537 | * |
||
1538 | * @return static |
||
1539 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1540 | * |
||
1541 | * @psalm-param \Generator<array-key,mixed> $generator |
||
1542 | * |
||
1543 | * @psalm-mutation-free |
||
1544 | */ |
||
1545 | 4 | public static function createFromGeneratorImmutable(\Generator $generator): self |
|
1549 | |||
1550 | /** |
||
1551 | * Create an new Arrayy object via JSON. |
||
1552 | * |
||
1553 | * @param string $json |
||
1554 | * |
||
1555 | * @return static |
||
1556 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1557 | * |
||
1558 | * @psalm-mutation-free |
||
1559 | */ |
||
1560 | 5 | public static function createFromJson(string $json): self |
|
1564 | |||
1565 | /** |
||
1566 | * Create an new Arrayy object via JSON. |
||
1567 | * |
||
1568 | * @param array $array |
||
1569 | * |
||
1570 | * @return static |
||
1571 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1572 | * |
||
1573 | * @psalm-mutation-free |
||
1574 | */ |
||
1575 | 1 | public static function createFromArray(array $array): self |
|
1579 | |||
1580 | /** |
||
1581 | * Create an new instance filled with values from an object that is iterable. |
||
1582 | * |
||
1583 | * @param \Traversable $object <p>iterable object</p> |
||
1584 | * |
||
1585 | * @return static |
||
1586 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1587 | * |
||
1588 | * @psalm-param \Traversable<array-key,mixed> $object |
||
1589 | * |
||
1590 | * @psalm-mutation-free |
||
1591 | */ |
||
1592 | 4 | public static function createFromObject(\Traversable $object): self |
|
1612 | |||
1613 | /** |
||
1614 | * Create an new instance filled with values from an object. |
||
1615 | * |
||
1616 | * @param object $object |
||
1617 | * |
||
1618 | * @return static |
||
1619 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1620 | * |
||
1621 | * @psalm-mutation-free |
||
1622 | */ |
||
1623 | 5 | public static function createFromObjectVars($object): self |
|
1627 | |||
1628 | /** |
||
1629 | * Create an new Arrayy object via string. |
||
1630 | * |
||
1631 | * @param string $str <p>The input string.</p> |
||
1632 | * @param string|null $delimiter <p>The boundary string.</p> |
||
1633 | * @param string|null $regEx <p>Use the $delimiter or the $regEx, so if $pattern is null, $delimiter will be |
||
1634 | * used.</p> |
||
1635 | * |
||
1636 | * @return static |
||
1637 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1638 | * |
||
1639 | * @psalm-mutation-free |
||
1640 | */ |
||
1641 | 10 | public static function createFromString(string $str, string $delimiter = null, string $regEx = null): self |
|
1673 | |||
1674 | /** |
||
1675 | * Create an new instance filled with a copy of values from a "Traversable"-object. |
||
1676 | * |
||
1677 | * @param \Traversable $traversable |
||
1678 | * |
||
1679 | * @return static |
||
1680 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1681 | * |
||
1682 | * @psalm-param \Traversable<array-key,mixed> $traversable |
||
1683 | * |
||
1684 | * @psalm-mutation-free |
||
1685 | */ |
||
1686 | 1 | public static function createFromTraversableImmutable(\Traversable $traversable): self |
|
1690 | |||
1691 | /** |
||
1692 | * Create an new instance containing a range of elements. |
||
1693 | * |
||
1694 | * @param float|int|string $low <p>First value of the sequence.</p> |
||
1695 | * @param float|int|string $high <p>The sequence is ended upon reaching the end value.</p> |
||
1696 | * @param float|int $step <p>Used as the increment between elements in the sequence.</p> |
||
1697 | * |
||
1698 | * @return static |
||
1699 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1700 | * |
||
1701 | * @psalm-mutation-free |
||
1702 | */ |
||
1703 | 2 | public static function createWithRange($low, $high, $step = 1): self |
|
1707 | |||
1708 | /** |
||
1709 | * Gets the element of the array at the current internal iterator position. |
||
1710 | * |
||
1711 | * @return false|mixed |
||
1712 | */ |
||
1713 | public function current() |
||
1717 | |||
1718 | /** |
||
1719 | * Custom sort by index via "uksort". |
||
1720 | * |
||
1721 | * @see http://php.net/manual/en/function.uksort.php |
||
1722 | * |
||
1723 | * @param callable $function |
||
1724 | * |
||
1725 | * @throws \InvalidArgumentException |
||
1726 | * |
||
1727 | * @return $this |
||
1728 | * <p>(Mutable) Return this Arrayy object.</p> |
||
1729 | * |
||
1730 | * @psalm-return static<TKey,T> |
||
1731 | */ |
||
1732 | 5 | public function customSortKeys(callable $function): self |
|
1740 | |||
1741 | /** |
||
1742 | * Custom sort by index via "uksort". |
||
1743 | * |
||
1744 | * @see http://php.net/manual/en/function.uksort.php |
||
1745 | * |
||
1746 | * @param callable $function |
||
1747 | * |
||
1748 | * @throws \InvalidArgumentException |
||
1749 | * |
||
1750 | * @return $this |
||
1751 | * <p>(Immutable) Return this Arrayy object.</p> |
||
1752 | * |
||
1753 | * @psalm-return static<TKey,T> |
||
1754 | * @psalm-mutation-free |
||
1755 | */ |
||
1756 | 1 | public function customSortKeysImmutable(callable $function): self |
|
1769 | |||
1770 | /** |
||
1771 | * Custom sort by value via "usort". |
||
1772 | * |
||
1773 | * @see http://php.net/manual/en/function.usort.php |
||
1774 | * |
||
1775 | * @param callable $function |
||
1776 | * |
||
1777 | * @throws \InvalidArgumentException |
||
1778 | * |
||
1779 | * @return $this |
||
1780 | * <p>(Mutable) Return this Arrayy object.</p> |
||
1781 | * |
||
1782 | * @psalm-return static<TKey,T> |
||
1783 | */ |
||
1784 | 10 | View Code Duplication | public function customSortValues($function): self |
1796 | |||
1797 | /** |
||
1798 | * Custom sort by value via "usort". |
||
1799 | * |
||
1800 | * @see http://php.net/manual/en/function.usort.php |
||
1801 | * |
||
1802 | * @param callable $function |
||
1803 | * |
||
1804 | * @throws \InvalidArgumentException |
||
1805 | * |
||
1806 | * @return $this |
||
1807 | * <p>(Immutable) Return this Arrayy object.</p> |
||
1808 | * |
||
1809 | * @psalm-return static<TKey,T> |
||
1810 | * @psalm-mutation-free |
||
1811 | */ |
||
1812 | 4 | public function customSortValuesImmutable($function): self |
|
1823 | |||
1824 | /** |
||
1825 | * Delete the given key or keys. |
||
1826 | * |
||
1827 | * @param int|int[]|string|string[] $keyOrKeys |
||
1828 | * |
||
1829 | * @return void |
||
1830 | */ |
||
1831 | 9 | public function delete($keyOrKeys) |
|
1839 | |||
1840 | /** |
||
1841 | * Return values that are only in the current array. |
||
1842 | * |
||
1843 | * @param array ...$array |
||
1844 | * |
||
1845 | * @return static |
||
1846 | * <p>(Immutable)</p> |
||
1847 | * |
||
1848 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$array |
||
1849 | * @psalm-return static<TKey,T> |
||
1850 | * @psalm-mutation-free |
||
1851 | */ |
||
1852 | 13 | public function diff(...$array): self |
|
1860 | |||
1861 | /** |
||
1862 | * Return values that are only in the current array. |
||
1863 | * |
||
1864 | * @param array ...$array |
||
1865 | * |
||
1866 | * @return static |
||
1867 | * <p>(Immutable)</p> |
||
1868 | * |
||
1869 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$array |
||
1870 | * @psalm-return static<TKey,T> |
||
1871 | * @psalm-mutation-free |
||
1872 | */ |
||
1873 | 8 | public function diffKey(...$array): self |
|
1881 | |||
1882 | /** |
||
1883 | * Return values and Keys that are only in the current array. |
||
1884 | * |
||
1885 | * @param array $array |
||
1886 | * |
||
1887 | * @return static |
||
1888 | * <p>(Immutable)</p> |
||
1889 | * |
||
1890 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
1891 | * @psalm-return static<TKey,T> |
||
1892 | * @psalm-mutation-free |
||
1893 | */ |
||
1894 | 8 | public function diffKeyAndValue(array $array = []): self |
|
1902 | |||
1903 | /** |
||
1904 | * Return values that are only in the current multi-dimensional array. |
||
1905 | * |
||
1906 | * @param array $array |
||
1907 | * @param array|\Generator|null $helperVariableForRecursion <p>(only for internal usage)</p> |
||
1908 | * |
||
1909 | * @return static |
||
1910 | * <p>(Immutable)</p> |
||
1911 | * |
||
1912 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
1913 | * @psalm-param null|array<TKey,T>|\Generator<TKey,T> $helperVariableForRecursion |
||
1914 | * @psalm-return static<TKey,T> |
||
1915 | * @psalm-mutation-free |
||
1916 | */ |
||
1917 | 1 | public function diffRecursive(array $array = [], $helperVariableForRecursion = null): self |
|
1952 | |||
1953 | /** |
||
1954 | * Return values that are only in the new $array. |
||
1955 | * |
||
1956 | * @param array $array |
||
1957 | * |
||
1958 | * @return static |
||
1959 | * <p>(Immutable)</p> |
||
1960 | * |
||
1961 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
1962 | * @psalm-return static<TKey,T> |
||
1963 | * @psalm-mutation-free |
||
1964 | */ |
||
1965 | 8 | public function diffReverse(array $array = []): self |
|
1973 | |||
1974 | /** |
||
1975 | * Divide an array into two arrays. One with keys and the other with values. |
||
1976 | * |
||
1977 | * @return static |
||
1978 | * <p>(Immutable)</p> |
||
1979 | * |
||
1980 | * @psalm-return static<TKey,T> |
||
1981 | * @psalm-mutation-free |
||
1982 | */ |
||
1983 | 1 | public function divide(): self |
|
1994 | |||
1995 | /** |
||
1996 | * Iterate over the current array and modify the array's value. |
||
1997 | * |
||
1998 | * @param \Closure $closure |
||
1999 | * |
||
2000 | * @return static |
||
2001 | * <p>(Immutable)</p> |
||
2002 | * |
||
2003 | * @psalm-return static<TKey,T> |
||
2004 | * @psalm-mutation-free |
||
2005 | */ |
||
2006 | 5 | View Code Duplication | public function each(\Closure $closure): self |
2021 | |||
2022 | /** |
||
2023 | * Sets the internal iterator to the last element in the array and returns this element. |
||
2024 | * |
||
2025 | * @return mixed |
||
2026 | */ |
||
2027 | public function end() |
||
2031 | |||
2032 | /** |
||
2033 | * Check if a value is in the current array using a closure. |
||
2034 | * |
||
2035 | * @param \Closure $closure |
||
2036 | * |
||
2037 | * @return bool |
||
2038 | * <p>Returns true if the given value is found, false otherwise.</p> |
||
2039 | */ |
||
2040 | 4 | public function exists(\Closure $closure): bool |
|
2055 | |||
2056 | /** |
||
2057 | * Fill the array until "$num" with "$default" values. |
||
2058 | * |
||
2059 | * @param int $num |
||
2060 | * @param mixed $default |
||
2061 | * |
||
2062 | * @return static |
||
2063 | * <p>(Immutable)</p> |
||
2064 | * |
||
2065 | * @psalm-return static<TKey,T> |
||
2066 | * @psalm-mutation-free |
||
2067 | */ |
||
2068 | 8 | public function fillWithDefaults(int $num, $default = null): self |
|
2091 | |||
2092 | /** |
||
2093 | * Find all items in an array that pass the truth test. |
||
2094 | * |
||
2095 | * @param \Closure|null $closure [optional] <p> |
||
2096 | * The callback function to use |
||
2097 | * </p> |
||
2098 | * <p> |
||
2099 | * If no callback is supplied, all entries of |
||
2100 | * input equal to false (see |
||
2101 | * converting to |
||
2102 | * boolean) will be removed. |
||
2103 | * </p> |
||
2104 | * @param int $flag [optional] <p> |
||
2105 | * Flag determining what arguments are sent to <i>callback</i>: |
||
2106 | * </p><ul> |
||
2107 | * <li> |
||
2108 | * <b>ARRAY_FILTER_USE_KEY</b> [1] - pass key as the only argument |
||
2109 | * to <i>callback</i> instead of the value</span> |
||
2110 | * </li> |
||
2111 | * <li> |
||
2112 | * <b>ARRAY_FILTER_USE_BOTH</b> [2] - pass both value and key as |
||
2113 | * arguments to <i>callback</i> instead of the value</span> |
||
2114 | * </li> |
||
2115 | * </ul> |
||
2116 | * |
||
2117 | * @return static |
||
2118 | * <p>(Immutable)</p> |
||
2119 | * |
||
2120 | * @psalm-param \Closure(T=,TKey=):bool|\Closure(T=):bool $closure |
||
2121 | * @psalm-return static<TKey,T> |
||
2122 | * @psalm-mutation-free |
||
2123 | */ |
||
2124 | 12 | public function filter($closure = null, int $flag = \ARRAY_FILTER_USE_BOTH) |
|
2136 | |||
2137 | /** |
||
2138 | * Filters an array of objects (or a numeric array of associative arrays) based on the value of a particular |
||
2139 | * property within that. |
||
2140 | * |
||
2141 | * @param string $property |
||
2142 | * @param string|string[] $value |
||
2143 | * @param string $comparisonOp |
||
2144 | * <p> |
||
2145 | * 'eq' (equals),<br /> |
||
2146 | * 'gt' (greater),<br /> |
||
2147 | * 'gte' || 'ge' (greater or equals),<br /> |
||
2148 | * 'lt' (less),<br /> |
||
2149 | * 'lte' || 'le' (less or equals),<br /> |
||
2150 | * 'ne' (not equals),<br /> |
||
2151 | * 'contains',<br /> |
||
2152 | * 'notContains',<br /> |
||
2153 | * 'newer' (via strtotime),<br /> |
||
2154 | * 'older' (via strtotime),<br /> |
||
2155 | * </p> |
||
2156 | * |
||
2157 | * @return static |
||
2158 | * <p>(Immutable)</p> |
||
2159 | * |
||
2160 | * @psalm-return static<TKey,T> |
||
2161 | * @psalm-mutation-free |
||
2162 | * |
||
2163 | * @psalm-suppress MissingClosureReturnType |
||
2164 | * @psalm-suppress MissingClosureParamType |
||
2165 | */ |
||
2166 | 1 | public function filterBy( |
|
2238 | |||
2239 | /** |
||
2240 | * Find the first item in an array that passes the truth test, |
||
2241 | * otherwise return false |
||
2242 | * |
||
2243 | * @param \Closure $closure |
||
2244 | * |
||
2245 | * @return false|mixed |
||
2246 | * <p>Return false if we did not find the value.</p> |
||
2247 | */ |
||
2248 | 8 | View Code Duplication | public function find(\Closure $closure) |
2258 | |||
2259 | /** |
||
2260 | * find by ... |
||
2261 | * |
||
2262 | * @param string $property |
||
2263 | * @param string|string[] $value |
||
2264 | * @param string $comparisonOp |
||
2265 | * |
||
2266 | * @return static |
||
2267 | * <p>(Immutable)</p> |
||
2268 | * |
||
2269 | * @psalm-return static<TKey,T> |
||
2270 | * @psalm-mutation-free |
||
2271 | */ |
||
2272 | 1 | public function findBy(string $property, $value, string $comparisonOp = 'eq'): self |
|
2276 | |||
2277 | /** |
||
2278 | * Get the first value from the current array. |
||
2279 | * |
||
2280 | * @return mixed |
||
2281 | * <p>Return null if there wasn't a element.</p> |
||
2282 | */ |
||
2283 | 23 | public function first() |
|
2292 | |||
2293 | /** |
||
2294 | * Get the first key from the current array. |
||
2295 | * |
||
2296 | * @return mixed |
||
2297 | * <p>Return null if there wasn't a element.</p> |
||
2298 | * @psalm-mutation-free |
||
2299 | */ |
||
2300 | 30 | public function firstKey() |
|
2306 | |||
2307 | /** |
||
2308 | * Get the first value(s) from the current array. |
||
2309 | * And will return an empty array if there was no first entry. |
||
2310 | * |
||
2311 | * @param int|null $number <p>How many values you will take?</p> |
||
2312 | * |
||
2313 | * @return static |
||
2314 | * <p>(Immutable)</p> |
||
2315 | * |
||
2316 | * @psalm-return static<TKey,T> |
||
2317 | * @psalm-mutation-free |
||
2318 | */ |
||
2319 | 37 | View Code Duplication | public function firstsImmutable(int $number = null): self |
2336 | |||
2337 | /** |
||
2338 | * Get the first value(s) from the current array. |
||
2339 | * And will return an empty array if there was no first entry. |
||
2340 | * |
||
2341 | * @param int|null $number <p>How many values you will take?</p> |
||
2342 | * |
||
2343 | * @return static |
||
2344 | * <p>(Immutable)</p> |
||
2345 | * |
||
2346 | * @psalm-return static<TKey,T> |
||
2347 | * @psalm-mutation-free |
||
2348 | */ |
||
2349 | 3 | View Code Duplication | public function firstsKeys(int $number = null): self |
2366 | |||
2367 | /** |
||
2368 | * Get and rmove the first value(s) from the current array. |
||
2369 | * And will return an empty array if there was no first entry. |
||
2370 | * |
||
2371 | * @param int|null $number <p>How many values you will take?</p> |
||
2372 | * |
||
2373 | * @return $this |
||
2374 | * <p>(Mutable)</p> |
||
2375 | * |
||
2376 | * @psalm-return static<TKey,T> |
||
2377 | */ |
||
2378 | 34 | public function firstsMutable(int $number = null): self |
|
2391 | |||
2392 | /** |
||
2393 | * Exchanges all keys with their associated values in an array. |
||
2394 | * |
||
2395 | * @return static |
||
2396 | * <p>(Immutable)</p> |
||
2397 | * |
||
2398 | * @psalm-return static<TKey,T> |
||
2399 | * @psalm-mutation-free |
||
2400 | */ |
||
2401 | 1 | public function flip(): self |
|
2409 | |||
2410 | /** |
||
2411 | * Get a value from an array (optional using dot-notation). |
||
2412 | * |
||
2413 | * @param mixed $key <p>The key to look for.</p> |
||
2414 | * @param mixed $fallback <p>Value to fallback to.</p> |
||
2415 | * @param array $array <p>The array to get from, if it's set to "null" we use the current array from the |
||
2416 | * class.</p> |
||
2417 | * |
||
2418 | * @return mixed|static |
||
2419 | * |
||
2420 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
2421 | * @psalm-mutation-free |
||
2422 | */ |
||
2423 | 240 | public function get($key, $fallback = null, array $array = null) |
|
2515 | |||
2516 | /** |
||
2517 | * alias: for "Arrayy->toArray()" |
||
2518 | * |
||
2519 | * @return array |
||
2520 | * |
||
2521 | * @see Arrayy::getArray() |
||
2522 | * |
||
2523 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
2524 | */ |
||
2525 | 14 | public function getAll(): array |
|
2529 | |||
2530 | /** |
||
2531 | * Get the current array from the "Arrayy"-object. |
||
2532 | * |
||
2533 | * alias for "toArray()" |
||
2534 | * |
||
2535 | * @param bool $convertAllArrayyElements <p> |
||
2536 | * Convert all Child-"Arrayy" objects also to arrays. |
||
2537 | * </p> |
||
2538 | * @param bool $preserveKeys <p> |
||
2539 | * e.g.: A generator maybe return the same key more then once, |
||
2540 | * so maybe you will ignore the keys. |
||
2541 | * </p> |
||
2542 | * |
||
2543 | * @return array |
||
2544 | * |
||
2545 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
2546 | * @psalm-mutation-free |
||
2547 | * |
||
2548 | * @see Arrayy::toArray() |
||
2549 | */ |
||
2550 | 498 | public function getArray( |
|
2559 | |||
2560 | /** |
||
2561 | * @param string $json |
||
2562 | * |
||
2563 | * @return $this |
||
2564 | */ |
||
2565 | 3 | public static function createFromJsonMapper(string $json) |
|
2581 | |||
2582 | /** |
||
2583 | * @return array<int|string,TypeCheckInterface>|mixed|TypeCheckArray<int|string,TypeCheckInterface>|TypeInterface |
||
2584 | * |
||
2585 | * @internal |
||
2586 | */ |
||
2587 | 6 | public function getPhpDocPropertiesFromClass() |
|
2595 | |||
2596 | /** |
||
2597 | * Get the current array from the "Arrayy"-object as list. |
||
2598 | * |
||
2599 | * alias for "toList()" |
||
2600 | * |
||
2601 | * @param bool $convertAllArrayyElements <p> |
||
2602 | * Convert all Child-"Arrayy" objects also to arrays. |
||
2603 | * </p> |
||
2604 | * |
||
2605 | * @return array |
||
2606 | * |
||
2607 | * @psalm-return array<int,mixed>|array<int,T> |
||
2608 | * @psalm-mutation-free |
||
2609 | * |
||
2610 | * @see Arrayy::toList() |
||
2611 | */ |
||
2612 | 1 | public function getList(bool $convertAllArrayyElements = false): array |
|
2616 | |||
2617 | /** |
||
2618 | * Returns the values from a single column of the input array, identified by |
||
2619 | * the $columnKey, can be used to extract data-columns from multi-arrays. |
||
2620 | * |
||
2621 | * Info: Optionally, you may provide an $indexKey to index the values in the returned |
||
2622 | * array by the values from the $indexKey column in the input array. |
||
2623 | * |
||
2624 | * @param mixed $columnKey |
||
2625 | * @param mixed $indexKey |
||
2626 | * |
||
2627 | * @return static |
||
2628 | * <p>(Immutable)</p> |
||
2629 | * |
||
2630 | * @psalm-return static<TKey,T> |
||
2631 | * @psalm-mutation-free |
||
2632 | */ |
||
2633 | 1 | public function getColumn($columnKey = null, $indexKey = null): self |
|
2641 | |||
2642 | /** |
||
2643 | * Get the current array from the "Arrayy"-object as generator by reference. |
||
2644 | * |
||
2645 | * @return \Generator |
||
2646 | * |
||
2647 | * @psalm-return \Generator<mixed,T>|\Generator<TKey,T> |
||
2648 | */ |
||
2649 | 75 | public function &getGeneratorByReference(): \Generator |
|
2667 | |||
2668 | /** |
||
2669 | * Get the current array from the "Arrayy"-object as generator. |
||
2670 | * |
||
2671 | * @return \Generator |
||
2672 | * |
||
2673 | * @psalm-return \Generator<mixed,T>|\Generator<TKey,T> |
||
2674 | * @psalm-mutation-free |
||
2675 | */ |
||
2676 | 994 | public function getGenerator(): \Generator |
|
2686 | |||
2687 | /** |
||
2688 | * alias: for "Arrayy->keys()" |
||
2689 | * |
||
2690 | * @return static |
||
2691 | * <p>(Immutable)</p> |
||
2692 | * |
||
2693 | * @see Arrayy::keys() |
||
2694 | * |
||
2695 | * @psalm-return static<array-key,TKey> |
||
2696 | * @psalm-mutation-free |
||
2697 | */ |
||
2698 | 2 | public function getKeys() |
|
2702 | |||
2703 | /** |
||
2704 | * Get the current array from the "Arrayy"-object as object. |
||
2705 | * |
||
2706 | * @return \stdClass |
||
2707 | */ |
||
2708 | 4 | public function getObject(): \stdClass |
|
2712 | |||
2713 | /** |
||
2714 | * alias: for "Arrayy->randomImmutable()" |
||
2715 | * |
||
2716 | * @return static |
||
2717 | * <p>(Immutable)</p> |
||
2718 | * |
||
2719 | * @see Arrayy::randomImmutable() |
||
2720 | * |
||
2721 | * @psalm-return static<int|array-key,T> |
||
2722 | */ |
||
2723 | 4 | public function getRandom(): self |
|
2727 | |||
2728 | /** |
||
2729 | * alias: for "Arrayy->randomKey()" |
||
2730 | * |
||
2731 | * @return mixed |
||
2732 | * <p>Get a key/index or null if there wasn't a key/index.</p> |
||
2733 | * |
||
2734 | * @see Arrayy::randomKey() |
||
2735 | */ |
||
2736 | 3 | public function getRandomKey() |
|
2740 | |||
2741 | /** |
||
2742 | * alias: for "Arrayy->randomKeys()" |
||
2743 | * |
||
2744 | * @param int $number |
||
2745 | * |
||
2746 | * @return static |
||
2747 | * <p>(Immutable)</p> |
||
2748 | * |
||
2749 | * @see Arrayy::randomKeys() |
||
2750 | * |
||
2751 | * @psalm-return static<TKey,T> |
||
2752 | */ |
||
2753 | 8 | public function getRandomKeys(int $number): self |
|
2757 | |||
2758 | /** |
||
2759 | * alias: for "Arrayy->randomValue()" |
||
2760 | * |
||
2761 | * @return mixed |
||
2762 | * <p>Get a random value or null if there wasn't a value.</p> |
||
2763 | * |
||
2764 | * @see Arrayy::randomValue() |
||
2765 | */ |
||
2766 | 3 | public function getRandomValue() |
|
2770 | |||
2771 | /** |
||
2772 | * alias: for "Arrayy->randomValues()" |
||
2773 | * |
||
2774 | * @param int $number |
||
2775 | * |
||
2776 | * @return static |
||
2777 | * <p>(Immutable)</p> |
||
2778 | * |
||
2779 | * @see Arrayy::randomValues() |
||
2780 | * |
||
2781 | * @psalm-return static<TKey,T> |
||
2782 | */ |
||
2783 | 6 | public function getRandomValues(int $number): self |
|
2787 | |||
2788 | /** |
||
2789 | * Gets all values. |
||
2790 | * |
||
2791 | * @return static |
||
2792 | * <p>The values of all elements in this array, in the order they |
||
2793 | * appear in the array.</p> |
||
2794 | * |
||
2795 | * @psalm-return static<TKey,T> |
||
2796 | */ |
||
2797 | 4 | public function getValues() |
|
2807 | |||
2808 | /** |
||
2809 | * Gets all values via Generator. |
||
2810 | * |
||
2811 | * @return \Generator |
||
2812 | * <p>The values of all elements in this array, in the order they |
||
2813 | * appear in the array as Generator.</p> |
||
2814 | * |
||
2815 | * @psalm-return \Generator<TKey,T> |
||
2816 | */ |
||
2817 | 4 | public function getValuesYield(): \Generator |
|
2821 | |||
2822 | /** |
||
2823 | * Group values from a array according to the results of a closure. |
||
2824 | * |
||
2825 | * @param callable|string $grouper <p>A callable function name.</p> |
||
2826 | * @param bool $saveKeys |
||
2827 | * |
||
2828 | * @return static |
||
2829 | * <p>(Immutable)</p> |
||
2830 | * |
||
2831 | * @psalm-return static<TKey,T> |
||
2832 | * @psalm-mutation-free |
||
2833 | */ |
||
2834 | 4 | public function group($grouper, bool $saveKeys = false): self |
|
2875 | |||
2876 | /** |
||
2877 | * Check if an array has a given key. |
||
2878 | * |
||
2879 | * @param mixed $key |
||
2880 | * |
||
2881 | * @return bool |
||
2882 | */ |
||
2883 | 30 | public function has($key): bool |
|
2909 | |||
2910 | /** |
||
2911 | * Check if an array has a given value. |
||
2912 | * |
||
2913 | * INFO: if you need to search recursive please use ```contains()``` |
||
2914 | * |
||
2915 | * @param mixed $value |
||
2916 | * |
||
2917 | * @return bool |
||
2918 | */ |
||
2919 | 1 | public function hasValue($value): bool |
|
2923 | |||
2924 | /** |
||
2925 | * Implodes the values of this array. |
||
2926 | * |
||
2927 | * @param string $glue |
||
2928 | * |
||
2929 | * @return string |
||
2930 | * @psalm-mutation-free |
||
2931 | */ |
||
2932 | 28 | public function implode(string $glue = ''): string |
|
2936 | |||
2937 | /** |
||
2938 | * Implodes the keys of this array. |
||
2939 | * |
||
2940 | * @param string $glue |
||
2941 | * |
||
2942 | * @return string |
||
2943 | * @psalm-mutation-free |
||
2944 | */ |
||
2945 | 8 | public function implodeKeys(string $glue = ''): string |
|
2949 | |||
2950 | /** |
||
2951 | * Given a list and an iterate-function that returns |
||
2952 | * a key for each element in the list (or a property name), |
||
2953 | * returns an object with an index of each item. |
||
2954 | * |
||
2955 | * @param mixed $key |
||
2956 | * |
||
2957 | * @return static |
||
2958 | * <p>(Immutable)</p> |
||
2959 | * |
||
2960 | * @psalm-return static<TKey,T> |
||
2961 | * @psalm-mutation-free |
||
2962 | */ |
||
2963 | 4 | public function indexBy($key): self |
|
2980 | |||
2981 | /** |
||
2982 | * alias: for "Arrayy->searchIndex()" |
||
2983 | * |
||
2984 | * @param mixed $value <p>The value to search for.</p> |
||
2985 | * |
||
2986 | * @return false|mixed |
||
2987 | * |
||
2988 | * @see Arrayy::searchIndex() |
||
2989 | */ |
||
2990 | 4 | public function indexOf($value) |
|
2994 | |||
2995 | /** |
||
2996 | * Get everything but the last..$to items. |
||
2997 | * |
||
2998 | * @param int $to |
||
2999 | * |
||
3000 | * @return static |
||
3001 | * <p>(Immutable)</p> |
||
3002 | * |
||
3003 | * @psalm-return static<TKey,T> |
||
3004 | * @psalm-mutation-free |
||
3005 | */ |
||
3006 | 12 | public function initial(int $to = 1): self |
|
3010 | |||
3011 | /** |
||
3012 | * Return an array with all elements found in input array. |
||
3013 | * |
||
3014 | * @param array $search |
||
3015 | * @param bool $keepKeys |
||
3016 | * |
||
3017 | * @return static |
||
3018 | * <p>(Immutable)</p> |
||
3019 | * |
||
3020 | * @psalm-param array<mixed,mixed>|array<TKey,T> $search |
||
3021 | * @psalm-return static<TKey,T> |
||
3022 | * @psalm-mutation-free |
||
3023 | */ |
||
3024 | 4 | public function intersection(array $search, bool $keepKeys = false): self |
|
3050 | |||
3051 | /** |
||
3052 | * Return an array with all elements found in input array. |
||
3053 | * |
||
3054 | * @param array ...$array |
||
3055 | * |
||
3056 | * @return static |
||
3057 | * <p>(Immutable)</p> |
||
3058 | * |
||
3059 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$array |
||
3060 | * @psalm-return static<TKey,T> |
||
3061 | * @psalm-mutation-free |
||
3062 | */ |
||
3063 | 1 | public function intersectionMulti(...$array): self |
|
3071 | |||
3072 | /** |
||
3073 | * Return a boolean flag which indicates whether the two input arrays have any common elements. |
||
3074 | * |
||
3075 | * @param array $search |
||
3076 | * |
||
3077 | * @return bool |
||
3078 | * |
||
3079 | * @psalm-param array<mixed,mixed>|array<TKey,T> $search |
||
3080 | */ |
||
3081 | 1 | public function intersects(array $search): bool |
|
3085 | |||
3086 | /** |
||
3087 | * Invoke a function on all of an array's values. |
||
3088 | * |
||
3089 | * @param callable $callable |
||
3090 | * @param mixed $arguments |
||
3091 | * |
||
3092 | * @return static |
||
3093 | * <p>(Immutable)</p> |
||
3094 | * |
||
3095 | * @psalm-param callable(T=,mixed):mixed $callable |
||
3096 | * @psalm-return static<TKey,T> |
||
3097 | * @psalm-mutation-free |
||
3098 | */ |
||
3099 | 1 | View Code Duplication | public function invoke($callable, $arguments = []): self |
3123 | |||
3124 | /** |
||
3125 | * Check whether array is associative or not. |
||
3126 | * |
||
3127 | * @param bool $recursive |
||
3128 | * |
||
3129 | * @return bool |
||
3130 | * <p>Returns true if associative, false otherwise.</p> |
||
3131 | */ |
||
3132 | 15 | View Code Duplication | public function isAssoc(bool $recursive = false): bool |
3146 | |||
3147 | /** |
||
3148 | * Check if a given key or keys are empty. |
||
3149 | * |
||
3150 | * @param int|int[]|string|string[]|null $keys |
||
3151 | * |
||
3152 | * @return bool |
||
3153 | * <p>Returns true if empty, false otherwise.</p> |
||
3154 | * @psalm-mutation-free |
||
3155 | */ |
||
3156 | 45 | public function isEmpty($keys = null): bool |
|
3174 | |||
3175 | /** |
||
3176 | * Check if the current array is equal to the given "$array" or not. |
||
3177 | * |
||
3178 | * @param array $array |
||
3179 | * |
||
3180 | * @return bool |
||
3181 | * |
||
3182 | * @psalm-param array<mixed,mixed> $array |
||
3183 | */ |
||
3184 | 1 | public function isEqual(array $array): bool |
|
3188 | |||
3189 | /** |
||
3190 | * Check if the current array is a multi-array. |
||
3191 | * |
||
3192 | * @return bool |
||
3193 | */ |
||
3194 | 22 | public function isMultiArray(): bool |
|
3202 | |||
3203 | /** |
||
3204 | * Check whether array is numeric or not. |
||
3205 | * |
||
3206 | * @return bool |
||
3207 | * <p>Returns true if numeric, false otherwise.</p> |
||
3208 | */ |
||
3209 | 5 | View Code Duplication | public function isNumeric(): bool |
3223 | |||
3224 | /** |
||
3225 | * Check if the current array is sequential [0, 1, 2, 3, 4, 5 ...] or not. |
||
3226 | * |
||
3227 | * @param bool $recursive |
||
3228 | * |
||
3229 | * @return bool |
||
3230 | * @psalm-mutation-free |
||
3231 | */ |
||
3232 | 9 | public function isSequential(bool $recursive = false): bool |
|
3249 | |||
3250 | /** |
||
3251 | * @return array |
||
3252 | * |
||
3253 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
3254 | */ |
||
3255 | 2 | public function jsonSerialize(): array |
|
3259 | |||
3260 | /** |
||
3261 | * Gets the key/index of the element at the current internal iterator position. |
||
3262 | * |
||
3263 | * @return int|string|null |
||
3264 | */ |
||
3265 | public function key() |
||
3269 | |||
3270 | /** |
||
3271 | * Checks if the given key exists in the provided array. |
||
3272 | * |
||
3273 | * INFO: This method only use "array_key_exists()" if you want to use "dot"-notation, |
||
3274 | * then you need to use "Arrayy->offsetExists()". |
||
3275 | * |
||
3276 | * @param int|string $key the key to look for |
||
3277 | * |
||
3278 | * @return bool |
||
3279 | * @psalm-mutation-free |
||
3280 | */ |
||
3281 | 162 | public function keyExists($key): bool |
|
3285 | |||
3286 | /** |
||
3287 | * Get all keys from the current array. |
||
3288 | * |
||
3289 | * @param bool $recursive [optional] <p> |
||
3290 | * Get all keys, also from all sub-arrays from an multi-dimensional array. |
||
3291 | * </p> |
||
3292 | * @param mixed|null $search_values [optional] <p> |
||
3293 | * If specified, then only keys containing these values are returned. |
||
3294 | * </p> |
||
3295 | * @param bool $strict [optional] <p> |
||
3296 | * Determines if strict comparison (===) should be used during the search. |
||
3297 | * </p> |
||
3298 | * |
||
3299 | * @return static |
||
3300 | * <p>(Immutable) An array of all the keys in input.</p> |
||
3301 | * |
||
3302 | * @psalm-return static<array-key,TKey> |
||
3303 | * @psalm-mutation-free |
||
3304 | */ |
||
3305 | 29 | public function keys( |
|
3375 | |||
3376 | /** |
||
3377 | * Sort an array by key in reverse order. |
||
3378 | * |
||
3379 | * @param int $sort_flags [optional] <p> |
||
3380 | * You may modify the behavior of the sort using the optional |
||
3381 | * parameter sort_flags, for details |
||
3382 | * see sort. |
||
3383 | * </p> |
||
3384 | * |
||
3385 | * @return $this |
||
3386 | * <p>(Mutable) Return this Arrayy object.</p> |
||
3387 | * |
||
3388 | * @psalm-return static<TKey,T> |
||
3389 | */ |
||
3390 | 4 | public function krsort(int $sort_flags = 0): self |
|
3398 | |||
3399 | /** |
||
3400 | * Sort an array by key in reverse order. |
||
3401 | * |
||
3402 | * @param int $sort_flags [optional] <p> |
||
3403 | * You may modify the behavior of the sort using the optional |
||
3404 | * parameter sort_flags, for details |
||
3405 | * see sort. |
||
3406 | * </p> |
||
3407 | * |
||
3408 | * @return $this |
||
3409 | * <p>(Immutable) Return this Arrayy object.</p> |
||
3410 | * |
||
3411 | * @psalm-return static<TKey,T> |
||
3412 | * @psalm-mutation-free |
||
3413 | */ |
||
3414 | 4 | public function krsortImmutable(int $sort_flags = 0): self |
|
3425 | |||
3426 | /** |
||
3427 | * Get the last value from the current array. |
||
3428 | * |
||
3429 | * @return mixed|null |
||
3430 | * <p>Return null if there wasn't a element.</p> |
||
3431 | * @psalm-mutation-free |
||
3432 | */ |
||
3433 | 17 | public function last() |
|
3442 | |||
3443 | /** |
||
3444 | * Get the last key from the current array. |
||
3445 | * |
||
3446 | * @return mixed|null |
||
3447 | * <p>Return null if there wasn't a element.</p> |
||
3448 | * @psalm-mutation-free |
||
3449 | */ |
||
3450 | 21 | public function lastKey() |
|
3456 | |||
3457 | /** |
||
3458 | * Get the last value(s) from the current array. |
||
3459 | * |
||
3460 | * @param int|null $number |
||
3461 | * |
||
3462 | * @return static |
||
3463 | * <p>(Immutable)</p> |
||
3464 | * |
||
3465 | * @psalm-return static<TKey,T> |
||
3466 | * @psalm-mutation-free |
||
3467 | */ |
||
3468 | 13 | public function lastsImmutable(int $number = null): self |
|
3499 | |||
3500 | /** |
||
3501 | * Get the last value(s) from the current array. |
||
3502 | * |
||
3503 | * @param int|null $number |
||
3504 | * |
||
3505 | * @return $this |
||
3506 | * <p>(Mutable)</p> |
||
3507 | * |
||
3508 | * @psalm-return static<TKey,T> |
||
3509 | */ |
||
3510 | 13 | public function lastsMutable(int $number = null): self |
|
3539 | |||
3540 | /** |
||
3541 | * Count the values from the current array. |
||
3542 | * |
||
3543 | * alias: for "Arrayy->count()" |
||
3544 | * |
||
3545 | * @param int $mode |
||
3546 | * |
||
3547 | * @return int |
||
3548 | * |
||
3549 | * @see Arrayy::count() |
||
3550 | */ |
||
3551 | 20 | public function length(int $mode = \COUNT_NORMAL): int |
|
3555 | |||
3556 | /** |
||
3557 | * Apply the given function to the every element of the array, |
||
3558 | * collecting the results. |
||
3559 | * |
||
3560 | * @param callable $callable |
||
3561 | * @param bool $useKeyAsSecondParameter |
||
3562 | * @param mixed ...$arguments |
||
3563 | * |
||
3564 | * @return static |
||
3565 | * <p>(Immutable) Arrayy object with modified elements.</p> |
||
3566 | * |
||
3567 | * @psalm-param callable(T,TKey=,mixed=):mixed $callable |
||
3568 | * @psalm-return static<TKey,T> |
||
3569 | * @psalm-mutation-free |
||
3570 | */ |
||
3571 | 5 | public function map( |
|
3604 | |||
3605 | /** |
||
3606 | * Check if all items in current array match a truth test. |
||
3607 | * |
||
3608 | * @param \Closure $closure |
||
3609 | * |
||
3610 | * @return bool |
||
3611 | */ |
||
3612 | 15 | View Code Duplication | public function matches(\Closure $closure): bool |
3628 | |||
3629 | /** |
||
3630 | * Check if any item in the current array matches a truth test. |
||
3631 | * |
||
3632 | * @param \Closure $closure |
||
3633 | * |
||
3634 | * @return bool |
||
3635 | */ |
||
3636 | 14 | View Code Duplication | public function matchesAny(\Closure $closure): bool |
3652 | |||
3653 | /** |
||
3654 | * Get the max value from an array. |
||
3655 | * |
||
3656 | * @return false|mixed |
||
3657 | * <p>Will return false if there are no values.</p> |
||
3658 | */ |
||
3659 | 10 | View Code Duplication | public function max() |
3678 | |||
3679 | /** |
||
3680 | * Merge the new $array into the current array. |
||
3681 | * |
||
3682 | * - keep key,value from the current array, also if the index is in the new $array |
||
3683 | * |
||
3684 | * @param array $array |
||
3685 | * @param bool $recursive |
||
3686 | * |
||
3687 | * @return static |
||
3688 | * <p>(Immutable)</p> |
||
3689 | * |
||
3690 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
3691 | * @psalm-return static<int|TKey,T> |
||
3692 | * @psalm-mutation-free |
||
3693 | */ |
||
3694 | 32 | View Code Duplication | public function mergeAppendKeepIndex(array $array = [], bool $recursive = false): self |
3709 | |||
3710 | /** |
||
3711 | * Merge the new $array into the current array. |
||
3712 | * |
||
3713 | * - replace duplicate assoc-keys from the current array with the key,values from the new $array |
||
3714 | * - create new indexes |
||
3715 | * |
||
3716 | * @param array $array |
||
3717 | * @param bool $recursive |
||
3718 | * |
||
3719 | * @return static |
||
3720 | * <p>(Immutable)</p> |
||
3721 | * |
||
3722 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
3723 | * @psalm-return static<TKey,T> |
||
3724 | * @psalm-mutation-free |
||
3725 | */ |
||
3726 | 19 | View Code Duplication | public function mergeAppendNewIndex(array $array = [], bool $recursive = false): self |
3741 | |||
3742 | /** |
||
3743 | * Merge the the current array into the $array. |
||
3744 | * |
||
3745 | * - use key,value from the new $array, also if the index is in the current array |
||
3746 | * |
||
3747 | * @param array $array |
||
3748 | * @param bool $recursive |
||
3749 | * |
||
3750 | * @return static |
||
3751 | * <p>(Immutable)</p> |
||
3752 | * |
||
3753 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
3754 | * @psalm-return static<TKey,T> |
||
3755 | * @psalm-mutation-free |
||
3756 | */ |
||
3757 | 16 | View Code Duplication | public function mergePrependKeepIndex(array $array = [], bool $recursive = false): self |
3772 | |||
3773 | /** |
||
3774 | * Merge the current array into the new $array. |
||
3775 | * |
||
3776 | * - replace duplicate assoc-keys from new $array with the key,values from the current array |
||
3777 | * - create new indexes |
||
3778 | * |
||
3779 | * @param array $array |
||
3780 | * @param bool $recursive |
||
3781 | * |
||
3782 | * @return static |
||
3783 | * <p>(Immutable)</p> |
||
3784 | * |
||
3785 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
3786 | * @psalm-return static<TKey,T> |
||
3787 | * @psalm-mutation-free |
||
3788 | */ |
||
3789 | 20 | View Code Duplication | public function mergePrependNewIndex(array $array = [], bool $recursive = false): self |
3804 | |||
3805 | /** |
||
3806 | * @return ArrayyMeta|static |
||
3807 | */ |
||
3808 | 16 | public static function meta() |
|
3812 | |||
3813 | /** |
||
3814 | * Get the min value from an array. |
||
3815 | * |
||
3816 | * @return false|mixed |
||
3817 | * <p>Will return false if there are no values.</p> |
||
3818 | */ |
||
3819 | 10 | View Code Duplication | public function min() |
3838 | |||
3839 | /** |
||
3840 | * Get the most used value from the array. |
||
3841 | * |
||
3842 | * @return mixed|null |
||
3843 | * <p>(Immutable) Return null if there wasn't a element.</p> |
||
3844 | * @psalm-mutation-free |
||
3845 | */ |
||
3846 | 3 | public function mostUsedValue() |
|
3850 | |||
3851 | /** |
||
3852 | * Get the most used value from the array. |
||
3853 | * |
||
3854 | * @param int|null $number <p>How many values you will take?</p> |
||
3855 | * |
||
3856 | * @return static |
||
3857 | * <p>(Immutable)</p> |
||
3858 | * |
||
3859 | * @psalm-return static<TKey,T> |
||
3860 | * @psalm-mutation-free |
||
3861 | */ |
||
3862 | 3 | public function mostUsedValues(int $number = null): self |
|
3866 | |||
3867 | /** |
||
3868 | * Move an array element to a new index. |
||
3869 | * |
||
3870 | * cherry-picked from: http://stackoverflow.com/questions/12624153/move-an-array-element-to-a-new-index-in-php |
||
3871 | * |
||
3872 | * @param int|string $from |
||
3873 | * @param int $to |
||
3874 | * |
||
3875 | * @return static |
||
3876 | * <p>(Immutable)</p> |
||
3877 | * |
||
3878 | * @psalm-return static<TKey,T> |
||
3879 | * @psalm-mutation-free |
||
3880 | */ |
||
3881 | 1 | public function moveElement($from, $to): self |
|
3914 | |||
3915 | /** |
||
3916 | * Move an array element to the first place. |
||
3917 | * |
||
3918 | * INFO: Instead of "Arrayy->moveElement()" this method will NOT |
||
3919 | * loss the keys of an indexed array. |
||
3920 | * |
||
3921 | * @param int|string $key |
||
3922 | * |
||
3923 | * @return static |
||
3924 | * <p>(Immutable)</p> |
||
3925 | * |
||
3926 | * @psalm-return static<TKey,T> |
||
3927 | * @psalm-mutation-free |
||
3928 | */ |
||
3929 | 1 | View Code Duplication | public function moveElementToFirstPlace($key): self |
3945 | |||
3946 | /** |
||
3947 | * Move an array element to the last place. |
||
3948 | * |
||
3949 | * INFO: Instead of "Arrayy->moveElement()" this method will NOT |
||
3950 | * loss the keys of an indexed array. |
||
3951 | * |
||
3952 | * @param int|string $key |
||
3953 | * |
||
3954 | * @return static |
||
3955 | * <p>(Immutable)</p> |
||
3956 | * |
||
3957 | * @psalm-return static<TKey,T> |
||
3958 | * @psalm-mutation-free |
||
3959 | */ |
||
3960 | 1 | View Code Duplication | public function moveElementToLastPlace($key): self |
3976 | |||
3977 | /** |
||
3978 | * Moves the internal iterator position to the next element and returns this element. |
||
3979 | * |
||
3980 | * @return false|mixed |
||
3981 | * <p>(Mutable) Will return false if there are no values.</p> |
||
3982 | */ |
||
3983 | public function next() |
||
3987 | |||
3988 | /** |
||
3989 | * Get the next nth keys and values from the array. |
||
3990 | * |
||
3991 | * @param int $step |
||
3992 | * @param int $offset |
||
3993 | * |
||
3994 | * @return static |
||
3995 | * <p>(Immutable)</p> |
||
3996 | * |
||
3997 | * @psalm-return static<TKey,T> |
||
3998 | * @psalm-mutation-free |
||
3999 | */ |
||
4000 | 1 | public function nth(int $step, int $offset = 0): self |
|
4019 | |||
4020 | /** |
||
4021 | * Get a subset of the items from the given array. |
||
4022 | * |
||
4023 | * @param mixed[] $keys |
||
4024 | * |
||
4025 | * @return static |
||
4026 | * <p>(Immutable)</p> |
||
4027 | * |
||
4028 | * @psalm-return static<TKey,T> |
||
4029 | * @psalm-mutation-free |
||
4030 | */ |
||
4031 | 1 | public function only(array $keys): self |
|
4041 | |||
4042 | /** |
||
4043 | * Pad array to the specified size with a given value. |
||
4044 | * |
||
4045 | * @param int $size <p>Size of the result array.</p> |
||
4046 | * @param mixed $value <p>Empty value by default.</p> |
||
4047 | * |
||
4048 | * @return static |
||
4049 | * <p>(Immutable) Arrayy object padded to $size with $value.</p> |
||
4050 | * |
||
4051 | * @psalm-return static<TKey,T> |
||
4052 | * @psalm-mutation-free |
||
4053 | */ |
||
4054 | 5 | public function pad(int $size, $value): self |
|
4062 | |||
4063 | /** |
||
4064 | * Partitions this array in two array according to a predicate. |
||
4065 | * Keys are preserved in the resulting array. |
||
4066 | * |
||
4067 | * @param \Closure $closure |
||
4068 | * <p>The predicate on which to partition.</p> |
||
4069 | * |
||
4070 | * @return array<int, static> |
||
4071 | * <p>An array with two elements. The first element contains the array |
||
4072 | * of elements where the predicate returned TRUE, the second element |
||
4073 | * contains the array of elements where the predicate returned FALSE.</p> |
||
4074 | * |
||
4075 | * @psalm-return array<int, static<TKey,T>> |
||
4076 | */ |
||
4077 | 1 | public function partition(\Closure $closure): array |
|
4093 | |||
4094 | /** |
||
4095 | * Pop a specified value off the end of the current array. |
||
4096 | * |
||
4097 | * @return mixed|null |
||
4098 | * <p>(Mutable) The popped element from the current array or null if the array is e.g. empty.</p> |
||
4099 | */ |
||
4100 | 5 | public function pop() |
|
4106 | |||
4107 | /** |
||
4108 | * Prepend a (key) + value to the current array. |
||
4109 | * |
||
4110 | * @param mixed $value |
||
4111 | * @param mixed $key |
||
4112 | * |
||
4113 | * @return $this |
||
4114 | * <p>(Mutable) Return this Arrayy object, with the prepended value.</p> |
||
4115 | * |
||
4116 | * @psalm-return static<TKey,T> |
||
4117 | */ |
||
4118 | 11 | public function prepend($value, $key = null) |
|
4134 | |||
4135 | /** |
||
4136 | * Add a suffix to each key. |
||
4137 | * |
||
4138 | * @param mixed $suffix |
||
4139 | * |
||
4140 | * @return static |
||
4141 | * <p>(Immutable) Return an Arrayy object, with the prepended keys.</p> |
||
4142 | * |
||
4143 | * @psalm-return static<TKey,T> |
||
4144 | * @psalm-mutation-free |
||
4145 | */ |
||
4146 | 10 | View Code Duplication | public function prependToEachKey($suffix): self |
4172 | |||
4173 | /** |
||
4174 | * Add a suffix to each value. |
||
4175 | * |
||
4176 | * @param mixed $suffix |
||
4177 | * |
||
4178 | * @return static |
||
4179 | * <p>(Immutable) Return an Arrayy object, with the prepended values.</p> |
||
4180 | * |
||
4181 | * @psalm-return static<TKey,T> |
||
4182 | * @psalm-mutation-free |
||
4183 | */ |
||
4184 | 10 | View Code Duplication | public function prependToEachValue($suffix): self |
4212 | |||
4213 | /** |
||
4214 | * Return the value of a given key and |
||
4215 | * delete the key. |
||
4216 | * |
||
4217 | * @param int|int[]|string|string[]|null $keyOrKeys |
||
4218 | * @param mixed $fallback |
||
4219 | * |
||
4220 | * @return mixed |
||
4221 | */ |
||
4222 | 5 | public function pull($keyOrKeys = null, $fallback = null) |
|
4244 | |||
4245 | /** |
||
4246 | * Push one or more values onto the end of array at once. |
||
4247 | * |
||
4248 | * @param array ...$args |
||
4249 | * |
||
4250 | * @return $this |
||
4251 | * <p>(Mutable) Return this Arrayy object, with pushed elements to the end of array.</p> |
||
4252 | * |
||
4253 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
4254 | * |
||
4255 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$args |
||
4256 | * @psalm-return static<TKey,T> |
||
4257 | */ |
||
4258 | 7 | public function push(...$args) |
|
4276 | |||
4277 | /** |
||
4278 | * Get a random value from the current array. |
||
4279 | * |
||
4280 | * @param int|null $number <p>How many values you will take?</p> |
||
4281 | * |
||
4282 | * @return static |
||
4283 | * <p>(Immutable)</p> |
||
4284 | * |
||
4285 | * @psalm-return static<int|array-key,T> |
||
4286 | */ |
||
4287 | 19 | public function randomImmutable(int $number = null): self |
|
4320 | |||
4321 | /** |
||
4322 | * Pick a random key/index from the keys of this array. |
||
4323 | * |
||
4324 | * @throws \RangeException If array is empty |
||
4325 | * |
||
4326 | * @return mixed |
||
4327 | * <p>Get a key/index or null if there wasn't a key/index.</p> |
||
4328 | */ |
||
4329 | 4 | public function randomKey() |
|
4339 | |||
4340 | /** |
||
4341 | * Pick a given number of random keys/indexes out of this array. |
||
4342 | * |
||
4343 | * @param int $number <p>The number of keys/indexes (should be <= \count($this->array))</p> |
||
4344 | * |
||
4345 | * @throws \RangeException If array is empty |
||
4346 | * |
||
4347 | * @return static |
||
4348 | * <p>(Immutable)</p> |
||
4349 | * |
||
4350 | * @psalm-return static<TKey,T> |
||
4351 | */ |
||
4352 | 13 | public function randomKeys(int $number): self |
|
4380 | |||
4381 | /** |
||
4382 | * Get a random value from the current array. |
||
4383 | * |
||
4384 | * @param int|null $number <p>How many values you will take?</p> |
||
4385 | * |
||
4386 | * @return $this |
||
4387 | * <p>(Mutable) Return this Arrayy object.</p> |
||
4388 | * |
||
4389 | * @psalm-return static<TKey,T> |
||
4390 | */ |
||
4391 | 17 | public function randomMutable(int $number = null): self |
|
4416 | |||
4417 | /** |
||
4418 | * Pick a random value from the values of this array. |
||
4419 | * |
||
4420 | * @return mixed |
||
4421 | * <p>Get a random value or null if there wasn't a value.</p> |
||
4422 | */ |
||
4423 | 4 | public function randomValue() |
|
4433 | |||
4434 | /** |
||
4435 | * Pick a given number of random values out of this array. |
||
4436 | * |
||
4437 | * @param int $number |
||
4438 | * |
||
4439 | * @return static |
||
4440 | * <p>(Mutable)</p> |
||
4441 | * |
||
4442 | * @psalm-return static<TKey,T> |
||
4443 | */ |
||
4444 | 7 | public function randomValues(int $number): self |
|
4448 | |||
4449 | /** |
||
4450 | * Get a random value from an array, with the ability to skew the results. |
||
4451 | * |
||
4452 | * Example: randomWeighted(['foo' => 1, 'bar' => 2]) has a 66% chance of returning bar. |
||
4453 | * |
||
4454 | * @param array $array |
||
4455 | * @param int|null $number <p>How many values you will take?</p> |
||
4456 | * |
||
4457 | * @return static<int,mixed> |
||
4458 | * <p>(Immutable)</p> |
||
4459 | * |
||
4460 | * @psalm-param array<mixed,mixed> $array |
||
4461 | * @psalm-return static<int|array-key,T> |
||
4462 | */ |
||
4463 | 9 | public function randomWeighted(array $array, int $number = null): self |
|
4478 | |||
4479 | /** |
||
4480 | * Reduce the current array via callable e.g. anonymous-function. |
||
4481 | * |
||
4482 | * @param callable $callable |
||
4483 | * @param mixed $init |
||
4484 | * |
||
4485 | * @return static |
||
4486 | * <p>(Immutable)</p> |
||
4487 | * |
||
4488 | * @psalm-return static<TKey,T> |
||
4489 | * @psalm-mutation-free |
||
4490 | */ |
||
4491 | 18 | public function reduce($callable, $init = []): self |
|
4521 | |||
4522 | /** |
||
4523 | * @param bool $unique |
||
4524 | * |
||
4525 | * @return static |
||
4526 | * <p>(Immutable)</p> |
||
4527 | * |
||
4528 | * @psalm-return static<TKey,T> |
||
4529 | * @psalm-mutation-free |
||
4530 | */ |
||
4531 | 14 | public function reduce_dimension(bool $unique = true): self |
|
4554 | |||
4555 | /** |
||
4556 | * Create a numerically re-indexed Arrayy object. |
||
4557 | * |
||
4558 | * @return $this |
||
4559 | * <p>(Mutable) Return this Arrayy object, with re-indexed array-elements.</p> |
||
4560 | * |
||
4561 | * @psalm-return static<TKey,T> |
||
4562 | */ |
||
4563 | 9 | public function reindex(): self |
|
4571 | |||
4572 | /** |
||
4573 | * Return all items that fail the truth test. |
||
4574 | * |
||
4575 | * @param \Closure $closure |
||
4576 | * |
||
4577 | * @return static |
||
4578 | * <p>(Immutable)</p> |
||
4579 | * |
||
4580 | * @psalm-return static<TKey,T> |
||
4581 | * @psalm-mutation-free |
||
4582 | */ |
||
4583 | 1 | View Code Duplication | public function reject(\Closure $closure): self |
4600 | |||
4601 | /** |
||
4602 | * Remove a value from the current array (optional using dot-notation). |
||
4603 | * |
||
4604 | * @param mixed $key |
||
4605 | * |
||
4606 | * @return static |
||
4607 | * <p>(Mutable)</p> |
||
4608 | * |
||
4609 | * @psalm-param TKey $key |
||
4610 | * @psalm-return static<TKey,T> |
||
4611 | */ |
||
4612 | 21 | public function remove($key) |
|
4635 | |||
4636 | /** |
||
4637 | * alias: for "Arrayy->removeValue()" |
||
4638 | * |
||
4639 | * @param mixed $element |
||
4640 | * |
||
4641 | * @return static |
||
4642 | * <p>(Immutable)</p> |
||
4643 | * |
||
4644 | * @psalm-param T $element |
||
4645 | * @psalm-return static<TKey,T> |
||
4646 | * @psalm-mutation-free |
||
4647 | */ |
||
4648 | 8 | public function removeElement($element) |
|
4652 | |||
4653 | /** |
||
4654 | * Remove the first value from the current array. |
||
4655 | * |
||
4656 | * @return static |
||
4657 | * <p>(Immutable)</p> |
||
4658 | * |
||
4659 | * @psalm-return static<TKey,T> |
||
4660 | * @psalm-mutation-free |
||
4661 | */ |
||
4662 | 7 | View Code Duplication | public function removeFirst(): self |
4674 | |||
4675 | /** |
||
4676 | * Remove the last value from the current array. |
||
4677 | * |
||
4678 | * @return static |
||
4679 | * <p>(Immutable)</p> |
||
4680 | * |
||
4681 | * @psalm-return static<TKey,T> |
||
4682 | * @psalm-mutation-free |
||
4683 | */ |
||
4684 | 7 | View Code Duplication | public function removeLast(): self |
4696 | |||
4697 | /** |
||
4698 | * Removes a particular value from an array (numeric or associative). |
||
4699 | * |
||
4700 | * @param mixed $value |
||
4701 | * |
||
4702 | * @return static |
||
4703 | * <p>(Immutable)</p> |
||
4704 | * |
||
4705 | * @psalm-param T $value |
||
4706 | * @psalm-return static<TKey,T> |
||
4707 | * @psalm-mutation-free |
||
4708 | */ |
||
4709 | 8 | public function removeValue($value): self |
|
4732 | |||
4733 | /** |
||
4734 | * Generate array of repeated arrays. |
||
4735 | * |
||
4736 | * @param int $times <p>How many times has to be repeated.</p> |
||
4737 | * |
||
4738 | * @return static |
||
4739 | * <p>(Immutable)</p> |
||
4740 | * |
||
4741 | * @psalm-return static<TKey,T> |
||
4742 | * @psalm-mutation-free |
||
4743 | */ |
||
4744 | 1 | public function repeat($times): self |
|
4756 | |||
4757 | /** |
||
4758 | * Replace a key with a new key/value pair. |
||
4759 | * |
||
4760 | * @param mixed $oldKey |
||
4761 | * @param mixed $newKey |
||
4762 | * @param mixed $newValue |
||
4763 | * |
||
4764 | * @return static |
||
4765 | * <p>(Immutable)</p> |
||
4766 | * |
||
4767 | * @psalm-return static<TKey,T> |
||
4768 | * @psalm-mutation-free |
||
4769 | */ |
||
4770 | 5 | public function replace($oldKey, $newKey, $newValue): self |
|
4780 | |||
4781 | /** |
||
4782 | * Create an array using the current array as values and the other array as keys. |
||
4783 | * |
||
4784 | * @param array $keys <p>An array of keys.</p> |
||
4785 | * |
||
4786 | * @return static |
||
4787 | * <p>(Immutable) Arrayy object with keys from the other array.</p> |
||
4788 | * |
||
4789 | * @psalm-param array<mixed,mixed>|array<mixed,TKey> $keys |
||
4790 | * @psalm-return static<TKey,T> |
||
4791 | * @psalm-mutation-free |
||
4792 | */ |
||
4793 | 2 | public function replaceAllKeys(array $keys): self |
|
4801 | |||
4802 | /** |
||
4803 | * Create an array using the current array as keys and the other array as values. |
||
4804 | * |
||
4805 | * @param array $array <p>An array o values.</p> |
||
4806 | * |
||
4807 | * @return static |
||
4808 | * <p>(Immutable) Arrayy object with values from the other array.</p> |
||
4809 | * |
||
4810 | * @psalm-param array<mixed,T> $array |
||
4811 | * @psalm-return static<TKey,T> |
||
4812 | * @psalm-mutation-free |
||
4813 | */ |
||
4814 | 2 | public function replaceAllValues(array $array): self |
|
4822 | |||
4823 | /** |
||
4824 | * Replace the keys in an array with another set. |
||
4825 | * |
||
4826 | * @param array $keys <p>An array of keys matching the array's size</p> |
||
4827 | * |
||
4828 | * @return static |
||
4829 | * <p>(Immutable)</p> |
||
4830 | * |
||
4831 | * @psalm-param array<mixed,mixed>|array<mixed,TKey> $keys |
||
4832 | * @psalm-return static<TKey,T> |
||
4833 | * @psalm-mutation-free |
||
4834 | */ |
||
4835 | 1 | public function replaceKeys(array $keys): self |
|
4846 | |||
4847 | /** |
||
4848 | * Replace the first matched value in an array. |
||
4849 | * |
||
4850 | * @param mixed $search <p>The value to replace.</p> |
||
4851 | * @param mixed $replacement <p>The value to replace.</p> |
||
4852 | * |
||
4853 | * @return static |
||
4854 | * <p>(Immutable)</p> |
||
4855 | * |
||
4856 | * @psalm-return static<TKey,T> |
||
4857 | * @psalm-mutation-free |
||
4858 | */ |
||
4859 | 3 | public function replaceOneValue($search, $replacement = ''): self |
|
4874 | |||
4875 | /** |
||
4876 | * Replace values in the current array. |
||
4877 | * |
||
4878 | * @param mixed $search <p>The value to replace.</p> |
||
4879 | * @param mixed $replacement <p>What to replace it with.</p> |
||
4880 | * |
||
4881 | * @return static |
||
4882 | * <p>(Immutable)</p> |
||
4883 | * |
||
4884 | * @psalm-return static<TKey,T> |
||
4885 | * @psalm-mutation-free |
||
4886 | */ |
||
4887 | 1 | public function replaceValues($search, $replacement = ''): self |
|
4899 | |||
4900 | /** |
||
4901 | * Get the last elements from index $from until the end of this array. |
||
4902 | * |
||
4903 | * @param int $from |
||
4904 | * |
||
4905 | * @return static |
||
4906 | * <p>(Immutable)</p> |
||
4907 | * |
||
4908 | * @psalm-return static<TKey,T> |
||
4909 | * @psalm-mutation-free |
||
4910 | */ |
||
4911 | 15 | View Code Duplication | public function rest(int $from = 1): self |
4921 | |||
4922 | /** |
||
4923 | * Return the array in the reverse order. |
||
4924 | * |
||
4925 | * @return $this |
||
4926 | * <p>(Mutable) Return this Arrayy object.</p> |
||
4927 | * |
||
4928 | * @psalm-return static<TKey,T> |
||
4929 | */ |
||
4930 | 9 | public function reverse(): self |
|
4938 | |||
4939 | /** |
||
4940 | * Sort an array in reverse order. |
||
4941 | * |
||
4942 | * @param int $sort_flags [optional] <p> |
||
4943 | * You may modify the behavior of the sort using the optional |
||
4944 | * parameter sort_flags, for details |
||
4945 | * see sort. |
||
4946 | * </p> |
||
4947 | * |
||
4948 | * @return $this |
||
4949 | * <p>(Mutable) Return this Arrayy object.</p> |
||
4950 | * |
||
4951 | * @psalm-return static<TKey,T> |
||
4952 | */ |
||
4953 | 4 | public function rsort(int $sort_flags = 0): self |
|
4961 | |||
4962 | /** |
||
4963 | * Sort an array in reverse order. |
||
4964 | * |
||
4965 | * @param int $sort_flags [optional] <p> |
||
4966 | * You may modify the behavior of the sort using the optional |
||
4967 | * parameter sort_flags, for details |
||
4968 | * see sort. |
||
4969 | * </p> |
||
4970 | * |
||
4971 | * @return $this |
||
4972 | * <p>(Immutable) Return this Arrayy object.</p> |
||
4973 | * |
||
4974 | * @psalm-return static<TKey,T> |
||
4975 | * @psalm-mutation-free |
||
4976 | */ |
||
4977 | 4 | public function rsortImmutable(int $sort_flags = 0): self |
|
4988 | |||
4989 | /** |
||
4990 | * Search for the first index of the current array via $value. |
||
4991 | * |
||
4992 | * @param mixed $value |
||
4993 | * |
||
4994 | * @return false|float|int|string |
||
4995 | * <p>Will return <b>FALSE</b> if the value can't be found.</p> |
||
4996 | * @psalm-mutation-free |
||
4997 | */ |
||
4998 | 21 | public function searchIndex($value) |
|
5008 | |||
5009 | /** |
||
5010 | * Search for the value of the current array via $index. |
||
5011 | * |
||
5012 | * @param mixed $index |
||
5013 | * |
||
5014 | * @return static |
||
5015 | * <p>(Immutable) Will return a empty Arrayy if the value wasn't found.</p> |
||
5016 | * |
||
5017 | * @psalm-return static<TKey,T> |
||
5018 | * @psalm-mutation-free |
||
5019 | */ |
||
5020 | 9 | public function searchValue($index): self |
|
5050 | |||
5051 | /** |
||
5052 | * Set a value for the current array (optional using dot-notation). |
||
5053 | * |
||
5054 | * @param string $key <p>The key to set.</p> |
||
5055 | * @param mixed $value <p>Its value.</p> |
||
5056 | * |
||
5057 | * @return $this |
||
5058 | * <p>(Mutable) Return this Arrayy object.</p> |
||
5059 | * |
||
5060 | * @psalm-param TKey $key |
||
5061 | * @psalm-param T $value |
||
5062 | * @psalm-return static<TKey,T> |
||
5063 | */ |
||
5064 | 28 | public function set($key, $value): self |
|
5070 | |||
5071 | /** |
||
5072 | * Get a value from a array and set it if it was not. |
||
5073 | * |
||
5074 | * WARNING: this method only set the value, if the $key is not already set |
||
5075 | * |
||
5076 | * @param mixed $key <p>The key</p> |
||
5077 | * @param mixed $fallback <p>The default value to set if it isn't.</p> |
||
5078 | * |
||
5079 | * @return mixed |
||
5080 | * <p>(Mutable)</p> |
||
5081 | */ |
||
5082 | 11 | public function setAndGet($key, $fallback = null) |
|
5093 | |||
5094 | /** |
||
5095 | * Shifts a specified value off the beginning of array. |
||
5096 | * |
||
5097 | * @return mixed |
||
5098 | * <p>(Mutable) A shifted element from the current array.</p> |
||
5099 | */ |
||
5100 | 5 | public function shift() |
|
5106 | |||
5107 | /** |
||
5108 | * Shuffle the current array. |
||
5109 | * |
||
5110 | * @param bool $secure <p>using a CSPRNG | @link https://paragonie.com/b/JvICXzh_jhLyt4y3</p> |
||
5111 | * @param array $array [optional] |
||
5112 | * |
||
5113 | * @return static |
||
5114 | * <p>(Immutable)</p> |
||
5115 | * |
||
5116 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
5117 | * @psalm-return static<TKey,T> |
||
5118 | * |
||
5119 | * @noinspection BadExceptionsProcessingInspection |
||
5120 | * @noinspection RandomApiMigrationInspection |
||
5121 | * @noinspection NonSecureShuffleUsageInspection |
||
5122 | */ |
||
5123 | 2 | public function shuffle(bool $secure = false, array $array = null): self |
|
5124 | { |
||
5125 | 2 | if ($array === null) { |
|
5126 | 2 | $array = $this->toArray(false); |
|
5127 | } |
||
5128 | |||
5129 | 2 | if ($secure !== true) { |
|
5130 | 2 | \shuffle($array); |
|
5131 | } else { |
||
5132 | 1 | $size = \count($array, \COUNT_NORMAL); |
|
5133 | 1 | $keys = \array_keys($array); |
|
5134 | 1 | for ($i = $size - 1; $i > 0; --$i) { |
|
5135 | try { |
||
5136 | 1 | $r = \random_int(0, $i); |
|
5137 | } catch (\Exception $e) { |
||
5138 | $r = \mt_rand(0, $i); |
||
5139 | } |
||
5140 | 1 | if ($r !== $i) { |
|
5141 | $temp = $array[$keys[$r]]; |
||
5142 | $array[$keys[$r]] = $array[$keys[$i]]; |
||
5143 | $array[$keys[$i]] = $temp; |
||
5144 | } |
||
5145 | } |
||
5146 | } |
||
5147 | |||
5148 | 2 | foreach ($array as $key => $value) { |
|
5149 | // check if recursive is needed |
||
5150 | 2 | if (\is_array($value) === true) { |
|
5151 | 2 | $array[$key] = $this->shuffle($secure, $value); |
|
5152 | } |
||
5153 | } |
||
5154 | |||
5155 | 2 | return static::create( |
|
5156 | 2 | $array, |
|
5157 | 2 | $this->iteratorClass, |
|
5158 | 2 | false |
|
5159 | ); |
||
5160 | } |
||
5161 | |||
5162 | /** |
||
5163 | * Count the values from the current array. |
||
5164 | * |
||
5165 | * alias: for "Arrayy->count()" |
||
5166 | * |
||
5167 | * @param int $mode |
||
5168 | * |
||
5169 | * @return int |
||
5170 | */ |
||
5171 | 20 | public function size(int $mode = \COUNT_NORMAL): int |
|
5175 | |||
5176 | /** |
||
5177 | * Checks whether array has exactly $size items. |
||
5178 | * |
||
5179 | * @param int $size |
||
5180 | * |
||
5181 | * @return bool |
||
5182 | */ |
||
5183 | 1 | public function sizeIs(int $size): bool |
|
5198 | |||
5199 | /** |
||
5200 | * Checks whether array has between $fromSize to $toSize items. $toSize can be |
||
5201 | * smaller than $fromSize. |
||
5202 | * |
||
5203 | * @param int $fromSize |
||
5204 | * @param int $toSize |
||
5205 | * |
||
5206 | * @return bool |
||
5207 | */ |
||
5208 | 1 | public function sizeIsBetween(int $fromSize, int $toSize): bool |
|
5228 | |||
5229 | /** |
||
5230 | * Checks whether array has more than $size items. |
||
5231 | * |
||
5232 | * @param int $size |
||
5233 | * |
||
5234 | * @return bool |
||
5235 | */ |
||
5236 | 1 | View Code Duplication | public function sizeIsGreaterThan(int $size): bool |
5250 | |||
5251 | /** |
||
5252 | * Checks whether array has less than $size items. |
||
5253 | * |
||
5254 | * @param int $size |
||
5255 | * |
||
5256 | * @return bool |
||
5257 | */ |
||
5258 | 1 | View Code Duplication | public function sizeIsLessThan(int $size): bool |
5272 | |||
5273 | /** |
||
5274 | * Counts all elements in an array, or something in an object. |
||
5275 | * |
||
5276 | * <p> |
||
5277 | * For objects, if you have SPL installed, you can hook into count() by implementing interface {@see Countable}. |
||
5278 | * The interface has exactly one method, {@see Countable::count()}, which returns the return value for the count() |
||
5279 | * function. Please see the {@see Array} section of the manual for a detailed explanation of how arrays are |
||
5280 | * implemented and used in PHP. |
||
5281 | * </p> |
||
5282 | * |
||
5283 | * @return int |
||
5284 | * <p> |
||
5285 | * The number of elements in var, which is |
||
5286 | * typically an array, since anything else will have one |
||
5287 | * element. |
||
5288 | * </p> |
||
5289 | * <p> |
||
5290 | * If var is not an array or an object with |
||
5291 | * implemented Countable interface, |
||
5292 | * 1 will be returned. |
||
5293 | * There is one exception, if var is &null;, |
||
5294 | * 0 will be returned. |
||
5295 | * </p> |
||
5296 | * <p> |
||
5297 | * Caution: count may return 0 for a variable that isn't set, |
||
5298 | * but it may also return 0 for a variable that has been initialized with an |
||
5299 | * empty array. Use isset to test if a variable is set. |
||
5300 | * </p> |
||
5301 | */ |
||
5302 | 10 | public function sizeRecursive(): int |
|
5306 | |||
5307 | /** |
||
5308 | * Extract a slice of the array. |
||
5309 | * |
||
5310 | * @param int $offset <p>Slice begin index.</p> |
||
5311 | * @param int|null $length <p>Length of the slice.</p> |
||
5312 | * @param bool $preserveKeys <p>Whether array keys are preserved or no.</p> |
||
5313 | * |
||
5314 | * @return static |
||
5315 | * <p>(Immutable) A slice of the original array with length $length.</p> |
||
5316 | * |
||
5317 | * @psalm-return static<TKey,T> |
||
5318 | * @psalm-mutation-free |
||
5319 | */ |
||
5320 | 5 | public function slice(int $offset, int $length = null, bool $preserveKeys = false) |
|
5333 | |||
5334 | /** |
||
5335 | * Sort the current array and optional you can keep the keys. |
||
5336 | * |
||
5337 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
5338 | * @param int $strategy <p>sort_flags => use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
5339 | * <strong>SORT_NATURAL</strong></p> |
||
5340 | * @param bool $keepKeys |
||
5341 | * |
||
5342 | * @return static |
||
5343 | * <p>(Mutable) Return this Arrayy object.</p> |
||
5344 | * |
||
5345 | * @psalm-return static<TKey,T> |
||
5346 | */ |
||
5347 | 20 | public function sort( |
|
5361 | |||
5362 | /** |
||
5363 | * Sort the current array and optional you can keep the keys. |
||
5364 | * |
||
5365 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
5366 | * @param int $strategy <p>sort_flags => use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
5367 | * <strong>SORT_NATURAL</strong></p> |
||
5368 | * @param bool $keepKeys |
||
5369 | * |
||
5370 | * @return static |
||
5371 | * <p>(Immutable) Return this Arrayy object.</p> |
||
5372 | * |
||
5373 | * @psalm-return static<TKey,T> |
||
5374 | */ |
||
5375 | 12 | public function sortImmutable( |
|
5391 | |||
5392 | /** |
||
5393 | * Sort the current array by key. |
||
5394 | * |
||
5395 | * @see http://php.net/manual/en/function.ksort.php |
||
5396 | * @see http://php.net/manual/en/function.krsort.php |
||
5397 | * |
||
5398 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
5399 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
5400 | * <strong>SORT_NATURAL</strong></p> |
||
5401 | * |
||
5402 | * @return $this |
||
5403 | * <p>(Mutable) Return this Arrayy object.</p> |
||
5404 | * |
||
5405 | * @psalm-return static<TKey,T> |
||
5406 | */ |
||
5407 | 18 | public function sortKeys( |
|
5417 | |||
5418 | /** |
||
5419 | * Sort the current array by key. |
||
5420 | * |
||
5421 | * @see http://php.net/manual/en/function.ksort.php |
||
5422 | * @see http://php.net/manual/en/function.krsort.php |
||
5423 | * |
||
5424 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
5425 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
5426 | * <strong>SORT_NATURAL</strong></p> |
||
5427 | * |
||
5428 | * @return $this |
||
5429 | * <p>(Immutable) Return this Arrayy object.</p> |
||
5430 | * |
||
5431 | * @psalm-return static<TKey,T> |
||
5432 | * @psalm-mutation-free |
||
5433 | */ |
||
5434 | 8 | public function sortKeysImmutable( |
|
5447 | |||
5448 | /** |
||
5449 | * Sort the current array by value. |
||
5450 | * |
||
5451 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
5452 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
5453 | * <strong>SORT_NATURAL</strong></p> |
||
5454 | * |
||
5455 | * @return static |
||
5456 | * <p>(Mutable)</p> |
||
5457 | * |
||
5458 | * @psalm-return static<TKey,T> |
||
5459 | */ |
||
5460 | 1 | public function sortValueKeepIndex( |
|
5466 | |||
5467 | /** |
||
5468 | * Sort the current array by value. |
||
5469 | * |
||
5470 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
5471 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
5472 | * <strong>SORT_NATURAL</strong></p> |
||
5473 | * |
||
5474 | * @return static |
||
5475 | * <p>(Mutable)</p> |
||
5476 | * |
||
5477 | * @psalm-return static<TKey,T> |
||
5478 | */ |
||
5479 | 1 | public function sortValueNewIndex($direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
5483 | |||
5484 | /** |
||
5485 | * Sort a array by value, by a closure or by a property. |
||
5486 | * |
||
5487 | * - If the sorter is null, the array is sorted naturally. |
||
5488 | * - Associative (string) keys will be maintained, but numeric keys will be re-indexed. |
||
5489 | * |
||
5490 | * @param callable|string|null $sorter |
||
5491 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or |
||
5492 | * <strong>SORT_DESC</strong></p> |
||
5493 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
5494 | * <strong>SORT_NATURAL</strong></p> |
||
5495 | * |
||
5496 | * @return static |
||
5497 | * <p>(Immutable)</p> |
||
5498 | * |
||
5499 | * @psalm-return static<TKey,T> |
||
5500 | * @psalm-mutation-free |
||
5501 | */ |
||
5502 | 1 | public function sorter($sorter = null, $direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
5543 | |||
5544 | /** |
||
5545 | * @param int $offset |
||
5546 | * @param int|null $length |
||
5547 | * @param array $replacement |
||
5548 | * |
||
5549 | * @return static |
||
5550 | * <p>(Immutable)</p> |
||
5551 | * |
||
5552 | * @psalm-param array<mixed,mixed>|array<mixed,T> $replacement |
||
5553 | * @psalm-return static<TKey,T> |
||
5554 | * @psalm-mutation-free |
||
5555 | */ |
||
5556 | 1 | public function splice(int $offset, int $length = null, $replacement = []): self |
|
5573 | |||
5574 | /** |
||
5575 | * Split an array in the given amount of pieces. |
||
5576 | * |
||
5577 | * @param int $numberOfPieces |
||
5578 | * @param bool $keepKeys |
||
5579 | * |
||
5580 | * @return static |
||
5581 | * <p>(Immutable)</p> |
||
5582 | * |
||
5583 | * @psalm-return static<TKey,T> |
||
5584 | * @psalm-mutation-free |
||
5585 | */ |
||
5586 | 1 | public function split(int $numberOfPieces = 2, bool $keepKeys = false): self |
|
5605 | |||
5606 | /** |
||
5607 | * Stripe all empty items. |
||
5608 | * |
||
5609 | * @return static |
||
5610 | * <p>(Immutable)</p> |
||
5611 | * |
||
5612 | * @psalm-return static<TKey,T> |
||
5613 | * @psalm-mutation-free |
||
5614 | */ |
||
5615 | 1 | public function stripEmpty(): self |
|
5627 | |||
5628 | /** |
||
5629 | * Swap two values between positions by key. |
||
5630 | * |
||
5631 | * @param int|string $swapA <p>a key in the array</p> |
||
5632 | * @param int|string $swapB <p>a key in the array</p> |
||
5633 | * |
||
5634 | * @return static |
||
5635 | * <p>(Immutable)</p> |
||
5636 | * |
||
5637 | * @psalm-return static<TKey,T> |
||
5638 | * @psalm-mutation-free |
||
5639 | */ |
||
5640 | 1 | public function swap($swapA, $swapB): self |
|
5652 | |||
5653 | /** |
||
5654 | * Get the current array from the "Arrayy"-object. |
||
5655 | * alias for "getArray()" |
||
5656 | * |
||
5657 | * @param bool $convertAllArrayyElements <p> |
||
5658 | * Convert all Child-"Arrayy" objects also to arrays. |
||
5659 | * </p> |
||
5660 | * @param bool $preserveKeys <p> |
||
5661 | * e.g.: A generator maybe return the same key more then once, |
||
5662 | * so maybe you will ignore the keys. |
||
5663 | * </p> |
||
5664 | * |
||
5665 | * @return array |
||
5666 | * |
||
5667 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
5668 | * @psalm-mutation-free |
||
5669 | */ |
||
5670 | 943 | public function toArray( |
|
5695 | |||
5696 | /** |
||
5697 | * Get the current array from the "Arrayy"-object as list. |
||
5698 | * |
||
5699 | * @param bool $convertAllArrayyElements <p> |
||
5700 | * Convert all Child-"Arrayy" objects also to arrays. |
||
5701 | * </p> |
||
5702 | * |
||
5703 | * @return array |
||
5704 | * |
||
5705 | * @psalm-return list<array<TKey,T>> |
||
5706 | * @psalm-mutation-free |
||
5707 | */ |
||
5708 | 1 | public function toList(bool $convertAllArrayyElements = false): array |
|
5715 | |||
5716 | /** |
||
5717 | * Convert the current array to JSON. |
||
5718 | * |
||
5719 | * @param int $options [optional] <p>e.g. JSON_PRETTY_PRINT</p> |
||
5720 | * @param int $depth [optional] <p>Set the maximum depth. Must be greater than zero.</p> |
||
5721 | * |
||
5722 | * @return string |
||
5723 | */ |
||
5724 | 12 | public function toJson(int $options = 0, int $depth = 512): string |
|
5733 | |||
5734 | /** |
||
5735 | * @param string[]|null $items [optional] |
||
5736 | * @param string[] $helper [optional] |
||
5737 | * |
||
5738 | * @return static|static[] |
||
5739 | * |
||
5740 | * @psalm-return static<int, static<TKey,T>> |
||
5741 | */ |
||
5742 | 1 | public function toPermutation(array $items = null, array $helper = []): self |
|
5776 | |||
5777 | /** |
||
5778 | * Implodes array to a string with specified separator. |
||
5779 | * |
||
5780 | * @param string $separator [optional] <p>The element's separator.</p> |
||
5781 | * |
||
5782 | * @return string |
||
5783 | * <p>The string representation of array, separated by ",".</p> |
||
5784 | */ |
||
5785 | 19 | public function toString(string $separator = ','): string |
|
5789 | |||
5790 | /** |
||
5791 | * Return a duplicate free copy of the current array. |
||
5792 | * |
||
5793 | * @return $this |
||
5794 | * <p>(Mutable)</p> |
||
5795 | * |
||
5796 | * @psalm-return static<TKey,T> |
||
5797 | */ |
||
5798 | 13 | public function unique(): self |
|
5820 | |||
5821 | /** |
||
5822 | * Return a duplicate free copy of the current array. (with the old keys) |
||
5823 | * |
||
5824 | * @return $this |
||
5825 | * <p>(Mutable)</p> |
||
5826 | * |
||
5827 | * @psalm-return static<TKey,T> |
||
5828 | */ |
||
5829 | 11 | public function uniqueKeepIndex(): self |
|
5855 | |||
5856 | /** |
||
5857 | * alias: for "Arrayy->unique()" |
||
5858 | * |
||
5859 | * @return static |
||
5860 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
5861 | * |
||
5862 | * @see Arrayy::unique() |
||
5863 | * |
||
5864 | * @psalm-return static<TKey,T> |
||
5865 | */ |
||
5866 | 10 | public function uniqueNewIndex(): self |
|
5870 | |||
5871 | /** |
||
5872 | * Prepends one or more values to the beginning of array at once. |
||
5873 | * |
||
5874 | * @param array ...$args |
||
5875 | * |
||
5876 | * @return $this |
||
5877 | * <p>(Mutable) Return this Arrayy object, with prepended elements to the beginning of array.</p> |
||
5878 | * |
||
5879 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$args |
||
5880 | * @psalm-return static<TKey,T> |
||
5881 | */ |
||
5882 | 4 | public function unshift(...$args): self |
|
5890 | |||
5891 | /** |
||
5892 | * Tests whether the given closure return something valid for all elements of this array. |
||
5893 | * |
||
5894 | * @param \Closure $closure the predicate |
||
5895 | * |
||
5896 | * @return bool |
||
5897 | * <p>TRUE, if the predicate yields TRUE for all elements, FALSE otherwise.</p> |
||
5898 | */ |
||
5899 | 1 | View Code Duplication | public function validate(\Closure $closure): bool |
5909 | |||
5910 | /** |
||
5911 | * Get all values from a array. |
||
5912 | * |
||
5913 | * @return static |
||
5914 | * <p>(Immutable)</p> |
||
5915 | * |
||
5916 | * @psalm-return static<TKey,T> |
||
5917 | * @psalm-mutation-free |
||
5918 | */ |
||
5919 | 2 | public function values(): self |
|
5932 | |||
5933 | /** |
||
5934 | * Apply the given function to every element in the array, discarding the results. |
||
5935 | * |
||
5936 | * @param callable $callable |
||
5937 | * @param bool $recursive <p>Whether array will be walked recursively or no</p> |
||
5938 | * |
||
5939 | * @return $this |
||
5940 | * <p>(Mutable) Return this Arrayy object, with modified elements.</p> |
||
5941 | * |
||
5942 | * @psalm-return static<TKey,T> |
||
5943 | */ |
||
5944 | 12 | public function walk($callable, bool $recursive = false): self |
|
5958 | |||
5959 | /** |
||
5960 | * Returns a collection of matching items. |
||
5961 | * |
||
5962 | * @param string $keyOrPropertyOrMethod the property or method to evaluate |
||
5963 | * @param mixed $value the value to match |
||
5964 | * |
||
5965 | * @throws \InvalidArgumentException if property or method is not defined |
||
5966 | * |
||
5967 | * @return static |
||
5968 | * |
||
5969 | * @psalm-param T $value |
||
5970 | * @psalm-return static<TKey,T> |
||
5971 | */ |
||
5972 | 1 | public function where(string $keyOrPropertyOrMethod, $value): self |
|
5985 | |||
5986 | /** |
||
5987 | * Convert an array into a object. |
||
5988 | * |
||
5989 | * @param array $array |
||
5990 | * |
||
5991 | * @return \stdClass |
||
5992 | * |
||
5993 | * @psalm-param array<mixed,mixed> $array |
||
5994 | */ |
||
5995 | 4 | final protected static function arrayToObject(array $array = []): \stdClass |
|
6014 | |||
6015 | /** |
||
6016 | * @param array|\Generator|null $input <p> |
||
6017 | * An array containing keys to return. |
||
6018 | * </p> |
||
6019 | * @param mixed|null $search_values [optional] <p> |
||
6020 | * If specified, then only keys containing these values are returned. |
||
6021 | * </p> |
||
6022 | * @param bool $strict [optional] <p> |
||
6023 | * Determines if strict comparison (===) should be used during the |
||
6024 | * search. |
||
6025 | * </p> |
||
6026 | * |
||
6027 | * @return array |
||
6028 | * <p>an array of all the keys in input</p> |
||
6029 | * |
||
6030 | * @psalm-param array<mixed,mixed>|\Generator<TKey,T>|null $input |
||
6031 | * @psalm-return array<TKey|mixed> |
||
6032 | * @psalm-mutation-free |
||
6033 | */ |
||
6034 | 11 | protected function array_keys_recursive( |
|
6095 | |||
6096 | /** |
||
6097 | * @param mixed $path |
||
6098 | * @param callable $callable |
||
6099 | * @param array|null $currentOffset |
||
6100 | * |
||
6101 | * @return void |
||
6102 | * |
||
6103 | * @psalm-param array<mixed,mixed>|array<TKey,T>|null $currentOffset |
||
6104 | * @psalm-mutation-free |
||
6105 | */ |
||
6106 | 11 | protected function callAtPath($path, $callable, &$currentOffset = null) |
|
6135 | |||
6136 | /** |
||
6137 | * Extracts the value of the given property or method from the object. |
||
6138 | * |
||
6139 | * @param static $object <p>The object to extract the value from.</p> |
||
6140 | * @param string $keyOrPropertyOrMethod <p>The property or method for which the |
||
6141 | * value should be extracted.</p> |
||
6142 | * |
||
6143 | * @throws \InvalidArgumentException if the method or property is not defined |
||
6144 | * |
||
6145 | * @return mixed |
||
6146 | * <p>The value extracted from the specified property or method.</p> |
||
6147 | * |
||
6148 | * @psalm-param self<TKey,T> $object |
||
6149 | */ |
||
6150 | 2 | final protected function extractValue(self $object, string $keyOrPropertyOrMethod) |
|
6172 | |||
6173 | /** |
||
6174 | * create a fallback for array |
||
6175 | * |
||
6176 | * 1. use the current array, if it's a array |
||
6177 | * 2. fallback to empty array, if there is nothing |
||
6178 | * 3. call "getArray()" on object, if there is a "Arrayy"-object |
||
6179 | * 4. call "createFromObject()" on object, if there is a "\Traversable"-object |
||
6180 | * 5. call "__toArray()" on object, if the method exists |
||
6181 | * 6. cast a string or object with "__toString()" into an array |
||
6182 | * 7. throw a "InvalidArgumentException"-Exception |
||
6183 | * |
||
6184 | * @param mixed $data |
||
6185 | * |
||
6186 | * @throws \InvalidArgumentException |
||
6187 | * |
||
6188 | * @return array |
||
6189 | * |
||
6190 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
6191 | */ |
||
6192 | 1196 | protected function fallbackForArray(&$data): array |
|
6202 | |||
6203 | /** |
||
6204 | * @param bool $preserveKeys <p> |
||
6205 | * e.g.: A generator maybe return the same key more then once, |
||
6206 | * so maybe you will ignore the keys. |
||
6207 | * </p> |
||
6208 | * |
||
6209 | * @return bool |
||
6210 | * |
||
6211 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
6212 | * @psalm-mutation-free :/ |
||
6213 | */ |
||
6214 | 1108 | protected function generatorToArray(bool $preserveKeys = true) |
|
6225 | |||
6226 | /** |
||
6227 | * Get correct PHP constant for direction. |
||
6228 | * |
||
6229 | * @param int|string $direction |
||
6230 | * |
||
6231 | * @return int |
||
6232 | * @psalm-mutation-free |
||
6233 | */ |
||
6234 | 43 | protected function getDirection($direction): int |
|
6256 | |||
6257 | /** |
||
6258 | * @return TypeCheckInterface[] |
||
6259 | * |
||
6260 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
6261 | */ |
||
6262 | 22 | protected function getPropertiesFromPhpDoc() |
|
6293 | |||
6294 | /** |
||
6295 | * @param mixed $glue |
||
6296 | * @param mixed $pieces |
||
6297 | * @param bool $useKeys |
||
6298 | * |
||
6299 | * @return string |
||
6300 | * @psalm-mutation-free |
||
6301 | */ |
||
6302 | 36 | protected function implode_recursive( |
|
6335 | |||
6336 | /** |
||
6337 | * @param mixed $needle <p> |
||
6338 | * The searched value. |
||
6339 | * </p> |
||
6340 | * <p> |
||
6341 | * If needle is a string, the comparison is done |
||
6342 | * in a case-sensitive manner. |
||
6343 | * </p> |
||
6344 | * @param array|\Generator|null $haystack <p> |
||
6345 | * The array. |
||
6346 | * </p> |
||
6347 | * @param bool $strict [optional] <p> |
||
6348 | * If the third parameter strict is set to true |
||
6349 | * then the in_array function will also check the |
||
6350 | * types of the |
||
6351 | * needle in the haystack. |
||
6352 | * </p> |
||
6353 | * |
||
6354 | * @return bool |
||
6355 | * <p>true if needle is found in the array, false otherwise</p> |
||
6356 | * |
||
6357 | * @psalm-param array<mixed,mixed>|\Generator<TKey,T>|null $haystack |
||
6358 | * @psalm-mutation-free |
||
6359 | */ |
||
6360 | 19 | protected function in_array_recursive($needle, $haystack = null, $strict = true): bool |
|
6385 | |||
6386 | /** |
||
6387 | * @param mixed $data |
||
6388 | * |
||
6389 | * @return array|null |
||
6390 | * |
||
6391 | * @psalm-return array<mixed,mixed>|array<TKey,T>|null |
||
6392 | */ |
||
6393 | 1196 | protected function internalGetArray(&$data) |
|
6444 | |||
6445 | /** |
||
6446 | * Internal mechanics of remove method. |
||
6447 | * |
||
6448 | * @param mixed $key |
||
6449 | * |
||
6450 | * @return bool |
||
6451 | */ |
||
6452 | 21 | protected function internalRemove($key): bool |
|
6485 | |||
6486 | /** |
||
6487 | * Internal mechanic of set method. |
||
6488 | * |
||
6489 | * @param int|string|null $key |
||
6490 | * @param mixed $value |
||
6491 | * @param bool $checkProperties |
||
6492 | * |
||
6493 | * @return bool |
||
6494 | */ |
||
6495 | 1047 | protected function internalSet( |
|
6554 | |||
6555 | /** |
||
6556 | * Convert a object into an array. |
||
6557 | * |
||
6558 | * @param mixed|object $object |
||
6559 | * |
||
6560 | * @return array|mixed |
||
6561 | * |
||
6562 | * @psalm-mutation-free |
||
6563 | */ |
||
6564 | 5 | protected static function objectToArray($object) |
|
6577 | |||
6578 | /** |
||
6579 | * @param array $data |
||
6580 | * @param bool $checkPropertiesInConstructor |
||
6581 | * |
||
6582 | * @return void |
||
6583 | * |
||
6584 | * @psalm-param array<mixed,T> $data |
||
6585 | */ |
||
6586 | 1194 | protected function setInitialValuesAndProperties(array &$data, bool $checkPropertiesInConstructor) |
|
6631 | |||
6632 | /** |
||
6633 | * sorting keys |
||
6634 | * |
||
6635 | * @param array $elements |
||
6636 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
6637 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
6638 | * <strong>SORT_NATURAL</strong></p> |
||
6639 | * |
||
6640 | * @return $this |
||
6641 | * <p>(Mutable) Return this Arrayy object.</p> |
||
6642 | * |
||
6643 | * @psalm-param array<mixed,mixed>|array<mixed|TKey,T> $elements |
||
6644 | * @psalm-return static<TKey,T> |
||
6645 | */ |
||
6646 | 18 | protected function sorterKeys( |
|
6667 | |||
6668 | /** |
||
6669 | * @param array $elements <p>Warning: used as reference</p> |
||
6670 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
6671 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
6672 | * <strong>SORT_NATURAL</strong></p> |
||
6673 | * @param bool $keepKeys |
||
6674 | * |
||
6675 | * @return $this |
||
6676 | * <p>(Mutable) Return this Arrayy object.</p> |
||
6677 | * |
||
6678 | * @psalm-param array<mixed,mixed>|array<mixed|TKey,T> $elements |
||
6679 | * @psalm-return static<TKey,T> |
||
6680 | */ |
||
6681 | 24 | protected function sorting(array &$elements, $direction = \SORT_ASC, int $strategy = \SORT_REGULAR, bool $keepKeys = false): self |
|
6711 | |||
6712 | /** |
||
6713 | * @param array $array |
||
6714 | * |
||
6715 | * @return array |
||
6716 | * |
||
6717 | * @psalm-mutation-free |
||
6718 | */ |
||
6719 | 25 | private function getArrayRecursiveHelperArrayy(array $array) |
|
6741 | |||
6742 | /** |
||
6743 | * @param int|string|null $key |
||
6744 | * @param mixed $value |
||
6745 | * |
||
6746 | * @return void |
||
6747 | */ |
||
6748 | 109 | private function checkType($key, $value) |
|
6766 | } |
||
6767 |
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..