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 | 869 | 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 | 867 | 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 array $array |
||
| 948 | * |
||
| 949 | * @return static <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 950 | */ |
||
| 951 | 537 | 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 | 869 | 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 | 61 | public function get($key, $fallback = null, array $array = null) |
|
| 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 | 22 | public function has($key): bool |
|
| 1806 | |||
| 1807 | /** |
||
| 1808 | * Implodes the values of this array. |
||
| 1809 | * |
||
| 1810 | * @param string $glue |
||
| 1811 | * |
||
| 1812 | * @return string |
||
| 1813 | */ |
||
| 1814 | 27 | public function implode(string $glue = ''): string |
|
| 1818 | |||
| 1819 | /** |
||
| 1820 | * Implodes the keys of this array. |
||
| 1821 | * |
||
| 1822 | * @param string $glue |
||
| 1823 | * |
||
| 1824 | * @return string |
||
| 1825 | */ |
||
| 1826 | 8 | public function implodeKeys(string $glue = ''): string |
|
| 1830 | |||
| 1831 | /** |
||
| 1832 | * @param mixed $glue |
||
| 1833 | * @param string|array|static $pieces |
||
| 1834 | * @param bool $useKeys |
||
| 1835 | * |
||
| 1836 | * @return string |
||
| 1837 | */ |
||
| 1838 | 35 | protected function implode_recursive($glue = '', $pieces = [], bool $useKeys = false): string |
|
| 1860 | |||
| 1861 | /** |
||
| 1862 | * @param mixed $needle <p> |
||
| 1863 | * The searched value. |
||
| 1864 | * </p> |
||
| 1865 | * <p> |
||
| 1866 | * If needle is a string, the comparison is done |
||
| 1867 | * in a case-sensitive manner. |
||
| 1868 | * </p> |
||
| 1869 | * @param array $haystack <p> |
||
| 1870 | * The array. |
||
| 1871 | * </p> |
||
| 1872 | * @param bool $strict [optional] <p> |
||
| 1873 | * If the third parameter strict is set to true |
||
| 1874 | * then the in_array function will also check the |
||
| 1875 | * types of the |
||
| 1876 | * needle in the haystack. |
||
| 1877 | * </p> |
||
| 1878 | * |
||
| 1879 | * @return bool true if needle is found in the array, false otherwise. |
||
| 1880 | */ |
||
| 1881 | 44 | protected function in_array_recursive($needle, array $haystack = null, $strict = true): bool |
|
| 1902 | |||
| 1903 | /** |
||
| 1904 | * Given a list and an iterate-function that returns |
||
| 1905 | * a key for each element in the list (or a property name), |
||
| 1906 | * returns an object with an index of each item. |
||
| 1907 | * |
||
| 1908 | * @param mixed $key |
||
| 1909 | * |
||
| 1910 | * @return static <p>(Immutable)</p> |
||
| 1911 | */ |
||
| 1912 | 3 | public function indexBy($key) |
|
| 1924 | |||
| 1925 | /** |
||
| 1926 | * alias: for "Arrayy->searchIndex()" |
||
| 1927 | * |
||
| 1928 | * @see Arrayy::searchIndex() |
||
| 1929 | * |
||
| 1930 | * @param mixed $value <p>The value to search for.</p> |
||
| 1931 | * |
||
| 1932 | * @return mixed |
||
| 1933 | */ |
||
| 1934 | 4 | public function indexOf($value) |
|
| 1938 | |||
| 1939 | /** |
||
| 1940 | * Get everything but the last..$to items. |
||
| 1941 | * |
||
| 1942 | * @param int $to |
||
| 1943 | * |
||
| 1944 | * @return static <p>(Immutable)</p> |
||
| 1945 | */ |
||
| 1946 | 12 | public function initial(int $to = 1) |
|
| 1950 | |||
| 1951 | /** |
||
| 1952 | * @param mixed $value |
||
| 1953 | */ |
||
| 1954 | 476 | protected function internalGetArray(&$value) |
|
| 1971 | |||
| 1972 | /** |
||
| 1973 | * Internal mechanics of remove method. |
||
| 1974 | * |
||
| 1975 | * @param mixed $key |
||
| 1976 | * |
||
| 1977 | * @return bool |
||
| 1978 | */ |
||
| 1979 | 18 | protected function internalRemove($key): bool |
|
| 2000 | |||
| 2001 | /** |
||
| 2002 | * Internal mechanic of set method. |
||
| 2003 | * |
||
| 2004 | * @param mixed $key |
||
| 2005 | * @param mixed $value |
||
| 2006 | * |
||
| 2007 | * @return bool |
||
| 2008 | */ |
||
| 2009 | 30 | protected function internalSet($key, $value): bool |
|
| 2037 | |||
| 2038 | /** |
||
| 2039 | * Return an array with all elements found in input array. |
||
| 2040 | * |
||
| 2041 | * @param array $search |
||
| 2042 | * |
||
| 2043 | * @return static <p>(Immutable)</p> |
||
| 2044 | */ |
||
| 2045 | 2 | public function intersection(array $search) |
|
| 2049 | |||
| 2050 | /** |
||
| 2051 | * Return a boolean flag which indicates whether the two input arrays have any common elements. |
||
| 2052 | * |
||
| 2053 | * @param array $search |
||
| 2054 | * |
||
| 2055 | * @return bool |
||
| 2056 | */ |
||
| 2057 | 1 | public function intersects(array $search): bool |
|
| 2061 | |||
| 2062 | /** |
||
| 2063 | * Invoke a function on all of an array's values. |
||
| 2064 | * |
||
| 2065 | * @param mixed $callable |
||
| 2066 | * @param mixed $arguments |
||
| 2067 | * |
||
| 2068 | * @return static <p>(Immutable)</p> |
||
| 2069 | */ |
||
| 2070 | 1 | public function invoke($callable, $arguments = []) |
|
| 2089 | |||
| 2090 | /** |
||
| 2091 | * Check whether array is associative or not. |
||
| 2092 | * |
||
| 2093 | * @param bool $recursive |
||
| 2094 | * |
||
| 2095 | * @return bool <p>Returns true if associative, false otherwise.</p> |
||
| 2096 | */ |
||
| 2097 | 15 | public function isAssoc(bool $recursive = false): bool |
|
| 2111 | |||
| 2112 | /** |
||
| 2113 | * Check whether the array is empty or not. |
||
| 2114 | * |
||
| 2115 | * @return bool <p>Returns true if empty, false otherwise.</p> |
||
| 2116 | */ |
||
| 2117 | 88 | public function isEmpty(): bool |
|
| 2121 | |||
| 2122 | /** |
||
| 2123 | * Check if the current array is equal to the given "$array" or not. |
||
| 2124 | * |
||
| 2125 | * @param array $array |
||
| 2126 | * |
||
| 2127 | * @return bool |
||
| 2128 | */ |
||
| 2129 | public function isEqual(array $array): bool |
||
| 2133 | |||
| 2134 | /** |
||
| 2135 | * Check if the current array is a multi-array. |
||
| 2136 | * |
||
| 2137 | * @return bool |
||
| 2138 | */ |
||
| 2139 | 14 | public function isMultiArray(): bool |
|
| 2147 | |||
| 2148 | /** |
||
| 2149 | * Check whether array is numeric or not. |
||
| 2150 | * |
||
| 2151 | * @return bool <p>Returns true if numeric, false otherwise.</p> |
||
| 2152 | */ |
||
| 2153 | 5 | public function isNumeric(): bool |
|
| 2167 | |||
| 2168 | /** |
||
| 2169 | * Check if the current array is sequential [0, 1, 2, 3, 4, 5 ...] or not. |
||
| 2170 | * |
||
| 2171 | * @param bool $recursive |
||
| 2172 | * |
||
| 2173 | * @return bool |
||
| 2174 | */ |
||
| 2175 | 1 | public function isSequential(bool $recursive = false): bool |
|
| 2192 | |||
| 2193 | /** |
||
| 2194 | * @return array |
||
| 2195 | */ |
||
| 2196 | public function jsonSerialize(): array |
||
| 2200 | |||
| 2201 | /** |
||
| 2202 | * Get all keys from the current array. |
||
| 2203 | * |
||
| 2204 | * @param bool $recursive [optional] <p> |
||
| 2205 | * Get all keys, also from all sub-arrays from an multi-dimensional array. |
||
| 2206 | * </p> |
||
| 2207 | * @param mixed $search_value [optional] <p> |
||
| 2208 | * If specified, then only keys containing these values are returned. |
||
| 2209 | * </p> |
||
| 2210 | * @param bool $strict [optional] <p> |
||
| 2211 | * Determines if strict comparison (===) should be used during the search. |
||
| 2212 | * </p> |
||
| 2213 | * |
||
| 2214 | * @return static <p>(Immutable) An array of all the keys in input.</p> |
||
| 2215 | */ |
||
| 2216 | 26 | public function keys(bool $recursive = false, $search_value = null, bool $strict = true) |
|
| 2241 | |||
| 2242 | /** |
||
| 2243 | * Sort an array by key in reverse order. |
||
| 2244 | * |
||
| 2245 | * @param int $sort_flags [optional] <p> |
||
| 2246 | * You may modify the behavior of the sort using the optional |
||
| 2247 | * parameter sort_flags, for details |
||
| 2248 | * see sort. |
||
| 2249 | * </p> |
||
| 2250 | * |
||
| 2251 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
| 2252 | */ |
||
| 2253 | 4 | public function krsort(int $sort_flags = 0) |
|
| 2259 | |||
| 2260 | /** |
||
| 2261 | * Get the last value from the current array. |
||
| 2262 | * |
||
| 2263 | * @return mixed <p>Return null if there wasn't a element.</p> |
||
| 2264 | */ |
||
| 2265 | 4 | public function last() |
|
| 2269 | |||
| 2270 | /** |
||
| 2271 | * Get the last value(s) from the current array. |
||
| 2272 | * |
||
| 2273 | * @param int|null $number |
||
| 2274 | * |
||
| 2275 | * @return static <p>(Immutable)</p> |
||
| 2276 | */ |
||
| 2277 | 13 | public function lastsImmutable(int $number = null) |
|
| 2300 | |||
| 2301 | /** |
||
| 2302 | * Get the last value(s) from the current array. |
||
| 2303 | * |
||
| 2304 | * @param int|null $number |
||
| 2305 | * |
||
| 2306 | * @return static <p>(Mutable)</p> |
||
| 2307 | */ |
||
| 2308 | 13 | public function lastsMutable(int $number = null) |
|
| 2331 | |||
| 2332 | /** |
||
| 2333 | * Count the values from the current array. |
||
| 2334 | * |
||
| 2335 | * alias: for "Arrayy->count()" |
||
| 2336 | * |
||
| 2337 | * @see Arrayy::count() |
||
| 2338 | * |
||
| 2339 | * @param int $mode |
||
| 2340 | * |
||
| 2341 | * @return int |
||
| 2342 | */ |
||
| 2343 | 20 | public function length(int $mode = COUNT_NORMAL): int |
|
| 2347 | |||
| 2348 | /** |
||
| 2349 | * Apply the given function to the every element of the array, |
||
| 2350 | * collecting the results. |
||
| 2351 | * |
||
| 2352 | * @param \callable $callable |
||
| 2353 | * |
||
| 2354 | * @return static <p>(Immutable) Arrayy object with modified elements.</p> |
||
| 2355 | */ |
||
| 2356 | 4 | public function map($callable) |
|
| 2362 | |||
| 2363 | /** |
||
| 2364 | * Check if all items in current array match a truth test. |
||
| 2365 | * |
||
| 2366 | * @param \Closure $closure |
||
| 2367 | * |
||
| 2368 | * @return bool |
||
| 2369 | */ |
||
| 2370 | 15 | View Code Duplication | public function matches(\Closure $closure): bool |
| 2389 | |||
| 2390 | /** |
||
| 2391 | * Check if any item in the current array matches a truth test. |
||
| 2392 | * |
||
| 2393 | * @param \Closure $closure |
||
| 2394 | * |
||
| 2395 | * @return bool |
||
| 2396 | */ |
||
| 2397 | 14 | View Code Duplication | public function matchesAny(\Closure $closure): bool |
| 2416 | |||
| 2417 | /** |
||
| 2418 | * Get the max value from an array. |
||
| 2419 | * |
||
| 2420 | * @return mixed |
||
| 2421 | */ |
||
| 2422 | 10 | View Code Duplication | public function max() |
| 2430 | |||
| 2431 | /** |
||
| 2432 | * Merge the new $array into the current array. |
||
| 2433 | * |
||
| 2434 | * - keep key,value from the current array, also if the index is in the new $array |
||
| 2435 | * |
||
| 2436 | * @param array $array |
||
| 2437 | * @param bool $recursive |
||
| 2438 | * |
||
| 2439 | * @return static <p>(Immutable)</p> |
||
| 2440 | */ |
||
| 2441 | 25 | View Code Duplication | public function mergeAppendKeepIndex(array $array = [], bool $recursive = false) |
| 2451 | |||
| 2452 | /** |
||
| 2453 | * Merge the new $array into the current array. |
||
| 2454 | * |
||
| 2455 | * - replace duplicate assoc-keys from the current array with the key,values from the new $array |
||
| 2456 | * - create new indexes |
||
| 2457 | * |
||
| 2458 | * @param array $array |
||
| 2459 | * @param bool $recursive |
||
| 2460 | * |
||
| 2461 | * @return static <p>(Immutable)</p> |
||
| 2462 | */ |
||
| 2463 | 16 | View Code Duplication | public function mergeAppendNewIndex(array $array = [], bool $recursive = false) |
| 2473 | |||
| 2474 | /** |
||
| 2475 | * Merge the the current array into the $array. |
||
| 2476 | * |
||
| 2477 | * - use key,value from the new $array, also if the index is in the current array |
||
| 2478 | * |
||
| 2479 | * @param array $array |
||
| 2480 | * @param bool $recursive |
||
| 2481 | * |
||
| 2482 | * @return static <p>(Immutable)</p> |
||
| 2483 | */ |
||
| 2484 | 16 | View Code Duplication | public function mergePrependKeepIndex(array $array = [], bool $recursive = false) |
| 2494 | |||
| 2495 | /** |
||
| 2496 | * Merge the current array into the new $array. |
||
| 2497 | * |
||
| 2498 | * - replace duplicate assoc-keys from new $array with the key,values from the current array |
||
| 2499 | * - create new indexes |
||
| 2500 | * |
||
| 2501 | * @param array $array |
||
| 2502 | * @param bool $recursive |
||
| 2503 | * |
||
| 2504 | * @return static <p>(Immutable)</p> |
||
| 2505 | */ |
||
| 2506 | 17 | View Code Duplication | public function mergePrependNewIndex(array $array = [], bool $recursive = false) |
| 2516 | |||
| 2517 | /** |
||
| 2518 | * Get the min value from an array. |
||
| 2519 | * |
||
| 2520 | * @return mixed |
||
| 2521 | */ |
||
| 2522 | 10 | View Code Duplication | public function min() |
| 2530 | |||
| 2531 | /** |
||
| 2532 | * Move an array element to a new index. |
||
| 2533 | * |
||
| 2534 | * cherry-picked from: http://stackoverflow.com/questions/12624153/move-an-array-element-to-a-new-index-in-php |
||
| 2535 | * |
||
| 2536 | * @param int|string $from |
||
| 2537 | * @param int|string $to |
||
| 2538 | * |
||
| 2539 | * @return static <p>(Immutable)</p> |
||
| 2540 | */ |
||
| 2541 | 1 | public function moveElement($from, $to) |
|
| 2568 | |||
| 2569 | /** |
||
| 2570 | * Convert a object into an array. |
||
| 2571 | * |
||
| 2572 | * @param object $object |
||
| 2573 | * |
||
| 2574 | * @return mixed |
||
| 2575 | */ |
||
| 2576 | 5 | protected static function objectToArray($object) |
|
| 2588 | |||
| 2589 | /** |
||
| 2590 | * Get a subset of the items from the given array. |
||
| 2591 | * |
||
| 2592 | * @param mixed[] $keys |
||
| 2593 | * |
||
| 2594 | * @return static <p>(Immutable)</p> |
||
| 2595 | */ |
||
| 2596 | public function only(array $keys) |
||
| 2602 | |||
| 2603 | /** |
||
| 2604 | * Pad array to the specified size with a given value. |
||
| 2605 | * |
||
| 2606 | * @param int $size <p>Size of the result array.</p> |
||
| 2607 | * @param mixed $value <p>Empty value by default.</p> |
||
| 2608 | * |
||
| 2609 | * @return static <p>(Immutable) Arrayy object padded to $size with $value.</p> |
||
| 2610 | */ |
||
| 2611 | 4 | public function pad(int $size, $value) |
|
| 2617 | |||
| 2618 | /** |
||
| 2619 | * Pop a specified value off the end of the current array. |
||
| 2620 | * |
||
| 2621 | * @return mixed <p>(Mutable) The popped element from the current array.</p> |
||
| 2622 | */ |
||
| 2623 | 16 | public function pop() |
|
| 2627 | |||
| 2628 | /** |
||
| 2629 | * Prepend a (key) + value to the current array. |
||
| 2630 | * |
||
| 2631 | * @param mixed $value |
||
| 2632 | * @param mixed $key |
||
| 2633 | * |
||
| 2634 | * @return static <p>(Mutable) Return this Arrayy object, with the prepended value.</p> |
||
| 2635 | */ |
||
| 2636 | 8 | public function prepend($value, $key = null) |
|
| 2647 | |||
| 2648 | /** |
||
| 2649 | * Add a suffix to each key. |
||
| 2650 | * |
||
| 2651 | * @param mixed $suffix |
||
| 2652 | * |
||
| 2653 | * @return static <p>(Immutable) Return an Arrayy object, with the prepended keys.</p> |
||
| 2654 | */ |
||
| 2655 | 10 | View Code Duplication | public function prependToEachKey($suffix) |
| 2671 | |||
| 2672 | /** |
||
| 2673 | * Add a suffix to each value. |
||
| 2674 | * |
||
| 2675 | * @param mixed $suffix |
||
| 2676 | * |
||
| 2677 | * @return static <p>(Immutable) Return an Arrayy object, with the prepended values.</p> |
||
| 2678 | */ |
||
| 2679 | 10 | View Code Duplication | public function prependToEachValue($suffix) |
| 2696 | |||
| 2697 | /** |
||
| 2698 | * Push one or more values onto the end of array at once. |
||
| 2699 | * |
||
| 2700 | * @return static <p>(Mutable) Return this Arrayy object, with pushed elements to the end of array.</p> |
||
| 2701 | */ |
||
| 2702 | 4 | View Code Duplication | public function push(/* variadic arguments allowed */) |
| 2711 | |||
| 2712 | /** |
||
| 2713 | * Get a random value from the current array. |
||
| 2714 | * |
||
| 2715 | * @param null|int $number <p>How many values you will take?</p> |
||
| 2716 | * |
||
| 2717 | * @return static <p>(Immutable)</p> |
||
| 2718 | */ |
||
| 2719 | 18 | public function randomImmutable(int $number = null) |
|
| 2736 | |||
| 2737 | /** |
||
| 2738 | * Pick a random key/index from the keys of this array. |
||
| 2739 | * |
||
| 2740 | * @return mixed <p>Get a key/index or null if there wasn't a key/index.</p> |
||
| 2741 | * |
||
| 2742 | * @throws \RangeException If array is empty |
||
| 2743 | */ |
||
| 2744 | 4 | public function randomKey() |
|
| 2754 | |||
| 2755 | /** |
||
| 2756 | * Pick a given number of random keys/indexes out of this array. |
||
| 2757 | * |
||
| 2758 | * @param int $number <p>The number of keys/indexes (should be <= \count($this->array))</p> |
||
| 2759 | * |
||
| 2760 | * @return static <p>(Immutable)</p> |
||
| 2761 | * |
||
| 2762 | * @throws \RangeException If array is empty |
||
| 2763 | */ |
||
| 2764 | 13 | public function randomKeys(int $number) |
|
| 2782 | |||
| 2783 | /** |
||
| 2784 | * Get a random value from the current array. |
||
| 2785 | * |
||
| 2786 | * @param null|int $number <p>How many values you will take?</p> |
||
| 2787 | * |
||
| 2788 | * @return static <p>(Mutable)</p> |
||
| 2789 | */ |
||
| 2790 | 17 | public function randomMutable(int $number = null) |
|
| 2807 | |||
| 2808 | /** |
||
| 2809 | * Pick a random value from the values of this array. |
||
| 2810 | * |
||
| 2811 | * @return mixed <p>Get a random value or null if there wasn't a value.</p> |
||
| 2812 | */ |
||
| 2813 | 4 | public function randomValue() |
|
| 2823 | |||
| 2824 | /** |
||
| 2825 | * Pick a given number of random values out of this array. |
||
| 2826 | * |
||
| 2827 | * @param int $number |
||
| 2828 | * |
||
| 2829 | * @return static <p>(Mutable)</p> |
||
| 2830 | */ |
||
| 2831 | 7 | public function randomValues(int $number) |
|
| 2835 | |||
| 2836 | /** |
||
| 2837 | * Get a random value from an array, with the ability to skew the results. |
||
| 2838 | * |
||
| 2839 | * Example: randomWeighted(['foo' => 1, 'bar' => 2]) has a 66% chance of returning bar. |
||
| 2840 | * |
||
| 2841 | * @param array $array |
||
| 2842 | * @param null|int $number <p>How many values you will take?</p> |
||
| 2843 | * |
||
| 2844 | * @return static <p>(Immutable)</p> |
||
| 2845 | */ |
||
| 2846 | 9 | public function randomWeighted(array $array, int $number = null) |
|
| 2859 | |||
| 2860 | /** |
||
| 2861 | * Reduce the current array via callable e.g. anonymous-function. |
||
| 2862 | * |
||
| 2863 | * @param \callable $callable |
||
| 2864 | * @param array $init |
||
| 2865 | * |
||
| 2866 | * @return static <p>(Immutable)</p> |
||
| 2867 | */ |
||
| 2868 | 4 | public function reduce($callable, array $init = []) |
|
| 2880 | |||
| 2881 | /** |
||
| 2882 | * Create a numerically re-indexed Arrayy object. |
||
| 2883 | * |
||
| 2884 | * @return static <p>(Mutable) Return this Arrayy object, with re-indexed array-elements.</p> |
||
| 2885 | */ |
||
| 2886 | 9 | public function reindex() |
|
| 2892 | |||
| 2893 | /** |
||
| 2894 | * Return all items that fail the truth test. |
||
| 2895 | * |
||
| 2896 | * @param \Closure $closure |
||
| 2897 | * |
||
| 2898 | * @return static <p>(Immutable)</p> |
||
| 2899 | */ |
||
| 2900 | 1 | View Code Duplication | public function reject(\Closure $closure) |
| 2912 | |||
| 2913 | /** |
||
| 2914 | * Remove a value from the current array (optional using dot-notation). |
||
| 2915 | * |
||
| 2916 | * @param mixed $key |
||
| 2917 | * |
||
| 2918 | * @return static <p>(Immutable)</p> |
||
| 2919 | */ |
||
| 2920 | 18 | public function remove($key) |
|
| 2935 | |||
| 2936 | /** |
||
| 2937 | * Remove the first value from the current array. |
||
| 2938 | * |
||
| 2939 | * @return static <p>(Immutable)</p> |
||
| 2940 | */ |
||
| 2941 | 7 | public function removeFirst() |
|
| 2948 | |||
| 2949 | /** |
||
| 2950 | * Remove the last value from the current array. |
||
| 2951 | * |
||
| 2952 | * @return static <p>(Immutable)</p> |
||
| 2953 | */ |
||
| 2954 | 7 | public function removeLast() |
|
| 2961 | |||
| 2962 | /** |
||
| 2963 | * Removes a particular value from an array (numeric or associative). |
||
| 2964 | * |
||
| 2965 | * @param mixed $value |
||
| 2966 | * |
||
| 2967 | * @return static <p>(Immutable)</p> |
||
| 2968 | */ |
||
| 2969 | 7 | public function removeValue($value) |
|
| 2987 | |||
| 2988 | /** |
||
| 2989 | * Generate array of repeated arrays. |
||
| 2990 | * |
||
| 2991 | * @param int $times <p>How many times has to be repeated.</p> |
||
| 2992 | * |
||
| 2993 | * @return Arrayy |
||
| 2994 | */ |
||
| 2995 | 1 | public function repeat($times): self |
|
| 3003 | |||
| 3004 | /** |
||
| 3005 | * Replace a key with a new key/value pair. |
||
| 3006 | * |
||
| 3007 | * @param mixed $replace |
||
| 3008 | * @param mixed $key |
||
| 3009 | * @param mixed $value |
||
| 3010 | * |
||
| 3011 | * @return static <p>(Immutable)</p> |
||
| 3012 | */ |
||
| 3013 | 2 | public function replace($replace, $key, $value) |
|
| 3019 | |||
| 3020 | /** |
||
| 3021 | * Create an array using the current array as values and the other array as keys. |
||
| 3022 | * |
||
| 3023 | * @param array $keys <p>An array of keys.</p> |
||
| 3024 | * |
||
| 3025 | * @return static <p>(Immutable) Arrayy object with keys from the other array.</p> |
||
| 3026 | */ |
||
| 3027 | 2 | public function replaceAllKeys(array $keys) |
|
| 3033 | |||
| 3034 | /** |
||
| 3035 | * Create an array using the current array as keys and the other array as values. |
||
| 3036 | * |
||
| 3037 | * @param array $array <p>An array o values.</p> |
||
| 3038 | * |
||
| 3039 | * @return static <p>(Immutable) Arrayy object with values from the other array.</p> |
||
| 3040 | */ |
||
| 3041 | 2 | public function replaceAllValues(array $array) |
|
| 3047 | |||
| 3048 | /** |
||
| 3049 | * Replace the keys in an array with another set. |
||
| 3050 | * |
||
| 3051 | * @param array $keys <p>An array of keys matching the array's size</p> |
||
| 3052 | * |
||
| 3053 | * @return static <p>(Immutable)</p> |
||
| 3054 | */ |
||
| 3055 | 1 | public function replaceKeys(array $keys) |
|
| 3062 | |||
| 3063 | /** |
||
| 3064 | * Replace the first matched value in an array. |
||
| 3065 | * |
||
| 3066 | * @param mixed $search <p>The value to replace.</p> |
||
| 3067 | * @param mixed $replacement <p>The value to replace.</p> |
||
| 3068 | * |
||
| 3069 | * @return static <p>(Immutable)</p> |
||
| 3070 | */ |
||
| 3071 | 3 | public function replaceOneValue($search, $replacement = '') |
|
| 3082 | |||
| 3083 | /** |
||
| 3084 | * Replace values in the current array. |
||
| 3085 | * |
||
| 3086 | * @param mixed $search <p>The value to replace.</p> |
||
| 3087 | * @param mixed $replacement <p>What to replace it with.</p> |
||
| 3088 | * |
||
| 3089 | * @return static <p>(Immutable)</p> |
||
| 3090 | */ |
||
| 3091 | 1 | public function replaceValues($search, $replacement = '') |
|
| 3101 | |||
| 3102 | /** |
||
| 3103 | * Get the last elements from index $from until the end of this array. |
||
| 3104 | * |
||
| 3105 | * @param int $from |
||
| 3106 | * |
||
| 3107 | * @return static <p>(Immutable)</p> |
||
| 3108 | */ |
||
| 3109 | 15 | public function rest(int $from = 1) |
|
| 3115 | |||
| 3116 | /** |
||
| 3117 | * Return the array in the reverse order. |
||
| 3118 | * |
||
| 3119 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
| 3120 | */ |
||
| 3121 | 8 | public function reverse() |
|
| 3127 | |||
| 3128 | /** |
||
| 3129 | * Sort an array in reverse order. |
||
| 3130 | * |
||
| 3131 | * @param int $sort_flags [optional] <p> |
||
| 3132 | * You may modify the behavior of the sort using the optional |
||
| 3133 | * parameter sort_flags, for details |
||
| 3134 | * see sort. |
||
| 3135 | * </p> |
||
| 3136 | * |
||
| 3137 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
| 3138 | */ |
||
| 3139 | 4 | public function rsort(int $sort_flags = 0) |
|
| 3145 | |||
| 3146 | /** |
||
| 3147 | * Search for the first index of the current array via $value. |
||
| 3148 | * |
||
| 3149 | * @param mixed $value |
||
| 3150 | * |
||
| 3151 | * @return int|float|string |
||
| 3152 | */ |
||
| 3153 | 20 | public function searchIndex($value) |
|
| 3157 | |||
| 3158 | /** |
||
| 3159 | * Search for the value of the current array via $index. |
||
| 3160 | * |
||
| 3161 | * @param mixed $index |
||
| 3162 | * |
||
| 3163 | * @return static <p>(Immutable) Will return a empty Arrayy if the value wasn't found.</p> |
||
| 3164 | */ |
||
| 3165 | 9 | public function searchValue($index) |
|
| 3186 | |||
| 3187 | /** |
||
| 3188 | * Set a value for the current array (optional using dot-notation). |
||
| 3189 | * |
||
| 3190 | * @param mixed $key <p>The key to set.</p> |
||
| 3191 | * @param mixed $value <p>Its value.</p> |
||
| 3192 | * |
||
| 3193 | * @return static <p>(Immutable)</p> |
||
| 3194 | */ |
||
| 3195 | 17 | public function set($key, $value) |
|
| 3201 | |||
| 3202 | /** |
||
| 3203 | * Get a value from a array and set it if it was not. |
||
| 3204 | * |
||
| 3205 | * WARNING: this method only set the value, if the $key is not already set |
||
| 3206 | * |
||
| 3207 | * @param mixed $key <p>The key</p> |
||
| 3208 | * @param mixed $fallback <p>The default value to set if it isn't.</p> |
||
| 3209 | * |
||
| 3210 | * @return mixed <p>(Mutable)</p> |
||
| 3211 | */ |
||
| 3212 | 11 | public function setAndGet($key, $fallback = null) |
|
| 3221 | |||
| 3222 | /** |
||
| 3223 | * Shifts a specified value off the beginning of array. |
||
| 3224 | * |
||
| 3225 | * @return mixed <p>(Mutable) A shifted element from the current array.</p> |
||
| 3226 | */ |
||
| 3227 | 4 | public function shift() |
|
| 3231 | |||
| 3232 | /** |
||
| 3233 | * Shuffle the current array. |
||
| 3234 | * |
||
| 3235 | * @param bool $secure <p>using a CSPRNG | @link https://paragonie.com/b/JvICXzh_jhLyt4y3</p> |
||
| 3236 | * @param array $array [optional] |
||
| 3237 | * |
||
| 3238 | * @return static <p>(Immutable)</p> |
||
| 3239 | */ |
||
| 3240 | 1 | public function shuffle(bool $secure = false, array $array = null) |
|
| 3277 | |||
| 3278 | /** |
||
| 3279 | * Count the values from the current array. |
||
| 3280 | * |
||
| 3281 | * alias: for "Arrayy->count()" |
||
| 3282 | * |
||
| 3283 | * @param int $mode |
||
| 3284 | * |
||
| 3285 | * @return int |
||
| 3286 | */ |
||
| 3287 | 20 | public function size(int $mode = COUNT_NORMAL): int |
|
| 3291 | |||
| 3292 | /** |
||
| 3293 | * Counts all elements in an array, or something in an object. |
||
| 3294 | * <p>For objects, if you have SPL installed, you can hook into count() by implementing interface {@see Countable}. |
||
| 3295 | * The interface has exactly one method, {@see Countable::count()}, which returns the return value for the count() |
||
| 3296 | * function. Please see the {@see Array} section of the manual for a detailed explanation of how arrays are |
||
| 3297 | * implemented and used in PHP. |
||
| 3298 | * |
||
| 3299 | * @return int the number of elements in var, which is |
||
| 3300 | * typically an array, since anything else will have one |
||
| 3301 | * element. |
||
| 3302 | * </p> |
||
| 3303 | * <p> |
||
| 3304 | * If var is not an array or an object with |
||
| 3305 | * implemented Countable interface, |
||
| 3306 | * 1 will be returned. |
||
| 3307 | * There is one exception, if var is &null;, |
||
| 3308 | * 0 will be returned. |
||
| 3309 | * </p> |
||
| 3310 | * <p> |
||
| 3311 | * Caution: count may return 0 for a variable that isn't set, |
||
| 3312 | * but it may also return 0 for a variable that has been initialized with an |
||
| 3313 | * empty array. Use isset to test if a variable is set. |
||
| 3314 | * |
||
| 3315 | * @return int |
||
| 3316 | */ |
||
| 3317 | 10 | public function sizeRecursive(): int |
|
| 3321 | |||
| 3322 | /** |
||
| 3323 | * Extract a slice of the array. |
||
| 3324 | * |
||
| 3325 | * @param int $offset <p>Slice begin index.</p> |
||
| 3326 | * @param int|null $length <p>Length of the slice.</p> |
||
| 3327 | * @param bool $preserveKeys <p>Whether array keys are preserved or no.</p> |
||
| 3328 | * |
||
| 3329 | * @return static <p>A slice of the original array with length $length.</p> |
||
| 3330 | */ |
||
| 3331 | 4 | public function slice(int $offset, int $length = null, bool $preserveKeys = false) |
|
| 3337 | |||
| 3338 | /** |
||
| 3339 | * Sort the current array and optional you can keep the keys. |
||
| 3340 | * |
||
| 3341 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 3342 | * @param int $strategy <p>sort_flags => use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 3343 | * <strong>SORT_NATURAL</strong></p> |
||
| 3344 | * @param bool $keepKeys |
||
| 3345 | * |
||
| 3346 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
| 3347 | */ |
||
| 3348 | 19 | public function sort($direction = SORT_ASC, int $strategy = SORT_REGULAR, bool $keepKeys = false) |
|
| 3354 | |||
| 3355 | /** |
||
| 3356 | * Sort the current array by key. |
||
| 3357 | * |
||
| 3358 | * @link http://php.net/manual/en/function.ksort.php |
||
| 3359 | * @link http://php.net/manual/en/function.krsort.php |
||
| 3360 | * |
||
| 3361 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 3362 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 3363 | * <strong>SORT_NATURAL</strong></p> |
||
| 3364 | * |
||
| 3365 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
| 3366 | */ |
||
| 3367 | 18 | public function sortKeys($direction = SORT_ASC, int $strategy = SORT_REGULAR) |
|
| 3373 | |||
| 3374 | /** |
||
| 3375 | * Sort the current array by value. |
||
| 3376 | * |
||
| 3377 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 3378 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 3379 | * <strong>SORT_NATURAL</strong></p> |
||
| 3380 | * |
||
| 3381 | * @return static <p>(Mutable)</p> |
||
| 3382 | */ |
||
| 3383 | 1 | public function sortValueKeepIndex($direction = SORT_ASC, int $strategy = SORT_REGULAR) |
|
| 3387 | |||
| 3388 | /** |
||
| 3389 | * Sort the current array by value. |
||
| 3390 | * |
||
| 3391 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 3392 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 3393 | * <strong>SORT_NATURAL</strong></p> |
||
| 3394 | * |
||
| 3395 | * @return static <p>(Mutable)</p> |
||
| 3396 | */ |
||
| 3397 | 1 | public function sortValueNewIndex($direction = SORT_ASC, int $strategy = SORT_REGULAR) |
|
| 3401 | |||
| 3402 | /** |
||
| 3403 | * Sort a array by value, by a closure or by a property. |
||
| 3404 | * |
||
| 3405 | * - If the sorter is null, the array is sorted naturally. |
||
| 3406 | * - Associative (string) keys will be maintained, but numeric keys will be re-indexed. |
||
| 3407 | * |
||
| 3408 | * @param \callable|null $sorter |
||
| 3409 | * @param string|int $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 3410 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 3411 | * <strong>SORT_NATURAL</strong></p> |
||
| 3412 | * |
||
| 3413 | * @return static <p>(Immutable)</p> |
||
| 3414 | */ |
||
| 3415 | 1 | public function sorter($sorter = null, $direction = SORT_ASC, int $strategy = SORT_REGULAR) |
|
| 3441 | |||
| 3442 | /** |
||
| 3443 | * sorting keys |
||
| 3444 | * |
||
| 3445 | * @param array $elements |
||
| 3446 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 3447 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 3448 | * <strong>SORT_NATURAL</strong></p> |
||
| 3449 | * |
||
| 3450 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
| 3451 | */ |
||
| 3452 | 18 | protected function sorterKeys(array &$elements, $direction = SORT_ASC, int $strategy = SORT_REGULAR) |
|
| 3469 | |||
| 3470 | /** |
||
| 3471 | * @param array &$elements |
||
| 3472 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 3473 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 3474 | * <strong>SORT_NATURAL</strong></p> |
||
| 3475 | * @param bool $keepKeys |
||
| 3476 | * |
||
| 3477 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
| 3478 | */ |
||
| 3479 | 19 | protected function sorting(array &$elements, $direction = SORT_ASC, int $strategy = SORT_REGULAR, bool $keepKeys = false) |
|
| 3508 | |||
| 3509 | /** |
||
| 3510 | * Split an array in the given amount of pieces. |
||
| 3511 | * |
||
| 3512 | * @param int $numberOfPieces |
||
| 3513 | * @param bool $keepKeys |
||
| 3514 | * |
||
| 3515 | * @return static <p>(Immutable)</p> |
||
| 3516 | */ |
||
| 3517 | 1 | public function split(int $numberOfPieces = 2, bool $keepKeys = false) |
|
| 3530 | |||
| 3531 | /** |
||
| 3532 | * Stripe all empty items. |
||
| 3533 | * |
||
| 3534 | * @return static <p>(Immutable)</p> |
||
| 3535 | */ |
||
| 3536 | 1 | public function stripEmpty() |
|
| 3548 | |||
| 3549 | /** |
||
| 3550 | * Swap two values between positions by key. |
||
| 3551 | * |
||
| 3552 | * @param string|int $swapA <p>a key in the array</p> |
||
| 3553 | * @param string|int $swapB <p>a key in the array</p> |
||
| 3554 | * |
||
| 3555 | * @return static <p>(Immutable)</p> |
||
| 3556 | */ |
||
| 3557 | 1 | public function swap($swapA, $swapB) |
|
| 3565 | |||
| 3566 | /** |
||
| 3567 | * alias: for "Arrayy->getArray()" |
||
| 3568 | * |
||
| 3569 | * @see Arrayy::getArray() |
||
| 3570 | */ |
||
| 3571 | 186 | public function toArray() |
|
| 3575 | |||
| 3576 | /** |
||
| 3577 | * Convert the current array to JSON. |
||
| 3578 | * |
||
| 3579 | * @param int $options [optional] <p>e.g. JSON_PRETTY_PRINT</p> |
||
| 3580 | * @param int $depth [optional] <p>Set the maximum depth. Must be greater than zero.</p> |
||
| 3581 | * |
||
| 3582 | * @return string |
||
| 3583 | */ |
||
| 3584 | 6 | public function toJson(int $options = 0, int $depth = 512): string |
|
| 3588 | |||
| 3589 | /** |
||
| 3590 | * Implodes array to a string with specified separator. |
||
| 3591 | * |
||
| 3592 | * @param string $separator [optional] <p>The element's separator.</p> |
||
| 3593 | * |
||
| 3594 | * @return string <p>The string representation of array, separated by ",".</p> |
||
| 3595 | */ |
||
| 3596 | 19 | public function toString(string $separator = ','): string |
|
| 3600 | |||
| 3601 | /** |
||
| 3602 | * Return a duplicate free copy of the current array. |
||
| 3603 | * |
||
| 3604 | * @return static <p>(Mutable)</p> |
||
| 3605 | */ |
||
| 3606 | 9 | public function unique() |
|
| 3630 | |||
| 3631 | /** |
||
| 3632 | * Return a duplicate free copy of the current array. (with the old keys) |
||
| 3633 | * |
||
| 3634 | * @return static <p>(Mutable)</p> |
||
| 3635 | */ |
||
| 3636 | 9 | public function uniqueKeepIndex() |
|
| 3663 | |||
| 3664 | /** |
||
| 3665 | * alias: for "Arrayy->unique()" |
||
| 3666 | * |
||
| 3667 | * @see Arrayy::unique() |
||
| 3668 | * |
||
| 3669 | * @return static <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
| 3670 | */ |
||
| 3671 | 9 | public function uniqueNewIndex() |
|
| 3675 | |||
| 3676 | /** |
||
| 3677 | * Prepends one or more values to the beginning of array at once. |
||
| 3678 | * |
||
| 3679 | * @return static <p>(Mutable) Return this Arrayy object, with prepended elements to the beginning of array.</p> |
||
| 3680 | */ |
||
| 3681 | 4 | View Code Duplication | public function unshift(/* variadic arguments allowed */) |
| 3690 | |||
| 3691 | /** |
||
| 3692 | * Get all values from a array. |
||
| 3693 | * |
||
| 3694 | * @return static <p>(Immutable)</p> |
||
| 3695 | */ |
||
| 3696 | 2 | public function values() |
|
| 3700 | |||
| 3701 | /** |
||
| 3702 | * Apply the given function to every element in the array, discarding the results. |
||
| 3703 | * |
||
| 3704 | * @param \callable $callable |
||
| 3705 | * @param bool $recursive <p>Whether array will be walked recursively or no</p> |
||
| 3706 | * |
||
| 3707 | * @return static <p>(Mutable) Return this Arrayy object, with modified elements.</p> |
||
| 3708 | */ |
||
| 3709 | 35 | public function walk($callable, bool $recursive = false) |
|
| 3719 | } |
||
| 3720 |
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: