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) + value to the current array. |
||
| 146 | * |
||
| 147 | * @param mixed $value |
||
| 148 | * @param mixed $key |
||
| 149 | * |
||
| 150 | * @return static <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
| 151 | */ |
||
| 152 | 9 | public function append($value, $key = null) |
|
| 162 | |||
| 163 | /** |
||
| 164 | * Sort the entries by value. |
||
| 165 | * |
||
| 166 | * @param int $sort_flags [optional] <p> |
||
| 167 | * You may modify the behavior of the sort using the optional |
||
| 168 | * parameter sort_flags, for details |
||
| 169 | * see sort. |
||
| 170 | * </p> |
||
| 171 | * |
||
| 172 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
| 173 | */ |
||
| 174 | 4 | public function asort(int $sort_flags = 0) |
|
| 180 | |||
| 181 | /** |
||
| 182 | * Counts all elements in an array, or something in an object. |
||
| 183 | * <p>For objects, if you have SPL installed, you can hook into count() by implementing interface {@see Countable}. |
||
| 184 | * The interface has exactly one method, {@see Countable::count()}, which returns the return value for the count() |
||
| 185 | * function. Please see the {@see Array} section of the manual for a detailed explanation of how arrays are |
||
| 186 | * implemented and used in PHP. |
||
| 187 | * |
||
| 188 | * @link http://php.net/manual/en/function.count.php |
||
| 189 | * |
||
| 190 | * @param int $mode [optional] If the optional mode parameter is set to |
||
| 191 | * COUNT_RECURSIVE (or 1), count |
||
| 192 | * will recursively count the array. This is particularly useful for |
||
| 193 | * counting all the elements of a multidimensional array. count does not detect infinite recursion. |
||
| 194 | * |
||
| 195 | * @return int the number of elements in var, which is |
||
| 196 | * typically an array, since anything else will have one |
||
| 197 | * element. |
||
| 198 | * </p> |
||
| 199 | * <p> |
||
| 200 | * If var is not an array or an object with |
||
| 201 | * implemented Countable interface, |
||
| 202 | * 1 will be returned. |
||
| 203 | * There is one exception, if var is &null;, |
||
| 204 | * 0 will be returned. |
||
| 205 | * </p> |
||
| 206 | * <p> |
||
| 207 | * Caution: count may return 0 for a variable that isn't set, |
||
| 208 | * but it may also return 0 for a variable that has been initialized with an |
||
| 209 | * empty array. Use isset to test if a variable is set. |
||
| 210 | * |
||
| 211 | * @return int |
||
| 212 | */ |
||
| 213 | 37 | public function count(int $mode = COUNT_NORMAL): int |
|
| 217 | |||
| 218 | /** |
||
| 219 | * Exchange the array for another one. |
||
| 220 | * |
||
| 221 | * @param array|static $data |
||
| 222 | * |
||
| 223 | * @return array |
||
| 224 | */ |
||
| 225 | 1 | public function exchangeArray($data): array |
|
| 231 | |||
| 232 | /** |
||
| 233 | * Creates a copy of the ArrayyObject. |
||
| 234 | * |
||
| 235 | * @return array |
||
| 236 | */ |
||
| 237 | 1 | public function getArrayCopy(): array |
|
| 241 | |||
| 242 | /** |
||
| 243 | * Returns a new ArrayyIterator, thus implementing the \ArrayIterator interface. |
||
| 244 | * |
||
| 245 | * @return \ArrayIterator <p>An iterator for the values in the array.</p> |
||
| 246 | */ |
||
| 247 | 20 | public function getIterator(): \ArrayIterator |
|
| 253 | |||
| 254 | /** |
||
| 255 | * Gets the iterator classname for the ArrayObject. |
||
| 256 | * |
||
| 257 | * @return string |
||
| 258 | */ |
||
| 259 | 20 | public function getIteratorClass(): string |
|
| 263 | |||
| 264 | /** |
||
| 265 | * Sort the entries by key |
||
| 266 | * |
||
| 267 | * @param int $sort_flags [optional] <p> |
||
| 268 | * You may modify the behavior of the sort using the optional |
||
| 269 | * parameter sort_flags, for details |
||
| 270 | * see sort. |
||
| 271 | * </p> |
||
| 272 | * |
||
| 273 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
| 274 | */ |
||
| 275 | 4 | public function ksort(int $sort_flags = 0) |
|
| 281 | |||
| 282 | /** |
||
| 283 | * Sort an array using a case insensitive "natural order" algorithm |
||
| 284 | * |
||
| 285 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
| 286 | */ |
||
| 287 | public function natcasesort() |
||
| 293 | |||
| 294 | /** |
||
| 295 | * Sort entries using a "natural order" algorithm |
||
| 296 | * |
||
| 297 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
| 298 | */ |
||
| 299 | 1 | public function natsort() |
|
| 305 | |||
| 306 | /** |
||
| 307 | * Whether or not an offset exists. |
||
| 308 | * |
||
| 309 | * @param int|float|string $offset |
||
| 310 | * |
||
| 311 | * @return bool |
||
| 312 | */ |
||
| 313 | 40 | public function offsetExists($offset): bool |
|
| 357 | |||
| 358 | /** |
||
| 359 | * Returns the value at specified offset. |
||
| 360 | * |
||
| 361 | * @param int|float|string $offset |
||
| 362 | * |
||
| 363 | * @return mixed <p>Will return null if the offset did not exists.</p> |
||
| 364 | */ |
||
| 365 | 26 | public function offsetGet($offset) |
|
| 369 | |||
| 370 | /** |
||
| 371 | * Assigns a value to the specified offset. |
||
| 372 | * |
||
| 373 | * @param int|float|string $offset |
||
| 374 | * @param mixed $value |
||
| 375 | */ |
||
| 376 | 17 | public function offsetSet($offset, $value) |
|
| 384 | |||
| 385 | /** |
||
| 386 | * Unset an offset. |
||
| 387 | * |
||
| 388 | * @param int|float|string $offset |
||
| 389 | */ |
||
| 390 | 7 | public function offsetUnset($offset) |
|
| 416 | |||
| 417 | /** |
||
| 418 | * Serialize the current "Arrayy"-object. |
||
| 419 | * |
||
| 420 | * @return string |
||
| 421 | */ |
||
| 422 | 1 | public function serialize() |
|
| 426 | |||
| 427 | /** |
||
| 428 | * Sets the iterator classname for the current "Arrayy"-object. |
||
| 429 | * |
||
| 430 | * @param string $class |
||
| 431 | * |
||
| 432 | * @return void |
||
| 433 | * |
||
| 434 | * @throws \InvalidArgumentException |
||
| 435 | */ |
||
| 436 | 868 | public function setIteratorClass($class) |
|
| 455 | |||
| 456 | /** |
||
| 457 | * Sort the entries with a user-defined comparison function and maintain key association. |
||
| 458 | * |
||
| 459 | * @param \callable $function |
||
| 460 | * |
||
| 461 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
| 462 | * |
||
| 463 | * @throws \InvalidArgumentException |
||
| 464 | */ |
||
| 465 | View Code Duplication | public function uasort($function) |
|
| 477 | |||
| 478 | /** |
||
| 479 | * Sort the entries by keys using a user-defined comparison function. |
||
| 480 | * |
||
| 481 | * @param \callable $function |
||
| 482 | * |
||
| 483 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
| 484 | * |
||
| 485 | * @throws \InvalidArgumentException |
||
| 486 | */ |
||
| 487 | 5 | public function uksort($function) |
|
| 491 | |||
| 492 | /** |
||
| 493 | * Unserialize an string and return this object. |
||
| 494 | * |
||
| 495 | * @param string $string |
||
| 496 | * |
||
| 497 | * @return static <p>(Mutable)</p> |
||
| 498 | */ |
||
| 499 | 1 | public function unserialize($string) |
|
| 505 | |||
| 506 | /** |
||
| 507 | * Add a suffix to each key. |
||
| 508 | * |
||
| 509 | * @param mixed $prefix |
||
| 510 | * |
||
| 511 | * @return static <p>(Immutable) Return an Arrayy object, with the prefixed keys.</p> |
||
| 512 | */ |
||
| 513 | 10 | View Code Duplication | public function appendToEachKey($prefix) |
| 528 | |||
| 529 | /** |
||
| 530 | * Add a prefix to each value. |
||
| 531 | * |
||
| 532 | * @param mixed $prefix |
||
| 533 | * |
||
| 534 | * @return static <p>(Immutable) Return an Arrayy object, with the prefixed values.</p> |
||
| 535 | */ |
||
| 536 | 10 | View Code Duplication | public function appendToEachValue($prefix) |
| 553 | |||
| 554 | /** |
||
| 555 | * Convert an array into a object. |
||
| 556 | * |
||
| 557 | * @param array $array PHP array |
||
| 558 | * |
||
| 559 | * @return \stdClass (object) |
||
| 560 | */ |
||
| 561 | 4 | protected static function arrayToObject(array $array = []): \stdClass |
|
| 579 | |||
| 580 | /** |
||
| 581 | * @param array $input <p> |
||
| 582 | * An array containing keys to return. |
||
| 583 | * </p> |
||
| 584 | * @param mixed $search_value [optional] <p> |
||
| 585 | * If specified, then only keys containing these values are returned. |
||
| 586 | * </p> |
||
| 587 | * @param bool $strict [optional] <p> |
||
| 588 | * Determines if strict comparison (===) should be used during the search. |
||
| 589 | * </p> |
||
| 590 | * |
||
| 591 | * @return array an array of all the keys in input. |
||
| 592 | */ |
||
| 593 | 10 | protected function array_keys_recursive(array $input = null, $search_value = null, bool $strict = true): array |
|
| 624 | |||
| 625 | /** |
||
| 626 | * Sort an array in reverse order and maintain index association. |
||
| 627 | * |
||
| 628 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
| 629 | */ |
||
| 630 | 4 | public function arsort() |
|
| 636 | |||
| 637 | /** |
||
| 638 | * Iterate over the current array and execute a callback for each loop. |
||
| 639 | * |
||
| 640 | * @param \Closure $closure |
||
| 641 | * |
||
| 642 | * @return static <p>(Immutable)</p> |
||
| 643 | */ |
||
| 644 | 2 | View Code Duplication | public function at(\Closure $closure) |
| 654 | |||
| 655 | /** |
||
| 656 | * Returns the average value of the current array. |
||
| 657 | * |
||
| 658 | * @param int $decimals <p>The number of decimal-numbers to return.</p> |
||
| 659 | * |
||
| 660 | * @return int|double <p>The average value.</p> |
||
| 661 | */ |
||
| 662 | 10 | public function average($decimals = 0) |
|
| 676 | |||
| 677 | /** |
||
| 678 | * @param mixed $path |
||
| 679 | * @param \callable $callable |
||
| 680 | * @param null|array $currentOffset |
||
| 681 | */ |
||
| 682 | 4 | protected function callAtPath($path, $callable, &$currentOffset = null) |
|
| 705 | |||
| 706 | /** |
||
| 707 | * Changes all keys in an array. |
||
| 708 | * |
||
| 709 | * @param int $case [optional] <p> Either <strong>CASE_UPPER</strong><br /> |
||
| 710 | * or <strong>CASE_LOWER</strong> (default)</p> |
||
| 711 | * |
||
| 712 | * @return static <p>(Immutable)</p> |
||
| 713 | */ |
||
| 714 | 1 | public function changeKeyCase(int $case = CASE_LOWER) |
|
| 718 | |||
| 719 | /** |
||
| 720 | * Change the path separator of the array wrapper. |
||
| 721 | * |
||
| 722 | * By default, the separator is: "." |
||
| 723 | * |
||
| 724 | * @param string $separator <p>Separator to set.</p> |
||
| 725 | * |
||
| 726 | * @return static <p>Mutable</p> |
||
| 727 | */ |
||
| 728 | 1 | public function changeSeparator($separator) |
|
| 734 | |||
| 735 | /** |
||
| 736 | * Create a chunked version of the current array. |
||
| 737 | * |
||
| 738 | * @param int $size <p>Size of each chunk.</p> |
||
| 739 | * @param bool $preserveKeys <p>Whether array keys are preserved or no.</p> |
||
| 740 | * |
||
| 741 | * @return static <p>(Immutable) A new array of chunks from the original array.</p> |
||
| 742 | */ |
||
| 743 | 4 | public function chunk($size, $preserveKeys = false) |
|
| 749 | |||
| 750 | /** |
||
| 751 | * Clean all falsy values from the current array. |
||
| 752 | * |
||
| 753 | * @return static <p>(Immutable)</p> |
||
| 754 | */ |
||
| 755 | 8 | public function clean() |
|
| 763 | |||
| 764 | /** |
||
| 765 | * WARNING!!! -> Clear the current array. |
||
| 766 | * |
||
| 767 | * @return static <p>(Mutable) Return this Arrayy object, with an empty array.</p> |
||
| 768 | */ |
||
| 769 | 4 | public function clear() |
|
| 775 | |||
| 776 | /** |
||
| 777 | * Check if an item is in the current array. |
||
| 778 | * |
||
| 779 | * @param string|int|float $value |
||
| 780 | * @param bool $recursive |
||
| 781 | * @param bool $strict |
||
| 782 | * |
||
| 783 | * @return bool |
||
| 784 | */ |
||
| 785 | 22 | public function contains($value, $recursive = false, $strict = true): bool |
|
| 793 | |||
| 794 | /** |
||
| 795 | * Check if an (case-insensitive) string is in the current array. |
||
| 796 | * |
||
| 797 | * @param string $value |
||
| 798 | * @param bool $recursive |
||
| 799 | * |
||
| 800 | * @return bool |
||
| 801 | */ |
||
| 802 | 26 | public function containsCaseInsensitive($value, $recursive = false): bool |
|
| 828 | |||
| 829 | /** |
||
| 830 | * Check if the given key/index exists in the array. |
||
| 831 | * |
||
| 832 | * @param string|int|float $key <p>key/index to search for</p> |
||
| 833 | * |
||
| 834 | * @return bool <p>Returns true if the given key/index exists in the array, false otherwise.</p> |
||
| 835 | */ |
||
| 836 | 4 | public function containsKey($key): bool |
|
| 840 | |||
| 841 | /** |
||
| 842 | * Check if all given needles are present in the array as key/index. |
||
| 843 | * |
||
| 844 | * @param array $needles <p>The keys you are searching for.</p> |
||
| 845 | * @param bool $recursive |
||
| 846 | * |
||
| 847 | * @return bool <p>Returns true if all the given keys/indexes exists in the array, false otherwise.</p> |
||
| 848 | */ |
||
| 849 | 2 | public function containsKeys(array $needles, $recursive = false): bool |
|
| 873 | |||
| 874 | /** |
||
| 875 | * Check if all given needles are present in the array as key/index. |
||
| 876 | * |
||
| 877 | * @param array $needles <p>The keys you are searching for.</p> |
||
| 878 | * |
||
| 879 | * @return bool <p>Returns true if all the given keys/indexes exists in the array, false otherwise.</p> |
||
| 880 | */ |
||
| 881 | 1 | public function containsKeysRecursive(array $needles): bool |
|
| 885 | |||
| 886 | /** |
||
| 887 | * alias: for "Arrayy->contains()" |
||
| 888 | * |
||
| 889 | * @see Arrayy::contains() |
||
| 890 | * |
||
| 891 | * @param string|int|float $value |
||
| 892 | * |
||
| 893 | * @return bool |
||
| 894 | */ |
||
| 895 | 9 | public function containsValue($value): bool |
|
| 899 | |||
| 900 | /** |
||
| 901 | * alias: for "Arrayy->contains($value, true)" |
||
| 902 | * |
||
| 903 | * @see Arrayy::contains() |
||
| 904 | * |
||
| 905 | * @param string|int|float $value |
||
| 906 | * |
||
| 907 | * @return bool |
||
| 908 | */ |
||
| 909 | 18 | public function containsValueRecursive($value): bool |
|
| 913 | |||
| 914 | /** |
||
| 915 | * Check if all given needles are present in the array. |
||
| 916 | * |
||
| 917 | * @param array $needles |
||
| 918 | * |
||
| 919 | * @return bool <p>Returns true if all the given values exists in the array, false otherwise.</p> |
||
| 920 | */ |
||
| 921 | 1 | public function containsValues(array $needles): bool |
|
| 927 | |||
| 928 | /** |
||
| 929 | * Counts all the values of an array |
||
| 930 | * |
||
| 931 | * @link http://php.net/manual/en/function.array-count-values.php |
||
| 932 | * |
||
| 933 | * @return static <p> |
||
| 934 | * (Immutable) |
||
| 935 | * An associative Arrayy-object of values from input as |
||
| 936 | * keys and their count as value. |
||
| 937 | * </p> |
||
| 938 | */ |
||
| 939 | 1 | public function countValues(): self |
|
| 943 | |||
| 944 | /** |
||
| 945 | * Creates an Arrayy object. |
||
| 946 | * |
||
| 947 | * @param mixed $array |
||
| 948 | * |
||
| 949 | * @return static <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 950 | */ |
||
| 951 | 538 | public static function create($array = []): self |
|
| 955 | |||
| 956 | /** |
||
| 957 | * WARNING: Creates an Arrayy object by reference. |
||
| 958 | * |
||
| 959 | * @param array $array |
||
| 960 | * |
||
| 961 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
| 962 | */ |
||
| 963 | 1 | public function createByReference(array &$array = []): self |
|
| 971 | |||
| 972 | /** |
||
| 973 | * Create an new Arrayy object via JSON. |
||
| 974 | * |
||
| 975 | * @param string $json |
||
| 976 | * |
||
| 977 | * @return static <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 978 | */ |
||
| 979 | 5 | public static function createFromJson(string $json) |
|
| 985 | |||
| 986 | /** |
||
| 987 | * Create an new instance filled with values from an object that have implemented ArrayAccess. |
||
| 988 | * |
||
| 989 | * @param \ArrayAccess $object <p>Object that implements ArrayAccess</p> |
||
| 990 | * |
||
| 991 | * @return static <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 992 | */ |
||
| 993 | 4 | public static function createFromObject(\ArrayAccess $object) |
|
| 1003 | |||
| 1004 | /** |
||
| 1005 | * Create an new instance filled with values from an object. |
||
| 1006 | * |
||
| 1007 | * @param object $object |
||
| 1008 | * |
||
| 1009 | * @return static <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1010 | */ |
||
| 1011 | 5 | public static function createFromObjectVars($object): self |
|
| 1015 | |||
| 1016 | /** |
||
| 1017 | * Create an new Arrayy object via string. |
||
| 1018 | * |
||
| 1019 | * @param string $str <p>The input string.</p> |
||
| 1020 | * @param string|null $delimiter <p>The boundary string.</p> |
||
| 1021 | * @param string|null $regEx <p>Use the $delimiter or the $regEx, so if $pattern is null, $delimiter will be |
||
| 1022 | * used.</p> |
||
| 1023 | * |
||
| 1024 | * @return static <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1025 | */ |
||
| 1026 | 8 | public static function createFromString(string $str, string $delimiter = null, string $regEx = null) |
|
| 1052 | |||
| 1053 | /** |
||
| 1054 | * Create an new instance containing a range of elements. |
||
| 1055 | * |
||
| 1056 | * @param mixed $low <p>First value of the sequence.</p> |
||
| 1057 | * @param mixed $high <p>The sequence is ended upon reaching the end value.</p> |
||
| 1058 | * @param int $step <p>Used as the increment between elements in the sequence.</p> |
||
| 1059 | * |
||
| 1060 | * @return static <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1061 | */ |
||
| 1062 | 1 | public static function createWithRange($low, $high, int $step = 1) |
|
| 1066 | |||
| 1067 | /** |
||
| 1068 | * Custom sort by index via "uksort". |
||
| 1069 | * |
||
| 1070 | * @link http://php.net/manual/en/function.uksort.php |
||
| 1071 | * |
||
| 1072 | * @param \callable $function |
||
| 1073 | * |
||
| 1074 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
| 1075 | * |
||
| 1076 | * @throws \InvalidArgumentException |
||
| 1077 | */ |
||
| 1078 | 5 | View Code Duplication | public function customSortKeys($function) |
| 1090 | |||
| 1091 | /** |
||
| 1092 | * Custom sort by value via "usort". |
||
| 1093 | * |
||
| 1094 | * @link http://php.net/manual/en/function.usort.php |
||
| 1095 | * |
||
| 1096 | * @param \callable $function |
||
| 1097 | * |
||
| 1098 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
| 1099 | * |
||
| 1100 | * @throws \InvalidArgumentException |
||
| 1101 | */ |
||
| 1102 | 5 | View Code Duplication | public function customSortValues($function) |
| 1114 | |||
| 1115 | /** |
||
| 1116 | * Return values that are only in the current array. |
||
| 1117 | * |
||
| 1118 | * @param array $array |
||
| 1119 | * |
||
| 1120 | * @return static <p>(Immutable)</p> |
||
| 1121 | */ |
||
| 1122 | 12 | public function diff(array $array = []) |
|
| 1128 | |||
| 1129 | /** |
||
| 1130 | * Return values that are only in the current multi-dimensional array. |
||
| 1131 | * |
||
| 1132 | * @param array $array |
||
| 1133 | * @param null|array $helperVariableForRecursion <p>(only for internal usage)</p> |
||
| 1134 | * |
||
| 1135 | * @return static <p>(Immutable)</p> |
||
| 1136 | */ |
||
| 1137 | 1 | public function diffRecursive(array $array = [], $helperVariableForRecursion = null) |
|
| 1168 | |||
| 1169 | /** |
||
| 1170 | * Return values that are only in the new $array. |
||
| 1171 | * |
||
| 1172 | * @param array $array |
||
| 1173 | * |
||
| 1174 | * @return static <p>(Immutable)</p> |
||
| 1175 | */ |
||
| 1176 | 8 | public function diffReverse(array $array = []) |
|
| 1182 | |||
| 1183 | /** |
||
| 1184 | * Divide an array into two arrays. One with keys and the other with values. |
||
| 1185 | * |
||
| 1186 | * @return static <p>(Immutable)</p> |
||
| 1187 | */ |
||
| 1188 | 1 | public function divide() |
|
| 1197 | |||
| 1198 | /** |
||
| 1199 | * Iterate over the current array and modify the array's value. |
||
| 1200 | * |
||
| 1201 | * @param \Closure $closure |
||
| 1202 | * |
||
| 1203 | * @return static <p>(Immutable)</p> |
||
| 1204 | */ |
||
| 1205 | 4 | View Code Duplication | public function each(\Closure $closure) |
| 1215 | |||
| 1216 | /** |
||
| 1217 | * Check if a value is in the current array using a closure. |
||
| 1218 | * |
||
| 1219 | * @param \Closure $closure |
||
| 1220 | * |
||
| 1221 | * @return bool <p>Returns true if the given value is found, false otherwise.</p> |
||
| 1222 | */ |
||
| 1223 | 4 | public function exists(\Closure $closure): bool |
|
| 1235 | |||
| 1236 | /** |
||
| 1237 | * create a fallback for array |
||
| 1238 | * |
||
| 1239 | * 1. use the current array, if it's a array |
||
| 1240 | * 2. call "getArray()" on object, if there is a "Arrayy"-object |
||
| 1241 | * 3. fallback to empty array, if there is nothing |
||
| 1242 | * 4. call "createFromObject()" on object, if there is a "\ArrayAccess"-object |
||
| 1243 | * 5. call "__toArray()" on object, if the method exists |
||
| 1244 | * 6. cast a string or object with "__toString()" into an array |
||
| 1245 | * 7. throw a "InvalidArgumentException"-Exception |
||
| 1246 | * |
||
| 1247 | * @param $array |
||
| 1248 | * |
||
| 1249 | * @return array |
||
| 1250 | * |
||
| 1251 | * @throws \InvalidArgumentException |
||
| 1252 | */ |
||
| 1253 | 870 | protected function fallbackForArray(&$array): array |
|
| 1295 | |||
| 1296 | /** |
||
| 1297 | * Fill the array until "$num" with "$default" values. |
||
| 1298 | * |
||
| 1299 | * @param int $num |
||
| 1300 | * @param mixed $default |
||
| 1301 | * |
||
| 1302 | * @return static <p>(Immutable)</p> |
||
| 1303 | */ |
||
| 1304 | 8 | public function fillWithDefaults(int $num, $default = null) |
|
| 1321 | |||
| 1322 | /** |
||
| 1323 | * Find all items in an array that pass the truth test. |
||
| 1324 | * |
||
| 1325 | * @param \Closure|null $closure [optional] <p> |
||
| 1326 | * The callback function to use |
||
| 1327 | * </p> |
||
| 1328 | * <p> |
||
| 1329 | * If no callback is supplied, all entries of |
||
| 1330 | * input equal to false (see |
||
| 1331 | * converting to |
||
| 1332 | * boolean) will be removed. |
||
| 1333 | * </p> |
||
| 1334 | * |
||
| 1335 | * * @param int $flag [optional] <p> |
||
| 1336 | * Flag determining what arguments are sent to <i>callback</i>: |
||
| 1337 | * </p><ul> |
||
| 1338 | * <li> |
||
| 1339 | * <b>ARRAY_FILTER_USE_KEY</b> [1] - pass key as the only argument |
||
| 1340 | * to <i>callback</i> instead of the value</span> |
||
| 1341 | * </li> |
||
| 1342 | * <li> |
||
| 1343 | * <b>ARRAY_FILTER_USE_BOTH</b> [2] - pass both value and key as |
||
| 1344 | * arguments to <i>callback</i> instead of the value</span> |
||
| 1345 | * </li> |
||
| 1346 | * </ul> |
||
| 1347 | * |
||
| 1348 | * @return static <p>(Immutable)</p> |
||
| 1349 | */ |
||
| 1350 | 9 | public function filter($closure = null, int $flag = 0) |
|
| 1360 | |||
| 1361 | /** |
||
| 1362 | * Filters an array of objects (or a numeric array of associative arrays) based on the value of a particular property |
||
| 1363 | * within that. |
||
| 1364 | * |
||
| 1365 | * @param string $property |
||
| 1366 | * @param string|string[] $value |
||
| 1367 | * @param string $comparisonOp |
||
| 1368 | * <p> |
||
| 1369 | * 'eq' (equals),<br /> |
||
| 1370 | * 'gt' (greater),<br /> |
||
| 1371 | * 'gte' || 'ge' (greater or equals),<br /> |
||
| 1372 | * 'lt' (less),<br /> |
||
| 1373 | * 'lte' || 'le' (less or equals),<br /> |
||
| 1374 | * 'ne' (not equals),<br /> |
||
| 1375 | * 'contains',<br /> |
||
| 1376 | * 'notContains',<br /> |
||
| 1377 | * 'newer' (via strtotime),<br /> |
||
| 1378 | * 'older' (via strtotime),<br /> |
||
| 1379 | * </p> |
||
| 1380 | * |
||
| 1381 | * @return static <p>(Immutable)</p> |
||
| 1382 | */ |
||
| 1383 | 1 | public function filterBy(string $property, $value, string $comparisonOp = null) |
|
| 1448 | |||
| 1449 | /** |
||
| 1450 | * Find the first item in an array that passes the truth test, |
||
| 1451 | * otherwise return false |
||
| 1452 | * |
||
| 1453 | * @param \Closure $closure |
||
| 1454 | * |
||
| 1455 | * @return mixed|false <p>Return false if we did not find the value.</p> |
||
| 1456 | */ |
||
| 1457 | 8 | View Code Duplication | public function find(\Closure $closure) |
| 1467 | |||
| 1468 | /** |
||
| 1469 | * find by ... |
||
| 1470 | * |
||
| 1471 | * @param string $property |
||
| 1472 | * @param string|string[] $value |
||
| 1473 | * @param string $comparisonOp |
||
| 1474 | * |
||
| 1475 | * @return static <p>(Immutable)</p> |
||
| 1476 | */ |
||
| 1477 | public function findBy(string $property, $value, string $comparisonOp = 'eq') |
||
| 1481 | |||
| 1482 | /** |
||
| 1483 | * Get the first value from the current array. |
||
| 1484 | * |
||
| 1485 | * @return mixed <p>Return null if there wasn't a element.</p> |
||
| 1486 | */ |
||
| 1487 | 13 | public function first() |
|
| 1498 | |||
| 1499 | /** |
||
| 1500 | * Get the first value(s) from the current array. |
||
| 1501 | * |
||
| 1502 | * @param int|null $number <p>How many values you will take?</p> |
||
| 1503 | * |
||
| 1504 | * @return static <p>(Immutable)</p> |
||
| 1505 | */ |
||
| 1506 | 28 | public function firstsImmutable(int $number = null) |
|
| 1519 | |||
| 1520 | /** |
||
| 1521 | * Get the first value(s) from the current array. |
||
| 1522 | * |
||
| 1523 | * @param int|null $number <p>How many values you will take?</p> |
||
| 1524 | * |
||
| 1525 | * @return static <p>(Mutable)</p> |
||
| 1526 | */ |
||
| 1527 | 26 | public function firstsMutable(int $number = null) |
|
| 1538 | |||
| 1539 | /** |
||
| 1540 | * Exchanges all keys with their associated values in an array. |
||
| 1541 | * |
||
| 1542 | * @return static <p>(Immutable)</p> |
||
| 1543 | */ |
||
| 1544 | 1 | public function flip() |
|
| 1550 | |||
| 1551 | /** |
||
| 1552 | * Get a value from an array (optional using dot-notation). |
||
| 1553 | * |
||
| 1554 | * @param mixed $key <p>The key to look for.</p> |
||
| 1555 | * @param mixed $fallback <p>Value to fallback to.</p> |
||
| 1556 | * @param array $array <p>The array to get from, if it's set to "null" we use the current array from the |
||
| 1557 | * class.</p> |
||
| 1558 | * |
||
| 1559 | * @return mixed |
||
| 1560 | */ |
||
| 1561 | 62 | public function get($key, $fallback = null, array $array = null) |
|
| 1562 | { |
||
| 1563 | 62 | if ($array !== null) { |
|
| 1564 | 3 | $usedArray = $array; |
|
| 1565 | } else { |
||
| 1566 | 59 | $usedArray = $this->array; |
|
| 1567 | } |
||
| 1568 | |||
| 1569 | 62 | if ($key === null) { |
|
| 1570 | 1 | return static::create($usedArray); |
|
| 1571 | } |
||
| 1572 | |||
| 1573 | // php cast "bool"-index into "int"-index |
||
| 1574 | 62 | if ((bool)$key === $key) { |
|
| 1575 | 2 | $key = (int)$key; |
|
| 1576 | } |
||
| 1577 | |||
| 1578 | 62 | if (\array_key_exists($key, $usedArray) === true) { |
|
| 1579 | 52 | if (\is_array($usedArray[$key])) { |
|
| 1580 | 6 | return static::create($usedArray[$key]); |
|
| 1581 | } |
||
| 1582 | |||
| 1583 | 48 | return $usedArray[$key]; |
|
| 1584 | } |
||
| 1585 | |||
| 1586 | // Crawl through array, get key according to object or not |
||
| 1587 | 21 | foreach (\explode($this->pathSeparator, (string)$key) as $segment) { |
|
| 1588 | 21 | if (!isset($usedArray[$segment])) { |
|
| 1589 | 20 | return $fallback instanceof \Closure ? $fallback() : $fallback; |
|
| 1590 | } |
||
| 1591 | |||
| 1592 | 6 | $usedArray = $usedArray[$segment]; |
|
| 1593 | } |
||
| 1594 | |||
| 1595 | 6 | if (\is_array($usedArray)) { |
|
| 1596 | 1 | return static::create($usedArray); |
|
| 1597 | } |
||
| 1598 | |||
| 1599 | 6 | return $usedArray; |
|
| 1600 | } |
||
| 1601 | |||
| 1602 | /** |
||
| 1603 | * Get the current array from the "Arrayy"-object. |
||
| 1604 | * |
||
| 1605 | * @return array |
||
| 1606 | */ |
||
| 1607 | 578 | public function getArray(): array |
|
| 1613 | |||
| 1614 | /** |
||
| 1615 | * Returns the values from a single column of the input array, identified by |
||
| 1616 | * the $columnKey, can be used to extract data-columns from multi-arrays. |
||
| 1617 | * |
||
| 1618 | * Info: Optionally, you may provide an $indexKey to index the values in the returned |
||
| 1619 | * array by the values from the $indexKey column in the input array. |
||
| 1620 | * |
||
| 1621 | * @param mixed $columnKey |
||
| 1622 | * @param mixed $indexKey |
||
| 1623 | * |
||
| 1624 | * @return static <p>(Immutable)</p> |
||
| 1625 | */ |
||
| 1626 | 1 | public function getColumn($columnKey = null, $indexKey = null) |
|
| 1632 | |||
| 1633 | /** |
||
| 1634 | * Get correct PHP constant for direction. |
||
| 1635 | * |
||
| 1636 | * @param int|string $direction |
||
| 1637 | * |
||
| 1638 | * @return int |
||
| 1639 | */ |
||
| 1640 | 38 | protected function getDirection($direction): int |
|
| 1662 | |||
| 1663 | /** |
||
| 1664 | * alias: for "Arrayy->keys()" |
||
| 1665 | * |
||
| 1666 | * @see Arrayy::keys() |
||
| 1667 | * |
||
| 1668 | * @return static <p>(Immutable)</p> |
||
| 1669 | */ |
||
| 1670 | 1 | public function getKeys() |
|
| 1674 | |||
| 1675 | /** |
||
| 1676 | * Get the current array from the "Arrayy"-object as object. |
||
| 1677 | * |
||
| 1678 | * @return \stdClass (object) |
||
| 1679 | */ |
||
| 1680 | 4 | public function getObject(): \stdClass |
|
| 1684 | |||
| 1685 | /** |
||
| 1686 | * alias: for "Arrayy->randomImmutable()" |
||
| 1687 | * |
||
| 1688 | * @see Arrayy::randomImmutable() |
||
| 1689 | * |
||
| 1690 | * @return static <p>(Immutable)</p> |
||
| 1691 | */ |
||
| 1692 | 4 | public function getRandom() |
|
| 1696 | |||
| 1697 | /** |
||
| 1698 | * alias: for "Arrayy->randomKey()" |
||
| 1699 | * |
||
| 1700 | * @see Arrayy::randomKey() |
||
| 1701 | * |
||
| 1702 | * @return mixed <p>Get a key/index or null if there wasn't a key/index.</p> |
||
| 1703 | */ |
||
| 1704 | 3 | public function getRandomKey() |
|
| 1708 | |||
| 1709 | /** |
||
| 1710 | * alias: for "Arrayy->randomKeys()" |
||
| 1711 | * |
||
| 1712 | * @see Arrayy::randomKeys() |
||
| 1713 | * |
||
| 1714 | * @param int $number |
||
| 1715 | * |
||
| 1716 | * @return static <p>(Immutable)</p> |
||
| 1717 | */ |
||
| 1718 | 8 | public function getRandomKeys(int $number) |
|
| 1722 | |||
| 1723 | /** |
||
| 1724 | * alias: for "Arrayy->randomValue()" |
||
| 1725 | * |
||
| 1726 | * @see Arrayy::randomValue() |
||
| 1727 | * |
||
| 1728 | * @return mixed <p>get a random value or null if there wasn't a value.</p> |
||
| 1729 | */ |
||
| 1730 | 3 | public function getRandomValue() |
|
| 1734 | |||
| 1735 | /** |
||
| 1736 | * alias: for "Arrayy->randomValues()" |
||
| 1737 | * |
||
| 1738 | * @see Arrayy::randomValues() |
||
| 1739 | * |
||
| 1740 | * @param int $number |
||
| 1741 | * |
||
| 1742 | * @return static <p>(Immutable)</p> |
||
| 1743 | */ |
||
| 1744 | 6 | public function getRandomValues(int $number) |
|
| 1748 | |||
| 1749 | /** |
||
| 1750 | * Group values from a array according to the results of a closure. |
||
| 1751 | * |
||
| 1752 | * @param \callable $grouper <p>A callable function name.</p> |
||
| 1753 | * @param bool $saveKeys |
||
| 1754 | * |
||
| 1755 | * @return static <p>(Immutable)</p> |
||
| 1756 | */ |
||
| 1757 | 3 | public function group($grouper, bool $saveKeys = false) |
|
| 1791 | |||
| 1792 | /** |
||
| 1793 | * Check if an array has a given key. |
||
| 1794 | * |
||
| 1795 | * @param mixed $key |
||
| 1796 | * |
||
| 1797 | * @return bool |
||
| 1798 | */ |
||
| 1799 | 23 | public function has($key): bool |
|
| 1810 | |||
| 1811 | /** |
||
| 1812 | * Implodes the values of this array. |
||
| 1813 | * |
||
| 1814 | * @param string $glue |
||
| 1815 | * |
||
| 1816 | * @return string |
||
| 1817 | */ |
||
| 1818 | 27 | public function implode(string $glue = ''): string |
|
| 1822 | |||
| 1823 | /** |
||
| 1824 | * Implodes the keys of this array. |
||
| 1825 | * |
||
| 1826 | * @param string $glue |
||
| 1827 | * |
||
| 1828 | * @return string |
||
| 1829 | */ |
||
| 1830 | 8 | public function implodeKeys(string $glue = ''): string |
|
| 1834 | |||
| 1835 | /** |
||
| 1836 | * @param mixed $glue |
||
| 1837 | * @param string|array|static $pieces |
||
| 1838 | * @param bool $useKeys |
||
| 1839 | * |
||
| 1840 | * @return string |
||
| 1841 | */ |
||
| 1842 | 35 | protected function implode_recursive($glue = '', $pieces = [], bool $useKeys = false): string |
|
| 1864 | |||
| 1865 | /** |
||
| 1866 | * @param mixed $needle <p> |
||
| 1867 | * The searched value. |
||
| 1868 | * </p> |
||
| 1869 | * <p> |
||
| 1870 | * If needle is a string, the comparison is done |
||
| 1871 | * in a case-sensitive manner. |
||
| 1872 | * </p> |
||
| 1873 | * @param array $haystack <p> |
||
| 1874 | * The array. |
||
| 1875 | * </p> |
||
| 1876 | * @param bool $strict [optional] <p> |
||
| 1877 | * If the third parameter strict is set to true |
||
| 1878 | * then the in_array function will also check the |
||
| 1879 | * types of the |
||
| 1880 | * needle in the haystack. |
||
| 1881 | * </p> |
||
| 1882 | * |
||
| 1883 | * @return bool true if needle is found in the array, false otherwise. |
||
| 1884 | */ |
||
| 1885 | 44 | protected function in_array_recursive($needle, array $haystack = null, $strict = true): bool |
|
| 1906 | |||
| 1907 | /** |
||
| 1908 | * Given a list and an iterate-function that returns |
||
| 1909 | * a key for each element in the list (or a property name), |
||
| 1910 | * returns an object with an index of each item. |
||
| 1911 | * |
||
| 1912 | * @param mixed $key |
||
| 1913 | * |
||
| 1914 | * @return static <p>(Immutable)</p> |
||
| 1915 | */ |
||
| 1916 | 3 | public function indexBy($key) |
|
| 1928 | |||
| 1929 | /** |
||
| 1930 | * alias: for "Arrayy->searchIndex()" |
||
| 1931 | * |
||
| 1932 | * @see Arrayy::searchIndex() |
||
| 1933 | * |
||
| 1934 | * @param mixed $value <p>The value to search for.</p> |
||
| 1935 | * |
||
| 1936 | * @return mixed |
||
| 1937 | */ |
||
| 1938 | 4 | public function indexOf($value) |
|
| 1942 | |||
| 1943 | /** |
||
| 1944 | * Get everything but the last..$to items. |
||
| 1945 | * |
||
| 1946 | * @param int $to |
||
| 1947 | * |
||
| 1948 | * @return static <p>(Immutable)</p> |
||
| 1949 | */ |
||
| 1950 | 12 | public function initial(int $to = 1) |
|
| 1954 | |||
| 1955 | /** |
||
| 1956 | * @param mixed $value |
||
| 1957 | */ |
||
| 1958 | 476 | protected function internalGetArray(&$value) |
|
| 1975 | |||
| 1976 | /** |
||
| 1977 | * Internal mechanics of remove method. |
||
| 1978 | * |
||
| 1979 | * @param mixed $key |
||
| 1980 | * |
||
| 1981 | * @return bool |
||
| 1982 | */ |
||
| 1983 | 18 | protected function internalRemove($key): bool |
|
| 2004 | |||
| 2005 | /** |
||
| 2006 | * Internal mechanic of set method. |
||
| 2007 | * |
||
| 2008 | * @param mixed $key |
||
| 2009 | * @param mixed $value |
||
| 2010 | * |
||
| 2011 | * @return bool |
||
| 2012 | */ |
||
| 2013 | 30 | protected function internalSet($key, $value): bool |
|
| 2041 | |||
| 2042 | /** |
||
| 2043 | * Return an array with all elements found in input array. |
||
| 2044 | * |
||
| 2045 | * @param array $search |
||
| 2046 | * |
||
| 2047 | * @return static <p>(Immutable)</p> |
||
| 2048 | */ |
||
| 2049 | 2 | public function intersection(array $search) |
|
| 2053 | |||
| 2054 | /** |
||
| 2055 | * Return a boolean flag which indicates whether the two input arrays have any common elements. |
||
| 2056 | * |
||
| 2057 | * @param array $search |
||
| 2058 | * |
||
| 2059 | * @return bool |
||
| 2060 | */ |
||
| 2061 | 1 | public function intersects(array $search): bool |
|
| 2065 | |||
| 2066 | /** |
||
| 2067 | * Invoke a function on all of an array's values. |
||
| 2068 | * |
||
| 2069 | * @param mixed $callable |
||
| 2070 | * @param mixed $arguments |
||
| 2071 | * |
||
| 2072 | * @return static <p>(Immutable)</p> |
||
| 2073 | */ |
||
| 2074 | 1 | public function invoke($callable, $arguments = []) |
|
| 2093 | |||
| 2094 | /** |
||
| 2095 | * Check whether array is associative or not. |
||
| 2096 | * |
||
| 2097 | * @param bool $recursive |
||
| 2098 | * |
||
| 2099 | * @return bool <p>Returns true if associative, false otherwise.</p> |
||
| 2100 | */ |
||
| 2101 | 15 | public function isAssoc(bool $recursive = false): bool |
|
| 2115 | |||
| 2116 | /** |
||
| 2117 | * Check whether the array is empty or not. |
||
| 2118 | * |
||
| 2119 | * @return bool <p>Returns true if empty, false otherwise.</p> |
||
| 2120 | */ |
||
| 2121 | 88 | public function isEmpty(): bool |
|
| 2125 | |||
| 2126 | /** |
||
| 2127 | * Check if the current array is equal to the given "$array" or not. |
||
| 2128 | * |
||
| 2129 | * @param array $array |
||
| 2130 | * |
||
| 2131 | * @return bool |
||
| 2132 | */ |
||
| 2133 | public function isEqual(array $array): bool |
||
| 2137 | |||
| 2138 | /** |
||
| 2139 | * Check if the current array is a multi-array. |
||
| 2140 | * |
||
| 2141 | * @return bool |
||
| 2142 | */ |
||
| 2143 | 14 | public function isMultiArray(): bool |
|
| 2151 | |||
| 2152 | /** |
||
| 2153 | * Check whether array is numeric or not. |
||
| 2154 | * |
||
| 2155 | * @return bool <p>Returns true if numeric, false otherwise.</p> |
||
| 2156 | */ |
||
| 2157 | 5 | public function isNumeric(): bool |
|
| 2171 | |||
| 2172 | /** |
||
| 2173 | * Check if the current array is sequential [0, 1, 2, 3, 4, 5 ...] or not. |
||
| 2174 | * |
||
| 2175 | * @param bool $recursive |
||
| 2176 | * |
||
| 2177 | * @return bool |
||
| 2178 | */ |
||
| 2179 | 1 | public function isSequential(bool $recursive = false): bool |
|
| 2196 | |||
| 2197 | /** |
||
| 2198 | * @return array |
||
| 2199 | */ |
||
| 2200 | public function jsonSerialize(): array |
||
| 2204 | |||
| 2205 | /** |
||
| 2206 | * Get all keys from the current array. |
||
| 2207 | * |
||
| 2208 | * @param bool $recursive [optional] <p> |
||
| 2209 | * Get all keys, also from all sub-arrays from an multi-dimensional array. |
||
| 2210 | * </p> |
||
| 2211 | * @param mixed $search_value [optional] <p> |
||
| 2212 | * If specified, then only keys containing these values are returned. |
||
| 2213 | * </p> |
||
| 2214 | * @param bool $strict [optional] <p> |
||
| 2215 | * Determines if strict comparison (===) should be used during the search. |
||
| 2216 | * </p> |
||
| 2217 | * |
||
| 2218 | * @return static <p>(Immutable) An array of all the keys in input.</p> |
||
| 2219 | */ |
||
| 2220 | 26 | public function keys(bool $recursive = false, $search_value = null, bool $strict = true) |
|
| 2245 | |||
| 2246 | /** |
||
| 2247 | * Sort an array by key in reverse order. |
||
| 2248 | * |
||
| 2249 | * @param int $sort_flags [optional] <p> |
||
| 2250 | * You may modify the behavior of the sort using the optional |
||
| 2251 | * parameter sort_flags, for details |
||
| 2252 | * see sort. |
||
| 2253 | * </p> |
||
| 2254 | * |
||
| 2255 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
| 2256 | */ |
||
| 2257 | 4 | public function krsort(int $sort_flags = 0) |
|
| 2263 | |||
| 2264 | /** |
||
| 2265 | * Get the last value from the current array. |
||
| 2266 | * |
||
| 2267 | * @return mixed <p>Return null if there wasn't a element.</p> |
||
| 2268 | */ |
||
| 2269 | 4 | public function last() |
|
| 2273 | |||
| 2274 | /** |
||
| 2275 | * Get the last value(s) from the current array. |
||
| 2276 | * |
||
| 2277 | * @param int|null $number |
||
| 2278 | * |
||
| 2279 | * @return static <p>(Immutable)</p> |
||
| 2280 | */ |
||
| 2281 | 13 | public function lastsImmutable(int $number = null) |
|
| 2304 | |||
| 2305 | /** |
||
| 2306 | * Get the last value(s) from the current array. |
||
| 2307 | * |
||
| 2308 | * @param int|null $number |
||
| 2309 | * |
||
| 2310 | * @return static <p>(Mutable)</p> |
||
| 2311 | */ |
||
| 2312 | 13 | public function lastsMutable(int $number = null) |
|
| 2335 | |||
| 2336 | /** |
||
| 2337 | * Count the values from the current array. |
||
| 2338 | * |
||
| 2339 | * alias: for "Arrayy->count()" |
||
| 2340 | * |
||
| 2341 | * @see Arrayy::count() |
||
| 2342 | * |
||
| 2343 | * @param int $mode |
||
| 2344 | * |
||
| 2345 | * @return int |
||
| 2346 | */ |
||
| 2347 | 20 | public function length(int $mode = COUNT_NORMAL): int |
|
| 2351 | |||
| 2352 | /** |
||
| 2353 | * Apply the given function to the every element of the array, |
||
| 2354 | * collecting the results. |
||
| 2355 | * |
||
| 2356 | * @param \callable $callable |
||
| 2357 | * |
||
| 2358 | * @return static <p>(Immutable) Arrayy object with modified elements.</p> |
||
| 2359 | */ |
||
| 2360 | 4 | public function map($callable) |
|
| 2366 | |||
| 2367 | /** |
||
| 2368 | * Check if all items in current array match a truth test. |
||
| 2369 | * |
||
| 2370 | * @param \Closure $closure |
||
| 2371 | * |
||
| 2372 | * @return bool |
||
| 2373 | */ |
||
| 2374 | 15 | View Code Duplication | public function matches(\Closure $closure): bool |
| 2393 | |||
| 2394 | /** |
||
| 2395 | * Check if any item in the current array matches a truth test. |
||
| 2396 | * |
||
| 2397 | * @param \Closure $closure |
||
| 2398 | * |
||
| 2399 | * @return bool |
||
| 2400 | */ |
||
| 2401 | 14 | View Code Duplication | public function matchesAny(\Closure $closure): bool |
| 2420 | |||
| 2421 | /** |
||
| 2422 | * Get the max value from an array. |
||
| 2423 | * |
||
| 2424 | * @return mixed |
||
| 2425 | */ |
||
| 2426 | 10 | View Code Duplication | public function max() |
| 2434 | |||
| 2435 | /** |
||
| 2436 | * Merge the new $array into the current array. |
||
| 2437 | * |
||
| 2438 | * - keep key,value from the current array, also if the index is in the new $array |
||
| 2439 | * |
||
| 2440 | * @param array $array |
||
| 2441 | * @param bool $recursive |
||
| 2442 | * |
||
| 2443 | * @return static <p>(Immutable)</p> |
||
| 2444 | */ |
||
| 2445 | 25 | View Code Duplication | public function mergeAppendKeepIndex(array $array = [], bool $recursive = false) |
| 2455 | |||
| 2456 | /** |
||
| 2457 | * Merge the new $array into the current array. |
||
| 2458 | * |
||
| 2459 | * - replace duplicate assoc-keys from the current array with the key,values from the new $array |
||
| 2460 | * - create new indexes |
||
| 2461 | * |
||
| 2462 | * @param array $array |
||
| 2463 | * @param bool $recursive |
||
| 2464 | * |
||
| 2465 | * @return static <p>(Immutable)</p> |
||
| 2466 | */ |
||
| 2467 | 16 | View Code Duplication | public function mergeAppendNewIndex(array $array = [], bool $recursive = false) |
| 2477 | |||
| 2478 | /** |
||
| 2479 | * Merge the the current array into the $array. |
||
| 2480 | * |
||
| 2481 | * - use key,value from the new $array, also if the index is in the current array |
||
| 2482 | * |
||
| 2483 | * @param array $array |
||
| 2484 | * @param bool $recursive |
||
| 2485 | * |
||
| 2486 | * @return static <p>(Immutable)</p> |
||
| 2487 | */ |
||
| 2488 | 16 | View Code Duplication | public function mergePrependKeepIndex(array $array = [], bool $recursive = false) |
| 2498 | |||
| 2499 | /** |
||
| 2500 | * Merge the current array into the new $array. |
||
| 2501 | * |
||
| 2502 | * - replace duplicate assoc-keys from new $array with the key,values from the current array |
||
| 2503 | * - create new indexes |
||
| 2504 | * |
||
| 2505 | * @param array $array |
||
| 2506 | * @param bool $recursive |
||
| 2507 | * |
||
| 2508 | * @return static <p>(Immutable)</p> |
||
| 2509 | */ |
||
| 2510 | 17 | View Code Duplication | public function mergePrependNewIndex(array $array = [], bool $recursive = false) |
| 2520 | |||
| 2521 | /** |
||
| 2522 | * Get the min value from an array. |
||
| 2523 | * |
||
| 2524 | * @return mixed |
||
| 2525 | */ |
||
| 2526 | 10 | View Code Duplication | public function min() |
| 2534 | |||
| 2535 | /** |
||
| 2536 | * Move an array element to a new index. |
||
| 2537 | * |
||
| 2538 | * cherry-picked from: http://stackoverflow.com/questions/12624153/move-an-array-element-to-a-new-index-in-php |
||
| 2539 | * |
||
| 2540 | * @param int|string $from |
||
| 2541 | * @param int|string $to |
||
| 2542 | * |
||
| 2543 | * @return static <p>(Immutable)</p> |
||
| 2544 | */ |
||
| 2545 | 1 | public function moveElement($from, $to) |
|
| 2572 | |||
| 2573 | /** |
||
| 2574 | * Convert a object into an array. |
||
| 2575 | * |
||
| 2576 | * @param object $object |
||
| 2577 | * |
||
| 2578 | * @return mixed |
||
| 2579 | */ |
||
| 2580 | 5 | protected static function objectToArray($object) |
|
| 2592 | |||
| 2593 | /** |
||
| 2594 | * Get a subset of the items from the given array. |
||
| 2595 | * |
||
| 2596 | * @param mixed[] $keys |
||
| 2597 | * |
||
| 2598 | * @return static <p>(Immutable)</p> |
||
| 2599 | */ |
||
| 2600 | public function only(array $keys) |
||
| 2606 | |||
| 2607 | /** |
||
| 2608 | * Pad array to the specified size with a given value. |
||
| 2609 | * |
||
| 2610 | * @param int $size <p>Size of the result array.</p> |
||
| 2611 | * @param mixed $value <p>Empty value by default.</p> |
||
| 2612 | * |
||
| 2613 | * @return static <p>(Immutable) Arrayy object padded to $size with $value.</p> |
||
| 2614 | */ |
||
| 2615 | 4 | public function pad(int $size, $value) |
|
| 2621 | |||
| 2622 | /** |
||
| 2623 | * Pop a specified value off the end of the current array. |
||
| 2624 | * |
||
| 2625 | * @return mixed <p>(Mutable) The popped element from the current array.</p> |
||
| 2626 | */ |
||
| 2627 | 16 | public function pop() |
|
| 2631 | |||
| 2632 | /** |
||
| 2633 | * Prepend a (key) + value to the current array. |
||
| 2634 | * |
||
| 2635 | * @param mixed $value |
||
| 2636 | * @param mixed $key |
||
| 2637 | * |
||
| 2638 | * @return static <p>(Mutable) Return this Arrayy object, with the prepended value.</p> |
||
| 2639 | */ |
||
| 2640 | 8 | public function prepend($value, $key = null) |
|
| 2651 | |||
| 2652 | /** |
||
| 2653 | * Add a suffix to each key. |
||
| 2654 | * |
||
| 2655 | * @param mixed $suffix |
||
| 2656 | * |
||
| 2657 | * @return static <p>(Immutable) Return an Arrayy object, with the prepended keys.</p> |
||
| 2658 | */ |
||
| 2659 | 10 | View Code Duplication | public function prependToEachKey($suffix) |
| 2675 | |||
| 2676 | /** |
||
| 2677 | * Add a suffix to each value. |
||
| 2678 | * |
||
| 2679 | * @param mixed $suffix |
||
| 2680 | * |
||
| 2681 | * @return static <p>(Immutable) Return an Arrayy object, with the prepended values.</p> |
||
| 2682 | */ |
||
| 2683 | 10 | View Code Duplication | public function prependToEachValue($suffix) |
| 2700 | |||
| 2701 | /** |
||
| 2702 | * Push one or more values onto the end of array at once. |
||
| 2703 | * |
||
| 2704 | * @return static <p>(Mutable) Return this Arrayy object, with pushed elements to the end of array.</p> |
||
| 2705 | */ |
||
| 2706 | 4 | View Code Duplication | public function push(/* variadic arguments allowed */) |
| 2715 | |||
| 2716 | /** |
||
| 2717 | * Get a random value from the current array. |
||
| 2718 | * |
||
| 2719 | * @param null|int $number <p>How many values you will take?</p> |
||
| 2720 | * |
||
| 2721 | * @return static <p>(Immutable)</p> |
||
| 2722 | */ |
||
| 2723 | 18 | public function randomImmutable(int $number = null) |
|
| 2740 | |||
| 2741 | /** |
||
| 2742 | * Pick a random key/index from the keys of this array. |
||
| 2743 | * |
||
| 2744 | * @return mixed <p>Get a key/index or null if there wasn't a key/index.</p> |
||
| 2745 | * |
||
| 2746 | * @throws \RangeException If array is empty |
||
| 2747 | */ |
||
| 2748 | 4 | public function randomKey() |
|
| 2758 | |||
| 2759 | /** |
||
| 2760 | * Pick a given number of random keys/indexes out of this array. |
||
| 2761 | * |
||
| 2762 | * @param int $number <p>The number of keys/indexes (should be <= \count($this->array))</p> |
||
| 2763 | * |
||
| 2764 | * @return static <p>(Immutable)</p> |
||
| 2765 | * |
||
| 2766 | * @throws \RangeException If array is empty |
||
| 2767 | */ |
||
| 2768 | 13 | public function randomKeys(int $number) |
|
| 2786 | |||
| 2787 | /** |
||
| 2788 | * Get a random value from the current array. |
||
| 2789 | * |
||
| 2790 | * @param null|int $number <p>How many values you will take?</p> |
||
| 2791 | * |
||
| 2792 | * @return static <p>(Mutable)</p> |
||
| 2793 | */ |
||
| 2794 | 17 | public function randomMutable(int $number = null) |
|
| 2811 | |||
| 2812 | /** |
||
| 2813 | * Pick a random value from the values of this array. |
||
| 2814 | * |
||
| 2815 | * @return mixed <p>Get a random value or null if there wasn't a value.</p> |
||
| 2816 | */ |
||
| 2817 | 4 | public function randomValue() |
|
| 2827 | |||
| 2828 | /** |
||
| 2829 | * Pick a given number of random values out of this array. |
||
| 2830 | * |
||
| 2831 | * @param int $number |
||
| 2832 | * |
||
| 2833 | * @return static <p>(Mutable)</p> |
||
| 2834 | */ |
||
| 2835 | 7 | public function randomValues(int $number) |
|
| 2839 | |||
| 2840 | /** |
||
| 2841 | * Get a random value from an array, with the ability to skew the results. |
||
| 2842 | * |
||
| 2843 | * Example: randomWeighted(['foo' => 1, 'bar' => 2]) has a 66% chance of returning bar. |
||
| 2844 | * |
||
| 2845 | * @param array $array |
||
| 2846 | * @param null|int $number <p>How many values you will take?</p> |
||
| 2847 | * |
||
| 2848 | * @return static <p>(Immutable)</p> |
||
| 2849 | */ |
||
| 2850 | 9 | public function randomWeighted(array $array, int $number = null) |
|
| 2863 | |||
| 2864 | /** |
||
| 2865 | * Reduce the current array via callable e.g. anonymous-function. |
||
| 2866 | * |
||
| 2867 | * @param \callable $callable |
||
| 2868 | * @param array $init |
||
| 2869 | * |
||
| 2870 | * @return static <p>(Immutable)</p> |
||
| 2871 | */ |
||
| 2872 | 4 | public function reduce($callable, array $init = []) |
|
| 2884 | |||
| 2885 | /** |
||
| 2886 | * Create a numerically re-indexed Arrayy object. |
||
| 2887 | * |
||
| 2888 | * @return static <p>(Mutable) Return this Arrayy object, with re-indexed array-elements.</p> |
||
| 2889 | */ |
||
| 2890 | 9 | public function reindex() |
|
| 2896 | |||
| 2897 | /** |
||
| 2898 | * Return all items that fail the truth test. |
||
| 2899 | * |
||
| 2900 | * @param \Closure $closure |
||
| 2901 | * |
||
| 2902 | * @return static <p>(Immutable)</p> |
||
| 2903 | */ |
||
| 2904 | 1 | View Code Duplication | public function reject(\Closure $closure) |
| 2916 | |||
| 2917 | /** |
||
| 2918 | * Remove a value from the current array (optional using dot-notation). |
||
| 2919 | * |
||
| 2920 | * @param mixed $key |
||
| 2921 | * |
||
| 2922 | * @return static <p>(Immutable)</p> |
||
| 2923 | */ |
||
| 2924 | 18 | public function remove($key) |
|
| 2939 | |||
| 2940 | /** |
||
| 2941 | * Remove the first value from the current array. |
||
| 2942 | * |
||
| 2943 | * @return static <p>(Immutable)</p> |
||
| 2944 | */ |
||
| 2945 | 7 | public function removeFirst() |
|
| 2952 | |||
| 2953 | /** |
||
| 2954 | * Remove the last value from the current array. |
||
| 2955 | * |
||
| 2956 | * @return static <p>(Immutable)</p> |
||
| 2957 | */ |
||
| 2958 | 7 | public function removeLast() |
|
| 2965 | |||
| 2966 | /** |
||
| 2967 | * Removes a particular value from an array (numeric or associative). |
||
| 2968 | * |
||
| 2969 | * @param mixed $value |
||
| 2970 | * |
||
| 2971 | * @return static <p>(Immutable)</p> |
||
| 2972 | */ |
||
| 2973 | 7 | public function removeValue($value) |
|
| 2991 | |||
| 2992 | /** |
||
| 2993 | * Generate array of repeated arrays. |
||
| 2994 | * |
||
| 2995 | * @param int $times <p>How many times has to be repeated.</p> |
||
| 2996 | * |
||
| 2997 | * @return Arrayy |
||
| 2998 | */ |
||
| 2999 | 1 | public function repeat($times): self |
|
| 3007 | |||
| 3008 | /** |
||
| 3009 | * Replace a key with a new key/value pair. |
||
| 3010 | * |
||
| 3011 | * @param mixed $replace |
||
| 3012 | * @param mixed $key |
||
| 3013 | * @param mixed $value |
||
| 3014 | * |
||
| 3015 | * @return static <p>(Immutable)</p> |
||
| 3016 | */ |
||
| 3017 | 2 | public function replace($replace, $key, $value) |
|
| 3023 | |||
| 3024 | /** |
||
| 3025 | * Create an array using the current array as values and the other array as keys. |
||
| 3026 | * |
||
| 3027 | * @param array $keys <p>An array of keys.</p> |
||
| 3028 | * |
||
| 3029 | * @return static <p>(Immutable) Arrayy object with keys from the other array.</p> |
||
| 3030 | */ |
||
| 3031 | 2 | public function replaceAllKeys(array $keys) |
|
| 3037 | |||
| 3038 | /** |
||
| 3039 | * Create an array using the current array as keys and the other array as values. |
||
| 3040 | * |
||
| 3041 | * @param array $array <p>An array o values.</p> |
||
| 3042 | * |
||
| 3043 | * @return static <p>(Immutable) Arrayy object with values from the other array.</p> |
||
| 3044 | */ |
||
| 3045 | 2 | public function replaceAllValues(array $array) |
|
| 3051 | |||
| 3052 | /** |
||
| 3053 | * Replace the keys in an array with another set. |
||
| 3054 | * |
||
| 3055 | * @param array $keys <p>An array of keys matching the array's size</p> |
||
| 3056 | * |
||
| 3057 | * @return static <p>(Immutable)</p> |
||
| 3058 | */ |
||
| 3059 | 1 | public function replaceKeys(array $keys) |
|
| 3066 | |||
| 3067 | /** |
||
| 3068 | * Replace the first matched value in an array. |
||
| 3069 | * |
||
| 3070 | * @param mixed $search <p>The value to replace.</p> |
||
| 3071 | * @param mixed $replacement <p>The value to replace.</p> |
||
| 3072 | * |
||
| 3073 | * @return static <p>(Immutable)</p> |
||
| 3074 | */ |
||
| 3075 | 3 | public function replaceOneValue($search, $replacement = '') |
|
| 3086 | |||
| 3087 | /** |
||
| 3088 | * Replace values in the current array. |
||
| 3089 | * |
||
| 3090 | * @param mixed $search <p>The value to replace.</p> |
||
| 3091 | * @param mixed $replacement <p>What to replace it with.</p> |
||
| 3092 | * |
||
| 3093 | * @return static <p>(Immutable)</p> |
||
| 3094 | */ |
||
| 3095 | 1 | public function replaceValues($search, $replacement = '') |
|
| 3105 | |||
| 3106 | /** |
||
| 3107 | * Get the last elements from index $from until the end of this array. |
||
| 3108 | * |
||
| 3109 | * @param int $from |
||
| 3110 | * |
||
| 3111 | * @return static <p>(Immutable)</p> |
||
| 3112 | */ |
||
| 3113 | 15 | public function rest(int $from = 1) |
|
| 3119 | |||
| 3120 | /** |
||
| 3121 | * Return the array in the reverse order. |
||
| 3122 | * |
||
| 3123 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
| 3124 | */ |
||
| 3125 | 8 | public function reverse() |
|
| 3131 | |||
| 3132 | /** |
||
| 3133 | * Sort an array in reverse order. |
||
| 3134 | * |
||
| 3135 | * @param int $sort_flags [optional] <p> |
||
| 3136 | * You may modify the behavior of the sort using the optional |
||
| 3137 | * parameter sort_flags, for details |
||
| 3138 | * see sort. |
||
| 3139 | * </p> |
||
| 3140 | * |
||
| 3141 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
| 3142 | */ |
||
| 3143 | 4 | public function rsort(int $sort_flags = 0) |
|
| 3149 | |||
| 3150 | /** |
||
| 3151 | * Search for the first index of the current array via $value. |
||
| 3152 | * |
||
| 3153 | * @param mixed $value |
||
| 3154 | * |
||
| 3155 | * @return int|float|string |
||
| 3156 | */ |
||
| 3157 | 20 | public function searchIndex($value) |
|
| 3161 | |||
| 3162 | /** |
||
| 3163 | * Search for the value of the current array via $index. |
||
| 3164 | * |
||
| 3165 | * @param mixed $index |
||
| 3166 | * |
||
| 3167 | * @return static <p>(Immutable) Will return a empty Arrayy if the value wasn't found.</p> |
||
| 3168 | */ |
||
| 3169 | 9 | public function searchValue($index) |
|
| 3190 | |||
| 3191 | /** |
||
| 3192 | * Set a value for the current array (optional using dot-notation). |
||
| 3193 | * |
||
| 3194 | * @param mixed $key <p>The key to set.</p> |
||
| 3195 | * @param mixed $value <p>Its value.</p> |
||
| 3196 | * |
||
| 3197 | * @return static <p>(Immutable)</p> |
||
| 3198 | */ |
||
| 3199 | 17 | public function set($key, $value) |
|
| 3205 | |||
| 3206 | /** |
||
| 3207 | * Get a value from a array and set it if it was not. |
||
| 3208 | * |
||
| 3209 | * WARNING: this method only set the value, if the $key is not already set |
||
| 3210 | * |
||
| 3211 | * @param mixed $key <p>The key</p> |
||
| 3212 | * @param mixed $fallback <p>The default value to set if it isn't.</p> |
||
| 3213 | * |
||
| 3214 | * @return mixed <p>(Mutable)</p> |
||
| 3215 | */ |
||
| 3216 | 11 | public function setAndGet($key, $fallback = null) |
|
| 3225 | |||
| 3226 | /** |
||
| 3227 | * Shifts a specified value off the beginning of array. |
||
| 3228 | * |
||
| 3229 | * @return mixed <p>(Mutable) A shifted element from the current array.</p> |
||
| 3230 | */ |
||
| 3231 | 4 | public function shift() |
|
| 3235 | |||
| 3236 | /** |
||
| 3237 | * Shuffle the current array. |
||
| 3238 | * |
||
| 3239 | * @param bool $secure <p>using a CSPRNG | @link https://paragonie.com/b/JvICXzh_jhLyt4y3</p> |
||
| 3240 | * @param array $array [optional] |
||
| 3241 | * |
||
| 3242 | * @return static <p>(Immutable)</p> |
||
| 3243 | */ |
||
| 3244 | 1 | public function shuffle(bool $secure = false, array $array = null) |
|
| 3281 | |||
| 3282 | /** |
||
| 3283 | * Count the values from the current array. |
||
| 3284 | * |
||
| 3285 | * alias: for "Arrayy->count()" |
||
| 3286 | * |
||
| 3287 | * @param int $mode |
||
| 3288 | * |
||
| 3289 | * @return int |
||
| 3290 | */ |
||
| 3291 | 20 | public function size(int $mode = COUNT_NORMAL): int |
|
| 3295 | |||
| 3296 | /** |
||
| 3297 | * Counts all elements in an array, or something in an object. |
||
| 3298 | * <p>For objects, if you have SPL installed, you can hook into count() by implementing interface {@see Countable}. |
||
| 3299 | * The interface has exactly one method, {@see Countable::count()}, which returns the return value for the count() |
||
| 3300 | * function. Please see the {@see Array} section of the manual for a detailed explanation of how arrays are |
||
| 3301 | * implemented and used in PHP. |
||
| 3302 | * |
||
| 3303 | * @return int the number of elements in var, which is |
||
| 3304 | * typically an array, since anything else will have one |
||
| 3305 | * element. |
||
| 3306 | * </p> |
||
| 3307 | * <p> |
||
| 3308 | * If var is not an array or an object with |
||
| 3309 | * implemented Countable interface, |
||
| 3310 | * 1 will be returned. |
||
| 3311 | * There is one exception, if var is &null;, |
||
| 3312 | * 0 will be returned. |
||
| 3313 | * </p> |
||
| 3314 | * <p> |
||
| 3315 | * Caution: count may return 0 for a variable that isn't set, |
||
| 3316 | * but it may also return 0 for a variable that has been initialized with an |
||
| 3317 | * empty array. Use isset to test if a variable is set. |
||
| 3318 | * |
||
| 3319 | * @return int |
||
| 3320 | */ |
||
| 3321 | 10 | public function sizeRecursive(): int |
|
| 3325 | |||
| 3326 | /** |
||
| 3327 | * Extract a slice of the array. |
||
| 3328 | * |
||
| 3329 | * @param int $offset <p>Slice begin index.</p> |
||
| 3330 | * @param int|null $length <p>Length of the slice.</p> |
||
| 3331 | * @param bool $preserveKeys <p>Whether array keys are preserved or no.</p> |
||
| 3332 | * |
||
| 3333 | * @return static <p>A slice of the original array with length $length.</p> |
||
| 3334 | */ |
||
| 3335 | 4 | public function slice(int $offset, int $length = null, bool $preserveKeys = false) |
|
| 3341 | |||
| 3342 | /** |
||
| 3343 | * Sort the current array and optional you can keep the keys. |
||
| 3344 | * |
||
| 3345 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 3346 | * @param int $strategy <p>sort_flags => use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 3347 | * <strong>SORT_NATURAL</strong></p> |
||
| 3348 | * @param bool $keepKeys |
||
| 3349 | * |
||
| 3350 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
| 3351 | */ |
||
| 3352 | 19 | public function sort($direction = SORT_ASC, int $strategy = SORT_REGULAR, bool $keepKeys = false) |
|
| 3358 | |||
| 3359 | /** |
||
| 3360 | * Sort the current array by key. |
||
| 3361 | * |
||
| 3362 | * @link http://php.net/manual/en/function.ksort.php |
||
| 3363 | * @link http://php.net/manual/en/function.krsort.php |
||
| 3364 | * |
||
| 3365 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 3366 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 3367 | * <strong>SORT_NATURAL</strong></p> |
||
| 3368 | * |
||
| 3369 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
| 3370 | */ |
||
| 3371 | 18 | public function sortKeys($direction = SORT_ASC, int $strategy = SORT_REGULAR) |
|
| 3377 | |||
| 3378 | /** |
||
| 3379 | * Sort the current array by value. |
||
| 3380 | * |
||
| 3381 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 3382 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 3383 | * <strong>SORT_NATURAL</strong></p> |
||
| 3384 | * |
||
| 3385 | * @return static <p>(Mutable)</p> |
||
| 3386 | */ |
||
| 3387 | 1 | public function sortValueKeepIndex($direction = SORT_ASC, int $strategy = SORT_REGULAR) |
|
| 3391 | |||
| 3392 | /** |
||
| 3393 | * Sort the current array by value. |
||
| 3394 | * |
||
| 3395 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 3396 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 3397 | * <strong>SORT_NATURAL</strong></p> |
||
| 3398 | * |
||
| 3399 | * @return static <p>(Mutable)</p> |
||
| 3400 | */ |
||
| 3401 | 1 | public function sortValueNewIndex($direction = SORT_ASC, int $strategy = SORT_REGULAR) |
|
| 3405 | |||
| 3406 | /** |
||
| 3407 | * Sort a array by value, by a closure or by a property. |
||
| 3408 | * |
||
| 3409 | * - If the sorter is null, the array is sorted naturally. |
||
| 3410 | * - Associative (string) keys will be maintained, but numeric keys will be re-indexed. |
||
| 3411 | * |
||
| 3412 | * @param \callable|null $sorter |
||
| 3413 | * @param string|int $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 3414 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 3415 | * <strong>SORT_NATURAL</strong></p> |
||
| 3416 | * |
||
| 3417 | * @return static <p>(Immutable)</p> |
||
| 3418 | */ |
||
| 3419 | 1 | public function sorter($sorter = null, $direction = SORT_ASC, int $strategy = SORT_REGULAR) |
|
| 3445 | |||
| 3446 | /** |
||
| 3447 | * sorting keys |
||
| 3448 | * |
||
| 3449 | * @param array $elements |
||
| 3450 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 3451 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 3452 | * <strong>SORT_NATURAL</strong></p> |
||
| 3453 | * |
||
| 3454 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
| 3455 | */ |
||
| 3456 | 18 | protected function sorterKeys(array &$elements, $direction = SORT_ASC, int $strategy = SORT_REGULAR) |
|
| 3473 | |||
| 3474 | /** |
||
| 3475 | * @param array &$elements |
||
| 3476 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 3477 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 3478 | * <strong>SORT_NATURAL</strong></p> |
||
| 3479 | * @param bool $keepKeys |
||
| 3480 | * |
||
| 3481 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
| 3482 | */ |
||
| 3483 | 19 | protected function sorting(array &$elements, $direction = SORT_ASC, int $strategy = SORT_REGULAR, bool $keepKeys = false) |
|
| 3512 | |||
| 3513 | /** |
||
| 3514 | * Split an array in the given amount of pieces. |
||
| 3515 | * |
||
| 3516 | * @param int $numberOfPieces |
||
| 3517 | * @param bool $keepKeys |
||
| 3518 | * |
||
| 3519 | * @return static <p>(Immutable)</p> |
||
| 3520 | */ |
||
| 3521 | 1 | public function split(int $numberOfPieces = 2, bool $keepKeys = false) |
|
| 3534 | |||
| 3535 | /** |
||
| 3536 | * Stripe all empty items. |
||
| 3537 | * |
||
| 3538 | * @return static <p>(Immutable)</p> |
||
| 3539 | */ |
||
| 3540 | 1 | public function stripEmpty() |
|
| 3552 | |||
| 3553 | /** |
||
| 3554 | * Swap two values between positions by key. |
||
| 3555 | * |
||
| 3556 | * @param string|int $swapA <p>a key in the array</p> |
||
| 3557 | * @param string|int $swapB <p>a key in the array</p> |
||
| 3558 | * |
||
| 3559 | * @return static <p>(Immutable)</p> |
||
| 3560 | */ |
||
| 3561 | 1 | public function swap($swapA, $swapB) |
|
| 3569 | |||
| 3570 | /** |
||
| 3571 | * alias: for "Arrayy->getArray()" |
||
| 3572 | * |
||
| 3573 | * @see Arrayy::getArray() |
||
| 3574 | */ |
||
| 3575 | 186 | public function toArray() |
|
| 3579 | |||
| 3580 | /** |
||
| 3581 | * Convert the current array to JSON. |
||
| 3582 | * |
||
| 3583 | * @param int $options [optional] <p>e.g. JSON_PRETTY_PRINT</p> |
||
| 3584 | * @param int $depth [optional] <p>Set the maximum depth. Must be greater than zero.</p> |
||
| 3585 | * |
||
| 3586 | * @return string |
||
| 3587 | */ |
||
| 3588 | 6 | public function toJson(int $options = 0, int $depth = 512): string |
|
| 3592 | |||
| 3593 | /** |
||
| 3594 | * Implodes array to a string with specified separator. |
||
| 3595 | * |
||
| 3596 | * @param string $separator [optional] <p>The element's separator.</p> |
||
| 3597 | * |
||
| 3598 | * @return string <p>The string representation of array, separated by ",".</p> |
||
| 3599 | */ |
||
| 3600 | 19 | public function toString(string $separator = ','): string |
|
| 3604 | |||
| 3605 | /** |
||
| 3606 | * Return a duplicate free copy of the current array. |
||
| 3607 | * |
||
| 3608 | * @return static <p>(Mutable)</p> |
||
| 3609 | */ |
||
| 3610 | 9 | public function unique() |
|
| 3634 | |||
| 3635 | /** |
||
| 3636 | * Return a duplicate free copy of the current array. (with the old keys) |
||
| 3637 | * |
||
| 3638 | * @return static <p>(Mutable)</p> |
||
| 3639 | */ |
||
| 3640 | 9 | public function uniqueKeepIndex() |
|
| 3667 | |||
| 3668 | /** |
||
| 3669 | * alias: for "Arrayy->unique()" |
||
| 3670 | * |
||
| 3671 | * @see Arrayy::unique() |
||
| 3672 | * |
||
| 3673 | * @return static <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
| 3674 | */ |
||
| 3675 | 9 | public function uniqueNewIndex() |
|
| 3679 | |||
| 3680 | /** |
||
| 3681 | * Prepends one or more values to the beginning of array at once. |
||
| 3682 | * |
||
| 3683 | * @return static <p>(Mutable) Return this Arrayy object, with prepended elements to the beginning of array.</p> |
||
| 3684 | */ |
||
| 3685 | 4 | View Code Duplication | public function unshift(/* variadic arguments allowed */) |
| 3694 | |||
| 3695 | /** |
||
| 3696 | * Get all values from a array. |
||
| 3697 | * |
||
| 3698 | * @return static <p>(Immutable)</p> |
||
| 3699 | */ |
||
| 3700 | 2 | public function values() |
|
| 3704 | |||
| 3705 | /** |
||
| 3706 | * Apply the given function to every element in the array, discarding the results. |
||
| 3707 | * |
||
| 3708 | * @param \callable $callable |
||
| 3709 | * @param bool $recursive <p>Whether array will be walked recursively or no</p> |
||
| 3710 | * |
||
| 3711 | * @return static <p>(Mutable) Return this Arrayy object, with modified elements.</p> |
||
| 3712 | */ |
||
| 3713 | 35 | public function walk($callable, bool $recursive = false) |
|
| 3723 | } |
||
| 3724 |
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: