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 |
||
| 15 | class Arrayy extends \ArrayObject implements \IteratorAggregate, \ArrayAccess, \Serializable, \Countable |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * @var array |
||
| 19 | */ |
||
| 20 | protected $array = []; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @var string |
||
| 24 | */ |
||
| 25 | protected $iteratorClass = ArrayyIterator::class; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var string |
||
| 29 | */ |
||
| 30 | protected $pathSeparator = '.'; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var bool |
||
| 34 | */ |
||
| 35 | protected $checkPropertyTypes = false; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @var bool |
||
| 39 | */ |
||
| 40 | protected $checkForMissingPropertiesInConstructor = false; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @var bool |
||
| 44 | */ |
||
| 45 | protected $checkPropertiesMismatchInConstructor = false; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @var array|Property[] |
||
| 49 | */ |
||
| 50 | protected $properties = []; |
||
| 51 | |||
| 52 | /** @noinspection MagicMethodsValidityInspection */ |
||
| 53 | /** @noinspection PhpMissingParentConstructorInspection */ |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Initializes |
||
| 57 | * |
||
| 58 | * @param mixed $array <p> |
||
| 59 | * Should be an array, otherwise it will try to convert |
||
| 60 | * it into an array. |
||
| 61 | * </p> |
||
| 62 | * @param string $iteratorClass optional <p> |
||
| 63 | * You can overwrite the ArrayyIterator, but mostly you don't |
||
| 64 | * need this option. |
||
| 65 | * </p> |
||
| 66 | * @param bool $checkForMissingPropertiesInConstructor optional <p> |
||
| 67 | * You need to extend the "Arrayy"-class and you need to set |
||
| 68 | * the $checkPropertiesMismatchInConstructor class property to |
||
| 69 | * true, otherwise this option didn't not work anyway. |
||
| 70 | * </p> |
||
| 71 | */ |
||
| 72 | 889 | public function __construct($array = [], string $iteratorClass = ArrayyIterator::class, bool $checkForMissingPropertiesInConstructor = true) |
|
| 106 | |||
| 107 | /** |
||
| 108 | * Get a value by key. |
||
| 109 | * |
||
| 110 | * @param mixed $key |
||
| 111 | * |
||
| 112 | * @return mixed |
||
| 113 | * <p>Get a Value from the current array.</p> |
||
| 114 | */ |
||
| 115 | 3 | public function &__get($key) |
|
| 125 | |||
| 126 | /** |
||
| 127 | * Call object as function. |
||
| 128 | * |
||
| 129 | * @param mixed $key |
||
| 130 | * |
||
| 131 | * @return mixed |
||
| 132 | */ |
||
| 133 | 1 | public function __invoke($key = null) |
|
| 141 | |||
| 142 | /** |
||
| 143 | * Whether or not an element exists by key. |
||
| 144 | * |
||
| 145 | * @param mixed $key |
||
| 146 | * |
||
| 147 | * @return bool |
||
| 148 | * <p>True is the key/index exists, otherwise false.</p> |
||
| 149 | */ |
||
| 150 | public function __isset($key) |
||
| 154 | |||
| 155 | /** |
||
| 156 | * Assigns a value to the specified element. |
||
| 157 | * |
||
| 158 | * @param mixed $key |
||
| 159 | * @param mixed $value |
||
| 160 | */ |
||
| 161 | 2 | public function __set($key, $value) |
|
| 165 | |||
| 166 | /** |
||
| 167 | * magic to string |
||
| 168 | * |
||
| 169 | * @return string |
||
| 170 | */ |
||
| 171 | 15 | public function __toString() |
|
| 175 | |||
| 176 | /** |
||
| 177 | * Unset element by key. |
||
| 178 | * |
||
| 179 | * @param mixed $key |
||
| 180 | */ |
||
| 181 | public function __unset($key) |
||
| 185 | |||
| 186 | /** |
||
| 187 | * alias: for "Arrayy->append()" |
||
| 188 | * |
||
| 189 | * @see Arrayy::append() |
||
| 190 | * |
||
| 191 | * @param mixed $value |
||
| 192 | * |
||
| 193 | * @return static |
||
| 194 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
| 195 | */ |
||
| 196 | 1 | public function add($value) |
|
| 200 | |||
| 201 | /** |
||
| 202 | * Append a (key) + value to the current array. |
||
| 203 | * |
||
| 204 | * @param mixed $value |
||
| 205 | * @param mixed $key |
||
| 206 | * |
||
| 207 | * @return static |
||
| 208 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
| 209 | */ |
||
| 210 | 9 | public function append($value, $key = null) |
|
| 228 | |||
| 229 | /** |
||
| 230 | * Sort the entries by value. |
||
| 231 | * |
||
| 232 | * @param int $sort_flags [optional] <p> |
||
| 233 | * You may modify the behavior of the sort using the optional |
||
| 234 | * parameter sort_flags, for details |
||
| 235 | * see sort. |
||
| 236 | * </p> |
||
| 237 | * |
||
| 238 | * @return static |
||
| 239 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 240 | */ |
||
| 241 | 4 | public function asort(int $sort_flags = 0) |
|
| 247 | |||
| 248 | /** |
||
| 249 | * Counts all elements in an array, or something in an object. |
||
| 250 | * |
||
| 251 | * <p> |
||
| 252 | * For objects, if you have SPL installed, you can hook into count() by implementing interface {@see Countable}. |
||
| 253 | * The interface has exactly one method, {@see Countable::count()}, which returns the return value for the count() |
||
| 254 | * function. Please see the {@see Array} section of the manual for a detailed explanation of how arrays are |
||
| 255 | * implemented and used in PHP. |
||
| 256 | * </p> |
||
| 257 | * |
||
| 258 | * @see http://php.net/manual/en/function.count.php |
||
| 259 | * |
||
| 260 | * @param int $mode [optional] If the optional mode parameter is set to |
||
| 261 | * COUNT_RECURSIVE (or 1), count |
||
| 262 | * will recursively count the array. This is particularly useful for |
||
| 263 | * counting all the elements of a multidimensional array. count does not detect infinite recursion. |
||
| 264 | * |
||
| 265 | * @return int |
||
| 266 | * <p> |
||
| 267 | * The number of elements in var, which is |
||
| 268 | * typically an array, since anything else will have one |
||
| 269 | * element. |
||
| 270 | * </p> |
||
| 271 | * <p> |
||
| 272 | * If var is not an array or an object with |
||
| 273 | * implemented Countable interface, |
||
| 274 | * 1 will be returned. |
||
| 275 | * There is one exception, if var is &null;, |
||
| 276 | * 0 will be returned. |
||
| 277 | * </p> |
||
| 278 | * <p> |
||
| 279 | * Caution: count may return 0 for a variable that isn't set, |
||
| 280 | * but it may also return 0 for a variable that has been initialized with an |
||
| 281 | * empty array. Use isset to test if a variable is set. |
||
| 282 | * </p> |
||
| 283 | */ |
||
| 284 | 37 | public function count(int $mode = \COUNT_NORMAL): int |
|
| 288 | |||
| 289 | /** |
||
| 290 | * Exchange the array for another one. |
||
| 291 | * |
||
| 292 | * @param array|static $data |
||
| 293 | * |
||
| 294 | * @return array |
||
| 295 | */ |
||
| 296 | 1 | public function exchangeArray($data): array |
|
| 302 | |||
| 303 | /** |
||
| 304 | * Creates a copy of the ArrayyObject. |
||
| 305 | * |
||
| 306 | * @return array |
||
| 307 | */ |
||
| 308 | 1 | public function getArrayCopy(): array |
|
| 312 | |||
| 313 | /** |
||
| 314 | * Returns a new ArrayyIterator, thus implementing the \ArrayIterator interface. |
||
| 315 | * |
||
| 316 | * @return \ArrayIterator |
||
| 317 | * <p>An iterator for the values in the array.</p> |
||
| 318 | */ |
||
| 319 | 12 | public function getIterator(): \ArrayIterator |
|
| 325 | |||
| 326 | /** |
||
| 327 | * Gets the iterator classname for the ArrayObject. |
||
| 328 | * |
||
| 329 | * @return string |
||
| 330 | */ |
||
| 331 | 12 | public function getIteratorClass(): string |
|
| 335 | |||
| 336 | /** |
||
| 337 | * Sort the entries by key |
||
| 338 | * |
||
| 339 | * @param int $sort_flags [optional] <p> |
||
| 340 | * You may modify the behavior of the sort using the optional |
||
| 341 | * parameter sort_flags, for details |
||
| 342 | * see sort. |
||
| 343 | * </p> |
||
| 344 | * |
||
| 345 | * @return static |
||
| 346 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 347 | */ |
||
| 348 | 4 | public function ksort(int $sort_flags = 0) |
|
| 354 | |||
| 355 | /** |
||
| 356 | * Sort an array using a case insensitive "natural order" algorithm |
||
| 357 | * |
||
| 358 | * @return static |
||
| 359 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 360 | */ |
||
| 361 | public function natcasesort() |
||
| 367 | |||
| 368 | /** |
||
| 369 | * Sort entries using a "natural order" algorithm |
||
| 370 | * |
||
| 371 | * @return static |
||
| 372 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 373 | */ |
||
| 374 | 1 | public function natsort() |
|
| 380 | |||
| 381 | /** |
||
| 382 | * Whether or not an offset exists. |
||
| 383 | * |
||
| 384 | * @param bool|float|int|string $offset |
||
| 385 | * |
||
| 386 | * @return bool |
||
| 387 | */ |
||
| 388 | 44 | public function offsetExists($offset): bool |
|
| 431 | |||
| 432 | /** |
||
| 433 | * Returns the value at specified offset. |
||
| 434 | * |
||
| 435 | * @param float|int|string $offset |
||
| 436 | * |
||
| 437 | * @return mixed |
||
| 438 | * <p>Will return null if the offset did not exists.</p> |
||
| 439 | */ |
||
| 440 | 30 | public function offsetGet($offset) |
|
| 444 | |||
| 445 | /** |
||
| 446 | * Assigns a value to the specified offset. |
||
| 447 | * |
||
| 448 | * @param int|string|null $offset |
||
| 449 | * @param mixed $value |
||
| 450 | */ |
||
| 451 | 20 | public function offsetSet($offset, $value) |
|
| 459 | |||
| 460 | /** |
||
| 461 | * Unset an offset. |
||
| 462 | * |
||
| 463 | * @param float|int|string $offset |
||
| 464 | */ |
||
| 465 | 7 | public function offsetUnset($offset) |
|
| 489 | |||
| 490 | /** @noinspection SenselessProxyMethodInspection | can not add return type, because of the "Serializable" interface */ |
||
| 491 | |||
| 492 | /** |
||
| 493 | * Serialize the current "Arrayy"-object. |
||
| 494 | * |
||
| 495 | * @return string |
||
| 496 | */ |
||
| 497 | 1 | public function serialize() |
|
| 501 | |||
| 502 | /** |
||
| 503 | * Sets the iterator classname for the current "Arrayy"-object. |
||
| 504 | * |
||
| 505 | * @param string $class |
||
| 506 | * |
||
| 507 | * @throws \InvalidArgumentException |
||
| 508 | * |
||
| 509 | * @return void |
||
| 510 | */ |
||
| 511 | 883 | public function setIteratorClass($class) |
|
| 530 | |||
| 531 | /** |
||
| 532 | * Sort the entries with a user-defined comparison function and maintain key association. |
||
| 533 | * |
||
| 534 | * @param \callable $function |
||
| 535 | * |
||
| 536 | * @throws \InvalidArgumentException |
||
| 537 | * |
||
| 538 | * @return static |
||
| 539 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 540 | */ |
||
| 541 | View Code Duplication | public function uasort($function) |
|
| 553 | |||
| 554 | /** |
||
| 555 | * Sort the entries by keys using a user-defined comparison function. |
||
| 556 | * |
||
| 557 | * @param \callable $function |
||
| 558 | * |
||
| 559 | * @throws \InvalidArgumentException |
||
| 560 | * |
||
| 561 | * @return static |
||
| 562 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 563 | */ |
||
| 564 | 5 | public function uksort($function) |
|
| 568 | |||
| 569 | /** |
||
| 570 | * Unserialize an string and return this object. |
||
| 571 | * |
||
| 572 | * @param string $string |
||
| 573 | * |
||
| 574 | * @return static |
||
| 575 | * <p>(Mutable)</p> |
||
| 576 | */ |
||
| 577 | 1 | public function unserialize($string) |
|
| 583 | |||
| 584 | /** |
||
| 585 | * Append a (key) + values to the current array. |
||
| 586 | * |
||
| 587 | * @param array $values |
||
| 588 | * @param mixed $key |
||
| 589 | * |
||
| 590 | * @return static |
||
| 591 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
| 592 | */ |
||
| 593 | 1 | public function appendArrayValues(array $values, $key = null) |
|
| 617 | |||
| 618 | /** |
||
| 619 | * Add a suffix to each key. |
||
| 620 | * |
||
| 621 | * @param mixed $prefix |
||
| 622 | * |
||
| 623 | * @return static |
||
| 624 | * <p>(Immutable) Return an Arrayy object, with the prefixed keys.</p> |
||
| 625 | */ |
||
| 626 | 10 | View Code Duplication | public function appendToEachKey($prefix) |
| 645 | |||
| 646 | /** |
||
| 647 | * Add a prefix to each value. |
||
| 648 | * |
||
| 649 | * @param mixed $prefix |
||
| 650 | * |
||
| 651 | * @return static |
||
| 652 | * <p>(Immutable) Return an Arrayy object, with the prefixed values.</p> |
||
| 653 | */ |
||
| 654 | 10 | View Code Duplication | public function appendToEachValue($prefix) |
| 673 | |||
| 674 | /** |
||
| 675 | * Convert an array into a object. |
||
| 676 | * |
||
| 677 | * @param array $array PHP array |
||
| 678 | * |
||
| 679 | * @return \stdClass |
||
| 680 | */ |
||
| 681 | 4 | protected static function arrayToObject(array $array = []): \stdClass |
|
| 700 | |||
| 701 | /** |
||
| 702 | * @param array|\Generator|null $input <p> |
||
| 703 | * An array containing keys to return. |
||
| 704 | * </p> |
||
| 705 | * @param mixed $search_value [optional] <p> |
||
| 706 | * If specified, then only keys containing these values are returned. |
||
| 707 | * </p> |
||
| 708 | * @param bool $strict [optional] <p> |
||
| 709 | * Determines if strict comparison (===) should be used during the |
||
| 710 | * search. |
||
| 711 | * </p> |
||
| 712 | * |
||
| 713 | * @return array |
||
| 714 | * <p>an array of all the keys in input</p> |
||
| 715 | */ |
||
| 716 | 10 | protected function array_keys_recursive($input = null, $search_value = null, bool $strict = true): array |
|
| 747 | |||
| 748 | /** |
||
| 749 | * Sort an array in reverse order and maintain index association. |
||
| 750 | * |
||
| 751 | * @return static |
||
| 752 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 753 | */ |
||
| 754 | 4 | public function arsort() |
|
| 760 | |||
| 761 | /** |
||
| 762 | * Iterate over the current array and execute a callback for each loop. |
||
| 763 | * |
||
| 764 | * @param \Closure $closure |
||
| 765 | * |
||
| 766 | * @return static |
||
| 767 | * <p>(Immutable)</p> |
||
| 768 | */ |
||
| 769 | 2 | public function at(\Closure $closure) |
|
| 783 | |||
| 784 | /** |
||
| 785 | * Returns the average value of the current array. |
||
| 786 | * |
||
| 787 | * @param int $decimals <p>The number of decimal-numbers to return.</p> |
||
| 788 | * |
||
| 789 | * @return float|int |
||
| 790 | * <p>The average value.</p> |
||
| 791 | */ |
||
| 792 | 10 | public function average($decimals = 0) |
|
| 806 | |||
| 807 | /** |
||
| 808 | * @param mixed $path |
||
| 809 | * @param \callable $callable |
||
| 810 | * @param array|null $currentOffset |
||
| 811 | */ |
||
| 812 | 4 | protected function callAtPath($path, $callable, &$currentOffset = null) |
|
| 835 | |||
| 836 | /** |
||
| 837 | * Changes all keys in an array. |
||
| 838 | * |
||
| 839 | * @param int $case [optional] <p> Either <strong>CASE_UPPER</strong><br /> |
||
| 840 | * or <strong>CASE_LOWER</strong> (default)</p> |
||
| 841 | * |
||
| 842 | * @return static |
||
| 843 | * <p>(Immutable)</p> |
||
| 844 | */ |
||
| 845 | 1 | public function changeKeyCase(int $case = \CASE_LOWER) |
|
| 874 | |||
| 875 | /** |
||
| 876 | * Change the path separator of the array wrapper. |
||
| 877 | * |
||
| 878 | * By default, the separator is: "." |
||
| 879 | * |
||
| 880 | * @param string $separator <p>Separator to set.</p> |
||
| 881 | * |
||
| 882 | * @return static |
||
| 883 | * <p>Mutable</p> |
||
| 884 | */ |
||
| 885 | 1 | public function changeSeparator($separator) |
|
| 891 | |||
| 892 | /** |
||
| 893 | * Create a chunked version of the current array. |
||
| 894 | * |
||
| 895 | * @param int $size <p>Size of each chunk.</p> |
||
| 896 | * @param bool $preserveKeys <p>Whether array keys are preserved or no.</p> |
||
| 897 | * |
||
| 898 | * @return static |
||
| 899 | * <p>(Immutable) A new array of chunks from the original array.</p> |
||
| 900 | */ |
||
| 901 | 4 | public function chunk($size, $preserveKeys = false) |
|
| 909 | |||
| 910 | /** |
||
| 911 | * Clean all falsy values from the current array. |
||
| 912 | * |
||
| 913 | * @return static |
||
| 914 | * <p>(Immutable)</p> |
||
| 915 | */ |
||
| 916 | 8 | public function clean() |
|
| 924 | |||
| 925 | /** |
||
| 926 | * WARNING!!! -> Clear the current array. |
||
| 927 | * |
||
| 928 | * @return static |
||
| 929 | * <p>(Mutable) Return this Arrayy object, with an empty array.</p> |
||
| 930 | */ |
||
| 931 | 4 | public function clear() |
|
| 937 | |||
| 938 | /** |
||
| 939 | * Check if an item is in the current array. |
||
| 940 | * |
||
| 941 | * @param float|int|string $value |
||
| 942 | * @param bool $recursive |
||
| 943 | * @param bool $strict |
||
| 944 | * |
||
| 945 | * @return bool |
||
| 946 | */ |
||
| 947 | 22 | public function contains($value, $recursive = false, $strict = true): bool |
|
| 955 | |||
| 956 | /** |
||
| 957 | * Check if an (case-insensitive) string is in the current array. |
||
| 958 | * |
||
| 959 | * @param string $value |
||
| 960 | * @param bool $recursive |
||
| 961 | * |
||
| 962 | * @return bool |
||
| 963 | */ |
||
| 964 | 26 | public function containsCaseInsensitive($value, $recursive = false): bool |
|
| 994 | |||
| 995 | /** |
||
| 996 | * Check if the given key/index exists in the array. |
||
| 997 | * |
||
| 998 | * @param float|int|string $key <p>key/index to search for</p> |
||
| 999 | * |
||
| 1000 | * @return bool |
||
| 1001 | * <p>Returns true if the given key/index exists in the array, false otherwise.</p> |
||
| 1002 | */ |
||
| 1003 | 4 | public function containsKey($key): bool |
|
| 1007 | |||
| 1008 | /** |
||
| 1009 | * Check if all given needles are present in the array as key/index. |
||
| 1010 | * |
||
| 1011 | * @param array $needles <p>The keys you are searching for.</p> |
||
| 1012 | * @param bool $recursive |
||
| 1013 | * |
||
| 1014 | * @return bool |
||
| 1015 | * <p>Returns true if all the given keys/indexes exists in the array, false otherwise.</p> |
||
| 1016 | */ |
||
| 1017 | 2 | public function containsKeys(array $needles, $recursive = false): bool |
|
| 1041 | |||
| 1042 | /** |
||
| 1043 | * Check if all given needles are present in the array as key/index. |
||
| 1044 | * |
||
| 1045 | * @param array $needles <p>The keys you are searching for.</p> |
||
| 1046 | * |
||
| 1047 | * @return bool |
||
| 1048 | * <p>Returns true if all the given keys/indexes exists in the array, false otherwise.</p> |
||
| 1049 | */ |
||
| 1050 | 1 | public function containsKeysRecursive(array $needles): bool |
|
| 1054 | |||
| 1055 | /** |
||
| 1056 | * alias: for "Arrayy->contains()" |
||
| 1057 | * |
||
| 1058 | * @see Arrayy::contains() |
||
| 1059 | * |
||
| 1060 | * @param float|int|string $value |
||
| 1061 | * |
||
| 1062 | * @return bool |
||
| 1063 | */ |
||
| 1064 | 9 | public function containsValue($value): bool |
|
| 1068 | |||
| 1069 | /** |
||
| 1070 | * alias: for "Arrayy->contains($value, true)" |
||
| 1071 | * |
||
| 1072 | * @see Arrayy::contains() |
||
| 1073 | * |
||
| 1074 | * @param float|int|string $value |
||
| 1075 | * |
||
| 1076 | * @return bool |
||
| 1077 | */ |
||
| 1078 | 18 | public function containsValueRecursive($value): bool |
|
| 1082 | |||
| 1083 | /** |
||
| 1084 | * Check if all given needles are present in the array. |
||
| 1085 | * |
||
| 1086 | * @param array $needles |
||
| 1087 | * |
||
| 1088 | * @return bool |
||
| 1089 | * <p>Returns true if all the given values exists in the array, false otherwise.</p> |
||
| 1090 | */ |
||
| 1091 | 1 | public function containsValues(array $needles): bool |
|
| 1097 | |||
| 1098 | /** |
||
| 1099 | * Counts all the values of an array |
||
| 1100 | * |
||
| 1101 | * @see http://php.net/manual/en/function.array-count-values.php |
||
| 1102 | * |
||
| 1103 | * @return static |
||
| 1104 | * <p> |
||
| 1105 | * (Immutable) |
||
| 1106 | * An associative Arrayy-object of values from input as |
||
| 1107 | * keys and their count as value. |
||
| 1108 | * </p> |
||
| 1109 | */ |
||
| 1110 | 1 | public function countValues(): self |
|
| 1114 | |||
| 1115 | /** |
||
| 1116 | * Creates an Arrayy object. |
||
| 1117 | * |
||
| 1118 | * @param mixed $array |
||
| 1119 | * @param string $iteratorClass |
||
| 1120 | * @param bool $checkForMissingPropertiesInConstructor |
||
| 1121 | * |
||
| 1122 | * @return static |
||
| 1123 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1124 | */ |
||
| 1125 | 534 | public static function create($array = [], string $iteratorClass = ArrayyIterator::class, bool $checkForMissingPropertiesInConstructor = true): self |
|
| 1129 | |||
| 1130 | /** |
||
| 1131 | * WARNING: Creates an Arrayy object by reference. |
||
| 1132 | * |
||
| 1133 | * @param array $array |
||
| 1134 | * |
||
| 1135 | * @return static |
||
| 1136 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1137 | */ |
||
| 1138 | 1 | public function createByReference(array &$array = []): self |
|
| 1146 | |||
| 1147 | /** |
||
| 1148 | * Create an new Arrayy object via JSON. |
||
| 1149 | * |
||
| 1150 | * @param string $json |
||
| 1151 | * |
||
| 1152 | * @return static |
||
| 1153 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1154 | */ |
||
| 1155 | 5 | public static function createFromJson(string $json) |
|
| 1160 | |||
| 1161 | /** |
||
| 1162 | * Create an new instance filled with values from an object that have implemented ArrayAccess. |
||
| 1163 | * |
||
| 1164 | * @param \ArrayAccess $object <p>Object that implements ArrayAccess</p> |
||
| 1165 | * |
||
| 1166 | * @return static |
||
| 1167 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1168 | */ |
||
| 1169 | 4 | public static function createFromObject(\ArrayAccess $object) |
|
| 1186 | |||
| 1187 | /** |
||
| 1188 | * Create an new instance filled with a copy of values from a "Generator"-object. |
||
| 1189 | * |
||
| 1190 | * @param \Generator $generator |
||
| 1191 | * |
||
| 1192 | * @return static |
||
| 1193 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1194 | */ |
||
| 1195 | 4 | public static function createFromGeneratorImmutable(\Generator $generator) |
|
| 1206 | |||
| 1207 | /** |
||
| 1208 | * Create an new instance filled with values from an object. |
||
| 1209 | * |
||
| 1210 | * @param object $object |
||
| 1211 | * |
||
| 1212 | * @return static |
||
| 1213 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1214 | */ |
||
| 1215 | 5 | public static function createFromObjectVars($object): self |
|
| 1219 | |||
| 1220 | /** |
||
| 1221 | * Create an new Arrayy object via string. |
||
| 1222 | * |
||
| 1223 | * @param string $str <p>The input string.</p> |
||
| 1224 | * @param string|null $delimiter <p>The boundary string.</p> |
||
| 1225 | * @param string|null $regEx <p>Use the $delimiter or the $regEx, so if $pattern is null, $delimiter will be |
||
| 1226 | * used.</p> |
||
| 1227 | * |
||
| 1228 | * @return static |
||
| 1229 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1230 | */ |
||
| 1231 | 8 | public static function createFromString(string $str, string $delimiter = null, string $regEx = null) |
|
| 1256 | |||
| 1257 | /** |
||
| 1258 | * Create an new instance containing a range of elements. |
||
| 1259 | * |
||
| 1260 | * @param mixed $low <p>First value of the sequence.</p> |
||
| 1261 | * @param mixed $high <p>The sequence is ended upon reaching the end value.</p> |
||
| 1262 | * @param int $step <p>Used as the increment between elements in the sequence.</p> |
||
| 1263 | * |
||
| 1264 | * @return static |
||
| 1265 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1266 | */ |
||
| 1267 | 1 | public static function createWithRange($low, $high, int $step = 1) |
|
| 1271 | |||
| 1272 | /** |
||
| 1273 | * Custom sort by index via "uksort". |
||
| 1274 | * |
||
| 1275 | * @see http://php.net/manual/en/function.uksort.php |
||
| 1276 | * |
||
| 1277 | * @param \callable $function |
||
| 1278 | * |
||
| 1279 | * @throws \InvalidArgumentException |
||
| 1280 | * |
||
| 1281 | * @return static |
||
| 1282 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1283 | */ |
||
| 1284 | 5 | View Code Duplication | public function customSortKeys($function) |
| 1296 | |||
| 1297 | /** |
||
| 1298 | * Custom sort by value via "usort". |
||
| 1299 | * |
||
| 1300 | * @see http://php.net/manual/en/function.usort.php |
||
| 1301 | * |
||
| 1302 | * @param \callable $function |
||
| 1303 | * |
||
| 1304 | * @throws \InvalidArgumentException |
||
| 1305 | * |
||
| 1306 | * @return static |
||
| 1307 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1308 | */ |
||
| 1309 | 5 | View Code Duplication | public function customSortValues($function) |
| 1321 | |||
| 1322 | /** |
||
| 1323 | * Return values that are only in the current array. |
||
| 1324 | * |
||
| 1325 | * @param array $array |
||
| 1326 | * |
||
| 1327 | * @return static |
||
| 1328 | * <p>(Immutable)</p> |
||
| 1329 | */ |
||
| 1330 | 12 | public function diff(array $array = []) |
|
| 1336 | |||
| 1337 | /** |
||
| 1338 | * Return values that are only in the current multi-dimensional array. |
||
| 1339 | * |
||
| 1340 | * @param array $array |
||
| 1341 | * @param array|null $helperVariableForRecursion <p>(only for internal usage)</p> |
||
| 1342 | * |
||
| 1343 | * @return static |
||
| 1344 | * <p>(Immutable)</p> |
||
| 1345 | */ |
||
| 1346 | 1 | public function diffRecursive(array $array = [], $helperVariableForRecursion = null) |
|
| 1377 | |||
| 1378 | /** |
||
| 1379 | * Return values that are only in the new $array. |
||
| 1380 | * |
||
| 1381 | * @param array $array |
||
| 1382 | * |
||
| 1383 | * @return static |
||
| 1384 | * <p>(Immutable)</p> |
||
| 1385 | */ |
||
| 1386 | 8 | public function diffReverse(array $array = []) |
|
| 1394 | |||
| 1395 | /** |
||
| 1396 | * Divide an array into two arrays. One with keys and the other with values. |
||
| 1397 | * |
||
| 1398 | * @return static |
||
| 1399 | * <p>(Immutable)</p> |
||
| 1400 | */ |
||
| 1401 | 1 | public function divide() |
|
| 1412 | |||
| 1413 | /** |
||
| 1414 | * Iterate over the current array and modify the array's value. |
||
| 1415 | * |
||
| 1416 | * @param \Closure $closure |
||
| 1417 | * |
||
| 1418 | * @return static |
||
| 1419 | * <p>(Immutable)</p> |
||
| 1420 | */ |
||
| 1421 | 4 | View Code Duplication | public function each(\Closure $closure) |
| 1432 | |||
| 1433 | /** |
||
| 1434 | * Check if a value is in the current array using a closure. |
||
| 1435 | * |
||
| 1436 | * @param \Closure $closure |
||
| 1437 | * |
||
| 1438 | * @return bool |
||
| 1439 | * <p>Returns true if the given value is found, false otherwise.</p> |
||
| 1440 | */ |
||
| 1441 | 4 | public function exists(\Closure $closure): bool |
|
| 1456 | |||
| 1457 | /** |
||
| 1458 | * create a fallback for array |
||
| 1459 | * |
||
| 1460 | * 1. use the current array, if it's a array |
||
| 1461 | * 2. fallback to empty array, if there is nothing |
||
| 1462 | * 3. call "getArray()" on object, if there is a "Arrayy"-object |
||
| 1463 | * 4. call "createFromObject()" on object, if there is a "\ArrayAccess"-object |
||
| 1464 | * 5. call "__toArray()" on object, if the method exists |
||
| 1465 | * 6. cast a string or object with "__toString()" into an array |
||
| 1466 | * 7. throw a "InvalidArgumentException"-Exception |
||
| 1467 | * |
||
| 1468 | * @param mixed $array |
||
| 1469 | * |
||
| 1470 | * @throws \InvalidArgumentException |
||
| 1471 | * |
||
| 1472 | * @return array |
||
| 1473 | */ |
||
| 1474 | 889 | protected function fallbackForArray(&$array): array |
|
| 1516 | |||
| 1517 | /** |
||
| 1518 | * Fill the array until "$num" with "$default" values. |
||
| 1519 | * |
||
| 1520 | * @param int $num |
||
| 1521 | * @param mixed $default |
||
| 1522 | * |
||
| 1523 | * @return static |
||
| 1524 | * <p>(Immutable)</p> |
||
| 1525 | */ |
||
| 1526 | 8 | public function fillWithDefaults(int $num, $default = null) |
|
| 1543 | |||
| 1544 | /** |
||
| 1545 | * Find all items in an array that pass the truth test. |
||
| 1546 | * |
||
| 1547 | * @param \Closure|null $closure [optional] <p> |
||
| 1548 | * The callback function to use |
||
| 1549 | * </p> |
||
| 1550 | * <p> |
||
| 1551 | * If no callback is supplied, all entries of |
||
| 1552 | * input equal to false (see |
||
| 1553 | * converting to |
||
| 1554 | * boolean) will be removed. |
||
| 1555 | * </p> |
||
| 1556 | * * @param int $flag [optional] <p> |
||
| 1557 | * Flag determining what arguments are sent to <i>callback</i>: |
||
| 1558 | * </p><ul> |
||
| 1559 | * <li> |
||
| 1560 | * <b>ARRAY_FILTER_USE_KEY</b> [1] - pass key as the only argument |
||
| 1561 | * to <i>callback</i> instead of the value</span> |
||
| 1562 | * </li> |
||
| 1563 | * <li> |
||
| 1564 | * <b>ARRAY_FILTER_USE_BOTH</b> [2] - pass both value and key as |
||
| 1565 | * arguments to <i>callback</i> instead of the value</span> |
||
| 1566 | * </li> |
||
| 1567 | * </ul> |
||
| 1568 | * |
||
| 1569 | * @return static |
||
| 1570 | * <p>(Immutable)</p> |
||
| 1571 | */ |
||
| 1572 | 10 | public function filter($closure = null, int $flag = \ARRAY_FILTER_USE_BOTH) |
|
| 1584 | |||
| 1585 | /** |
||
| 1586 | * Filters an array of objects (or a numeric array of associative arrays) based on the value of a particular |
||
| 1587 | * property within that. |
||
| 1588 | * |
||
| 1589 | * @param string $property |
||
| 1590 | * @param string|string[] $value |
||
| 1591 | * @param string $comparisonOp |
||
| 1592 | * <p> |
||
| 1593 | * 'eq' (equals),<br /> |
||
| 1594 | * 'gt' (greater),<br /> |
||
| 1595 | * 'gte' || 'ge' (greater or equals),<br /> |
||
| 1596 | * 'lt' (less),<br /> |
||
| 1597 | * 'lte' || 'le' (less or equals),<br /> |
||
| 1598 | * 'ne' (not equals),<br /> |
||
| 1599 | * 'contains',<br /> |
||
| 1600 | * 'notContains',<br /> |
||
| 1601 | * 'newer' (via strtotime),<br /> |
||
| 1602 | * 'older' (via strtotime),<br /> |
||
| 1603 | * </p> |
||
| 1604 | * |
||
| 1605 | * @return static |
||
| 1606 | * <p>(Immutable)</p> |
||
| 1607 | */ |
||
| 1608 | 1 | public function filterBy(string $property, $value, string $comparisonOp = null) |
|
| 1673 | |||
| 1674 | /** |
||
| 1675 | * Find the first item in an array that passes the truth test, |
||
| 1676 | * otherwise return false |
||
| 1677 | * |
||
| 1678 | * @param \Closure $closure |
||
| 1679 | * |
||
| 1680 | * @return false|mixed |
||
| 1681 | * <p>Return false if we did not find the value.</p> |
||
| 1682 | */ |
||
| 1683 | 8 | public function find(\Closure $closure) |
|
| 1693 | |||
| 1694 | /** |
||
| 1695 | * find by ... |
||
| 1696 | * |
||
| 1697 | * @param string $property |
||
| 1698 | * @param string|string[] $value |
||
| 1699 | * @param string $comparisonOp |
||
| 1700 | * |
||
| 1701 | * @return static |
||
| 1702 | * <p>(Immutable)</p> |
||
| 1703 | */ |
||
| 1704 | public function findBy(string $property, $value, string $comparisonOp = 'eq') |
||
| 1708 | |||
| 1709 | /** |
||
| 1710 | * Get the first value from the current array. |
||
| 1711 | * |
||
| 1712 | * @return mixed |
||
| 1713 | * <p>Return null if there wasn't a element.</p> |
||
| 1714 | */ |
||
| 1715 | 13 | public function first() |
|
| 1721 | |||
| 1722 | /** |
||
| 1723 | * Get the first value(s) from the current array. |
||
| 1724 | * |
||
| 1725 | * @param int|null $number <p>How many values you will take?</p> |
||
| 1726 | * |
||
| 1727 | * @return static |
||
| 1728 | * <p>(Immutable)</p> |
||
| 1729 | */ |
||
| 1730 | 28 | View Code Duplication | public function firstsImmutable(int $number = null) |
| 1743 | |||
| 1744 | /** |
||
| 1745 | * Get the first value(s) from the current array. |
||
| 1746 | * |
||
| 1747 | * @param int|null $number <p>How many values you will take?</p> |
||
| 1748 | * |
||
| 1749 | * @return static |
||
| 1750 | * <p>(Mutable)</p> |
||
| 1751 | */ |
||
| 1752 | 26 | public function firstsMutable(int $number = null) |
|
| 1763 | |||
| 1764 | /** |
||
| 1765 | * Exchanges all keys with their associated values in an array. |
||
| 1766 | * |
||
| 1767 | * @return static |
||
| 1768 | * <p>(Immutable)</p> |
||
| 1769 | */ |
||
| 1770 | 1 | public function flip() |
|
| 1778 | |||
| 1779 | /** |
||
| 1780 | * Get a value from an array (optional using dot-notation). |
||
| 1781 | * |
||
| 1782 | * @param mixed $key <p>The key to look for.</p> |
||
| 1783 | * @param mixed $fallback <p>Value to fallback to.</p> |
||
| 1784 | * @param array $array <p>The array to get from, if it's set to "null" we use the current array from the |
||
| 1785 | * class.</p> |
||
| 1786 | * |
||
| 1787 | * @return mixed|static |
||
| 1788 | */ |
||
| 1789 | 68 | public function get($key, $fallback = null, array $array = null) |
|
| 1829 | |||
| 1830 | /** |
||
| 1831 | * Get the current array from the "Arrayy"-object. |
||
| 1832 | * |
||
| 1833 | * @return array |
||
| 1834 | */ |
||
| 1835 | 580 | public function getArray(): array |
|
| 1850 | |||
| 1851 | /** |
||
| 1852 | * Get the current array from the "Arrayy"-object as generator. |
||
| 1853 | * |
||
| 1854 | * @return \Generator |
||
| 1855 | */ |
||
| 1856 | 125 | public function getGenerator(): \Generator |
|
| 1860 | |||
| 1861 | /** |
||
| 1862 | * Returns the values from a single column of the input array, identified by |
||
| 1863 | * the $columnKey, can be used to extract data-columns from multi-arrays. |
||
| 1864 | * |
||
| 1865 | * Info: Optionally, you may provide an $indexKey to index the values in the returned |
||
| 1866 | * array by the values from the $indexKey column in the input array. |
||
| 1867 | * |
||
| 1868 | * @param mixed $columnKey |
||
| 1869 | * @param mixed $indexKey |
||
| 1870 | * |
||
| 1871 | * @return static |
||
| 1872 | * <p>(Immutable)</p> |
||
| 1873 | */ |
||
| 1874 | 1 | public function getColumn($columnKey = null, $indexKey = null) |
|
| 1882 | |||
| 1883 | /** |
||
| 1884 | * Get correct PHP constant for direction. |
||
| 1885 | * |
||
| 1886 | * @param int|string $direction |
||
| 1887 | * |
||
| 1888 | * @return int |
||
| 1889 | */ |
||
| 1890 | 39 | protected function getDirection($direction): int |
|
| 1912 | |||
| 1913 | /** |
||
| 1914 | * alias: for "Arrayy->keys()" |
||
| 1915 | * |
||
| 1916 | * @see Arrayy::keys() |
||
| 1917 | * |
||
| 1918 | * @return static |
||
| 1919 | * <p>(Immutable)</p> |
||
| 1920 | */ |
||
| 1921 | 1 | public function getKeys() |
|
| 1925 | |||
| 1926 | /** |
||
| 1927 | * Get the current array from the "Arrayy"-object as object. |
||
| 1928 | * |
||
| 1929 | * @return \stdClass |
||
| 1930 | */ |
||
| 1931 | 4 | public function getObject(): \stdClass |
|
| 1935 | |||
| 1936 | /** |
||
| 1937 | * @return array|Property[] |
||
| 1938 | */ |
||
| 1939 | 9 | protected function getPublicProperties(): array |
|
| 1961 | |||
| 1962 | /** |
||
| 1963 | * alias: for "Arrayy->randomImmutable()" |
||
| 1964 | * |
||
| 1965 | * @see Arrayy::randomImmutable() |
||
| 1966 | * |
||
| 1967 | * @return static |
||
| 1968 | * <p>(Immutable)</p> |
||
| 1969 | */ |
||
| 1970 | 4 | public function getRandom() |
|
| 1974 | |||
| 1975 | /** |
||
| 1976 | * alias: for "Arrayy->randomKey()" |
||
| 1977 | * |
||
| 1978 | * @see Arrayy::randomKey() |
||
| 1979 | * |
||
| 1980 | * @return mixed |
||
| 1981 | * <p>Get a key/index or null if there wasn't a key/index.</p> |
||
| 1982 | */ |
||
| 1983 | 3 | public function getRandomKey() |
|
| 1987 | |||
| 1988 | /** |
||
| 1989 | * alias: for "Arrayy->randomKeys()" |
||
| 1990 | * |
||
| 1991 | * @see Arrayy::randomKeys() |
||
| 1992 | * |
||
| 1993 | * @param int $number |
||
| 1994 | * |
||
| 1995 | * @return static |
||
| 1996 | * <p>(Immutable)</p> |
||
| 1997 | */ |
||
| 1998 | 8 | public function getRandomKeys(int $number) |
|
| 2002 | |||
| 2003 | /** |
||
| 2004 | * alias: for "Arrayy->randomValue()" |
||
| 2005 | * |
||
| 2006 | * @see Arrayy::randomValue() |
||
| 2007 | * |
||
| 2008 | * @return mixed |
||
| 2009 | * <p>Get a random value or null if there wasn't a value.</p> |
||
| 2010 | */ |
||
| 2011 | 3 | public function getRandomValue() |
|
| 2015 | |||
| 2016 | /** |
||
| 2017 | * alias: for "Arrayy->randomValues()" |
||
| 2018 | * |
||
| 2019 | * @see Arrayy::randomValues() |
||
| 2020 | * |
||
| 2021 | * @param int $number |
||
| 2022 | * |
||
| 2023 | * @return static |
||
| 2024 | * <p>(Immutable)</p> |
||
| 2025 | */ |
||
| 2026 | 6 | public function getRandomValues(int $number) |
|
| 2030 | |||
| 2031 | /** |
||
| 2032 | * Group values from a array according to the results of a closure. |
||
| 2033 | * |
||
| 2034 | * @param \callable $grouper <p>A callable function name.</p> |
||
| 2035 | * @param bool $saveKeys |
||
| 2036 | * |
||
| 2037 | * @return static |
||
| 2038 | * <p>(Immutable)</p> |
||
| 2039 | */ |
||
| 2040 | 4 | public function group($grouper, bool $saveKeys = false) |
|
| 2072 | |||
| 2073 | /** |
||
| 2074 | * Check if an array has a given key. |
||
| 2075 | * |
||
| 2076 | * @param mixed $key |
||
| 2077 | * |
||
| 2078 | * @return bool |
||
| 2079 | */ |
||
| 2080 | 23 | public function has($key): bool |
|
| 2091 | |||
| 2092 | /** |
||
| 2093 | * Implodes the values of this array. |
||
| 2094 | * |
||
| 2095 | * @param string $glue |
||
| 2096 | * |
||
| 2097 | * @return string |
||
| 2098 | */ |
||
| 2099 | 27 | public function implode(string $glue = ''): string |
|
| 2103 | |||
| 2104 | /** |
||
| 2105 | * Implodes the keys of this array. |
||
| 2106 | * |
||
| 2107 | * @param string $glue |
||
| 2108 | * |
||
| 2109 | * @return string |
||
| 2110 | */ |
||
| 2111 | 8 | public function implodeKeys(string $glue = ''): string |
|
| 2115 | |||
| 2116 | /** |
||
| 2117 | * @param mixed $glue |
||
| 2118 | * @param array|static|string $pieces |
||
| 2119 | * @param bool $useKeys |
||
| 2120 | * |
||
| 2121 | * @return string |
||
| 2122 | */ |
||
| 2123 | 35 | protected function implode_recursive($glue = '', $pieces = [], bool $useKeys = false): string |
|
| 2145 | |||
| 2146 | /** |
||
| 2147 | * @param mixed $needle <p> |
||
| 2148 | * The searched value. |
||
| 2149 | * </p> |
||
| 2150 | * <p> |
||
| 2151 | * If needle is a string, the comparison is done |
||
| 2152 | * in a case-sensitive manner. |
||
| 2153 | * </p> |
||
| 2154 | * @param array|\Generator|null $haystack <p> |
||
| 2155 | * The array. |
||
| 2156 | * </p> |
||
| 2157 | * @param bool $strict [optional] <p> |
||
| 2158 | * If the third parameter strict is set to true |
||
| 2159 | * then the in_array function will also check the |
||
| 2160 | * types of the |
||
| 2161 | * needle in the haystack. |
||
| 2162 | * </p> |
||
| 2163 | * |
||
| 2164 | * @return bool |
||
| 2165 | * <p>true if needle is found in the array, false otherwise</p> |
||
| 2166 | */ |
||
| 2167 | 44 | protected function in_array_recursive($needle, $haystack = null, $strict = true): bool |
|
| 2187 | |||
| 2188 | /** |
||
| 2189 | * Given a list and an iterate-function that returns |
||
| 2190 | * a key for each element in the list (or a property name), |
||
| 2191 | * returns an object with an index of each item. |
||
| 2192 | * |
||
| 2193 | * @param mixed $key |
||
| 2194 | * |
||
| 2195 | * @return static |
||
| 2196 | * <p>(Immutable)</p> |
||
| 2197 | */ |
||
| 2198 | 4 | public function indexBy($key) |
|
| 2211 | |||
| 2212 | /** |
||
| 2213 | * alias: for "Arrayy->searchIndex()" |
||
| 2214 | * |
||
| 2215 | * @see Arrayy::searchIndex() |
||
| 2216 | * |
||
| 2217 | * @param mixed $value <p>The value to search for.</p> |
||
| 2218 | * |
||
| 2219 | * @return mixed |
||
| 2220 | */ |
||
| 2221 | 4 | public function indexOf($value) |
|
| 2225 | |||
| 2226 | /** |
||
| 2227 | * Get everything but the last..$to items. |
||
| 2228 | * |
||
| 2229 | * @param int $to |
||
| 2230 | * |
||
| 2231 | * @return static |
||
| 2232 | * <p>(Immutable)</p> |
||
| 2233 | */ |
||
| 2234 | 12 | public function initial(int $to = 1) |
|
| 2238 | |||
| 2239 | /** |
||
| 2240 | * @param mixed $value |
||
| 2241 | */ |
||
| 2242 | protected function internalGetArray(&$value) |
||
| 2266 | |||
| 2267 | /** |
||
| 2268 | * Internal mechanics of remove method. |
||
| 2269 | * |
||
| 2270 | * @param mixed $key |
||
| 2271 | * |
||
| 2272 | * @return bool |
||
| 2273 | */ |
||
| 2274 | 18 | protected function internalRemove($key): bool |
|
| 2295 | |||
| 2296 | /** |
||
| 2297 | * Internal mechanic of set method. |
||
| 2298 | * |
||
| 2299 | * @param string|null $key |
||
| 2300 | * @param mixed $value |
||
| 2301 | * |
||
| 2302 | * @return bool |
||
| 2303 | */ |
||
| 2304 | 778 | protected function internalSet($key, $value): bool |
|
| 2333 | |||
| 2334 | /** |
||
| 2335 | * Return an array with all elements found in input array. |
||
| 2336 | * |
||
| 2337 | * @param array $search |
||
| 2338 | * |
||
| 2339 | * @return static |
||
| 2340 | * <p>(Immutable)</p> |
||
| 2341 | */ |
||
| 2342 | 2 | public function intersection(array $search) |
|
| 2350 | |||
| 2351 | /** |
||
| 2352 | * Return a boolean flag which indicates whether the two input arrays have any common elements. |
||
| 2353 | * |
||
| 2354 | * @param array $search |
||
| 2355 | * |
||
| 2356 | * @return bool |
||
| 2357 | */ |
||
| 2358 | 1 | public function intersects(array $search): bool |
|
| 2362 | |||
| 2363 | /** |
||
| 2364 | * Invoke a function on all of an array's values. |
||
| 2365 | * |
||
| 2366 | * @param mixed $callable |
||
| 2367 | * @param mixed $arguments |
||
| 2368 | * |
||
| 2369 | * @return static |
||
| 2370 | * <p>(Immutable)</p> |
||
| 2371 | */ |
||
| 2372 | 1 | public function invoke($callable, $arguments = []) |
|
| 2391 | |||
| 2392 | /** |
||
| 2393 | * Check whether array is associative or not. |
||
| 2394 | * |
||
| 2395 | * @param bool $recursive |
||
| 2396 | * |
||
| 2397 | * @return bool |
||
| 2398 | * <p>Returns true if associative, false otherwise.</p> |
||
| 2399 | */ |
||
| 2400 | 15 | public function isAssoc(bool $recursive = false): bool |
|
| 2414 | |||
| 2415 | /** |
||
| 2416 | * Check whether the array is empty or not. |
||
| 2417 | * |
||
| 2418 | * @return bool |
||
| 2419 | * <p>Returns true if empty, false otherwise.</p> |
||
| 2420 | */ |
||
| 2421 | 92 | public function isEmpty(): bool |
|
| 2425 | |||
| 2426 | /** |
||
| 2427 | * Check if the current array is equal to the given "$array" or not. |
||
| 2428 | * |
||
| 2429 | * @param array $array |
||
| 2430 | * |
||
| 2431 | * @return bool |
||
| 2432 | */ |
||
| 2433 | public function isEqual(array $array): bool |
||
| 2437 | |||
| 2438 | /** |
||
| 2439 | * Check if the current array is a multi-array. |
||
| 2440 | * |
||
| 2441 | * @return bool |
||
| 2442 | */ |
||
| 2443 | 14 | public function isMultiArray(): bool |
|
| 2451 | |||
| 2452 | /** |
||
| 2453 | * Check whether array is numeric or not. |
||
| 2454 | * |
||
| 2455 | * @return bool |
||
| 2456 | * <p>Returns true if numeric, false otherwise.</p> |
||
| 2457 | */ |
||
| 2458 | 5 | public function isNumeric(): bool |
|
| 2472 | |||
| 2473 | /** |
||
| 2474 | * Check if the current array is sequential [0, 1, 2, 3, 4, 5 ...] or not. |
||
| 2475 | * |
||
| 2476 | * @param bool $recursive |
||
| 2477 | * |
||
| 2478 | * @return bool |
||
| 2479 | */ |
||
| 2480 | 1 | public function isSequential(bool $recursive = false): bool |
|
| 2497 | |||
| 2498 | /** |
||
| 2499 | * @return array |
||
| 2500 | */ |
||
| 2501 | public function jsonSerialize(): array |
||
| 2505 | |||
| 2506 | /** |
||
| 2507 | * Get all keys from the current array. |
||
| 2508 | * |
||
| 2509 | * @param bool $recursive [optional] <p> |
||
| 2510 | * Get all keys, also from all sub-arrays from an multi-dimensional array. |
||
| 2511 | * </p> |
||
| 2512 | * @param mixed $search_value [optional] <p> |
||
| 2513 | * If specified, then only keys containing these values are returned. |
||
| 2514 | * </p> |
||
| 2515 | * @param bool $strict [optional] <p> |
||
| 2516 | * Determines if strict comparison (===) should be used during the search. |
||
| 2517 | * </p> |
||
| 2518 | * |
||
| 2519 | * @return static |
||
| 2520 | * <p>(Immutable) An array of all the keys in input.</p> |
||
| 2521 | */ |
||
| 2522 | 26 | public function keys(bool $recursive = false, $search_value = null, bool $strict = true) |
|
| 2547 | |||
| 2548 | /** |
||
| 2549 | * Sort an array by key in reverse order. |
||
| 2550 | * |
||
| 2551 | * @param int $sort_flags [optional] <p> |
||
| 2552 | * You may modify the behavior of the sort using the optional |
||
| 2553 | * parameter sort_flags, for details |
||
| 2554 | * see sort. |
||
| 2555 | * </p> |
||
| 2556 | * |
||
| 2557 | * @return static |
||
| 2558 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 2559 | */ |
||
| 2560 | 4 | public function krsort(int $sort_flags = 0) |
|
| 2566 | |||
| 2567 | /** |
||
| 2568 | * Get the last value from the current array. |
||
| 2569 | * |
||
| 2570 | * @return mixed |
||
| 2571 | * <p>Return null if there wasn't a element.</p> |
||
| 2572 | */ |
||
| 2573 | 4 | public function last() |
|
| 2577 | |||
| 2578 | /** |
||
| 2579 | * Get the last value(s) from the current array. |
||
| 2580 | * |
||
| 2581 | * @param int|null $number |
||
| 2582 | * |
||
| 2583 | * @return static |
||
| 2584 | * <p>(Immutable)</p> |
||
| 2585 | */ |
||
| 2586 | 13 | public function lastsImmutable(int $number = null) |
|
| 2609 | |||
| 2610 | /** |
||
| 2611 | * Get the last value(s) from the current array. |
||
| 2612 | * |
||
| 2613 | * @param int|null $number |
||
| 2614 | * |
||
| 2615 | * @return static |
||
| 2616 | * <p>(Mutable)</p> |
||
| 2617 | */ |
||
| 2618 | 13 | public function lastsMutable(int $number = null) |
|
| 2641 | |||
| 2642 | /** |
||
| 2643 | * Count the values from the current array. |
||
| 2644 | * |
||
| 2645 | * alias: for "Arrayy->count()" |
||
| 2646 | * |
||
| 2647 | * @see Arrayy::count() |
||
| 2648 | * |
||
| 2649 | * @param int $mode |
||
| 2650 | * |
||
| 2651 | * @return int |
||
| 2652 | */ |
||
| 2653 | 20 | public function length(int $mode = \COUNT_NORMAL): int |
|
| 2657 | |||
| 2658 | /** |
||
| 2659 | * Apply the given function to the every element of the array, |
||
| 2660 | * collecting the results. |
||
| 2661 | * |
||
| 2662 | * @param \callable $callable |
||
| 2663 | * |
||
| 2664 | * @return static |
||
| 2665 | * <p>(Immutable) Arrayy object with modified elements.</p> |
||
| 2666 | */ |
||
| 2667 | 4 | public function map($callable) |
|
| 2675 | |||
| 2676 | /** |
||
| 2677 | * Check if all items in current array match a truth test. |
||
| 2678 | * |
||
| 2679 | * @param \Closure $closure |
||
| 2680 | * |
||
| 2681 | * @return bool |
||
| 2682 | */ |
||
| 2683 | 15 | View Code Duplication | public function matches(\Closure $closure): bool |
| 2699 | |||
| 2700 | /** |
||
| 2701 | * Check if any item in the current array matches a truth test. |
||
| 2702 | * |
||
| 2703 | * @param \Closure $closure |
||
| 2704 | * |
||
| 2705 | * @return bool |
||
| 2706 | */ |
||
| 2707 | 14 | View Code Duplication | public function matchesAny(\Closure $closure): bool |
| 2723 | |||
| 2724 | /** |
||
| 2725 | * Get the max value from an array. |
||
| 2726 | * |
||
| 2727 | * @return mixed |
||
| 2728 | */ |
||
| 2729 | 10 | View Code Duplication | public function max() |
| 2737 | |||
| 2738 | /** |
||
| 2739 | * Merge the new $array into the current array. |
||
| 2740 | * |
||
| 2741 | * - keep key,value from the current array, also if the index is in the new $array |
||
| 2742 | * |
||
| 2743 | * @param array $array |
||
| 2744 | * @param bool $recursive |
||
| 2745 | * |
||
| 2746 | * @return static |
||
| 2747 | * <p>(Immutable)</p> |
||
| 2748 | */ |
||
| 2749 | 25 | View Code Duplication | public function mergeAppendKeepIndex(array $array = [], bool $recursive = false) |
| 2759 | |||
| 2760 | /** |
||
| 2761 | * Merge the new $array into the current array. |
||
| 2762 | * |
||
| 2763 | * - replace duplicate assoc-keys from the current array with the key,values from the new $array |
||
| 2764 | * - create new indexes |
||
| 2765 | * |
||
| 2766 | * @param array $array |
||
| 2767 | * @param bool $recursive |
||
| 2768 | * |
||
| 2769 | * @return static |
||
| 2770 | * <p>(Immutable)</p> |
||
| 2771 | */ |
||
| 2772 | 16 | View Code Duplication | public function mergeAppendNewIndex(array $array = [], bool $recursive = false) |
| 2782 | |||
| 2783 | /** |
||
| 2784 | * Merge the the current array into the $array. |
||
| 2785 | * |
||
| 2786 | * - use key,value from the new $array, also if the index is in the current array |
||
| 2787 | * |
||
| 2788 | * @param array $array |
||
| 2789 | * @param bool $recursive |
||
| 2790 | * |
||
| 2791 | * @return static |
||
| 2792 | * <p>(Immutable)</p> |
||
| 2793 | */ |
||
| 2794 | 16 | View Code Duplication | public function mergePrependKeepIndex(array $array = [], bool $recursive = false) |
| 2804 | |||
| 2805 | /** |
||
| 2806 | * Merge the current array into the new $array. |
||
| 2807 | * |
||
| 2808 | * - replace duplicate assoc-keys from new $array with the key,values from the current array |
||
| 2809 | * - create new indexes |
||
| 2810 | * |
||
| 2811 | * @param array $array |
||
| 2812 | * @param bool $recursive |
||
| 2813 | * |
||
| 2814 | * @return static |
||
| 2815 | * <p>(Immutable)</p> |
||
| 2816 | */ |
||
| 2817 | 17 | View Code Duplication | public function mergePrependNewIndex(array $array = [], bool $recursive = false) |
| 2827 | |||
| 2828 | /** |
||
| 2829 | * @return ArrayyMeta|static |
||
| 2830 | */ |
||
| 2831 | 8 | public static function meta() |
|
| 2835 | |||
| 2836 | /** |
||
| 2837 | * Get the min value from an array. |
||
| 2838 | * |
||
| 2839 | * @return mixed |
||
| 2840 | */ |
||
| 2841 | 10 | View Code Duplication | public function min() |
| 2849 | |||
| 2850 | /** |
||
| 2851 | * Move an array element to a new index. |
||
| 2852 | * |
||
| 2853 | * cherry-picked from: http://stackoverflow.com/questions/12624153/move-an-array-element-to-a-new-index-in-php |
||
| 2854 | * |
||
| 2855 | * @param int|string $from |
||
| 2856 | * @param int|string $to |
||
| 2857 | * |
||
| 2858 | * @return static |
||
| 2859 | * <p>(Immutable)</p> |
||
| 2860 | */ |
||
| 2861 | 1 | public function moveElement($from, $to) |
|
| 2888 | |||
| 2889 | /** |
||
| 2890 | * Convert a object into an array. |
||
| 2891 | * |
||
| 2892 | * @param object $object |
||
| 2893 | * |
||
| 2894 | * @return mixed |
||
| 2895 | */ |
||
| 2896 | 5 | protected static function objectToArray($object) |
|
| 2908 | |||
| 2909 | /** |
||
| 2910 | * Get a subset of the items from the given array. |
||
| 2911 | * |
||
| 2912 | * @param mixed[] $keys |
||
| 2913 | * |
||
| 2914 | * @return static |
||
| 2915 | * <p>(Immutable)</p> |
||
| 2916 | */ |
||
| 2917 | public function only(array $keys) |
||
| 2927 | |||
| 2928 | /** |
||
| 2929 | * Pad array to the specified size with a given value. |
||
| 2930 | * |
||
| 2931 | * @param int $size <p>Size of the result array.</p> |
||
| 2932 | * @param mixed $value <p>Empty value by default.</p> |
||
| 2933 | * |
||
| 2934 | * @return static |
||
| 2935 | * <p>(Immutable) Arrayy object padded to $size with $value.</p> |
||
| 2936 | */ |
||
| 2937 | 4 | public function pad(int $size, $value) |
|
| 2945 | |||
| 2946 | /** |
||
| 2947 | * Pop a specified value off the end of the current array. |
||
| 2948 | * |
||
| 2949 | * @return mixed |
||
| 2950 | * <p>(Mutable) The popped element from the current array.</p> |
||
| 2951 | */ |
||
| 2952 | 16 | public function pop() |
|
| 2956 | |||
| 2957 | /** |
||
| 2958 | * Prepend a (key) + value to the current array. |
||
| 2959 | * |
||
| 2960 | * @param mixed $value |
||
| 2961 | * @param mixed $key |
||
| 2962 | * |
||
| 2963 | * @return static |
||
| 2964 | * <p>(Mutable) Return this Arrayy object, with the prepended value.</p> |
||
| 2965 | */ |
||
| 2966 | 8 | public function prepend($value, $key = null) |
|
| 2977 | |||
| 2978 | /** |
||
| 2979 | * Add a suffix to each key. |
||
| 2980 | * |
||
| 2981 | * @param mixed $suffix |
||
| 2982 | * |
||
| 2983 | * @return static |
||
| 2984 | * <p>(Immutable) Return an Arrayy object, with the prepended keys.</p> |
||
| 2985 | */ |
||
| 2986 | 10 | View Code Duplication | public function prependToEachKey($suffix) |
| 3003 | |||
| 3004 | /** |
||
| 3005 | * Add a suffix to each value. |
||
| 3006 | * |
||
| 3007 | * @param mixed $suffix |
||
| 3008 | * |
||
| 3009 | * @return static |
||
| 3010 | * <p>(Immutable) Return an Arrayy object, with the prepended values.</p> |
||
| 3011 | */ |
||
| 3012 | 10 | View Code Duplication | public function prependToEachValue($suffix) |
| 3033 | |||
| 3034 | /** |
||
| 3035 | * Push one or more values onto the end of array at once. |
||
| 3036 | * |
||
| 3037 | * @return static |
||
| 3038 | * <p>(Mutable) Return this Arrayy object, with pushed elements to the end of array.</p> |
||
| 3039 | */ |
||
| 3040 | 4 | View Code Duplication | public function push(/* variadic arguments allowed */) |
| 3049 | |||
| 3050 | /** |
||
| 3051 | * Get a random value from the current array. |
||
| 3052 | * |
||
| 3053 | * @param int|null $number <p>How many values you will take?</p> |
||
| 3054 | * |
||
| 3055 | * @return static |
||
| 3056 | * <p>(Immutable)</p> |
||
| 3057 | */ |
||
| 3058 | 18 | public function randomImmutable(int $number = null) |
|
| 3077 | |||
| 3078 | /** |
||
| 3079 | * Pick a random key/index from the keys of this array. |
||
| 3080 | * |
||
| 3081 | * @throws \RangeException If array is empty |
||
| 3082 | * |
||
| 3083 | * @return mixed |
||
| 3084 | * <p>Get a key/index or null if there wasn't a key/index.</p> |
||
| 3085 | */ |
||
| 3086 | 4 | public function randomKey() |
|
| 3096 | |||
| 3097 | /** |
||
| 3098 | * Pick a given number of random keys/indexes out of this array. |
||
| 3099 | * |
||
| 3100 | * @param int $number <p>The number of keys/indexes (should be <= \count($this->array))</p> |
||
| 3101 | * |
||
| 3102 | * @throws \RangeException If array is empty |
||
| 3103 | * |
||
| 3104 | * @return static |
||
| 3105 | * <p>(Immutable)</p> |
||
| 3106 | */ |
||
| 3107 | 13 | public function randomKeys(int $number) |
|
| 3125 | |||
| 3126 | /** |
||
| 3127 | * Get a random value from the current array. |
||
| 3128 | * |
||
| 3129 | * @param int|null $number <p>How many values you will take?</p> |
||
| 3130 | * |
||
| 3131 | * @return static |
||
| 3132 | * <p>(Mutable)</p> |
||
| 3133 | */ |
||
| 3134 | 17 | public function randomMutable(int $number = null) |
|
| 3153 | |||
| 3154 | /** |
||
| 3155 | * Pick a random value from the values of this array. |
||
| 3156 | * |
||
| 3157 | * @return mixed |
||
| 3158 | * <p>Get a random value or null if there wasn't a value.</p> |
||
| 3159 | */ |
||
| 3160 | 4 | public function randomValue() |
|
| 3170 | |||
| 3171 | /** |
||
| 3172 | * Pick a given number of random values out of this array. |
||
| 3173 | * |
||
| 3174 | * @param int $number |
||
| 3175 | * |
||
| 3176 | * @return static |
||
| 3177 | * <p>(Mutable)</p> |
||
| 3178 | */ |
||
| 3179 | 7 | public function randomValues(int $number) |
|
| 3183 | |||
| 3184 | /** |
||
| 3185 | * Get a random value from an array, with the ability to skew the results. |
||
| 3186 | * |
||
| 3187 | * Example: randomWeighted(['foo' => 1, 'bar' => 2]) has a 66% chance of returning bar. |
||
| 3188 | * |
||
| 3189 | * @param array $array |
||
| 3190 | * @param int|null $number <p>How many values you will take?</p> |
||
| 3191 | * |
||
| 3192 | * @return static |
||
| 3193 | * <p>(Immutable)</p> |
||
| 3194 | */ |
||
| 3195 | 9 | public function randomWeighted(array $array, int $number = null) |
|
| 3210 | |||
| 3211 | /** |
||
| 3212 | * Reduce the current array via callable e.g. anonymous-function. |
||
| 3213 | * |
||
| 3214 | * @param \callable $callable |
||
| 3215 | * @param array $init |
||
| 3216 | * |
||
| 3217 | * @return static |
||
| 3218 | * <p>(Immutable)</p> |
||
| 3219 | */ |
||
| 3220 | 4 | public function reduce($callable, array $init = []) |
|
| 3232 | |||
| 3233 | /** |
||
| 3234 | * Create a numerically re-indexed Arrayy object. |
||
| 3235 | * |
||
| 3236 | * @return static |
||
| 3237 | * <p>(Mutable) Return this Arrayy object, with re-indexed array-elements.</p> |
||
| 3238 | */ |
||
| 3239 | 9 | public function reindex() |
|
| 3245 | |||
| 3246 | /** |
||
| 3247 | * Return all items that fail the truth test. |
||
| 3248 | * |
||
| 3249 | * @param \Closure $closure |
||
| 3250 | * |
||
| 3251 | * @return static |
||
| 3252 | * <p>(Immutable)</p> |
||
| 3253 | */ |
||
| 3254 | 1 | View Code Duplication | public function reject(\Closure $closure) |
| 3266 | |||
| 3267 | /** |
||
| 3268 | * Remove a value from the current array (optional using dot-notation). |
||
| 3269 | * |
||
| 3270 | * @param mixed $key |
||
| 3271 | * |
||
| 3272 | * @return static |
||
| 3273 | * <p>(Immutable)</p> |
||
| 3274 | */ |
||
| 3275 | 18 | public function remove($key) |
|
| 3290 | |||
| 3291 | /** |
||
| 3292 | * Remove the first value from the current array. |
||
| 3293 | * |
||
| 3294 | * @return static |
||
| 3295 | * <p>(Immutable)</p> |
||
| 3296 | */ |
||
| 3297 | 7 | public function removeFirst() |
|
| 3304 | |||
| 3305 | /** |
||
| 3306 | * Remove the last value from the current array. |
||
| 3307 | * |
||
| 3308 | * @return static |
||
| 3309 | * <p>(Immutable)</p> |
||
| 3310 | */ |
||
| 3311 | 7 | public function removeLast() |
|
| 3318 | |||
| 3319 | /** |
||
| 3320 | * Removes a particular value from an array (numeric or associative). |
||
| 3321 | * |
||
| 3322 | * @param mixed $value |
||
| 3323 | * |
||
| 3324 | * @return static |
||
| 3325 | * <p>(Immutable)</p> |
||
| 3326 | */ |
||
| 3327 | 7 | public function removeValue($value) |
|
| 3345 | |||
| 3346 | /** |
||
| 3347 | * Generate array of repeated arrays. |
||
| 3348 | * |
||
| 3349 | * @param int $times <p>How many times has to be repeated.</p> |
||
| 3350 | * |
||
| 3351 | * @return static |
||
| 3352 | * <p>(Immutable)</p> |
||
| 3353 | */ |
||
| 3354 | 1 | public function repeat($times): self |
|
| 3366 | |||
| 3367 | /** |
||
| 3368 | * Replace a key with a new key/value pair. |
||
| 3369 | * |
||
| 3370 | * @param mixed $replace |
||
| 3371 | * @param mixed $key |
||
| 3372 | * @param mixed $value |
||
| 3373 | * |
||
| 3374 | * @return static |
||
| 3375 | * <p>(Immutable)</p> |
||
| 3376 | */ |
||
| 3377 | 2 | public function replace($replace, $key, $value) |
|
| 3383 | |||
| 3384 | /** |
||
| 3385 | * Create an array using the current array as values and the other array as keys. |
||
| 3386 | * |
||
| 3387 | * @param array $keys <p>An array of keys.</p> |
||
| 3388 | * |
||
| 3389 | * @return static |
||
| 3390 | * <p>(Immutable) Arrayy object with keys from the other array.</p> |
||
| 3391 | */ |
||
| 3392 | 2 | public function replaceAllKeys(array $keys) |
|
| 3400 | |||
| 3401 | /** |
||
| 3402 | * Create an array using the current array as keys and the other array as values. |
||
| 3403 | * |
||
| 3404 | * @param array $array <p>An array o values.</p> |
||
| 3405 | * |
||
| 3406 | * @return static |
||
| 3407 | * <p>(Immutable) Arrayy object with values from the other array.</p> |
||
| 3408 | */ |
||
| 3409 | 2 | public function replaceAllValues(array $array) |
|
| 3417 | |||
| 3418 | /** |
||
| 3419 | * Replace the keys in an array with another set. |
||
| 3420 | * |
||
| 3421 | * @param array $keys <p>An array of keys matching the array's size</p> |
||
| 3422 | * |
||
| 3423 | * @return static |
||
| 3424 | * <p>(Immutable)</p> |
||
| 3425 | */ |
||
| 3426 | 1 | public function replaceKeys(array $keys) |
|
| 3433 | |||
| 3434 | /** |
||
| 3435 | * Replace the first matched value in an array. |
||
| 3436 | * |
||
| 3437 | * @param mixed $search <p>The value to replace.</p> |
||
| 3438 | * @param mixed $replacement <p>The value to replace.</p> |
||
| 3439 | * |
||
| 3440 | * @return static |
||
| 3441 | * <p>(Immutable)</p> |
||
| 3442 | */ |
||
| 3443 | 3 | public function replaceOneValue($search, $replacement = '') |
|
| 3454 | |||
| 3455 | /** |
||
| 3456 | * Replace values in the current array. |
||
| 3457 | * |
||
| 3458 | * @param mixed $search <p>The value to replace.</p> |
||
| 3459 | * @param mixed $replacement <p>What to replace it with.</p> |
||
| 3460 | * |
||
| 3461 | * @return static |
||
| 3462 | * <p>(Immutable)</p> |
||
| 3463 | */ |
||
| 3464 | 1 | public function replaceValues($search, $replacement = '') |
|
| 3474 | |||
| 3475 | /** |
||
| 3476 | * Get the last elements from index $from until the end of this array. |
||
| 3477 | * |
||
| 3478 | * @param int $from |
||
| 3479 | * |
||
| 3480 | * @return static |
||
| 3481 | * <p>(Immutable)</p> |
||
| 3482 | */ |
||
| 3483 | 15 | public function rest(int $from = 1) |
|
| 3493 | |||
| 3494 | /** |
||
| 3495 | * Return the array in the reverse order. |
||
| 3496 | * |
||
| 3497 | * @return static |
||
| 3498 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 3499 | */ |
||
| 3500 | 8 | public function reverse() |
|
| 3506 | |||
| 3507 | /** |
||
| 3508 | * Sort an array in reverse order. |
||
| 3509 | * |
||
| 3510 | * @param int $sort_flags [optional] <p> |
||
| 3511 | * You may modify the behavior of the sort using the optional |
||
| 3512 | * parameter sort_flags, for details |
||
| 3513 | * see sort. |
||
| 3514 | * </p> |
||
| 3515 | * |
||
| 3516 | * @return static |
||
| 3517 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 3518 | */ |
||
| 3519 | 4 | public function rsort(int $sort_flags = 0) |
|
| 3525 | |||
| 3526 | /** |
||
| 3527 | * Search for the first index of the current array via $value. |
||
| 3528 | * |
||
| 3529 | * @param mixed $value |
||
| 3530 | * |
||
| 3531 | * @return float|int|string |
||
| 3532 | */ |
||
| 3533 | 20 | public function searchIndex($value) |
|
| 3537 | |||
| 3538 | /** |
||
| 3539 | * Search for the value of the current array via $index. |
||
| 3540 | * |
||
| 3541 | * @param mixed $index |
||
| 3542 | * |
||
| 3543 | * @return static |
||
| 3544 | * <p>(Immutable) Will return a empty Arrayy if the value wasn't found.</p> |
||
| 3545 | */ |
||
| 3546 | 9 | public function searchValue($index) |
|
| 3566 | |||
| 3567 | /** |
||
| 3568 | * Set a value for the current array (optional using dot-notation). |
||
| 3569 | * |
||
| 3570 | * @param string $key <p>The key to set.</p> |
||
| 3571 | * @param mixed $value <p>Its value.</p> |
||
| 3572 | * |
||
| 3573 | * @return static |
||
| 3574 | * <p>(Mutable)</p> |
||
| 3575 | */ |
||
| 3576 | 17 | public function set($key, $value) |
|
| 3582 | |||
| 3583 | /** |
||
| 3584 | * Get a value from a array and set it if it was not. |
||
| 3585 | * |
||
| 3586 | * WARNING: this method only set the value, if the $key is not already set |
||
| 3587 | * |
||
| 3588 | * @param mixed $key <p>The key</p> |
||
| 3589 | * @param mixed $fallback <p>The default value to set if it isn't.</p> |
||
| 3590 | * |
||
| 3591 | * @return mixed |
||
| 3592 | * <p>(Mutable)</p> |
||
| 3593 | */ |
||
| 3594 | 11 | public function setAndGet($key, $fallback = null) |
|
| 3603 | |||
| 3604 | /** |
||
| 3605 | * Shifts a specified value off the beginning of array. |
||
| 3606 | * |
||
| 3607 | * @return mixed |
||
| 3608 | * <p>(Mutable) A shifted element from the current array.</p> |
||
| 3609 | */ |
||
| 3610 | 4 | public function shift() |
|
| 3614 | |||
| 3615 | /** |
||
| 3616 | * Shuffle the current array. |
||
| 3617 | * |
||
| 3618 | * @param bool $secure <p>using a CSPRNG | @link https://paragonie.com/b/JvICXzh_jhLyt4y3</p> |
||
| 3619 | * @param array $array [optional] |
||
| 3620 | * |
||
| 3621 | * @return static |
||
| 3622 | * <p>(Immutable)</p> |
||
| 3623 | */ |
||
| 3624 | 1 | public function shuffle(bool $secure = false, array $array = null) |
|
| 3662 | |||
| 3663 | /** |
||
| 3664 | * Count the values from the current array. |
||
| 3665 | * |
||
| 3666 | * alias: for "Arrayy->count()" |
||
| 3667 | * |
||
| 3668 | * @param int $mode |
||
| 3669 | * |
||
| 3670 | * @return int |
||
| 3671 | */ |
||
| 3672 | 20 | public function size(int $mode = \COUNT_NORMAL): int |
|
| 3676 | |||
| 3677 | /** |
||
| 3678 | * Counts all elements in an array, or something in an object. |
||
| 3679 | * |
||
| 3680 | * <p> |
||
| 3681 | * For objects, if you have SPL installed, you can hook into count() by implementing interface {@see Countable}. |
||
| 3682 | * The interface has exactly one method, {@see Countable::count()}, which returns the return value for the count() |
||
| 3683 | * function. Please see the {@see Array} section of the manual for a detailed explanation of how arrays are |
||
| 3684 | * implemented and used in PHP. |
||
| 3685 | * </p> |
||
| 3686 | * |
||
| 3687 | * @return int |
||
| 3688 | * <p> |
||
| 3689 | * The number of elements in var, which is |
||
| 3690 | * typically an array, since anything else will have one |
||
| 3691 | * element. |
||
| 3692 | * </p> |
||
| 3693 | * <p> |
||
| 3694 | * If var is not an array or an object with |
||
| 3695 | * implemented Countable interface, |
||
| 3696 | * 1 will be returned. |
||
| 3697 | * There is one exception, if var is &null;, |
||
| 3698 | * 0 will be returned. |
||
| 3699 | * </p> |
||
| 3700 | * <p> |
||
| 3701 | * Caution: count may return 0 for a variable that isn't set, |
||
| 3702 | * but it may also return 0 for a variable that has been initialized with an |
||
| 3703 | * empty array. Use isset to test if a variable is set. |
||
| 3704 | * </p> |
||
| 3705 | */ |
||
| 3706 | 10 | public function sizeRecursive(): int |
|
| 3710 | |||
| 3711 | /** |
||
| 3712 | * Extract a slice of the array. |
||
| 3713 | * |
||
| 3714 | * @param int $offset <p>Slice begin index.</p> |
||
| 3715 | * @param int|null $length <p>Length of the slice.</p> |
||
| 3716 | * @param bool $preserveKeys <p>Whether array keys are preserved or no.</p> |
||
| 3717 | * |
||
| 3718 | * @return static |
||
| 3719 | * <p>A slice of the original array with length $length.</p> |
||
| 3720 | */ |
||
| 3721 | 4 | public function slice(int $offset, int $length = null, bool $preserveKeys = false) |
|
| 3729 | |||
| 3730 | /** |
||
| 3731 | * Sort the current array and optional you can keep the keys. |
||
| 3732 | * |
||
| 3733 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 3734 | * @param int $strategy <p>sort_flags => use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 3735 | * <strong>SORT_NATURAL</strong></p> |
||
| 3736 | * @param bool $keepKeys |
||
| 3737 | * |
||
| 3738 | * @return static |
||
| 3739 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 3740 | */ |
||
| 3741 | 20 | public function sort($direction = \SORT_ASC, int $strategy = \SORT_REGULAR, bool $keepKeys = false) |
|
| 3745 | |||
| 3746 | /** |
||
| 3747 | * Sort the current array by key. |
||
| 3748 | * |
||
| 3749 | * @see http://php.net/manual/en/function.ksort.php |
||
| 3750 | * @see http://php.net/manual/en/function.krsort.php |
||
| 3751 | * |
||
| 3752 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 3753 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 3754 | * <strong>SORT_NATURAL</strong></p> |
||
| 3755 | * |
||
| 3756 | * @return static |
||
| 3757 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 3758 | */ |
||
| 3759 | 18 | public function sortKeys($direction = \SORT_ASC, int $strategy = \SORT_REGULAR) |
|
| 3766 | |||
| 3767 | /** |
||
| 3768 | * Sort the current array by value. |
||
| 3769 | * |
||
| 3770 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 3771 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 3772 | * <strong>SORT_NATURAL</strong></p> |
||
| 3773 | * |
||
| 3774 | * @return static |
||
| 3775 | * <p>(Mutable)</p> |
||
| 3776 | */ |
||
| 3777 | 1 | public function sortValueKeepIndex($direction = \SORT_ASC, int $strategy = \SORT_REGULAR) |
|
| 3781 | |||
| 3782 | /** |
||
| 3783 | * Sort the current array by value. |
||
| 3784 | * |
||
| 3785 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 3786 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 3787 | * <strong>SORT_NATURAL</strong></p> |
||
| 3788 | * |
||
| 3789 | * @return static |
||
| 3790 | * <p>(Mutable)</p> |
||
| 3791 | */ |
||
| 3792 | 1 | public function sortValueNewIndex($direction = \SORT_ASC, int $strategy = \SORT_REGULAR) |
|
| 3796 | |||
| 3797 | /** |
||
| 3798 | * Sort a array by value, by a closure or by a property. |
||
| 3799 | * |
||
| 3800 | * - If the sorter is null, the array is sorted naturally. |
||
| 3801 | * - Associative (string) keys will be maintained, but numeric keys will be re-indexed. |
||
| 3802 | * |
||
| 3803 | * @param \callable|null $sorter |
||
| 3804 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 3805 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 3806 | * <strong>SORT_NATURAL</strong></p> |
||
| 3807 | * |
||
| 3808 | * @return static |
||
| 3809 | * <p>(Immutable)</p> |
||
| 3810 | */ |
||
| 3811 | 1 | public function sorter($sorter = null, $direction = \SORT_ASC, int $strategy = \SORT_REGULAR) |
|
| 3837 | |||
| 3838 | /** |
||
| 3839 | * sorting keys |
||
| 3840 | * |
||
| 3841 | * @param array $elements |
||
| 3842 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 3843 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 3844 | * <strong>SORT_NATURAL</strong></p> |
||
| 3845 | * |
||
| 3846 | * @return static |
||
| 3847 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 3848 | */ |
||
| 3849 | 18 | protected function sorterKeys(array &$elements, $direction = \SORT_ASC, int $strategy = \SORT_REGULAR) |
|
| 3867 | |||
| 3868 | /** |
||
| 3869 | * @param array $elements <p>Warning: used as reference</p> |
||
| 3870 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 3871 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 3872 | * <strong>SORT_NATURAL</strong></p> |
||
| 3873 | * @param bool $keepKeys |
||
| 3874 | * |
||
| 3875 | * @return static |
||
| 3876 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 3877 | */ |
||
| 3878 | 20 | protected function sorting(array &$elements, $direction = \SORT_ASC, int $strategy = \SORT_REGULAR, bool $keepKeys = false) |
|
| 3908 | |||
| 3909 | /** |
||
| 3910 | * Split an array in the given amount of pieces. |
||
| 3911 | * |
||
| 3912 | * @param int $numberOfPieces |
||
| 3913 | * @param bool $keepKeys |
||
| 3914 | * |
||
| 3915 | * @return static |
||
| 3916 | * <p>(Immutable)</p> |
||
| 3917 | */ |
||
| 3918 | 1 | View Code Duplication | public function split(int $numberOfPieces = 2, bool $keepKeys = false) |
| 3931 | |||
| 3932 | /** |
||
| 3933 | * Stripe all empty items. |
||
| 3934 | * |
||
| 3935 | * @return static |
||
| 3936 | * <p>(Immutable)</p> |
||
| 3937 | */ |
||
| 3938 | 1 | public function stripEmpty() |
|
| 3950 | |||
| 3951 | /** |
||
| 3952 | * Swap two values between positions by key. |
||
| 3953 | * |
||
| 3954 | * @param int|string $swapA <p>a key in the array</p> |
||
| 3955 | * @param int|string $swapB <p>a key in the array</p> |
||
| 3956 | * |
||
| 3957 | * @return static |
||
| 3958 | * <p>(Immutable)</p> |
||
| 3959 | */ |
||
| 3960 | 1 | public function swap($swapA, $swapB) |
|
| 3968 | |||
| 3969 | /** |
||
| 3970 | * alias: for "Arrayy->getArray()" |
||
| 3971 | * |
||
| 3972 | * @see Arrayy::getArray() |
||
| 3973 | */ |
||
| 3974 | 192 | public function toArray() |
|
| 3978 | |||
| 3979 | /** |
||
| 3980 | * Convert the current array to JSON. |
||
| 3981 | * |
||
| 3982 | * @param int $options [optional] <p>e.g. JSON_PRETTY_PRINT</p> |
||
| 3983 | * @param int $depth [optional] <p>Set the maximum depth. Must be greater than zero.</p> |
||
| 3984 | * |
||
| 3985 | * @return string |
||
| 3986 | */ |
||
| 3987 | 6 | public function toJson(int $options = 0, int $depth = 512): string |
|
| 3992 | |||
| 3993 | /** |
||
| 3994 | * Implodes array to a string with specified separator. |
||
| 3995 | * |
||
| 3996 | * @param string $separator [optional] <p>The element's separator.</p> |
||
| 3997 | * |
||
| 3998 | * @return string |
||
| 3999 | * <p>The string representation of array, separated by ",".</p> |
||
| 4000 | */ |
||
| 4001 | 19 | public function toString(string $separator = ','): string |
|
| 4005 | |||
| 4006 | /** |
||
| 4007 | * Return a duplicate free copy of the current array. |
||
| 4008 | * |
||
| 4009 | * @return static |
||
| 4010 | * <p>(Mutable)</p> |
||
| 4011 | */ |
||
| 4012 | 10 | public function unique() |
|
| 4036 | |||
| 4037 | /** |
||
| 4038 | * Return a duplicate free copy of the current array. (with the old keys) |
||
| 4039 | * |
||
| 4040 | * @return static |
||
| 4041 | * <p>(Mutable)</p> |
||
| 4042 | */ |
||
| 4043 | 11 | public function uniqueKeepIndex() |
|
| 4070 | |||
| 4071 | /** |
||
| 4072 | * alias: for "Arrayy->unique()" |
||
| 4073 | * |
||
| 4074 | * @see Arrayy::unique() |
||
| 4075 | * |
||
| 4076 | * @return static |
||
| 4077 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
| 4078 | */ |
||
| 4079 | 10 | public function uniqueNewIndex() |
|
| 4083 | |||
| 4084 | /** |
||
| 4085 | * Prepends one or more values to the beginning of array at once. |
||
| 4086 | * |
||
| 4087 | * @return static |
||
| 4088 | * <p>(Mutable) Return this Arrayy object, with prepended elements to the beginning of array.</p> |
||
| 4089 | */ |
||
| 4090 | 4 | View Code Duplication | public function unshift(/* variadic arguments allowed */) |
| 4099 | |||
| 4100 | /** |
||
| 4101 | * Get all values from a array. |
||
| 4102 | * |
||
| 4103 | * @return static |
||
| 4104 | * <p>(Immutable)</p> |
||
| 4105 | */ |
||
| 4106 | 2 | public function values() |
|
| 4114 | |||
| 4115 | /** |
||
| 4116 | * Apply the given function to every element in the array, discarding the results. |
||
| 4117 | * |
||
| 4118 | * @param \callable $callable |
||
| 4119 | * @param bool $recursive <p>Whether array will be walked recursively or no</p> |
||
| 4120 | * |
||
| 4121 | * @return static |
||
| 4122 | * <p>(Mutable) Return this Arrayy object, with modified elements.</p> |
||
| 4123 | */ |
||
| 4124 | 37 | public function walk($callable, bool $recursive = false) |
|
| 4134 | } |
||
| 4135 |
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: