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 |
||
| 21 | class Arrayy extends \ArrayObject implements \IteratorAggregate, \ArrayAccess, \Serializable, \JsonSerializable, \Countable |
||
| 22 | { |
||
| 23 | const ARRAYY_HELPER_TYPES_FOR_ALL_PROPERTIES = '!!!!Arrayy_Helper_Types_For_All_Properties!!!!'; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var array |
||
| 27 | * @phpstan-var array<T> |
||
| 28 | */ |
||
| 29 | protected $array = []; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var ArrayyRewindableGenerator|null |
||
| 33 | * @phpstan-var ArrayyRewindableGenerator<T>|null |
||
| 34 | */ |
||
| 35 | protected $generator; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @var string |
||
| 39 | */ |
||
| 40 | protected $iteratorClass = ArrayyIterator::class; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @var string |
||
| 44 | */ |
||
| 45 | protected $pathSeparator = '.'; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @var bool |
||
| 49 | */ |
||
| 50 | protected $checkPropertyTypes = false; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @var bool |
||
| 54 | */ |
||
| 55 | protected $checkForMissingPropertiesInConstructor = false; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @var bool |
||
| 59 | */ |
||
| 60 | protected $checkPropertiesMismatchInConstructor = false; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @var bool |
||
| 64 | */ |
||
| 65 | protected $checkPropertiesMismatch = true; |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @var array<TypeCheckInterface>|\Arrayy\Type\TypeInterface|TypeCheckArray<TypeCheckInterface> |
||
| 69 | */ |
||
| 70 | protected $properties = []; |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Initializes |
||
| 74 | * |
||
| 75 | * @param mixed $data <p> |
||
| 76 | * Should be an array or a generator, otherwise it will try |
||
| 77 | * to convert it into an array. |
||
| 78 | * </p> |
||
| 79 | * @param string $iteratorClass optional <p> |
||
| 80 | * You can overwrite the ArrayyIterator, but mostly you don't |
||
| 81 | * need this option. |
||
| 82 | * </p> |
||
| 83 | * @param bool $checkPropertiesInConstructor optional <p> |
||
| 84 | * You need to extend the "Arrayy"-class and you need to set |
||
| 85 | * the $checkPropertiesMismatchInConstructor class property |
||
| 86 | 1050 | * to |
|
| 87 | * true, otherwise this option didn't not work anyway. |
||
| 88 | * </p> |
||
| 89 | * |
||
| 90 | * @phpstan-param class-string $iteratorClass |
||
| 91 | 1050 | */ |
|
| 92 | public function __construct( |
||
| 106 | |||
| 107 | /** |
||
| 108 | 1 | * Call object as function. |
|
| 109 | * |
||
| 110 | 1 | * @param mixed $key |
|
| 111 | 1 | * |
|
| 112 | * @return mixed |
||
| 113 | 1 | */ |
|
| 114 | public function __invoke($key = null) |
||
| 124 | |||
| 125 | /** |
||
| 126 | * Whether or not an element exists by key. |
||
| 127 | * |
||
| 128 | * @param mixed $key |
||
| 129 | * |
||
| 130 | * @return bool |
||
| 131 | * <p>True is the key/index exists, otherwise false.</p> |
||
| 132 | */ |
||
| 133 | public function __isset($key): bool |
||
| 137 | |||
| 138 | 2 | /** |
|
| 139 | * Assigns a value to the specified element. |
||
| 140 | 2 | * |
|
| 141 | 2 | * @param mixed $key |
|
| 142 | * @param mixed $value |
||
| 143 | * |
||
| 144 | * @return void |
||
| 145 | */ |
||
| 146 | public function __set($key, $value) |
||
| 150 | 15 | ||
| 151 | /** |
||
| 152 | * magic to string |
||
| 153 | * |
||
| 154 | * @return string |
||
| 155 | */ |
||
| 156 | public function __toString(): string |
||
| 160 | |||
| 161 | /** |
||
| 162 | * Unset element by key. |
||
| 163 | * |
||
| 164 | * @param mixed $key |
||
| 165 | */ |
||
| 166 | public function __unset($key) |
||
| 170 | |||
| 171 | 4 | /** |
|
| 172 | * Get a value by key. |
||
| 173 | 4 | * |
|
| 174 | * @param mixed $key |
||
| 175 | 4 | * |
|
| 176 | * @return mixed |
||
| 177 | * <p>Get a Value from the current array.</p> |
||
| 178 | */ |
||
| 179 | 4 | public function &__get($key) |
|
| 189 | |||
| 190 | /** |
||
| 191 | * alias: for "Arrayy->append()" |
||
| 192 | 3 | * |
|
| 193 | * @param mixed $value |
||
| 194 | 3 | * |
|
| 195 | * @return static |
||
| 196 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
| 197 | * |
||
| 198 | * @see Arrayy::append() |
||
| 199 | */ |
||
| 200 | public function add($value) |
||
| 204 | |||
| 205 | /** |
||
| 206 | 13 | * Append a (key) + value to the current array. |
|
| 207 | * |
||
| 208 | 13 | * @param mixed $value |
|
| 209 | * @param mixed $key |
||
| 210 | 13 | * |
|
| 211 | 4 | * @return static |
|
| 212 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
| 213 | */ |
||
| 214 | 12 | public function append($value, $key = null): self |
|
| 238 | |||
| 239 | /** |
||
| 240 | * Sort the entries by value. |
||
| 241 | * |
||
| 242 | * @param int $sort_flags [optional] <p> |
||
| 243 | 4 | * You may modify the behavior of the sort using the optional |
|
| 244 | * parameter sort_flags, for details |
||
| 245 | 4 | * see sort. |
|
| 246 | * </p> |
||
| 247 | 4 | * |
|
| 248 | * @return static |
||
| 249 | 4 | * <p>(Mutable) Return this Arrayy object.</p> |
|
| 250 | */ |
||
| 251 | public function asort(int $sort_flags = 0): self |
||
| 259 | |||
| 260 | /** |
||
| 261 | * Counts all elements in an array, or something in an object. |
||
| 262 | * |
||
| 263 | * <p> |
||
| 264 | * For objects, if you have SPL installed, you can hook into count() by implementing interface {@see Countable}. |
||
| 265 | * The interface has exactly one method, {@see Countable::count()}, which returns the return value for the count() |
||
| 266 | * function. Please see the {@see Array} section of the manual for a detailed explanation of how arrays are |
||
| 267 | * implemented and used in PHP. |
||
| 268 | * </p> |
||
| 269 | * |
||
| 270 | * @see http://php.net/manual/en/function.count.php |
||
| 271 | * |
||
| 272 | * @param int $mode [optional] If the optional mode parameter is set to |
||
| 273 | * COUNT_RECURSIVE (or 1), count |
||
| 274 | * will recursively count the array. This is particularly useful for |
||
| 275 | * counting all the elements of a multidimensional array. count does not detect infinite recursion. |
||
| 276 | * |
||
| 277 | * @return int |
||
| 278 | * <p> |
||
| 279 | * The number of elements in var, which is |
||
| 280 | * typically an array, since anything else will have one |
||
| 281 | * element. |
||
| 282 | * </p> |
||
| 283 | * <p> |
||
| 284 | * If var is not an array or an object with |
||
| 285 | * implemented Countable interface, |
||
| 286 | * 1 will be returned. |
||
| 287 | * There is one exception, if var is &null;, |
||
| 288 | 50 | * 0 will be returned. |
|
| 289 | * </p> |
||
| 290 | 50 | * <p> |
|
| 291 | * Caution: count may return 0 for a variable that isn't set, |
||
| 292 | * but it may also return 0 for a variable that has been initialized with an |
||
| 293 | * empty array. Use isset to test if a variable is set. |
||
| 294 | * </p> |
||
| 295 | */ |
||
| 296 | public function count(int $mode = \COUNT_NORMAL): int |
||
| 300 | 1 | ||
| 301 | /** |
||
| 302 | 1 | * Exchange the array for another one. |
|
| 303 | * |
||
| 304 | 1 | * @param array|static $data |
|
| 305 | * |
||
| 306 | * @return array |
||
| 307 | */ |
||
| 308 | public function exchangeArray($data): array |
||
| 314 | 5 | ||
| 315 | /** |
||
| 316 | 5 | * Creates a copy of the ArrayyObject. |
|
| 317 | * |
||
| 318 | * @return array |
||
| 319 | * |
||
| 320 | * @phpstan-return array<T> |
||
| 321 | */ |
||
| 322 | public function getArrayCopy(): array |
||
| 328 | 1 | ||
| 329 | /** |
||
| 330 | * Returns a new iterator, thus implementing the \Iterator interface. |
||
| 331 | 23 | * |
|
| 332 | * @return \Iterator<mixed, mixed> |
||
|
|
|||
| 333 | 23 | * <p>An iterator for the values in the array.</p> |
|
| 334 | 23 | */ |
|
| 335 | public function getIterator(): \Iterator |
||
| 349 | |||
| 350 | /** |
||
| 351 | * Gets the iterator classname for the ArrayObject. |
||
| 352 | * |
||
| 353 | * @return string |
||
| 354 | */ |
||
| 355 | public function getIteratorClass(): string |
||
| 359 | |||
| 360 | /** |
||
| 361 | * Sort the entries by key |
||
| 362 | 4 | * |
|
| 363 | * @param int $sort_flags [optional] <p> |
||
| 364 | 4 | * You may modify the behavior of the sort using the optional |
|
| 365 | * parameter sort_flags, for details |
||
| 366 | 4 | * see sort. |
|
| 367 | * </p> |
||
| 368 | 4 | * |
|
| 369 | * @return static |
||
| 370 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 371 | */ |
||
| 372 | public function ksort(int $sort_flags = 0): self |
||
| 380 | |||
| 381 | /** |
||
| 382 | * Sort an array using a case insensitive "natural order" algorithm |
||
| 383 | * |
||
| 384 | * @return static |
||
| 385 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 386 | */ |
||
| 387 | public function natcasesort(): self |
||
| 395 | |||
| 396 | 1 | /** |
|
| 397 | * Sort entries using a "natural order" algorithm |
||
| 398 | 1 | * |
|
| 399 | * @return static |
||
| 400 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 401 | */ |
||
| 402 | public function natsort(): self |
||
| 410 | 126 | ||
| 411 | /** |
||
| 412 | 126 | * Whether or not an offset exists. |
|
| 413 | 5 | * |
|
| 414 | * @param bool|int|string $offset |
||
| 415 | * |
||
| 416 | * @return bool |
||
| 417 | 121 | * |
|
| 418 | 1 | * @noinspection PhpSillyAssignmentInspection |
|
| 419 | */ |
||
| 420 | public function offsetExists($offset): bool |
||
| 477 | |||
| 478 | /** |
||
| 479 | * Returns the value at specified offset. |
||
| 480 | * |
||
| 481 | * @param int|string $offset |
||
| 482 | 21 | * |
|
| 483 | * @return mixed |
||
| 484 | 21 | * <p>Will return null if the offset did not exists.</p> |
|
| 485 | */ |
||
| 486 | 21 | public function offsetGet($offset) |
|
| 490 | |||
| 491 | 4 | /** |
|
| 492 | * Assigns a value to the specified offset. |
||
| 493 | 16 | * |
|
| 494 | 16 | * @param int|string|null $offset |
|
| 495 | 16 | * @param mixed $value |
|
| 496 | 16 | * |
|
| 497 | * @return void |
||
| 498 | */ |
||
| 499 | 20 | public function offsetSet($offset, $value) |
|
| 517 | 7 | ||
| 518 | /** |
||
| 519 | * Unset an offset. |
||
| 520 | * |
||
| 521 | 5 | * @param int|string $offset |
|
| 522 | * |
||
| 523 | 5 | * @return void |
|
| 524 | */ |
||
| 525 | 5 | public function offsetUnset($offset) |
|
| 562 | |||
| 563 | /** |
||
| 564 | * Serialize the current "Arrayy"-object. |
||
| 565 | * |
||
| 566 | * @return string |
||
| 567 | 1041 | */ |
|
| 568 | public function serialize(): string |
||
| 578 | |||
| 579 | /** |
||
| 580 | * Sets the iterator classname for the current "Arrayy"-object. |
||
| 581 | * |
||
| 582 | * @param string $class |
||
| 583 | * |
||
| 584 | * @throws \InvalidArgumentException |
||
| 585 | * |
||
| 586 | * @return void |
||
| 587 | */ |
||
| 588 | public function setIteratorClass($class) |
||
| 607 | |||
| 608 | /** |
||
| 609 | * Sort the entries with a user-defined comparison function and maintain key association. |
||
| 610 | * |
||
| 611 | * @param callable $function |
||
| 612 | * |
||
| 613 | * @throws \InvalidArgumentException |
||
| 614 | * |
||
| 615 | * @return static |
||
| 616 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 617 | */ |
||
| 618 | View Code Duplication | public function uasort($function): self |
|
| 630 | |||
| 631 | /** |
||
| 632 | 2 | * Sort the entries by keys using a user-defined comparison function. |
|
| 633 | * |
||
| 634 | 2 | * @param callable $function |
|
| 635 | 2 | * |
|
| 636 | * @throws \InvalidArgumentException |
||
| 637 | 2 | * |
|
| 638 | * @return static |
||
| 639 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 640 | */ |
||
| 641 | public function uksort($function): self |
||
| 645 | |||
| 646 | /** |
||
| 647 | * Unserialize an string and return the instance of the "Arrayy"-class. |
||
| 648 | * |
||
| 649 | * @param string $string |
||
| 650 | * |
||
| 651 | * @return static |
||
| 652 | 1 | */ |
|
| 653 | public function unserialize($string): self |
||
| 663 | 1 | ||
| 664 | /** |
||
| 665 | * Append a (key) + values to the current array. |
||
| 666 | 1 | * |
|
| 667 | * @param array $values |
||
| 668 | * @param mixed $key |
||
| 669 | * |
||
| 670 | * @return static |
||
| 671 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
| 672 | */ |
||
| 673 | public function appendArrayValues(array $values, $key = null): self |
||
| 699 | |||
| 700 | 9 | /** |
|
| 701 | * Add a suffix to each key. |
||
| 702 | * |
||
| 703 | * @param mixed $prefix |
||
| 704 | 10 | * |
|
| 705 | * @return static |
||
| 706 | * <p>(Immutable) Return an Arrayy object, with the prefixed keys.</p> |
||
| 707 | */ |
||
| 708 | View Code Duplication | public function appendToEachKey($prefix): self |
|
| 727 | |||
| 728 | 8 | /** |
|
| 729 | * Add a prefix to each value. |
||
| 730 | * |
||
| 731 | * @param mixed $prefix |
||
| 732 | 10 | * |
|
| 733 | * @return static |
||
| 734 | * <p>(Immutable) Return an Arrayy object, with the prefixed values.</p> |
||
| 735 | */ |
||
| 736 | View Code Duplication | public function appendToEachValue($prefix): self |
|
| 755 | |||
| 756 | /** |
||
| 757 | * Sort an array in reverse order and maintain index association. |
||
| 758 | 2 | * |
|
| 759 | * @return static |
||
| 760 | 2 | * <p>(Mutable) Return this Arrayy object.</p> |
|
| 761 | */ |
||
| 762 | 2 | public function arsort(): self |
|
| 770 | |||
| 771 | /** |
||
| 772 | * Iterate over the current array and execute a callback for each loop. |
||
| 773 | * |
||
| 774 | * @param \Closure $closure |
||
| 775 | * |
||
| 776 | * @return static |
||
| 777 | * <p>(Immutable)</p> |
||
| 778 | */ |
||
| 779 | public function at(\Closure $closure): self |
||
| 793 | 8 | ||
| 794 | /** |
||
| 795 | * Returns the average value of the current array. |
||
| 796 | * |
||
| 797 | * @param int $decimals <p>The number of decimal-numbers to return.</p> |
||
| 798 | * |
||
| 799 | * @return float|int |
||
| 800 | * <p>The average value.</p> |
||
| 801 | */ |
||
| 802 | public function average($decimals = 0) |
||
| 816 | 1 | ||
| 817 | 1 | /** |
|
| 818 | 1 | * Changes all keys in an array. |
|
| 819 | * |
||
| 820 | 1 | * @param int $case [optional] <p> Either <strong>CASE_UPPER</strong><br /> |
|
| 821 | * or <strong>CASE_LOWER</strong> (default)</p> |
||
| 822 | * |
||
| 823 | 1 | * @return static |
|
| 824 | * <p>(Immutable)</p> |
||
| 825 | */ |
||
| 826 | 1 | public function changeKeyCase(int $case = \CASE_LOWER): self |
|
| 853 | |||
| 854 | /** |
||
| 855 | * Change the path separator of the array wrapper. |
||
| 856 | * |
||
| 857 | * By default, the separator is: "." |
||
| 858 | * |
||
| 859 | 5 | * @param string $separator <p>Separator to set.</p> |
|
| 860 | * |
||
| 861 | 5 | * @return static |
|
| 862 | 5 | * <p>Mutable</p> |
|
| 863 | 5 | */ |
|
| 864 | 5 | public function changeSeparator($separator): self |
|
| 870 | |||
| 871 | /** |
||
| 872 | * Create a chunked version of the current array. |
||
| 873 | * |
||
| 874 | 8 | * @param int $size <p>Size of each chunk.</p> |
|
| 875 | * @param bool $preserveKeys <p>Whether array keys are preserved or no.</p> |
||
| 876 | 8 | * |
|
| 877 | * @return static |
||
| 878 | 7 | * <p>(Immutable) A new array of chunks from the original array.</p> |
|
| 879 | 8 | */ |
|
| 880 | public function chunk($size, $preserveKeys = false): self |
||
| 888 | |||
| 889 | 4 | /** |
|
| 890 | * Clean all falsy values from the current array. |
||
| 891 | 4 | * |
|
| 892 | 4 | * @return static |
|
| 893 | * <p>(Immutable)</p> |
||
| 894 | 4 | */ |
|
| 895 | public function clean(): self |
||
| 903 | |||
| 904 | /** |
||
| 905 | * WARNING!!! -> Clear the current array. |
||
| 906 | 23 | * |
|
| 907 | * @return static |
||
| 908 | 23 | * <p>(Mutable) Return this Arrayy object, with an empty array.</p> |
|
| 909 | 18 | */ |
|
| 910 | public function clear(): self |
||
| 917 | |||
| 918 | /** |
||
| 919 | * Check if an item is in the current array. |
||
| 920 | * |
||
| 921 | * @param float|int|string $value |
||
| 922 | * @param bool $recursive |
||
| 923 | * @param bool $strict |
||
| 924 | * |
||
| 925 | 7 | * @return bool |
|
| 926 | * |
||
| 927 | * @phpstan-param T $value |
||
| 928 | */ |
||
| 929 | public function contains($value, bool $recursive = false, bool $strict = true): bool |
||
| 950 | 10 | ||
| 951 | /** |
||
| 952 | * Check if an (case-insensitive) string is in the current array. |
||
| 953 | 13 | * |
|
| 954 | 11 | * @param string $value |
|
| 955 | 8 | * @param bool $recursive |
|
| 956 | * |
||
| 957 | * @return bool |
||
| 958 | */ |
||
| 959 | 5 | public function containsCaseInsensitive($value, $recursive = false): bool |
|
| 984 | 2 | ||
| 985 | /** |
||
| 986 | 2 | * Check if the given key/index exists in the array. |
|
| 987 | * |
||
| 988 | 2 | * @param int|string $key <p>key/index to search for</p> |
|
| 989 | 2 | * |
|
| 990 | 2 | * @return bool |
|
| 991 | 2 | * <p>Returns true if the given key/index exists in the array, false otherwise.</p> |
|
| 992 | */ |
||
| 993 | 2 | public function containsKey($key): bool |
|
| 997 | 2 | ||
| 998 | 2 | /** |
|
| 999 | * Check if all given needles are present in the array as key/index. |
||
| 1000 | * |
||
| 1001 | * @param array $needles <p>The keys you are searching for.</p> |
||
| 1002 | 1 | * @param bool $recursive |
|
| 1003 | 1 | * |
|
| 1004 | 1 | * @return bool |
|
| 1005 | * <p>Returns true if all the given keys/indexes exists in the array, false otherwise.</p> |
||
| 1006 | */ |
||
| 1007 | 1 | public function containsKeys(array $needles, $recursive = false): bool |
|
| 1035 | 9 | ||
| 1036 | /** |
||
| 1037 | 9 | * Check if all given needles are present in the array as key/index. |
|
| 1038 | * |
||
| 1039 | * @param array $needles <p>The keys you are searching for.</p> |
||
| 1040 | * |
||
| 1041 | * @return bool |
||
| 1042 | * <p>Returns true if all the given keys/indexes exists in the array, false otherwise.</p> |
||
| 1043 | */ |
||
| 1044 | public function containsKeysRecursive(array $needles): bool |
||
| 1048 | |||
| 1049 | 18 | /** |
|
| 1050 | * alias: for "Arrayy->contains()" |
||
| 1051 | 18 | * |
|
| 1052 | * @param float|int|string $value |
||
| 1053 | * |
||
| 1054 | * @return bool |
||
| 1055 | * |
||
| 1056 | * @see Arrayy::contains() |
||
| 1057 | * |
||
| 1058 | * @phpstan-param T $value |
||
| 1059 | */ |
||
| 1060 | public function containsValue($value): bool |
||
| 1064 | 1 | ||
| 1065 | /** |
||
| 1066 | 1 | * alias: for "Arrayy->contains($value, true)" |
|
| 1067 | * |
||
| 1068 | * @param float|int|string $value |
||
| 1069 | * |
||
| 1070 | * @return bool |
||
| 1071 | * |
||
| 1072 | * @see Arrayy::contains() |
||
| 1073 | * |
||
| 1074 | * @phpstan-param T $value |
||
| 1075 | */ |
||
| 1076 | public function containsValueRecursive($value): bool |
||
| 1080 | |||
| 1081 | 7 | /** |
|
| 1082 | * Check if all given needles are present in the array. |
||
| 1083 | 7 | * |
|
| 1084 | * @param array $needles |
||
| 1085 | * |
||
| 1086 | * @return bool |
||
| 1087 | * <p>Returns true if all the given values exists in the array, false otherwise.</p> |
||
| 1088 | */ |
||
| 1089 | public function containsValues(array $needles): bool |
||
| 1095 | |||
| 1096 | 657 | /** |
|
| 1097 | * Counts all the values of an array |
||
| 1098 | * |
||
| 1099 | * @see http://php.net/manual/en/function.array-count-values.php |
||
| 1100 | * |
||
| 1101 | 657 | * @return static |
|
| 1102 | 657 | * <p> |
|
| 1103 | 657 | * (Immutable) |
|
| 1104 | 657 | * An associative Arrayy-object of values from input as |
|
| 1105 | * keys and their count as value. |
||
| 1106 | * </p> |
||
| 1107 | */ |
||
| 1108 | public function countValues(): self |
||
| 1112 | |||
| 1113 | /** |
||
| 1114 | * Creates an Arrayy object. |
||
| 1115 | * |
||
| 1116 | 1 | * @param mixed $data |
|
| 1117 | * @param string $iteratorClass |
||
| 1118 | 1 | * @param bool $checkPropertiesInConstructor |
|
| 1119 | * |
||
| 1120 | 1 | * @return static |
|
| 1121 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1122 | 1 | */ |
|
| 1123 | public static function create( |
||
| 1134 | |||
| 1135 | 5 | /** |
|
| 1136 | * WARNING: Creates an Arrayy object by reference. |
||
| 1137 | * |
||
| 1138 | * @param array $array |
||
| 1139 | * |
||
| 1140 | * @return static |
||
| 1141 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1142 | */ |
||
| 1143 | public function createByReference(array &$array = []): self |
||
| 1151 | |||
| 1152 | /** |
||
| 1153 | * Create an new instance from a callable function which will return an Generator. |
||
| 1154 | * |
||
| 1155 | * @param callable():Generator $generatorFunction |
||
| 1156 | * |
||
| 1157 | * @return static |
||
| 1158 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1159 | 5 | */ |
|
| 1160 | public static function createFromGeneratorFunction(callable $generatorFunction): self |
||
| 1164 | |||
| 1165 | /** |
||
| 1166 | * Create an new instance filled with a copy of values from a "Generator"-object. |
||
| 1167 | * |
||
| 1168 | * @param \Generator $generator |
||
| 1169 | * |
||
| 1170 | * @return static |
||
| 1171 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1172 | 4 | */ |
|
| 1173 | public static function createFromGeneratorImmutable(\Generator $generator): self |
||
| 1177 | 4 | ||
| 1178 | 4 | /** |
|
| 1179 | * Create an new Arrayy object via JSON. |
||
| 1180 | * |
||
| 1181 | * @param string $json |
||
| 1182 | * |
||
| 1183 | 4 | * @return static |
|
| 1184 | 3 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
|
| 1185 | */ |
||
| 1186 | public static function createFromJson(string $json): self |
||
| 1190 | |||
| 1191 | /** |
||
| 1192 | * Create an new instance filled with values from an object that is iterable. |
||
| 1193 | * |
||
| 1194 | * @param \Traversable $object <p>iterable object</p> |
||
| 1195 | * |
||
| 1196 | * @return static |
||
| 1197 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1198 | 5 | */ |
|
| 1199 | public static function createFromObject(\Traversable $object): self |
||
| 1216 | 10 | ||
| 1217 | 1 | /** |
|
| 1218 | * Create an new instance filled with values from an object. |
||
| 1219 | 1 | * |
|
| 1220 | 1 | * @param object $object |
|
| 1221 | * |
||
| 1222 | * @return static |
||
| 1223 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1224 | 9 | */ |
|
| 1225 | 7 | public static function createFromObjectVars($object): self |
|
| 1229 | |||
| 1230 | /** |
||
| 1231 | * Create an new Arrayy object via string. |
||
| 1232 | 10 | * |
|
| 1233 | 10 | * @param string $str <p>The input string.</p> |
|
| 1234 | * @param string|null $delimiter <p>The boundary string.</p> |
||
| 1235 | 10 | * @param string|null $regEx <p>Use the $delimiter or the $regEx, so if $pattern is null, $delimiter will be |
|
| 1236 | 10 | * used.</p> |
|
| 1237 | * |
||
| 1238 | 10 | * @return static |
|
| 1239 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1240 | */ |
||
| 1241 | 10 | public static function createFromString(string $str, string $delimiter = null, string $regEx = null): self |
|
| 1270 | |||
| 1271 | /** |
||
| 1272 | * Create an new instance filled with a copy of values from a "Traversable"-object. |
||
| 1273 | * |
||
| 1274 | * @param \Traversable $traversable |
||
| 1275 | * |
||
| 1276 | * @return static |
||
| 1277 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1278 | */ |
||
| 1279 | public static function createFromTraversableImmutable(\Traversable $traversable): self |
||
| 1283 | |||
| 1284 | 5 | /** |
|
| 1285 | * Create an new instance containing a range of elements. |
||
| 1286 | 5 | * |
|
| 1287 | * @param mixed $low <p>First value of the sequence.</p> |
||
| 1288 | * @param mixed $high <p>The sequence is ended upon reaching the end value.</p> |
||
| 1289 | * @param int $step <p>Used as the increment between elements in the sequence.</p> |
||
| 1290 | 5 | * |
|
| 1291 | * @return static |
||
| 1292 | 5 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
|
| 1293 | */ |
||
| 1294 | 5 | public static function createWithRange($low, $high, int $step = 1): self |
|
| 1298 | |||
| 1299 | /** |
||
| 1300 | * Gets the element of the array at the current internal iterator position. |
||
| 1301 | * |
||
| 1302 | * @return mixed |
||
| 1303 | * |
||
| 1304 | * @phpstan-return T|false |
||
| 1305 | */ |
||
| 1306 | public function current() |
||
| 1310 | |||
| 1311 | 6 | /** |
|
| 1312 | * Custom sort by index via "uksort". |
||
| 1313 | * |
||
| 1314 | * @see http://php.net/manual/en/function.uksort.php |
||
| 1315 | 6 | * |
|
| 1316 | * @param callable $function |
||
| 1317 | 6 | * |
|
| 1318 | * @throws \InvalidArgumentException |
||
| 1319 | 6 | * |
|
| 1320 | * @return static |
||
| 1321 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1322 | */ |
||
| 1323 | View Code Duplication | public function customSortKeys($function): self |
|
| 1335 | |||
| 1336 | /** |
||
| 1337 | * Custom sort by value via "usort". |
||
| 1338 | * |
||
| 1339 | * @see http://php.net/manual/en/function.usort.php |
||
| 1340 | * |
||
| 1341 | * @param callable $function |
||
| 1342 | * |
||
| 1343 | * @throws \InvalidArgumentException |
||
| 1344 | 13 | * |
|
| 1345 | * @return static |
||
| 1346 | 13 | * <p>(Mutable) Return this Arrayy object.</p> |
|
| 1347 | 13 | */ |
|
| 1348 | 13 | View Code Duplication | public function customSortValues($function): self |
| 1360 | |||
| 1361 | 8 | /** |
|
| 1362 | * Delete the given key or keys. |
||
| 1363 | 8 | * |
|
| 1364 | 8 | * @param int|int[]|string|string[] $keyOrKeys |
|
| 1365 | 8 | * |
|
| 1366 | 8 | * @return void |
|
| 1367 | */ |
||
| 1368 | public function delete($keyOrKeys) |
||
| 1376 | |||
| 1377 | /** |
||
| 1378 | 8 | * Return values that are only in the current array. |
|
| 1379 | * |
||
| 1380 | 8 | * @param array ...$array |
|
| 1381 | 8 | * |
|
| 1382 | 8 | * @return static |
|
| 1383 | 8 | * <p>(Immutable)</p> |
|
| 1384 | */ |
||
| 1385 | public function diff(...$array): self |
||
| 1393 | |||
| 1394 | /** |
||
| 1395 | * Return values that are only in the current array. |
||
| 1396 | 1 | * |
|
| 1397 | * @param array ...$array |
||
| 1398 | * |
||
| 1399 | 1 | * @return static |
|
| 1400 | * <p>(Immutable)</p> |
||
| 1401 | */ |
||
| 1402 | 1 | public function diffKey(...$array): self |
|
| 1410 | |||
| 1411 | 1 | /** |
|
| 1412 | 1 | * Return values and Keys that are only in the current array. |
|
| 1413 | * |
||
| 1414 | * @param array $array |
||
| 1415 | * |
||
| 1416 | 1 | * @return static |
|
| 1417 | 1 | * <p>(Immutable)</p> |
|
| 1418 | 1 | */ |
|
| 1419 | public function diffKeyAndValue(array $array = []): self |
||
| 1427 | 1 | ||
| 1428 | 1 | /** |
|
| 1429 | * Return values that are only in the current multi-dimensional array. |
||
| 1430 | * |
||
| 1431 | * @param array $array |
||
| 1432 | * @param array|null $helperVariableForRecursion <p>(only for internal usage)</p> |
||
| 1433 | * |
||
| 1434 | * @return static |
||
| 1435 | * <p>(Immutable)</p> |
||
| 1436 | */ |
||
| 1437 | public function diffRecursive(array $array = [], $helperVariableForRecursion = null): self |
||
| 1472 | |||
| 1473 | /** |
||
| 1474 | * Return values that are only in the new $array. |
||
| 1475 | 5 | * |
|
| 1476 | * @param array $array |
||
| 1477 | * |
||
| 1478 | 5 | * @return static |
|
| 1479 | * <p>(Immutable)</p> |
||
| 1480 | 5 | */ |
|
| 1481 | 5 | public function diffReverse(array $array = []): self |
|
| 1489 | |||
| 1490 | /** |
||
| 1491 | * Divide an array into two arrays. One with keys and the other with values. |
||
| 1492 | * |
||
| 1493 | * @return static |
||
| 1494 | * <p>(Immutable)</p> |
||
| 1495 | */ |
||
| 1496 | public function divide(): self |
||
| 1507 | |||
| 1508 | 1 | /** |
|
| 1509 | * Iterate over the current array and modify the array's value. |
||
| 1510 | * |
||
| 1511 | * @param \Closure $closure |
||
| 1512 | 4 | * |
|
| 1513 | * @return static |
||
| 1514 | * <p>(Immutable)</p> |
||
| 1515 | */ |
||
| 1516 | View Code Duplication | public function each(\Closure $closure): self |
|
| 1531 | |||
| 1532 | 7 | /** |
|
| 1533 | * Sets the internal iterator to the last element in the array and returns this element. |
||
| 1534 | 7 | * |
|
| 1535 | * @return mixed |
||
| 1536 | 7 | */ |
|
| 1537 | 4 | public function end() |
|
| 1541 | 7 | ||
| 1542 | 7 | /** |
|
| 1543 | 7 | * Check if a value is in the current array using a closure. |
|
| 1544 | 7 | * |
|
| 1545 | * @param \Closure $closure |
||
| 1546 | * |
||
| 1547 | * @return bool |
||
| 1548 | * <p>Returns true if the given value is found, false otherwise.</p> |
||
| 1549 | */ |
||
| 1550 | public function exists(\Closure $closure): bool |
||
| 1565 | |||
| 1566 | /** |
||
| 1567 | * Fill the array until "$num" with "$default" values. |
||
| 1568 | * |
||
| 1569 | * @param int $num |
||
| 1570 | * @param mixed $default |
||
| 1571 | * |
||
| 1572 | * @return static |
||
| 1573 | * <p>(Immutable)</p> |
||
| 1574 | */ |
||
| 1575 | public function fillWithDefaults(int $num, $default = null): self |
||
| 1598 | |||
| 1599 | /** |
||
| 1600 | * Find all items in an array that pass the truth test. |
||
| 1601 | * |
||
| 1602 | * @param \Closure|null $closure [optional] <p> |
||
| 1603 | * The callback function to use |
||
| 1604 | * </p> |
||
| 1605 | * <p> |
||
| 1606 | * If no callback is supplied, all entries of |
||
| 1607 | * input equal to false (see |
||
| 1608 | * converting to |
||
| 1609 | * boolean) will be removed. |
||
| 1610 | * </p> |
||
| 1611 | * @param int $flag [optional] <p> |
||
| 1612 | 1 | * Flag determining what arguments are sent to <i>callback</i>: |
|
| 1613 | * </p><ul> |
||
| 1614 | 1 | * <li> |
|
| 1615 | 1 | * <b>ARRAY_FILTER_USE_KEY</b> [1] - pass key as the only argument |
|
| 1616 | * to <i>callback</i> instead of the value</span> |
||
| 1617 | * </li> |
||
| 1618 | * <li> |
||
| 1619 | * <b>ARRAY_FILTER_USE_BOTH</b> [2] - pass both value and key as |
||
| 1620 | 1 | * arguments to <i>callback</i> instead of the value</span> |
|
| 1621 | 1 | * </li> |
|
| 1622 | * </ul> |
||
| 1623 | * |
||
| 1624 | 1 | * @return static |
|
| 1625 | * <p>(Immutable)</p> |
||
| 1626 | */ |
||
| 1627 | 1 | public function filter($closure = null, int $flag = \ARRAY_FILTER_USE_BOTH) |
|
| 1639 | 1 | ||
| 1640 | /** |
||
| 1641 | * Filters an array of objects (or a numeric array of associative arrays) based on the value of a particular |
||
| 1642 | 1 | * property within that. |
|
| 1643 | * |
||
| 1644 | 1 | * @param string $property |
|
| 1645 | 1 | * @param string|string[] $value |
|
| 1646 | * @param string $comparisonOp |
||
| 1647 | * <p> |
||
| 1648 | 1 | * 'eq' (equals),<br /> |
|
| 1649 | * 'gt' (greater),<br /> |
||
| 1650 | * 'gte' || 'ge' (greater or equals),<br /> |
||
| 1651 | 1 | * 'lt' (less),<br /> |
|
| 1652 | * 'lte' || 'le' (less or equals),<br /> |
||
| 1653 | * 'ne' (not equals),<br /> |
||
| 1654 | 1 | * 'contains',<br /> |
|
| 1655 | * 'notContains',<br /> |
||
| 1656 | * 'newer' (via strtotime),<br /> |
||
| 1657 | 1 | * 'older' (via strtotime),<br /> |
|
| 1658 | 1 | * </p> |
|
| 1659 | 1 | * |
|
| 1660 | * @return static |
||
| 1661 | 1 | * <p>(Immutable)</p> |
|
| 1662 | 1 | */ |
|
| 1663 | 1 | public function filterBy(string $property, $value, string $comparisonOp = null): self |
|
| 1732 | |||
| 1733 | /** |
||
| 1734 | * Find the first item in an array that passes the truth test, |
||
| 1735 | * otherwise return false |
||
| 1736 | * |
||
| 1737 | * @param \Closure $closure |
||
| 1738 | * |
||
| 1739 | 28 | * @return false|mixed |
|
| 1740 | * <p>Return false if we did not find the value.</p> |
||
| 1741 | 28 | */ |
|
| 1742 | public function find(\Closure $closure) |
||
| 1752 | |||
| 1753 | /** |
||
| 1754 | * find by ... |
||
| 1755 | 37 | * |
|
| 1756 | * @param string $property |
||
| 1757 | 37 | * @param string|string[] $value |
|
| 1758 | * @param string $comparisonOp |
||
| 1759 | 37 | * |
|
| 1760 | 14 | * @return static |
|
| 1761 | * <p>(Immutable)</p> |
||
| 1762 | 23 | */ |
|
| 1763 | 23 | public function findBy(string $property, $value, string $comparisonOp = 'eq'): self |
|
| 1767 | 37 | ||
| 1768 | 37 | /** |
|
| 1769 | 37 | * Get the first value from the current array. |
|
| 1770 | * |
||
| 1771 | * @return mixed |
||
| 1772 | * <p>Return null if there wasn't a element.</p> |
||
| 1773 | */ |
||
| 1774 | public function first() |
||
| 1783 | |||
| 1784 | 3 | /** |
|
| 1785 | * Get the first key from the current array. |
||
| 1786 | 3 | * |
|
| 1787 | * @return mixed |
||
| 1788 | * <p>Return null if there wasn't a element.</p> |
||
| 1789 | 3 | */ |
|
| 1790 | 3 | public function firstKey() |
|
| 1796 | 3 | ||
| 1797 | /** |
||
| 1798 | * Get the first value(s) from the current array. |
||
| 1799 | * And will return an empty array if there was no first entry. |
||
| 1800 | * |
||
| 1801 | * @param int|null $number <p>How many values you will take?</p> |
||
| 1802 | * |
||
| 1803 | * @return static |
||
| 1804 | * <p>(Immutable)</p> |
||
| 1805 | */ |
||
| 1806 | View Code Duplication | public function firstsImmutable(int $number = null): self |
|
| 1823 | |||
| 1824 | /** |
||
| 1825 | * Get the first value(s) from the current array. |
||
| 1826 | * And will return an empty array if there was no first entry. |
||
| 1827 | * |
||
| 1828 | * @param int|null $number <p>How many values you will take?</p> |
||
| 1829 | 1 | * |
|
| 1830 | * @return static |
||
| 1831 | 1 | * <p>(Immutable)</p> |
|
| 1832 | 1 | */ |
|
| 1833 | 1 | View Code Duplication | public function firstsKeys(int $number = null): self |
| 1850 | 168 | ||
| 1851 | 4 | /** |
|
| 1852 | * Get and rmove the first value(s) from the current array. |
||
| 1853 | 165 | * And will return an empty array if there was no first entry. |
|
| 1854 | * |
||
| 1855 | 165 | * @param int|null $number <p>How many values you will take?</p> |
|
| 1856 | * |
||
| 1857 | * @return static |
||
| 1858 | 168 | * <p>(Mutable)</p> |
|
| 1859 | 1 | */ |
|
| 1860 | 1 | public function firstsMutable(int $number = null): self |
|
| 1873 | 11 | ||
| 1874 | 11 | /** |
|
| 1875 | 11 | * Exchanges all keys with their associated values in an array. |
|
| 1876 | 11 | * |
|
| 1877 | * @return static |
||
| 1878 | * <p>(Immutable)</p> |
||
| 1879 | */ |
||
| 1880 | 150 | public function flip(): self |
|
| 1888 | 24 | ||
| 1889 | /** |
||
| 1890 | 24 | * Tests whether the given predicate p holds for all elements of this array. |
|
| 1891 | * |
||
| 1892 | 7 | * @param \Closure $closure the predicate |
|
| 1893 | 7 | * |
|
| 1894 | 7 | * @return bool |
|
| 1895 | * <p>TRUE, if the predicate yields TRUE for all elements, FALSE otherwise.</p> |
||
| 1896 | 7 | */ |
|
| 1897 | public function forAll(\Closure $closure): bool |
||
| 1907 | |||
| 1908 | 7 | /** |
|
| 1909 | * Get a value from an array (optional using dot-notation). |
||
| 1910 | * |
||
| 1911 | * @param mixed $key <p>The key to look for.</p> |
||
| 1912 | 6 | * @param mixed $fallback <p>Value to fallback to.</p> |
|
| 1913 | * @param array $array <p>The array to get from, if it's set to "null" we use the current array from the |
||
| 1914 | 6 | * class.</p> |
|
| 1915 | * |
||
| 1916 | 1 | * @return mixed|static |
|
| 1917 | */ |
||
| 1918 | 1 | public function get($key, $fallback = null, array $array = null) |
|
| 2010 | |||
| 2011 | 917 | /** |
|
| 2012 | 39 | * alias: for "Arrayy->getArray()" |
|
| 2013 | * |
||
| 2014 | * @return array |
||
| 2015 | 917 | * |
|
| 2016 | 873 | * @see Arrayy::getArray() |
|
| 2017 | */ |
||
| 2018 | public function getAll(): array |
||
| 2022 | |||
| 2023 | /** |
||
| 2024 | * Get the current array from the "Arrayy"-object. |
||
| 2025 | * |
||
| 2026 | 2 | * @param bool $convertAllArrayyElements |
|
| 2027 | * |
||
| 2028 | 2 | * @return array |
|
| 2029 | */ |
||
| 2030 | public function getArray($convertAllArrayyElements = false): array |
||
| 2051 | 4 | ||
| 2052 | /** |
||
| 2053 | * Returns the values from a single column of the input array, identified by |
||
| 2054 | * the $columnKey, can be used to extract data-columns from multi-arrays. |
||
| 2055 | * |
||
| 2056 | * Info: Optionally, you may provide an $indexKey to index the values in the returned |
||
| 2057 | * array by the values from the $indexKey column in the input array. |
||
| 2058 | * |
||
| 2059 | * @param mixed $columnKey |
||
| 2060 | * @param mixed $indexKey |
||
| 2061 | * |
||
| 2062 | 3 | * @return static |
|
| 2063 | * <p>(Immutable)</p> |
||
| 2064 | 3 | */ |
|
| 2065 | public function getColumn($columnKey = null, $indexKey = null): self |
||
| 2073 | |||
| 2074 | /** |
||
| 2075 | * Get the current array from the "Arrayy"-object as generator. |
||
| 2076 | * |
||
| 2077 | 8 | * @return \Generator |
|
| 2078 | */ |
||
| 2079 | 8 | public function getGenerator(): \Generator |
|
| 2087 | |||
| 2088 | /** |
||
| 2089 | * alias: for "Arrayy->keys()" |
||
| 2090 | 3 | * |
|
| 2091 | * @return static |
||
| 2092 | 3 | * <p>(Immutable)</p> |
|
| 2093 | * |
||
| 2094 | * @see Arrayy::keys() |
||
| 2095 | */ |
||
| 2096 | public function getKeys() |
||
| 2100 | |||
| 2101 | /** |
||
| 2102 | * Get the current array from the "Arrayy"-object as object. |
||
| 2103 | * |
||
| 2104 | * @return \stdClass |
||
| 2105 | 6 | */ |
|
| 2106 | public function getObject(): \stdClass |
||
| 2110 | |||
| 2111 | /** |
||
| 2112 | * alias: for "Arrayy->randomImmutable()" |
||
| 2113 | * |
||
| 2114 | * @return static |
||
| 2115 | * <p>(Immutable)</p> |
||
| 2116 | * |
||
| 2117 | * @see Arrayy::randomImmutable() |
||
| 2118 | */ |
||
| 2119 | 4 | public function getRandom(): self |
|
| 2123 | |||
| 2124 | /** |
||
| 2125 | 4 | * alias: for "Arrayy->randomKey()" |
|
| 2126 | 4 | * |
|
| 2127 | 3 | * @return mixed |
|
| 2128 | * <p>Get a key/index or null if there wasn't a key/index.</p> |
||
| 2129 | 1 | * |
|
| 2130 | * @see Arrayy::randomKey() |
||
| 2131 | */ |
||
| 2132 | 4 | public function getRandomKey() |
|
| 2136 | |||
| 2137 | /** |
||
| 2138 | 4 | * alias: for "Arrayy->randomKeys()" |
|
| 2139 | 4 | * |
|
| 2140 | * @param int $number |
||
| 2141 | * |
||
| 2142 | * @return static |
||
| 2143 | 4 | * <p>(Immutable)</p> |
|
| 2144 | 3 | * |
|
| 2145 | 2 | * @see Arrayy::randomKeys() |
|
| 2146 | 2 | */ |
|
| 2147 | public function getRandomKeys(int $number): self |
||
| 2151 | |||
| 2152 | /** |
||
| 2153 | * alias: for "Arrayy->randomValue()" |
||
| 2154 | 4 | * |
|
| 2155 | 4 | * @return mixed |
|
| 2156 | 4 | * <p>Get a random value or null if there wasn't a value.</p> |
|
| 2157 | 4 | * |
|
| 2158 | * @see Arrayy::randomValue() |
||
| 2159 | */ |
||
| 2160 | public function getRandomValue() |
||
| 2164 | |||
| 2165 | /** |
||
| 2166 | * alias: for "Arrayy->randomValues()" |
||
| 2167 | * |
||
| 2168 | * @param int $number |
||
| 2169 | * |
||
| 2170 | 1 | * @return static |
|
| 2171 | * <p>(Immutable)</p> |
||
| 2172 | 1 | * |
|
| 2173 | * @see Arrayy::randomValues() |
||
| 2174 | */ |
||
| 2175 | public function getRandomValues(int $number): self |
||
| 2179 | |||
| 2180 | /** |
||
| 2181 | * Gets all values. |
||
| 2182 | 23 | * |
|
| 2183 | * @return static |
||
| 2184 | 23 | * <p>The values of all elements in this array, in the order they |
|
| 2185 | * appear in the array.</p> |
||
| 2186 | 23 | */ |
|
| 2187 | public function getValues() |
||
| 2197 | |||
| 2198 | /** |
||
| 2199 | * Gets all values via Generator. |
||
| 2200 | * |
||
| 2201 | 28 | * @return \Generator |
|
| 2202 | * <p>The values of all elements in this array, in the order they |
||
| 2203 | 28 | * appear in the array as Generator.</p> |
|
| 2204 | */ |
||
| 2205 | public function getValuesYield(): \Generator |
||
| 2209 | |||
| 2210 | /** |
||
| 2211 | * Group values from a array according to the results of a closure. |
||
| 2212 | * |
||
| 2213 | 8 | * @param callable|string $grouper <p>A callable function name.</p> |
|
| 2214 | * @param bool $saveKeys |
||
| 2215 | 8 | * |
|
| 2216 | * @return static |
||
| 2217 | * <p>(Immutable)</p> |
||
| 2218 | */ |
||
| 2219 | public function group($grouper, bool $saveKeys = false): self |
||
| 2260 | |||
| 2261 | /** |
||
| 2262 | * Check if an array has a given key. |
||
| 2263 | * |
||
| 2264 | * @param mixed $key |
||
| 2265 | * |
||
| 2266 | * @return bool |
||
| 2267 | */ |
||
| 2268 | 12 | public function has($key): bool |
|
| 2279 | |||
| 2280 | /** |
||
| 2281 | 1 | * Check if an array has a given value. |
|
| 2282 | * |
||
| 2283 | 1 | * INFO: if you need to search recursive please use ```contains()``` |
|
| 2284 | 1 | * |
|
| 2285 | 1 | * @param mixed $value |
|
| 2286 | 1 | * |
|
| 2287 | * @return bool |
||
| 2288 | */ |
||
| 2289 | public function hasValue($value): bool |
||
| 2293 | |||
| 2294 | /** |
||
| 2295 | * Implodes the values of this array. |
||
| 2296 | * |
||
| 2297 | * @param string $glue |
||
| 2298 | * |
||
| 2299 | 4 | * @return string |
|
| 2300 | */ |
||
| 2301 | 4 | public function implode(string $glue = ''): string |
|
| 2305 | 1 | ||
| 2306 | /** |
||
| 2307 | 1 | * Implodes the keys of this array. |
|
| 2308 | 1 | * |
|
| 2309 | * @param string $glue |
||
| 2310 | 1 | * |
|
| 2311 | 1 | * @return string |
|
| 2312 | */ |
||
| 2313 | public function implodeKeys(string $glue = ''): string |
||
| 2317 | 3 | ||
| 2318 | 3 | /** |
|
| 2319 | * Given a list and an iterate-function that returns |
||
| 2320 | * a key for each element in the list (or a property name), |
||
| 2321 | * returns an object with an index of each item. |
||
| 2322 | * |
||
| 2323 | * @param mixed $key |
||
| 2324 | * |
||
| 2325 | * @return static |
||
| 2326 | * <p>(Immutable)</p> |
||
| 2327 | */ |
||
| 2328 | public function indexBy($key): self |
||
| 2345 | |||
| 2346 | 1 | /** |
|
| 2347 | 1 | * alias: for "Arrayy->searchIndex()" |
|
| 2348 | 1 | * |
|
| 2349 | 1 | * @param mixed $value <p>The value to search for.</p> |
|
| 2350 | 1 | * |
|
| 2351 | * @return false|mixed |
||
| 2352 | * |
||
| 2353 | * @see Arrayy::searchIndex() |
||
| 2354 | */ |
||
| 2355 | 1 | public function indexOf($value) |
|
| 2359 | |||
| 2360 | /** |
||
| 2361 | 1 | * Get everything but the last..$to items. |
|
| 2362 | 1 | * |
|
| 2363 | 1 | * @param int $to |
|
| 2364 | 1 | * |
|
| 2365 | * @return static |
||
| 2366 | * <p>(Immutable)</p> |
||
| 2367 | */ |
||
| 2368 | public function initial(int $to = 1): self |
||
| 2372 | |||
| 2373 | /** |
||
| 2374 | * Return an array with all elements found in input array. |
||
| 2375 | * |
||
| 2376 | 15 | * @param array $search |
|
| 2377 | * @param bool $keepKeys |
||
| 2378 | 15 | * |
|
| 2379 | 3 | * @return static |
|
| 2380 | * <p>(Immutable)</p> |
||
| 2381 | */ |
||
| 2382 | 13 | public function intersection(array $search, bool $keepKeys = false): self |
|
| 2404 | |||
| 2405 | 38 | /** |
|
| 2406 | 38 | * Return an array with all elements found in input array. |
|
| 2407 | * |
||
| 2408 | * @param array ...$array |
||
| 2409 | * |
||
| 2410 | * @return static |
||
| 2411 | * <p>(Immutable)</p> |
||
| 2412 | */ |
||
| 2413 | public function intersectionMulti(...$array): self |
||
| 2421 | |||
| 2422 | /** |
||
| 2423 | * Return a boolean flag which indicates whether the two input arrays have any common elements. |
||
| 2424 | * |
||
| 2425 | 1 | * @param array $search |
|
| 2426 | * |
||
| 2427 | 1 | * @return bool |
|
| 2428 | */ |
||
| 2429 | public function intersects(array $search): bool |
||
| 2433 | |||
| 2434 | /** |
||
| 2435 | 22 | * Invoke a function on all of an array's values. |
|
| 2436 | * |
||
| 2437 | * @param callable $callable |
||
| 2438 | 22 | * @param mixed $arguments |
|
| 2439 | * |
||
| 2440 | 22 | * @return static |
|
| 2441 | * <p>(Immutable)</p> |
||
| 2442 | */ |
||
| 2443 | public function invoke($callable, $arguments = []): self |
||
| 2467 | |||
| 2468 | /** |
||
| 2469 | * Check whether array is associative or not. |
||
| 2470 | * |
||
| 2471 | * @param bool $recursive |
||
| 2472 | 1 | * |
|
| 2473 | * @return bool |
||
| 2474 | * <p>Returns true if associative, false otherwise.</p> |
||
| 2475 | */ |
||
| 2476 | View Code Duplication | public function isAssoc(bool $recursive = false): bool |
|
| 2490 | |||
| 2491 | /** |
||
| 2492 | * Check if a given key or keys are empty. |
||
| 2493 | * |
||
| 2494 | * @param int|int[]|string|string[]|null $keys |
||
| 2495 | * |
||
| 2496 | * @return bool |
||
| 2497 | * <p>Returns true if empty, false otherwise.</p> |
||
| 2498 | */ |
||
| 2499 | public function isEmpty($keys = null): bool |
||
| 2517 | |||
| 2518 | /** |
||
| 2519 | * Check if the current array is equal to the given "$array" or not. |
||
| 2520 | * |
||
| 2521 | * @param array $array |
||
| 2522 | * |
||
| 2523 | * @return bool |
||
| 2524 | */ |
||
| 2525 | public function isEqual(array $array): bool |
||
| 2529 | 29 | ||
| 2530 | /** |
||
| 2531 | * Check if the current array is a multi-array. |
||
| 2532 | * |
||
| 2533 | * @return bool |
||
| 2534 | */ |
||
| 2535 | public function isMultiArray(): bool |
||
| 2543 | |||
| 2544 | 4 | /** |
|
| 2545 | 4 | * Check whether array is numeric or not. |
|
| 2546 | 4 | * |
|
| 2547 | 4 | * @return bool |
|
| 2548 | * <p>Returns true if numeric, false otherwise.</p> |
||
| 2549 | */ |
||
| 2550 | View Code Duplication | public function isNumeric(): bool |
|
| 2564 | |||
| 2565 | /** |
||
| 2566 | 1 | * Check if the current array is sequential [0, 1, 2, 3, 4, 5 ...] or not. |
|
| 2567 | * |
||
| 2568 | 1 | * @param bool $recursive |
|
| 2569 | * |
||
| 2570 | 1 | * @return bool |
|
| 2571 | */ |
||
| 2572 | public function isSequential(bool $recursive = false): bool |
||
| 2589 | |||
| 2590 | 1 | /** |
|
| 2591 | * @return array |
||
| 2592 | */ |
||
| 2593 | 28 | public function jsonSerialize(): array |
|
| 2597 | |||
| 2598 | /** |
||
| 2599 | * Gets the key/index of the element at the current internal iterator position. |
||
| 2600 | * |
||
| 2601 | * @return int|string|null |
||
| 2602 | */ |
||
| 2603 | public function key() |
||
| 2607 | |||
| 2608 | /** |
||
| 2609 | * Checks if the given key exists in the provided array. |
||
| 2610 | * |
||
| 2611 | * INFO: This method only use "array_key_exists()" if you want to use "dot"-notation, |
||
| 2612 | 4 | * then you need to use "Arrayy->offsetExists()". |
|
| 2613 | * |
||
| 2614 | 4 | * @param int|string $key the key to look for |
|
| 2615 | * |
||
| 2616 | 4 | * @return bool |
|
| 2617 | */ |
||
| 2618 | 4 | public function keyExists($key): bool |
|
| 2622 | |||
| 2623 | /** |
||
| 2624 | * Get all keys from the current array. |
||
| 2625 | * |
||
| 2626 | * @param bool $recursive [optional] <p> |
||
| 2627 | 17 | * Get all keys, also from all sub-arrays from an multi-dimensional array. |
|
| 2628 | * </p> |
||
| 2629 | 17 | * @param mixed|null $search_values [optional] <p> |
|
| 2630 | 17 | * If specified, then only keys containing these values are returned. |
|
| 2631 | 2 | * </p> |
|
| 2632 | * @param bool $strict [optional] <p> |
||
| 2633 | * Determines if strict comparison (===) should be used during the search. |
||
| 2634 | 15 | * </p> |
|
| 2635 | * |
||
| 2636 | * @return static |
||
| 2637 | * <p>(Immutable) An array of all the keys in input.</p> |
||
| 2638 | */ |
||
| 2639 | public function keys( |
||
| 2719 | 4 | ||
| 2720 | 4 | /** |
|
| 2721 | * Sort an array by key in reverse order. |
||
| 2722 | * |
||
| 2723 | 12 | * @param int $sort_flags [optional] <p> |
|
| 2724 | * You may modify the behavior of the sort using the optional |
||
| 2725 | 12 | * parameter sort_flags, for details |
|
| 2726 | * see sort. |
||
| 2727 | * </p> |
||
| 2728 | * |
||
| 2729 | * @return static |
||
| 2730 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 2731 | */ |
||
| 2732 | public function krsort(int $sort_flags = 0): self |
||
| 2740 | |||
| 2741 | 20 | /** |
|
| 2742 | * Get the last value from the current array. |
||
| 2743 | * |
||
| 2744 | * @return mixed |
||
| 2745 | * <p>Return null if there wasn't a element.</p> |
||
| 2746 | */ |
||
| 2747 | public function last() |
||
| 2756 | |||
| 2757 | 5 | /** |
|
| 2758 | * Get the last key from the current array. |
||
| 2759 | 5 | * |
|
| 2760 | * @return mixed |
||
| 2761 | 5 | * <p>Return null if there wasn't a element.</p> |
|
| 2762 | 4 | */ |
|
| 2763 | 3 | public function lastKey() |
|
| 2769 | |||
| 2770 | 4 | /** |
|
| 2771 | * Get the last value(s) from the current array. |
||
| 2772 | * |
||
| 2773 | 4 | * @param int|null $number |
|
| 2774 | * |
||
| 2775 | * @return static |
||
| 2776 | * <p>(Immutable)</p> |
||
| 2777 | 5 | */ |
|
| 2778 | 5 | public function lastsImmutable(int $number = null): self |
|
| 2809 | |||
| 2810 | /** |
||
| 2811 | * Get the last value(s) from the current array. |
||
| 2812 | * |
||
| 2813 | * @param int|null $number |
||
| 2814 | 14 | * |
|
| 2815 | * @return static |
||
| 2816 | 14 | * <p>(Mutable)</p> |
|
| 2817 | 2 | */ |
|
| 2818 | public function lastsMutable(int $number = null): self |
||
| 2847 | |||
| 2848 | /** |
||
| 2849 | * Count the values from the current array. |
||
| 2850 | * |
||
| 2851 | * alias: for "Arrayy->count()" |
||
| 2852 | * |
||
| 2853 | * @param int $mode |
||
| 2854 | * |
||
| 2855 | * @return int |
||
| 2856 | 25 | * |
|
| 2857 | * @see Arrayy::count() |
||
| 2858 | 25 | */ |
|
| 2859 | 4 | public function length(int $mode = \COUNT_NORMAL): int |
|
| 2863 | |||
| 2864 | 25 | /** |
|
| 2865 | 25 | * Apply the given function to the every element of the array, |
|
| 2866 | 25 | * collecting the results. |
|
| 2867 | 25 | * |
|
| 2868 | * @param callable $callable |
||
| 2869 | * @param bool $useKeyAsSecondParameter |
||
| 2870 | * @param mixed ...$arguments |
||
| 2871 | * |
||
| 2872 | * @return static |
||
| 2873 | * <p>(Immutable) Arrayy object with modified elements.</p> |
||
| 2874 | */ |
||
| 2875 | public function map(callable $callable, bool $useKeyAsSecondParameter = false, ...$arguments) |
||
| 2902 | |||
| 2903 | /** |
||
| 2904 | * Check if all items in current array match a truth test. |
||
| 2905 | * |
||
| 2906 | * @param \Closure $closure |
||
| 2907 | * |
||
| 2908 | * @return bool |
||
| 2909 | 16 | */ |
|
| 2910 | View Code Duplication | public function matches(\Closure $closure): bool |
|
| 2926 | |||
| 2927 | /** |
||
| 2928 | * Check if any item in the current array matches a truth test. |
||
| 2929 | * |
||
| 2930 | * @param \Closure $closure |
||
| 2931 | * |
||
| 2932 | * @return bool |
||
| 2933 | */ |
||
| 2934 | View Code Duplication | public function matchesAny(\Closure $closure): bool |
|
| 2950 | |||
| 2951 | /** |
||
| 2952 | * Get the max value from an array. |
||
| 2953 | * |
||
| 2954 | 15 | * @return mixed |
|
| 2955 | */ |
||
| 2956 | 15 | View Code Duplication | public function max() |
| 2964 | 10 | ||
| 2965 | /** |
||
| 2966 | 10 | * Merge the new $array into the current array. |
|
| 2967 | 1 | * |
|
| 2968 | * - keep key,value from the current array, also if the index is in the new $array |
||
| 2969 | * |
||
| 2970 | 9 | * @param array $array |
|
| 2971 | * @param bool $recursive |
||
| 2972 | * |
||
| 2973 | * @return static |
||
| 2974 | * <p>(Immutable)</p> |
||
| 2975 | */ |
||
| 2976 | View Code Duplication | public function mergeAppendKeepIndex(array $array = [], bool $recursive = false): self |
|
| 2990 | |||
| 2991 | /** |
||
| 2992 | 3 | * Merge the new $array into the current array. |
|
| 2993 | * |
||
| 2994 | 3 | * - replace duplicate assoc-keys from the current array with the key,values from the new $array |
|
| 2995 | * - create new indexes |
||
| 2996 | * |
||
| 2997 | * @param array $array |
||
| 2998 | * @param bool $recursive |
||
| 2999 | * |
||
| 3000 | * @return static |
||
| 3001 | * <p>(Immutable)</p> |
||
| 3002 | */ |
||
| 3003 | View Code Duplication | public function mergeAppendNewIndex(array $array = [], bool $recursive = false): self |
|
| 3017 | 1 | ||
| 3018 | 1 | /** |
|
| 3019 | 1 | * Merge the the current array into the $array. |
|
| 3020 | 1 | * |
|
| 3021 | * - use key,value from the new $array, also if the index is in the current array |
||
| 3022 | 1 | * |
|
| 3023 | 1 | * @param array $array |
|
| 3024 | 1 | * @param bool $recursive |
|
| 3025 | 1 | * |
|
| 3026 | 1 | * @return static |
|
| 3027 | * <p>(Immutable)</p> |
||
| 3028 | 1 | */ |
|
| 3029 | 1 | View Code Duplication | public function mergePrependKeepIndex(array $array = [], bool $recursive = false): self |
| 3043 | |||
| 3044 | /** |
||
| 3045 | * Merge the current array into the new $array. |
||
| 3046 | * |
||
| 3047 | * - replace duplicate assoc-keys from new $array with the key,values from the current array |
||
| 3048 | * - create new indexes |
||
| 3049 | * |
||
| 3050 | * @param array $array |
||
| 3051 | * @param bool $recursive |
||
| 3052 | * |
||
| 3053 | 1 | * @return static |
|
| 3054 | * <p>(Immutable)</p> |
||
| 3055 | 1 | */ |
|
| 3056 | View Code Duplication | public function mergePrependNewIndex(array $array = [], bool $recursive = false): self |
|
| 3070 | |||
| 3071 | /** |
||
| 3072 | * @return ArrayyMeta|static |
||
| 3073 | */ |
||
| 3074 | public static function meta() |
||
| 3078 | |||
| 3079 | /** |
||
| 3080 | * Get the min value from an array. |
||
| 3081 | 1 | * |
|
| 3082 | * @return mixed |
||
| 3083 | 1 | */ |
|
| 3084 | View Code Duplication | public function min() |
|
| 3092 | 1 | ||
| 3093 | 1 | /** |
|
| 3094 | 1 | * Get the most used value from the array. |
|
| 3095 | * |
||
| 3096 | * @return mixed |
||
| 3097 | * <p>Return null if there wasn't a element.</p> |
||
| 3098 | */ |
||
| 3099 | public function mostUsedValue() |
||
| 3103 | |||
| 3104 | /** |
||
| 3105 | * Get the most used value from the array. |
||
| 3106 | * |
||
| 3107 | * @param int|null $number <p>How many values you will take?</p> |
||
| 3108 | * |
||
| 3109 | * @return static |
||
| 3110 | * <p>(Immutable)</p> |
||
| 3111 | */ |
||
| 3112 | public function mostUsedValues(int $number = null): self |
||
| 3116 | |||
| 3117 | /** |
||
| 3118 | * Move an array element to a new index. |
||
| 3119 | * |
||
| 3120 | * cherry-picked from: http://stackoverflow.com/questions/12624153/move-an-array-element-to-a-new-index-in-php |
||
| 3121 | * |
||
| 3122 | * @param int|string $from |
||
| 3123 | * @param int $to |
||
| 3124 | * |
||
| 3125 | * @return static |
||
| 3126 | 5 | * <p>(Immutable)</p> |
|
| 3127 | */ |
||
| 3128 | 5 | public function moveElement($from, $to): self |
|
| 3161 | 11 | ||
| 3162 | 3 | /** |
|
| 3163 | * Move an array element to the first place. |
||
| 3164 | * |
||
| 3165 | 9 | * INFO: Instead of "Arrayy->moveElement()" this method will NOT |
|
| 3166 | 8 | * loss the keys of an indexed array. |
|
| 3167 | * |
||
| 3168 | 2 | * @param int|string $key |
|
| 3169 | * |
||
| 3170 | * @return static |
||
| 3171 | 9 | * <p>(Immutable)</p> |
|
| 3172 | */ |
||
| 3173 | View Code Duplication | public function moveElementToFirstPlace($key): self |
|
| 3189 | |||
| 3190 | 9 | /** |
|
| 3191 | * Move an array element to the last place. |
||
| 3192 | * |
||
| 3193 | * INFO: Instead of "Arrayy->moveElement()" this method will NOT |
||
| 3194 | * loss the keys of an indexed array. |
||
| 3195 | * |
||
| 3196 | * @param int|string $key |
||
| 3197 | * |
||
| 3198 | 9 | * @return static |
|
| 3199 | * <p>(Immutable)</p> |
||
| 3200 | */ |
||
| 3201 | View Code Duplication | public function moveElementToLastPlace($key): self |
|
| 3217 | 10 | ||
| 3218 | /** |
||
| 3219 | * Moves the internal iterator position to the next element and returns this element. |
||
| 3220 | 10 | * |
|
| 3221 | * @return mixed |
||
| 3222 | 10 | */ |
|
| 3223 | 9 | public function next() |
|
| 3227 | |||
| 3228 | /** |
||
| 3229 | * Get a subset of the items from the given array. |
||
| 3230 | * |
||
| 3231 | * @param mixed[] $keys |
||
| 3232 | 9 | * |
|
| 3233 | 1 | * @return static |
|
| 3234 | * <p>(Immutable)</p> |
||
| 3235 | 8 | */ |
|
| 3236 | public function only(array $keys): self |
||
| 3246 | |||
| 3247 | /** |
||
| 3248 | * Pad array to the specified size with a given value. |
||
| 3249 | * |
||
| 3250 | * @param int $size <p>Size of the result array.</p> |
||
| 3251 | * @param mixed $value <p>Empty value by default.</p> |
||
| 3252 | * |
||
| 3253 | * @return static |
||
| 3254 | * <p>(Immutable) Arrayy object padded to $size with $value.</p> |
||
| 3255 | 1 | */ |
|
| 3256 | public function pad(int $size, $value): self |
||
| 3264 | 1 | ||
| 3265 | 1 | /** |
|
| 3266 | 1 | * Partitions this array in two array according to a predicate. |
|
| 3267 | 1 | * Keys are preserved in the resulting array. |
|
| 3268 | 1 | * |
|
| 3269 | * @param \Closure $closure |
||
| 3270 | * <p>The predicate on which to partition.</p> |
||
| 3271 | 1 | * |
|
| 3272 | 1 | * @return array<int, Arrayy> |
|
| 3273 | * <p>An array with two elements. The first element contains the array |
||
| 3274 | * of elements where the predicate returned TRUE, the second element |
||
| 3275 | 1 | * contains the array of elements where the predicate returned FALSE.</p> |
|
| 3276 | */ |
||
| 3277 | public function partition(\Closure $closure): array |
||
| 3293 | 5 | ||
| 3294 | /** |
||
| 3295 | 5 | * Pop a specified value off the end of the current array. |
|
| 3296 | * |
||
| 3297 | 1 | * @return mixed |
|
| 3298 | 1 | * <p>(Mutable) The popped element from the current array.</p> |
|
| 3299 | */ |
||
| 3300 | public function pop() |
||
| 3306 | |||
| 3307 | /** |
||
| 3308 | * Prepend a (key) + value to the current array. |
||
| 3309 | * |
||
| 3310 | * @param mixed $value |
||
| 3311 | * @param mixed $key |
||
| 3312 | * |
||
| 3313 | * @return static |
||
| 3314 | * <p>(Mutable) Return this Arrayy object, with the prepended value.</p> |
||
| 3315 | 19 | */ |
|
| 3316 | public function prepend($value, $key = null): self |
||
| 3332 | 13 | ||
| 3333 | 13 | /** |
|
| 3334 | 13 | * Add a suffix to each key. |
|
| 3335 | * |
||
| 3336 | * @param mixed $suffix |
||
| 3337 | * |
||
| 3338 | 6 | * @return static |
|
| 3339 | * <p>(Immutable) Return an Arrayy object, with the prepended keys.</p> |
||
| 3340 | 6 | */ |
|
| 3341 | View Code Duplication | public function prependToEachKey($suffix): self |
|
| 3367 | |||
| 3368 | /** |
||
| 3369 | * Add a suffix to each value. |
||
| 3370 | * |
||
| 3371 | * @param mixed $suffix |
||
| 3372 | * |
||
| 3373 | * @return static |
||
| 3374 | * <p>(Immutable) Return an Arrayy object, with the prepended values.</p> |
||
| 3375 | */ |
||
| 3376 | View Code Duplication | public function prependToEachValue($suffix): self |
|
| 3404 | |||
| 3405 | /** |
||
| 3406 | * Return the value of a given key and |
||
| 3407 | * delete the key. |
||
| 3408 | * |
||
| 3409 | * @param int|int[]|string|string[]|null $keyOrKeys |
||
| 3410 | * @param mixed $fallback |
||
| 3411 | 17 | * |
|
| 3412 | * @return mixed |
||
| 3413 | 17 | */ |
|
| 3414 | public function pull($keyOrKeys = null, $fallback = null) |
||
| 3436 | |||
| 3437 | /** |
||
| 3438 | * Push one or more values onto the end of array at once. |
||
| 3439 | * |
||
| 3440 | * @param array ...$args |
||
| 3441 | * |
||
| 3442 | * @return static |
||
| 3443 | 4 | * <p>(Mutable) Return this Arrayy object, with pushed elements to the end of array.</p> |
|
| 3444 | * |
||
| 3445 | 4 | * @noinspection ReturnTypeCanBeDeclaredInspection |
|
| 3446 | */ |
||
| 3447 | 4 | public function push(...$args) |
|
| 3465 | |||
| 3466 | /** |
||
| 3467 | * Get a random value from the current array. |
||
| 3468 | * |
||
| 3469 | * @param int|null $number <p>How many values you will take?</p> |
||
| 3470 | * |
||
| 3471 | * @return static |
||
| 3472 | * <p>(Immutable)</p> |
||
| 3473 | */ |
||
| 3474 | public function randomImmutable(int $number = null): self |
||
| 3507 | |||
| 3508 | 1 | /** |
|
| 3509 | 1 | * Pick a random key/index from the keys of this array. |
|
| 3510 | * |
||
| 3511 | * @throws \RangeException If array is empty |
||
| 3512 | 1 | * |
|
| 3513 | 1 | * @return mixed |
|
| 3514 | 1 | * <p>Get a key/index or null if there wasn't a key/index.</p> |
|
| 3515 | 1 | */ |
|
| 3516 | public function randomKey() |
||
| 3526 | |||
| 3527 | 18 | /** |
|
| 3528 | 18 | * Pick a given number of random keys/indexes out of this array. |
|
| 3529 | 18 | * |
|
| 3530 | 18 | * @param int $number <p>The number of keys/indexes (should be <= \count($this->array))</p> |
|
| 3531 | * |
||
| 3532 | * @throws \RangeException If array is empty |
||
| 3533 | * |
||
| 3534 | * @return static |
||
| 3535 | * <p>(Immutable)</p> |
||
| 3536 | */ |
||
| 3537 | public function randomKeys(int $number): self |
||
| 3561 | |||
| 3562 | /** |
||
| 3563 | * Get a random value from the current array. |
||
| 3564 | * |
||
| 3565 | * @param int|null $number <p>How many values you will take?</p> |
||
| 3566 | 9 | * |
|
| 3567 | * @return static |
||
| 3568 | 9 | * <p>(Mutable)</p> |
|
| 3569 | */ |
||
| 3570 | 9 | public function randomMutable(int $number = null): self |
|
| 3595 | 1 | ||
| 3596 | 1 | /** |
|
| 3597 | 1 | * Pick a random value from the values of this array. |
|
| 3598 | * |
||
| 3599 | * @return mixed |
||
| 3600 | * <p>Get a random value or null if there wasn't a value.</p> |
||
| 3601 | */ |
||
| 3602 | public function randomValue() |
||
| 3612 | 18 | ||
| 3613 | /** |
||
| 3614 | * Pick a given number of random values out of this array. |
||
| 3615 | * |
||
| 3616 | * @param int $number |
||
| 3617 | * |
||
| 3618 | * @return static |
||
| 3619 | * <p>(Mutable)</p> |
||
| 3620 | */ |
||
| 3621 | public function randomValues(int $number): self |
||
| 3625 | |||
| 3626 | 18 | /** |
|
| 3627 | 18 | * Get a random value from an array, with the ability to skew the results. |
|
| 3628 | 18 | * |
|
| 3629 | 18 | * Example: randomWeighted(['foo' => 1, 'bar' => 2]) has a 66% chance of returning bar. |
|
| 3630 | * |
||
| 3631 | * @param array $array |
||
| 3632 | * @param int|null $number <p>How many values you will take?</p> |
||
| 3633 | * |
||
| 3634 | * @return static |
||
| 3635 | * <p>(Immutable)</p> |
||
| 3636 | */ |
||
| 3637 | public function randomWeighted(array $array, int $number = null): self |
||
| 3652 | |||
| 3653 | /** |
||
| 3654 | * Reduce the current array via callable e.g. anonymous-function. |
||
| 3655 | * |
||
| 3656 | * @param callable $callable |
||
| 3657 | * @param mixed $init |
||
| 3658 | 7 | * |
|
| 3659 | * @return static |
||
| 3660 | 7 | * <p>(Immutable)</p> |
|
| 3661 | */ |
||
| 3662 | 7 | public function reduce($callable, $init = []): self |
|
| 3692 | |||
| 3693 | /** |
||
| 3694 | * @param bool $unique |
||
| 3695 | 7 | * |
|
| 3696 | 7 | * @return static |
|
| 3697 | * <p>(Immutable)</p> |
||
| 3698 | */ |
||
| 3699 | 7 | public function reduce_dimension(bool $unique = true): self |
|
| 3718 | |||
| 3719 | /** |
||
| 3720 | 1 | * Create a numerically re-indexed Arrayy object. |
|
| 3721 | 1 | * |
|
| 3722 | 1 | * @return static |
|
| 3723 | 1 | * <p>(Mutable) Return this Arrayy object, with re-indexed array-elements.</p> |
|
| 3724 | */ |
||
| 3725 | public function reindex(): self |
||
| 3733 | |||
| 3734 | /** |
||
| 3735 | * Return all items that fail the truth test. |
||
| 3736 | * |
||
| 3737 | 2 | * @param \Closure $closure |
|
| 3738 | * |
||
| 3739 | 2 | * @return static |
|
| 3740 | * <p>(Immutable)</p> |
||
| 3741 | 2 | */ |
|
| 3742 | 2 | View Code Duplication | public function reject(\Closure $closure): self |
| 3759 | |||
| 3760 | /** |
||
| 3761 | * Remove a value from the current array (optional using dot-notation). |
||
| 3762 | * |
||
| 3763 | * @param mixed $key |
||
| 3764 | * |
||
| 3765 | * @return static |
||
| 3766 | * <p>(Mutable)</p> |
||
| 3767 | */ |
||
| 3768 | public function remove($key) |
||
| 3791 | |||
| 3792 | 1 | /** |
|
| 3793 | 1 | * alias: for "Arrayy->count()" |
|
| 3794 | 1 | * |
|
| 3795 | 1 | * @param mixed $element |
|
| 3796 | * |
||
| 3797 | * @return static |
||
| 3798 | */ |
||
| 3799 | public function removeElement($element) |
||
| 3803 | |||
| 3804 | /** |
||
| 3805 | * Remove the first value from the current array. |
||
| 3806 | * |
||
| 3807 | * @return static |
||
| 3808 | 3 | * <p>(Immutable)</p> |
|
| 3809 | */ |
||
| 3810 | 3 | View Code Duplication | public function removeFirst(): self |
| 3822 | |||
| 3823 | /** |
||
| 3824 | * Remove the last value from the current array. |
||
| 3825 | * |
||
| 3826 | * @return static |
||
| 3827 | * <p>(Immutable)</p> |
||
| 3828 | */ |
||
| 3829 | View Code Duplication | public function removeLast(): self |
|
| 3841 | |||
| 3842 | /** |
||
| 3843 | * Removes a particular value from an array (numeric or associative). |
||
| 3844 | * |
||
| 3845 | * @param mixed $value |
||
| 3846 | * |
||
| 3847 | * @return static |
||
| 3848 | * <p>(Immutable)</p> |
||
| 3849 | */ |
||
| 3850 | 15 | public function removeValue($value): self |
|
| 3873 | 1 | ||
| 3874 | /** |
||
| 3875 | 1 | * Generate array of repeated arrays. |
|
| 3876 | 1 | * |
|
| 3877 | 1 | * @param int $times <p>How many times has to be repeated.</p> |
|
| 3878 | 1 | * |
|
| 3879 | * @return static |
||
| 3880 | * <p>(Immutable)</p> |
||
| 3881 | */ |
||
| 3882 | public function repeat($times): self |
||
| 3894 | 9 | ||
| 3895 | /** |
||
| 3896 | * Replace a key with a new key/value pair. |
||
| 3897 | * |
||
| 3898 | * @param mixed $replace |
||
| 3899 | * @param mixed $key |
||
| 3900 | * @param mixed $value |
||
| 3901 | * |
||
| 3902 | * @return static |
||
| 3903 | * <p>(Immutable)</p> |
||
| 3904 | */ |
||
| 3905 | public function replace($replace, $key, $value): self |
||
| 3912 | |||
| 3913 | 4 | /** |
|
| 3914 | * Create an array using the current array as values and the other array as keys. |
||
| 3915 | 4 | * |
|
| 3916 | * @param array $keys <p>An array of keys.</p> |
||
| 3917 | * |
||
| 3918 | * @return static |
||
| 3919 | * <p>(Immutable) Arrayy object with keys from the other array.</p> |
||
| 3920 | */ |
||
| 3921 | public function replaceAllKeys(array $keys): self |
||
| 3929 | 20 | ||
| 3930 | 10 | /** |
|
| 3931 | * Create an array using the current array as keys and the other array as values. |
||
| 3932 | * |
||
| 3933 | * @param array $array <p>An array o values.</p> |
||
| 3934 | 11 | * |
|
| 3935 | * @return static |
||
| 3936 | * <p>(Immutable) Arrayy object with values from the other array.</p> |
||
| 3937 | */ |
||
| 3938 | public function replaceAllValues(array $array): self |
||
| 3946 | |||
| 3947 | 9 | /** |
|
| 3948 | * Replace the keys in an array with another set. |
||
| 3949 | * |
||
| 3950 | 9 | * @param array $keys <p>An array of keys matching the array's size</p> |
|
| 3951 | * |
||
| 3952 | 9 | * @return static |
|
| 3953 | * <p>(Immutable)</p> |
||
| 3954 | */ |
||
| 3955 | public function replaceKeys(array $keys): self |
||
| 3966 | 7 | ||
| 3967 | /** |
||
| 3968 | * Replace the first matched value in an array. |
||
| 3969 | 9 | * |
|
| 3970 | 9 | * @param mixed $search <p>The value to replace.</p> |
|
| 3971 | 9 | * @param mixed $replacement <p>The value to replace.</p> |
|
| 3972 | 9 | * |
|
| 3973 | * @return static |
||
| 3974 | * <p>(Immutable)</p> |
||
| 3975 | */ |
||
| 3976 | public function replaceOneValue($search, $replacement = ''): self |
||
| 3991 | 18 | ||
| 3992 | /** |
||
| 3993 | * Replace values in the current array. |
||
| 3994 | * |
||
| 3995 | * @param mixed $search <p>The value to replace.</p> |
||
| 3996 | * @param mixed $replacement <p>What to replace it with.</p> |
||
| 3997 | * |
||
| 3998 | * @return static |
||
| 3999 | * <p>(Immutable)</p> |
||
| 4000 | */ |
||
| 4001 | public function replaceValues($search, $replacement = ''): self |
||
| 4009 | |||
| 4010 | 11 | /** |
|
| 4011 | 4 | * Get the last elements from index $from until the end of this array. |
|
| 4012 | * |
||
| 4013 | * @param int $from |
||
| 4014 | 11 | * |
|
| 4015 | * @return static |
||
| 4016 | * <p>(Immutable)</p> |
||
| 4017 | */ |
||
| 4018 | View Code Duplication | public function rest(int $from = 1): self |
|
| 4028 | |||
| 4029 | /** |
||
| 4030 | * Return the array in the reverse order. |
||
| 4031 | * |
||
| 4032 | * @return static |
||
| 4033 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 4034 | */ |
||
| 4035 | public function reverse(): self |
||
| 4043 | |||
| 4044 | /** |
||
| 4045 | 2 | * Sort an array in reverse order. |
|
| 4046 | * |
||
| 4047 | 2 | * @param int $sort_flags [optional] <p> |
|
| 4048 | * You may modify the behavior of the sort using the optional |
||
| 4049 | 1 | * parameter sort_flags, for details |
|
| 4050 | 1 | * see sort. |
|
| 4051 | 1 | * </p> |
|
| 4052 | * |
||
| 4053 | 1 | * @return static |
|
| 4054 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 4055 | */ |
||
| 4056 | public function rsort(int $sort_flags = 0): self |
||
| 4064 | |||
| 4065 | /** |
||
| 4066 | 1 | * Search for the first index of the current array via $value. |
|
| 4067 | * |
||
| 4068 | * @param mixed $value |
||
| 4069 | 2 | * |
|
| 4070 | * @return false|float|int|string |
||
| 4071 | 2 | * <p>Will return <b>FALSE</b> if the value can't be found.</p> |
|
| 4072 | */ |
||
| 4073 | public function searchIndex($value) |
||
| 4083 | |||
| 4084 | /** |
||
| 4085 | * Search for the value of the current array via $index. |
||
| 4086 | * |
||
| 4087 | * @param mixed $index |
||
| 4088 | * |
||
| 4089 | * @return static |
||
| 4090 | * <p>(Immutable) Will return a empty Arrayy if the value wasn't found.</p> |
||
| 4091 | */ |
||
| 4092 | 20 | public function searchValue($index): self |
|
| 4122 | |||
| 4123 | /** |
||
| 4124 | * Set a value for the current array (optional using dot-notation). |
||
| 4125 | * |
||
| 4126 | * @param string $key <p>The key to set.</p> |
||
| 4127 | * @param mixed $value <p>Its value.</p> |
||
| 4128 | 1 | * |
|
| 4129 | * @return static |
||
| 4130 | 1 | * <p>(Mutable)</p> |
|
| 4131 | 1 | */ |
|
| 4132 | 1 | public function set($key, $value): self |
|
| 4140 | 1 | ||
| 4141 | 1 | /** |
|
| 4142 | 1 | * Get a value from a array and set it if it was not. |
|
| 4143 | * |
||
| 4144 | * WARNING: this method only set the value, if the $key is not already set |
||
| 4145 | * |
||
| 4146 | 1 | * @param mixed $key <p>The key</p> |
|
| 4147 | * @param mixed $fallback <p>The default value to set if it isn't.</p> |
||
| 4148 | * |
||
| 4149 | * @return mixed |
||
| 4150 | * <p>(Mutable)</p> |
||
| 4151 | */ |
||
| 4152 | public function setAndGet($key, $fallback = null) |
||
| 4163 | 1 | ||
| 4164 | 1 | /** |
|
| 4165 | * Shifts a specified value off the beginning of array. |
||
| 4166 | * |
||
| 4167 | * @return mixed |
||
| 4168 | 1 | * <p>(Mutable) A shifted element from the current array.</p> |
|
| 4169 | */ |
||
| 4170 | public function shift() |
||
| 4176 | |||
| 4177 | /** |
||
| 4178 | 1 | * Shuffle the current array. |
|
| 4179 | * |
||
| 4180 | * @param bool $secure <p>using a CSPRNG | @link https://paragonie.com/b/JvICXzh_jhLyt4y3</p> |
||
| 4181 | 1 | * @param array $array [optional] |
|
| 4182 | * |
||
| 4183 | 1 | * @return static |
|
| 4184 | 1 | * <p>(Immutable)</p> |
|
| 4185 | 1 | */ |
|
| 4186 | 1 | public function shuffle(bool $secure = false, array $array = null): self |
|
| 4229 | |||
| 4230 | /** |
||
| 4231 | * Count the values from the current array. |
||
| 4232 | * |
||
| 4233 | * alias: for "Arrayy->count()" |
||
| 4234 | * |
||
| 4235 | * @param int $mode |
||
| 4236 | * |
||
| 4237 | 5 | * @return int |
|
| 4238 | */ |
||
| 4239 | 5 | public function size(int $mode = \COUNT_NORMAL): int |
|
| 4243 | 5 | ||
| 4244 | 5 | /** |
|
| 4245 | * Checks whether array has exactly $size items. |
||
| 4246 | 5 | * |
|
| 4247 | 5 | * @param int $size |
|
| 4248 | * |
||
| 4249 | * @return bool |
||
| 4250 | */ |
||
| 4251 | View Code Duplication | public function sizeIs(int $size): bool |
|
| 4265 | |||
| 4266 | 20 | /** |
|
| 4267 | 20 | * Checks whether array has between $fromSize to $toSize items. $toSize can be |
|
| 4268 | 20 | * smaller than $fromSize. |
|
| 4269 | 20 | * |
|
| 4270 | 20 | * @param int $fromSize |
|
| 4271 | * @param int $toSize |
||
| 4272 | * |
||
| 4273 | * @return bool |
||
| 4274 | */ |
||
| 4275 | public function sizeIsBetween(int $fromSize, int $toSize): bool |
||
| 4295 | |||
| 4296 | /** |
||
| 4297 | * Checks whether array has more than $size items. |
||
| 4298 | * |
||
| 4299 | * @param int $size |
||
| 4300 | * |
||
| 4301 | * @return bool |
||
| 4302 | */ |
||
| 4303 | View Code Duplication | public function sizeIsGreaterThan(int $size): bool |
|
| 4317 | |||
| 4318 | /** |
||
| 4319 | * Checks whether array has less than $size items. |
||
| 4320 | * |
||
| 4321 | 1 | * @param int $size |
|
| 4322 | * |
||
| 4323 | 1 | * @return bool |
|
| 4324 | */ |
||
| 4325 | View Code Duplication | public function sizeIsLessThan(int $size): bool |
|
| 4339 | |||
| 4340 | /** |
||
| 4341 | 1 | * Counts all elements in an array, or something in an object. |
|
| 4342 | * |
||
| 4343 | 1 | * <p> |
|
| 4344 | 1 | * For objects, if you have SPL installed, you can hook into count() by implementing interface {@see Countable}. |
|
| 4345 | * The interface has exactly one method, {@see Countable::count()}, which returns the return value for the count() |
||
| 4346 | * function. Please see the {@see Array} section of the manual for a detailed explanation of how arrays are |
||
| 4347 | 1 | * implemented and used in PHP. |
|
| 4348 | 1 | * </p> |
|
| 4349 | 1 | * |
|
| 4350 | 1 | * @return int |
|
| 4351 | 1 | * <p> |
|
| 4352 | * The number of elements in var, which is |
||
| 4353 | * typically an array, since anything else will have one |
||
| 4354 | 1 | * element. |
|
| 4355 | * </p> |
||
| 4356 | 1 | * <p> |
|
| 4357 | 1 | * If var is not an array or an object with |
|
| 4358 | * implemented Countable interface, |
||
| 4359 | * 1 will be returned. |
||
| 4360 | 1 | * There is one exception, if var is &null;, |
|
| 4361 | 1 | * 0 will be returned. |
|
| 4362 | * </p> |
||
| 4363 | * <p> |
||
| 4364 | 1 | * Caution: count may return 0 for a variable that isn't set, |
|
| 4365 | * but it may also return 0 for a variable that has been initialized with an |
||
| 4366 | 1 | * empty array. Use isset to test if a variable is set. |
|
| 4367 | * </p> |
||
| 4368 | */ |
||
| 4369 | public function sizeRecursive(): int |
||
| 4373 | 1 | ||
| 4374 | 1 | /** |
|
| 4375 | 1 | * Extract a slice of the array. |
|
| 4376 | * |
||
| 4377 | * @param int $offset <p>Slice begin index.</p> |
||
| 4378 | * @param int|null $length <p>Length of the slice.</p> |
||
| 4379 | * @param bool $preserveKeys <p>Whether array keys are preserved or no.</p> |
||
| 4380 | * |
||
| 4381 | * @return static |
||
| 4382 | * <p>A slice of the original array with length $length.</p> |
||
| 4383 | */ |
||
| 4384 | public function slice(int $offset, int $length = null, bool $preserveKeys = false) |
||
| 4397 | 1 | ||
| 4398 | 1 | /** |
|
| 4399 | * Sort the current array and optional you can keep the keys. |
||
| 4400 | * |
||
| 4401 | 1 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
|
| 4402 | 1 | * @param int $strategy <p>sort_flags => use e.g.: <strong>SORT_REGULAR</strong> (default) or |
|
| 4403 | 1 | * <strong>SORT_NATURAL</strong></p> |
|
| 4404 | 1 | * @param bool $keepKeys |
|
| 4405 | * |
||
| 4406 | * @return static |
||
| 4407 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 4408 | */ |
||
| 4409 | public function sort($direction = \SORT_ASC, int $strategy = \SORT_REGULAR, bool $keepKeys = false): self |
||
| 4420 | |||
| 4421 | /** |
||
| 4422 | 1 | * Sort the current array by key. |
|
| 4423 | 1 | * |
|
| 4424 | * @see http://php.net/manual/en/function.ksort.php |
||
| 4425 | * @see http://php.net/manual/en/function.krsort.php |
||
| 4426 | * |
||
| 4427 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 4428 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 4429 | * <strong>SORT_NATURAL</strong></p> |
||
| 4430 | * |
||
| 4431 | * @return static |
||
| 4432 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 4433 | */ |
||
| 4434 | public function sortKeys($direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
||
| 4442 | 1 | ||
| 4443 | 1 | /** |
|
| 4444 | 1 | * Sort the current array by value. |
|
| 4445 | 1 | * |
|
| 4446 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 4447 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 4448 | * <strong>SORT_NATURAL</strong></p> |
||
| 4449 | * |
||
| 4450 | * @return static |
||
| 4451 | * <p>(Mutable)</p> |
||
| 4452 | */ |
||
| 4453 | public function sortValueKeepIndex($direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
||
| 4457 | |||
| 4458 | 236 | /** |
|
| 4459 | * Sort the current array by value. |
||
| 4460 | * |
||
| 4461 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 4462 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 4463 | * <strong>SORT_NATURAL</strong></p> |
||
| 4464 | * |
||
| 4465 | * @return static |
||
| 4466 | * <p>(Mutable)</p> |
||
| 4467 | */ |
||
| 4468 | public function sortValueNewIndex($direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
||
| 4472 | 7 | ||
| 4473 | /** |
||
| 4474 | * Sort a array by value, by a closure or by a property. |
||
| 4475 | * |
||
| 4476 | 7 | * - If the sorter is null, the array is sorted naturally. |
|
| 4477 | * - Associative (string) keys will be maintained, but numeric keys will be re-indexed. |
||
| 4478 | * |
||
| 4479 | * @param callable|string|null $sorter |
||
| 4480 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or |
||
| 4481 | * <strong>SORT_DESC</strong></p> |
||
| 4482 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 4483 | * <strong>SORT_NATURAL</strong></p> |
||
| 4484 | * |
||
| 4485 | * @return static |
||
| 4486 | * <p>(Immutable)</p> |
||
| 4487 | 19 | */ |
|
| 4488 | public function sorter($sorter = null, $direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
||
| 4525 | |||
| 4526 | /** |
||
| 4527 | * @param int $offset |
||
| 4528 | 11 | * @param int|null $length |
|
| 4529 | * @param array $replacement |
||
| 4530 | 11 | * |
|
| 4531 | 11 | * @return static |
|
| 4532 | * <p>(Immutable)</p> |
||
| 4533 | 10 | */ |
|
| 4534 | 10 | public function splice(int $offset, int $length = null, $replacement = []): self |
|
| 4546 | 11 | ||
| 4547 | /** |
||
| 4548 | * Split an array in the given amount of pieces. |
||
| 4549 | 11 | * |
|
| 4550 | * @param int $numberOfPieces |
||
| 4551 | * @param bool $keepKeys |
||
| 4552 | * |
||
| 4553 | * @return static |
||
| 4554 | * <p>(Immutable)</p> |
||
| 4555 | */ |
||
| 4556 | public function split(int $numberOfPieces = 2, bool $keepKeys = false): self |
||
| 4575 | 4 | ||
| 4576 | /** |
||
| 4577 | 4 | * Stripe all empty items. |
|
| 4578 | * |
||
| 4579 | 4 | * @return static |
|
| 4580 | * <p>(Immutable)</p> |
||
| 4581 | */ |
||
| 4582 | public function stripEmpty(): self |
||
| 4594 | 2 | ||
| 4595 | /** |
||
| 4596 | 2 | * Swap two values between positions by key. |
|
| 4597 | 2 | * |
|
| 4598 | 2 | * @param int|string $swapA <p>a key in the array</p> |
|
| 4599 | * @param int|string $swapB <p>a key in the array</p> |
||
| 4600 | * |
||
| 4601 | * @return static |
||
| 4602 | * <p>(Immutable)</p> |
||
| 4603 | */ |
||
| 4604 | public function swap($swapA, $swapB): self |
||
| 4616 | 6 | ||
| 4617 | /** |
||
| 4618 | 6 | * alias: for "Arrayy->getArray()" |
|
| 4619 | * |
||
| 4620 | * @param bool $convertAllArrayyElements |
||
| 4621 | 12 | * |
|
| 4622 | * @return array |
||
| 4623 | * |
||
| 4624 | * @see Arrayy::getArray() |
||
| 4625 | */ |
||
| 4626 | public function toArray(bool $convertAllArrayyElements = false): array |
||
| 4630 | 1048 | ||
| 4631 | /** |
||
| 4632 | 1048 | * Convert the current array to JSON. |
|
| 4633 | * |
||
| 4634 | 1048 | * @param int $options [optional] <p>e.g. JSON_PRETTY_PRINT</p> |
|
| 4635 | 73 | * @param int $depth [optional] <p>Set the maximum depth. Must be greater than zero.</p> |
|
| 4636 | 73 | * |
|
| 4637 | 73 | * @return string |
|
| 4638 | 73 | */ |
|
| 4639 | 73 | public function toJson(int $options = 0, int $depth = 512): string |
|
| 4648 | 16 | ||
| 4649 | /** |
||
| 4650 | * Implodes array to a string with specified separator. |
||
| 4651 | * |
||
| 4652 | 985 | * @param string $separator [optional] <p>The element's separator.</p> |
|
| 4653 | * |
||
| 4654 | 985 | * @return string |
|
| 4655 | * <p>The string representation of array, separated by ",".</p> |
||
| 4656 | 985 | */ |
|
| 4657 | public function toString(string $separator = ','): string |
||
| 4661 | 984 | ||
| 4662 | 854 | /** |
|
| 4663 | 854 | * Return a duplicate free copy of the current array. |
|
| 4664 | 854 | * |
|
| 4665 | 854 | * @return static |
|
| 4666 | * <p>(Mutable)</p> |
||
| 4667 | */ |
||
| 4668 | public function unique(): self |
||
| 4686 | |||
| 4687 | 3 | /** |
|
| 4688 | 3 | * Return a duplicate free copy of the current array. (with the old keys) |
|
| 4689 | 1 | * |
|
| 4690 | * @return static |
||
| 4691 | 3 | * <p>(Mutable)</p> |
|
| 4692 | */ |
||
| 4693 | public function uniqueKeepIndex(): self |
||
| 4721 | |||
| 4722 | 11 | /** |
|
| 4723 | 4 | * alias: for "Arrayy->unique()" |
|
| 4724 | * |
||
| 4725 | * @return static |
||
| 4726 | 11 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
|
| 4727 | 11 | * |
|
| 4728 | 11 | * @see Arrayy::unique() |
|
| 4729 | */ |
||
| 4730 | public function uniqueNewIndex(): self |
||
| 4734 | |||
| 4735 | /** |
||
| 4736 | 1 | * Prepends one or more values to the beginning of array at once. |
|
| 4737 | * |
||
| 4738 | 1 | * @param array ...$args |
|
| 4739 | * |
||
| 4740 | * @return static |
||
| 4741 | 1 | * <p>(Mutable) Return this Arrayy object, with prepended elements to the beginning of array.</p> |
|
| 4742 | */ |
||
| 4743 | 1 | public function unshift(...$args): self |
|
| 4751 | 1 | ||
| 4752 | /** |
||
| 4753 | 1 | * Get all values from a array. |
|
| 4754 | * |
||
| 4755 | * @return static |
||
| 4756 | * <p>(Immutable)</p> |
||
| 4757 | 1 | */ |
|
| 4758 | public function values(): self |
||
| 4771 | |||
| 4772 | 11 | /** |
|
| 4773 | * Apply the given function to every element in the array, discarding the results. |
||
| 4774 | * |
||
| 4775 | * @param callable $callable |
||
| 4776 | * @param bool $recursive <p>Whether array will be walked recursively or no</p> |
||
| 4777 | * |
||
| 4778 | * @return static |
||
| 4779 | * <p>(Mutable) Return this Arrayy object, with modified elements.</p> |
||
| 4780 | 4 | */ |
|
| 4781 | public function walk($callable, bool $recursive = false): self |
||
| 4793 | 4 | ||
| 4794 | /** |
||
| 4795 | 4 | * Convert an array into a object. |
|
| 4796 | * |
||
| 4797 | * @param array $array PHP array |
||
| 4798 | * |
||
| 4799 | 4 | * @return \stdClass |
|
| 4800 | 1 | */ |
|
| 4801 | 1 | protected static function arrayToObject(array $array = []): \stdClass |
|
| 4820 | |||
| 4821 | /** |
||
| 4822 | * @param array|\Generator|null $input <p> |
||
| 4823 | * An array containing keys to return. |
||
| 4824 | * </p> |
||
| 4825 | * @param mixed|null $search_values [optional] <p> |
||
| 4826 | * If specified, then only keys containing these values are returned. |
||
| 4827 | 1050 | * </p> |
|
| 4828 | * @param bool $strict [optional] <p> |
||
| 4829 | 1050 | * Determines if strict comparison (===) should be used during the |
|
| 4830 | * search. |
||
| 4831 | 1050 | * </p> |
|
| 4832 | 2 | * |
|
| 4833 | * @return array |
||
| 4834 | * <p>an array of all the keys in input</p> |
||
| 4835 | 1048 | */ |
|
| 4836 | protected function array_keys_recursive( |
||
| 4897 | |||
| 4898 | 36 | /** |
|
| 4899 | * @param mixed $path |
||
| 4900 | 32 | * @param callable $callable |
|
| 4901 | * @param array|null $currentOffset |
||
| 4902 | * |
||
| 4903 | 8 | * @return void |
|
| 4904 | */ |
||
| 4905 | protected function callAtPath($path, $callable, &$currentOffset = null) |
||
| 4934 | 14 | ||
| 4935 | 3 | /** |
|
| 4936 | * create a fallback for array |
||
| 4937 | * |
||
| 4938 | 14 | * 1. use the current array, if it's a array |
|
| 4939 | 14 | * 2. fallback to empty array, if there is nothing |
|
| 4940 | * 3. call "getArray()" on object, if there is a "Arrayy"-object |
||
| 4941 | * 4. call "createFromObject()" on object, if there is a "\Traversable"-object |
||
| 4942 | * 5. call "__toArray()" on object, if the method exists |
||
| 4943 | * 6. cast a string or object with "__toString()" into an array |
||
| 4944 | * 7. throw a "InvalidArgumentException"-Exception |
||
| 4945 | 14 | * |
|
| 4946 | 10 | * @param mixed $data |
|
| 4947 | * |
||
| 4948 | * @throws \InvalidArgumentException |
||
| 4949 | * |
||
| 4950 | 8 | * @return array |
|
| 4951 | */ |
||
| 4952 | protected function fallbackForArray(&$data): array |
||
| 4962 | |||
| 4963 | /** |
||
| 4964 | 51 | * @return bool |
|
| 4965 | 6 | * |
|
| 4966 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
| 4967 | */ |
||
| 4968 | 50 | protected function generatorToArray() |
|
| 4979 | |||
| 4980 | /** |
||
| 4981 | 42 | * Get correct PHP constant for direction. |
|
| 4982 | * |
||
| 4983 | * @param int|string $direction |
||
| 4984 | * |
||
| 4985 | 42 | * @return int |
|
| 4986 | */ |
||
| 4987 | protected function getDirection($direction): int |
||
| 5009 | |||
| 5010 | /** |
||
| 5011 | * @return TypeCheckPhpDoc[] |
||
| 5012 | * |
||
| 5013 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
| 5014 | 18 | */ |
|
| 5015 | protected function getPropertiesFromPhpDoc() |
||
| 5040 | |||
| 5041 | /** |
||
| 5042 | * @param mixed $glue |
||
| 5043 | 18 | * @param mixed $pieces |
|
| 5044 | * @param bool $useKeys |
||
| 5045 | 18 | * |
|
| 5046 | * @return string |
||
| 5047 | */ |
||
| 5048 | protected function implode_recursive($glue = '', $pieces = [], bool $useKeys = false): string |
||
| 5078 | 922 | ||
| 5079 | /** |
||
| 5080 | 922 | * @param mixed $needle <p> |
|
| 5081 | * The searched value. |
||
| 5082 | 3 | * </p> |
|
| 5083 | * <p> |
||
| 5084 | 3 | * If needle is a string, the comparison is done |
|
| 5085 | * in a case-sensitive manner. |
||
| 5086 | 3 | * </p> |
|
| 5087 | 3 | * @param array|\Generator|null $haystack <p> |
|
| 5088 | * The array. |
||
| 5089 | 3 | * </p> |
|
| 5090 | * @param bool $strict [optional] <p> |
||
| 5091 | * If the third parameter strict is set to true |
||
| 5092 | 3 | * then the in_array function will also check the |
|
| 5093 | * types of the |
||
| 5094 | * needle in the haystack. |
||
| 5095 | * </p> |
||
| 5096 | 922 | * |
|
| 5097 | * @return bool |
||
| 5098 | 922 | * <p>true if needle is found in the array, false otherwise</p> |
|
| 5099 | */ |
||
| 5100 | protected function in_array_recursive($needle, $haystack = null, $strict = true): bool |
||
| 5125 | |||
| 5126 | /** |
||
| 5127 | * @param mixed $data |
||
| 5128 | * |
||
| 5129 | * @return array|null |
||
| 5130 | */ |
||
| 5131 | protected function internalGetArray(&$data) |
||
| 5179 | 11 | ||
| 5180 | 11 | /** |
|
| 5181 | * Internal mechanics of remove method. |
||
| 5182 | 11 | * |
|
| 5183 | 4 | * @param mixed $key |
|
| 5184 | * |
||
| 5185 | 7 | * @return bool |
|
| 5186 | */ |
||
| 5187 | protected function internalRemove($key): bool |
||
| 5220 | 2 | ||
| 5221 | /** |
||
| 5222 | * Internal mechanic of set method. |
||
| 5223 | * |
||
| 5224 | * @param int|string|null $key |
||
| 5225 | * @param mixed $value |
||
| 5226 | * @param bool $checkProperties |
||
| 5227 | * |
||
| 5228 | 967 | * @return bool |
|
| 5229 | */ |
||
| 5230 | 967 | protected function internalSet( |
|
| 5276 | |||
| 5277 | /** |
||
| 5278 | * Convert a object into an array. |
||
| 5279 | * |
||
| 5280 | * @param object $object |
||
| 5281 | * |
||
| 5282 | * @return mixed |
||
| 5283 | */ |
||
| 5284 | protected static function objectToArray($object) |
||
| 5296 | |||
| 5297 | /** |
||
| 5298 | * @param array $data |
||
| 5299 | * @param bool $checkPropertiesInConstructor |
||
| 5300 | * |
||
| 5301 | * @return void |
||
| 5302 | */ |
||
| 5303 | protected function setInitialValuesAndProperties(array &$data, bool $checkPropertiesInConstructor) |
||
| 5345 | |||
| 5346 | /** |
||
| 5347 | * sorting keys |
||
| 5348 | * |
||
| 5349 | * @param array $elements |
||
| 5350 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 5351 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 5352 | * <strong>SORT_NATURAL</strong></p> |
||
| 5353 | * |
||
| 5354 | * @return static |
||
| 5355 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 5356 | */ |
||
| 5357 | protected function sorterKeys(array &$elements, $direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
||
| 5375 | |||
| 5376 | /** |
||
| 5377 | * @param array $elements <p>Warning: used as reference</p> |
||
| 5378 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 5379 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 5380 | * <strong>SORT_NATURAL</strong></p> |
||
| 5381 | * @param bool $keepKeys |
||
| 5382 | * |
||
| 5383 | * @return static |
||
| 5384 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 5385 | */ |
||
| 5386 | protected function sorting(array &$elements, $direction = \SORT_ASC, int $strategy = \SORT_REGULAR, bool $keepKeys = false): self |
||
| 5416 | |||
| 5417 | /** |
||
| 5418 | * @param int|string|null $key |
||
| 5419 | * @param mixed $value |
||
| 5420 | * |
||
| 5421 | * @return void |
||
| 5422 | */ |
||
| 5423 | private function checkType($key, $value) |
||
| 5439 | } |
||
| 5440 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.