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 |
||
17 | class Arrayy extends \ArrayObject implements \IteratorAggregate, \ArrayAccess, \Serializable, \Countable |
||
18 | { |
||
19 | /** |
||
20 | * @var array |
||
21 | */ |
||
22 | protected $array = []; |
||
23 | |||
24 | /** |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $iteratorClass = ArrayyIterator::class; |
||
28 | |||
29 | /** |
||
30 | * @var string |
||
31 | */ |
||
32 | protected $pathSeparator = '.'; |
||
33 | |||
34 | /** @noinspection MagicMethodsValidityInspection */ |
||
35 | /** |
||
36 | * Initializes |
||
37 | * |
||
38 | * @param mixed $array <p>Should be an array, otherwise it will try to convert it into an array.</p> |
||
39 | * @param string $iteratorClass |
||
40 | */ |
||
41 | 870 | public function __construct($array = [], $iteratorClass = ArrayyIterator::class) |
|
48 | |||
49 | /** |
||
50 | * Get a value by key. |
||
51 | * |
||
52 | * @param mixed $key |
||
53 | * |
||
54 | * @return mixed <p>Get a Value from the current array.</p> |
||
55 | */ |
||
56 | 2 | public function &__get($key) |
|
66 | |||
67 | /** |
||
68 | * Call object as function. |
||
69 | * |
||
70 | * @param mixed $key |
||
71 | * |
||
72 | * @return mixed |
||
73 | */ |
||
74 | 1 | public function __invoke($key = null) |
|
86 | |||
87 | /** |
||
88 | * Whether or not an element exists by key. |
||
89 | * |
||
90 | * @param mixed $key |
||
91 | * |
||
92 | * @return bool <p>True is the key/index exists, otherwise false.</p> |
||
93 | */ |
||
94 | public function __isset($key) |
||
98 | |||
99 | /** |
||
100 | * Assigns a value to the specified element. |
||
101 | * |
||
102 | * @param mixed $key |
||
103 | * @param mixed $value |
||
104 | */ |
||
105 | 2 | public function __set($key, $value) |
|
109 | |||
110 | /** |
||
111 | * magic to string |
||
112 | * |
||
113 | * @return string |
||
114 | */ |
||
115 | 15 | public function __toString() |
|
119 | |||
120 | /** |
||
121 | * Unset element by key. |
||
122 | * |
||
123 | * @param mixed $key |
||
124 | */ |
||
125 | public function __unset($key) |
||
129 | |||
130 | /** |
||
131 | * alias: for "Arrayy->append()" |
||
132 | * |
||
133 | * @see Arrayy::append() |
||
134 | * |
||
135 | * @param mixed $value |
||
136 | * |
||
137 | * @return static <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
138 | */ |
||
139 | 1 | public function add($value) |
|
143 | |||
144 | /** |
||
145 | * Append a (key) + values to the current array. |
||
146 | * |
||
147 | * @param array $values |
||
148 | * @param mixed $key |
||
149 | * |
||
150 | * @return static <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
151 | */ |
||
152 | 9 | public function appendArrayValues(array $values, $key = null) |
|
176 | 4 | ||
177 | /** |
||
178 | 4 | * Append a (key) + value to the current array. |
|
179 | * |
||
180 | * @param mixed $value |
||
181 | * @param mixed $key |
||
182 | * |
||
183 | * @return static <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
184 | */ |
||
185 | public function append($value, $key = null) |
||
203 | |||
204 | /** |
||
205 | * Sort the entries by value. |
||
206 | * |
||
207 | * @param int $sort_flags [optional] <p> |
||
208 | * You may modify the behavior of the sort using the optional |
||
209 | * parameter sort_flags, for details |
||
210 | * see sort. |
||
211 | * </p> |
||
212 | * |
||
213 | 37 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
|
214 | */ |
||
215 | 37 | public function asort(int $sort_flags = 0) |
|
221 | |||
222 | /** |
||
223 | * Counts all elements in an array, or something in an object. |
||
224 | * <p>For objects, if you have SPL installed, you can hook into count() by implementing interface {@see Countable}. |
||
225 | 1 | * The interface has exactly one method, {@see Countable::count()}, which returns the return value for the count() |
|
226 | * function. Please see the {@see Array} section of the manual for a detailed explanation of how arrays are |
||
227 | 1 | * implemented and used in PHP. |
|
228 | * |
||
229 | 1 | * @link http://php.net/manual/en/function.count.php |
|
230 | * |
||
231 | * @param int $mode [optional] If the optional mode parameter is set to |
||
232 | * COUNT_RECURSIVE (or 1), count |
||
233 | * will recursively count the array. This is particularly useful for |
||
234 | * counting all the elements of a multidimensional array. count does not detect infinite recursion. |
||
235 | * |
||
236 | * @return int the number of elements in var, which is |
||
237 | 1 | * typically an array, since anything else will have one |
|
238 | * element. |
||
239 | 1 | * </p> |
|
240 | * <p> |
||
241 | * If var is not an array or an object with |
||
242 | * implemented Countable interface, |
||
243 | * 1 will be returned. |
||
244 | * There is one exception, if var is &null;, |
||
245 | * 0 will be returned. |
||
246 | * </p> |
||
247 | 20 | * <p> |
|
248 | * Caution: count may return 0 for a variable that isn't set, |
||
249 | 20 | * but it may also return 0 for a variable that has been initialized with an |
|
250 | * empty array. Use isset to test if a variable is set. |
||
251 | 20 | * |
|
252 | * @return int |
||
253 | */ |
||
254 | public function count(int $mode = COUNT_NORMAL): int |
||
258 | |||
259 | 20 | /** |
|
260 | * Exchange the array for another one. |
||
261 | 20 | * |
|
262 | * @param array|static $data |
||
263 | * |
||
264 | * @return array |
||
265 | */ |
||
266 | public function exchangeArray($data): array |
||
272 | |||
273 | /** |
||
274 | * Creates a copy of the ArrayyObject. |
||
275 | 4 | * |
|
276 | * @return array |
||
277 | 4 | */ |
|
278 | public function getArrayCopy(): array |
||
282 | |||
283 | /** |
||
284 | * Returns a new ArrayyIterator, thus implementing the \ArrayIterator interface. |
||
285 | * |
||
286 | * @return \ArrayIterator <p>An iterator for the values in the array.</p> |
||
287 | */ |
||
288 | public function getIterator(): \ArrayIterator |
||
294 | |||
295 | /** |
||
296 | * Gets the iterator classname for the ArrayObject. |
||
297 | * |
||
298 | * @return string |
||
299 | 1 | */ |
|
300 | public function getIteratorClass(): string |
||
304 | |||
305 | /** |
||
306 | * Sort the entries by key |
||
307 | * |
||
308 | * @param int $sort_flags [optional] <p> |
||
309 | * You may modify the behavior of the sort using the optional |
||
310 | * parameter sort_flags, for details |
||
311 | * see sort. |
||
312 | * </p> |
||
313 | 40 | * |
|
314 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
315 | 40 | */ |
|
316 | 4 | public function ksort(int $sort_flags = 0) |
|
322 | |||
323 | /** |
||
324 | 36 | * Sort an array using a case insensitive "natural order" algorithm |
|
325 | * |
||
326 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
327 | 36 | */ |
|
328 | public function natcasesort() |
||
334 | |||
335 | 34 | /** |
|
336 | * Sort entries using a "natural order" algorithm |
||
337 | * |
||
338 | 3 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
|
339 | */ |
||
340 | 3 | public function natsort() |
|
346 | |||
347 | 3 | /** |
|
348 | 3 | * Whether or not an offset exists. |
|
349 | 3 | * |
|
350 | 3 | * @param int|float|string $offset |
|
351 | 3 | * |
|
352 | * @return bool |
||
353 | */ |
||
354 | public function offsetExists($offset): bool |
||
398 | |||
399 | 4 | /** |
|
400 | * Returns the value at specified offset. |
||
401 | * |
||
402 | 3 | * @param int|float|string $offset |
|
403 | * |
||
404 | 2 | * @return mixed <p>Will return null if the offset did not exists.</p> |
|
405 | 2 | */ |
|
406 | public function offsetGet($offset) |
||
410 | 2 | ||
411 | 2 | /** |
|
412 | * Assigns a value to the specified offset. |
||
413 | * |
||
414 | * @param int|float|string $offset |
||
415 | 3 | * @param mixed $value |
|
416 | */ |
||
417 | public function offsetSet($offset, $value) |
||
425 | |||
426 | /** |
||
427 | * Unset an offset. |
||
428 | * |
||
429 | * @param int|float|string $offset |
||
430 | */ |
||
431 | public function offsetUnset($offset) |
||
457 | |||
458 | /** |
||
459 | * Serialize the current "Arrayy"-object. |
||
460 | * |
||
461 | * @return string |
||
462 | */ |
||
463 | public function serialize() |
||
467 | |||
468 | /** |
||
469 | * Sets the iterator classname for the current "Arrayy"-object. |
||
470 | * |
||
471 | * @param string $class |
||
472 | * |
||
473 | * @return void |
||
474 | * |
||
475 | * @throws \InvalidArgumentException |
||
476 | */ |
||
477 | public function setIteratorClass($class) |
||
496 | |||
497 | /** |
||
498 | * Sort the entries with a user-defined comparison function and maintain key association. |
||
499 | 1 | * |
|
500 | * @param \callable $function |
||
501 | 1 | * |
|
502 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
503 | 1 | * |
|
504 | * @throws \InvalidArgumentException |
||
505 | */ |
||
506 | View Code Duplication | public function uasort($function) |
|
518 | |||
519 | 9 | /** |
|
520 | * Sort the entries by keys using a user-defined comparison function. |
||
521 | * |
||
522 | 9 | * @param \callable $function |
|
523 | * |
||
524 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
525 | * |
||
526 | 10 | * @throws \InvalidArgumentException |
|
527 | */ |
||
528 | public function uksort($function) |
||
532 | |||
533 | /** |
||
534 | * Unserialize an string and return this object. |
||
535 | * |
||
536 | 10 | * @param string $string |
|
537 | * |
||
538 | 10 | * @return static <p>(Mutable)</p> |
|
539 | 10 | */ |
|
540 | 9 | public function unserialize($string) |
|
546 | |||
547 | 9 | /** |
|
548 | * Add a suffix to each key. |
||
549 | * |
||
550 | * @param mixed $prefix |
||
551 | 10 | * |
|
552 | * @return static <p>(Immutable) Return an Arrayy object, with the prefixed keys.</p> |
||
553 | */ |
||
554 | View Code Duplication | public function appendToEachKey($prefix) |
|
569 | 3 | ||
570 | 3 | /** |
|
571 | 1 | * Add a prefix to each value. |
|
572 | 1 | * |
|
573 | * @param mixed $prefix |
||
574 | 3 | * |
|
575 | * @return static <p>(Immutable) Return an Arrayy object, with the prefixed values.</p> |
||
576 | */ |
||
577 | 3 | View Code Duplication | public function appendToEachValue($prefix) |
594 | |||
595 | /** |
||
596 | 10 | * Convert an array into a object. |
|
597 | * |
||
598 | 10 | * @param array $array PHP array |
|
599 | * |
||
600 | * @return \stdClass (object) |
||
601 | */ |
||
602 | 10 | protected static function arrayToObject(array $array = []): \stdClass |
|
620 | |||
621 | /** |
||
622 | 10 | * @param array $input <p> |
|
623 | * An array containing keys to return. |
||
624 | * </p> |
||
625 | * @param mixed $search_value [optional] <p> |
||
626 | * If specified, then only keys containing these values are returned. |
||
627 | * </p> |
||
628 | * @param bool $strict [optional] <p> |
||
629 | * Determines if strict comparison (===) should be used during the search. |
||
630 | 4 | * </p> |
|
631 | * |
||
632 | 4 | * @return array an array of all the keys in input. |
|
633 | */ |
||
634 | 4 | protected function array_keys_recursive(array $input = null, $search_value = null, bool $strict = true): array |
|
665 | |||
666 | 10 | /** |
|
667 | 2 | * Sort an array in reverse order and maintain index association. |
|
668 | * |
||
669 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
670 | 8 | */ |
|
671 | 3 | public function arsort() |
|
677 | |||
678 | /** |
||
679 | * Iterate over the current array and execute a callback for each loop. |
||
680 | * |
||
681 | * @param \Closure $closure |
||
682 | 4 | * |
|
683 | * @return static <p>(Immutable)</p> |
||
684 | 4 | */ |
|
685 | 4 | View Code Duplication | public function at(\Closure $closure) |
695 | 4 | ||
696 | 1 | /** |
|
697 | 1 | * Returns the average value of the current array. |
|
698 | 1 | * |
|
699 | 1 | * @param int $decimals <p>The number of decimal-numbers to return.</p> |
|
700 | * |
||
701 | * @return int|double <p>The average value.</p> |
||
702 | 4 | */ |
|
703 | public function average($decimals = 0) |
||
717 | |||
718 | /** |
||
719 | * @param mixed $path |
||
720 | * @param \callable $callable |
||
721 | * @param null|array $currentOffset |
||
722 | */ |
||
723 | protected function callAtPath($path, $callable, &$currentOffset = null) |
||
746 | |||
747 | 4 | /** |
|
748 | * Changes all keys in an array. |
||
749 | * |
||
750 | * @param int $case [optional] <p> Either <strong>CASE_UPPER</strong><br /> |
||
751 | * or <strong>CASE_LOWER</strong> (default)</p> |
||
752 | * |
||
753 | * @return static <p>(Immutable)</p> |
||
754 | */ |
||
755 | 8 | public function changeKeyCase(int $case = CASE_LOWER) |
|
759 | 7 | ||
760 | 8 | /** |
|
761 | * Change the path separator of the array wrapper. |
||
762 | * |
||
763 | * By default, the separator is: "." |
||
764 | * |
||
765 | * @param string $separator <p>Separator to set.</p> |
||
766 | * |
||
767 | * @return static <p>Mutable</p> |
||
768 | */ |
||
769 | 4 | public function changeSeparator($separator) |
|
775 | |||
776 | /** |
||
777 | * Create a chunked version of the current array. |
||
778 | * |
||
779 | * @param int $size <p>Size of each chunk.</p> |
||
780 | * @param bool $preserveKeys <p>Whether array keys are preserved or no.</p> |
||
781 | * |
||
782 | * @return static <p>(Immutable) A new array of chunks from the original array.</p> |
||
783 | */ |
||
784 | public function chunk($size, $preserveKeys = false) |
||
790 | |||
791 | 13 | /** |
|
792 | * Clean all falsy values from the current array. |
||
793 | * |
||
794 | * @return static <p>(Immutable)</p> |
||
795 | */ |
||
796 | public function clean() |
||
804 | 26 | ||
805 | 26 | /** |
|
806 | 26 | * WARNING!!! -> Clear the current array. |
|
807 | 26 | * |
|
808 | 26 | * @return static <p>(Mutable) Return this Arrayy object, with an empty array.</p> |
|
809 | 22 | */ |
|
810 | 26 | public function clear() |
|
816 | |||
817 | 13 | /** |
|
818 | 13 | * Check if an item is in the current array. |
|
819 | 13 | * |
|
820 | 13 | * @param string|int|float $value |
|
821 | 11 | * @param bool $recursive |
|
822 | 13 | * @param bool $strict |
|
823 | 13 | * |
|
824 | 13 | * @return bool |
|
825 | 13 | */ |
|
826 | public function contains($value, $recursive = false, $strict = true): bool |
||
834 | |||
835 | /** |
||
836 | 4 | * Check if an (case-insensitive) string is in the current array. |
|
837 | * |
||
838 | 4 | * @param string $value |
|
839 | * @param bool $recursive |
||
840 | * |
||
841 | * @return bool |
||
842 | */ |
||
843 | public function containsCaseInsensitive($value, $recursive = false): bool |
||
869 | 1 | ||
870 | 1 | /** |
|
871 | * Check if the given key/index exists in the array. |
||
872 | * |
||
873 | * @param string|int|float $key <p>key/index to search for</p> |
||
874 | * |
||
875 | * @return bool <p>Returns true if the given key/index exists in the array, false otherwise.</p> |
||
876 | */ |
||
877 | public function containsKey($key): bool |
||
881 | 1 | ||
882 | /** |
||
883 | 1 | * Check if all given needles are present in the array as key/index. |
|
884 | * |
||
885 | * @param array $needles <p>The keys you are searching for.</p> |
||
886 | * @param bool $recursive |
||
887 | * |
||
888 | * @return bool <p>Returns true if all the given keys/indexes exists in the array, false otherwise.</p> |
||
889 | */ |
||
890 | public function containsKeys(array $needles, $recursive = false): bool |
||
914 | |||
915 | /** |
||
916 | * Check if all given needles are present in the array as key/index. |
||
917 | * |
||
918 | * @param array $needles <p>The keys you are searching for.</p> |
||
919 | * |
||
920 | * @return bool <p>Returns true if all the given keys/indexes exists in the array, false otherwise.</p> |
||
921 | 1 | */ |
|
922 | public function containsKeysRecursive(array $needles): bool |
||
926 | |||
927 | /** |
||
928 | * alias: for "Arrayy->contains()" |
||
929 | * |
||
930 | * @see Arrayy::contains() |
||
931 | * |
||
932 | * @param string|int|float $value |
||
933 | * |
||
934 | * @return bool |
||
935 | */ |
||
936 | public function containsValue($value): bool |
||
940 | |||
941 | 1 | /** |
|
942 | * alias: for "Arrayy->contains($value, true)" |
||
943 | * |
||
944 | * @see Arrayy::contains() |
||
945 | * |
||
946 | * @param string|int|float $value |
||
947 | * |
||
948 | * @return bool |
||
949 | */ |
||
950 | public function containsValueRecursive($value): bool |
||
954 | |||
955 | /** |
||
956 | * Check if all given needles are present in the array. |
||
957 | * |
||
958 | * @param array $needles |
||
959 | * |
||
960 | * @return bool <p>Returns true if all the given values exists in the array, false otherwise.</p> |
||
961 | */ |
||
962 | public function containsValues(array $needles): bool |
||
968 | |||
969 | 1 | /** |
|
970 | * Counts all the values of an array |
||
971 | * |
||
972 | * @link http://php.net/manual/en/function.array-count-values.php |
||
973 | * |
||
974 | * @return static <p> |
||
975 | * (Immutable) |
||
976 | * An associative Arrayy-object of values from input as |
||
977 | * keys and their count as value. |
||
978 | * </p> |
||
979 | 5 | */ |
|
980 | public function countValues(): self |
||
984 | |||
985 | /** |
||
986 | * Creates an Arrayy object. |
||
987 | * |
||
988 | * @param mixed $array |
||
989 | * |
||
990 | * @return static <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
991 | */ |
||
992 | public static function create($array = []): self |
||
996 | 4 | ||
997 | /** |
||
998 | 3 | * WARNING: Creates an Arrayy object by reference. |
|
999 | * |
||
1000 | * @param array $array |
||
1001 | 4 | * |
|
1002 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
1003 | */ |
||
1004 | public function createByReference(array &$array = []): self |
||
1012 | |||
1013 | 5 | /** |
|
1014 | * Create an new Arrayy object via JSON. |
||
1015 | * |
||
1016 | * @param string $json |
||
1017 | * |
||
1018 | * @return static <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1019 | */ |
||
1020 | public static function createFromJson(string $json) |
||
1026 | 8 | ||
1027 | /** |
||
1028 | 8 | * Create an new instance filled with values from an object that have implemented ArrayAccess. |
|
1029 | 1 | * |
|
1030 | * @param \ArrayAccess $object <p>Object that implements ArrayAccess</p> |
||
1031 | 1 | * |
|
1032 | 1 | * @return static <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
|
1033 | */ |
||
1034 | public static function createFromObject(\ArrayAccess $object) |
||
1044 | 8 | ||
1045 | 8 | /** |
|
1046 | * Create an new instance filled with values from an object. |
||
1047 | 8 | * |
|
1048 | * @param object $object |
||
1049 | * |
||
1050 | 8 | * @return static <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
|
1051 | */ |
||
1052 | public static function createFromObjectVars($object): self |
||
1056 | |||
1057 | /** |
||
1058 | * Create an new Arrayy object via string. |
||
1059 | * |
||
1060 | * @param string $str <p>The input string.</p> |
||
1061 | * @param string|null $delimiter <p>The boundary string.</p> |
||
1062 | 1 | * @param string|null $regEx <p>Use the $delimiter or the $regEx, so if $pattern is null, $delimiter will be |
|
1063 | * used.</p> |
||
1064 | 1 | * |
|
1065 | * @return static <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1066 | */ |
||
1067 | public static function createFromString(string $str, string $delimiter = null, string $regEx = null) |
||
1093 | |||
1094 | /** |
||
1095 | * Create an new instance containing a range of elements. |
||
1096 | * |
||
1097 | * @param mixed $low <p>First value of the sequence.</p> |
||
1098 | * @param mixed $high <p>The sequence is ended upon reaching the end value.</p> |
||
1099 | * @param int $step <p>Used as the increment between elements in the sequence.</p> |
||
1100 | * |
||
1101 | * @return static <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1102 | 5 | */ |
|
1103 | public static function createWithRange($low, $high, int $step = 1) |
||
1107 | |||
1108 | /** |
||
1109 | * Custom sort by index via "uksort". |
||
1110 | 5 | * |
|
1111 | * @link http://php.net/manual/en/function.uksort.php |
||
1112 | 5 | * |
|
1113 | * @param \callable $function |
||
1114 | * |
||
1115 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
1116 | * |
||
1117 | * @throws \InvalidArgumentException |
||
1118 | */ |
||
1119 | View Code Duplication | public function customSortKeys($function) |
|
1131 | |||
1132 | /** |
||
1133 | * Custom sort by value via "usort". |
||
1134 | * |
||
1135 | * @link http://php.net/manual/en/function.usort.php |
||
1136 | * |
||
1137 | 1 | * @param \callable $function |
|
1138 | * |
||
1139 | 1 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
|
1140 | * |
||
1141 | * @throws \InvalidArgumentException |
||
1142 | 1 | */ |
|
1143 | View Code Duplication | public function customSortValues($function) |
|
1155 | 1 | ||
1156 | 1 | /** |
|
1157 | * Return values that are only in the current array. |
||
1158 | 1 | * |
|
1159 | 1 | * @param array $array |
|
1160 | * |
||
1161 | * @return static <p>(Immutable)</p> |
||
1162 | 1 | */ |
|
1163 | public function diff(array $array = []) |
||
1169 | |||
1170 | /** |
||
1171 | * Return values that are only in the current multi-dimensional array. |
||
1172 | * |
||
1173 | * @param array $array |
||
1174 | * @param null|array $helperVariableForRecursion <p>(only for internal usage)</p> |
||
1175 | * |
||
1176 | 8 | * @return static <p>(Immutable)</p> |
|
1177 | */ |
||
1178 | 8 | public function diffRecursive(array $array = [], $helperVariableForRecursion = null) |
|
1209 | 4 | ||
1210 | 4 | /** |
|
1211 | * Return values that are only in the new $array. |
||
1212 | * |
||
1213 | 4 | * @param array $array |
|
1214 | * |
||
1215 | * @return static <p>(Immutable)</p> |
||
1216 | */ |
||
1217 | public function diffReverse(array $array = []) |
||
1223 | 4 | ||
1224 | /** |
||
1225 | 4 | * Divide an array into two arrays. One with keys and the other with values. |
|
1226 | 4 | * |
|
1227 | 3 | * @return static <p>(Immutable)</p> |
|
1228 | 1 | */ |
|
1229 | 3 | public function divide() |
|
1238 | |||
1239 | /** |
||
1240 | * Iterate over the current array and modify the array's value. |
||
1241 | * |
||
1242 | * @param \Closure $closure |
||
1243 | * |
||
1244 | * @return static <p>(Immutable)</p> |
||
1245 | */ |
||
1246 | View Code Duplication | public function each(\Closure $closure) |
|
1256 | 867 | ||
1257 | /** |
||
1258 | * Check if a value is in the current array using a closure. |
||
1259 | 11 | * |
|
1260 | 1 | * @param \Closure $closure |
|
1261 | * |
||
1262 | * @return bool <p>Returns true if the given value is found, false otherwise.</p> |
||
1263 | 10 | */ |
|
1264 | 6 | public function exists(\Closure $closure): bool |
|
1276 | |||
1277 | /** |
||
1278 | 9 | * create a fallback for array |
|
1279 | * |
||
1280 | * 1. use the current array, if it's a array |
||
1281 | * 2. call "getArray()" on object, if there is a "Arrayy"-object |
||
1282 | * 3. fallback to empty array, if there is nothing |
||
1283 | * 4. call "createFromObject()" on object, if there is a "\ArrayAccess"-object |
||
1284 | 9 | * 5. call "__toArray()" on object, if the method exists |
|
1285 | * 6. cast a string or object with "__toString()" into an array |
||
1286 | 9 | * 7. throw a "InvalidArgumentException"-Exception |
|
1287 | * |
||
1288 | 7 | * @param $array |
|
1289 | * |
||
1290 | * @return array |
||
1291 | 2 | * |
|
1292 | 2 | * @throws \InvalidArgumentException |
|
1293 | */ |
||
1294 | protected function fallbackForArray(&$array): array |
||
1336 | |||
1337 | /** |
||
1338 | * Fill the array until "$num" with "$default" values. |
||
1339 | * |
||
1340 | * @param int $num |
||
1341 | * @param mixed $default |
||
1342 | * |
||
1343 | * @return static <p>(Immutable)</p> |
||
1344 | */ |
||
1345 | public function fillWithDefaults(int $num, $default = null) |
||
1362 | |||
1363 | /** |
||
1364 | * Find all items in an array that pass the truth test. |
||
1365 | * |
||
1366 | * @param \Closure|null $closure [optional] <p> |
||
1367 | * The callback function to use |
||
1368 | * </p> |
||
1369 | * <p> |
||
1370 | * If no callback is supplied, all entries of |
||
1371 | * input equal to false (see |
||
1372 | * converting to |
||
1373 | * boolean) will be removed. |
||
1374 | * </p> |
||
1375 | * |
||
1376 | * * @param int $flag [optional] <p> |
||
1377 | * Flag determining what arguments are sent to <i>callback</i>: |
||
1378 | * </p><ul> |
||
1379 | * <li> |
||
1380 | * <b>ARRAY_FILTER_USE_KEY</b> [1] - pass key as the only argument |
||
1381 | * to <i>callback</i> instead of the value</span> |
||
1382 | * </li> |
||
1383 | 1 | * <li> |
|
1384 | * <b>ARRAY_FILTER_USE_BOTH</b> [2] - pass both value and key as |
||
1385 | 1 | * arguments to <i>callback</i> instead of the value</span> |
|
1386 | 1 | * </li> |
|
1387 | * </ul> |
||
1388 | * |
||
1389 | * @return static <p>(Immutable)</p> |
||
1390 | 1 | */ |
|
1391 | 1 | public function filter($closure = null, int $flag = ARRAY_FILTER_USE_BOTH) |
|
1401 | 1 | ||
1402 | 1 | /** |
|
1403 | 1 | * Filters an array of objects (or a numeric array of associative arrays) based on the value of a particular property |
|
1404 | 1 | * within that. |
|
1405 | 1 | * |
|
1406 | * @param string $property |
||
1407 | 1 | * @param string|string[] $value |
|
1408 | 1 | * @param string $comparisonOp |
|
1409 | * <p> |
||
1410 | 1 | * 'eq' (equals),<br /> |
|
1411 | 1 | * 'gt' (greater),<br /> |
|
1412 | * 'gte' || 'ge' (greater or equals),<br /> |
||
1413 | 1 | * 'lt' (less),<br /> |
|
1414 | 1 | * 'lte' || 'le' (less or equals),<br /> |
|
1415 | 1 | * 'ne' (not equals),<br /> |
|
1416 | 1 | * 'contains',<br /> |
|
1417 | 1 | * 'notContains',<br /> |
|
1418 | * 'newer' (via strtotime),<br /> |
||
1419 | 1 | * 'older' (via strtotime),<br /> |
|
1420 | 1 | * </p> |
|
1421 | * |
||
1422 | 1 | * @return static <p>(Immutable)</p> |
|
1423 | 1 | */ |
|
1424 | public function filterBy(string $property, $value, string $comparisonOp = null) |
||
1489 | 13 | ||
1490 | 13 | /** |
|
1491 | * Find the first item in an array that passes the truth test, |
||
1492 | 13 | * otherwise return false |
|
1493 | 3 | * |
|
1494 | * @param \Closure $closure |
||
1495 | * |
||
1496 | 10 | * @return mixed|false <p>Return false if we did not find the value.</p> |
|
1497 | */ |
||
1498 | View Code Duplication | public function find(\Closure $closure) |
|
1508 | 28 | ||
1509 | 7 | /** |
|
1510 | 7 | * find by ... |
|
1511 | * |
||
1512 | 21 | * @param string $property |
|
1513 | 21 | * @param string|string[] $value |
|
1514 | 21 | * @param string $comparisonOp |
|
1515 | * |
||
1516 | * @return static <p>(Immutable)</p> |
||
1517 | 28 | */ |
|
1518 | public function findBy(string $property, $value, string $comparisonOp = 'eq') |
||
1522 | |||
1523 | /** |
||
1524 | * Get the first value from the current array. |
||
1525 | * |
||
1526 | * @return mixed <p>Return null if there wasn't a element.</p> |
||
1527 | 26 | */ |
|
1528 | public function first() |
||
1539 | |||
1540 | /** |
||
1541 | * Get the first value(s) from the current array. |
||
1542 | * |
||
1543 | * @param int|null $number <p>How many values you will take?</p> |
||
1544 | 1 | * |
|
1545 | * @return static <p>(Immutable)</p> |
||
1546 | 1 | */ |
|
1547 | public function firstsImmutable(int $number = null) |
||
1560 | |||
1561 | 62 | /** |
|
1562 | * Get the first value(s) from the current array. |
||
1563 | 62 | * |
|
1564 | 3 | * @param int|null $number <p>How many values you will take?</p> |
|
1565 | * |
||
1566 | 59 | * @return static <p>(Mutable)</p> |
|
1567 | */ |
||
1568 | public function firstsMutable(int $number = null) |
||
1579 | 52 | ||
1580 | 6 | /** |
|
1581 | * Exchanges all keys with their associated values in an array. |
||
1582 | * |
||
1583 | 48 | * @return static <p>(Immutable)</p> |
|
1584 | */ |
||
1585 | public function flip() |
||
1591 | |||
1592 | 6 | /** |
|
1593 | * Get a value from an array (optional using dot-notation). |
||
1594 | * |
||
1595 | 6 | * @param mixed $key <p>The key to look for.</p> |
|
1596 | 1 | * @param mixed $fallback <p>Value to fallback to.</p> |
|
1597 | * @param array $array <p>The array to get from, if it's set to "null" we use the current array from the |
||
1598 | * class.</p> |
||
1599 | 6 | * |
|
1600 | * @return mixed|static |
||
1601 | */ |
||
1602 | public function get($key, $fallback = null, array $array = null) |
||
1642 | 38 | ||
1643 | 10 | /** |
|
1644 | * Get the current array from the "Arrayy"-object. |
||
1645 | 10 | * |
|
1646 | 2 | * @return array |
|
1647 | */ |
||
1648 | 8 | public function getArray(): array |
|
1660 | 38 | ||
1661 | /** |
||
1662 | * Returns the values from a single column of the input array, identified by |
||
1663 | * the $columnKey, can be used to extract data-columns from multi-arrays. |
||
1664 | * |
||
1665 | * Info: Optionally, you may provide an $indexKey to index the values in the returned |
||
1666 | * array by the values from the $indexKey column in the input array. |
||
1667 | * |
||
1668 | * @param mixed $columnKey |
||
1669 | * @param mixed $indexKey |
||
1670 | 1 | * |
|
1671 | * @return static <p>(Immutable)</p> |
||
1672 | 1 | */ |
|
1673 | public function getColumn($columnKey = null, $indexKey = null) |
||
1679 | |||
1680 | 4 | /** |
|
1681 | * Get correct PHP constant for direction. |
||
1682 | 4 | * |
|
1683 | * @param int|string $direction |
||
1684 | * |
||
1685 | * @return int |
||
1686 | */ |
||
1687 | protected function getDirection($direction): int |
||
1709 | |||
1710 | /** |
||
1711 | * alias: for "Arrayy->keys()" |
||
1712 | * |
||
1713 | * @see Arrayy::keys() |
||
1714 | * |
||
1715 | * @return static <p>(Immutable)</p> |
||
1716 | */ |
||
1717 | public function getKeys() |
||
1721 | |||
1722 | /** |
||
1723 | * Get the current array from the "Arrayy"-object as object. |
||
1724 | * |
||
1725 | * @return \stdClass (object) |
||
1726 | */ |
||
1727 | public function getObject(): \stdClass |
||
1731 | |||
1732 | 3 | /** |
|
1733 | * alias: for "Arrayy->randomImmutable()" |
||
1734 | * |
||
1735 | * @see Arrayy::randomImmutable() |
||
1736 | * |
||
1737 | * @return static <p>(Immutable)</p> |
||
1738 | */ |
||
1739 | public function getRandom() |
||
1743 | |||
1744 | 6 | /** |
|
1745 | * alias: for "Arrayy->randomKey()" |
||
1746 | 6 | * |
|
1747 | * @see Arrayy::randomKey() |
||
1748 | * |
||
1749 | * @return mixed <p>Get a key/index or null if there wasn't a key/index.</p> |
||
1750 | */ |
||
1751 | public function getRandomKey() |
||
1755 | |||
1756 | /** |
||
1757 | 3 | * alias: for "Arrayy->randomKeys()" |
|
1758 | * |
||
1759 | 3 | * @see Arrayy::randomKeys() |
|
1760 | 3 | * |
|
1761 | * @param int $number |
||
1762 | * |
||
1763 | 3 | * @return static <p>(Immutable)</p> |
|
1764 | */ |
||
1765 | 3 | public function getRandomKeys(int $number) |
|
1769 | |||
1770 | /** |
||
1771 | * alias: for "Arrayy->randomValue()" |
||
1772 | 3 | * |
|
1773 | 3 | * @see Arrayy::randomValue() |
|
1774 | * |
||
1775 | * @return mixed <p>get a random value or null if there wasn't a value.</p> |
||
1776 | */ |
||
1777 | 3 | public function getRandomValue() |
|
1781 | |||
1782 | 1 | /** |
|
1783 | 3 | * alias: for "Arrayy->randomValues()" |
|
1784 | * |
||
1785 | * @see Arrayy::randomValues() |
||
1786 | * |
||
1787 | * @param int $number |
||
1788 | * |
||
1789 | 3 | * @return static <p>(Immutable)</p> |
|
1790 | */ |
||
1791 | public function getRandomValues(int $number) |
||
1795 | |||
1796 | /** |
||
1797 | * Group values from a array according to the results of a closure. |
||
1798 | * |
||
1799 | 23 | * @param \callable $grouper <p>A callable function name.</p> |
|
1800 | * @param bool $saveKeys |
||
1801 | 23 | * |
|
1802 | * @return static <p>(Immutable)</p> |
||
1803 | 23 | */ |
|
1804 | public function group($grouper, bool $saveKeys = false) |
||
1838 | |||
1839 | /** |
||
1840 | * Check if an array has a given key. |
||
1841 | * |
||
1842 | 35 | * @param mixed $key |
|
1843 | * |
||
1844 | 35 | * @return bool |
|
1845 | 1 | */ |
|
1846 | public function has($key): bool |
||
1857 | 35 | ||
1858 | /** |
||
1859 | * Implodes the values of this array. |
||
1860 | * |
||
1861 | * @param string $glue |
||
1862 | 35 | * |
|
1863 | * @return string |
||
1864 | */ |
||
1865 | public function implode(string $glue = ''): string |
||
1869 | |||
1870 | /** |
||
1871 | * Implodes the keys of this array. |
||
1872 | * |
||
1873 | * @param string $glue |
||
1874 | * |
||
1875 | * @return string |
||
1876 | */ |
||
1877 | public function implodeKeys(string $glue = ''): string |
||
1881 | |||
1882 | /** |
||
1883 | * @param mixed $glue |
||
1884 | * @param string|array|static $pieces |
||
1885 | 44 | * @param bool $useKeys |
|
1886 | * |
||
1887 | 44 | * @return string |
|
1888 | */ |
||
1889 | protected function implode_recursive($glue = '', $pieces = [], bool $useKeys = false): string |
||
1911 | |||
1912 | /** |
||
1913 | * @param mixed $needle <p> |
||
1914 | * The searched value. |
||
1915 | * </p> |
||
1916 | 3 | * <p> |
|
1917 | * If needle is a string, the comparison is done |
||
1918 | 3 | * in a case-sensitive manner. |
|
1919 | * </p> |
||
1920 | 3 | * @param array $haystack <p> |
|
1921 | 3 | * The array. |
|
1922 | 3 | * </p> |
|
1923 | * @param bool $strict [optional] <p> |
||
1924 | * If the third parameter strict is set to true |
||
1925 | * then the in_array function will also check the |
||
1926 | 3 | * types of the |
|
1927 | * needle in the haystack. |
||
1928 | * </p> |
||
1929 | * |
||
1930 | * @return bool true if needle is found in the array, false otherwise. |
||
1931 | */ |
||
1932 | protected function in_array_recursive($needle, array $haystack = null, $strict = true): bool |
||
1953 | |||
1954 | /** |
||
1955 | * Given a list and an iterate-function that returns |
||
1956 | * a key for each element in the list (or a property name), |
||
1957 | * returns an object with an index of each item. |
||
1958 | 476 | * |
|
1959 | * @param mixed $key |
||
1960 | 476 | * |
|
1961 | * @return static <p>(Immutable)</p> |
||
1962 | */ |
||
1963 | public function indexBy($key) |
||
1975 | |||
1976 | /** |
||
1977 | * alias: for "Arrayy->searchIndex()" |
||
1978 | * |
||
1979 | * @see Arrayy::searchIndex() |
||
1980 | * |
||
1981 | * @param mixed $value <p>The value to search for.</p> |
||
1982 | * |
||
1983 | 18 | * @return mixed |
|
1984 | */ |
||
1985 | 18 | public function indexOf($value) |
|
1989 | |||
1990 | /** |
||
1991 | * Get everything but the last..$to items. |
||
1992 | * |
||
1993 | * @param int $to |
||
1994 | * |
||
1995 | * @return static <p>(Immutable)</p> |
||
1996 | */ |
||
1997 | public function initial(int $to = 1) |
||
2001 | |||
2002 | 18 | /** |
|
2003 | * @param mixed $value |
||
2004 | */ |
||
2005 | protected function internalGetArray(&$value) |
||
2022 | |||
2023 | /** |
||
2024 | 30 | * Internal mechanics of remove method. |
|
2025 | 3 | * |
|
2026 | * @param mixed $key |
||
2027 | * |
||
2028 | * @return bool |
||
2029 | */ |
||
2030 | 3 | protected function internalRemove($key): bool |
|
2051 | 2 | ||
2052 | /** |
||
2053 | * Internal mechanic of set method. |
||
2054 | * |
||
2055 | * @param mixed $key |
||
2056 | * @param mixed $value |
||
2057 | * |
||
2058 | * @return bool |
||
2059 | */ |
||
2060 | protected function internalSet($key, $value): bool |
||
2081 | 1 | ||
2082 | /** |
||
2083 | * Return an array with all elements found in input array. |
||
2084 | * |
||
2085 | 1 | * @param array $search |
|
2086 | 1 | * |
|
2087 | * @return static <p>(Immutable)</p> |
||
2088 | 1 | */ |
|
2089 | public function intersection(array $search) |
||
2093 | |||
2094 | /** |
||
2095 | * Return a boolean flag which indicates whether the two input arrays have any common elements. |
||
2096 | * |
||
2097 | * @param array $search |
||
2098 | * |
||
2099 | * @return bool |
||
2100 | */ |
||
2101 | 15 | public function intersects(array $search): bool |
|
2105 | |||
2106 | /** |
||
2107 | 13 | * Invoke a function on all of an array's values. |
|
2108 | 13 | * |
|
2109 | 13 | * @param mixed $callable |
|
2110 | * @param mixed $arguments |
||
2111 | * |
||
2112 | * @return static <p>(Immutable)</p> |
||
2113 | 3 | */ |
|
2114 | public function invoke($callable, $arguments = []) |
||
2133 | |||
2134 | /** |
||
2135 | * Check whether array is associative or not. |
||
2136 | * |
||
2137 | * @param bool $recursive |
||
2138 | * |
||
2139 | * @return bool <p>Returns true if associative, false otherwise.</p> |
||
2140 | */ |
||
2141 | public function isAssoc(bool $recursive = false): bool |
||
2155 | |||
2156 | /** |
||
2157 | 5 | * Check whether the array is empty or not. |
|
2158 | * |
||
2159 | 5 | * @return bool <p>Returns true if empty, false otherwise.</p> |
|
2160 | 2 | */ |
|
2161 | public function isEmpty(): bool |
||
2165 | 4 | ||
2166 | /** |
||
2167 | * Check if the current array is equal to the given "$array" or not. |
||
2168 | * |
||
2169 | 2 | * @param array $array |
|
2170 | * |
||
2171 | * @return bool |
||
2172 | */ |
||
2173 | public function isEqual(array $array): bool |
||
2177 | |||
2178 | /** |
||
2179 | 1 | * Check if the current array is a multi-array. |
|
2180 | * |
||
2181 | * @return bool |
||
2182 | */ |
||
2183 | public function isMultiArray(): bool |
||
2191 | |||
2192 | 1 | /** |
|
2193 | * Check whether array is numeric or not. |
||
2194 | 1 | * |
|
2195 | * @return bool <p>Returns true if numeric, false otherwise.</p> |
||
2196 | */ |
||
2197 | public function isNumeric(): bool |
||
2211 | |||
2212 | /** |
||
2213 | * Check if the current array is sequential [0, 1, 2, 3, 4, 5 ...] or not. |
||
2214 | * |
||
2215 | * @param bool $recursive |
||
2216 | * |
||
2217 | * @return bool |
||
2218 | */ |
||
2219 | public function isSequential(bool $recursive = false): bool |
||
2236 | |||
2237 | 25 | /** |
|
2238 | 25 | * @return array |
|
2239 | */ |
||
2240 | public function jsonSerialize(): array |
||
2244 | |||
2245 | /** |
||
2246 | * Get all keys from the current array. |
||
2247 | * |
||
2248 | * @param bool $recursive [optional] <p> |
||
2249 | * Get all keys, also from all sub-arrays from an multi-dimensional array. |
||
2250 | * </p> |
||
2251 | * @param mixed $search_value [optional] <p> |
||
2252 | * If specified, then only keys containing these values are returned. |
||
2253 | * </p> |
||
2254 | * @param bool $strict [optional] <p> |
||
2255 | * Determines if strict comparison (===) should be used during the search. |
||
2256 | * </p> |
||
2257 | 4 | * |
|
2258 | * @return static <p>(Immutable) An array of all the keys in input.</p> |
||
2259 | 4 | */ |
|
2260 | public function keys(bool $recursive = false, $search_value = null, bool $strict = true) |
||
2285 | |||
2286 | /** |
||
2287 | 12 | * Sort an array by key in reverse order. |
|
2288 | 8 | * |
|
2289 | * @param int $sort_flags [optional] <p> |
||
2290 | 8 | * You may modify the behavior of the sort using the optional |
|
2291 | 1 | * parameter sort_flags, for details |
|
2292 | * see sort. |
||
2293 | 7 | * </p> |
|
2294 | * |
||
2295 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
2296 | 8 | */ |
|
2297 | public function krsort(int $sort_flags = 0) |
||
2303 | |||
2304 | /** |
||
2305 | * Get the last value from the current array. |
||
2306 | * |
||
2307 | * @return mixed <p>Return null if there wasn't a element.</p> |
||
2308 | */ |
||
2309 | public function last() |
||
2313 | |||
2314 | 13 | /** |
|
2315 | 1 | * Get the last value(s) from the current array. |
|
2316 | * |
||
2317 | * @param int|null $number |
||
2318 | 12 | * |
|
2319 | 8 | * @return static <p>(Immutable)</p> |
|
2320 | */ |
||
2321 | 8 | public function lastsImmutable(int $number = null) |
|
2344 | |||
2345 | /** |
||
2346 | * Get the last value(s) from the current array. |
||
2347 | 20 | * |
|
2348 | * @param int|null $number |
||
2349 | 20 | * |
|
2350 | * @return static <p>(Mutable)</p> |
||
2351 | */ |
||
2352 | public function lastsMutable(int $number = null) |
||
2375 | |||
2376 | 15 | /** |
|
2377 | 2 | * Count the values from the current array. |
|
2378 | * |
||
2379 | * alias: for "Arrayy->count()" |
||
2380 | * |
||
2381 | 13 | * @see Arrayy::count() |
|
2382 | * |
||
2383 | 13 | * @param int $mode |
|
2384 | 13 | * |
|
2385 | * @return int |
||
2386 | 13 | */ |
|
2387 | 13 | public function length(int $mode = COUNT_NORMAL): int |
|
2391 | 7 | ||
2392 | /** |
||
2393 | * Apply the given function to the every element of the array, |
||
2394 | * collecting the results. |
||
2395 | * |
||
2396 | * @param \callable $callable |
||
2397 | * |
||
2398 | * @return static <p>(Immutable) Arrayy object with modified elements.</p> |
||
2399 | */ |
||
2400 | public function map($callable) |
||
2406 | |||
2407 | /** |
||
2408 | 12 | * Check if all items in current array match a truth test. |
|
2409 | * |
||
2410 | 12 | * @param \Closure $closure |
|
2411 | 12 | * |
|
2412 | * @return bool |
||
2413 | 12 | */ |
|
2414 | 12 | View Code Duplication | public function matches(\Closure $closure): bool |
2433 | |||
2434 | /** |
||
2435 | * Check if any item in the current array matches a truth test. |
||
2436 | * |
||
2437 | * @param \Closure $closure |
||
2438 | * |
||
2439 | * @return bool |
||
2440 | */ |
||
2441 | View Code Duplication | public function matchesAny(\Closure $closure): bool |
|
2460 | |||
2461 | /** |
||
2462 | * Get the max value from an array. |
||
2463 | * |
||
2464 | * @return mixed |
||
2465 | */ |
||
2466 | View Code Duplication | public function max() |
|
2474 | |||
2475 | 16 | /** |
|
2476 | * Merge the new $array into the current array. |
||
2477 | * |
||
2478 | * - keep key,value from the current array, also if the index is in the new $array |
||
2479 | * |
||
2480 | * @param array $array |
||
2481 | * @param bool $recursive |
||
2482 | * |
||
2483 | * @return static <p>(Immutable)</p> |
||
2484 | */ |
||
2485 | View Code Duplication | public function mergeAppendKeepIndex(array $array = [], bool $recursive = false) |
|
2495 | |||
2496 | 16 | /** |
|
2497 | * Merge the new $array into the current array. |
||
2498 | * |
||
2499 | * - replace duplicate assoc-keys from the current array with the key,values from the new $array |
||
2500 | * - create new indexes |
||
2501 | * |
||
2502 | * @param array $array |
||
2503 | * @param bool $recursive |
||
2504 | * |
||
2505 | * @return static <p>(Immutable)</p> |
||
2506 | */ |
||
2507 | View Code Duplication | public function mergeAppendNewIndex(array $array = [], bool $recursive = false) |
|
2517 | |||
2518 | 17 | /** |
|
2519 | * Merge the the current array into the $array. |
||
2520 | * |
||
2521 | * - use key,value from the new $array, also if the index is in the current array |
||
2522 | * |
||
2523 | * @param array $array |
||
2524 | * @param bool $recursive |
||
2525 | * |
||
2526 | 10 | * @return static <p>(Immutable)</p> |
|
2527 | */ |
||
2528 | 10 | View Code Duplication | public function mergePrependKeepIndex(array $array = [], bool $recursive = false) |
2538 | |||
2539 | /** |
||
2540 | * Merge the current array into the new $array. |
||
2541 | * |
||
2542 | * - replace duplicate assoc-keys from new $array with the key,values from the current array |
||
2543 | * - create new indexes |
||
2544 | * |
||
2545 | 1 | * @param array $array |
|
2546 | * @param bool $recursive |
||
2547 | 1 | * |
|
2548 | * @return static <p>(Immutable)</p> |
||
2549 | 1 | */ |
|
2550 | 1 | View Code Duplication | public function mergePrependNewIndex(array $array = [], bool $recursive = false) |
2560 | 1 | ||
2561 | 1 | /** |
|
2562 | * Get the min value from an array. |
||
2563 | 1 | * |
|
2564 | 1 | * @return mixed |
|
2565 | */ |
||
2566 | View Code Duplication | public function min() |
|
2574 | |||
2575 | /** |
||
2576 | * Move an array element to a new index. |
||
2577 | * |
||
2578 | * cherry-picked from: http://stackoverflow.com/questions/12624153/move-an-array-element-to-a-new-index-in-php |
||
2579 | * |
||
2580 | 5 | * @param int|string $from |
|
2581 | * @param int|string $to |
||
2582 | 5 | * |
|
2583 | 4 | * @return static <p>(Immutable)</p> |
|
2584 | */ |
||
2585 | public function moveElement($from, $to) |
||
2612 | |||
2613 | /** |
||
2614 | * Convert a object into an array. |
||
2615 | 4 | * |
|
2616 | * @param object $object |
||
2617 | 4 | * |
|
2618 | * @return mixed |
||
2619 | 4 | */ |
|
2620 | protected static function objectToArray($object) |
||
2632 | |||
2633 | /** |
||
2634 | * Get a subset of the items from the given array. |
||
2635 | * |
||
2636 | * @param mixed[] $keys |
||
2637 | * |
||
2638 | * @return static <p>(Immutable)</p> |
||
2639 | */ |
||
2640 | 8 | public function only(array $keys) |
|
2646 | 1 | ||
2647 | /** |
||
2648 | * Pad array to the specified size with a given value. |
||
2649 | 8 | * |
|
2650 | * @param int $size <p>Size of the result array.</p> |
||
2651 | * @param mixed $value <p>Empty value by default.</p> |
||
2652 | * |
||
2653 | * @return static <p>(Immutable) Arrayy object padded to $size with $value.</p> |
||
2654 | */ |
||
2655 | public function pad(int $size, $value) |
||
2661 | 10 | ||
2662 | 10 | /** |
|
2663 | 9 | * Pop a specified value off the end of the current array. |
|
2664 | * |
||
2665 | 9 | * @return mixed <p>(Mutable) The popped element from the current array.</p> |
|
2666 | */ |
||
2667 | public function pop() |
||
2671 | |||
2672 | /** |
||
2673 | 10 | * Prepend a (key) + value to the current array. |
|
2674 | * |
||
2675 | * @param mixed $value |
||
2676 | * @param mixed $key |
||
2677 | * |
||
2678 | * @return static <p>(Mutable) Return this Arrayy object, with the prepended value.</p> |
||
2679 | */ |
||
2680 | public function prepend($value, $key = null) |
||
2691 | 9 | ||
2692 | 1 | /** |
|
2693 | * Add a suffix to each key. |
||
2694 | 9 | * |
|
2695 | * @param mixed $suffix |
||
2696 | * |
||
2697 | * @return static <p>(Immutable) Return an Arrayy object, with the prepended keys.</p> |
||
2698 | 10 | */ |
|
2699 | View Code Duplication | public function prependToEachKey($suffix) |
|
2715 | |||
2716 | /** |
||
2717 | * Add a suffix to each value. |
||
2718 | * |
||
2719 | * @param mixed $suffix |
||
2720 | * |
||
2721 | * @return static <p>(Immutable) Return an Arrayy object, with the prepended values.</p> |
||
2722 | */ |
||
2723 | 18 | View Code Duplication | public function prependToEachValue($suffix) |
2740 | |||
2741 | /** |
||
2742 | * Push one or more values onto the end of array at once. |
||
2743 | * |
||
2744 | * @return static <p>(Mutable) Return this Arrayy object, with pushed elements to the end of array.</p> |
||
2745 | */ |
||
2746 | View Code Duplication | public function push(/* variadic arguments allowed */) |
|
2755 | |||
2756 | 4 | /** |
|
2757 | * Get a random value from the current array. |
||
2758 | * |
||
2759 | * @param null|int $number <p>How many values you will take?</p> |
||
2760 | * |
||
2761 | * @return static <p>(Immutable)</p> |
||
2762 | */ |
||
2763 | public function randomImmutable(int $number = null) |
||
2782 | 11 | ||
2783 | /** |
||
2784 | 11 | * Pick a random key/index from the keys of this array. |
|
2785 | * |
||
2786 | * @return mixed <p>Get a key/index or null if there wasn't a key/index.</p> |
||
2787 | * |
||
2788 | * @throws \RangeException If array is empty |
||
2789 | */ |
||
2790 | public function randomKey() |
||
2800 | 17 | ||
2801 | 7 | /** |
|
2802 | 7 | * Pick a given number of random keys/indexes out of this array. |
|
2803 | * |
||
2804 | 7 | * @param int $number <p>The number of keys/indexes (should be <= \count($this->array))</p> |
|
2805 | * |
||
2806 | * @return static <p>(Immutable)</p> |
||
2807 | 11 | * |
|
2808 | * @throws \RangeException If array is empty |
||
2809 | 11 | */ |
|
2810 | public function randomKeys(int $number) |
||
2828 | |||
2829 | /** |
||
2830 | * Get a random value from the current array. |
||
2831 | * |
||
2832 | * @param null|int $number <p>How many values you will take?</p> |
||
2833 | * |
||
2834 | * @return static <p>(Mutable)</p> |
||
2835 | 7 | */ |
|
2836 | public function randomMutable(int $number = null) |
||
2855 | 9 | ||
2856 | 1 | /** |
|
2857 | * Pick a random value from the values of this array. |
||
2858 | * |
||
2859 | * @return mixed <p>Get a random value or null if there wasn't a value.</p> |
||
2860 | */ |
||
2861 | 9 | public function randomValue() |
|
2871 | |||
2872 | 4 | /** |
|
2873 | * Pick a given number of random values out of this array. |
||
2874 | 4 | * |
|
2875 | * @param int $number |
||
2876 | 4 | * |
|
2877 | * @return static <p>(Mutable)</p> |
||
2878 | */ |
||
2879 | 4 | public function randomValues(int $number) |
|
2883 | |||
2884 | /** |
||
2885 | * Get a random value from an array, with the ability to skew the results. |
||
2886 | * |
||
2887 | * Example: randomWeighted(['foo' => 1, 'bar' => 2]) has a 66% chance of returning bar. |
||
2888 | * |
||
2889 | * @param array $array |
||
2890 | 9 | * @param null|int $number <p>How many values you will take?</p> |
|
2891 | * |
||
2892 | 9 | * @return static <p>(Immutable)</p> |
|
2893 | */ |
||
2894 | 9 | public function randomWeighted(array $array, int $number = null) |
|
2907 | |||
2908 | 1 | /** |
|
2909 | 1 | * Reduce the current array via callable e.g. anonymous-function. |
|
2910 | 1 | * |
|
2911 | * @param \callable $callable |
||
2912 | * @param array $init |
||
2913 | * |
||
2914 | 1 | * @return static <p>(Immutable)</p> |
|
2915 | */ |
||
2916 | public function reduce($callable, array $init = []) |
||
2928 | |||
2929 | /** |
||
2930 | * Create a numerically re-indexed Arrayy object. |
||
2931 | * |
||
2932 | * @return static <p>(Mutable) Return this Arrayy object, with re-indexed array-elements.</p> |
||
2933 | */ |
||
2934 | public function reindex() |
||
2940 | |||
2941 | /** |
||
2942 | * Return all items that fail the truth test. |
||
2943 | * |
||
2944 | * @param \Closure $closure |
||
2945 | 7 | * |
|
2946 | * @return static <p>(Immutable)</p> |
||
2947 | 7 | */ |
|
2948 | 7 | View Code Duplication | public function reject(\Closure $closure) |
2960 | 7 | ||
2961 | 7 | /** |
|
2962 | * Remove a value from the current array (optional using dot-notation). |
||
2963 | 7 | * |
|
2964 | * @param mixed $key |
||
2965 | * |
||
2966 | * @return static <p>(Immutable)</p> |
||
2967 | */ |
||
2968 | public function remove($key) |
||
2983 | |||
2984 | /** |
||
2985 | 7 | * Remove the first value from the current array. |
|
2986 | 7 | * |
|
2987 | * @return static <p>(Immutable)</p> |
||
2988 | */ |
||
2989 | 7 | public function removeFirst() |
|
2996 | |||
2997 | /** |
||
2998 | * Remove the last value from the current array. |
||
2999 | 1 | * |
|
3000 | * @return static <p>(Immutable)</p> |
||
3001 | 1 | */ |
|
3002 | 1 | public function removeLast() |
|
3009 | |||
3010 | /** |
||
3011 | * Removes a particular value from an array (numeric or associative). |
||
3012 | * |
||
3013 | * @param mixed $value |
||
3014 | * |
||
3015 | * @return static <p>(Immutable)</p> |
||
3016 | */ |
||
3017 | 2 | public function removeValue($value) |
|
3035 | 2 | ||
3036 | /** |
||
3037 | * Generate array of repeated arrays. |
||
3038 | * |
||
3039 | * @param int $times <p>How many times has to be repeated.</p> |
||
3040 | * |
||
3041 | * @return Arrayy |
||
3042 | */ |
||
3043 | public function repeat($times): self |
||
3051 | |||
3052 | /** |
||
3053 | * Replace a key with a new key/value pair. |
||
3054 | * |
||
3055 | * @param mixed $replace |
||
3056 | * @param mixed $key |
||
3057 | * @param mixed $value |
||
3058 | * |
||
3059 | 1 | * @return static <p>(Immutable)</p> |
|
3060 | */ |
||
3061 | 1 | public function replace($replace, $key, $value) |
|
3067 | |||
3068 | /** |
||
3069 | * Create an array using the current array as values and the other array as keys. |
||
3070 | * |
||
3071 | * @param array $keys <p>An array of keys.</p> |
||
3072 | * |
||
3073 | * @return static <p>(Immutable) Arrayy object with keys from the other array.</p> |
||
3074 | */ |
||
3075 | 3 | public function replaceAllKeys(array $keys) |
|
3081 | 3 | ||
3082 | /** |
||
3083 | * Create an array using the current array as keys and the other array as values. |
||
3084 | 3 | * |
|
3085 | * @param array $array <p>An array o values.</p> |
||
3086 | * |
||
3087 | * @return static <p>(Immutable) Arrayy object with values from the other array.</p> |
||
3088 | */ |
||
3089 | public function replaceAllValues(array $array) |
||
3095 | 1 | ||
3096 | /** |
||
3097 | 1 | * Replace the keys in an array with another set. |
|
3098 | 1 | * |
|
3099 | 1 | * @param array $keys <p>An array of keys matching the array's size</p> |
|
3100 | 1 | * |
|
3101 | * @return static <p>(Immutable)</p> |
||
3102 | */ |
||
3103 | 1 | public function replaceKeys(array $keys) |
|
3110 | |||
3111 | /** |
||
3112 | * Replace the first matched value in an array. |
||
3113 | 15 | * |
|
3114 | * @param mixed $search <p>The value to replace.</p> |
||
3115 | 15 | * @param mixed $replacement <p>The value to replace.</p> |
|
3116 | * |
||
3117 | 15 | * @return static <p>(Immutable)</p> |
|
3118 | */ |
||
3119 | public function replaceOneValue($search, $replacement = '') |
||
3130 | |||
3131 | /** |
||
3132 | * Replace values in the current array. |
||
3133 | * |
||
3134 | * @param mixed $search <p>The value to replace.</p> |
||
3135 | * @param mixed $replacement <p>What to replace it with.</p> |
||
3136 | * |
||
3137 | * @return static <p>(Immutable)</p> |
||
3138 | */ |
||
3139 | public function replaceValues($search, $replacement = '') |
||
3149 | |||
3150 | /** |
||
3151 | * Get the last elements from index $from until the end of this array. |
||
3152 | * |
||
3153 | * @param int $from |
||
3154 | * |
||
3155 | * @return static <p>(Immutable)</p> |
||
3156 | */ |
||
3157 | 20 | public function rest(int $from = 1) |
|
3163 | |||
3164 | /** |
||
3165 | * Return the array in the reverse order. |
||
3166 | * |
||
3167 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
3168 | */ |
||
3169 | 9 | public function reverse() |
|
3175 | |||
3176 | /** |
||
3177 | * Sort an array in reverse order. |
||
3178 | * |
||
3179 | 9 | * @param int $sort_flags [optional] <p> |
|
3180 | 1 | * You may modify the behavior of the sort using the optional |
|
3181 | * parameter sort_flags, for details |
||
3182 | * see sort. |
||
3183 | 9 | * </p> |
|
3184 | 7 | * |
|
3185 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
3186 | */ |
||
3187 | public function rsort(int $sort_flags = 0) |
||
3193 | |||
3194 | /** |
||
3195 | * Search for the first index of the current array via $value. |
||
3196 | * |
||
3197 | * @param mixed $value |
||
3198 | * |
||
3199 | 17 | * @return int|float|string |
|
3200 | */ |
||
3201 | 17 | public function searchIndex($value) |
|
3205 | |||
3206 | /** |
||
3207 | * Search for the value of the current array via $index. |
||
3208 | * |
||
3209 | * @param mixed $index |
||
3210 | * |
||
3211 | * @return static <p>(Immutable) Will return a empty Arrayy if the value wasn't found.</p> |
||
3212 | */ |
||
3213 | public function searchValue($index) |
||
3234 | |||
3235 | /** |
||
3236 | * Set a value for the current array (optional using dot-notation). |
||
3237 | * |
||
3238 | * @param mixed $key <p>The key to set.</p> |
||
3239 | * @param mixed $value <p>Its value.</p> |
||
3240 | * |
||
3241 | * @return static <p>(Immutable)</p> |
||
3242 | */ |
||
3243 | public function set($key, $value) |
||
3249 | |||
3250 | 1 | /** |
|
3251 | 1 | * Get a value from a array and set it if it was not. |
|
3252 | * |
||
3253 | 1 | * WARNING: this method only set the value, if the $key is not already set |
|
3254 | 1 | * |
|
3255 | 1 | * @param mixed $key <p>The key</p> |
|
3256 | * @param mixed $fallback <p>The default value to set if it isn't.</p> |
||
3257 | 1 | * |
|
3258 | * @return mixed <p>(Mutable)</p> |
||
3259 | */ |
||
3260 | public function setAndGet($key, $fallback = null) |
||
3269 | 1 | ||
3270 | /** |
||
3271 | * Shifts a specified value off the beginning of array. |
||
3272 | 1 | * |
|
3273 | * @return mixed <p>(Mutable) A shifted element from the current array.</p> |
||
3274 | 1 | */ |
|
3275 | 1 | public function shift() |
|
3279 | 1 | ||
3280 | /** |
||
3281 | * Shuffle the current array. |
||
3282 | * |
||
3283 | * @param bool $secure <p>using a CSPRNG | @link https://paragonie.com/b/JvICXzh_jhLyt4y3</p> |
||
3284 | * @param array $array [optional] |
||
3285 | * |
||
3286 | * @return static <p>(Immutable)</p> |
||
3287 | */ |
||
3288 | public function shuffle(bool $secure = false, array $array = null) |
||
3326 | |||
3327 | /** |
||
3328 | * Count the values from the current array. |
||
3329 | * |
||
3330 | * alias: for "Arrayy->count()" |
||
3331 | * |
||
3332 | * @param int $mode |
||
3333 | * |
||
3334 | * @return int |
||
3335 | 4 | */ |
|
3336 | public function size(int $mode = COUNT_NORMAL): int |
||
3340 | |||
3341 | /** |
||
3342 | * Counts all elements in an array, or something in an object. |
||
3343 | * <p>For objects, if you have SPL installed, you can hook into count() by implementing interface {@see Countable}. |
||
3344 | * The interface has exactly one method, {@see Countable::count()}, which returns the return value for the count() |
||
3345 | * function. Please see the {@see Array} section of the manual for a detailed explanation of how arrays are |
||
3346 | * implemented and used in PHP. |
||
3347 | * |
||
3348 | * @return int the number of elements in var, which is |
||
3349 | * typically an array, since anything else will have one |
||
3350 | * element. |
||
3351 | * </p> |
||
3352 | 19 | * <p> |
|
3353 | * If var is not an array or an object with |
||
3354 | 19 | * implemented Countable interface, |
|
3355 | * 1 will be returned. |
||
3356 | 19 | * There is one exception, if var is &null;, |
|
3357 | * 0 will be returned. |
||
3358 | * </p> |
||
3359 | * <p> |
||
3360 | * Caution: count may return 0 for a variable that isn't set, |
||
3361 | * but it may also return 0 for a variable that has been initialized with an |
||
3362 | * empty array. Use isset to test if a variable is set. |
||
3363 | * |
||
3364 | * @return int |
||
3365 | */ |
||
3366 | public function sizeRecursive(): int |
||
3370 | |||
3371 | 18 | /** |
|
3372 | * Extract a slice of the array. |
||
3373 | 18 | * |
|
3374 | * @param int $offset <p>Slice begin index.</p> |
||
3375 | 18 | * @param int|null $length <p>Length of the slice.</p> |
|
3376 | * @param bool $preserveKeys <p>Whether array keys are preserved or no.</p> |
||
3377 | * |
||
3378 | * @return static <p>A slice of the original array with length $length.</p> |
||
3379 | */ |
||
3380 | public function slice(int $offset, int $length = null, bool $preserveKeys = false) |
||
3386 | |||
3387 | 1 | /** |
|
3388 | * Sort the current array and optional you can keep the keys. |
||
3389 | 1 | * |
|
3390 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
3391 | * @param int $strategy <p>sort_flags => use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
3392 | * <strong>SORT_NATURAL</strong></p> |
||
3393 | * @param bool $keepKeys |
||
3394 | * |
||
3395 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
3396 | */ |
||
3397 | public function sort($direction = SORT_ASC, int $strategy = SORT_REGULAR, bool $keepKeys = false) |
||
3403 | 1 | ||
3404 | /** |
||
3405 | * Sort the current array by key. |
||
3406 | * |
||
3407 | * @link http://php.net/manual/en/function.ksort.php |
||
3408 | * @link http://php.net/manual/en/function.krsort.php |
||
3409 | * |
||
3410 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
3411 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
3412 | * <strong>SORT_NATURAL</strong></p> |
||
3413 | * |
||
3414 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
3415 | */ |
||
3416 | public function sortKeys($direction = SORT_ASC, int $strategy = SORT_REGULAR) |
||
3422 | 1 | ||
3423 | /** |
||
3424 | * Sort the current array by value. |
||
3425 | 1 | * |
|
3426 | 1 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
|
3427 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
3428 | 1 | * <strong>SORT_NATURAL</strong></p> |
|
3429 | 1 | * |
|
3430 | 1 | * @return static <p>(Mutable)</p> |
|
3431 | 1 | */ |
|
3432 | 1 | public function sortValueKeepIndex($direction = SORT_ASC, int $strategy = SORT_REGULAR) |
|
3436 | |||
3437 | 1 | /** |
|
3438 | * Sort the current array by value. |
||
3439 | * |
||
3440 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
3441 | 1 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
|
3442 | * <strong>SORT_NATURAL</strong></p> |
||
3443 | 1 | * |
|
3444 | * @return static <p>(Mutable)</p> |
||
3445 | */ |
||
3446 | public function sortValueNewIndex($direction = SORT_ASC, int $strategy = SORT_REGULAR) |
||
3450 | |||
3451 | /** |
||
3452 | * Sort a array by value, by a closure or by a property. |
||
3453 | * |
||
3454 | * - If the sorter is null, the array is sorted naturally. |
||
3455 | * - Associative (string) keys will be maintained, but numeric keys will be re-indexed. |
||
3456 | 18 | * |
|
3457 | * @param \callable|null $sorter |
||
3458 | 18 | * @param string|int $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
|
3459 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
3460 | * <strong>SORT_NATURAL</strong></p> |
||
3461 | 18 | * |
|
3462 | 18 | * @return static <p>(Immutable)</p> |
|
3463 | 6 | */ |
|
3464 | 6 | public function sorter($sorter = null, $direction = SORT_ASC, int $strategy = SORT_REGULAR) |
|
3490 | |||
3491 | /** |
||
3492 | 19 | * sorting keys |
|
3493 | 19 | * |
|
3494 | 9 | * @param array $elements |
|
3495 | 5 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
|
3496 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
3497 | 4 | * <strong>SORT_NATURAL</strong></p> |
|
3498 | * |
||
3499 | 9 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
|
3500 | 10 | */ |
|
3501 | 10 | protected function sorterKeys(array &$elements, $direction = SORT_ASC, int $strategy = SORT_REGULAR) |
|
3518 | |||
3519 | /** |
||
3520 | * @param array &$elements |
||
3521 | 1 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
|
3522 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
3523 | 1 | * <strong>SORT_NATURAL</strong></p> |
|
3524 | * @param bool $keepKeys |
||
3525 | 1 | * |
|
3526 | 1 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
|
3527 | */ |
||
3528 | 1 | protected function sorting(array &$elements, $direction = SORT_ASC, int $strategy = SORT_REGULAR, bool $keepKeys = false) |
|
3557 | |||
3558 | /** |
||
3559 | * Split an array in the given amount of pieces. |
||
3560 | * |
||
3561 | 1 | * @param int $numberOfPieces |
|
3562 | * @param bool $keepKeys |
||
3563 | 1 | * |
|
3564 | * @return static <p>(Immutable)</p> |
||
3565 | 1 | */ |
|
3566 | public function split(int $numberOfPieces = 2, bool $keepKeys = false) |
||
3579 | |||
3580 | /** |
||
3581 | * Stripe all empty items. |
||
3582 | * |
||
3583 | * @return static <p>(Immutable)</p> |
||
3584 | */ |
||
3585 | public function stripEmpty() |
||
3597 | |||
3598 | /** |
||
3599 | * Swap two values between positions by key. |
||
3600 | 19 | * |
|
3601 | * @param string|int $swapA <p>a key in the array</p> |
||
3602 | 19 | * @param string|int $swapB <p>a key in the array</p> |
|
3603 | * |
||
3604 | * @return static <p>(Immutable)</p> |
||
3605 | */ |
||
3606 | public function swap($swapA, $swapB) |
||
3614 | 9 | ||
3615 | 9 | /** |
|
3616 | 9 | * alias: for "Arrayy->getArray()" |
|
3617 | 8 | * |
|
3618 | 8 | * @see Arrayy::getArray() |
|
3619 | */ |
||
3620 | public function toArray() |
||
3624 | |||
3625 | /** |
||
3626 | 9 | * Convert the current array to JSON. |
|
3627 | * |
||
3628 | * @param int $options [optional] <p>e.g. JSON_PRETTY_PRINT</p> |
||
3629 | 9 | * @param int $depth [optional] <p>Set the maximum depth. Must be greater than zero.</p> |
|
3630 | * |
||
3631 | * @return string |
||
3632 | 9 | */ |
|
3633 | public function toJson(int $options = 0, int $depth = 512): string |
||
3637 | |||
3638 | /** |
||
3639 | * Implodes array to a string with specified separator. |
||
3640 | 9 | * |
|
3641 | * @param string $separator [optional] <p>The element's separator.</p> |
||
3642 | * |
||
3643 | * @return string <p>The string representation of array, separated by ",".</p> |
||
3644 | */ |
||
3645 | 9 | public function toString(string $separator = ','): string |
|
3649 | 9 | ||
3650 | 8 | /** |
|
3651 | 8 | * Return a duplicate free copy of the current array. |
|
3652 | * |
||
3653 | * @return static <p>(Mutable)</p> |
||
3654 | 8 | */ |
|
3655 | 9 | public function unique() |
|
3679 | |||
3680 | /** |
||
3681 | * Return a duplicate free copy of the current array. (with the old keys) |
||
3682 | * |
||
3683 | * @return static <p>(Mutable)</p> |
||
3684 | */ |
||
3685 | 4 | public function uniqueKeepIndex() |
|
3712 | |||
3713 | 35 | /** |
|
3714 | * alias: for "Arrayy->unique()" |
||
3715 | 35 | * |
|
3716 | 30 | * @see Arrayy::unique() |
|
3717 | * |
||
3718 | 18 | * @return static <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
|
3719 | */ |
||
3720 | public function uniqueNewIndex() |
||
3724 | |||
3725 | /** |
||
3726 | * Prepends one or more values to the beginning of array at once. |
||
3727 | * |
||
3728 | * @return static <p>(Mutable) Return this Arrayy object, with prepended elements to the beginning of array.</p> |
||
3729 | */ |
||
3730 | View Code Duplication | public function unshift(/* variadic arguments allowed */) |
|
3739 | |||
3740 | /** |
||
3741 | * Get all values from a array. |
||
3742 | * |
||
3743 | * @return static <p>(Immutable)</p> |
||
3744 | */ |
||
3745 | public function values() |
||
3749 | |||
3750 | /** |
||
3751 | * Apply the given function to every element in the array, discarding the results. |
||
3752 | * |
||
3753 | * @param \callable $callable |
||
3754 | * @param bool $recursive <p>Whether array will be walked recursively or no</p> |
||
3755 | * |
||
3756 | * @return static <p>(Mutable) Return this Arrayy object, with modified elements.</p> |
||
3757 | */ |
||
3758 | public function walk($callable, bool $recursive = false) |
||
3768 | } |
||
3769 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: