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; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @var string |
||
| 31 | */ |
||
| 32 | protected $pathSeparator = '.'; |
||
| 33 | |||
| 34 | /** @noinspection MagicMethodsValidityInspection */ |
||
| 35 | /** |
||
| 36 | * Initializes |
||
| 37 | * |
||
| 38 | * @param array $array |
||
| 39 | * @param string $iteratorClass |
||
| 40 | 815 | */ |
|
| 41 | 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 | 2 | */ |
|
| 56 | public function &__get($key) |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Call object as function. |
||
| 69 | * |
||
| 70 | * @param mixed $key |
||
| 71 | * |
||
| 72 | * @return mixed |
||
| 73 | 1 | */ |
|
| 74 | 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 | 2 | */ |
|
| 105 | public function __set($key, $value) |
||
| 109 | |||
| 110 | /** |
||
| 111 | * magic to string |
||
| 112 | * |
||
| 113 | * @return string |
||
| 114 | 16 | */ |
|
| 115 | 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 | 1 | */ |
|
| 139 | 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 | 9 | */ |
|
| 152 | 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 | 4 | */ |
|
| 174 | public function asort(int $sort_flags = 0) |
||
| 180 | |||
| 181 | /** |
||
| 182 | * Count the values from the current array. |
||
| 183 | * |
||
| 184 | * alias: for "Arrayy->size()" |
||
| 185 | * |
||
| 186 | * @see Arrayy::size() |
||
| 187 | * |
||
| 188 | * @param int $mode |
||
| 189 | 93 | * |
|
| 190 | * @return int |
||
| 191 | 93 | */ |
|
| 192 | public function count(int $mode = COUNT_NORMAL): int |
||
| 196 | |||
| 197 | /** |
||
| 198 | * Exchange the array for another one. |
||
| 199 | * |
||
| 200 | * @param array|static $data |
||
| 201 | 1 | * |
|
| 202 | * @return array |
||
| 203 | 1 | */ |
|
| 204 | public function exchangeArray($data): array |
||
| 210 | |||
| 211 | /** |
||
| 212 | * Creates a copy of the ArrayyObject. |
||
| 213 | 1 | * |
|
| 214 | * @return array |
||
| 215 | 1 | */ |
|
| 216 | public function getArrayCopy(): array |
||
| 220 | |||
| 221 | /** |
||
| 222 | * Returns a new ArrayyIterator, thus implementing the IteratorAggregate interface. |
||
| 223 | 20 | * |
|
| 224 | * @return ArrayyIterator <p>An iterator for the values in the array.</p> |
||
| 225 | 20 | */ |
|
| 226 | public function getIterator(): ArrayyIterator |
||
| 232 | |||
| 233 | /** |
||
| 234 | * Gets the iterator classname for the ArrayObject. |
||
| 235 | 20 | * |
|
| 236 | * @return string |
||
| 237 | 20 | */ |
|
| 238 | public function getIteratorClass(): string |
||
| 242 | |||
| 243 | /** |
||
| 244 | * Sort the entries by key |
||
| 245 | * |
||
| 246 | * @param int $sort_flags [optional] <p> |
||
| 247 | * You may modify the behavior of the sort using the optional |
||
| 248 | * parameter sort_flags, for details |
||
| 249 | * see sort. |
||
| 250 | * </p> |
||
| 251 | 4 | * |
|
| 252 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
| 253 | 4 | */ |
|
| 254 | public function ksort(int $sort_flags = 0) |
||
| 260 | |||
| 261 | /** |
||
| 262 | * Sort an array using a case insensitive "natural order" algorithm |
||
| 263 | * |
||
| 264 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
| 265 | */ |
||
| 266 | public function natcasesort() |
||
| 272 | |||
| 273 | /** |
||
| 274 | * Sort entries using a "natural order" algorithm |
||
| 275 | 1 | * |
|
| 276 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
| 277 | 1 | */ |
|
| 278 | public function natsort() |
||
| 284 | |||
| 285 | /** |
||
| 286 | * Whether or not an offset exists. |
||
| 287 | * |
||
| 288 | * @param int|float|string $offset |
||
| 289 | 40 | * |
|
| 290 | * @return bool |
||
| 291 | 40 | */ |
|
| 292 | 4 | public function offsetExists($offset): bool |
|
| 336 | |||
| 337 | /** |
||
| 338 | * Returns the value at specified offset. |
||
| 339 | * |
||
| 340 | * @param int|float|string $offset |
||
| 341 | 26 | * |
|
| 342 | * @return mixed <p>Will return null if the offset did not exists.</p> |
||
| 343 | 26 | */ |
|
| 344 | public function offsetGet($offset) |
||
| 348 | |||
| 349 | /** |
||
| 350 | * Assigns a value to the specified offset. |
||
| 351 | * |
||
| 352 | 17 | * @param int|float|string $offset |
|
| 353 | * @param mixed $value |
||
| 354 | 17 | */ |
|
| 355 | 4 | public function offsetSet($offset, $value) |
|
| 363 | |||
| 364 | /** |
||
| 365 | * Unset an offset. |
||
| 366 | 7 | * |
|
| 367 | * @param int|float|string $offset |
||
| 368 | 7 | */ |
|
| 369 | 1 | public function offsetUnset($offset) |
|
| 395 | |||
| 396 | /** |
||
| 397 | * Serialize the current "Arrayy"-object. |
||
| 398 | 1 | * |
|
| 399 | * @return string |
||
| 400 | 1 | */ |
|
| 401 | public function serialize() |
||
| 405 | |||
| 406 | /** |
||
| 407 | * Sets the iterator classname for the current "Arrayy"-object. |
||
| 408 | * |
||
| 409 | * @param string $class |
||
| 410 | * |
||
| 411 | * @return void |
||
| 412 | 813 | * |
|
| 413 | * @throws \InvalidArgumentException |
||
| 414 | 813 | */ |
|
| 415 | 813 | public function setIteratorClass($class) |
|
| 434 | |||
| 435 | /** |
||
| 436 | * Sort the entries with a user-defined comparison function and maintain key association. |
||
| 437 | * |
||
| 438 | * @param \callable $function |
||
| 439 | * |
||
| 440 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
| 441 | * |
||
| 442 | * @throws \InvalidArgumentException |
||
| 443 | */ |
||
| 444 | View Code Duplication | public function uasort($function) |
|
| 456 | |||
| 457 | /** |
||
| 458 | * Sort the entries by keys using a user-defined comparison function. |
||
| 459 | * |
||
| 460 | * @param \callable $function |
||
| 461 | * |
||
| 462 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
| 463 | 5 | * |
|
| 464 | * @throws \InvalidArgumentException |
||
| 465 | 5 | */ |
|
| 466 | public function uksort($function) |
||
| 470 | |||
| 471 | /** |
||
| 472 | * Unserialize an string and return this object. |
||
| 473 | * |
||
| 474 | * @param string $string |
||
| 475 | 1 | * |
|
| 476 | * @return static <p>(Mutable)</p> |
||
| 477 | 1 | */ |
|
| 478 | public function unserialize($string) |
||
| 484 | |||
| 485 | /** |
||
| 486 | * Add a suffix to each key. |
||
| 487 | * |
||
| 488 | * @param mixed $prefix |
||
| 489 | 10 | * |
|
| 490 | * @return static <p>(Immutable) Return an Arrayy object, with the prefixed keys.</p> |
||
| 491 | 10 | */ |
|
| 492 | 10 | View Code Duplication | public function appendToEachKey($prefix) |
| 507 | |||
| 508 | /** |
||
| 509 | * Add a prefix to each value. |
||
| 510 | * |
||
| 511 | * @param mixed $prefix |
||
| 512 | 10 | * |
|
| 513 | * @return static <p>(Immutable) Return an Arrayy object, with the prefixed values.</p> |
||
| 514 | 10 | */ |
|
| 515 | 10 | View Code Duplication | public function appendToEachValue($prefix) |
| 532 | |||
| 533 | /** |
||
| 534 | * Convert an array into a object. |
||
| 535 | * |
||
| 536 | * @param array $array PHP array |
||
| 537 | 4 | * |
|
| 538 | * @return \stdClass (object) |
||
| 539 | 4 | */ |
|
| 540 | protected static function arrayToObject(array $array = []): \stdClass |
||
| 558 | |||
| 559 | /** |
||
| 560 | * Sort an array in reverse order and maintain index association. |
||
| 561 | 4 | * |
|
| 562 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
| 563 | 4 | */ |
|
| 564 | public function arsort() |
||
| 570 | |||
| 571 | /** |
||
| 572 | * Iterate over the current array and execute a callback for each loop. |
||
| 573 | * |
||
| 574 | * @param \Closure $closure |
||
| 575 | 2 | * |
|
| 576 | * @return static <p>(Immutable)</p> |
||
| 577 | 2 | */ |
|
| 578 | View Code Duplication | public function at(\Closure $closure) |
|
| 588 | |||
| 589 | /** |
||
| 590 | * Returns the average value of the current array. |
||
| 591 | * |
||
| 592 | * @param int $decimals <p>The number of decimal-numbers to return.</p> |
||
| 593 | 10 | * |
|
| 594 | * @return int|double <p>The average value.</p> |
||
| 595 | 10 | */ |
|
| 596 | public function average($decimals = 0) |
||
| 610 | |||
| 611 | /** |
||
| 612 | * @param mixed $path |
||
| 613 | 4 | * @param \callable $callable |
|
| 614 | * @param null|array $currentOffset |
||
| 615 | 4 | */ |
|
| 616 | 4 | protected function callAtPath($path, $callable, &$currentOffset = null) |
|
| 639 | |||
| 640 | /** |
||
| 641 | * Changes all keys in an array. |
||
| 642 | * |
||
| 643 | * @param int $case [optional] <p> Either <strong>CASE_UPPER</strong><br /> |
||
| 644 | * or <strong>CASE_LOWER</strong> (default)</p> |
||
| 645 | 1 | * |
|
| 646 | * @return static <p>(Immutable)</p> |
||
| 647 | 1 | */ |
|
| 648 | public function changeKeyCase(int $case = CASE_LOWER) |
||
| 652 | |||
| 653 | /** |
||
| 654 | * Change the path separator of the array wrapper. |
||
| 655 | * |
||
| 656 | * By default, the separator is: "." |
||
| 657 | * |
||
| 658 | * @param string $separator <p>Separator to set.</p> |
||
| 659 | 1 | * |
|
| 660 | * @return static <p>Mutable</p> |
||
| 661 | 1 | */ |
|
| 662 | public function changeSeparator($separator) |
||
| 668 | |||
| 669 | /** |
||
| 670 | * Create a chunked version of the current array. |
||
| 671 | * |
||
| 672 | * @param int $size <p>Size of each chunk.</p> |
||
| 673 | * @param bool $preserveKeys <p>Whether array keys are preserved or no.</p> |
||
| 674 | 4 | * |
|
| 675 | * @return static <p>(Immutable) A new array of chunks from the original array.</p> |
||
| 676 | 4 | */ |
|
| 677 | public function chunk($size, $preserveKeys = false) |
||
| 683 | |||
| 684 | /** |
||
| 685 | * Clean all falsy values from the current array. |
||
| 686 | 8 | * |
|
| 687 | * @return static <p>(Immutable)</p> |
||
| 688 | 8 | */ |
|
| 689 | public function clean() |
||
| 697 | |||
| 698 | /** |
||
| 699 | * WARNING!!! -> Clear the current array. |
||
| 700 | 4 | * |
|
| 701 | * @return static <p>(Mutable) Return this Arrayy object, with an empty array.</p> |
||
| 702 | 4 | */ |
|
| 703 | public function clear() |
||
| 709 | |||
| 710 | /** |
||
| 711 | * Check if an item is in the current array. |
||
| 712 | * |
||
| 713 | * @param string|int|float $value |
||
| 714 | 13 | * @param bool $recursive |
|
| 715 | * @param bool $strict |
||
| 716 | 13 | * |
|
| 717 | * @return bool |
||
| 718 | */ |
||
| 719 | public function contains($value, $recursive = false, $strict = true): bool |
||
| 727 | |||
| 728 | 13 | /** |
|
| 729 | 13 | * @param mixed $needle <p> |
|
| 730 | 13 | * The searched value. |
|
| 731 | * </p> |
||
| 732 | 13 | * <p> |
|
| 733 | 13 | * If needle is a string, the comparison is done |
|
| 734 | 13 | * in a case-sensitive manner. |
|
| 735 | 13 | * </p> |
|
| 736 | 13 | * @param array $haystack <p> |
|
| 737 | * The array. |
||
| 738 | 13 | * </p> |
|
| 739 | * @param bool $strict [optional] <p> |
||
| 740 | * If the third parameter strict is set to true |
||
| 741 | * then the in_array function will also check the |
||
| 742 | * types of the |
||
| 743 | * needle in the haystack. |
||
| 744 | * </p> |
||
| 745 | * |
||
| 746 | * @return bool true if needle is found in the array, false otherwise. |
||
| 747 | */ |
||
| 748 | 4 | protected function in_array_recursive($needle, array $haystack = null, $strict = true): bool |
|
| 769 | |||
| 770 | /** |
||
| 771 | * Check if an (case-insensitive) string is in the current array. |
||
| 772 | * |
||
| 773 | * @param string $value |
||
| 774 | 9 | * @param bool $recursive |
|
| 775 | * |
||
| 776 | 9 | * @return bool |
|
| 777 | */ |
||
| 778 | public function containsCaseInsensitive($value, $recursive = false): bool |
||
| 804 | 1 | ||
| 805 | /** |
||
| 806 | * Check if the given key/index exists in the array. |
||
| 807 | * |
||
| 808 | * @param string|int|float $key <p>key/index to search for</p> |
||
| 809 | * |
||
| 810 | * @return bool <p>Returns true if the given key/index exists in the array, false otherwise.</p> |
||
| 811 | */ |
||
| 812 | public function containsKey($key): bool |
||
| 816 | 522 | ||
| 817 | /** |
||
| 818 | * Check if all given needles are present in the array as key/index. |
||
| 819 | * |
||
| 820 | * @param array $needles <p>The keys you are searching for.</p> |
||
| 821 | * @param bool $recursive |
||
| 822 | * |
||
| 823 | * @return bool <p>Returns true if all the given keys/indexes exists in the array, false otherwise.</p> |
||
| 824 | */ |
||
| 825 | public function containsKeys(array $needles, $recursive = false): bool |
||
| 833 | |||
| 834 | /** |
||
| 835 | * Check if all given needles are present in the array as key/index. |
||
| 836 | * |
||
| 837 | * @param array $needles <p>The keys you are searching for.</p> |
||
| 838 | * |
||
| 839 | * @return bool <p>Returns true if all the given keys/indexes exists in the array, false otherwise.</p> |
||
| 840 | */ |
||
| 841 | public function containsKeysRecursive(array $needles): bool |
||
| 845 | |||
| 846 | 5 | /** |
|
| 847 | * alias: for "Arrayy->contains()" |
||
| 848 | * |
||
| 849 | * @see Arrayy::contains() |
||
| 850 | * |
||
| 851 | * @param string|int|float $value |
||
| 852 | * |
||
| 853 | * @return bool |
||
| 854 | */ |
||
| 855 | public function containsValue($value): bool |
||
| 859 | 4 | ||
| 860 | /** |
||
| 861 | 3 | * alias: for "Arrayy->contains($value, true)" |
|
| 862 | 4 | * |
|
| 863 | * @see Arrayy::contains() |
||
| 864 | 4 | * |
|
| 865 | * @param string|int|float $value |
||
| 866 | * |
||
| 867 | * @return bool |
||
| 868 | */ |
||
| 869 | public function containsValueRecursive($value): bool |
||
| 873 | |||
| 874 | 5 | /** |
|
| 875 | * Check if all given needles are present in the array. |
||
| 876 | 5 | * |
|
| 877 | * @param array $needles |
||
| 878 | * |
||
| 879 | * @return bool <p>Returns true if all the given values exists in the array, false otherwise.</p> |
||
| 880 | */ |
||
| 881 | public function containsValues(array $needles): bool |
||
| 885 | |||
| 886 | /** |
||
| 887 | * Counts all the values of an array |
||
| 888 | * |
||
| 889 | 8 | * @link http://php.net/manual/en/function.array-count-values.php |
|
| 890 | * |
||
| 891 | 8 | * @return static <p> |
|
| 892 | 1 | * (Immutable) |
|
| 893 | * An associative Arrayy-object of values from input as |
||
| 894 | 1 | * keys and their count as value. |
|
| 895 | 1 | * </p> |
|
| 896 | 1 | */ |
|
| 897 | public function countValues() |
||
| 901 | |||
| 902 | /** |
||
| 903 | 8 | * Creates an Arrayy object. |
|
| 904 | * |
||
| 905 | * @param array $array |
||
| 906 | * |
||
| 907 | 8 | * @return static <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
|
| 908 | 8 | */ |
|
| 909 | 8 | public static function create($array = []) |
|
| 913 | 8 | ||
| 914 | /** |
||
| 915 | * WARNING: Creates an Arrayy object by reference. |
||
| 916 | * |
||
| 917 | * @param array $array |
||
| 918 | * |
||
| 919 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
| 920 | */ |
||
| 921 | public function createByReference(&$array = []) |
||
| 929 | |||
| 930 | /** |
||
| 931 | * Create an new Arrayy object via JSON. |
||
| 932 | * |
||
| 933 | * @param string $json |
||
| 934 | * |
||
| 935 | * @return static <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 936 | */ |
||
| 937 | public static function createFromJson(string $json) |
||
| 943 | 5 | ||
| 944 | /** |
||
| 945 | * Create an new instance filled with values from an object that have implemented ArrayAccess. |
||
| 946 | * |
||
| 947 | * @param \ArrayAccess $object <p>Object that implements ArrayAccess</p> |
||
| 948 | * |
||
| 949 | 5 | * @return static <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
|
| 950 | */ |
||
| 951 | 5 | public static function createFromObject(\ArrayAccess $object) |
|
| 961 | |||
| 962 | /** |
||
| 963 | * Create an new instance filled with values from an object. |
||
| 964 | * |
||
| 965 | 5 | * @param object $object |
|
| 966 | * |
||
| 967 | 5 | * @return static <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
|
| 968 | */ |
||
| 969 | public static function createFromObjectVars($object) |
||
| 973 | 5 | ||
| 974 | /** |
||
| 975 | 5 | * Create an new Arrayy object via string. |
|
| 976 | * |
||
| 977 | * @param string $str <p>The input string.</p> |
||
| 978 | * @param string|null $delimiter <p>The boundary string.</p> |
||
| 979 | * @param string|null $regEx <p>Use the $delimiter or the $regEx, so if $pattern is null, $delimiter will be |
||
| 980 | * used.</p> |
||
| 981 | * |
||
| 982 | * @return static <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 983 | */ |
||
| 984 | public static function createFromString(string $str, string $delimiter = null, string $regEx = null) |
||
| 1010 | 1 | ||
| 1011 | 1 | /** |
|
| 1012 | * Create an new instance containing a range of elements. |
||
| 1013 | * |
||
| 1014 | 1 | * @param mixed $low <p>First value of the sequence.</p> |
|
| 1015 | 1 | * @param mixed $high <p>The sequence is ended upon reaching the end value.</p> |
|
| 1016 | 1 | * @param int $step <p>Used as the increment between elements in the sequence.</p> |
|
| 1017 | 1 | * |
|
| 1018 | 1 | * @return static <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
|
| 1019 | 1 | */ |
|
| 1020 | 1 | public static function createWithRange($low, $high, int $step = 1) |
|
| 1024 | 1 | ||
| 1025 | /** |
||
| 1026 | 1 | * Custom sort by index via "uksort". |
|
| 1027 | 1 | * |
|
| 1028 | * @link http://php.net/manual/en/function.uksort.php |
||
| 1029 | 1 | * |
|
| 1030 | * @param \callable $function |
||
| 1031 | 1 | * |
|
| 1032 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
| 1033 | * |
||
| 1034 | * @throws \InvalidArgumentException |
||
| 1035 | */ |
||
| 1036 | View Code Duplication | public function customSortKeys($function) |
|
| 1048 | |||
| 1049 | /** |
||
| 1050 | * Custom sort by value via "usort". |
||
| 1051 | * |
||
| 1052 | * @link http://php.net/manual/en/function.usort.php |
||
| 1053 | 1 | * |
|
| 1054 | * @param \callable $function |
||
| 1055 | 1 | * |
|
| 1056 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
| 1057 | 1 | * |
|
| 1058 | 1 | * @throws \InvalidArgumentException |
|
| 1059 | */ |
||
| 1060 | 1 | View Code Duplication | public function customSortValues($function) |
| 1072 | 4 | ||
| 1073 | /** |
||
| 1074 | 4 | * Return values that are only in the current array. |
|
| 1075 | 4 | * |
|
| 1076 | 4 | * @param array $array |
|
| 1077 | * |
||
| 1078 | 4 | * @return static <p>(Immutable)</p> |
|
| 1079 | */ |
||
| 1080 | public function diff(array $array = []) |
||
| 1086 | |||
| 1087 | /** |
||
| 1088 | 4 | * Return values that are only in the current multi-dimensional array. |
|
| 1089 | * |
||
| 1090 | 4 | * @param array $array |
|
| 1091 | 4 | * @param null|array $helperVariableForRecursion <p>(only for internal usage)</p> |
|
| 1092 | 3 | * |
|
| 1093 | 1 | * @return static <p>(Immutable)</p> |
|
| 1094 | 1 | */ |
|
| 1095 | public function diffRecursive(array $array = [], $helperVariableForRecursion = null) |
||
| 1128 | 10 | ||
| 1129 | 6 | /** |
|
| 1130 | * Return values that are only in the new $array. |
||
| 1131 | * |
||
| 1132 | 9 | * @param array $array |
|
| 1133 | * |
||
| 1134 | 9 | * @return static <p>(Immutable)</p> |
|
| 1135 | */ |
||
| 1136 | public function diffReverse(array $array = []) |
||
| 1142 | |||
| 1143 | 9 | /** |
|
| 1144 | * Divide an array into two arrays. One with keys and the other with values. |
||
| 1145 | * |
||
| 1146 | * @return static <p>(Immutable)</p> |
||
| 1147 | */ |
||
| 1148 | public function divide() |
||
| 1157 | |||
| 1158 | 2 | /** |
|
| 1159 | * Iterate over the current array and modify the array's value. |
||
| 1160 | * |
||
| 1161 | * @param \Closure $closure |
||
| 1162 | * |
||
| 1163 | * @return static <p>(Immutable)</p> |
||
| 1164 | */ |
||
| 1165 | View Code Duplication | public function each(\Closure $closure) |
|
| 1175 | |||
| 1176 | /** |
||
| 1177 | * Check if a value is in the current array using a closure. |
||
| 1178 | * |
||
| 1179 | * @param \Closure $closure |
||
| 1180 | * |
||
| 1181 | * @return bool <p>Returns true if the given value is found, false otherwise.</p> |
||
| 1182 | */ |
||
| 1183 | public function exists(\Closure $closure): bool |
||
| 1195 | 9 | ||
| 1196 | /** |
||
| 1197 | * create a fallback for array |
||
| 1198 | * |
||
| 1199 | 9 | * 1. use the current array, if it's a array |
|
| 1200 | * 2. call "getArray()" on object, if there is a "Arrayy"-object |
||
| 1201 | 9 | * 3. fallback to empty array, if there is nothing |
|
| 1202 | * 4. call "createFromObject()" on object, if there is a "\ArrayAccess"-object |
||
| 1203 | * 5. call "__toArray()" on object, if the method exists |
||
| 1204 | * 6. cast a string or object with "__toString()" into an array |
||
| 1205 | * 7. throw a "InvalidArgumentException"-Exception |
||
| 1206 | * |
||
| 1207 | * @param $array |
||
| 1208 | * |
||
| 1209 | * @return array |
||
| 1210 | * |
||
| 1211 | 1 | * @throws \InvalidArgumentException |
|
| 1212 | */ |
||
| 1213 | 1 | protected function fallbackForArray(&$array): array |
|
| 1255 | 1 | ||
| 1256 | 1 | /** |
|
| 1257 | 1 | * Find all items in an array that pass the truth test. |
|
| 1258 | * |
||
| 1259 | * @param \Closure|null $closure [optional] <p> |
||
| 1260 | * The callback function to use |
||
| 1261 | 1 | * </p> |
|
| 1262 | 1 | * <p> |
|
| 1263 | * If no callback is supplied, all entries of |
||
| 1264 | * input equal to false (see |
||
| 1265 | 1 | * converting to |
|
| 1266 | * boolean) will be removed. |
||
| 1267 | * </p> |
||
| 1268 | 1 | * |
|
| 1269 | * * @param int $flag [optional] <p> |
||
| 1270 | * Flag determining what arguments are sent to <i>callback</i>: |
||
| 1271 | 1 | * </p><ul> |
|
| 1272 | * <li> |
||
| 1273 | 1 | * <b>ARRAY_FILTER_USE_KEY</b> [1] - pass key as the only argument |
|
| 1274 | 1 | * to <i>callback</i> instead of the value</span> |
|
| 1275 | * </li> |
||
| 1276 | * <li> |
||
| 1277 | 1 | * <b>ARRAY_FILTER_USE_BOTH</b> [2] - pass both value and key as |
|
| 1278 | * arguments to <i>callback</i> instead of the value</span> |
||
| 1279 | * </li> |
||
| 1280 | 1 | * </ul> |
|
| 1281 | * |
||
| 1282 | * @return static <p>(Immutable)</p> |
||
| 1283 | 1 | */ |
|
| 1284 | public function filter($closure = null, int $flag = 0) |
||
| 1294 | |||
| 1295 | 1 | /** |
|
| 1296 | 1 | * Filters an array of objects (or a numeric array of associative arrays) based on the value of a particular property |
|
| 1297 | * within that. |
||
| 1298 | 1 | * |
|
| 1299 | 1 | * @param string $property |
|
| 1300 | 1 | * @param string|string[] $value |
|
| 1301 | * @param string $comparisonOp |
||
| 1302 | 1 | * <p> |
|
| 1303 | 1 | * 'eq' (equals),<br /> |
|
| 1304 | 1 | * 'gt' (greater),<br /> |
|
| 1305 | 1 | * 'gte' || 'ge' (greater or equals),<br /> |
|
| 1306 | * 'lt' (less),<br /> |
||
| 1307 | 1 | * 'lte' || 'le' (less or equals),<br /> |
|
| 1308 | 1 | * 'ne' (not equals),<br /> |
|
| 1309 | 1 | * 'contains',<br /> |
|
| 1310 | * 'notContains',<br /> |
||
| 1311 | 1 | * 'newer' (via strtotime),<br /> |
|
| 1312 | * 'older' (via strtotime),<br /> |
||
| 1313 | 1 | * </p> |
|
| 1314 | 1 | * |
|
| 1315 | * @return static <p>(Immutable)</p> |
||
| 1316 | 1 | */ |
|
| 1317 | public function filterBy(string $property, $value, string $comparisonOp = null) |
||
| 1382 | 21 | ||
| 1383 | 21 | /** |
|
| 1384 | 21 | * Find the first item in an array that passes the truth test, |
|
| 1385 | * otherwise return false |
||
| 1386 | * |
||
| 1387 | 28 | * @param \Closure $closure |
|
| 1388 | * |
||
| 1389 | * @return mixed|false <p>Return false if we did not find the value.</p> |
||
| 1390 | */ |
||
| 1391 | public function find(\Closure $closure) |
||
| 1401 | 11 | ||
| 1402 | 15 | /** |
|
| 1403 | 15 | * find by ... |
|
| 1404 | * |
||
| 1405 | * @param string $property |
||
| 1406 | 26 | * @param string|string[] $value |
|
| 1407 | * @param string $comparisonOp |
||
| 1408 | * |
||
| 1409 | * @return static <p>(Immutable)</p> |
||
| 1410 | */ |
||
| 1411 | public function findBy(string $property, $value, string $comparisonOp = 'eq') |
||
| 1415 | |||
| 1416 | 1 | /** |
|
| 1417 | * Get the first value from the current array. |
||
| 1418 | 1 | * |
|
| 1419 | * @return mixed <p>Return null if there wasn't a element.</p> |
||
| 1420 | */ |
||
| 1421 | public function first() |
||
| 1432 | |||
| 1433 | /** |
||
| 1434 | * Get the first value(s) from the current array. |
||
| 1435 | 61 | * |
|
| 1436 | 3 | * @param int|null $number <p>How many values you will take?</p> |
|
| 1437 | 61 | * |
|
| 1438 | 3 | * @return static <p>(Immutable)</p> |
|
| 1439 | 3 | */ |
|
| 1440 | 59 | public function firstsImmutable(int $number = null) |
|
| 1453 | 51 | ||
| 1454 | 6 | /** |
|
| 1455 | * Get the first value(s) from the current array. |
||
| 1456 | * |
||
| 1457 | 47 | * @param int|null $number <p>How many values you will take?</p> |
|
| 1458 | * |
||
| 1459 | * @return static <p>(Mutable)</p> |
||
| 1460 | */ |
||
| 1461 | 20 | public function firstsMutable(int $number = null) |
|
| 1472 | |||
| 1473 | 5 | /** |
|
| 1474 | * Exchanges all keys with their associated values in an array. |
||
| 1475 | * |
||
| 1476 | * @return static <p>(Immutable)</p> |
||
| 1477 | */ |
||
| 1478 | public function flip() |
||
| 1484 | |||
| 1485 | 536 | /** |
|
| 1486 | * Get a value from an array (optional using dot-notation). |
||
| 1487 | * |
||
| 1488 | * @param mixed $key <p>The key to look for.</p> |
||
| 1489 | * @param mixed $fallback <p>Value to fallback to.</p> |
||
| 1490 | * @param array $array <p>The array to get from, if it's set to "null" we use the current array from the |
||
| 1491 | * class.</p> |
||
| 1492 | * |
||
| 1493 | * @return mixed |
||
| 1494 | */ |
||
| 1495 | public function get($key, $fallback = null, array $array = null) |
||
| 1535 | |||
| 1536 | /** |
||
| 1537 | * Get the current array from the "Arrayy"-object. |
||
| 1538 | * |
||
| 1539 | * @return array |
||
| 1540 | */ |
||
| 1541 | public function getArray(): array |
||
| 1547 | |||
| 1548 | /** |
||
| 1549 | * Returns the values from a single column of the input array, identified by |
||
| 1550 | * the $columnKey, can be used to extract data-columns from multi-arrays. |
||
| 1551 | * |
||
| 1552 | * Info: Optionally, you may provide an $indexKey to index the values in the returned |
||
| 1553 | * array by the values from the $indexKey column in the input array. |
||
| 1554 | 4 | * |
|
| 1555 | * @param mixed $columnKey |
||
| 1556 | 4 | * @param mixed $indexKey |
|
| 1557 | * |
||
| 1558 | * @return static <p>(Immutable)</p> |
||
| 1559 | */ |
||
| 1560 | public function getColumn($columnKey = null, $indexKey = null) |
||
| 1566 | 3 | ||
| 1567 | /** |
||
| 1568 | 3 | * Get correct PHP constant for direction. |
|
| 1569 | * |
||
| 1570 | * @param int|string $direction |
||
| 1571 | * |
||
| 1572 | * @return int |
||
| 1573 | */ |
||
| 1574 | protected function getDirection($direction): int |
||
| 1596 | |||
| 1597 | /** |
||
| 1598 | * alias: for "Arrayy->keys()" |
||
| 1599 | * |
||
| 1600 | * @see Arrayy::keys() |
||
| 1601 | * |
||
| 1602 | * @return static <p>(Immutable)</p> |
||
| 1603 | */ |
||
| 1604 | 3 | public function getKeys() |
|
| 1608 | |||
| 1609 | /** |
||
| 1610 | * Get the current array from the "Arrayy"-object as object. |
||
| 1611 | * |
||
| 1612 | * @return \stdClass (object) |
||
| 1613 | */ |
||
| 1614 | public function getObject(): \stdClass |
||
| 1618 | 6 | ||
| 1619 | /** |
||
| 1620 | 6 | * alias: for "Arrayy->randomImmutable()" |
|
| 1621 | * |
||
| 1622 | * @see Arrayy::randomImmutable() |
||
| 1623 | * |
||
| 1624 | * @return static <p>(Immutable)</p> |
||
| 1625 | */ |
||
| 1626 | public function getRandom() |
||
| 1630 | |||
| 1631 | 3 | /** |
|
| 1632 | * alias: for "Arrayy->randomKey()" |
||
| 1633 | 3 | * |
|
| 1634 | 3 | * @see Arrayy::randomKey() |
|
| 1635 | * |
||
| 1636 | * @return mixed <p>Get a key/index or null if there wasn't a key/index.</p> |
||
| 1637 | 3 | */ |
|
| 1638 | public function getRandomKey() |
||
| 1642 | 3 | ||
| 1643 | /** |
||
| 1644 | * alias: for "Arrayy->randomKeys()" |
||
| 1645 | * |
||
| 1646 | 3 | * @see Arrayy::randomKeys() |
|
| 1647 | 3 | * |
|
| 1648 | 3 | * @param int $number |
|
| 1649 | * |
||
| 1650 | * @return static <p>(Immutable)</p> |
||
| 1651 | 3 | */ |
|
| 1652 | 2 | public function getRandomKeys(int $number) |
|
| 1656 | 1 | ||
| 1657 | 1 | /** |
|
| 1658 | * alias: for "Arrayy->randomValue()" |
||
| 1659 | 2 | * |
|
| 1660 | * @see Arrayy::randomValue() |
||
| 1661 | 3 | * |
|
| 1662 | * @return mixed <p>get a random value or null if there wasn't a value.</p> |
||
| 1663 | 3 | */ |
|
| 1664 | public function getRandomValue() |
||
| 1668 | |||
| 1669 | /** |
||
| 1670 | * alias: for "Arrayy->randomValues()" |
||
| 1671 | * |
||
| 1672 | * @see Arrayy::randomValues() |
||
| 1673 | 22 | * |
|
| 1674 | * @param int $number |
||
| 1675 | * |
||
| 1676 | 22 | * @return static <p>(Immutable)</p> |
|
| 1677 | */ |
||
| 1678 | 22 | public function getRandomValues(int $number) |
|
| 1682 | |||
| 1683 | /** |
||
| 1684 | * Group values from a array according to the results of a closure. |
||
| 1685 | * |
||
| 1686 | * @param \callable $grouper <p>A callable function name.</p> |
||
| 1687 | * @param bool $saveKeys |
||
| 1688 | 28 | * |
|
| 1689 | * @return static <p>(Immutable)</p> |
||
| 1690 | 28 | */ |
|
| 1691 | public function group($grouper, bool $saveKeys = false) |
||
| 1725 | |||
| 1726 | /** |
||
| 1727 | * Check if an array has a given key. |
||
| 1728 | 3 | * |
|
| 1729 | * @param mixed $key |
||
| 1730 | 3 | * |
|
| 1731 | * @return bool |
||
| 1732 | 3 | */ |
|
| 1733 | 3 | public function has($key): bool |
|
| 1740 | |||
| 1741 | /** |
||
| 1742 | * Implodes the keys of this array. |
||
| 1743 | * |
||
| 1744 | * @param string $glue |
||
| 1745 | * |
||
| 1746 | * @return string |
||
| 1747 | */ |
||
| 1748 | public function implodeKeys(string $glue = ''): string |
||
| 1752 | 4 | ||
| 1753 | /** |
||
| 1754 | * Implodes the values of this array. |
||
| 1755 | * |
||
| 1756 | * @param string $glue |
||
| 1757 | * |
||
| 1758 | * @return string |
||
| 1759 | */ |
||
| 1760 | public function implode(string $glue = ''): string |
||
| 1764 | 12 | ||
| 1765 | /** |
||
| 1766 | 12 | * @param mixed $glue |
|
| 1767 | * @param string|array|static $pieces |
||
| 1768 | * @param bool $useKeys |
||
| 1769 | * |
||
| 1770 | * @return string |
||
| 1771 | */ |
||
| 1772 | 446 | protected function implode_recursive($glue = '', $pieces, bool $useKeys = false): string |
|
| 1794 | |||
| 1795 | /** |
||
| 1796 | * Given a list and an iterate-function that returns |
||
| 1797 | 18 | * a key for each element in the list (or a property name), |
|
| 1798 | * returns an object with an index of each item. |
||
| 1799 | 18 | * |
|
| 1800 | * Just like groupBy, but for when you know your keys are unique. |
||
| 1801 | * |
||
| 1802 | 18 | * @param mixed $key |
|
| 1803 | * |
||
| 1804 | * @return static <p>(Immutable)</p> |
||
| 1805 | */ |
||
| 1806 | public function indexBy($key) |
||
| 1818 | |||
| 1819 | /** |
||
| 1820 | * alias: for "Arrayy->searchIndex()" |
||
| 1821 | * |
||
| 1822 | * @see Arrayy::searchIndex() |
||
| 1823 | * |
||
| 1824 | * @param mixed $value <p>The value to search for.</p> |
||
| 1825 | * |
||
| 1826 | * @return mixed |
||
| 1827 | 30 | */ |
|
| 1828 | public function indexOf($value) |
||
| 1832 | |||
| 1833 | /** |
||
| 1834 | 30 | * Get everything but the last..$to items. |
|
| 1835 | 30 | * |
|
| 1836 | * @param int $to |
||
| 1837 | * |
||
| 1838 | 30 | * @return static <p>(Immutable)</p> |
|
| 1839 | 3 | */ |
|
| 1840 | public function initial(int $to = 1) |
||
| 1846 | |||
| 1847 | /** |
||
| 1848 | 3 | * @param mixed $value |
|
| 1849 | 3 | */ |
|
| 1850 | protected function internalGetArray(&$value) |
||
| 1867 | |||
| 1868 | /** |
||
| 1869 | * Internal mechanics of remove method. |
||
| 1870 | * |
||
| 1871 | * @param mixed $key |
||
| 1872 | * |
||
| 1873 | * @return bool |
||
| 1874 | */ |
||
| 1875 | 1 | protected function internalRemove($key): bool |
|
| 1896 | 1 | ||
| 1897 | 1 | /** |
|
| 1898 | 1 | * Internal mechanic of set method. |
|
| 1899 | 1 | * |
|
| 1900 | * @param mixed $key |
||
| 1901 | * @param mixed $value |
||
| 1902 | 1 | * |
|
| 1903 | * @return bool |
||
| 1904 | */ |
||
| 1905 | protected function internalSet($key, $value): bool |
||
| 1933 | |||
| 1934 | /** |
||
| 1935 | * Return an array with all elements found in input array. |
||
| 1936 | * |
||
| 1937 | * @param array $search |
||
| 1938 | * |
||
| 1939 | * @return static <p>(Immutable)</p> |
||
| 1940 | */ |
||
| 1941 | public function intersection(array $search) |
||
| 1945 | |||
| 1946 | /** |
||
| 1947 | * Return a boolean flag which indicates whether the two input arrays have any common elements. |
||
| 1948 | * |
||
| 1949 | * @param array $search |
||
| 1950 | * |
||
| 1951 | * @return bool |
||
| 1952 | 14 | */ |
|
| 1953 | public function intersects(array $search): bool |
||
| 1957 | |||
| 1958 | /** |
||
| 1959 | * Invoke a function on all of an array's values. |
||
| 1960 | * |
||
| 1961 | * @param mixed $callable |
||
| 1962 | 5 | * @param mixed $arguments |
|
| 1963 | * |
||
| 1964 | 5 | * @return static <p>(Immutable)</p> |
|
| 1965 | 2 | */ |
|
| 1966 | public function invoke($callable, $arguments = []) |
||
| 1982 | 1 | ||
| 1983 | /** |
||
| 1984 | 1 | * Check whether array is associative or not. |
|
| 1985 | * |
||
| 1986 | * @param bool $recursive |
||
| 1987 | * |
||
| 1988 | * @return bool <p>Returns true if associative, false otherwise.</p> |
||
| 1989 | */ |
||
| 1990 | public function isAssoc(bool $recursive = false): bool |
||
| 2004 | |||
| 2005 | /** |
||
| 2006 | * Check whether the array is empty or not. |
||
| 2007 | * |
||
| 2008 | * @return bool <p>Returns true if empty, false otherwise.</p> |
||
| 2009 | */ |
||
| 2010 | public function isEmpty(): bool |
||
| 2014 | |||
| 2015 | /** |
||
| 2016 | 4 | * Check if the current array is equal to the given "$array" or not. |
|
| 2017 | * |
||
| 2018 | 4 | * @param array $array |
|
| 2019 | * |
||
| 2020 | 4 | * @return bool |
|
| 2021 | */ |
||
| 2022 | public function isEqual(array $array): bool |
||
| 2026 | |||
| 2027 | /** |
||
| 2028 | 4 | * Check if the current array is a multi-array. |
|
| 2029 | * |
||
| 2030 | 4 | * @return bool |
|
| 2031 | */ |
||
| 2032 | public function isMultiArray(): bool |
||
| 2036 | |||
| 2037 | /** |
||
| 2038 | * Check whether array is numeric or not. |
||
| 2039 | * |
||
| 2040 | 13 | * @return bool <p>Returns true if numeric, false otherwise.</p> |
|
| 2041 | */ |
||
| 2042 | 13 | public function isNumeric(): bool |
|
| 2056 | 8 | ||
| 2057 | 4 | /** |
|
| 2058 | 4 | * Check if the current array is sequential [0, 1, 2, 3, 4, 5 ...] or not. |
|
| 2059 | * |
||
| 2060 | * @param bool $recursive |
||
| 2061 | 12 | * |
|
| 2062 | * @return bool |
||
| 2063 | */ |
||
| 2064 | public function isSequential(bool $recursive = false): bool |
||
| 2072 | |||
| 2073 | 13 | /** |
|
| 2074 | 1 | * @return array |
|
| 2075 | */ |
||
| 2076 | public function jsonSerialize(): array |
||
| 2080 | 8 | ||
| 2081 | 1 | /** |
|
| 2082 | 1 | * Get all keys from the current array. |
|
| 2083 | 7 | * |
|
| 2084 | * @param bool $recursive [optional] <p> |
||
| 2085 | * Get all keys, also from all sub-arrays from an multi-dimensional array. |
||
| 2086 | 8 | * </p> |
|
| 2087 | 8 | * @param mixed $search_value [optional] <p> |
|
| 2088 | 4 | * If specified, then only keys containing these values are returned. |
|
| 2089 | 4 | * </p> |
|
| 2090 | * @param bool $strict [optional] <p> |
||
| 2091 | * Determines if strict comparison (===) should be used during the search. |
||
| 2092 | 12 | * </p> |
|
| 2093 | * |
||
| 2094 | * @return static <p>(Immutable) An array of all the keys in input.</p> |
||
| 2095 | */ |
||
| 2096 | public function keys(bool $recursive = false, $search_value = null, bool $strict = true) |
||
| 2114 | |||
| 2115 | /** |
||
| 2116 | * @param array $input <p> |
||
| 2117 | 4 | * An array containing keys to return. |
|
| 2118 | * </p> |
||
| 2119 | 4 | * @param mixed $search_value [optional] <p> |
|
| 2120 | * If specified, then only keys containing these values are returned. |
||
| 2121 | 4 | * </p> |
|
| 2122 | * @param bool $strict [optional] <p> |
||
| 2123 | * Determines if strict comparison (===) should be used during the search. |
||
| 2124 | * </p> |
||
| 2125 | * |
||
| 2126 | * @return array an array of all the keys in input. |
||
| 2127 | */ |
||
| 2128 | protected function array_keys_recursive(array $input = null, $search_value = null, bool $strict = true): array |
||
| 2159 | |||
| 2160 | 14 | /** |
|
| 2161 | 2 | * Sort an array by key in reverse order. |
|
| 2162 | * |
||
| 2163 | * @param int $sort_flags [optional] <p> |
||
| 2164 | * You may modify the behavior of the sort using the optional |
||
| 2165 | 12 | * parameter sort_flags, for details |
|
| 2166 | * see sort. |
||
| 2167 | 12 | * </p> |
|
| 2168 | 12 | * |
|
| 2169 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
| 2170 | 12 | */ |
|
| 2171 | 9 | public function krsort(int $sort_flags = 0) |
|
| 2177 | |||
| 2178 | /** |
||
| 2179 | * Get the last value from the current array. |
||
| 2180 | * |
||
| 2181 | * @return mixed <p>Return null if there wasn't a element.</p> |
||
| 2182 | */ |
||
| 2183 | 10 | public function last() |
|
| 2187 | |||
| 2188 | /** |
||
| 2189 | 9 | * Get the last value(s) from the current array. |
|
| 2190 | * |
||
| 2191 | * @param int|null $number |
||
| 2192 | * |
||
| 2193 | * @return static <p>(Immutable)</p> |
||
| 2194 | */ |
||
| 2195 | public function lastsImmutable(int $number = null) |
||
| 2218 | |||
| 2219 | /** |
||
| 2220 | * Get the last value(s) from the current array. |
||
| 2221 | * |
||
| 2222 | * @param int|null $number |
||
| 2223 | * |
||
| 2224 | 16 | * @return static <p>(Mutable)</p> |
|
| 2225 | */ |
||
| 2226 | 16 | public function lastsMutable(int $number = null) |
|
| 2249 | 4 | ||
| 2250 | 12 | /** |
|
| 2251 | * Count the values from the current array. |
||
| 2252 | * |
||
| 2253 | 16 | * alias: for "Arrayy->size()" |
|
| 2254 | * |
||
| 2255 | * @see Arrayy::size() |
||
| 2256 | * |
||
| 2257 | * @param int $mode |
||
| 2258 | * |
||
| 2259 | * @return int |
||
| 2260 | */ |
||
| 2261 | public function length(int $mode = COUNT_NORMAL): int |
||
| 2265 | |||
| 2266 | /** |
||
| 2267 | 17 | * Apply the given function to the every element of the array, |
|
| 2268 | * collecting the results. |
||
| 2269 | 17 | * |
|
| 2270 | 4 | * @param \callable $callable |
|
| 2271 | 4 | * |
|
| 2272 | 13 | * @return static <p>(Immutable) Arrayy object with modified elements.</p> |
|
| 2273 | */ |
||
| 2274 | public function map($callable) |
||
| 2280 | |||
| 2281 | /** |
||
| 2282 | * Check if all items in current array match a truth test. |
||
| 2283 | 10 | * |
|
| 2284 | * @param \Closure $closure |
||
| 2285 | 10 | * |
|
| 2286 | 1 | * @return bool |
|
| 2287 | */ |
||
| 2288 | View Code Duplication | public function matches(\Closure $closure): bool |
|
| 2307 | 1 | ||
| 2308 | 1 | /** |
|
| 2309 | 1 | * Check if any item in the current array matches a truth test. |
|
| 2310 | 1 | * |
|
| 2311 | 1 | * @param \Closure $closure |
|
| 2312 | 1 | * |
|
| 2313 | 1 | * @return bool |
|
| 2314 | 1 | */ |
|
| 2315 | 1 | View Code Duplication | public function matchesAny(\Closure $closure): bool |
| 2334 | |||
| 2335 | /** |
||
| 2336 | * Get the max value from an array. |
||
| 2337 | 5 | * |
|
| 2338 | * @return mixed |
||
| 2339 | 5 | */ |
|
| 2340 | 4 | public function max() |
|
| 2348 | |||
| 2349 | /** |
||
| 2350 | * Merge the new $array into the current array. |
||
| 2351 | * |
||
| 2352 | * - keep key,value from the current array, also if the index is in the new $array |
||
| 2353 | * |
||
| 2354 | * @param array $array |
||
| 2355 | * @param bool $recursive |
||
| 2356 | * |
||
| 2357 | * @return static <p>(Immutable)</p> |
||
| 2358 | */ |
||
| 2359 | View Code Duplication | public function mergeAppendKeepIndex(array $array = [], bool $recursive = false) |
|
| 2369 | |||
| 2370 | /** |
||
| 2371 | * Merge the new $array into the current array. |
||
| 2372 | 4 | * |
|
| 2373 | * - replace duplicate assoc-keys from the current array with the key,values from the new $array |
||
| 2374 | 4 | * - create new indexes |
|
| 2375 | * |
||
| 2376 | 4 | * @param array $array |
|
| 2377 | * @param bool $recursive |
||
| 2378 | * |
||
| 2379 | * @return static <p>(Immutable)</p> |
||
| 2380 | */ |
||
| 2381 | View Code Duplication | public function mergeAppendNewIndex(array $array = [], bool $recursive = false) |
|
| 2391 | |||
| 2392 | /** |
||
| 2393 | * Merge the the current array into the $array. |
||
| 2394 | * |
||
| 2395 | * - use key,value from the new $array, also if the index is in the current array |
||
| 2396 | * |
||
| 2397 | 8 | * @param array $array |
|
| 2398 | * @param bool $recursive |
||
| 2399 | 8 | * |
|
| 2400 | 8 | * @return static <p>(Immutable)</p> |
|
| 2401 | 8 | */ |
|
| 2402 | View Code Duplication | public function mergePrependKeepIndex(array $array = [], bool $recursive = false) |
|
| 2412 | |||
| 2413 | /** |
||
| 2414 | * Merge the current array into the new $array. |
||
| 2415 | * |
||
| 2416 | 10 | * - replace duplicate assoc-keys from new $array with the key,values from the current array |
|
| 2417 | * - create new indexes |
||
| 2418 | 10 | * |
|
| 2419 | 10 | * @param array $array |
|
| 2420 | 9 | * @param bool $recursive |
|
| 2421 | * |
||
| 2422 | 9 | * @return static <p>(Immutable)</p> |
|
| 2423 | */ |
||
| 2424 | View Code Duplication | public function mergePrependNewIndex(array $array = [], bool $recursive = false) |
|
| 2434 | |||
| 2435 | /** |
||
| 2436 | * Get the min value from an array. |
||
| 2437 | * |
||
| 2438 | * @return mixed |
||
| 2439 | */ |
||
| 2440 | 10 | public function min() |
|
| 2448 | 9 | ||
| 2449 | 1 | /** |
|
| 2450 | 1 | * Move an array element to a new index. |
|
| 2451 | 8 | * |
|
| 2452 | * cherry-picked from: http://stackoverflow.com/questions/12624153/move-an-array-element-to-a-new-index-in-php |
||
| 2453 | 10 | * |
|
| 2454 | * @param int|string $from |
||
| 2455 | 10 | * @param int|string $to |
|
| 2456 | * |
||
| 2457 | * @return static <p>(Immutable)</p> |
||
| 2458 | */ |
||
| 2459 | public function moveElement($from, $to) |
||
| 2486 | 17 | ||
| 2487 | 14 | /** |
|
| 2488 | * Convert a object into an array. |
||
| 2489 | 14 | * |
|
| 2490 | * @param object $object |
||
| 2491 | * |
||
| 2492 | 5 | * @return mixed |
|
| 2493 | 5 | */ |
|
| 2494 | protected static function objectToArray($object) |
||
| 2506 | |||
| 2507 | 4 | /** |
|
| 2508 | * Get a subset of the items from the given array. |
||
| 2509 | 4 | * |
|
| 2510 | * @param mixed[] $keys |
||
| 2511 | * |
||
| 2512 | * @return static <p>(Immutable)</p> |
||
| 2513 | 4 | */ |
|
| 2514 | public function only(array $keys) |
||
| 2520 | |||
| 2521 | /** |
||
| 2522 | * Pad array to the specified size with a given value. |
||
| 2523 | * |
||
| 2524 | * @param int $size <p>Size of the result array.</p> |
||
| 2525 | 14 | * @param mixed $value <p>Empty value by default.</p> |
|
| 2526 | * |
||
| 2527 | 14 | * @return static <p>(Immutable) Arrayy object padded to $size with $value.</p> |
|
| 2528 | 14 | */ |
|
| 2529 | public function pad(int $size, $value) |
||
| 2535 | |||
| 2536 | 3 | /** |
|
| 2537 | 3 | * Pop a specified value off the end of the current array. |
|
| 2538 | * |
||
| 2539 | * @return mixed <p>(Mutable) The popped element from the current array.</p> |
||
| 2540 | 11 | */ |
|
| 2541 | public function pop() |
||
| 2545 | |||
| 2546 | /** |
||
| 2547 | * Prepend a (key) + value to the current array. |
||
| 2548 | * |
||
| 2549 | * @param mixed $value |
||
| 2550 | * @param mixed $key |
||
| 2551 | * |
||
| 2552 | 17 | * @return static <p>(Mutable) Return this Arrayy object, with the prepended value.</p> |
|
| 2553 | */ |
||
| 2554 | 17 | public function prepend($value, $key = null) |
|
| 2565 | 11 | ||
| 2566 | /** |
||
| 2567 | 11 | * Add a suffix to each key. |
|
| 2568 | * |
||
| 2569 | * @param mixed $suffix |
||
| 2570 | * |
||
| 2571 | * @return static <p>(Immutable) Return an Arrayy object, with the prepended keys.</p> |
||
| 2572 | */ |
||
| 2573 | View Code Duplication | public function prependToEachKey($suffix) |
|
| 2589 | |||
| 2590 | /** |
||
| 2591 | * Add a suffix to each value. |
||
| 2592 | * |
||
| 2593 | 7 | * @param mixed $suffix |
|
| 2594 | * |
||
| 2595 | 7 | * @return static <p>(Immutable) Return an Arrayy object, with the prepended values.</p> |
|
| 2596 | */ |
||
| 2597 | 7 | View Code Duplication | public function prependToEachValue($suffix) |
| 2614 | 9 | ||
| 2615 | 2 | /** |
|
| 2616 | 1 | * Push one or more values onto the end of array at once. |
|
| 2617 | 1 | * |
|
| 2618 | 2 | * @return static <p>(Mutable) Return this Arrayy object, with pushed elements to the end of array.</p> |
|
| 2619 | 9 | */ |
|
| 2620 | View Code Duplication | public function push(/* variadic arguments allowed */) |
|
| 2629 | |||
| 2630 | /** |
||
| 2631 | * Get a random value from the current array. |
||
| 2632 | 4 | * |
|
| 2633 | * @param null|int $number <p>How many values you will take?</p> |
||
| 2634 | 4 | * |
|
| 2635 | * @return static <p>(Immutable)</p> |
||
| 2636 | 4 | */ |
|
| 2637 | public function randomImmutable(int $number = null) |
||
| 2654 | 9 | ||
| 2655 | /** |
||
| 2656 | * Pick a random key/index from the keys of this array. |
||
| 2657 | * |
||
| 2658 | * @return mixed <p>Get a key/index or null if there wasn't a key/index.</p> |
||
| 2659 | * |
||
| 2660 | * @throws \RangeException If array is empty |
||
| 2661 | */ |
||
| 2662 | public function randomKey() |
||
| 2672 | 1 | ||
| 2673 | /** |
||
| 2674 | 1 | * Pick a given number of random keys/indexes out of this array. |
|
| 2675 | * |
||
| 2676 | * @param int $number <p>The number of keys/indexes (should be <= $this->count())</p> |
||
| 2677 | * |
||
| 2678 | * @return static <p>(Immutable)</p> |
||
| 2679 | * |
||
| 2680 | * @throws \RangeException If array is empty |
||
| 2681 | */ |
||
| 2682 | public function randomKeys(int $number) |
||
| 2700 | |||
| 2701 | /** |
||
| 2702 | * Get a random value from the current array. |
||
| 2703 | * |
||
| 2704 | * @param null|int $number <p>How many values you will take?</p> |
||
| 2705 | 7 | * |
|
| 2706 | * @return static <p>(Mutable)</p> |
||
| 2707 | 7 | */ |
|
| 2708 | 7 | public function randomMutable(int $number = null) |
|
| 2725 | |||
| 2726 | /** |
||
| 2727 | * Pick a random value from the values of this array. |
||
| 2728 | * |
||
| 2729 | * @return mixed <p>Get a random value or null if there wasn't a value.</p> |
||
| 2730 | */ |
||
| 2731 | public function randomValue() |
||
| 2741 | 6 | ||
| 2742 | 6 | /** |
|
| 2743 | 7 | * Pick a given number of random values out of this array. |
|
| 2744 | * |
||
| 2745 | 7 | * @param int $number |
|
| 2746 | 7 | * |
|
| 2747 | 7 | * @return static <p>(Mutable)</p> |
|
| 2748 | */ |
||
| 2749 | 7 | public function randomValues(int $number) |
|
| 2753 | |||
| 2754 | /** |
||
| 2755 | * Get a random value from an array, with the ability to skew the results. |
||
| 2756 | * |
||
| 2757 | * Example: randomWeighted(['foo' => 1, 'bar' => 2]) has a 66% chance of returning bar. |
||
| 2758 | * |
||
| 2759 | 1 | * @param array $array |
|
| 2760 | * @param null|int $number <p>How many values you will take?</p> |
||
| 2761 | 1 | * |
|
| 2762 | 1 | * @return static <p>(Immutable)</p> |
|
| 2763 | */ |
||
| 2764 | public function randomWeighted(array $array, int $number = null) |
||
| 2777 | 2 | ||
| 2778 | /** |
||
| 2779 | 2 | * Reduce the current array via callable e.g. anonymous-function. |
|
| 2780 | * |
||
| 2781 | 2 | * @param \callable $callable |
|
| 2782 | * @param array $init |
||
| 2783 | * |
||
| 2784 | * @return static <p>(Immutable)</p> |
||
| 2785 | */ |
||
| 2786 | public function reduce($callable, array $init = []) |
||
| 2798 | |||
| 2799 | /** |
||
| 2800 | * Create a numerically re-indexed Arrayy object. |
||
| 2801 | * |
||
| 2802 | * @return static <p>(Mutable) Return this Arrayy object, with re-indexed array-elements.</p> |
||
| 2803 | */ |
||
| 2804 | public function reindex() |
||
| 2810 | |||
| 2811 | /** |
||
| 2812 | * Return all items that fail the truth test. |
||
| 2813 | * |
||
| 2814 | * @param \Closure $closure |
||
| 2815 | * |
||
| 2816 | * @return static <p>(Immutable)</p> |
||
| 2817 | */ |
||
| 2818 | View Code Duplication | public function reject(\Closure $closure) |
|
| 2830 | |||
| 2831 | /** |
||
| 2832 | * Remove a value from the current array (optional using dot-notation). |
||
| 2833 | * |
||
| 2834 | * @param mixed $key |
||
| 2835 | 3 | * |
|
| 2836 | * @return static <p>(Immutable)</p> |
||
| 2837 | 3 | */ |
|
| 2838 | 3 | public function remove($key) |
|
| 2853 | |||
| 2854 | /** |
||
| 2855 | 1 | * Remove the first value from the current array. |
|
| 2856 | * |
||
| 2857 | 1 | * @return static <p>(Immutable)</p> |
|
| 2858 | */ |
||
| 2859 | 1 | public function removeFirst() |
|
| 2866 | |||
| 2867 | /** |
||
| 2868 | * Remove the last value from the current array. |
||
| 2869 | * |
||
| 2870 | * @return static <p>(Immutable)</p> |
||
| 2871 | */ |
||
| 2872 | public function removeLast() |
||
| 2879 | |||
| 2880 | /** |
||
| 2881 | * Removes a particular value from an array (numeric or associative). |
||
| 2882 | * |
||
| 2883 | * @param mixed $value |
||
| 2884 | * |
||
| 2885 | 8 | * @return static <p>(Immutable)</p> |
|
| 2886 | */ |
||
| 2887 | 8 | public function removeValue($value) |
|
| 2905 | 4 | ||
| 2906 | /** |
||
| 2907 | 4 | * Generate array of repeated arrays. |
|
| 2908 | * |
||
| 2909 | * @param int $times <p>How many times has to be repeated.</p> |
||
| 2910 | * |
||
| 2911 | * @return Arrayy |
||
| 2912 | */ |
||
| 2913 | public function repeat($times): Arrayy |
||
| 2921 | |||
| 2922 | /** |
||
| 2923 | * Replace a key with a new key/value pair. |
||
| 2924 | * |
||
| 2925 | * @param mixed $replace |
||
| 2926 | * @param mixed $key |
||
| 2927 | * @param mixed $value |
||
| 2928 | * |
||
| 2929 | 9 | * @return static <p>(Immutable)</p> |
|
| 2930 | */ |
||
| 2931 | public function replace($replace, $key, $value) |
||
| 2937 | |||
| 2938 | /** |
||
| 2939 | 9 | * Create an array using the current array as values and the other array as keys. |
|
| 2940 | 1 | * |
|
| 2941 | 1 | * @param array $keys <p>An array of keys.</p> |
|
| 2942 | * |
||
| 2943 | 9 | * @return static <p>(Immutable) Arrayy object with keys from the other array.</p> |
|
| 2944 | 7 | */ |
|
| 2945 | 7 | public function replaceAllKeys(array $keys) |
|
| 2951 | |||
| 2952 | /** |
||
| 2953 | * Create an array using the current array as keys and the other array as values. |
||
| 2954 | * |
||
| 2955 | * @param array $array <p>An array o values.</p> |
||
| 2956 | * |
||
| 2957 | * @return static <p>(Immutable) Arrayy object with values from the other array.</p> |
||
| 2958 | */ |
||
| 2959 | 17 | public function replaceAllValues(array $array) |
|
| 2965 | |||
| 2966 | /** |
||
| 2967 | * Replace the keys in an array with another set. |
||
| 2968 | * |
||
| 2969 | * @param array $keys <p>An array of keys matching the array's size</p> |
||
| 2970 | * |
||
| 2971 | * @return static <p>(Immutable)</p> |
||
| 2972 | */ |
||
| 2973 | public function replaceKeys(array $keys) |
||
| 2980 | 4 | ||
| 2981 | 4 | /** |
|
| 2982 | * Replace the first matched value in an array. |
||
| 2983 | 11 | * |
|
| 2984 | * @param mixed $search <p>The value to replace.</p> |
||
| 2985 | * @param mixed $replacement <p>The value to replace.</p> |
||
| 2986 | * |
||
| 2987 | * @return static <p>(Immutable)</p> |
||
| 2988 | */ |
||
| 2989 | public function replaceOneValue($search, $replacement = '') |
||
| 3000 | |||
| 3001 | /** |
||
| 3002 | * Replace values in the current array. |
||
| 3003 | 1 | * |
|
| 3004 | * @param mixed $search <p>The value to replace.</p> |
||
| 3005 | 1 | * @param mixed $replacement <p>What to replace it with.</p> |
|
| 3006 | * |
||
| 3007 | 1 | * @return static <p>(Immutable)</p> |
|
| 3008 | 1 | */ |
|
| 3009 | 1 | public function replaceValues($search, $replacement = '') |
|
| 3019 | 1 | ||
| 3020 | /** |
||
| 3021 | * Get the last elements from index $from until the end of this array. |
||
| 3022 | 1 | * |
|
| 3023 | * @param int $from |
||
| 3024 | * |
||
| 3025 | 1 | * @return static <p>(Immutable)</p> |
|
| 3026 | */ |
||
| 3027 | public function rest(int $from = 1) |
||
| 3033 | 93 | ||
| 3034 | /** |
||
| 3035 | 93 | * Return the array in the reverse order. |
|
| 3036 | * |
||
| 3037 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
| 3038 | */ |
||
| 3039 | public function reverse() |
||
| 3045 | |||
| 3046 | /** |
||
| 3047 | 4 | * Sort an array in reverse order. |
|
| 3048 | * |
||
| 3049 | 4 | * @param int $sort_flags [optional] <p> |
|
| 3050 | * You may modify the behavior of the sort using the optional |
||
| 3051 | 4 | * parameter sort_flags, for details |
|
| 3052 | * see sort. |
||
| 3053 | * </p> |
||
| 3054 | * |
||
| 3055 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
| 3056 | */ |
||
| 3057 | public function rsort(int $sort_flags = 0) |
||
| 3063 | |||
| 3064 | 19 | /** |
|
| 3065 | * Search for the first index of the current array via $value. |
||
| 3066 | 19 | * |
|
| 3067 | * @param mixed $value |
||
| 3068 | 19 | * |
|
| 3069 | * @return int|float|string |
||
| 3070 | */ |
||
| 3071 | public function searchIndex($value) |
||
| 3075 | |||
| 3076 | /** |
||
| 3077 | * Search for the value of the current array via $index. |
||
| 3078 | * |
||
| 3079 | * @param mixed $index |
||
| 3080 | * |
||
| 3081 | * @return static <p>(Immutable) Will return a empty Arrayy if the value wasn't found.</p> |
||
| 3082 | */ |
||
| 3083 | 18 | public function searchValue($index) |
|
| 3104 | |||
| 3105 | /** |
||
| 3106 | * Set a value for the current array (optional using dot-notation). |
||
| 3107 | * |
||
| 3108 | * @param mixed $key <p>The key to set.</p> |
||
| 3109 | * @param mixed $value <p>Its value.</p> |
||
| 3110 | * |
||
| 3111 | 1 | * @return static <p>(Immutable)</p> |
|
| 3112 | */ |
||
| 3113 | 1 | public function set($key, $value) |
|
| 3119 | |||
| 3120 | /** |
||
| 3121 | * Get a value from a array and set it if it was not. |
||
| 3122 | * |
||
| 3123 | * WARNING: this method only set the value, if the $key is not already set |
||
| 3124 | * |
||
| 3125 | * @param mixed $key <p>The key</p> |
||
| 3126 | * @param mixed $fallback <p>The default value to set if it isn't.</p> |
||
| 3127 | * |
||
| 3128 | * @return mixed <p>(Mutable)</p> |
||
| 3129 | 1 | */ |
|
| 3130 | public function setAndGet($key, $fallback = null) |
||
| 3139 | 1 | ||
| 3140 | /** |
||
| 3141 | 1 | * Shifts a specified value off the beginning of array. |
|
| 3142 | * |
||
| 3143 | 1 | * @return mixed <p>(Mutable) A shifted element from the current array.</p> |
|
| 3144 | */ |
||
| 3145 | 1 | public function shift() |
|
| 3149 | |||
| 3150 | /** |
||
| 3151 | 1 | * Shuffle the current array. |
|
| 3152 | * |
||
| 3153 | 1 | * @param bool $secure <p>using a CSPRNG | @link https://paragonie.com/b/JvICXzh_jhLyt4y3</p> |
|
| 3154 | * @param array $array [optional] |
||
| 3155 | * |
||
| 3156 | * @return static <p>(Immutable)</p> |
||
| 3157 | */ |
||
| 3158 | public function shuffle(bool $secure = false, array $array = null) |
||
| 3191 | |||
| 3192 | 19 | /** |
|
| 3193 | * Counts all elements in an array, or something in an object. |
||
| 3194 | 19 | * <p>For objects, if you have SPL installed, you can hook into count() by implementing interface {@see Countable}. |
|
| 3195 | * The interface has exactly one method, {@see Countable::count()}, which returns the return value for the count() |
||
| 3196 | 19 | * function. Please see the {@see Array} section of the manual for a detailed explanation of how arrays are |
|
| 3197 | 19 | * implemented and used in PHP. |
|
| 3198 | 19 | * |
|
| 3199 | * @return int the number of elements in var, which is |
||
| 3200 | * typically an array, since anything else will have one |
||
| 3201 | 19 | * element. |
|
| 3202 | 19 | * </p> |
|
| 3203 | 9 | * <p> |
|
| 3204 | 5 | * If var is not an array or an object with |
|
| 3205 | 5 | * implemented Countable interface, |
|
| 3206 | 4 | * 1 will be returned. |
|
| 3207 | * There is one exception, if var is &null;, |
||
| 3208 | 9 | * 0 will be returned. |
|
| 3209 | 10 | * </p> |
|
| 3210 | 10 | * <p> |
|
| 3211 | 10 | * Caution: count may return 0 for a variable that isn't set, |
|
| 3212 | 10 | * but it may also return 0 for a variable that has been initialized with an |
|
| 3213 | 4 | * empty array. Use isset to test if a variable is set. |
|
| 3214 | 4 | * |
|
| 3215 | 6 | * @return int |
|
| 3216 | */ |
||
| 3217 | 10 | public function sizeRecursive(): int |
|
| 3221 | |||
| 3222 | /** |
||
| 3223 | * Counts all elements in an array, or something in an object. |
||
| 3224 | * <p>For objects, if you have SPL installed, you can hook into count() by implementing interface {@see Countable}. |
||
| 3225 | * The interface has exactly one method, {@see Countable::count()}, which returns the return value for the count() |
||
| 3226 | * function. Please see the {@see Array} section of the manual for a detailed explanation of how arrays are |
||
| 3227 | * implemented and used in PHP. |
||
| 3228 | * |
||
| 3229 | * @link http://php.net/manual/en/function.count.php |
||
| 3230 | 1 | * |
|
| 3231 | * @param int $mode [optional] If the optional mode parameter is set to |
||
| 3232 | 1 | * COUNT_RECURSIVE (or 1), count |
|
| 3233 | * will recursively count the array. This is particularly useful for |
||
| 3234 | 1 | * counting all the elements of a multidimensional array. count does not detect infinite recursion. |
|
| 3235 | 1 | * |
|
| 3236 | 1 | * @return int the number of elements in var, which is |
|
| 3237 | 1 | * typically an array, since anything else will have one |
|
| 3238 | 1 | * element. |
|
| 3239 | 1 | * </p> |
|
| 3240 | * <p> |
||
| 3241 | * If var is not an array or an object with |
||
| 3242 | 1 | * implemented Countable interface, |
|
| 3243 | * 1 will be returned. |
||
| 3244 | * There is one exception, if var is &null;, |
||
| 3245 | * 0 will be returned. |
||
| 3246 | * </p> |
||
| 3247 | * <p> |
||
| 3248 | * Caution: count may return 0 for a variable that isn't set, |
||
| 3249 | * but it may also return 0 for a variable that has been initialized with an |
||
| 3250 | 1 | * empty array. Use isset to test if a variable is set. |
|
| 3251 | * |
||
| 3252 | 1 | * @return int |
|
| 3253 | */ |
||
| 3254 | 1 | public function size(int $mode = COUNT_NORMAL): int |
|
| 3258 | 1 | ||
| 3259 | /** |
||
| 3260 | 1 | * Extract a slice of the array. |
|
| 3261 | * |
||
| 3262 | * @param int $offset <p>Slice begin index.</p> |
||
| 3263 | * @param int|null $length <p>Length of the slice.</p> |
||
| 3264 | * @param bool $preserveKeys <p>Whether array keys are preserved or no.</p> |
||
| 3265 | * |
||
| 3266 | * @return static <p>A slice of the original array with length $length.</p> |
||
| 3267 | */ |
||
| 3268 | public function slice(int $offset, int $length = null, bool $preserveKeys = false) |
||
| 3274 | |||
| 3275 | 1 | /** |
|
| 3276 | * Sort the current array and optional you can keep the keys. |
||
| 3277 | 1 | * |
|
| 3278 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 3279 | * @param int $strategy <p>sort_flags => use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 3280 | * <strong>SORT_NATURAL</strong></p> |
||
| 3281 | * @param bool $keepKeys |
||
| 3282 | * |
||
| 3283 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
| 3284 | */ |
||
| 3285 | 186 | public function sort($direction = SORT_ASC, int $strategy = SORT_REGULAR, bool $keepKeys = false) |
|
| 3291 | |||
| 3292 | /** |
||
| 3293 | * Sort the current array by key. |
||
| 3294 | * |
||
| 3295 | * @link http://php.net/manual/en/function.ksort.php |
||
| 3296 | * @link http://php.net/manual/en/function.krsort.php |
||
| 3297 | * |
||
| 3298 | 6 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
|
| 3299 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 3300 | 6 | * <strong>SORT_NATURAL</strong></p> |
|
| 3301 | * |
||
| 3302 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
| 3303 | */ |
||
| 3304 | public function sortKeys($direction = SORT_ASC, int $strategy = SORT_REGULAR) |
||
| 3310 | 19 | ||
| 3311 | /** |
||
| 3312 | 19 | * Sort the current array by value. |
|
| 3313 | * |
||
| 3314 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 3315 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 3316 | * <strong>SORT_NATURAL</strong></p> |
||
| 3317 | * |
||
| 3318 | * @return static <p>(Mutable)</p> |
||
| 3319 | */ |
||
| 3320 | 9 | public function sortValueKeepIndex($direction = SORT_ASC, int $strategy = SORT_REGULAR) |
|
| 3324 | 9 | ||
| 3325 | 9 | /** |
|
| 3326 | * Sort the current array by value. |
||
| 3327 | 8 | * |
|
| 3328 | 8 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
|
| 3329 | 8 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
|
| 3330 | * <strong>SORT_NATURAL</strong></p> |
||
| 3331 | 8 | * |
|
| 3332 | 9 | * @return static <p>(Mutable)</p> |
|
| 3333 | 9 | */ |
|
| 3334 | 9 | public function sortValueNewIndex($direction = SORT_ASC, int $strategy = SORT_REGULAR) |
|
| 3338 | |||
| 3339 | 9 | /** |
|
| 3340 | * Sort a array by value, by a closure or by a property. |
||
| 3341 | * |
||
| 3342 | 9 | * - If the sorter is null, the array is sorted naturally. |
|
| 3343 | * - Associative (string) keys will be maintained, but numeric keys will be re-indexed. |
||
| 3344 | * |
||
| 3345 | * @param \callable|null $sorter |
||
| 3346 | * @param string|int $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 3347 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 3348 | * <strong>SORT_NATURAL</strong></p> |
||
| 3349 | * |
||
| 3350 | 9 | * @return static <p>(Immutable)</p> |
|
| 3351 | */ |
||
| 3352 | public function sorter($sorter = null, $direction = SORT_ASC, int $strategy = SORT_REGULAR) |
||
| 3378 | |||
| 3379 | /** |
||
| 3380 | * sorting keys |
||
| 3381 | * |
||
| 3382 | * @param array $elements |
||
| 3383 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 3384 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 3385 | 9 | * <strong>SORT_NATURAL</strong></p> |
|
| 3386 | * |
||
| 3387 | 9 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
|
| 3388 | */ |
||
| 3389 | protected function sorterKeys(array &$elements, $direction = SORT_ASC, int $strategy = SORT_REGULAR) |
||
| 3406 | |||
| 3407 | /** |
||
| 3408 | * @param array &$elements |
||
| 3409 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 3410 | 2 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
|
| 3411 | * <strong>SORT_NATURAL</strong></p> |
||
| 3412 | 2 | * @param bool $keepKeys |
|
| 3413 | * |
||
| 3414 | * @return static <p>(Mutable) Return this Arrayy object.</p> |
||
| 3415 | */ |
||
| 3416 | protected function sorting(array &$elements, $direction = SORT_ASC, int $strategy = SORT_REGULAR, bool $keepKeys = false) |
||
| 3445 | |||
| 3446 | /** |
||
| 3447 | * Split an array in the given amount of pieces. |
||
| 3448 | * |
||
| 3449 | * @param int $numberOfPieces |
||
| 3450 | * @param bool $keepKeys |
||
| 3451 | * |
||
| 3452 | * @return static <p>(Immutable)</p> |
||
| 3453 | */ |
||
| 3454 | public function split(int $numberOfPieces = 2, bool $keepKeys = false) |
||
| 3468 | |||
| 3469 | /** |
||
| 3470 | * Stripe all empty items. |
||
| 3471 | * |
||
| 3472 | * @return static <p>(Immutable)</p> |
||
| 3473 | */ |
||
| 3474 | public function stripEmpty() |
||
| 3486 | |||
| 3487 | /** |
||
| 3488 | * Swap two values between positions by key. |
||
| 3489 | * |
||
| 3490 | * @param string|int $swapA <p>a key in the array</p> |
||
| 3491 | * @param string|int $swapB <p>a key in the array</p> |
||
| 3492 | * |
||
| 3493 | * @return static <p>(Immutable)</p> |
||
| 3494 | */ |
||
| 3495 | public function swap($swapA, $swapB) |
||
| 3503 | |||
| 3504 | /** |
||
| 3505 | * alias: for "Arrayy->getArray()" |
||
| 3506 | * |
||
| 3507 | * @see Arrayy::getArray() |
||
| 3508 | */ |
||
| 3509 | public function toArray() |
||
| 3513 | |||
| 3514 | /** |
||
| 3515 | * Convert the current array to JSON. |
||
| 3516 | * |
||
| 3517 | * @param null|int $options [optional] <p>e.g. JSON_PRETTY_PRINT</p> |
||
| 3518 | * @param int $depth [optional] <p>Set the maximum depth. Must be greater than zero.</p> |
||
| 3519 | * |
||
| 3520 | * @return string |
||
| 3521 | */ |
||
| 3522 | public function toJson($options = null, int $depth = 512): string |
||
| 3526 | |||
| 3527 | /** |
||
| 3528 | * Implodes array to a string with specified separator. |
||
| 3529 | * |
||
| 3530 | * @param string $separator [optional] <p>The element's separator.</p> |
||
| 3531 | * |
||
| 3532 | * @return string <p>The string representation of array, separated by ",".</p> |
||
| 3533 | */ |
||
| 3534 | public function toString(string $separator = ','): string |
||
| 3538 | |||
| 3539 | /** |
||
| 3540 | * Return a duplicate free copy of the current array. |
||
| 3541 | * |
||
| 3542 | * @return static <p>(Mutable)</p> |
||
| 3543 | */ |
||
| 3544 | public function unique() |
||
| 3568 | |||
| 3569 | /** |
||
| 3570 | * Return a duplicate free copy of the current array. (with the old keys) |
||
| 3571 | * |
||
| 3572 | * @return static <p>(Mutable)</p> |
||
| 3573 | */ |
||
| 3574 | public function uniqueKeepIndex() |
||
| 3601 | |||
| 3602 | /** |
||
| 3603 | * alias: for "Arrayy->unique()" |
||
| 3604 | * |
||
| 3605 | * @see Arrayy::unique() |
||
| 3606 | * |
||
| 3607 | * @return static <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
| 3608 | */ |
||
| 3609 | public function uniqueNewIndex() |
||
| 3613 | |||
| 3614 | /** |
||
| 3615 | * Prepends one or more values to the beginning of array at once. |
||
| 3616 | * |
||
| 3617 | * @return static <p>(Mutable) Return this Arrayy object, with prepended elements to the beginning of array.</p> |
||
| 3618 | */ |
||
| 3619 | View Code Duplication | public function unshift(/* variadic arguments allowed */) |
|
| 3628 | |||
| 3629 | /** |
||
| 3630 | * Get all values from a array. |
||
| 3631 | * |
||
| 3632 | * @return static <p>(Immutable)</p> |
||
| 3633 | */ |
||
| 3634 | public function values() |
||
| 3638 | |||
| 3639 | /** |
||
| 3640 | * Apply the given function to every element in the array, discarding the results. |
||
| 3641 | * |
||
| 3642 | * @param \callable $callable |
||
| 3643 | * @param bool $recursive <p>Whether array will be walked recursively or no</p> |
||
| 3644 | * |
||
| 3645 | * @return static <p>(Mutable) Return this Arrayy object, with modified elements.</p> |
||
| 3646 | */ |
||
| 3647 | public function walk($callable, bool $recursive = false) |
||
| 3657 | } |
||
| 3658 |
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: