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 |
||
26 | class Arrayy extends \ArrayObject implements \IteratorAggregate, \ArrayAccess, \Serializable, \JsonSerializable, \Countable |
||
27 | { |
||
28 | const ARRAYY_HELPER_TYPES_FOR_ALL_PROPERTIES = '!!!!Arrayy_Helper_Types_For_All_Properties!!!!'; |
||
29 | |||
30 | /** |
||
31 | * @var array |
||
32 | * |
||
33 | * @psalm-var array<TKey,T> |
||
34 | */ |
||
35 | protected $array = []; |
||
36 | |||
37 | /** |
||
38 | * @var \Arrayy\ArrayyRewindableGenerator|null |
||
39 | * |
||
40 | * @psalm-var \Arrayy\ArrayyRewindableGenerator<TKey,T>|null |
||
41 | */ |
||
42 | protected $generator; |
||
43 | |||
44 | /** |
||
45 | * @var string |
||
46 | * |
||
47 | * @psalm-var class-string<\Arrayy\ArrayyIterator> |
||
48 | */ |
||
49 | protected $iteratorClass = ArrayyIterator::class; |
||
50 | |||
51 | /** |
||
52 | * @var string |
||
53 | */ |
||
54 | protected $pathSeparator = '.'; |
||
55 | |||
56 | /** |
||
57 | * @var bool |
||
58 | */ |
||
59 | protected $checkPropertyTypes = false; |
||
60 | |||
61 | /** |
||
62 | * @var bool |
||
63 | */ |
||
64 | protected $checkForMissingPropertiesInConstructor = false; |
||
65 | |||
66 | /** |
||
67 | * @var bool |
||
68 | */ |
||
69 | protected $checkPropertiesMismatchInConstructor = false; |
||
70 | |||
71 | /** |
||
72 | * @var bool |
||
73 | */ |
||
74 | protected $checkPropertiesMismatch = true; |
||
75 | |||
76 | /** |
||
77 | * @var array<TypeCheckInterface>|\Arrayy\Type\TypeInterface|TypeCheckArray<TypeCheckInterface> |
||
78 | */ |
||
79 | protected $properties = []; |
||
80 | |||
81 | /** |
||
82 | * Initializes |
||
83 | * |
||
84 | * @param mixed $data <p> |
||
85 | * Should be an array or a generator, otherwise it will try |
||
86 | * to convert it into an array. |
||
87 | * </p> |
||
88 | * @param string $iteratorClass optional <p> |
||
89 | * You can overwrite the ArrayyIterator, but mostly you don't |
||
90 | * need this option. |
||
91 | * </p> |
||
92 | * @param bool $checkPropertiesInConstructor optional <p> |
||
93 | * You need to extend the "Arrayy"-class and you need to set |
||
94 | * the $checkPropertiesMismatchInConstructor class property |
||
95 | * to |
||
96 | * true, otherwise this option didn't not work anyway. |
||
97 | * </p> |
||
98 | * |
||
99 | * @psalm-param class-string<\Arrayy\ArrayyIterator> $iteratorClass |
||
100 | */ |
||
101 | 1066 | public function __construct( |
|
102 | $data = [], |
||
103 | string $iteratorClass = ArrayyIterator::class, |
||
104 | bool $checkPropertiesInConstructor = true |
||
105 | ) { |
||
106 | 1066 | $data = $this->fallbackForArray($data); |
|
107 | |||
108 | // used only for serialize + unserialize, all other methods are overwritten |
||
109 | 1064 | parent::__construct([], 0, $iteratorClass); |
|
110 | |||
111 | 1064 | $this->setInitialValuesAndProperties($data, $checkPropertiesInConstructor); |
|
112 | |||
113 | 1057 | $this->setIteratorClass($iteratorClass); |
|
114 | 1057 | } |
|
115 | |||
116 | /** |
||
117 | * Call object as function. |
||
118 | * |
||
119 | * @param mixed $key |
||
120 | * |
||
121 | * @return mixed |
||
122 | */ |
||
123 | 1 | public function __invoke($key = null) |
|
124 | { |
||
125 | 1 | if ($key !== null) { |
|
126 | 1 | $this->generatorToArray(); |
|
127 | |||
128 | 1 | return $this->array[$key] ?? false; |
|
129 | } |
||
130 | |||
131 | return $this->getArray(); |
||
132 | } |
||
133 | |||
134 | /** |
||
135 | * Whether or not an element exists by key. |
||
136 | * |
||
137 | * @param mixed $key |
||
138 | * |
||
139 | * @return bool |
||
140 | * <p>True is the key/index exists, otherwise false.</p> |
||
141 | */ |
||
142 | public function __isset($key): bool |
||
146 | |||
147 | /** |
||
148 | * Assigns a value to the specified element. |
||
149 | * |
||
150 | * @param mixed $key |
||
151 | * @param mixed $value |
||
152 | * |
||
153 | * @return void |
||
154 | */ |
||
155 | 2 | public function __set($key, $value) |
|
156 | { |
||
157 | 2 | $this->internalSet($key, $value); |
|
158 | 2 | } |
|
159 | |||
160 | /** |
||
161 | * magic to string |
||
162 | * |
||
163 | * @return string |
||
164 | */ |
||
165 | 15 | public function __toString(): string |
|
166 | { |
||
167 | 15 | return $this->toString(); |
|
168 | } |
||
169 | |||
170 | /** |
||
171 | * Unset element by key. |
||
172 | * |
||
173 | * @param mixed $key |
||
174 | */ |
||
175 | public function __unset($key) |
||
176 | { |
||
177 | $this->internalRemove($key); |
||
178 | } |
||
179 | |||
180 | /** |
||
181 | * Get a value by key. |
||
182 | * |
||
183 | * @param mixed $key |
||
184 | * |
||
185 | * @return mixed |
||
186 | * <p>Get a Value from the current array.</p> |
||
187 | */ |
||
188 | 4 | public function &__get($key) |
|
189 | { |
||
190 | 4 | $return = $this->get($key); |
|
191 | |||
192 | 4 | if (\is_array($return) === true) { |
|
193 | return static::create($return, $this->iteratorClass, false); |
||
194 | } |
||
195 | |||
196 | 4 | return $return; |
|
197 | } |
||
198 | |||
199 | /** |
||
200 | * alias: for "Arrayy->append()" |
||
201 | * |
||
202 | * @param mixed $value |
||
203 | * |
||
204 | * @return static |
||
205 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
206 | * |
||
207 | * @see Arrayy::append() |
||
208 | * |
||
209 | * @psalm-param T $value |
||
210 | * @psalm-return static<TKey,T> |
||
211 | */ |
||
212 | 3 | public function add($value) |
|
216 | |||
217 | /** |
||
218 | * Append a (key) + value to the current array. |
||
219 | * |
||
220 | * @param mixed $value |
||
221 | * @param mixed $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 | 13 | public function append($value, $key = null): self |
|
253 | |||
254 | /** |
||
255 | * Sort the entries by value. |
||
256 | * |
||
257 | * @param int $sort_flags [optional] <p> |
||
258 | * You may modify the behavior of the sort using the optional |
||
259 | * parameter sort_flags, for details |
||
260 | * see sort. |
||
261 | * </p> |
||
262 | * |
||
263 | * @return static |
||
264 | * <p>(Mutable) Return this Arrayy object.</p> |
||
265 | * |
||
266 | * @psalm-return static<TKey,T> |
||
267 | */ |
||
268 | 4 | public function asort(int $sort_flags = 0): self |
|
276 | |||
277 | /** |
||
278 | * Counts all elements in an array, or something in an object. |
||
279 | * |
||
280 | * <p> |
||
281 | * For objects, if you have SPL installed, you can hook into count() by implementing interface {@see Countable}. |
||
282 | * The interface has exactly one method, {@see Countable::count()}, which returns the return value for the count() |
||
283 | * function. Please see the {@see Array} section of the manual for a detailed explanation of how arrays are |
||
284 | * implemented and used in PHP. |
||
285 | * </p> |
||
286 | * |
||
287 | * @see http://php.net/manual/en/function.count.php |
||
288 | * |
||
289 | * @param int $mode [optional] If the optional mode parameter is set to |
||
290 | * COUNT_RECURSIVE (or 1), count |
||
291 | * will recursively count the array. This is particularly useful for |
||
292 | * counting all the elements of a multidimensional array. count does not detect infinite recursion. |
||
293 | * |
||
294 | * @return int |
||
295 | * <p> |
||
296 | * The number of elements in var, which is |
||
297 | * typically an array, since anything else will have one |
||
298 | * element. |
||
299 | * </p> |
||
300 | * <p> |
||
301 | * If var is not an array or an object with |
||
302 | * implemented Countable interface, |
||
303 | * 1 will be returned. |
||
304 | * There is one exception, if var is &null;, |
||
305 | * 0 will be returned. |
||
306 | * </p> |
||
307 | * <p> |
||
308 | * Caution: count may return 0 for a variable that isn't set, |
||
309 | * but it may also return 0 for a variable that has been initialized with an |
||
310 | * empty array. Use isset to test if a variable is set. |
||
311 | * </p> |
||
312 | */ |
||
313 | 145 | public function count(int $mode = \COUNT_NORMAL): int |
|
325 | |||
326 | /** |
||
327 | * Exchange the array for another one. |
||
328 | * |
||
329 | * @param array|static $data |
||
330 | * |
||
331 | * @return array |
||
332 | * |
||
333 | * @psalm-param array<TKey,T>|self<TKey,T> $data |
||
334 | * @psalm-return array<TKey,T> |
||
335 | */ |
||
336 | 1 | public function exchangeArray($data): array |
|
342 | |||
343 | /** |
||
344 | * Creates a copy of the ArrayyObject. |
||
345 | * |
||
346 | * @return array |
||
347 | * |
||
348 | * @psalm-return array<TKey,T> |
||
349 | */ |
||
350 | 5 | public function getArrayCopy(): array |
|
356 | |||
357 | /** |
||
358 | * Returns a new iterator, thus implementing the \Iterator interface. |
||
359 | * |
||
360 | * @return \Iterator<mixed, mixed> |
||
|
|||
361 | * <p>An iterator for the values in the array.</p> |
||
362 | */ |
||
363 | 24 | public function getIterator(): \Iterator |
|
377 | |||
378 | /** |
||
379 | * Gets the iterator classname for the ArrayObject. |
||
380 | * |
||
381 | * @return string |
||
382 | * |
||
383 | * @psalm-return class-string |
||
384 | */ |
||
385 | 23 | public function getIteratorClass(): string |
|
389 | |||
390 | /** |
||
391 | * Sort the entries by key |
||
392 | * |
||
393 | * @param int $sort_flags [optional] <p> |
||
394 | * You may modify the behavior of the sort using the optional |
||
395 | * parameter sort_flags, for details |
||
396 | * see sort. |
||
397 | * </p> |
||
398 | * |
||
399 | * @return static |
||
400 | * <p>(Mutable) Return this Arrayy object.</p> |
||
401 | * |
||
402 | * @psalm-return static<TKey,T> |
||
403 | */ |
||
404 | 4 | public function ksort(int $sort_flags = 0): self |
|
412 | |||
413 | /** |
||
414 | * Sort an array using a case insensitive "natural order" algorithm |
||
415 | * |
||
416 | * @return static |
||
417 | * <p>(Mutable) Return this Arrayy object.</p> |
||
418 | * |
||
419 | * @psalm-return static<TKey,T> |
||
420 | */ |
||
421 | public function natcasesort(): self |
||
429 | |||
430 | /** |
||
431 | * Sort entries using a "natural order" algorithm |
||
432 | * |
||
433 | * @return static |
||
434 | * <p>(Mutable) Return this Arrayy object.</p> |
||
435 | * |
||
436 | * @psalm-return static<TKey,T> |
||
437 | */ |
||
438 | 1 | public function natsort(): self |
|
446 | |||
447 | /** |
||
448 | * Whether or not an offset exists. |
||
449 | * |
||
450 | * @param bool|int|string $offset |
||
451 | * |
||
452 | * @return bool |
||
453 | * |
||
454 | * @noinspection PhpSillyAssignmentInspection |
||
455 | */ |
||
456 | 130 | public function offsetExists($offset): bool |
|
513 | |||
514 | /** |
||
515 | * Returns the value at specified offset. |
||
516 | * |
||
517 | * @param int|string $offset |
||
518 | * |
||
519 | * @return mixed |
||
520 | * <p>Will return null if the offset did not exists.</p> |
||
521 | */ |
||
522 | 101 | public function offsetGet($offset) |
|
526 | |||
527 | /** |
||
528 | * Assigns a value to the specified offset + check the type. |
||
529 | * |
||
530 | * @param int|string|null $offset |
||
531 | * @param mixed $value |
||
532 | * |
||
533 | * @return void |
||
534 | */ |
||
535 | 21 | public function offsetSet($offset, $value) |
|
553 | |||
554 | /** |
||
555 | * Unset an offset. |
||
556 | * |
||
557 | * @param int|string $offset |
||
558 | * |
||
559 | * @return void |
||
560 | */ |
||
561 | 12 | public function offsetUnset($offset) |
|
598 | |||
599 | /** |
||
600 | * Serialize the current "Arrayy"-object. |
||
601 | * |
||
602 | * @return string |
||
603 | */ |
||
604 | 2 | public function serialize(): string |
|
614 | |||
615 | /** |
||
616 | * Sets the iterator classname for the current "Arrayy"-object. |
||
617 | * |
||
618 | * @param string $iteratorClass |
||
619 | * |
||
620 | * @throws \InvalidArgumentException |
||
621 | * |
||
622 | * @return void |
||
623 | * |
||
624 | * @psalm-param class-string<\Arrayy\ArrayyIterator> $iteratorClass |
||
625 | */ |
||
626 | 1057 | public function setIteratorClass($iteratorClass) |
|
645 | |||
646 | /** |
||
647 | * Sort the entries with a user-defined comparison function and maintain key association. |
||
648 | * |
||
649 | * @param callable $function |
||
650 | * |
||
651 | * @throws \InvalidArgumentException |
||
652 | * |
||
653 | * @return static |
||
654 | * <p>(Mutable) Return this Arrayy object.</p> |
||
655 | * |
||
656 | * @psalm-return static<TKey,T> |
||
657 | */ |
||
658 | View Code Duplication | public function uasort($function): self |
|
670 | |||
671 | /** |
||
672 | * Sort the entries by keys using a user-defined comparison function. |
||
673 | * |
||
674 | * @param callable $function |
||
675 | * |
||
676 | * @throws \InvalidArgumentException |
||
677 | * |
||
678 | * @return static |
||
679 | * <p>(Mutable) Return this Arrayy object.</p> |
||
680 | * |
||
681 | * @psalm-return static<TKey,T> |
||
682 | */ |
||
683 | 5 | public function uksort($function): self |
|
687 | |||
688 | /** |
||
689 | * Unserialize an string and return the instance of the "Arrayy"-class. |
||
690 | * |
||
691 | * @param string $string |
||
692 | * |
||
693 | * @return static |
||
694 | * |
||
695 | * @psalm-return static<TKey,T> |
||
696 | */ |
||
697 | 2 | public function unserialize($string): self |
|
707 | |||
708 | /** |
||
709 | * Append a (key) + values to the current array. |
||
710 | * |
||
711 | * @param array $values |
||
712 | * @param mixed $key |
||
713 | * |
||
714 | * @return static |
||
715 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
716 | * |
||
717 | * @psalm-param array<mixed,T> $values |
||
718 | * @psalm-param TKey|null $key |
||
719 | * @psalm-return static<TKey,T> |
||
720 | */ |
||
721 | 1 | public function appendArrayValues(array $values, $key = null) |
|
747 | |||
748 | /** |
||
749 | * Add a suffix to each key. |
||
750 | * |
||
751 | * @param mixed $prefix |
||
752 | * |
||
753 | * @return static |
||
754 | * <p>(Immutable) Return an Arrayy object, with the prefixed keys.</p> |
||
755 | * |
||
756 | * @psalm-return static<TKey,T> |
||
757 | */ |
||
758 | 10 | View Code Duplication | public function appendToEachKey($prefix): self |
777 | |||
778 | /** |
||
779 | * Add a prefix to each value. |
||
780 | * |
||
781 | * @param mixed $prefix |
||
782 | * |
||
783 | * @return static |
||
784 | * <p>(Immutable) Return an Arrayy object, with the prefixed values.</p> |
||
785 | * |
||
786 | * @psalm-return static<TKey,T> |
||
787 | */ |
||
788 | 10 | View Code Duplication | public function appendToEachValue($prefix): self |
807 | |||
808 | /** |
||
809 | * Sort an array in reverse order and maintain index association. |
||
810 | * |
||
811 | * @return static |
||
812 | * <p>(Mutable) Return this Arrayy object.</p> |
||
813 | * |
||
814 | * @psalm-return static<TKey,T> |
||
815 | */ |
||
816 | 10 | public function arsort(): self |
|
824 | |||
825 | /** |
||
826 | * Iterate over the current array and execute a callback for each loop. |
||
827 | * |
||
828 | * @param \Closure $closure |
||
829 | * |
||
830 | * @return static |
||
831 | * <p>(Immutable)</p> |
||
832 | * |
||
833 | * @psalm-return static<TKey,T> |
||
834 | */ |
||
835 | 2 | public function at(\Closure $closure): self |
|
849 | |||
850 | /** |
||
851 | * Returns the average value of the current array. |
||
852 | * |
||
853 | * @param int $decimals <p>The number of decimal-numbers to return.</p> |
||
854 | * |
||
855 | * @return float|int |
||
856 | * <p>The average value.</p> |
||
857 | */ |
||
858 | 10 | public function average($decimals = 0) |
|
872 | |||
873 | /** |
||
874 | * Changes all keys in an array. |
||
875 | * |
||
876 | * @param int $case [optional] <p> Either <strong>CASE_UPPER</strong><br /> |
||
877 | * or <strong>CASE_LOWER</strong> (default)</p> |
||
878 | * |
||
879 | * @return static |
||
880 | * <p>(Immutable)</p> |
||
881 | * |
||
882 | * @psalm-return static<TKey,T> |
||
883 | */ |
||
884 | 1 | public function changeKeyCase(int $case = \CASE_LOWER): self |
|
911 | |||
912 | /** |
||
913 | * Change the path separator of the array wrapper. |
||
914 | * |
||
915 | * By default, the separator is: "." |
||
916 | * |
||
917 | * @param string $separator <p>Separator to set.</p> |
||
918 | * |
||
919 | * @return static |
||
920 | * <p>Mutable</p> |
||
921 | * |
||
922 | * @psalm-return static<TKey,T> |
||
923 | */ |
||
924 | 11 | public function changeSeparator($separator): self |
|
930 | |||
931 | /** |
||
932 | * Create a chunked version of the current array. |
||
933 | * |
||
934 | * @param int $size <p>Size of each chunk.</p> |
||
935 | * @param bool $preserveKeys <p>Whether array keys are preserved or no.</p> |
||
936 | * |
||
937 | * @return static |
||
938 | * <p>(Immutable) A new array of chunks from the original array.</p> |
||
939 | * |
||
940 | * @psalm-return static<TKey,T> |
||
941 | */ |
||
942 | 5 | public function chunk($size, $preserveKeys = false): self |
|
950 | |||
951 | /** |
||
952 | * Clean all falsy values from the current array. |
||
953 | * |
||
954 | * @return static |
||
955 | * <p>(Immutable)</p> |
||
956 | * |
||
957 | * @psalm-return static<TKey,T> |
||
958 | */ |
||
959 | 8 | public function clean(): self |
|
967 | |||
968 | /** |
||
969 | * WARNING!!! -> Clear the current array. |
||
970 | * |
||
971 | * @return static |
||
972 | * <p>(Mutable) Return this Arrayy object, with an empty array.</p> |
||
973 | * |
||
974 | * @psalm-return static<TKey,T> |
||
975 | */ |
||
976 | 5 | public function clear(): self |
|
983 | |||
984 | /** |
||
985 | * Check if an item is in the current array. |
||
986 | * |
||
987 | * @param float|int|string $value |
||
988 | * @param bool $recursive |
||
989 | * @param bool $strict |
||
990 | * |
||
991 | * @return bool |
||
992 | */ |
||
993 | 23 | public function contains($value, bool $recursive = false, bool $strict = true): bool |
|
1014 | |||
1015 | /** |
||
1016 | * Check if an (case-insensitive) string is in the current array. |
||
1017 | * |
||
1018 | * @param string $value |
||
1019 | * @param bool $recursive |
||
1020 | * |
||
1021 | * @return bool |
||
1022 | */ |
||
1023 | 26 | public function containsCaseInsensitive($value, $recursive = false): bool |
|
1048 | |||
1049 | /** |
||
1050 | * Check if the given key/index exists in the array. |
||
1051 | * |
||
1052 | * @param int|string $key <p>key/index to search for</p> |
||
1053 | * |
||
1054 | * @return bool |
||
1055 | * <p>Returns true if the given key/index exists in the array, false otherwise.</p> |
||
1056 | */ |
||
1057 | 4 | public function containsKey($key): bool |
|
1061 | |||
1062 | /** |
||
1063 | * Check if all given needles are present in the array as key/index. |
||
1064 | * |
||
1065 | * @param array $needles <p>The keys you are searching for.</p> |
||
1066 | * @param bool $recursive |
||
1067 | * |
||
1068 | * @return bool |
||
1069 | * <p>Returns true if all the given keys/indexes exists in the array, false otherwise.</p> |
||
1070 | * |
||
1071 | * @psalm-param array<mixed,mixed>|array<TKey> $needles |
||
1072 | */ |
||
1073 | 2 | public function containsKeys(array $needles, $recursive = false): bool |
|
1101 | |||
1102 | /** |
||
1103 | * Check if all given needles are present in the array as key/index. |
||
1104 | * |
||
1105 | * @param array $needles <p>The keys you are searching for.</p> |
||
1106 | * |
||
1107 | * @return bool |
||
1108 | * <p>Returns true if all the given keys/indexes exists in the array, false otherwise.</p> |
||
1109 | * |
||
1110 | * @psalm-param array<mixed,mixed>|array<TKey> $needles |
||
1111 | */ |
||
1112 | 1 | public function containsKeysRecursive(array $needles): bool |
|
1116 | |||
1117 | /** |
||
1118 | * alias: for "Arrayy->contains()" |
||
1119 | * |
||
1120 | * @param float|int|string $value |
||
1121 | * |
||
1122 | * @return bool |
||
1123 | * |
||
1124 | * @see Arrayy::contains() |
||
1125 | */ |
||
1126 | 9 | public function containsValue($value): bool |
|
1130 | |||
1131 | /** |
||
1132 | * alias: for "Arrayy->contains($value, true)" |
||
1133 | * |
||
1134 | * @param float|int|string $value |
||
1135 | * |
||
1136 | * @return bool |
||
1137 | * |
||
1138 | * @see Arrayy::contains() |
||
1139 | */ |
||
1140 | 18 | public function containsValueRecursive($value): bool |
|
1144 | |||
1145 | /** |
||
1146 | * Check if all given needles are present in the array. |
||
1147 | * |
||
1148 | * @param array $needles |
||
1149 | * |
||
1150 | * @return bool |
||
1151 | * <p>Returns true if all the given values exists in the array, false otherwise.</p> |
||
1152 | * |
||
1153 | * @psalm-param array<mixed>|array<T> $needles |
||
1154 | */ |
||
1155 | 1 | public function containsValues(array $needles): bool |
|
1161 | |||
1162 | /** |
||
1163 | * Counts all the values of an array |
||
1164 | * |
||
1165 | * @see http://php.net/manual/en/function.array-count-values.php |
||
1166 | * |
||
1167 | * @return static |
||
1168 | * <p> |
||
1169 | * (Immutable) |
||
1170 | * An associative Arrayy-object of values from input as |
||
1171 | * keys and their count as value. |
||
1172 | * </p> |
||
1173 | * |
||
1174 | * @psalm-return static<TKey,T> |
||
1175 | */ |
||
1176 | 7 | public function countValues(): self |
|
1180 | |||
1181 | /** |
||
1182 | * Creates an Arrayy object. |
||
1183 | * |
||
1184 | * @param mixed $data |
||
1185 | * @param string $iteratorClass |
||
1186 | * @param bool $checkPropertiesInConstructor |
||
1187 | * |
||
1188 | * @return static |
||
1189 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1190 | * |
||
1191 | * @psalm-param class-string<\Arrayy\ArrayyIterator> $iteratorClass |
||
1192 | * @psalm-return static<TKey,T> |
||
1193 | */ |
||
1194 | 670 | public static function create( |
|
1205 | |||
1206 | /** |
||
1207 | * WARNING: Creates an Arrayy object by reference. |
||
1208 | * |
||
1209 | * @param array $array |
||
1210 | * |
||
1211 | * @return static |
||
1212 | * <p>(Mutable) Return this Arrayy object.</p> |
||
1213 | * |
||
1214 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
1215 | * @psalm-return static<TKey,T> |
||
1216 | */ |
||
1217 | 1 | public function createByReference(array &$array = []): self |
|
1225 | |||
1226 | /** |
||
1227 | * Create an new instance from a callable function which will return an Generator. |
||
1228 | * |
||
1229 | * @param callable $generatorFunction |
||
1230 | * |
||
1231 | * @return static |
||
1232 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1233 | * |
||
1234 | * @psalm-param callable():\Generator<TKey,T> $generatorFunction |
||
1235 | * @psalm-return static<TKey,T> |
||
1236 | */ |
||
1237 | 5 | public static function createFromGeneratorFunction(callable $generatorFunction): self |
|
1241 | |||
1242 | /** |
||
1243 | * Create an new instance filled with a copy of values from a "Generator"-object. |
||
1244 | * |
||
1245 | * @param \Generator $generator |
||
1246 | * |
||
1247 | * @return static |
||
1248 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1249 | * |
||
1250 | * @psalm-param \Generator<TKey,T> $generator |
||
1251 | * @psalm-return static<TKey,T> |
||
1252 | */ |
||
1253 | 4 | public static function createFromGeneratorImmutable(\Generator $generator): self |
|
1257 | |||
1258 | /** |
||
1259 | * Create an new Arrayy object via JSON. |
||
1260 | * |
||
1261 | * @param string $json |
||
1262 | * |
||
1263 | * @return static |
||
1264 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1265 | * |
||
1266 | * @psalm-return static<TKey,T> |
||
1267 | */ |
||
1268 | 5 | public static function createFromJson(string $json): self |
|
1272 | |||
1273 | /** |
||
1274 | * Create an new instance filled with values from an object that is iterable. |
||
1275 | * |
||
1276 | * @param \Traversable $object <p>iterable object</p> |
||
1277 | * |
||
1278 | * @return static |
||
1279 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1280 | * |
||
1281 | * @psalm-param \Traversable<TKey,T> $object |
||
1282 | * @psalm-return static<TKey,T> |
||
1283 | */ |
||
1284 | 4 | public static function createFromObject(\Traversable $object): self |
|
1301 | |||
1302 | /** |
||
1303 | * Create an new instance filled with values from an object. |
||
1304 | * |
||
1305 | * @param object $object |
||
1306 | * |
||
1307 | * @return static |
||
1308 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1309 | * |
||
1310 | * @psalm-return static<TKey,T> |
||
1311 | */ |
||
1312 | 5 | public static function createFromObjectVars($object): self |
|
1316 | |||
1317 | /** |
||
1318 | * Create an new Arrayy object via string. |
||
1319 | * |
||
1320 | * @param string $str <p>The input string.</p> |
||
1321 | * @param string|null $delimiter <p>The boundary string.</p> |
||
1322 | * @param string|null $regEx <p>Use the $delimiter or the $regEx, so if $pattern is null, $delimiter will be |
||
1323 | * used.</p> |
||
1324 | * |
||
1325 | * @return static |
||
1326 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1327 | * |
||
1328 | * @psalm-return static<TKey,T> |
||
1329 | */ |
||
1330 | 10 | public static function createFromString(string $str, string $delimiter = null, string $regEx = null): self |
|
1359 | |||
1360 | /** |
||
1361 | * Create an new instance filled with a copy of values from a "Traversable"-object. |
||
1362 | * |
||
1363 | * @param \Traversable $traversable |
||
1364 | * |
||
1365 | * @return static |
||
1366 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1367 | * |
||
1368 | * @psalm-param \Traversable<TKey,T> $traversable |
||
1369 | * @psalm-return static<TKey,T> |
||
1370 | */ |
||
1371 | 1 | public static function createFromTraversableImmutable(\Traversable $traversable): self |
|
1375 | |||
1376 | /** |
||
1377 | * Create an new instance containing a range of elements. |
||
1378 | * |
||
1379 | * @param mixed $low <p>First value of the sequence.</p> |
||
1380 | * @param mixed $high <p>The sequence is ended upon reaching the end value.</p> |
||
1381 | * @param int $step <p>Used as the increment between elements in the sequence.</p> |
||
1382 | * |
||
1383 | * @return static |
||
1384 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1385 | * |
||
1386 | * @psalm-return static<TKey,T> |
||
1387 | */ |
||
1388 | 2 | public static function createWithRange($low, $high, int $step = 1): self |
|
1392 | |||
1393 | /** |
||
1394 | * Gets the element of the array at the current internal iterator position. |
||
1395 | * |
||
1396 | * @return false|mixed |
||
1397 | */ |
||
1398 | public function current() |
||
1402 | |||
1403 | /** |
||
1404 | * Custom sort by index via "uksort". |
||
1405 | * |
||
1406 | * @see http://php.net/manual/en/function.uksort.php |
||
1407 | * |
||
1408 | * @param callable $function |
||
1409 | * |
||
1410 | * @throws \InvalidArgumentException |
||
1411 | * |
||
1412 | * @return static |
||
1413 | * <p>(Mutable) Return this Arrayy object.</p> |
||
1414 | * |
||
1415 | * @psalm-return static<TKey,T> |
||
1416 | */ |
||
1417 | 5 | public function customSortKeys(callable $function): self |
|
1425 | |||
1426 | /** |
||
1427 | * Custom sort by value via "usort". |
||
1428 | * |
||
1429 | * @see http://php.net/manual/en/function.usort.php |
||
1430 | * |
||
1431 | * @param callable $function |
||
1432 | * |
||
1433 | * @throws \InvalidArgumentException |
||
1434 | * |
||
1435 | * @return static |
||
1436 | * <p>(Mutable) Return this Arrayy object.</p> |
||
1437 | * |
||
1438 | * @psalm-return static<TKey,T> |
||
1439 | */ |
||
1440 | 6 | View Code Duplication | public function customSortValues($function): self |
1452 | |||
1453 | /** |
||
1454 | * Delete the given key or keys. |
||
1455 | * |
||
1456 | * @param int|int[]|string|string[] $keyOrKeys |
||
1457 | * |
||
1458 | * @return void |
||
1459 | */ |
||
1460 | 4 | public function delete($keyOrKeys) |
|
1468 | |||
1469 | /** |
||
1470 | * Return values that are only in the current array. |
||
1471 | * |
||
1472 | * @param array ...$array |
||
1473 | * |
||
1474 | * @return static |
||
1475 | * <p>(Immutable)</p> |
||
1476 | * |
||
1477 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$array |
||
1478 | * @psalm-return static<TKey,T> |
||
1479 | */ |
||
1480 | 13 | public function diff(...$array): self |
|
1488 | |||
1489 | /** |
||
1490 | * Return values that are only in the current array. |
||
1491 | * |
||
1492 | * @param array ...$array |
||
1493 | * |
||
1494 | * @return static |
||
1495 | * <p>(Immutable)</p> |
||
1496 | * |
||
1497 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$array |
||
1498 | * @psalm-return static<TKey,T> |
||
1499 | */ |
||
1500 | 8 | public function diffKey(...$array): self |
|
1508 | |||
1509 | /** |
||
1510 | * Return values and Keys that are only in the current array. |
||
1511 | * |
||
1512 | * @param array $array |
||
1513 | * |
||
1514 | * @return static |
||
1515 | * <p>(Immutable)</p> |
||
1516 | * |
||
1517 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
1518 | * @psalm-return static<TKey,T> |
||
1519 | */ |
||
1520 | 8 | public function diffKeyAndValue(array $array = []): self |
|
1528 | |||
1529 | /** |
||
1530 | * Return values that are only in the current multi-dimensional array. |
||
1531 | * |
||
1532 | * @param array $array |
||
1533 | * @param array|null $helperVariableForRecursion <p>(only for internal usage)</p> |
||
1534 | * |
||
1535 | * @return static |
||
1536 | * <p>(Immutable)</p> |
||
1537 | * |
||
1538 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
1539 | * @psalm-param null|array<TKey,T> $helperVariableForRecursion |
||
1540 | * @psalm-return static<TKey,T> |
||
1541 | */ |
||
1542 | 1 | public function diffRecursive(array $array = [], $helperVariableForRecursion = null): self |
|
1577 | |||
1578 | /** |
||
1579 | * Return values that are only in the new $array. |
||
1580 | * |
||
1581 | * @param array $array |
||
1582 | * |
||
1583 | * @return static |
||
1584 | * <p>(Immutable)</p> |
||
1585 | * |
||
1586 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
1587 | * @psalm-return static<TKey,T> |
||
1588 | */ |
||
1589 | 8 | public function diffReverse(array $array = []): self |
|
1597 | |||
1598 | /** |
||
1599 | * Divide an array into two arrays. One with keys and the other with values. |
||
1600 | * |
||
1601 | * @return static |
||
1602 | * <p>(Immutable)</p> |
||
1603 | * |
||
1604 | * @psalm-return static<TKey,T> |
||
1605 | */ |
||
1606 | 1 | public function divide(): self |
|
1617 | |||
1618 | /** |
||
1619 | * Iterate over the current array and modify the array's value. |
||
1620 | * |
||
1621 | * @param \Closure $closure |
||
1622 | * |
||
1623 | * @return static |
||
1624 | * <p>(Immutable)</p> |
||
1625 | * |
||
1626 | * @psalm-return static<TKey,T> |
||
1627 | */ |
||
1628 | 5 | View Code Duplication | public function each(\Closure $closure): self |
1643 | |||
1644 | /** |
||
1645 | * Sets the internal iterator to the last element in the array and returns this element. |
||
1646 | * |
||
1647 | * @return mixed |
||
1648 | */ |
||
1649 | public function end() |
||
1653 | |||
1654 | /** |
||
1655 | * Check if a value is in the current array using a closure. |
||
1656 | * |
||
1657 | * @param \Closure $closure |
||
1658 | * |
||
1659 | * @return bool |
||
1660 | * <p>Returns true if the given value is found, false otherwise.</p> |
||
1661 | */ |
||
1662 | 4 | public function exists(\Closure $closure): bool |
|
1677 | |||
1678 | /** |
||
1679 | * Fill the array until "$num" with "$default" values. |
||
1680 | * |
||
1681 | * @param int $num |
||
1682 | * @param mixed $default |
||
1683 | * |
||
1684 | * @return static |
||
1685 | * <p>(Immutable)</p> |
||
1686 | * |
||
1687 | * @psalm-return static<TKey,T> |
||
1688 | */ |
||
1689 | 8 | public function fillWithDefaults(int $num, $default = null): self |
|
1712 | |||
1713 | /** |
||
1714 | * Find all items in an array that pass the truth test. |
||
1715 | * |
||
1716 | * @param \Closure|null $closure [optional] <p> |
||
1717 | * The callback function to use |
||
1718 | * </p> |
||
1719 | * <p> |
||
1720 | * If no callback is supplied, all entries of |
||
1721 | * input equal to false (see |
||
1722 | * converting to |
||
1723 | * boolean) will be removed. |
||
1724 | * </p> |
||
1725 | * @param int $flag [optional] <p> |
||
1726 | * Flag determining what arguments are sent to <i>callback</i>: |
||
1727 | * </p><ul> |
||
1728 | * <li> |
||
1729 | * <b>ARRAY_FILTER_USE_KEY</b> [1] - pass key as the only argument |
||
1730 | * to <i>callback</i> instead of the value</span> |
||
1731 | * </li> |
||
1732 | * <li> |
||
1733 | * <b>ARRAY_FILTER_USE_BOTH</b> [2] - pass both value and key as |
||
1734 | * arguments to <i>callback</i> instead of the value</span> |
||
1735 | * </li> |
||
1736 | * </ul> |
||
1737 | * |
||
1738 | * @return static |
||
1739 | * <p>(Immutable)</p> |
||
1740 | * |
||
1741 | * @psalm-param \Closure(T=,TKey=):bool|\Closure(T=):bool $closure |
||
1742 | * @psalm-return static<TKey,T> |
||
1743 | */ |
||
1744 | 12 | public function filter($closure = null, int $flag = \ARRAY_FILTER_USE_BOTH) |
|
1756 | |||
1757 | /** |
||
1758 | * Filters an array of objects (or a numeric array of associative arrays) based on the value of a particular |
||
1759 | * property within that. |
||
1760 | * |
||
1761 | * @param string $property |
||
1762 | * @param string|string[] $value |
||
1763 | * @param string $comparisonOp |
||
1764 | * <p> |
||
1765 | * 'eq' (equals),<br /> |
||
1766 | * 'gt' (greater),<br /> |
||
1767 | * 'gte' || 'ge' (greater or equals),<br /> |
||
1768 | * 'lt' (less),<br /> |
||
1769 | * 'lte' || 'le' (less or equals),<br /> |
||
1770 | * 'ne' (not equals),<br /> |
||
1771 | * 'contains',<br /> |
||
1772 | * 'notContains',<br /> |
||
1773 | * 'newer' (via strtotime),<br /> |
||
1774 | * 'older' (via strtotime),<br /> |
||
1775 | * </p> |
||
1776 | * |
||
1777 | * @return static |
||
1778 | * <p>(Immutable)</p> |
||
1779 | * |
||
1780 | * @psalm-return static<TKey,T> |
||
1781 | */ |
||
1782 | 1 | public function filterBy(string $property, $value, string $comparisonOp = null): self |
|
1851 | |||
1852 | /** |
||
1853 | * Find the first item in an array that passes the truth test, |
||
1854 | * otherwise return false |
||
1855 | * |
||
1856 | * @param \Closure $closure |
||
1857 | * |
||
1858 | * @return false|mixed |
||
1859 | * <p>Return false if we did not find the value.</p> |
||
1860 | */ |
||
1861 | 8 | View Code Duplication | public function find(\Closure $closure) |
1871 | |||
1872 | /** |
||
1873 | * find by ... |
||
1874 | * |
||
1875 | * @param string $property |
||
1876 | * @param string|string[] $value |
||
1877 | * @param string $comparisonOp |
||
1878 | * |
||
1879 | * @return static |
||
1880 | * <p>(Immutable)</p> |
||
1881 | * |
||
1882 | * @psalm-return static<TKey,T> |
||
1883 | */ |
||
1884 | 1 | public function findBy(string $property, $value, string $comparisonOp = 'eq'): self |
|
1888 | |||
1889 | /** |
||
1890 | * Get the first value from the current array. |
||
1891 | * |
||
1892 | * @return mixed |
||
1893 | * <p>Return null if there wasn't a element.</p> |
||
1894 | */ |
||
1895 | 21 | public function first() |
|
1904 | |||
1905 | /** |
||
1906 | * Get the first key from the current array. |
||
1907 | * |
||
1908 | * @return mixed |
||
1909 | * <p>Return null if there wasn't a element.</p> |
||
1910 | */ |
||
1911 | 28 | public function firstKey() |
|
1917 | |||
1918 | /** |
||
1919 | * Get the first value(s) from the current array. |
||
1920 | * And will return an empty array if there was no first entry. |
||
1921 | * |
||
1922 | * @param int|null $number <p>How many values you will take?</p> |
||
1923 | * |
||
1924 | * @return static |
||
1925 | * <p>(Immutable)</p> |
||
1926 | * |
||
1927 | * @psalm-return static<TKey,T> |
||
1928 | */ |
||
1929 | 37 | View Code Duplication | public function firstsImmutable(int $number = null): self |
1946 | |||
1947 | /** |
||
1948 | * Get the first value(s) from the current array. |
||
1949 | * And will return an empty array if there was no first entry. |
||
1950 | * |
||
1951 | * @param int|null $number <p>How many values you will take?</p> |
||
1952 | * |
||
1953 | * @return static |
||
1954 | * <p>(Immutable)</p> |
||
1955 | * |
||
1956 | * @psalm-return static<TKey,T> |
||
1957 | */ |
||
1958 | 3 | View Code Duplication | public function firstsKeys(int $number = null): self |
1975 | |||
1976 | /** |
||
1977 | * Get and rmove the first value(s) from the current array. |
||
1978 | * And will return an empty array if there was no first entry. |
||
1979 | * |
||
1980 | * @param int|null $number <p>How many values you will take?</p> |
||
1981 | * |
||
1982 | * @return static |
||
1983 | * <p>(Mutable)</p> |
||
1984 | * |
||
1985 | * @psalm-return static<TKey,T> |
||
1986 | */ |
||
1987 | 34 | public function firstsMutable(int $number = null): self |
|
2000 | |||
2001 | /** |
||
2002 | * Exchanges all keys with their associated values in an array. |
||
2003 | * |
||
2004 | * @return static |
||
2005 | * <p>(Immutable)</p> |
||
2006 | * |
||
2007 | * @psalm-return static<TKey,T> |
||
2008 | */ |
||
2009 | 1 | public function flip(): self |
|
2017 | |||
2018 | /** |
||
2019 | * Get a value from an array (optional using dot-notation). |
||
2020 | * |
||
2021 | * @param mixed $key <p>The key to look for.</p> |
||
2022 | * @param mixed $fallback <p>Value to fallback to.</p> |
||
2023 | * @param array $array <p>The array to get from, if it's set to "null" we use the current array from the |
||
2024 | * class.</p> |
||
2025 | * |
||
2026 | * @return mixed|static |
||
2027 | * |
||
2028 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
2029 | */ |
||
2030 | 172 | public function get($key, $fallback = null, array $array = null) |
|
2122 | |||
2123 | /** |
||
2124 | * alias: for "Arrayy->getArray()" |
||
2125 | * |
||
2126 | * @return array |
||
2127 | * |
||
2128 | * @see Arrayy::getArray() |
||
2129 | * |
||
2130 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
2131 | */ |
||
2132 | 1 | public function getAll(): array |
|
2136 | |||
2137 | /** |
||
2138 | * Get the current array from the "Arrayy"-object. |
||
2139 | * |
||
2140 | * @param bool $convertAllArrayyElements |
||
2141 | * |
||
2142 | * @return array |
||
2143 | * |
||
2144 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
2145 | */ |
||
2146 | 859 | public function getArray($convertAllArrayyElements = false): array |
|
2167 | |||
2168 | /** |
||
2169 | * Returns the values from a single column of the input array, identified by |
||
2170 | * the $columnKey, can be used to extract data-columns from multi-arrays. |
||
2171 | * |
||
2172 | * Info: Optionally, you may provide an $indexKey to index the values in the returned |
||
2173 | * array by the values from the $indexKey column in the input array. |
||
2174 | * |
||
2175 | * @param mixed $columnKey |
||
2176 | * @param mixed $indexKey |
||
2177 | * |
||
2178 | * @return static |
||
2179 | * <p>(Immutable)</p> |
||
2180 | * |
||
2181 | * @psalm-return static<TKey,T> |
||
2182 | */ |
||
2183 | 1 | public function getColumn($columnKey = null, $indexKey = null): self |
|
2191 | |||
2192 | /** |
||
2193 | * Get the current array from the "Arrayy"-object as generator. |
||
2194 | * |
||
2195 | * @return \Generator |
||
2196 | * |
||
2197 | * @psalm-return \Generator<mixed,T>|\Generator<TKey,T> |
||
2198 | */ |
||
2199 | 942 | public function getGenerator(): \Generator |
|
2207 | |||
2208 | /** |
||
2209 | * alias: for "Arrayy->keys()" |
||
2210 | * |
||
2211 | * @return static |
||
2212 | * <p>(Immutable)</p> |
||
2213 | * |
||
2214 | * @see Arrayy::keys() |
||
2215 | * |
||
2216 | * @psalm-return static<TKey,T> |
||
2217 | */ |
||
2218 | 2 | public function getKeys() |
|
2222 | |||
2223 | /** |
||
2224 | * Get the current array from the "Arrayy"-object as object. |
||
2225 | * |
||
2226 | * @return \stdClass |
||
2227 | */ |
||
2228 | 4 | public function getObject(): \stdClass |
|
2232 | |||
2233 | /** |
||
2234 | * alias: for "Arrayy->randomImmutable()" |
||
2235 | * |
||
2236 | * @return static |
||
2237 | * <p>(Immutable)</p> |
||
2238 | * |
||
2239 | * @see Arrayy::randomImmutable() |
||
2240 | * |
||
2241 | * @psalm-return static<TKey,T> |
||
2242 | */ |
||
2243 | 4 | public function getRandom(): self |
|
2247 | |||
2248 | /** |
||
2249 | * alias: for "Arrayy->randomKey()" |
||
2250 | * |
||
2251 | * @return mixed |
||
2252 | * <p>Get a key/index or null if there wasn't a key/index.</p> |
||
2253 | * |
||
2254 | * @see Arrayy::randomKey() |
||
2255 | */ |
||
2256 | 3 | public function getRandomKey() |
|
2260 | |||
2261 | /** |
||
2262 | * alias: for "Arrayy->randomKeys()" |
||
2263 | * |
||
2264 | * @param int $number |
||
2265 | * |
||
2266 | * @return static |
||
2267 | * <p>(Immutable)</p> |
||
2268 | * |
||
2269 | * @see Arrayy::randomKeys() |
||
2270 | * |
||
2271 | * @psalm-return static<TKey,T> |
||
2272 | */ |
||
2273 | 8 | public function getRandomKeys(int $number): self |
|
2277 | |||
2278 | /** |
||
2279 | * alias: for "Arrayy->randomValue()" |
||
2280 | * |
||
2281 | * @return mixed |
||
2282 | * <p>Get a random value or null if there wasn't a value.</p> |
||
2283 | * |
||
2284 | * @see Arrayy::randomValue() |
||
2285 | */ |
||
2286 | 3 | public function getRandomValue() |
|
2290 | |||
2291 | /** |
||
2292 | * alias: for "Arrayy->randomValues()" |
||
2293 | * |
||
2294 | * @param int $number |
||
2295 | * |
||
2296 | * @return static |
||
2297 | * <p>(Immutable)</p> |
||
2298 | * |
||
2299 | * @see Arrayy::randomValues() |
||
2300 | * * |
||
2301 | * @psalm-return static<TKey,T> |
||
2302 | */ |
||
2303 | 6 | public function getRandomValues(int $number): self |
|
2307 | |||
2308 | /** |
||
2309 | * Gets all values. |
||
2310 | * |
||
2311 | * @return static |
||
2312 | * <p>The values of all elements in this array, in the order they |
||
2313 | * appear in the array.</p> |
||
2314 | * |
||
2315 | * @psalm-return static<TKey,T> |
||
2316 | */ |
||
2317 | 4 | public function getValues() |
|
2327 | |||
2328 | /** |
||
2329 | * Gets all values via Generator. |
||
2330 | * |
||
2331 | * @return \Generator |
||
2332 | * <p>The values of all elements in this array, in the order they |
||
2333 | * appear in the array as Generator.</p> |
||
2334 | * |
||
2335 | * @psalm-return \Generator<TKey,T> |
||
2336 | */ |
||
2337 | 4 | public function getValuesYield(): \Generator |
|
2341 | |||
2342 | /** |
||
2343 | * Group values from a array according to the results of a closure. |
||
2344 | * |
||
2345 | * @param callable|string $grouper <p>A callable function name.</p> |
||
2346 | * @param bool $saveKeys |
||
2347 | * |
||
2348 | * @return static |
||
2349 | * <p>(Immutable)</p> |
||
2350 | * |
||
2351 | * @psalm-return static<TKey,T> |
||
2352 | */ |
||
2353 | 4 | public function group($grouper, bool $saveKeys = false): self |
|
2394 | |||
2395 | /** |
||
2396 | * Check if an array has a given key. |
||
2397 | * |
||
2398 | * @param mixed $key |
||
2399 | * |
||
2400 | * @return bool |
||
2401 | */ |
||
2402 | 23 | public function has($key): bool |
|
2413 | |||
2414 | /** |
||
2415 | * Check if an array has a given value. |
||
2416 | * |
||
2417 | * INFO: if you need to search recursive please use ```contains()``` |
||
2418 | * |
||
2419 | * @param mixed $value |
||
2420 | * |
||
2421 | * @return bool |
||
2422 | */ |
||
2423 | 1 | public function hasValue($value): bool |
|
2427 | |||
2428 | /** |
||
2429 | * Implodes the values of this array. |
||
2430 | * |
||
2431 | * @param string $glue |
||
2432 | * |
||
2433 | * @return string |
||
2434 | */ |
||
2435 | 28 | public function implode(string $glue = ''): string |
|
2439 | |||
2440 | /** |
||
2441 | * Implodes the keys of this array. |
||
2442 | * |
||
2443 | * @param string $glue |
||
2444 | * |
||
2445 | * @return string |
||
2446 | */ |
||
2447 | 8 | public function implodeKeys(string $glue = ''): string |
|
2451 | |||
2452 | /** |
||
2453 | * Given a list and an iterate-function that returns |
||
2454 | * a key for each element in the list (or a property name), |
||
2455 | * returns an object with an index of each item. |
||
2456 | * |
||
2457 | * @param mixed $key |
||
2458 | * |
||
2459 | * @return static |
||
2460 | * <p>(Immutable)</p> |
||
2461 | * |
||
2462 | * @psalm-return static<TKey,T> |
||
2463 | */ |
||
2464 | 4 | public function indexBy($key): self |
|
2481 | |||
2482 | /** |
||
2483 | * alias: for "Arrayy->searchIndex()" |
||
2484 | * |
||
2485 | * @param mixed $value <p>The value to search for.</p> |
||
2486 | * |
||
2487 | * @return false|mixed |
||
2488 | * |
||
2489 | * @see Arrayy::searchIndex() |
||
2490 | */ |
||
2491 | 4 | public function indexOf($value) |
|
2495 | |||
2496 | /** |
||
2497 | * Get everything but the last..$to items. |
||
2498 | * |
||
2499 | * @param int $to |
||
2500 | * |
||
2501 | * @return static |
||
2502 | * <p>(Immutable)</p> |
||
2503 | * |
||
2504 | * @psalm-return static<TKey,T> |
||
2505 | */ |
||
2506 | 12 | public function initial(int $to = 1): self |
|
2510 | |||
2511 | /** |
||
2512 | * Return an array with all elements found in input array. |
||
2513 | * |
||
2514 | * @param array $search |
||
2515 | * @param bool $keepKeys |
||
2516 | * |
||
2517 | * @return static |
||
2518 | * <p>(Immutable)</p> |
||
2519 | * |
||
2520 | * @psalm-param array<mixed,mixed>|array<TKey,T> $search |
||
2521 | * @psalm-return static<TKey,T> |
||
2522 | */ |
||
2523 | 4 | public function intersection(array $search, bool $keepKeys = false): self |
|
2545 | |||
2546 | /** |
||
2547 | * Return an array with all elements found in input array. |
||
2548 | * |
||
2549 | * @param array ...$array |
||
2550 | * |
||
2551 | * @return static |
||
2552 | * <p>(Immutable)</p> |
||
2553 | * |
||
2554 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$array |
||
2555 | * @psalm-return static<TKey,T> |
||
2556 | */ |
||
2557 | 1 | public function intersectionMulti(...$array): self |
|
2565 | |||
2566 | /** |
||
2567 | * Return a boolean flag which indicates whether the two input arrays have any common elements. |
||
2568 | * |
||
2569 | * @param array $search |
||
2570 | * |
||
2571 | * @return bool |
||
2572 | * |
||
2573 | * @psalm-param array<mixed,mixed>|array<TKey,T> $search |
||
2574 | */ |
||
2575 | 1 | public function intersects(array $search): bool |
|
2579 | |||
2580 | /** |
||
2581 | * Invoke a function on all of an array's values. |
||
2582 | * |
||
2583 | * @param callable $callable |
||
2584 | * @param mixed $arguments |
||
2585 | * |
||
2586 | * @return static |
||
2587 | * <p>(Immutable)</p> |
||
2588 | * |
||
2589 | * @psalm-param callable(T=,mixed):mixed $callable |
||
2590 | * @psalm-return static<TKey,T> |
||
2591 | */ |
||
2592 | 1 | public function invoke($callable, $arguments = []): self |
|
2616 | |||
2617 | /** |
||
2618 | * Check whether array is associative or not. |
||
2619 | * |
||
2620 | * @param bool $recursive |
||
2621 | * |
||
2622 | * @return bool |
||
2623 | * <p>Returns true if associative, false otherwise.</p> |
||
2624 | */ |
||
2625 | 15 | View Code Duplication | public function isAssoc(bool $recursive = false): bool |
2639 | |||
2640 | /** |
||
2641 | * Check if a given key or keys are empty. |
||
2642 | * |
||
2643 | * @param int|int[]|string|string[]|null $keys |
||
2644 | * |
||
2645 | * @return bool |
||
2646 | * <p>Returns true if empty, false otherwise.</p> |
||
2647 | */ |
||
2648 | 38 | public function isEmpty($keys = null): bool |
|
2666 | |||
2667 | /** |
||
2668 | * Check if the current array is equal to the given "$array" or not. |
||
2669 | * |
||
2670 | * @param array $array |
||
2671 | * |
||
2672 | * @return bool |
||
2673 | * |
||
2674 | * @psalm-param array<mixed,mixed> $array |
||
2675 | */ |
||
2676 | 1 | public function isEqual(array $array): bool |
|
2680 | |||
2681 | /** |
||
2682 | * Check if the current array is a multi-array. |
||
2683 | * |
||
2684 | * @return bool |
||
2685 | */ |
||
2686 | 22 | public function isMultiArray(): bool |
|
2694 | |||
2695 | /** |
||
2696 | * Check whether array is numeric or not. |
||
2697 | * |
||
2698 | * @return bool |
||
2699 | * <p>Returns true if numeric, false otherwise.</p> |
||
2700 | */ |
||
2701 | 5 | View Code Duplication | public function isNumeric(): bool |
2715 | |||
2716 | /** |
||
2717 | * Check if the current array is sequential [0, 1, 2, 3, 4, 5 ...] or not. |
||
2718 | * |
||
2719 | * @param bool $recursive |
||
2720 | * |
||
2721 | * @return bool |
||
2722 | */ |
||
2723 | 9 | public function isSequential(bool $recursive = false): bool |
|
2740 | |||
2741 | /** |
||
2742 | * @return array |
||
2743 | * |
||
2744 | * @psalm-return array<TKey,T> |
||
2745 | */ |
||
2746 | public function jsonSerialize(): array |
||
2750 | |||
2751 | /** |
||
2752 | * Gets the key/index of the element at the current internal iterator position. |
||
2753 | * |
||
2754 | * @return int|string|null |
||
2755 | */ |
||
2756 | public function key() |
||
2760 | |||
2761 | /** |
||
2762 | * Checks if the given key exists in the provided array. |
||
2763 | * |
||
2764 | * INFO: This method only use "array_key_exists()" if you want to use "dot"-notation, |
||
2765 | * then you need to use "Arrayy->offsetExists()". |
||
2766 | * |
||
2767 | * @param int|string $key the key to look for |
||
2768 | * |
||
2769 | * @return bool |
||
2770 | */ |
||
2771 | 127 | public function keyExists($key): bool |
|
2775 | |||
2776 | /** |
||
2777 | * Get all keys from the current array. |
||
2778 | * |
||
2779 | * @param bool $recursive [optional] <p> |
||
2780 | * Get all keys, also from all sub-arrays from an multi-dimensional array. |
||
2781 | * </p> |
||
2782 | * @param mixed|null $search_values [optional] <p> |
||
2783 | * If specified, then only keys containing these values are returned. |
||
2784 | * </p> |
||
2785 | * @param bool $strict [optional] <p> |
||
2786 | * Determines if strict comparison (===) should be used during the search. |
||
2787 | * </p> |
||
2788 | * |
||
2789 | * @return static |
||
2790 | * <p>(Immutable) An array of all the keys in input.</p> |
||
2791 | * |
||
2792 | * @psalm-return static<TKey,T> |
||
2793 | */ |
||
2794 | 29 | public function keys( |
|
2864 | |||
2865 | /** |
||
2866 | * Sort an array by key in reverse order. |
||
2867 | * |
||
2868 | * @param int $sort_flags [optional] <p> |
||
2869 | * You may modify the behavior of the sort using the optional |
||
2870 | * parameter sort_flags, for details |
||
2871 | * see sort. |
||
2872 | * </p> |
||
2873 | * |
||
2874 | * @return static |
||
2875 | * <p>(Mutable) Return this Arrayy object.</p> |
||
2876 | * |
||
2877 | * @psalm-return static<TKey,T> |
||
2878 | */ |
||
2879 | 4 | public function krsort(int $sort_flags = 0): self |
|
2887 | |||
2888 | /** |
||
2889 | * Get the last value from the current array. |
||
2890 | * |
||
2891 | * @return mixed |
||
2892 | * <p>Return null if there wasn't a element.</p> |
||
2893 | */ |
||
2894 | 17 | public function last() |
|
2903 | |||
2904 | /** |
||
2905 | * Get the last key from the current array. |
||
2906 | * |
||
2907 | * @return mixed |
||
2908 | * <p>Return null if there wasn't a element.</p> |
||
2909 | */ |
||
2910 | 21 | public function lastKey() |
|
2916 | |||
2917 | /** |
||
2918 | * Get the last value(s) from the current array. |
||
2919 | * |
||
2920 | * @param int|null $number |
||
2921 | * |
||
2922 | * @return static |
||
2923 | * <p>(Immutable)</p> |
||
2924 | * |
||
2925 | * @psalm-return static<TKey,T> |
||
2926 | */ |
||
2927 | 13 | public function lastsImmutable(int $number = null): self |
|
2958 | |||
2959 | /** |
||
2960 | * Get the last value(s) from the current array. |
||
2961 | * |
||
2962 | * @param int|null $number |
||
2963 | * |
||
2964 | * @return static |
||
2965 | * <p>(Mutable)</p> |
||
2966 | * |
||
2967 | * @psalm-return static<TKey,T> |
||
2968 | */ |
||
2969 | 13 | public function lastsMutable(int $number = null): self |
|
2998 | |||
2999 | /** |
||
3000 | * Count the values from the current array. |
||
3001 | * |
||
3002 | * alias: for "Arrayy->count()" |
||
3003 | * |
||
3004 | * @param int $mode |
||
3005 | * |
||
3006 | * @return int |
||
3007 | * |
||
3008 | * @see Arrayy::count() |
||
3009 | */ |
||
3010 | 20 | public function length(int $mode = \COUNT_NORMAL): int |
|
3014 | |||
3015 | /** |
||
3016 | * Apply the given function to the every element of the array, |
||
3017 | * collecting the results. |
||
3018 | * |
||
3019 | * @param callable $callable |
||
3020 | * @param bool $useKeyAsSecondParameter |
||
3021 | * @param mixed ...$arguments |
||
3022 | * |
||
3023 | * @return static |
||
3024 | * <p>(Immutable) Arrayy object with modified elements.</p> |
||
3025 | * |
||
3026 | * @psalm-param callable(T=,TKey=,mixed):mixed|callable(T=,mixed):mixed $callable |
||
3027 | * @psalm-return static<TKey,T> |
||
3028 | */ |
||
3029 | 5 | public function map(callable $callable, bool $useKeyAsSecondParameter = false, ...$arguments) |
|
3056 | |||
3057 | /** |
||
3058 | * Check if all items in current array match a truth test. |
||
3059 | * |
||
3060 | * @param \Closure $closure |
||
3061 | * |
||
3062 | * @return bool |
||
3063 | */ |
||
3064 | 15 | View Code Duplication | public function matches(\Closure $closure): bool |
3080 | |||
3081 | /** |
||
3082 | * Check if any item in the current array matches a truth test. |
||
3083 | * |
||
3084 | * @param \Closure $closure |
||
3085 | * |
||
3086 | * @return bool |
||
3087 | */ |
||
3088 | 14 | View Code Duplication | public function matchesAny(\Closure $closure): bool |
3104 | |||
3105 | /** |
||
3106 | * Get the max value from an array. |
||
3107 | * |
||
3108 | * @return mixed |
||
3109 | */ |
||
3110 | 10 | View Code Duplication | public function max() |
3129 | |||
3130 | /** |
||
3131 | * Merge the new $array into the current array. |
||
3132 | * |
||
3133 | * - keep key,value from the current array, also if the index is in the new $array |
||
3134 | * |
||
3135 | * @param array $array |
||
3136 | * @param bool $recursive |
||
3137 | * |
||
3138 | * @return static |
||
3139 | * <p>(Immutable)</p> |
||
3140 | * |
||
3141 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
3142 | * @psalm-return static<TKey,T> |
||
3143 | */ |
||
3144 | 25 | View Code Duplication | public function mergeAppendKeepIndex(array $array = [], bool $recursive = false): self |
3158 | |||
3159 | /** |
||
3160 | * Merge the new $array into the current array. |
||
3161 | * |
||
3162 | * - replace duplicate assoc-keys from the current array with the key,values from the new $array |
||
3163 | * - create new indexes |
||
3164 | * |
||
3165 | * @param array $array |
||
3166 | * @param bool $recursive |
||
3167 | * |
||
3168 | * @return static |
||
3169 | * <p>(Immutable)</p> |
||
3170 | * |
||
3171 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
3172 | * @psalm-return static<TKey,T> |
||
3173 | */ |
||
3174 | 16 | View Code Duplication | public function mergeAppendNewIndex(array $array = [], bool $recursive = false): self |
3188 | |||
3189 | /** |
||
3190 | * Merge the the current array into the $array. |
||
3191 | * |
||
3192 | * - use key,value from the new $array, also if the index is in the current array |
||
3193 | * |
||
3194 | * @param array $array |
||
3195 | * @param bool $recursive |
||
3196 | * |
||
3197 | * @return static |
||
3198 | * <p>(Immutable)</p> |
||
3199 | * |
||
3200 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
3201 | * @psalm-return static<TKey,T> |
||
3202 | */ |
||
3203 | 16 | View Code Duplication | public function mergePrependKeepIndex(array $array = [], bool $recursive = false): self |
3217 | |||
3218 | /** |
||
3219 | * Merge the current array into the new $array. |
||
3220 | * |
||
3221 | * - replace duplicate assoc-keys from new $array with the key,values from the current array |
||
3222 | * - create new indexes |
||
3223 | * |
||
3224 | * @param array $array |
||
3225 | * @param bool $recursive |
||
3226 | * |
||
3227 | * @return static |
||
3228 | * <p>(Immutable)</p> |
||
3229 | * |
||
3230 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
3231 | * @psalm-return static<TKey,T> |
||
3232 | */ |
||
3233 | 17 | View Code Duplication | public function mergePrependNewIndex(array $array = [], bool $recursive = false): self |
3247 | |||
3248 | /** |
||
3249 | * @return ArrayyMeta|static |
||
3250 | */ |
||
3251 | 15 | public static function meta() |
|
3255 | |||
3256 | /** |
||
3257 | * Get the min value from an array. |
||
3258 | * |
||
3259 | * @return mixed |
||
3260 | */ |
||
3261 | 10 | View Code Duplication | public function min() |
3280 | |||
3281 | /** |
||
3282 | * Get the most used value from the array. |
||
3283 | * |
||
3284 | * @return mixed |
||
3285 | * <p>Return null if there wasn't a element.</p> |
||
3286 | */ |
||
3287 | 3 | public function mostUsedValue() |
|
3291 | |||
3292 | /** |
||
3293 | * Get the most used value from the array. |
||
3294 | * |
||
3295 | * @param int|null $number <p>How many values you will take?</p> |
||
3296 | * |
||
3297 | * @return static |
||
3298 | * <p>(Immutable)</p> |
||
3299 | * |
||
3300 | * @psalm-return static<TKey,T> |
||
3301 | */ |
||
3302 | 3 | public function mostUsedValues(int $number = null): self |
|
3306 | |||
3307 | /** |
||
3308 | * Move an array element to a new index. |
||
3309 | * |
||
3310 | * cherry-picked from: http://stackoverflow.com/questions/12624153/move-an-array-element-to-a-new-index-in-php |
||
3311 | * |
||
3312 | * @param int|string $from |
||
3313 | * @param int $to |
||
3314 | * |
||
3315 | * @return static |
||
3316 | * <p>(Immutable)</p> |
||
3317 | * |
||
3318 | * @psalm-return static<TKey,T> |
||
3319 | */ |
||
3320 | 1 | public function moveElement($from, $to): self |
|
3353 | |||
3354 | /** |
||
3355 | * Move an array element to the first place. |
||
3356 | * |
||
3357 | * INFO: Instead of "Arrayy->moveElement()" this method will NOT |
||
3358 | * loss the keys of an indexed array. |
||
3359 | * |
||
3360 | * @param int|string $key |
||
3361 | * |
||
3362 | * @return static |
||
3363 | * <p>(Immutable)</p> |
||
3364 | * |
||
3365 | * @psalm-return static<TKey,T> |
||
3366 | */ |
||
3367 | 1 | View Code Duplication | public function moveElementToFirstPlace($key): self |
3383 | |||
3384 | /** |
||
3385 | * Move an array element to the last place. |
||
3386 | * |
||
3387 | * INFO: Instead of "Arrayy->moveElement()" this method will NOT |
||
3388 | * loss the keys of an indexed array. |
||
3389 | * |
||
3390 | * @param int|string $key |
||
3391 | * |
||
3392 | * @return static |
||
3393 | * <p>(Immutable)</p> |
||
3394 | * |
||
3395 | * @psalm-return static<TKey,T> |
||
3396 | */ |
||
3397 | 1 | View Code Duplication | public function moveElementToLastPlace($key): self |
3413 | |||
3414 | /** |
||
3415 | * Moves the internal iterator position to the next element and returns this element. |
||
3416 | * |
||
3417 | * @return mixed |
||
3418 | */ |
||
3419 | public function next() |
||
3423 | |||
3424 | /** |
||
3425 | * Get the next nth keys and values from the array. |
||
3426 | * |
||
3427 | * @param int $step |
||
3428 | * @param int $offset |
||
3429 | * |
||
3430 | * @return static |
||
3431 | * <p>(Immutable)</p> |
||
3432 | * |
||
3433 | * @psalm-return static<TKey,T> |
||
3434 | */ |
||
3435 | 1 | public function nth(int $step, int $offset = 0): self |
|
3454 | |||
3455 | /** |
||
3456 | * Get a subset of the items from the given array. |
||
3457 | * |
||
3458 | * @param mixed[] $keys |
||
3459 | * |
||
3460 | * @return static |
||
3461 | * <p>(Immutable)</p> |
||
3462 | * |
||
3463 | * @psalm-return static<TKey,T> |
||
3464 | */ |
||
3465 | 1 | public function only(array $keys): self |
|
3475 | |||
3476 | /** |
||
3477 | * Pad array to the specified size with a given value. |
||
3478 | * |
||
3479 | * @param int $size <p>Size of the result array.</p> |
||
3480 | * @param mixed $value <p>Empty value by default.</p> |
||
3481 | * |
||
3482 | * @return static |
||
3483 | * <p>(Immutable) Arrayy object padded to $size with $value.</p> |
||
3484 | * |
||
3485 | * @psalm-return static<TKey,T> |
||
3486 | */ |
||
3487 | 5 | public function pad(int $size, $value): self |
|
3495 | |||
3496 | /** |
||
3497 | * Partitions this array in two array according to a predicate. |
||
3498 | * Keys are preserved in the resulting array. |
||
3499 | * |
||
3500 | * @param \Closure $closure |
||
3501 | * <p>The predicate on which to partition.</p> |
||
3502 | * |
||
3503 | * @return array<int, static> |
||
3504 | * <p>An array with two elements. The first element contains the array |
||
3505 | * of elements where the predicate returned TRUE, the second element |
||
3506 | * contains the array of elements where the predicate returned FALSE.</p> |
||
3507 | * |
||
3508 | * @psalm-return array<int, static<mixed,T>> |
||
3509 | */ |
||
3510 | 1 | public function partition(\Closure $closure): array |
|
3526 | |||
3527 | /** |
||
3528 | * Pop a specified value off the end of the current array. |
||
3529 | * |
||
3530 | * @return mixed |
||
3531 | * <p>(Mutable) The popped element from the current array.</p> |
||
3532 | */ |
||
3533 | 5 | public function pop() |
|
3539 | |||
3540 | /** |
||
3541 | * Prepend a (key) + value to the current array. |
||
3542 | * |
||
3543 | * @param mixed $value |
||
3544 | * @param mixed $key |
||
3545 | * |
||
3546 | * @return static |
||
3547 | * <p>(Mutable) Return this Arrayy object, with the prepended value.</p> |
||
3548 | * |
||
3549 | * @psalm-return static<TKey,T> |
||
3550 | */ |
||
3551 | 11 | public function prepend($value, $key = null) |
|
3567 | |||
3568 | /** |
||
3569 | * Add a suffix to each key. |
||
3570 | * |
||
3571 | * @param mixed $suffix |
||
3572 | * |
||
3573 | * @return static |
||
3574 | * <p>(Immutable) Return an Arrayy object, with the prepended keys.</p> |
||
3575 | * |
||
3576 | * @psalm-return static<TKey,T> |
||
3577 | */ |
||
3578 | 10 | View Code Duplication | public function prependToEachKey($suffix): self |
3604 | |||
3605 | /** |
||
3606 | * Add a suffix to each value. |
||
3607 | * |
||
3608 | * @param mixed $suffix |
||
3609 | * |
||
3610 | * @return static |
||
3611 | * <p>(Immutable) Return an Arrayy object, with the prepended values.</p> |
||
3612 | * |
||
3613 | * @psalm-return static<TKey,T> |
||
3614 | */ |
||
3615 | 10 | View Code Duplication | public function prependToEachValue($suffix): self |
3643 | |||
3644 | /** |
||
3645 | * Return the value of a given key and |
||
3646 | * delete the key. |
||
3647 | * |
||
3648 | * @param int|int[]|string|string[]|null $keyOrKeys |
||
3649 | * @param mixed $fallback |
||
3650 | * |
||
3651 | * @return mixed |
||
3652 | */ |
||
3653 | 1 | public function pull($keyOrKeys = null, $fallback = null) |
|
3675 | |||
3676 | /** |
||
3677 | * Push one or more values onto the end of array at once. |
||
3678 | * |
||
3679 | * @param array ...$args |
||
3680 | * |
||
3681 | * @return static |
||
3682 | * <p>(Mutable) Return this Arrayy object, with pushed elements to the end of array.</p> |
||
3683 | * |
||
3684 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
3685 | * |
||
3686 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$args |
||
3687 | * @psalm-return static<TKey,T> |
||
3688 | */ |
||
3689 | 5 | public function push(...$args) |
|
3707 | |||
3708 | /** |
||
3709 | * Get a random value from the current array. |
||
3710 | * |
||
3711 | * @param int|null $number <p>How many values you will take?</p> |
||
3712 | * |
||
3713 | * @return static |
||
3714 | * <p>(Immutable)</p> |
||
3715 | * |
||
3716 | * @psalm-return static<TKey,T> |
||
3717 | */ |
||
3718 | 19 | public function randomImmutable(int $number = null): self |
|
3751 | |||
3752 | /** |
||
3753 | * Pick a random key/index from the keys of this array. |
||
3754 | * |
||
3755 | * @throws \RangeException If array is empty |
||
3756 | * |
||
3757 | * @return mixed |
||
3758 | * <p>Get a key/index or null if there wasn't a key/index.</p> |
||
3759 | */ |
||
3760 | 4 | public function randomKey() |
|
3770 | |||
3771 | /** |
||
3772 | * Pick a given number of random keys/indexes out of this array. |
||
3773 | * |
||
3774 | * @param int $number <p>The number of keys/indexes (should be <= \count($this->array))</p> |
||
3775 | * |
||
3776 | * @throws \RangeException If array is empty |
||
3777 | * |
||
3778 | * @return static |
||
3779 | * <p>(Immutable)</p> |
||
3780 | * |
||
3781 | * @psalm-return static<TKey,T> |
||
3782 | */ |
||
3783 | 13 | public function randomKeys(int $number): self |
|
3811 | |||
3812 | /** |
||
3813 | * Get a random value from the current array. |
||
3814 | * |
||
3815 | * @param int|null $number <p>How many values you will take?</p> |
||
3816 | * |
||
3817 | * @return static |
||
3818 | * <p>(Mutable)</p> |
||
3819 | * |
||
3820 | * @psalm-return static<TKey,T> |
||
3821 | */ |
||
3822 | 17 | public function randomMutable(int $number = null): self |
|
3847 | |||
3848 | /** |
||
3849 | * Pick a random value from the values of this array. |
||
3850 | * |
||
3851 | * @return mixed |
||
3852 | * <p>Get a random value or null if there wasn't a value.</p> |
||
3853 | */ |
||
3854 | 4 | public function randomValue() |
|
3864 | |||
3865 | /** |
||
3866 | * Pick a given number of random values out of this array. |
||
3867 | * |
||
3868 | * @param int $number |
||
3869 | * |
||
3870 | * @return static |
||
3871 | * <p>(Mutable)</p> |
||
3872 | * |
||
3873 | * @psalm-return static<TKey,T> |
||
3874 | */ |
||
3875 | 7 | public function randomValues(int $number): self |
|
3879 | |||
3880 | /** |
||
3881 | * Get a random value from an array, with the ability to skew the results. |
||
3882 | * |
||
3883 | * Example: randomWeighted(['foo' => 1, 'bar' => 2]) has a 66% chance of returning bar. |
||
3884 | * |
||
3885 | * @param array $array |
||
3886 | * @param int|null $number <p>How many values you will take?</p> |
||
3887 | * |
||
3888 | * @return static |
||
3889 | * <p>(Immutable)</p> |
||
3890 | * |
||
3891 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
3892 | * @psalm-return static<TKey,T> |
||
3893 | */ |
||
3894 | 9 | public function randomWeighted(array $array, int $number = null): self |
|
3909 | |||
3910 | /** |
||
3911 | * Reduce the current array via callable e.g. anonymous-function. |
||
3912 | * |
||
3913 | * @param callable $callable |
||
3914 | * @param mixed $init |
||
3915 | * |
||
3916 | * @return static |
||
3917 | * <p>(Immutable)</p> |
||
3918 | * |
||
3919 | * @psalm-return static<TKey,T> |
||
3920 | */ |
||
3921 | 18 | public function reduce($callable, $init = []): self |
|
3951 | |||
3952 | /** |
||
3953 | * @param bool $unique |
||
3954 | * |
||
3955 | * @return static |
||
3956 | * <p>(Immutable)</p> |
||
3957 | * |
||
3958 | * @psalm-return static<TKey,T> |
||
3959 | */ |
||
3960 | 14 | public function reduce_dimension(bool $unique = true): self |
|
3979 | |||
3980 | /** |
||
3981 | * Create a numerically re-indexed Arrayy object. |
||
3982 | * |
||
3983 | * @return static |
||
3984 | * <p>(Mutable) Return this Arrayy object, with re-indexed array-elements.</p> |
||
3985 | * |
||
3986 | * @psalm-return static<TKey,T> |
||
3987 | */ |
||
3988 | 9 | public function reindex(): self |
|
3996 | |||
3997 | /** |
||
3998 | * Return all items that fail the truth test. |
||
3999 | * |
||
4000 | * @param \Closure $closure |
||
4001 | * |
||
4002 | * @return static |
||
4003 | * <p>(Immutable)</p> |
||
4004 | * |
||
4005 | * @psalm-return static<TKey,T> |
||
4006 | */ |
||
4007 | 1 | View Code Duplication | public function reject(\Closure $closure): self |
4024 | |||
4025 | /** |
||
4026 | * Remove a value from the current array (optional using dot-notation). |
||
4027 | * |
||
4028 | * @param mixed $key |
||
4029 | * |
||
4030 | * @return static |
||
4031 | * <p>(Mutable)</p> |
||
4032 | * |
||
4033 | * @psalm-param TKey $key |
||
4034 | * @psalm-return static<TKey,T> |
||
4035 | */ |
||
4036 | 18 | public function remove($key) |
|
4059 | |||
4060 | /** |
||
4061 | * alias: for "Arrayy->removeValue()" |
||
4062 | * |
||
4063 | * @param mixed $element |
||
4064 | * |
||
4065 | * @return static |
||
4066 | * <p>(Immutable)</p> |
||
4067 | * |
||
4068 | * @psalm-param T $element |
||
4069 | * @psalm-return static<TKey,T> |
||
4070 | */ |
||
4071 | 8 | public function removeElement($element) |
|
4075 | |||
4076 | /** |
||
4077 | * Remove the first value from the current array. |
||
4078 | * |
||
4079 | * @return static |
||
4080 | * <p>(Immutable)</p> |
||
4081 | * |
||
4082 | * @psalm-return static<TKey,T> |
||
4083 | */ |
||
4084 | 7 | View Code Duplication | public function removeFirst(): self |
4096 | |||
4097 | /** |
||
4098 | * Remove the last value from the current array. |
||
4099 | * |
||
4100 | * @return static |
||
4101 | * <p>(Immutable)</p> |
||
4102 | * |
||
4103 | * @psalm-return static<TKey,T> |
||
4104 | */ |
||
4105 | 7 | View Code Duplication | public function removeLast(): self |
4117 | |||
4118 | /** |
||
4119 | * Removes a particular value from an array (numeric or associative). |
||
4120 | * |
||
4121 | * @param mixed $value |
||
4122 | * |
||
4123 | * @return static |
||
4124 | * <p>(Immutable)</p> |
||
4125 | * |
||
4126 | * @psalm-param T $value |
||
4127 | * @psalm-return static<TKey,T> |
||
4128 | */ |
||
4129 | 8 | public function removeValue($value): self |
|
4152 | |||
4153 | /** |
||
4154 | * Generate array of repeated arrays. |
||
4155 | * |
||
4156 | * @param int $times <p>How many times has to be repeated.</p> |
||
4157 | * |
||
4158 | * @return static |
||
4159 | * <p>(Immutable)</p> |
||
4160 | * |
||
4161 | * @psalm-return static<TKey,T> |
||
4162 | */ |
||
4163 | 1 | public function repeat($times): self |
|
4175 | |||
4176 | /** |
||
4177 | * Replace a key with a new key/value pair. |
||
4178 | * |
||
4179 | * @param mixed $replace |
||
4180 | * @param mixed $key |
||
4181 | * @param mixed $value |
||
4182 | * |
||
4183 | * @return static |
||
4184 | * <p>(Immutable)</p> |
||
4185 | * |
||
4186 | * @psalm-return static<TKey,T> |
||
4187 | */ |
||
4188 | 2 | public function replace($replace, $key, $value): self |
|
4195 | |||
4196 | /** |
||
4197 | * Create an array using the current array as values and the other array as keys. |
||
4198 | * |
||
4199 | * @param array $keys <p>An array of keys.</p> |
||
4200 | * |
||
4201 | * @return static |
||
4202 | * <p>(Immutable) Arrayy object with keys from the other array.</p> |
||
4203 | * |
||
4204 | * @psalm-param array<mixed,mixed>|array<mixed,TKey> $keys |
||
4205 | * @psalm-return static<TKey,T> |
||
4206 | */ |
||
4207 | 2 | public function replaceAllKeys(array $keys): self |
|
4215 | |||
4216 | /** |
||
4217 | * Create an array using the current array as keys and the other array as values. |
||
4218 | * |
||
4219 | * @param array $array <p>An array o values.</p> |
||
4220 | * |
||
4221 | * @return static |
||
4222 | * <p>(Immutable) Arrayy object with values from the other array.</p> |
||
4223 | * |
||
4224 | * @psalm-param array<mixed,T> $array |
||
4225 | * @psalm-return static<TKey,T> |
||
4226 | */ |
||
4227 | 2 | public function replaceAllValues(array $array): self |
|
4235 | |||
4236 | /** |
||
4237 | * Replace the keys in an array with another set. |
||
4238 | * |
||
4239 | * @param array $keys <p>An array of keys matching the array's size</p> |
||
4240 | * |
||
4241 | * @return static |
||
4242 | * <p>(Immutable)</p> |
||
4243 | * |
||
4244 | * @psalm-param array<mixed,mixed>|array<mixed,TKey> $keys |
||
4245 | * @psalm-return static<TKey,T> |
||
4246 | */ |
||
4247 | 1 | public function replaceKeys(array $keys): self |
|
4258 | |||
4259 | /** |
||
4260 | * Replace the first matched value in an array. |
||
4261 | * |
||
4262 | * @param mixed $search <p>The value to replace.</p> |
||
4263 | * @param mixed $replacement <p>The value to replace.</p> |
||
4264 | * |
||
4265 | * @return static |
||
4266 | * <p>(Immutable)</p> |
||
4267 | * |
||
4268 | * @psalm-return static<TKey,T> |
||
4269 | */ |
||
4270 | 3 | public function replaceOneValue($search, $replacement = ''): self |
|
4285 | |||
4286 | /** |
||
4287 | * Replace values in the current array. |
||
4288 | * |
||
4289 | * @param mixed $search <p>The value to replace.</p> |
||
4290 | * @param mixed $replacement <p>What to replace it with.</p> |
||
4291 | * |
||
4292 | * @return static |
||
4293 | * <p>(Immutable)</p> |
||
4294 | * |
||
4295 | * @psalm-return static<TKey,T> |
||
4296 | */ |
||
4297 | 1 | public function replaceValues($search, $replacement = ''): self |
|
4305 | |||
4306 | /** |
||
4307 | * Get the last elements from index $from until the end of this array. |
||
4308 | * |
||
4309 | * @param int $from |
||
4310 | * |
||
4311 | * @return static |
||
4312 | * <p>(Immutable)</p> |
||
4313 | * |
||
4314 | * @psalm-return static<TKey,T> |
||
4315 | */ |
||
4316 | 15 | View Code Duplication | public function rest(int $from = 1): self |
4326 | |||
4327 | /** |
||
4328 | * Return the array in the reverse order. |
||
4329 | * |
||
4330 | * @return static |
||
4331 | * <p>(Mutable) Return this Arrayy object.</p> |
||
4332 | * |
||
4333 | * @psalm-return static<TKey,T> |
||
4334 | */ |
||
4335 | 9 | public function reverse(): self |
|
4343 | |||
4344 | /** |
||
4345 | * Sort an array in reverse order. |
||
4346 | * |
||
4347 | * @param int $sort_flags [optional] <p> |
||
4348 | * You may modify the behavior of the sort using the optional |
||
4349 | * parameter sort_flags, for details |
||
4350 | * see sort. |
||
4351 | * </p> |
||
4352 | * |
||
4353 | * @return static |
||
4354 | * <p>(Mutable) Return this Arrayy object.</p> |
||
4355 | * |
||
4356 | * @psalm-return static<TKey,T> |
||
4357 | */ |
||
4358 | 4 | public function rsort(int $sort_flags = 0): self |
|
4366 | |||
4367 | /** |
||
4368 | * Search for the first index of the current array via $value. |
||
4369 | * |
||
4370 | * @param mixed $value |
||
4371 | * |
||
4372 | * @return false|float|int|string |
||
4373 | * <p>Will return <b>FALSE</b> if the value can't be found.</p> |
||
4374 | */ |
||
4375 | 21 | public function searchIndex($value) |
|
4385 | |||
4386 | /** |
||
4387 | * Search for the value of the current array via $index. |
||
4388 | * |
||
4389 | * @param mixed $index |
||
4390 | * |
||
4391 | * @return static |
||
4392 | * <p>(Immutable) Will return a empty Arrayy if the value wasn't found.</p> |
||
4393 | * |
||
4394 | * @psalm-return static<TKey,T> |
||
4395 | */ |
||
4396 | 9 | public function searchValue($index): self |
|
4426 | |||
4427 | /** |
||
4428 | * Set a value for the current array (optional using dot-notation). |
||
4429 | * |
||
4430 | * @param string $key <p>The key to set.</p> |
||
4431 | * @param mixed $value <p>Its value.</p> |
||
4432 | * |
||
4433 | * @return static |
||
4434 | * <p>(Mutable)</p> |
||
4435 | * |
||
4436 | * @psalm-param TKey $key |
||
4437 | * @psalm-param T $value |
||
4438 | * @psalm-return static<TKey,T> |
||
4439 | */ |
||
4440 | 18 | public function set($key, $value): self |
|
4448 | |||
4449 | /** |
||
4450 | * Get a value from a array and set it if it was not. |
||
4451 | * |
||
4452 | * WARNING: this method only set the value, if the $key is not already set |
||
4453 | * |
||
4454 | * @param mixed $key <p>The key</p> |
||
4455 | * @param mixed $fallback <p>The default value to set if it isn't.</p> |
||
4456 | * |
||
4457 | * @return mixed |
||
4458 | * <p>(Mutable)</p> |
||
4459 | */ |
||
4460 | 11 | public function setAndGet($key, $fallback = null) |
|
4471 | |||
4472 | /** |
||
4473 | * Shifts a specified value off the beginning of array. |
||
4474 | * |
||
4475 | * @return mixed |
||
4476 | * <p>(Mutable) A shifted element from the current array.</p> |
||
4477 | */ |
||
4478 | 5 | public function shift() |
|
4484 | |||
4485 | /** |
||
4486 | * Shuffle the current array. |
||
4487 | * |
||
4488 | * @param bool $secure <p>using a CSPRNG | @link https://paragonie.com/b/JvICXzh_jhLyt4y3</p> |
||
4489 | * @param array $array [optional] |
||
4490 | * |
||
4491 | * @return static |
||
4492 | * <p>(Immutable)</p> |
||
4493 | * |
||
4494 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
4495 | * @psalm-return static<TKey,T> |
||
4496 | */ |
||
4497 | 2 | public function shuffle(bool $secure = false, array $array = null): self |
|
4498 | { |
||
4499 | 2 | if ($array === null) { |
|
4500 | 2 | $array = $this->getArray(); |
|
4501 | } |
||
4502 | |||
4503 | 2 | if ($secure !== true) { |
|
4504 | /** @noinspection NonSecureShuffleUsageInspection */ |
||
4505 | 2 | \shuffle($array); |
|
4506 | } else { |
||
4507 | 1 | $size = \count($array, \COUNT_NORMAL); |
|
4508 | 1 | $keys = \array_keys($array); |
|
4509 | 1 | for ($i = $size - 1; $i > 0; --$i) { |
|
4510 | try { |
||
4511 | 1 | $r = \random_int(0, $i); |
|
4512 | } catch (\Exception $e) { |
||
4513 | /** @noinspection RandomApiMigrationInspection */ |
||
4514 | $r = \mt_rand(0, $i); |
||
4515 | } |
||
4516 | 1 | if ($r !== $i) { |
|
4517 | $temp = $array[$keys[$r]]; |
||
4518 | $array[$keys[$r]] = $array[$keys[$i]]; |
||
4519 | $array[$keys[$i]] = $temp; |
||
4520 | } |
||
4521 | } |
||
4522 | |||
4523 | // reset indices |
||
4524 | 1 | $array = \array_values($array); |
|
4525 | } |
||
4526 | |||
4527 | 2 | foreach ($array as $key => $value) { |
|
4528 | // check if recursive is needed |
||
4529 | 2 | if (\is_array($value) === true) { |
|
4530 | $array[$key] = $this->shuffle($secure, $value); |
||
4531 | } |
||
4532 | } |
||
4533 | |||
4534 | 2 | return static::create( |
|
4535 | 2 | $array, |
|
4536 | 2 | $this->iteratorClass, |
|
4537 | 2 | false |
|
4538 | ); |
||
4539 | } |
||
4540 | |||
4541 | /** |
||
4542 | * Count the values from the current array. |
||
4543 | * |
||
4544 | * alias: for "Arrayy->count()" |
||
4545 | * |
||
4546 | * @param int $mode |
||
4547 | * |
||
4548 | * @return int |
||
4549 | */ |
||
4550 | 20 | public function size(int $mode = \COUNT_NORMAL): int |
|
4554 | |||
4555 | /** |
||
4556 | * Checks whether array has exactly $size items. |
||
4557 | * |
||
4558 | * @param int $size |
||
4559 | * |
||
4560 | * @return bool |
||
4561 | */ |
||
4562 | 1 | View Code Duplication | public function sizeIs(int $size): bool |
4576 | |||
4577 | /** |
||
4578 | * Checks whether array has between $fromSize to $toSize items. $toSize can be |
||
4579 | * smaller than $fromSize. |
||
4580 | * |
||
4581 | * @param int $fromSize |
||
4582 | * @param int $toSize |
||
4583 | * |
||
4584 | * @return bool |
||
4585 | */ |
||
4586 | 1 | public function sizeIsBetween(int $fromSize, int $toSize): bool |
|
4606 | |||
4607 | /** |
||
4608 | * Checks whether array has more than $size items. |
||
4609 | * |
||
4610 | * @param int $size |
||
4611 | * |
||
4612 | * @return bool |
||
4613 | */ |
||
4614 | 1 | View Code Duplication | public function sizeIsGreaterThan(int $size): bool |
4628 | |||
4629 | /** |
||
4630 | * Checks whether array has less than $size items. |
||
4631 | * |
||
4632 | * @param int $size |
||
4633 | * |
||
4634 | * @return bool |
||
4635 | */ |
||
4636 | 1 | View Code Duplication | public function sizeIsLessThan(int $size): bool |
4650 | |||
4651 | /** |
||
4652 | * Counts all elements in an array, or something in an object. |
||
4653 | * |
||
4654 | * <p> |
||
4655 | * For objects, if you have SPL installed, you can hook into count() by implementing interface {@see Countable}. |
||
4656 | * The interface has exactly one method, {@see Countable::count()}, which returns the return value for the count() |
||
4657 | * function. Please see the {@see Array} section of the manual for a detailed explanation of how arrays are |
||
4658 | * implemented and used in PHP. |
||
4659 | * </p> |
||
4660 | * |
||
4661 | * @return int |
||
4662 | * <p> |
||
4663 | * The number of elements in var, which is |
||
4664 | * typically an array, since anything else will have one |
||
4665 | * element. |
||
4666 | * </p> |
||
4667 | * <p> |
||
4668 | * If var is not an array or an object with |
||
4669 | * implemented Countable interface, |
||
4670 | * 1 will be returned. |
||
4671 | * There is one exception, if var is &null;, |
||
4672 | * 0 will be returned. |
||
4673 | * </p> |
||
4674 | * <p> |
||
4675 | * Caution: count may return 0 for a variable that isn't set, |
||
4676 | * but it may also return 0 for a variable that has been initialized with an |
||
4677 | * empty array. Use isset to test if a variable is set. |
||
4678 | * </p> |
||
4679 | */ |
||
4680 | 10 | public function sizeRecursive(): int |
|
4684 | |||
4685 | /** |
||
4686 | * Extract a slice of the array. |
||
4687 | * |
||
4688 | * @param int $offset <p>Slice begin index.</p> |
||
4689 | * @param int|null $length <p>Length of the slice.</p> |
||
4690 | * @param bool $preserveKeys <p>Whether array keys are preserved or no.</p> |
||
4691 | * |
||
4692 | * @return static |
||
4693 | * <p>(Immutable) A slice of the original array with length $length.</p> |
||
4694 | * |
||
4695 | * @psalm-return static<TKey,T> |
||
4696 | */ |
||
4697 | 5 | public function slice(int $offset, int $length = null, bool $preserveKeys = false) |
|
4710 | |||
4711 | /** |
||
4712 | * Sort the current array and optional you can keep the keys. |
||
4713 | * |
||
4714 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
4715 | * @param int $strategy <p>sort_flags => use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
4716 | * <strong>SORT_NATURAL</strong></p> |
||
4717 | * @param bool $keepKeys |
||
4718 | * |
||
4719 | * @return static |
||
4720 | * <p>(Mutable) Return this Arrayy object.</p> |
||
4721 | * |
||
4722 | * @psalm-return static<TKey,T> |
||
4723 | */ |
||
4724 | 20 | public function sort($direction = \SORT_ASC, int $strategy = \SORT_REGULAR, bool $keepKeys = false): self |
|
4735 | |||
4736 | /** |
||
4737 | * Sort the current array by key. |
||
4738 | * |
||
4739 | * @see http://php.net/manual/en/function.ksort.php |
||
4740 | * @see http://php.net/manual/en/function.krsort.php |
||
4741 | * |
||
4742 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
4743 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
4744 | * <strong>SORT_NATURAL</strong></p> |
||
4745 | * |
||
4746 | * @return static |
||
4747 | * <p>(Mutable) Return this Arrayy object.</p> |
||
4748 | * |
||
4749 | * @psalm-return static<TKey,T> |
||
4750 | */ |
||
4751 | 18 | public function sortKeys($direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
4759 | |||
4760 | /** |
||
4761 | * Sort the current array by value. |
||
4762 | * |
||
4763 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
4764 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
4765 | * <strong>SORT_NATURAL</strong></p> |
||
4766 | * |
||
4767 | * @return static |
||
4768 | * <p>(Mutable)</p> |
||
4769 | * |
||
4770 | * @psalm-return static<TKey,T> |
||
4771 | */ |
||
4772 | 1 | public function sortValueKeepIndex($direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
4776 | |||
4777 | /** |
||
4778 | * Sort the current array by value. |
||
4779 | * |
||
4780 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
4781 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
4782 | * <strong>SORT_NATURAL</strong></p> |
||
4783 | * |
||
4784 | * @return static |
||
4785 | * <p>(Mutable)</p> |
||
4786 | * |
||
4787 | * @psalm-return static<TKey,T> |
||
4788 | */ |
||
4789 | 1 | public function sortValueNewIndex($direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
4793 | |||
4794 | /** |
||
4795 | * Sort a array by value, by a closure or by a property. |
||
4796 | * |
||
4797 | * - If the sorter is null, the array is sorted naturally. |
||
4798 | * - Associative (string) keys will be maintained, but numeric keys will be re-indexed. |
||
4799 | * |
||
4800 | * @param callable|string|null $sorter |
||
4801 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or |
||
4802 | * <strong>SORT_DESC</strong></p> |
||
4803 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
4804 | * <strong>SORT_NATURAL</strong></p> |
||
4805 | * |
||
4806 | * @return static |
||
4807 | * <p>(Immutable)</p> |
||
4808 | * |
||
4809 | * @psalm-return static<TKey,T> |
||
4810 | */ |
||
4811 | 1 | public function sorter($sorter = null, $direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
4848 | |||
4849 | /** |
||
4850 | * @param int $offset |
||
4851 | * @param int|null $length |
||
4852 | * @param array $replacement |
||
4853 | * |
||
4854 | * @return static |
||
4855 | * <p>(Immutable)</p> |
||
4856 | * |
||
4857 | * @psalm-param array<mixed,mixed>|array<mixed,T> $replacement |
||
4858 | * @psalm-return static<TKey,T> |
||
4859 | */ |
||
4860 | 1 | public function splice(int $offset, int $length = null, $replacement = []): self |
|
4877 | |||
4878 | /** |
||
4879 | * Split an array in the given amount of pieces. |
||
4880 | * |
||
4881 | * @param int $numberOfPieces |
||
4882 | * @param bool $keepKeys |
||
4883 | * |
||
4884 | * @return static |
||
4885 | * <p>(Immutable)</p> |
||
4886 | * |
||
4887 | * @psalm-return static<TKey,T> |
||
4888 | */ |
||
4889 | 1 | public function split(int $numberOfPieces = 2, bool $keepKeys = false): self |
|
4908 | |||
4909 | /** |
||
4910 | * Stripe all empty items. |
||
4911 | * |
||
4912 | * @return static |
||
4913 | * <p>(Immutable)</p> |
||
4914 | * |
||
4915 | * @psalm-return static<TKey,T> |
||
4916 | */ |
||
4917 | 1 | public function stripEmpty(): self |
|
4929 | |||
4930 | /** |
||
4931 | * Swap two values between positions by key. |
||
4932 | * |
||
4933 | * @param int|string $swapA <p>a key in the array</p> |
||
4934 | * @param int|string $swapB <p>a key in the array</p> |
||
4935 | * |
||
4936 | * @return static |
||
4937 | * <p>(Immutable)</p> |
||
4938 | * |
||
4939 | * @psalm-return static<TKey,T> |
||
4940 | */ |
||
4941 | 1 | public function swap($swapA, $swapB): self |
|
4953 | |||
4954 | /** |
||
4955 | * alias: for "Arrayy->getArray()" |
||
4956 | * |
||
4957 | * @param bool $convertAllArrayyElements |
||
4958 | * |
||
4959 | * @return array |
||
4960 | * |
||
4961 | * @see Arrayy::getArray() |
||
4962 | * |
||
4963 | * @psalm-return array<array-key,mixed> |
||
4964 | */ |
||
4965 | 241 | public function toArray(bool $convertAllArrayyElements = false): array |
|
4969 | |||
4970 | /** |
||
4971 | * Convert the current array to JSON. |
||
4972 | * |
||
4973 | * @param int $options [optional] <p>e.g. JSON_PRETTY_PRINT</p> |
||
4974 | * @param int $depth [optional] <p>Set the maximum depth. Must be greater than zero.</p> |
||
4975 | * |
||
4976 | * @return string |
||
4977 | */ |
||
4978 | 7 | public function toJson(int $options = 0, int $depth = 512): string |
|
4987 | |||
4988 | /** |
||
4989 | * @param string[]|null $items |
||
4990 | * @param string[] $helper |
||
4991 | * |
||
4992 | * @return static |
||
4993 | * |
||
4994 | * @psalm-return static<mixed,T> |
||
4995 | */ |
||
4996 | 1 | public function toPermutation(array $items = null, array $helper = []): self |
|
5030 | |||
5031 | /** |
||
5032 | * Implodes array to a string with specified separator. |
||
5033 | * |
||
5034 | * @param string $separator [optional] <p>The element's separator.</p> |
||
5035 | * |
||
5036 | * @return string |
||
5037 | * <p>The string representation of array, separated by ",".</p> |
||
5038 | */ |
||
5039 | 19 | public function toString(string $separator = ','): string |
|
5043 | |||
5044 | /** |
||
5045 | * Return a duplicate free copy of the current array. |
||
5046 | * |
||
5047 | * @return static |
||
5048 | * <p>(Mutable)</p> |
||
5049 | * |
||
5050 | * @psalm-return static<TKey,T> |
||
5051 | */ |
||
5052 | 13 | public function unique(): self |
|
5070 | |||
5071 | /** |
||
5072 | * Return a duplicate free copy of the current array. (with the old keys) |
||
5073 | * |
||
5074 | * @return static |
||
5075 | * <p>(Mutable)</p> |
||
5076 | * |
||
5077 | * @psalm-return static<TKey,T> |
||
5078 | */ |
||
5079 | 11 | public function uniqueKeepIndex(): self |
|
5107 | |||
5108 | /** |
||
5109 | * alias: for "Arrayy->unique()" |
||
5110 | * |
||
5111 | * @return static |
||
5112 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
5113 | * |
||
5114 | * @see Arrayy::unique() |
||
5115 | * |
||
5116 | * @psalm-return static<TKey,T> |
||
5117 | */ |
||
5118 | 10 | public function uniqueNewIndex(): self |
|
5122 | |||
5123 | /** |
||
5124 | * Prepends one or more values to the beginning of array at once. |
||
5125 | * |
||
5126 | * @param array ...$args |
||
5127 | * |
||
5128 | * @return static |
||
5129 | * <p>(Mutable) Return this Arrayy object, with prepended elements to the beginning of array.</p> |
||
5130 | * |
||
5131 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$args |
||
5132 | * @psalm-return static<TKey,T> |
||
5133 | */ |
||
5134 | 4 | public function unshift(...$args): self |
|
5142 | |||
5143 | /** |
||
5144 | * Tests whether the given closure retrun something valid for all elements of this array. |
||
5145 | * |
||
5146 | * @param \Closure $closure the predicate |
||
5147 | * |
||
5148 | * @return bool |
||
5149 | * <p>TRUE, if the predicate yields TRUE for all elements, FALSE otherwise.</p> |
||
5150 | */ |
||
5151 | 1 | View Code Duplication | public function validate(\Closure $closure): bool |
5161 | |||
5162 | /** |
||
5163 | * Get all values from a array. |
||
5164 | * |
||
5165 | * @return static |
||
5166 | * <p>(Immutable)</p> |
||
5167 | * |
||
5168 | * @psalm-return static<mixed,T> |
||
5169 | */ |
||
5170 | 2 | public function values(): self |
|
5183 | |||
5184 | /** |
||
5185 | * Apply the given function to every element in the array, discarding the results. |
||
5186 | * |
||
5187 | * @param callable $callable |
||
5188 | * @param bool $recursive <p>Whether array will be walked recursively or no</p> |
||
5189 | * |
||
5190 | * @return static |
||
5191 | * <p>(Mutable) Return this Arrayy object, with modified elements.</p> |
||
5192 | * |
||
5193 | * @psalm-return static<TKey,T> |
||
5194 | */ |
||
5195 | 12 | public function walk($callable, bool $recursive = false): self |
|
5207 | |||
5208 | /** |
||
5209 | * Returns a collection of matching items. |
||
5210 | * |
||
5211 | * @param string $keyOrPropertyOrMethod the property or method to evaluate |
||
5212 | * @param mixed $value the value to match |
||
5213 | * |
||
5214 | * @throws \InvalidArgumentException if property or method is not defined |
||
5215 | * |
||
5216 | * @return static |
||
5217 | * |
||
5218 | * @psalm-param T $value |
||
5219 | * @psalm-return static<TKey,T> |
||
5220 | */ |
||
5221 | 1 | public function where(string $keyOrPropertyOrMethod, $value): self |
|
5234 | |||
5235 | /** |
||
5236 | * Convert an array into a object. |
||
5237 | * |
||
5238 | * @param array $array |
||
5239 | * |
||
5240 | * @return \stdClass |
||
5241 | * |
||
5242 | * @psalm-param array<mixed,mixed> $array |
||
5243 | */ |
||
5244 | 4 | final protected static function arrayToObject(array $array = []): \stdClass |
|
5263 | |||
5264 | /** |
||
5265 | * @param array|\Generator|null $input <p> |
||
5266 | * An array containing keys to return. |
||
5267 | * </p> |
||
5268 | * @param mixed|null $search_values [optional] <p> |
||
5269 | * If specified, then only keys containing these values are returned. |
||
5270 | * </p> |
||
5271 | * @param bool $strict [optional] <p> |
||
5272 | * Determines if strict comparison (===) should be used during the |
||
5273 | * search. |
||
5274 | * </p> |
||
5275 | * |
||
5276 | * @return array |
||
5277 | * <p>an array of all the keys in input</p> |
||
5278 | * |
||
5279 | * @psalm-param array<mixed,mixed>|\Generator<TKey,T>|null $input |
||
5280 | * @psalm-return array<TKey|mixed> |
||
5281 | */ |
||
5282 | 11 | protected function array_keys_recursive( |
|
5343 | |||
5344 | /** |
||
5345 | * @param mixed $path |
||
5346 | * @param callable $callable |
||
5347 | * @param array|null $currentOffset |
||
5348 | * |
||
5349 | * @return void |
||
5350 | * |
||
5351 | * @psalm-param array<mixed,mixed>|array<TKey,T>|null $currentOffset |
||
5352 | */ |
||
5353 | 4 | protected function callAtPath($path, $callable, &$currentOffset = null) |
|
5382 | |||
5383 | /** |
||
5384 | * Extracts the value of the given property or method from the object. |
||
5385 | * |
||
5386 | * @param static $object <p>The object to extract the value from.</p> |
||
5387 | * @param string $keyOrPropertyOrMethod <p>The property or method for which the |
||
5388 | * value should be extracted.</p> |
||
5389 | * |
||
5390 | * @throws \InvalidArgumentException if the method or property is not defined |
||
5391 | * |
||
5392 | * @return mixed |
||
5393 | * <p>The value extracted from the specified property or method.</p> |
||
5394 | * |
||
5395 | * @psalm-param self<TKey,T> $object |
||
5396 | */ |
||
5397 | 2 | final protected function extractValue(self $object, string $keyOrPropertyOrMethod) |
|
5419 | |||
5420 | /** |
||
5421 | * create a fallback for array |
||
5422 | * |
||
5423 | * 1. use the current array, if it's a array |
||
5424 | * 2. fallback to empty array, if there is nothing |
||
5425 | * 3. call "getArray()" on object, if there is a "Arrayy"-object |
||
5426 | * 4. call "createFromObject()" on object, if there is a "\Traversable"-object |
||
5427 | * 5. call "__toArray()" on object, if the method exists |
||
5428 | * 6. cast a string or object with "__toString()" into an array |
||
5429 | * 7. throw a "InvalidArgumentException"-Exception |
||
5430 | * |
||
5431 | * @param mixed $data |
||
5432 | * |
||
5433 | * @throws \InvalidArgumentException |
||
5434 | * |
||
5435 | * @return array |
||
5436 | * |
||
5437 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
5438 | */ |
||
5439 | 1066 | protected function fallbackForArray(&$data): array |
|
5449 | |||
5450 | /** |
||
5451 | * @return bool |
||
5452 | * |
||
5453 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
5454 | */ |
||
5455 | 982 | protected function generatorToArray() |
|
5466 | |||
5467 | /** |
||
5468 | * Get correct PHP constant for direction. |
||
5469 | * |
||
5470 | * @param int|string $direction |
||
5471 | * |
||
5472 | * @return int |
||
5473 | */ |
||
5474 | 39 | protected function getDirection($direction): int |
|
5496 | |||
5497 | /** |
||
5498 | * @return TypeCheckPhpDoc[] |
||
5499 | * |
||
5500 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
5501 | */ |
||
5502 | 16 | protected function getPropertiesFromPhpDoc() |
|
5527 | |||
5528 | /** |
||
5529 | * @param mixed $glue |
||
5530 | * @param mixed $pieces |
||
5531 | * @param bool $useKeys |
||
5532 | * |
||
5533 | * @return string |
||
5534 | */ |
||
5535 | 36 | protected function implode_recursive($glue = '', $pieces = [], bool $useKeys = false): string |
|
5565 | |||
5566 | /** |
||
5567 | * @param mixed $needle <p> |
||
5568 | * The searched value. |
||
5569 | * </p> |
||
5570 | * <p> |
||
5571 | * If needle is a string, the comparison is done |
||
5572 | * in a case-sensitive manner. |
||
5573 | * </p> |
||
5574 | * @param array|\Generator|null $haystack <p> |
||
5575 | * The array. |
||
5576 | * </p> |
||
5577 | * @param bool $strict [optional] <p> |
||
5578 | * If the third parameter strict is set to true |
||
5579 | * then the in_array function will also check the |
||
5580 | * types of the |
||
5581 | * needle in the haystack. |
||
5582 | * </p> |
||
5583 | * |
||
5584 | * @return bool |
||
5585 | * <p>true if needle is found in the array, false otherwise</p> |
||
5586 | * |
||
5587 | * @psalm-param array<mixed,mixed>|\Generator<TKey,T>|null $haystack |
||
5588 | */ |
||
5589 | 18 | protected function in_array_recursive($needle, $haystack = null, $strict = true): bool |
|
5614 | |||
5615 | /** |
||
5616 | * @param mixed $data |
||
5617 | * |
||
5618 | * @return array|null |
||
5619 | * |
||
5620 | * @psalm-return array<mixed,mixed>|array<TKey,T>|null |
||
5621 | */ |
||
5622 | 1066 | protected function internalGetArray(&$data) |
|
5670 | |||
5671 | /** |
||
5672 | * Internal mechanics of remove method. |
||
5673 | * |
||
5674 | * @param mixed $key |
||
5675 | * |
||
5676 | * @return bool |
||
5677 | */ |
||
5678 | 18 | protected function internalRemove($key): bool |
|
5711 | |||
5712 | /** |
||
5713 | * Internal mechanic of set method. |
||
5714 | * |
||
5715 | * @param int|string|null $key |
||
5716 | * @param mixed $value |
||
5717 | * @param bool $checkProperties |
||
5718 | * |
||
5719 | * @return bool |
||
5720 | */ |
||
5721 | 938 | protected function internalSet( |
|
5767 | |||
5768 | /** |
||
5769 | * Convert a object into an array. |
||
5770 | * |
||
5771 | * @param object $object |
||
5772 | * |
||
5773 | * @return mixed |
||
5774 | */ |
||
5775 | 5 | protected static function objectToArray($object) |
|
5787 | |||
5788 | /** |
||
5789 | * @param array $data |
||
5790 | * @param bool $checkPropertiesInConstructor |
||
5791 | * |
||
5792 | * @return void |
||
5793 | * |
||
5794 | * @psalm-param array<mixed,T> $data |
||
5795 | */ |
||
5796 | 1064 | protected function setInitialValuesAndProperties(array &$data, bool $checkPropertiesInConstructor) |
|
5838 | |||
5839 | /** |
||
5840 | * sorting keys |
||
5841 | * |
||
5842 | * @param array $elements |
||
5843 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
5844 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
5845 | * <strong>SORT_NATURAL</strong></p> |
||
5846 | * |
||
5847 | * @return static |
||
5848 | * <p>(Mutable) Return this Arrayy object.</p> |
||
5849 | * |
||
5850 | * @psalm-param array<mixed,mixed>|array<mixed|TKey,T> $elements |
||
5851 | * @psalm-return static<mixed|TKey,T> |
||
5852 | */ |
||
5853 | 18 | protected function sorterKeys(array &$elements, $direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
5871 | |||
5872 | /** |
||
5873 | * @param array $elements <p>Warning: used as reference</p> |
||
5874 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
5875 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
5876 | * <strong>SORT_NATURAL</strong></p> |
||
5877 | * @param bool $keepKeys |
||
5878 | * |
||
5879 | * @return static |
||
5880 | * <p>(Mutable) Return this Arrayy object.</p> |
||
5881 | * |
||
5882 | * @psalm-param array<mixed> $elements |
||
5883 | * @psalm-return static<mixed|TKey,T> |
||
5884 | */ |
||
5885 | 20 | protected function sorting(array &$elements, $direction = \SORT_ASC, int $strategy = \SORT_REGULAR, bool $keepKeys = false): self |
|
5915 | |||
5916 | /** |
||
5917 | * @param int|string|null $key |
||
5918 | * @param mixed $value |
||
5919 | * |
||
5920 | * @return void |
||
5921 | */ |
||
5922 | 87 | private function checkType($key, $value) |
|
5940 | } |
||
5941 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.