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 |
||
| 27 | class Arrayy extends \ArrayObject implements \IteratorAggregate, \ArrayAccess, \Serializable, \JsonSerializable, \Countable |
||
| 28 | { |
||
| 29 | const ARRAYY_HELPER_TYPES_FOR_ALL_PROPERTIES = '!!!!Arrayy_Helper_Types_For_All_Properties!!!!'; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var array |
||
| 33 | * |
||
| 34 | * @psalm-var array<mixed,mixed>|array<TKey,T> |
||
| 35 | */ |
||
| 36 | protected $array = []; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @var \Arrayy\ArrayyRewindableGenerator|null |
||
| 40 | * |
||
| 41 | * @psalm-var \Arrayy\ArrayyRewindableGenerator<TKey,T>|null |
||
| 42 | */ |
||
| 43 | protected $generator; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @var string |
||
| 47 | * |
||
| 48 | * @psalm-var class-string<\Arrayy\ArrayyIterator> |
||
| 49 | */ |
||
| 50 | protected $iteratorClass = ArrayyIterator::class; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @var string |
||
| 54 | */ |
||
| 55 | protected $pathSeparator = '.'; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @var bool |
||
| 59 | */ |
||
| 60 | protected $checkPropertyTypes = false; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @var bool |
||
| 64 | */ |
||
| 65 | protected $checkForMissingPropertiesInConstructor = false; |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @var bool |
||
| 69 | */ |
||
| 70 | protected $checkPropertiesMismatchInConstructor = false; |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @var bool |
||
| 74 | */ |
||
| 75 | protected $checkPropertiesMismatch = true; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * @var array<int|string,TypeCheckInterface>|TypeCheckArray<int|string,TypeCheckInterface>|TypeInterface |
||
| 79 | */ |
||
| 80 | protected $properties = []; |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Initializes |
||
| 84 | * |
||
| 85 | * @param mixed $data <p> |
||
| 86 | * Should be an array or a generator, otherwise it will try |
||
| 87 | * to convert it into an array. |
||
| 88 | * </p> |
||
| 89 | * @param string $iteratorClass optional <p> |
||
| 90 | * You can overwrite the ArrayyIterator, but mostly you don't |
||
| 91 | * need this option. |
||
| 92 | * </p> |
||
| 93 | * @param bool $checkPropertiesInConstructor optional <p> |
||
| 94 | * You need to extend the "Arrayy"-class and you need to set |
||
| 95 | * the $checkPropertiesMismatchInConstructor class property |
||
| 96 | * to |
||
| 97 | * true, otherwise this option didn't not work anyway. |
||
| 98 | * </p> |
||
| 99 | * |
||
| 100 | * @psalm-param class-string<\Arrayy\ArrayyIterator> $iteratorClass |
||
| 101 | */ |
||
| 102 | 1173 | public function __construct( |
|
| 119 | |||
| 120 | /** |
||
| 121 | * @return void |
||
| 122 | */ |
||
| 123 | 50 | public function __clone() |
|
| 133 | |||
| 134 | /** |
||
| 135 | * Call object as function. |
||
| 136 | * |
||
| 137 | * @param mixed $key |
||
| 138 | * |
||
| 139 | * @return mixed |
||
| 140 | */ |
||
| 141 | 1 | public function __invoke($key = null) |
|
| 151 | |||
| 152 | /** |
||
| 153 | * Whether or not an element exists by key. |
||
| 154 | * |
||
| 155 | * @param mixed $key |
||
| 156 | * |
||
| 157 | * @return bool |
||
| 158 | * <p>True is the key/index exists, otherwise false.</p> |
||
| 159 | */ |
||
| 160 | public function __isset($key): bool |
||
| 164 | |||
| 165 | /** |
||
| 166 | * Assigns a value to the specified element. |
||
| 167 | * |
||
| 168 | * @param mixed $key |
||
| 169 | * @param mixed $value |
||
| 170 | * |
||
| 171 | * @return void |
||
| 172 | */ |
||
| 173 | 2 | public function __set($key, $value) |
|
| 177 | |||
| 178 | /** |
||
| 179 | * magic to string |
||
| 180 | * |
||
| 181 | * @return string |
||
| 182 | */ |
||
| 183 | 15 | public function __toString(): string |
|
| 187 | |||
| 188 | /** |
||
| 189 | * Unset element by key. |
||
| 190 | * |
||
| 191 | * @param mixed $key |
||
| 192 | */ |
||
| 193 | public function __unset($key) |
||
| 197 | |||
| 198 | /** |
||
| 199 | * Get a value by key. |
||
| 200 | * |
||
| 201 | * @param mixed $key |
||
| 202 | * |
||
| 203 | * @return mixed |
||
| 204 | * <p>Get a Value from the current array.</p> |
||
| 205 | */ |
||
| 206 | 4 | public function &__get($key) |
|
| 216 | |||
| 217 | /** |
||
| 218 | * Add new values (optional using dot-notation). |
||
| 219 | * |
||
| 220 | * @param mixed $value |
||
| 221 | * @param int|string|null $key |
||
| 222 | * |
||
| 223 | * @return static |
||
| 224 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
| 225 | * |
||
| 226 | * @psalm-param T $value |
||
| 227 | * @psalm-return static<TKey,T> |
||
| 228 | */ |
||
| 229 | 6 | public function add($value, $key = null) |
|
| 244 | |||
| 245 | /** |
||
| 246 | * Append a (key) + value to the current array. |
||
| 247 | * |
||
| 248 | * @param mixed $value |
||
| 249 | * @param mixed $key |
||
| 250 | * |
||
| 251 | * @return $this |
||
| 252 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
| 253 | * |
||
| 254 | * @psalm-return static<TKey,T> |
||
| 255 | */ |
||
| 256 | 17 | public function append($value, $key = null): self |
|
| 280 | |||
| 281 | /** |
||
| 282 | * Sort the entries by value. |
||
| 283 | * |
||
| 284 | * @param int $sort_flags [optional] <p> |
||
| 285 | * You may modify the behavior of the sort using the optional |
||
| 286 | * parameter sort_flags, for details |
||
| 287 | * see sort. |
||
| 288 | * </p> |
||
| 289 | * |
||
| 290 | * @return $this |
||
| 291 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 292 | * |
||
| 293 | * @psalm-return static<TKey,T> |
||
| 294 | */ |
||
| 295 | 4 | public function asort(int $sort_flags = 0): self |
|
| 303 | |||
| 304 | /** |
||
| 305 | * Sort the entries by value. |
||
| 306 | * |
||
| 307 | * @param int $sort_flags [optional] <p> |
||
| 308 | * You may modify the behavior of the sort using the optional |
||
| 309 | * parameter sort_flags, for details |
||
| 310 | * see sort. |
||
| 311 | * </p> |
||
| 312 | * |
||
| 313 | * @return $this |
||
| 314 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 315 | * |
||
| 316 | * @psalm-return static<TKey,T> |
||
| 317 | * @psalm-mutation-free |
||
| 318 | */ |
||
| 319 | 4 | public function asortImmutable(int $sort_flags = 0): self |
|
| 330 | |||
| 331 | /** |
||
| 332 | * Counts all elements in an array, or something in an object. |
||
| 333 | * |
||
| 334 | * <p> |
||
| 335 | * For objects, if you have SPL installed, you can hook into count() by implementing interface {@see Countable}. |
||
| 336 | * The interface has exactly one method, {@see Countable::count()}, which returns the return value for the count() |
||
| 337 | * function. Please see the {@see Array} section of the manual for a detailed explanation of how arrays are |
||
| 338 | * implemented and used in PHP. |
||
| 339 | * </p> |
||
| 340 | * |
||
| 341 | * @see http://php.net/manual/en/function.count.php |
||
| 342 | * |
||
| 343 | * @param int $mode [optional] If the optional mode parameter is set to |
||
| 344 | * COUNT_RECURSIVE (or 1), count |
||
| 345 | * will recursively count the array. This is particularly useful for |
||
| 346 | * counting all the elements of a multidimensional array. count does not detect infinite recursion. |
||
| 347 | * |
||
| 348 | * @return int |
||
| 349 | * <p> |
||
| 350 | * The number of elements in var, which is |
||
| 351 | * typically an array, since anything else will have one |
||
| 352 | * element. |
||
| 353 | * </p> |
||
| 354 | * <p> |
||
| 355 | * If var is not an array or an object with |
||
| 356 | * implemented Countable interface, |
||
| 357 | * 1 will be returned. |
||
| 358 | * There is one exception, if var is &null;, |
||
| 359 | * 0 will be returned. |
||
| 360 | * </p> |
||
| 361 | * <p> |
||
| 362 | * Caution: count may return 0 for a variable that isn't set, |
||
| 363 | * but it may also return 0 for a variable that has been initialized with an |
||
| 364 | * empty array. Use isset to test if a variable is set. |
||
| 365 | * </p> |
||
| 366 | * @psalm-mutation-free |
||
| 367 | */ |
||
| 368 | 147 | public function count(int $mode = \COUNT_NORMAL): int |
|
| 380 | |||
| 381 | /** |
||
| 382 | * Exchange the array for another one. |
||
| 383 | * |
||
| 384 | * @param array|static $data |
||
| 385 | * |
||
| 386 | * @return array |
||
| 387 | * |
||
| 388 | * @psalm-param array<TKey,T>|self<TKey,T> $data |
||
| 389 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 390 | */ |
||
| 391 | 1 | public function exchangeArray($data): array |
|
| 397 | |||
| 398 | /** |
||
| 399 | * Creates a copy of the ArrayyObject. |
||
| 400 | * |
||
| 401 | * @return array |
||
| 402 | * |
||
| 403 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 404 | */ |
||
| 405 | 6 | public function getArrayCopy(): array |
|
| 411 | |||
| 412 | /** |
||
| 413 | * Returns a new iterator, thus implementing the \Iterator interface. |
||
| 414 | * |
||
| 415 | * @return \Iterator<mixed, mixed> |
||
| 416 | * <p>An iterator for the values in the array.</p> |
||
| 417 | * @psalm-return \Iterator<array-key|TKey, mixed|T> |
||
| 418 | */ |
||
| 419 | 26 | public function getIterator(): \Iterator |
|
| 436 | |||
| 437 | /** |
||
| 438 | * Gets the iterator classname for the ArrayObject. |
||
| 439 | * |
||
| 440 | * @return string |
||
| 441 | * |
||
| 442 | * @psalm-return class-string |
||
| 443 | */ |
||
| 444 | 25 | public function getIteratorClass(): string |
|
| 448 | |||
| 449 | /** |
||
| 450 | * Sort the entries by key. |
||
| 451 | * |
||
| 452 | * @param int $sort_flags [optional] <p> |
||
| 453 | * You may modify the behavior of the sort using the optional |
||
| 454 | * parameter sort_flags, for details |
||
| 455 | * see sort. |
||
| 456 | * </p> |
||
| 457 | * |
||
| 458 | * @return $this |
||
| 459 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 460 | * |
||
| 461 | * @psalm-return static<TKey,T> |
||
| 462 | */ |
||
| 463 | 4 | public function ksort(int $sort_flags = 0): self |
|
| 471 | |||
| 472 | /** |
||
| 473 | * Sort the entries by key. |
||
| 474 | * |
||
| 475 | * @param int $sort_flags [optional] <p> |
||
| 476 | * You may modify the behavior of the sort using the optional |
||
| 477 | * parameter sort_flags, for details |
||
| 478 | * see sort. |
||
| 479 | * </p> |
||
| 480 | * |
||
| 481 | * @return $this |
||
| 482 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 483 | * |
||
| 484 | * @psalm-return static<TKey,T> |
||
| 485 | */ |
||
| 486 | 4 | public function ksortImmutable(int $sort_flags = 0): self |
|
| 497 | |||
| 498 | /** |
||
| 499 | * Sort an array using a case insensitive "natural order" algorithm. |
||
| 500 | * |
||
| 501 | * @return $this |
||
| 502 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 503 | * |
||
| 504 | * @psalm-return static<TKey,T> |
||
| 505 | */ |
||
| 506 | 8 | public function natcasesort(): self |
|
| 514 | |||
| 515 | /** |
||
| 516 | * Sort an array using a case insensitive "natural order" algorithm. |
||
| 517 | * |
||
| 518 | * @return $this |
||
| 519 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 520 | * |
||
| 521 | * @psalm-return static<TKey,T> |
||
| 522 | * @psalm-mutation-free |
||
| 523 | */ |
||
| 524 | 4 | public function natcasesortImmutable(): self |
|
| 535 | |||
| 536 | /** |
||
| 537 | * Sort entries using a "natural order" algorithm. |
||
| 538 | * |
||
| 539 | * @return $this |
||
| 540 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 541 | * |
||
| 542 | * @psalm-return static<TKey,T> |
||
| 543 | */ |
||
| 544 | 9 | public function natsort(): self |
|
| 552 | |||
| 553 | /** |
||
| 554 | * Sort entries using a "natural order" algorithm. |
||
| 555 | * |
||
| 556 | * @return $this |
||
| 557 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 558 | * |
||
| 559 | * @psalm-return static<TKey,T> |
||
| 560 | * @psalm-mutation-free |
||
| 561 | */ |
||
| 562 | 4 | public function natsortImmutable(): self |
|
| 573 | |||
| 574 | /** |
||
| 575 | * Whether or not an offset exists. |
||
| 576 | * |
||
| 577 | * @param bool|int|string $offset |
||
| 578 | * |
||
| 579 | * @return bool |
||
| 580 | * |
||
| 581 | * @noinspection PhpSillyAssignmentInspection |
||
| 582 | * |
||
| 583 | * @psalm-mutation-free |
||
| 584 | */ |
||
| 585 | 137 | public function offsetExists($offset): bool |
|
| 647 | |||
| 648 | /** |
||
| 649 | * Returns the value at specified offset. |
||
| 650 | * |
||
| 651 | * @param int|string $offset |
||
| 652 | * |
||
| 653 | * @return mixed |
||
| 654 | * <p>Will return null if the offset did not exists.</p> |
||
| 655 | */ |
||
| 656 | 106 | public function offsetGet($offset) |
|
| 660 | |||
| 661 | /** |
||
| 662 | * Assigns a value to the specified offset + check the type. |
||
| 663 | * |
||
| 664 | * @param int|string|null $offset |
||
| 665 | * @param mixed $value |
||
| 666 | * |
||
| 667 | * @return void |
||
| 668 | */ |
||
| 669 | 20 | public function offsetSet($offset, $value) |
|
| 687 | |||
| 688 | /** |
||
| 689 | * Unset an offset. |
||
| 690 | * |
||
| 691 | * @param int|string $offset |
||
| 692 | * |
||
| 693 | * @return void |
||
| 694 | * <p>(Mutable) Return nothing.</p> |
||
| 695 | */ |
||
| 696 | 25 | public function offsetUnset($offset) |
|
| 747 | |||
| 748 | /** |
||
| 749 | * Serialize the current "Arrayy"-object. |
||
| 750 | * |
||
| 751 | * @return string |
||
| 752 | */ |
||
| 753 | 2 | public function serialize(): string |
|
| 763 | |||
| 764 | /** |
||
| 765 | * Sets the iterator classname for the current "Arrayy"-object. |
||
| 766 | * |
||
| 767 | * @param string $iteratorClass |
||
| 768 | * |
||
| 769 | * @throws \InvalidArgumentException |
||
| 770 | * |
||
| 771 | * @return void |
||
| 772 | * |
||
| 773 | * @psalm-param class-string<\Arrayy\ArrayyIterator> $iteratorClass |
||
| 774 | */ |
||
| 775 | 1164 | public function setIteratorClass($iteratorClass) |
|
| 797 | |||
| 798 | /** |
||
| 799 | * Sort the entries with a user-defined comparison function and maintain key association. |
||
| 800 | * |
||
| 801 | * @param callable $function |
||
| 802 | * |
||
| 803 | * @throws \InvalidArgumentException |
||
| 804 | * |
||
| 805 | * @return $this |
||
| 806 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 807 | * |
||
| 808 | * @psalm-return static<TKey,T> |
||
| 809 | */ |
||
| 810 | 8 | View Code Duplication | public function uasort($function): self |
| 822 | |||
| 823 | /** |
||
| 824 | * Sort the entries with a user-defined comparison function and maintain key association. |
||
| 825 | * |
||
| 826 | * @param callable $function |
||
| 827 | * |
||
| 828 | * @throws \InvalidArgumentException |
||
| 829 | * |
||
| 830 | * @return $this |
||
| 831 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 832 | * |
||
| 833 | * @psalm-return static<TKey,T> |
||
| 834 | * @psalm-mutation-free |
||
| 835 | */ |
||
| 836 | 4 | public function uasortImmutable($function): self |
|
| 847 | |||
| 848 | /** |
||
| 849 | * Sort the entries by keys using a user-defined comparison function. |
||
| 850 | * |
||
| 851 | * @param callable $function |
||
| 852 | * |
||
| 853 | * @throws \InvalidArgumentException |
||
| 854 | * |
||
| 855 | * @return static |
||
| 856 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 857 | * |
||
| 858 | * @psalm-return static<TKey,T> |
||
| 859 | */ |
||
| 860 | 5 | public function uksort($function): self |
|
| 864 | |||
| 865 | /** |
||
| 866 | * Sort the entries by keys using a user-defined comparison function. |
||
| 867 | * |
||
| 868 | * @param callable $function |
||
| 869 | * |
||
| 870 | * @throws \InvalidArgumentException |
||
| 871 | * |
||
| 872 | * @return static |
||
| 873 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 874 | * |
||
| 875 | * @psalm-return static<TKey,T> |
||
| 876 | * @psalm-mutation-free |
||
| 877 | */ |
||
| 878 | 1 | public function uksortImmutable($function): self |
|
| 882 | |||
| 883 | /** |
||
| 884 | * Unserialize an string and return the instance of the "Arrayy"-class. |
||
| 885 | * |
||
| 886 | * @param string $string |
||
| 887 | * |
||
| 888 | * @return $this |
||
| 889 | * |
||
| 890 | * @psalm-return static<TKey,T> |
||
| 891 | */ |
||
| 892 | 2 | public function unserialize($string): self |
|
| 902 | |||
| 903 | /** |
||
| 904 | * Append a (key) + values to the current array. |
||
| 905 | * |
||
| 906 | * @param array $values |
||
| 907 | * @param mixed $key |
||
| 908 | * |
||
| 909 | * @return $this |
||
| 910 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
| 911 | * |
||
| 912 | * @psalm-param array<mixed,T> $values |
||
| 913 | * @psalm-param TKey|null $key |
||
| 914 | * @psalm-return static<TKey,T> |
||
| 915 | */ |
||
| 916 | 1 | public function appendArrayValues(array $values, $key = null) |
|
| 942 | |||
| 943 | /** |
||
| 944 | * Add a suffix to each key. |
||
| 945 | * |
||
| 946 | * @param mixed $prefix |
||
| 947 | * |
||
| 948 | * @return static |
||
| 949 | * <p>(Immutable) Return an Arrayy object, with the prefixed keys.</p> |
||
| 950 | * |
||
| 951 | * @psalm-return static<TKey,T> |
||
| 952 | * @psalm-mutation-free |
||
| 953 | */ |
||
| 954 | 10 | View Code Duplication | public function appendToEachKey($prefix): self |
| 973 | |||
| 974 | /** |
||
| 975 | * Add a prefix to each value. |
||
| 976 | * |
||
| 977 | * @param mixed $prefix |
||
| 978 | * |
||
| 979 | * @return static |
||
| 980 | * <p>(Immutable) Return an Arrayy object, with the prefixed values.</p> |
||
| 981 | * |
||
| 982 | * @psalm-return static<TKey,T> |
||
| 983 | * @psalm-mutation-free |
||
| 984 | */ |
||
| 985 | 10 | View Code Duplication | public function appendToEachValue($prefix): self |
| 1004 | |||
| 1005 | /** |
||
| 1006 | * Sort an array in reverse order and maintain index association. |
||
| 1007 | * |
||
| 1008 | * @return $this |
||
| 1009 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1010 | * |
||
| 1011 | * @psalm-return static<TKey,T> |
||
| 1012 | */ |
||
| 1013 | 4 | public function arsort(): self |
|
| 1021 | |||
| 1022 | /** |
||
| 1023 | * Sort an array in reverse order and maintain index association. |
||
| 1024 | * |
||
| 1025 | * @return $this |
||
| 1026 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 1027 | * |
||
| 1028 | * @psalm-return static<TKey,T> |
||
| 1029 | * @psalm-mutation-free |
||
| 1030 | */ |
||
| 1031 | 10 | public function arsortImmutable(): self |
|
| 1041 | |||
| 1042 | /** |
||
| 1043 | * Iterate over the current array and execute a callback for each loop. |
||
| 1044 | * |
||
| 1045 | * @param \Closure $closure |
||
| 1046 | * |
||
| 1047 | * @return static |
||
| 1048 | * <p>(Immutable)</p> |
||
| 1049 | * |
||
| 1050 | * @psalm-return static<TKey,T> |
||
| 1051 | * @psalm-mutation-free |
||
| 1052 | */ |
||
| 1053 | 2 | public function at(\Closure $closure): self |
|
| 1067 | |||
| 1068 | /** |
||
| 1069 | * Returns the average value of the current array. |
||
| 1070 | * |
||
| 1071 | * @param int $decimals <p>The number of decimal-numbers to return.</p> |
||
| 1072 | * |
||
| 1073 | * @return float|int |
||
| 1074 | * <p>The average value.</p> |
||
| 1075 | * @psalm-mutation-free |
||
| 1076 | */ |
||
| 1077 | 10 | public function average($decimals = 0) |
|
| 1091 | |||
| 1092 | /** |
||
| 1093 | * Changes all keys in an array. |
||
| 1094 | * |
||
| 1095 | * @param int $case [optional] <p> Either <strong>CASE_UPPER</strong><br /> |
||
| 1096 | * or <strong>CASE_LOWER</strong> (default)</p> |
||
| 1097 | * |
||
| 1098 | * @return static |
||
| 1099 | * <p>(Immutable)</p> |
||
| 1100 | * |
||
| 1101 | * @psalm-return static<TKey,T> |
||
| 1102 | * @psalm-mutation-free |
||
| 1103 | */ |
||
| 1104 | 1 | public function changeKeyCase(int $case = \CASE_LOWER): self |
|
| 1131 | |||
| 1132 | /** |
||
| 1133 | * Change the path separator of the array wrapper. |
||
| 1134 | * |
||
| 1135 | * By default, the separator is: "." |
||
| 1136 | * |
||
| 1137 | * @param string $separator <p>Separator to set.</p> |
||
| 1138 | * |
||
| 1139 | * @return $this |
||
| 1140 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1141 | * |
||
| 1142 | * @psalm-return static<TKey,T> |
||
| 1143 | */ |
||
| 1144 | 11 | public function changeSeparator($separator): self |
|
| 1150 | |||
| 1151 | /** |
||
| 1152 | * Create a chunked version of the current array. |
||
| 1153 | * |
||
| 1154 | * @param int $size <p>Size of each chunk.</p> |
||
| 1155 | * @param bool $preserveKeys <p>Whether array keys are preserved or no.</p> |
||
| 1156 | * |
||
| 1157 | * @return static |
||
| 1158 | * <p>(Immutable) A new array of chunks from the original array.</p> |
||
| 1159 | * |
||
| 1160 | * @psalm-return static<TKey,T> |
||
| 1161 | * @psalm-mutation-free |
||
| 1162 | */ |
||
| 1163 | 5 | public function chunk($size, $preserveKeys = false): self |
|
| 1171 | |||
| 1172 | /** |
||
| 1173 | * Clean all falsy values from the current array. |
||
| 1174 | * |
||
| 1175 | * @return static |
||
| 1176 | * <p>(Immutable)</p> |
||
| 1177 | * |
||
| 1178 | * @psalm-return static<TKey,T> |
||
| 1179 | * @psalm-mutation-free |
||
| 1180 | */ |
||
| 1181 | 8 | public function clean(): self |
|
| 1189 | |||
| 1190 | /** |
||
| 1191 | * WARNING!!! -> Clear the current full array or a $key of it. |
||
| 1192 | * |
||
| 1193 | * @param int|int[]|string|string[]|null $key |
||
| 1194 | * |
||
| 1195 | * @return $this |
||
| 1196 | * <p>(Mutable) Return this Arrayy object, with an empty array.</p> |
||
| 1197 | * |
||
| 1198 | * @psalm-return static<TKey,T> |
||
| 1199 | */ |
||
| 1200 | 10 | public function clear($key = null): self |
|
| 1219 | |||
| 1220 | /** |
||
| 1221 | * Check if an item is in the current array. |
||
| 1222 | * |
||
| 1223 | * @param float|int|string $value |
||
| 1224 | * @param bool $recursive |
||
| 1225 | * @param bool $strict |
||
| 1226 | * |
||
| 1227 | * @return bool |
||
| 1228 | * @psalm-mutation-free |
||
| 1229 | */ |
||
| 1230 | 23 | public function contains($value, bool $recursive = false, bool $strict = true): bool |
|
| 1251 | |||
| 1252 | /** |
||
| 1253 | * Check if an (case-insensitive) string is in the current array. |
||
| 1254 | * |
||
| 1255 | * @param mixed $value |
||
| 1256 | * @param bool $recursive |
||
| 1257 | * |
||
| 1258 | * @return bool |
||
| 1259 | * @psalm-mutation-free |
||
| 1260 | * |
||
| 1261 | * @psalm-suppress InvalidCast - hack for int|float|bool support |
||
| 1262 | */ |
||
| 1263 | 26 | public function containsCaseInsensitive($value, $recursive = false): bool |
|
| 1292 | |||
| 1293 | /** |
||
| 1294 | * Check if the given key/index exists in the array. |
||
| 1295 | * |
||
| 1296 | * @param int|string $key <p>key/index to search for</p> |
||
| 1297 | * |
||
| 1298 | * @return bool |
||
| 1299 | * <p>Returns true if the given key/index exists in the array, false otherwise.</p> |
||
| 1300 | * |
||
| 1301 | * @psalm-mutation-free |
||
| 1302 | */ |
||
| 1303 | 4 | public function containsKey($key): bool |
|
| 1307 | |||
| 1308 | /** |
||
| 1309 | * Check if all given needles are present in the array as key/index. |
||
| 1310 | * |
||
| 1311 | * @param array $needles <p>The keys you are searching for.</p> |
||
| 1312 | * @param bool $recursive |
||
| 1313 | * |
||
| 1314 | * @return bool |
||
| 1315 | * <p>Returns true if all the given keys/indexes exists in the array, false otherwise.</p> |
||
| 1316 | * |
||
| 1317 | * @psalm-param array<mixed,mixed>|array<TKey> $needles |
||
| 1318 | * @psalm-mutation-free |
||
| 1319 | */ |
||
| 1320 | 2 | public function containsKeys(array $needles, $recursive = false): bool |
|
| 1348 | |||
| 1349 | /** |
||
| 1350 | * Check if all given needles are present in the array as key/index. |
||
| 1351 | * |
||
| 1352 | * @param array $needles <p>The keys you are searching for.</p> |
||
| 1353 | * |
||
| 1354 | * @return bool |
||
| 1355 | * <p>Returns true if all the given keys/indexes exists in the array, false otherwise.</p> |
||
| 1356 | * |
||
| 1357 | * @psalm-param array<mixed,mixed>|array<TKey> $needles |
||
| 1358 | * @psalm-mutation-free |
||
| 1359 | */ |
||
| 1360 | 1 | public function containsKeysRecursive(array $needles): bool |
|
| 1364 | |||
| 1365 | /** |
||
| 1366 | * alias: for "Arrayy->contains()" |
||
| 1367 | * |
||
| 1368 | * @param float|int|string $value |
||
| 1369 | * |
||
| 1370 | * @return bool |
||
| 1371 | * |
||
| 1372 | * @see Arrayy::contains() |
||
| 1373 | * @psalm-mutation-free |
||
| 1374 | */ |
||
| 1375 | 9 | public function containsValue($value): bool |
|
| 1379 | |||
| 1380 | /** |
||
| 1381 | * alias: for "Arrayy->contains($value, true)" |
||
| 1382 | * |
||
| 1383 | * @param float|int|string $value |
||
| 1384 | * |
||
| 1385 | * @return bool |
||
| 1386 | * |
||
| 1387 | * @see Arrayy::contains() |
||
| 1388 | * @psalm-mutation-free |
||
| 1389 | */ |
||
| 1390 | 18 | public function containsValueRecursive($value): bool |
|
| 1394 | |||
| 1395 | /** |
||
| 1396 | * Check if all given needles are present in the array. |
||
| 1397 | * |
||
| 1398 | * @param array $needles |
||
| 1399 | * |
||
| 1400 | * @return bool |
||
| 1401 | * <p>Returns true if all the given values exists in the array, false otherwise.</p> |
||
| 1402 | * |
||
| 1403 | * @psalm-param array<mixed>|array<T> $needles |
||
| 1404 | * @psalm-mutation-free |
||
| 1405 | */ |
||
| 1406 | 1 | public function containsValues(array $needles): bool |
|
| 1412 | |||
| 1413 | /** |
||
| 1414 | * Counts all the values of an array |
||
| 1415 | * |
||
| 1416 | * @see http://php.net/manual/en/function.array-count-values.php |
||
| 1417 | * |
||
| 1418 | * @return static |
||
| 1419 | * <p> |
||
| 1420 | * (Immutable) |
||
| 1421 | * An associative Arrayy-object of values from input as |
||
| 1422 | * keys and their count as value. |
||
| 1423 | * </p> |
||
| 1424 | * |
||
| 1425 | * @psalm-return static<TKey,T> |
||
| 1426 | * @psalm-mutation-free |
||
| 1427 | */ |
||
| 1428 | 7 | public function countValues(): self |
|
| 1432 | |||
| 1433 | /** |
||
| 1434 | * Creates an Arrayy object. |
||
| 1435 | * |
||
| 1436 | * @param mixed $data |
||
| 1437 | * @param string $iteratorClass |
||
| 1438 | * @param bool $checkPropertiesInConstructor |
||
| 1439 | * |
||
| 1440 | * @return static |
||
| 1441 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1442 | * |
||
| 1443 | * @psalm-param class-string<\Arrayy\ArrayyIterator> $iteratorClass |
||
| 1444 | * |
||
| 1445 | * @psalm-mutation-free |
||
| 1446 | */ |
||
| 1447 | 693 | public static function create( |
|
| 1458 | |||
| 1459 | /** |
||
| 1460 | * Flatten an array with the given character as a key delimiter |
||
| 1461 | * |
||
| 1462 | * @param string $delimiter |
||
| 1463 | * @param string $prepend |
||
| 1464 | * @param array|null $items |
||
| 1465 | * |
||
| 1466 | * @return array |
||
| 1467 | */ |
||
| 1468 | 2 | public function flatten($delimiter = '.', $prepend = '', $items = null) |
|
| 1491 | |||
| 1492 | /** |
||
| 1493 | * WARNING: Creates an Arrayy object by reference. |
||
| 1494 | * |
||
| 1495 | * @param array $array |
||
| 1496 | * |
||
| 1497 | * @return $this |
||
| 1498 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1499 | * |
||
| 1500 | * @psalm-param array<mixed,mixed>|array<array-key,mixed> $array |
||
| 1501 | */ |
||
| 1502 | 2 | public function createByReference(array &$array = []): self |
|
| 1510 | |||
| 1511 | /** |
||
| 1512 | * Create an new instance from a callable function which will return an Generator. |
||
| 1513 | * |
||
| 1514 | * @param callable $generatorFunction |
||
| 1515 | * |
||
| 1516 | * @return static |
||
| 1517 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1518 | * |
||
| 1519 | * @psalm-param callable():\Generator<array-key,mixed> $generatorFunction |
||
| 1520 | * |
||
| 1521 | * @psalm-mutation-free |
||
| 1522 | */ |
||
| 1523 | 7 | public static function createFromGeneratorFunction(callable $generatorFunction): self |
|
| 1527 | |||
| 1528 | /** |
||
| 1529 | * Create an new instance filled with a copy of values from a "Generator"-object. |
||
| 1530 | * |
||
| 1531 | * @param \Generator $generator |
||
| 1532 | * |
||
| 1533 | * @return static |
||
| 1534 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1535 | * |
||
| 1536 | * @psalm-param \Generator<array-key,mixed> $generator |
||
| 1537 | * |
||
| 1538 | * @psalm-mutation-free |
||
| 1539 | */ |
||
| 1540 | 4 | public static function createFromGeneratorImmutable(\Generator $generator): self |
|
| 1544 | |||
| 1545 | /** |
||
| 1546 | * Create an new Arrayy object via JSON. |
||
| 1547 | * |
||
| 1548 | * @param string $json |
||
| 1549 | * |
||
| 1550 | * @return static |
||
| 1551 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1552 | * |
||
| 1553 | * @psalm-mutation-free |
||
| 1554 | */ |
||
| 1555 | 5 | public static function createFromJson(string $json): self |
|
| 1559 | |||
| 1560 | /** |
||
| 1561 | * Create an new Arrayy object via JSON. |
||
| 1562 | * |
||
| 1563 | * @param array $array |
||
| 1564 | * |
||
| 1565 | * @return static |
||
| 1566 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1567 | * |
||
| 1568 | * @psalm-mutation-free |
||
| 1569 | */ |
||
| 1570 | 1 | public static function createFromArray(array $array): self |
|
| 1574 | |||
| 1575 | /** |
||
| 1576 | * Create an new instance filled with values from an object that is iterable. |
||
| 1577 | * |
||
| 1578 | * @param \Traversable $object <p>iterable object</p> |
||
| 1579 | * |
||
| 1580 | * @return static |
||
| 1581 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1582 | * |
||
| 1583 | * @psalm-param \Traversable<array-key,mixed> $object |
||
| 1584 | * |
||
| 1585 | * @psalm-mutation-free |
||
| 1586 | */ |
||
| 1587 | 4 | public static function createFromObject(\Traversable $object): self |
|
| 1607 | |||
| 1608 | /** |
||
| 1609 | * Create an new instance filled with values from an object. |
||
| 1610 | * |
||
| 1611 | * @param object $object |
||
| 1612 | * |
||
| 1613 | * @return static |
||
| 1614 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1615 | * |
||
| 1616 | * @psalm-mutation-free |
||
| 1617 | */ |
||
| 1618 | 5 | public static function createFromObjectVars($object): self |
|
| 1622 | |||
| 1623 | /** |
||
| 1624 | * Create an new Arrayy object via string. |
||
| 1625 | * |
||
| 1626 | * @param string $str <p>The input string.</p> |
||
| 1627 | * @param string|null $delimiter <p>The boundary string.</p> |
||
| 1628 | * @param string|null $regEx <p>Use the $delimiter or the $regEx, so if $pattern is null, $delimiter will be |
||
| 1629 | * used.</p> |
||
| 1630 | * |
||
| 1631 | * @return static |
||
| 1632 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1633 | * |
||
| 1634 | * @psalm-mutation-free |
||
| 1635 | */ |
||
| 1636 | 10 | public static function createFromString(string $str, string $delimiter = null, string $regEx = null): self |
|
| 1668 | |||
| 1669 | /** |
||
| 1670 | * Create an new instance filled with a copy of values from a "Traversable"-object. |
||
| 1671 | * |
||
| 1672 | * @param \Traversable $traversable |
||
| 1673 | * |
||
| 1674 | * @return static |
||
| 1675 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1676 | * |
||
| 1677 | * @psalm-param \Traversable<array-key,mixed> $traversable |
||
| 1678 | * |
||
| 1679 | * @psalm-mutation-free |
||
| 1680 | */ |
||
| 1681 | 1 | public static function createFromTraversableImmutable(\Traversable $traversable): self |
|
| 1685 | |||
| 1686 | /** |
||
| 1687 | * Create an new instance containing a range of elements. |
||
| 1688 | * |
||
| 1689 | * @param float|int|string $low <p>First value of the sequence.</p> |
||
| 1690 | * @param float|int|string $high <p>The sequence is ended upon reaching the end value.</p> |
||
| 1691 | * @param float|int $step <p>Used as the increment between elements in the sequence.</p> |
||
| 1692 | * |
||
| 1693 | * @return static |
||
| 1694 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1695 | * |
||
| 1696 | * @psalm-mutation-free |
||
| 1697 | */ |
||
| 1698 | 2 | public static function createWithRange($low, $high, $step = 1): self |
|
| 1702 | |||
| 1703 | /** |
||
| 1704 | * Gets the element of the array at the current internal iterator position. |
||
| 1705 | * |
||
| 1706 | * @return false|mixed |
||
| 1707 | */ |
||
| 1708 | public function current() |
||
| 1712 | |||
| 1713 | /** |
||
| 1714 | * Custom sort by index via "uksort". |
||
| 1715 | * |
||
| 1716 | * @see http://php.net/manual/en/function.uksort.php |
||
| 1717 | * |
||
| 1718 | * @param callable $function |
||
| 1719 | * |
||
| 1720 | * @throws \InvalidArgumentException |
||
| 1721 | * |
||
| 1722 | * @return $this |
||
| 1723 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1724 | * |
||
| 1725 | * @psalm-return static<TKey,T> |
||
| 1726 | */ |
||
| 1727 | 5 | public function customSortKeys(callable $function): self |
|
| 1735 | |||
| 1736 | /** |
||
| 1737 | * Custom sort by index via "uksort". |
||
| 1738 | * |
||
| 1739 | * @see http://php.net/manual/en/function.uksort.php |
||
| 1740 | * |
||
| 1741 | * @param callable $function |
||
| 1742 | * |
||
| 1743 | * @throws \InvalidArgumentException |
||
| 1744 | * |
||
| 1745 | * @return $this |
||
| 1746 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 1747 | * |
||
| 1748 | * @psalm-return static<TKey,T> |
||
| 1749 | * @psalm-mutation-free |
||
| 1750 | */ |
||
| 1751 | 1 | public function customSortKeysImmutable(callable $function): self |
|
| 1764 | |||
| 1765 | /** |
||
| 1766 | * Custom sort by value via "usort". |
||
| 1767 | * |
||
| 1768 | * @see http://php.net/manual/en/function.usort.php |
||
| 1769 | * |
||
| 1770 | * @param callable $function |
||
| 1771 | * |
||
| 1772 | * @throws \InvalidArgumentException |
||
| 1773 | * |
||
| 1774 | * @return $this |
||
| 1775 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1776 | * |
||
| 1777 | * @psalm-return static<TKey,T> |
||
| 1778 | */ |
||
| 1779 | 10 | View Code Duplication | public function customSortValues($function): self |
| 1791 | |||
| 1792 | /** |
||
| 1793 | * Custom sort by value via "usort". |
||
| 1794 | * |
||
| 1795 | * @see http://php.net/manual/en/function.usort.php |
||
| 1796 | * |
||
| 1797 | * @param callable $function |
||
| 1798 | * |
||
| 1799 | * @throws \InvalidArgumentException |
||
| 1800 | * |
||
| 1801 | * @return $this |
||
| 1802 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 1803 | * |
||
| 1804 | * @psalm-return static<TKey,T> |
||
| 1805 | * @psalm-mutation-free |
||
| 1806 | */ |
||
| 1807 | 4 | public function customSortValuesImmutable($function): self |
|
| 1818 | |||
| 1819 | /** |
||
| 1820 | * Delete the given key or keys. |
||
| 1821 | * |
||
| 1822 | * @param int|int[]|string|string[] $keyOrKeys |
||
| 1823 | * |
||
| 1824 | * @return void |
||
| 1825 | */ |
||
| 1826 | 9 | public function delete($keyOrKeys) |
|
| 1834 | |||
| 1835 | /** |
||
| 1836 | * Return values that are only in the current array. |
||
| 1837 | * |
||
| 1838 | * @param array ...$array |
||
| 1839 | * |
||
| 1840 | * @return static |
||
| 1841 | * <p>(Immutable)</p> |
||
| 1842 | * |
||
| 1843 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$array |
||
| 1844 | * @psalm-return static<TKey,T> |
||
| 1845 | * @psalm-mutation-free |
||
| 1846 | */ |
||
| 1847 | 13 | public function diff(...$array): self |
|
| 1855 | |||
| 1856 | /** |
||
| 1857 | * Return values that are only in the current array. |
||
| 1858 | * |
||
| 1859 | * @param array ...$array |
||
| 1860 | * |
||
| 1861 | * @return static |
||
| 1862 | * <p>(Immutable)</p> |
||
| 1863 | * |
||
| 1864 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$array |
||
| 1865 | * @psalm-return static<TKey,T> |
||
| 1866 | * @psalm-mutation-free |
||
| 1867 | */ |
||
| 1868 | 8 | public function diffKey(...$array): self |
|
| 1876 | |||
| 1877 | /** |
||
| 1878 | * Return values and Keys that are only in the current array. |
||
| 1879 | * |
||
| 1880 | * @param array $array |
||
| 1881 | * |
||
| 1882 | * @return static |
||
| 1883 | * <p>(Immutable)</p> |
||
| 1884 | * |
||
| 1885 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 1886 | * @psalm-return static<TKey,T> |
||
| 1887 | * @psalm-mutation-free |
||
| 1888 | */ |
||
| 1889 | 8 | public function diffKeyAndValue(array $array = []): self |
|
| 1897 | |||
| 1898 | /** |
||
| 1899 | * Return values that are only in the current multi-dimensional array. |
||
| 1900 | * |
||
| 1901 | * @param array $array |
||
| 1902 | * @param array|\Generator|null $helperVariableForRecursion <p>(only for internal usage)</p> |
||
| 1903 | * |
||
| 1904 | * @return static |
||
| 1905 | * <p>(Immutable)</p> |
||
| 1906 | * |
||
| 1907 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 1908 | * @psalm-param null|array<TKey,T>|\Generator<TKey,T> $helperVariableForRecursion |
||
| 1909 | * @psalm-return static<TKey,T> |
||
| 1910 | * @psalm-mutation-free |
||
| 1911 | */ |
||
| 1912 | 1 | public function diffRecursive(array $array = [], $helperVariableForRecursion = null): self |
|
| 1947 | |||
| 1948 | /** |
||
| 1949 | * Return values that are only in the new $array. |
||
| 1950 | * |
||
| 1951 | * @param array $array |
||
| 1952 | * |
||
| 1953 | * @return static |
||
| 1954 | * <p>(Immutable)</p> |
||
| 1955 | * |
||
| 1956 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 1957 | * @psalm-return static<TKey,T> |
||
| 1958 | * @psalm-mutation-free |
||
| 1959 | */ |
||
| 1960 | 8 | public function diffReverse(array $array = []): self |
|
| 1968 | |||
| 1969 | /** |
||
| 1970 | * Divide an array into two arrays. One with keys and the other with values. |
||
| 1971 | * |
||
| 1972 | * @return static |
||
| 1973 | * <p>(Immutable)</p> |
||
| 1974 | * |
||
| 1975 | * @psalm-return static<TKey,T> |
||
| 1976 | * @psalm-mutation-free |
||
| 1977 | */ |
||
| 1978 | 1 | public function divide(): self |
|
| 1989 | |||
| 1990 | /** |
||
| 1991 | * Iterate over the current array and modify the array's value. |
||
| 1992 | * |
||
| 1993 | * @param \Closure $closure |
||
| 1994 | * |
||
| 1995 | * @return static |
||
| 1996 | * <p>(Immutable)</p> |
||
| 1997 | * |
||
| 1998 | * @psalm-return static<TKey,T> |
||
| 1999 | * @psalm-mutation-free |
||
| 2000 | */ |
||
| 2001 | 5 | View Code Duplication | public function each(\Closure $closure): self |
| 2016 | |||
| 2017 | /** |
||
| 2018 | * Sets the internal iterator to the last element in the array and returns this element. |
||
| 2019 | * |
||
| 2020 | * @return mixed |
||
| 2021 | */ |
||
| 2022 | public function end() |
||
| 2026 | |||
| 2027 | /** |
||
| 2028 | * Check if a value is in the current array using a closure. |
||
| 2029 | * |
||
| 2030 | * @param \Closure $closure |
||
| 2031 | * |
||
| 2032 | * @return bool |
||
| 2033 | * <p>Returns true if the given value is found, false otherwise.</p> |
||
| 2034 | */ |
||
| 2035 | 4 | public function exists(\Closure $closure): bool |
|
| 2050 | |||
| 2051 | /** |
||
| 2052 | * Fill the array until "$num" with "$default" values. |
||
| 2053 | * |
||
| 2054 | * @param int $num |
||
| 2055 | * @param mixed $default |
||
| 2056 | * |
||
| 2057 | * @return static |
||
| 2058 | * <p>(Immutable)</p> |
||
| 2059 | * |
||
| 2060 | * @psalm-return static<TKey,T> |
||
| 2061 | * @psalm-mutation-free |
||
| 2062 | */ |
||
| 2063 | 8 | public function fillWithDefaults(int $num, $default = null): self |
|
| 2086 | |||
| 2087 | /** |
||
| 2088 | * Find all items in an array that pass the truth test. |
||
| 2089 | * |
||
| 2090 | * @param \Closure|null $closure [optional] <p> |
||
| 2091 | * The callback function to use |
||
| 2092 | * </p> |
||
| 2093 | * <p> |
||
| 2094 | * If no callback is supplied, all entries of |
||
| 2095 | * input equal to false (see |
||
| 2096 | * converting to |
||
| 2097 | * boolean) will be removed. |
||
| 2098 | * </p> |
||
| 2099 | * @param int $flag [optional] <p> |
||
| 2100 | * Flag determining what arguments are sent to <i>callback</i>: |
||
| 2101 | * </p><ul> |
||
| 2102 | * <li> |
||
| 2103 | * <b>ARRAY_FILTER_USE_KEY</b> [1] - pass key as the only argument |
||
| 2104 | * to <i>callback</i> instead of the value</span> |
||
| 2105 | * </li> |
||
| 2106 | * <li> |
||
| 2107 | * <b>ARRAY_FILTER_USE_BOTH</b> [2] - pass both value and key as |
||
| 2108 | * arguments to <i>callback</i> instead of the value</span> |
||
| 2109 | * </li> |
||
| 2110 | * </ul> |
||
| 2111 | * |
||
| 2112 | * @return static |
||
| 2113 | * <p>(Immutable)</p> |
||
| 2114 | * |
||
| 2115 | * @psalm-param \Closure(T=,TKey=):bool|\Closure(T=):bool $closure |
||
| 2116 | * @psalm-return static<TKey,T> |
||
| 2117 | * @psalm-mutation-free |
||
| 2118 | */ |
||
| 2119 | 12 | public function filter($closure = null, int $flag = \ARRAY_FILTER_USE_BOTH) |
|
| 2131 | |||
| 2132 | /** |
||
| 2133 | * Filters an array of objects (or a numeric array of associative arrays) based on the value of a particular |
||
| 2134 | * property within that. |
||
| 2135 | * |
||
| 2136 | * @param string $property |
||
| 2137 | * @param string|string[] $value |
||
| 2138 | * @param string $comparisonOp |
||
| 2139 | * <p> |
||
| 2140 | * 'eq' (equals),<br /> |
||
| 2141 | * 'gt' (greater),<br /> |
||
| 2142 | * 'gte' || 'ge' (greater or equals),<br /> |
||
| 2143 | * 'lt' (less),<br /> |
||
| 2144 | * 'lte' || 'le' (less or equals),<br /> |
||
| 2145 | * 'ne' (not equals),<br /> |
||
| 2146 | * 'contains',<br /> |
||
| 2147 | * 'notContains',<br /> |
||
| 2148 | * 'newer' (via strtotime),<br /> |
||
| 2149 | * 'older' (via strtotime),<br /> |
||
| 2150 | * </p> |
||
| 2151 | * |
||
| 2152 | * @return static |
||
| 2153 | * <p>(Immutable)</p> |
||
| 2154 | * |
||
| 2155 | * @psalm-return static<TKey,T> |
||
| 2156 | * @psalm-mutation-free |
||
| 2157 | * |
||
| 2158 | * @psalm-suppress MissingClosureReturnType |
||
| 2159 | * @psalm-suppress MissingClosureParamType |
||
| 2160 | */ |
||
| 2161 | 1 | public function filterBy( |
|
| 2233 | |||
| 2234 | /** |
||
| 2235 | * Find the first item in an array that passes the truth test, |
||
| 2236 | * otherwise return false |
||
| 2237 | * |
||
| 2238 | * @param \Closure $closure |
||
| 2239 | * |
||
| 2240 | * @return false|mixed |
||
| 2241 | * <p>Return false if we did not find the value.</p> |
||
| 2242 | */ |
||
| 2243 | 8 | View Code Duplication | public function find(\Closure $closure) |
| 2253 | |||
| 2254 | /** |
||
| 2255 | * find by ... |
||
| 2256 | * |
||
| 2257 | * @param string $property |
||
| 2258 | * @param string|string[] $value |
||
| 2259 | * @param string $comparisonOp |
||
| 2260 | * |
||
| 2261 | * @return static |
||
| 2262 | * <p>(Immutable)</p> |
||
| 2263 | * |
||
| 2264 | * @psalm-return static<TKey,T> |
||
| 2265 | * @psalm-mutation-free |
||
| 2266 | */ |
||
| 2267 | 1 | public function findBy(string $property, $value, string $comparisonOp = 'eq'): self |
|
| 2271 | |||
| 2272 | /** |
||
| 2273 | * Get the first value from the current array. |
||
| 2274 | * |
||
| 2275 | * @return mixed |
||
| 2276 | * <p>Return null if there wasn't a element.</p> |
||
| 2277 | */ |
||
| 2278 | 21 | public function first() |
|
| 2287 | |||
| 2288 | /** |
||
| 2289 | * Get the first key from the current array. |
||
| 2290 | * |
||
| 2291 | * @return mixed |
||
| 2292 | * <p>Return null if there wasn't a element.</p> |
||
| 2293 | * @psalm-mutation-free |
||
| 2294 | */ |
||
| 2295 | 28 | public function firstKey() |
|
| 2301 | |||
| 2302 | /** |
||
| 2303 | * Get the first value(s) from the current array. |
||
| 2304 | * And will return an empty array if there was no first entry. |
||
| 2305 | * |
||
| 2306 | * @param int|null $number <p>How many values you will take?</p> |
||
| 2307 | * |
||
| 2308 | * @return static |
||
| 2309 | * <p>(Immutable)</p> |
||
| 2310 | * |
||
| 2311 | * @psalm-return static<TKey,T> |
||
| 2312 | * @psalm-mutation-free |
||
| 2313 | */ |
||
| 2314 | 37 | View Code Duplication | public function firstsImmutable(int $number = null): self |
| 2331 | |||
| 2332 | /** |
||
| 2333 | * Get the first value(s) from the current array. |
||
| 2334 | * And will return an empty array if there was no first entry. |
||
| 2335 | * |
||
| 2336 | * @param int|null $number <p>How many values you will take?</p> |
||
| 2337 | * |
||
| 2338 | * @return static |
||
| 2339 | * <p>(Immutable)</p> |
||
| 2340 | * |
||
| 2341 | * @psalm-return static<TKey,T> |
||
| 2342 | * @psalm-mutation-free |
||
| 2343 | */ |
||
| 2344 | 3 | View Code Duplication | public function firstsKeys(int $number = null): self |
| 2361 | |||
| 2362 | /** |
||
| 2363 | * Get and rmove the first value(s) from the current array. |
||
| 2364 | * And will return an empty array if there was no first entry. |
||
| 2365 | * |
||
| 2366 | * @param int|null $number <p>How many values you will take?</p> |
||
| 2367 | * |
||
| 2368 | * @return $this |
||
| 2369 | * <p>(Mutable)</p> |
||
| 2370 | * |
||
| 2371 | * @psalm-return static<TKey,T> |
||
| 2372 | */ |
||
| 2373 | 34 | public function firstsMutable(int $number = null): self |
|
| 2386 | |||
| 2387 | /** |
||
| 2388 | * Exchanges all keys with their associated values in an array. |
||
| 2389 | * |
||
| 2390 | * @return static |
||
| 2391 | * <p>(Immutable)</p> |
||
| 2392 | * |
||
| 2393 | * @psalm-return static<TKey,T> |
||
| 2394 | * @psalm-mutation-free |
||
| 2395 | */ |
||
| 2396 | 1 | public function flip(): self |
|
| 2404 | |||
| 2405 | /** |
||
| 2406 | * Get a value from an array (optional using dot-notation). |
||
| 2407 | * |
||
| 2408 | * @param mixed $key <p>The key to look for.</p> |
||
| 2409 | * @param mixed $fallback <p>Value to fallback to.</p> |
||
| 2410 | * @param array $array <p>The array to get from, if it's set to "null" we use the current array from the |
||
| 2411 | * class.</p> |
||
| 2412 | * |
||
| 2413 | * @return mixed|static |
||
| 2414 | * |
||
| 2415 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 2416 | * @psalm-mutation-free |
||
| 2417 | */ |
||
| 2418 | 219 | public function get($key, $fallback = null, array $array = null) |
|
| 2510 | |||
| 2511 | /** |
||
| 2512 | * alias: for "Arrayy->toArray()" |
||
| 2513 | * |
||
| 2514 | * @return array |
||
| 2515 | * |
||
| 2516 | * @see Arrayy::getArray() |
||
| 2517 | * |
||
| 2518 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 2519 | */ |
||
| 2520 | 12 | public function getAll(): array |
|
| 2524 | |||
| 2525 | /** |
||
| 2526 | * Get the current array from the "Arrayy"-object. |
||
| 2527 | * |
||
| 2528 | * alias for "toArray()" |
||
| 2529 | * |
||
| 2530 | * @param bool $convertAllArrayyElements <p> |
||
| 2531 | * Convert all Child-"Arrayy" objects also to arrays. |
||
| 2532 | * </p> |
||
| 2533 | * @param bool $preserveKeys <p> |
||
| 2534 | * e.g.: A generator maybe return the same key more then once, |
||
| 2535 | * so maybe you will ignore the keys. |
||
| 2536 | * </p> |
||
| 2537 | * |
||
| 2538 | * @return array |
||
| 2539 | * |
||
| 2540 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 2541 | * @psalm-mutation-free |
||
| 2542 | * |
||
| 2543 | * @see Arrayy::toArray() |
||
| 2544 | */ |
||
| 2545 | 494 | public function getArray( |
|
| 2554 | |||
| 2555 | /** |
||
| 2556 | * Get the current array from the "Arrayy"-object as list. |
||
| 2557 | * |
||
| 2558 | * alias for "toList()" |
||
| 2559 | * |
||
| 2560 | * @param bool $convertAllArrayyElements <p> |
||
| 2561 | * Convert all Child-"Arrayy" objects also to arrays. |
||
| 2562 | * </p> |
||
| 2563 | * |
||
| 2564 | * @return array |
||
| 2565 | * |
||
| 2566 | * @psalm-return array<int,mixed>|array<int,T> |
||
| 2567 | * @psalm-mutation-free |
||
| 2568 | * |
||
| 2569 | * @see Arrayy::toList() |
||
| 2570 | */ |
||
| 2571 | 1 | public function getList(bool $convertAllArrayyElements = false): array |
|
| 2575 | |||
| 2576 | /** |
||
| 2577 | * Returns the values from a single column of the input array, identified by |
||
| 2578 | * the $columnKey, can be used to extract data-columns from multi-arrays. |
||
| 2579 | * |
||
| 2580 | * Info: Optionally, you may provide an $indexKey to index the values in the returned |
||
| 2581 | * array by the values from the $indexKey column in the input array. |
||
| 2582 | * |
||
| 2583 | * @param mixed $columnKey |
||
| 2584 | * @param mixed $indexKey |
||
| 2585 | * |
||
| 2586 | * @return static |
||
| 2587 | * <p>(Immutable)</p> |
||
| 2588 | * |
||
| 2589 | * @psalm-return static<TKey,T> |
||
| 2590 | * @psalm-mutation-free |
||
| 2591 | */ |
||
| 2592 | 1 | public function getColumn($columnKey = null, $indexKey = null): self |
|
| 2600 | |||
| 2601 | /** |
||
| 2602 | * Get the current array from the "Arrayy"-object as generator. |
||
| 2603 | * |
||
| 2604 | * @return \Generator |
||
| 2605 | * |
||
| 2606 | * @psalm-return \Generator<mixed,T>|\Generator<TKey,T> |
||
| 2607 | * @psalm-mutation-free |
||
| 2608 | */ |
||
| 2609 | 1012 | public function getGenerator(): \Generator |
|
| 2617 | |||
| 2618 | /** |
||
| 2619 | * alias: for "Arrayy->keys()" |
||
| 2620 | * |
||
| 2621 | * @return static |
||
| 2622 | * <p>(Immutable)</p> |
||
| 2623 | * |
||
| 2624 | * @see Arrayy::keys() |
||
| 2625 | * |
||
| 2626 | * @psalm-return static<array-key,TKey> |
||
| 2627 | * @psalm-mutation-free |
||
| 2628 | */ |
||
| 2629 | 2 | public function getKeys() |
|
| 2633 | |||
| 2634 | /** |
||
| 2635 | * Get the current array from the "Arrayy"-object as object. |
||
| 2636 | * |
||
| 2637 | * @return \stdClass |
||
| 2638 | */ |
||
| 2639 | 4 | public function getObject(): \stdClass |
|
| 2643 | |||
| 2644 | /** |
||
| 2645 | * alias: for "Arrayy->randomImmutable()" |
||
| 2646 | * |
||
| 2647 | * @return static |
||
| 2648 | * <p>(Immutable)</p> |
||
| 2649 | * |
||
| 2650 | * @see Arrayy::randomImmutable() |
||
| 2651 | * |
||
| 2652 | * @psalm-return static<int|array-key,T> |
||
| 2653 | */ |
||
| 2654 | 4 | public function getRandom(): self |
|
| 2658 | |||
| 2659 | /** |
||
| 2660 | * alias: for "Arrayy->randomKey()" |
||
| 2661 | * |
||
| 2662 | * @return mixed |
||
| 2663 | * <p>Get a key/index or null if there wasn't a key/index.</p> |
||
| 2664 | * |
||
| 2665 | * @see Arrayy::randomKey() |
||
| 2666 | */ |
||
| 2667 | 3 | public function getRandomKey() |
|
| 2671 | |||
| 2672 | /** |
||
| 2673 | * alias: for "Arrayy->randomKeys()" |
||
| 2674 | * |
||
| 2675 | * @param int $number |
||
| 2676 | * |
||
| 2677 | * @return static |
||
| 2678 | * <p>(Immutable)</p> |
||
| 2679 | * |
||
| 2680 | * @see Arrayy::randomKeys() |
||
| 2681 | * |
||
| 2682 | * @psalm-return static<TKey,T> |
||
| 2683 | */ |
||
| 2684 | 8 | public function getRandomKeys(int $number): self |
|
| 2688 | |||
| 2689 | /** |
||
| 2690 | * alias: for "Arrayy->randomValue()" |
||
| 2691 | * |
||
| 2692 | * @return mixed |
||
| 2693 | * <p>Get a random value or null if there wasn't a value.</p> |
||
| 2694 | * |
||
| 2695 | * @see Arrayy::randomValue() |
||
| 2696 | */ |
||
| 2697 | 3 | public function getRandomValue() |
|
| 2701 | |||
| 2702 | /** |
||
| 2703 | * alias: for "Arrayy->randomValues()" |
||
| 2704 | * |
||
| 2705 | * @param int $number |
||
| 2706 | * |
||
| 2707 | * @return static |
||
| 2708 | * <p>(Immutable)</p> |
||
| 2709 | * |
||
| 2710 | * @see Arrayy::randomValues() |
||
| 2711 | * |
||
| 2712 | * @psalm-return static<TKey,T> |
||
| 2713 | */ |
||
| 2714 | 6 | public function getRandomValues(int $number): self |
|
| 2718 | |||
| 2719 | /** |
||
| 2720 | * Gets all values. |
||
| 2721 | * |
||
| 2722 | * @return static |
||
| 2723 | * <p>The values of all elements in this array, in the order they |
||
| 2724 | * appear in the array.</p> |
||
| 2725 | * |
||
| 2726 | * @psalm-return static<TKey,T> |
||
| 2727 | */ |
||
| 2728 | 4 | public function getValues() |
|
| 2738 | |||
| 2739 | /** |
||
| 2740 | * Gets all values via Generator. |
||
| 2741 | * |
||
| 2742 | * @return \Generator |
||
| 2743 | * <p>The values of all elements in this array, in the order they |
||
| 2744 | * appear in the array as Generator.</p> |
||
| 2745 | * |
||
| 2746 | * @psalm-return \Generator<TKey,T> |
||
| 2747 | */ |
||
| 2748 | 4 | public function getValuesYield(): \Generator |
|
| 2752 | |||
| 2753 | /** |
||
| 2754 | * Group values from a array according to the results of a closure. |
||
| 2755 | * |
||
| 2756 | * @param callable|string $grouper <p>A callable function name.</p> |
||
| 2757 | * @param bool $saveKeys |
||
| 2758 | * |
||
| 2759 | * @return static |
||
| 2760 | * <p>(Immutable)</p> |
||
| 2761 | * |
||
| 2762 | * @psalm-return static<TKey,T> |
||
| 2763 | * @psalm-mutation-free |
||
| 2764 | */ |
||
| 2765 | 4 | public function group($grouper, bool $saveKeys = false): self |
|
| 2806 | |||
| 2807 | /** |
||
| 2808 | * Check if an array has a given key. |
||
| 2809 | * |
||
| 2810 | * @param mixed $key |
||
| 2811 | * |
||
| 2812 | * @return bool |
||
| 2813 | */ |
||
| 2814 | 30 | public function has($key): bool |
|
| 2840 | |||
| 2841 | /** |
||
| 2842 | * Check if an array has a given value. |
||
| 2843 | * |
||
| 2844 | * INFO: if you need to search recursive please use ```contains()``` |
||
| 2845 | * |
||
| 2846 | * @param mixed $value |
||
| 2847 | * |
||
| 2848 | * @return bool |
||
| 2849 | */ |
||
| 2850 | 1 | public function hasValue($value): bool |
|
| 2854 | |||
| 2855 | /** |
||
| 2856 | * Implodes the values of this array. |
||
| 2857 | * |
||
| 2858 | * @param string $glue |
||
| 2859 | * |
||
| 2860 | * @return string |
||
| 2861 | * @psalm-mutation-free |
||
| 2862 | */ |
||
| 2863 | 28 | public function implode(string $glue = ''): string |
|
| 2867 | |||
| 2868 | /** |
||
| 2869 | * Implodes the keys of this array. |
||
| 2870 | * |
||
| 2871 | * @param string $glue |
||
| 2872 | * |
||
| 2873 | * @return string |
||
| 2874 | * @psalm-mutation-free |
||
| 2875 | */ |
||
| 2876 | 8 | public function implodeKeys(string $glue = ''): string |
|
| 2880 | |||
| 2881 | /** |
||
| 2882 | * Given a list and an iterate-function that returns |
||
| 2883 | * a key for each element in the list (or a property name), |
||
| 2884 | * returns an object with an index of each item. |
||
| 2885 | * |
||
| 2886 | * @param mixed $key |
||
| 2887 | * |
||
| 2888 | * @return static |
||
| 2889 | * <p>(Immutable)</p> |
||
| 2890 | * |
||
| 2891 | * @psalm-return static<TKey,T> |
||
| 2892 | * @psalm-mutation-free |
||
| 2893 | */ |
||
| 2894 | 4 | public function indexBy($key): self |
|
| 2911 | |||
| 2912 | /** |
||
| 2913 | * alias: for "Arrayy->searchIndex()" |
||
| 2914 | * |
||
| 2915 | * @param mixed $value <p>The value to search for.</p> |
||
| 2916 | * |
||
| 2917 | * @return false|mixed |
||
| 2918 | * |
||
| 2919 | * @see Arrayy::searchIndex() |
||
| 2920 | */ |
||
| 2921 | 4 | public function indexOf($value) |
|
| 2925 | |||
| 2926 | /** |
||
| 2927 | * Get everything but the last..$to items. |
||
| 2928 | * |
||
| 2929 | * @param int $to |
||
| 2930 | * |
||
| 2931 | * @return static |
||
| 2932 | * <p>(Immutable)</p> |
||
| 2933 | * |
||
| 2934 | * @psalm-return static<TKey,T> |
||
| 2935 | * @psalm-mutation-free |
||
| 2936 | */ |
||
| 2937 | 12 | public function initial(int $to = 1): self |
|
| 2941 | |||
| 2942 | /** |
||
| 2943 | * Return an array with all elements found in input array. |
||
| 2944 | * |
||
| 2945 | * @param array $search |
||
| 2946 | * @param bool $keepKeys |
||
| 2947 | * |
||
| 2948 | * @return static |
||
| 2949 | * <p>(Immutable)</p> |
||
| 2950 | * |
||
| 2951 | * @psalm-param array<mixed,mixed>|array<TKey,T> $search |
||
| 2952 | * @psalm-return static<TKey,T> |
||
| 2953 | * @psalm-mutation-free |
||
| 2954 | */ |
||
| 2955 | 4 | public function intersection(array $search, bool $keepKeys = false): self |
|
| 2981 | |||
| 2982 | /** |
||
| 2983 | * Return an array with all elements found in input array. |
||
| 2984 | * |
||
| 2985 | * @param array ...$array |
||
| 2986 | * |
||
| 2987 | * @return static |
||
| 2988 | * <p>(Immutable)</p> |
||
| 2989 | * |
||
| 2990 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$array |
||
| 2991 | * @psalm-return static<TKey,T> |
||
| 2992 | * @psalm-mutation-free |
||
| 2993 | */ |
||
| 2994 | 1 | public function intersectionMulti(...$array): self |
|
| 3002 | |||
| 3003 | /** |
||
| 3004 | * Return a boolean flag which indicates whether the two input arrays have any common elements. |
||
| 3005 | * |
||
| 3006 | * @param array $search |
||
| 3007 | * |
||
| 3008 | * @return bool |
||
| 3009 | * |
||
| 3010 | * @psalm-param array<mixed,mixed>|array<TKey,T> $search |
||
| 3011 | */ |
||
| 3012 | 1 | public function intersects(array $search): bool |
|
| 3016 | |||
| 3017 | /** |
||
| 3018 | * Invoke a function on all of an array's values. |
||
| 3019 | * |
||
| 3020 | * @param callable $callable |
||
| 3021 | * @param mixed $arguments |
||
| 3022 | * |
||
| 3023 | * @return static |
||
| 3024 | * <p>(Immutable)</p> |
||
| 3025 | * |
||
| 3026 | * @psalm-param callable(T=,mixed):mixed $callable |
||
| 3027 | * @psalm-return static<TKey,T> |
||
| 3028 | * @psalm-mutation-free |
||
| 3029 | */ |
||
| 3030 | 1 | View Code Duplication | public function invoke($callable, $arguments = []): self |
| 3054 | |||
| 3055 | /** |
||
| 3056 | * Check whether array is associative or not. |
||
| 3057 | * |
||
| 3058 | * @param bool $recursive |
||
| 3059 | * |
||
| 3060 | * @return bool |
||
| 3061 | * <p>Returns true if associative, false otherwise.</p> |
||
| 3062 | */ |
||
| 3063 | 15 | View Code Duplication | public function isAssoc(bool $recursive = false): bool |
| 3077 | |||
| 3078 | /** |
||
| 3079 | * Check if a given key or keys are empty. |
||
| 3080 | * |
||
| 3081 | * @param int|int[]|string|string[]|null $keys |
||
| 3082 | * |
||
| 3083 | * @return bool |
||
| 3084 | * <p>Returns true if empty, false otherwise.</p> |
||
| 3085 | * @psalm-mutation-free |
||
| 3086 | */ |
||
| 3087 | 45 | public function isEmpty($keys = null): bool |
|
| 3105 | |||
| 3106 | /** |
||
| 3107 | * Check if the current array is equal to the given "$array" or not. |
||
| 3108 | * |
||
| 3109 | * @param array $array |
||
| 3110 | * |
||
| 3111 | * @return bool |
||
| 3112 | * |
||
| 3113 | * @psalm-param array<mixed,mixed> $array |
||
| 3114 | */ |
||
| 3115 | 1 | public function isEqual(array $array): bool |
|
| 3119 | |||
| 3120 | /** |
||
| 3121 | * Check if the current array is a multi-array. |
||
| 3122 | * |
||
| 3123 | * @return bool |
||
| 3124 | */ |
||
| 3125 | 22 | public function isMultiArray(): bool |
|
| 3133 | |||
| 3134 | /** |
||
| 3135 | * Check whether array is numeric or not. |
||
| 3136 | * |
||
| 3137 | * @return bool |
||
| 3138 | * <p>Returns true if numeric, false otherwise.</p> |
||
| 3139 | */ |
||
| 3140 | 5 | View Code Duplication | public function isNumeric(): bool |
| 3154 | |||
| 3155 | /** |
||
| 3156 | * Check if the current array is sequential [0, 1, 2, 3, 4, 5 ...] or not. |
||
| 3157 | * |
||
| 3158 | * @param bool $recursive |
||
| 3159 | * |
||
| 3160 | * @return bool |
||
| 3161 | * @psalm-mutation-free |
||
| 3162 | */ |
||
| 3163 | 9 | public function isSequential(bool $recursive = false): bool |
|
| 3180 | |||
| 3181 | /** |
||
| 3182 | * @return array |
||
| 3183 | * |
||
| 3184 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 3185 | */ |
||
| 3186 | 1 | public function jsonSerialize(): array |
|
| 3190 | |||
| 3191 | /** |
||
| 3192 | * Gets the key/index of the element at the current internal iterator position. |
||
| 3193 | * |
||
| 3194 | * @return int|string|null |
||
| 3195 | */ |
||
| 3196 | public function key() |
||
| 3200 | |||
| 3201 | /** |
||
| 3202 | * Checks if the given key exists in the provided array. |
||
| 3203 | * |
||
| 3204 | * INFO: This method only use "array_key_exists()" if you want to use "dot"-notation, |
||
| 3205 | * then you need to use "Arrayy->offsetExists()". |
||
| 3206 | * |
||
| 3207 | * @param int|string $key the key to look for |
||
| 3208 | * |
||
| 3209 | * @return bool |
||
| 3210 | * @psalm-mutation-free |
||
| 3211 | */ |
||
| 3212 | 142 | public function keyExists($key): bool |
|
| 3216 | |||
| 3217 | /** |
||
| 3218 | * Get all keys from the current array. |
||
| 3219 | * |
||
| 3220 | * @param bool $recursive [optional] <p> |
||
| 3221 | * Get all keys, also from all sub-arrays from an multi-dimensional array. |
||
| 3222 | * </p> |
||
| 3223 | * @param mixed|null $search_values [optional] <p> |
||
| 3224 | * If specified, then only keys containing these values are returned. |
||
| 3225 | * </p> |
||
| 3226 | * @param bool $strict [optional] <p> |
||
| 3227 | * Determines if strict comparison (===) should be used during the search. |
||
| 3228 | * </p> |
||
| 3229 | * |
||
| 3230 | * @return static |
||
| 3231 | * <p>(Immutable) An array of all the keys in input.</p> |
||
| 3232 | * |
||
| 3233 | * @psalm-return static<array-key,TKey> |
||
| 3234 | * @psalm-mutation-free |
||
| 3235 | */ |
||
| 3236 | 29 | public function keys( |
|
| 3306 | |||
| 3307 | /** |
||
| 3308 | * Sort an array by key in reverse order. |
||
| 3309 | * |
||
| 3310 | * @param int $sort_flags [optional] <p> |
||
| 3311 | * You may modify the behavior of the sort using the optional |
||
| 3312 | * parameter sort_flags, for details |
||
| 3313 | * see sort. |
||
| 3314 | * </p> |
||
| 3315 | * |
||
| 3316 | * @return $this |
||
| 3317 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 3318 | * |
||
| 3319 | * @psalm-return static<TKey,T> |
||
| 3320 | */ |
||
| 3321 | 4 | public function krsort(int $sort_flags = 0): self |
|
| 3329 | |||
| 3330 | /** |
||
| 3331 | * Sort an array by key in reverse order. |
||
| 3332 | * |
||
| 3333 | * @param int $sort_flags [optional] <p> |
||
| 3334 | * You may modify the behavior of the sort using the optional |
||
| 3335 | * parameter sort_flags, for details |
||
| 3336 | * see sort. |
||
| 3337 | * </p> |
||
| 3338 | * |
||
| 3339 | * @return $this |
||
| 3340 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 3341 | * |
||
| 3342 | * @psalm-return static<TKey,T> |
||
| 3343 | * @psalm-mutation-free |
||
| 3344 | */ |
||
| 3345 | 4 | public function krsortImmutable(int $sort_flags = 0): self |
|
| 3356 | |||
| 3357 | /** |
||
| 3358 | * Get the last value from the current array. |
||
| 3359 | * |
||
| 3360 | * @return mixed|null |
||
| 3361 | * <p>Return null if there wasn't a element.</p> |
||
| 3362 | * @psalm-mutation-free |
||
| 3363 | */ |
||
| 3364 | 17 | public function last() |
|
| 3373 | |||
| 3374 | /** |
||
| 3375 | * Get the last key from the current array. |
||
| 3376 | * |
||
| 3377 | * @return mixed|null |
||
| 3378 | * <p>Return null if there wasn't a element.</p> |
||
| 3379 | * @psalm-mutation-free |
||
| 3380 | */ |
||
| 3381 | 21 | public function lastKey() |
|
| 3387 | |||
| 3388 | /** |
||
| 3389 | * Get the last value(s) from the current array. |
||
| 3390 | * |
||
| 3391 | * @param int|null $number |
||
| 3392 | * |
||
| 3393 | * @return static |
||
| 3394 | * <p>(Immutable)</p> |
||
| 3395 | * |
||
| 3396 | * @psalm-return static<TKey,T> |
||
| 3397 | * @psalm-mutation-free |
||
| 3398 | */ |
||
| 3399 | 13 | public function lastsImmutable(int $number = null): self |
|
| 3430 | |||
| 3431 | /** |
||
| 3432 | * Get the last value(s) from the current array. |
||
| 3433 | * |
||
| 3434 | * @param int|null $number |
||
| 3435 | * |
||
| 3436 | * @return $this |
||
| 3437 | * <p>(Mutable)</p> |
||
| 3438 | * |
||
| 3439 | * @psalm-return static<TKey,T> |
||
| 3440 | */ |
||
| 3441 | 13 | public function lastsMutable(int $number = null): self |
|
| 3470 | |||
| 3471 | /** |
||
| 3472 | * Count the values from the current array. |
||
| 3473 | * |
||
| 3474 | * alias: for "Arrayy->count()" |
||
| 3475 | * |
||
| 3476 | * @param int $mode |
||
| 3477 | * |
||
| 3478 | * @return int |
||
| 3479 | * |
||
| 3480 | * @see Arrayy::count() |
||
| 3481 | */ |
||
| 3482 | 20 | public function length(int $mode = \COUNT_NORMAL): int |
|
| 3486 | |||
| 3487 | /** |
||
| 3488 | * Apply the given function to the every element of the array, |
||
| 3489 | * collecting the results. |
||
| 3490 | * |
||
| 3491 | * @param callable $callable |
||
| 3492 | * @param bool $useKeyAsSecondParameter |
||
| 3493 | * @param mixed ...$arguments |
||
| 3494 | * |
||
| 3495 | * @return static |
||
| 3496 | * <p>(Immutable) Arrayy object with modified elements.</p> |
||
| 3497 | * |
||
| 3498 | * @psalm-param callable(T,TKey=,mixed=):mixed $callable |
||
| 3499 | * @psalm-return static<TKey,T> |
||
| 3500 | * @psalm-mutation-free |
||
| 3501 | */ |
||
| 3502 | 5 | public function map( |
|
| 3535 | |||
| 3536 | /** |
||
| 3537 | * Check if all items in current array match a truth test. |
||
| 3538 | * |
||
| 3539 | * @param \Closure $closure |
||
| 3540 | * |
||
| 3541 | * @return bool |
||
| 3542 | */ |
||
| 3543 | 15 | View Code Duplication | public function matches(\Closure $closure): bool |
| 3559 | |||
| 3560 | /** |
||
| 3561 | * Check if any item in the current array matches a truth test. |
||
| 3562 | * |
||
| 3563 | * @param \Closure $closure |
||
| 3564 | * |
||
| 3565 | * @return bool |
||
| 3566 | */ |
||
| 3567 | 14 | View Code Duplication | public function matchesAny(\Closure $closure): bool |
| 3583 | |||
| 3584 | /** |
||
| 3585 | * Get the max value from an array. |
||
| 3586 | * |
||
| 3587 | * @return false|mixed |
||
| 3588 | * <p>Will return false if there are no values.</p> |
||
| 3589 | */ |
||
| 3590 | 10 | View Code Duplication | public function max() |
| 3609 | |||
| 3610 | /** |
||
| 3611 | * Merge the new $array into the current array. |
||
| 3612 | * |
||
| 3613 | * - keep key,value from the current array, also if the index is in the new $array |
||
| 3614 | * |
||
| 3615 | * @param array $array |
||
| 3616 | * @param bool $recursive |
||
| 3617 | * |
||
| 3618 | * @return static |
||
| 3619 | * <p>(Immutable)</p> |
||
| 3620 | * |
||
| 3621 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 3622 | * @psalm-return static<int|TKey,T> |
||
| 3623 | * @psalm-mutation-free |
||
| 3624 | */ |
||
| 3625 | 32 | View Code Duplication | public function mergeAppendKeepIndex(array $array = [], bool $recursive = false): self |
| 3640 | |||
| 3641 | /** |
||
| 3642 | * Merge the new $array into the current array. |
||
| 3643 | * |
||
| 3644 | * - replace duplicate assoc-keys from the current array with the key,values from the new $array |
||
| 3645 | * - create new indexes |
||
| 3646 | * |
||
| 3647 | * @param array $array |
||
| 3648 | * @param bool $recursive |
||
| 3649 | * |
||
| 3650 | * @return static |
||
| 3651 | * <p>(Immutable)</p> |
||
| 3652 | * |
||
| 3653 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 3654 | * @psalm-return static<TKey,T> |
||
| 3655 | * @psalm-mutation-free |
||
| 3656 | */ |
||
| 3657 | 19 | View Code Duplication | public function mergeAppendNewIndex(array $array = [], bool $recursive = false): self |
| 3672 | |||
| 3673 | /** |
||
| 3674 | * Merge the the current array into the $array. |
||
| 3675 | * |
||
| 3676 | * - use key,value from the new $array, also if the index is in the current array |
||
| 3677 | * |
||
| 3678 | * @param array $array |
||
| 3679 | * @param bool $recursive |
||
| 3680 | * |
||
| 3681 | * @return static |
||
| 3682 | * <p>(Immutable)</p> |
||
| 3683 | * |
||
| 3684 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 3685 | * @psalm-return static<TKey,T> |
||
| 3686 | * @psalm-mutation-free |
||
| 3687 | */ |
||
| 3688 | 16 | View Code Duplication | public function mergePrependKeepIndex(array $array = [], bool $recursive = false): self |
| 3703 | |||
| 3704 | /** |
||
| 3705 | * Merge the current array into the new $array. |
||
| 3706 | * |
||
| 3707 | * - replace duplicate assoc-keys from new $array with the key,values from the current array |
||
| 3708 | * - create new indexes |
||
| 3709 | * |
||
| 3710 | * @param array $array |
||
| 3711 | * @param bool $recursive |
||
| 3712 | * |
||
| 3713 | * @return static |
||
| 3714 | * <p>(Immutable)</p> |
||
| 3715 | * |
||
| 3716 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 3717 | * @psalm-return static<TKey,T> |
||
| 3718 | * @psalm-mutation-free |
||
| 3719 | */ |
||
| 3720 | 20 | View Code Duplication | public function mergePrependNewIndex(array $array = [], bool $recursive = false): self |
| 3735 | |||
| 3736 | /** |
||
| 3737 | * @return ArrayyMeta|static |
||
| 3738 | */ |
||
| 3739 | 15 | public static function meta() |
|
| 3743 | |||
| 3744 | /** |
||
| 3745 | * Get the min value from an array. |
||
| 3746 | * |
||
| 3747 | * @return false|mixed |
||
| 3748 | * <p>Will return false if there are no values.</p> |
||
| 3749 | */ |
||
| 3750 | 10 | View Code Duplication | public function min() |
| 3769 | |||
| 3770 | /** |
||
| 3771 | * Get the most used value from the array. |
||
| 3772 | * |
||
| 3773 | * @return mixed|null |
||
| 3774 | * <p>(Immutable) Return null if there wasn't a element.</p> |
||
| 3775 | * @psalm-mutation-free |
||
| 3776 | */ |
||
| 3777 | 3 | public function mostUsedValue() |
|
| 3781 | |||
| 3782 | /** |
||
| 3783 | * Get the most used value from the array. |
||
| 3784 | * |
||
| 3785 | * @param int|null $number <p>How many values you will take?</p> |
||
| 3786 | * |
||
| 3787 | * @return static |
||
| 3788 | * <p>(Immutable)</p> |
||
| 3789 | * |
||
| 3790 | * @psalm-return static<TKey,T> |
||
| 3791 | * @psalm-mutation-free |
||
| 3792 | */ |
||
| 3793 | 3 | public function mostUsedValues(int $number = null): self |
|
| 3797 | |||
| 3798 | /** |
||
| 3799 | * Move an array element to a new index. |
||
| 3800 | * |
||
| 3801 | * cherry-picked from: http://stackoverflow.com/questions/12624153/move-an-array-element-to-a-new-index-in-php |
||
| 3802 | * |
||
| 3803 | * @param int|string $from |
||
| 3804 | * @param int $to |
||
| 3805 | * |
||
| 3806 | * @return static |
||
| 3807 | * <p>(Immutable)</p> |
||
| 3808 | * |
||
| 3809 | * @psalm-return static<TKey,T> |
||
| 3810 | * @psalm-mutation-free |
||
| 3811 | */ |
||
| 3812 | 1 | public function moveElement($from, $to): self |
|
| 3845 | |||
| 3846 | /** |
||
| 3847 | * Move an array element to the first place. |
||
| 3848 | * |
||
| 3849 | * INFO: Instead of "Arrayy->moveElement()" this method will NOT |
||
| 3850 | * loss the keys of an indexed array. |
||
| 3851 | * |
||
| 3852 | * @param int|string $key |
||
| 3853 | * |
||
| 3854 | * @return static |
||
| 3855 | * <p>(Immutable)</p> |
||
| 3856 | * |
||
| 3857 | * @psalm-return static<TKey,T> |
||
| 3858 | * @psalm-mutation-free |
||
| 3859 | */ |
||
| 3860 | 1 | View Code Duplication | public function moveElementToFirstPlace($key): self |
| 3876 | |||
| 3877 | /** |
||
| 3878 | * Move an array element to the last place. |
||
| 3879 | * |
||
| 3880 | * INFO: Instead of "Arrayy->moveElement()" this method will NOT |
||
| 3881 | * loss the keys of an indexed array. |
||
| 3882 | * |
||
| 3883 | * @param int|string $key |
||
| 3884 | * |
||
| 3885 | * @return static |
||
| 3886 | * <p>(Immutable)</p> |
||
| 3887 | * |
||
| 3888 | * @psalm-return static<TKey,T> |
||
| 3889 | * @psalm-mutation-free |
||
| 3890 | */ |
||
| 3891 | 1 | View Code Duplication | public function moveElementToLastPlace($key): self |
| 3907 | |||
| 3908 | /** |
||
| 3909 | * Moves the internal iterator position to the next element and returns this element. |
||
| 3910 | * |
||
| 3911 | * @return false|mixed |
||
| 3912 | * <p>(Mutable) Will return false if there are no values.</p> |
||
| 3913 | */ |
||
| 3914 | public function next() |
||
| 3918 | |||
| 3919 | /** |
||
| 3920 | * Get the next nth keys and values from the array. |
||
| 3921 | * |
||
| 3922 | * @param int $step |
||
| 3923 | * @param int $offset |
||
| 3924 | * |
||
| 3925 | * @return static |
||
| 3926 | * <p>(Immutable)</p> |
||
| 3927 | * |
||
| 3928 | * @psalm-return static<TKey,T> |
||
| 3929 | * @psalm-mutation-free |
||
| 3930 | */ |
||
| 3931 | public function nth(int $step, int $offset = 0): self |
||
| 3950 | |||
| 3951 | /** |
||
| 3952 | * Get a subset of the items from the given array. |
||
| 3953 | * |
||
| 3954 | * @param mixed[] $keys |
||
| 3955 | * |
||
| 3956 | * @return static |
||
| 3957 | * <p>(Immutable)</p> |
||
| 3958 | * |
||
| 3959 | * @psalm-return static<TKey,T> |
||
| 3960 | * @psalm-mutation-free |
||
| 3961 | */ |
||
| 3962 | 1 | public function only(array $keys): self |
|
| 3972 | |||
| 3973 | /** |
||
| 3974 | * Pad array to the specified size with a given value. |
||
| 3975 | * |
||
| 3976 | * @param int $size <p>Size of the result array.</p> |
||
| 3977 | * @param mixed $value <p>Empty value by default.</p> |
||
| 3978 | * |
||
| 3979 | * @return static |
||
| 3980 | * <p>(Immutable) Arrayy object padded to $size with $value.</p> |
||
| 3981 | * |
||
| 3982 | * @psalm-return static<TKey,T> |
||
| 3983 | * @psalm-mutation-free |
||
| 3984 | */ |
||
| 3985 | 5 | public function pad(int $size, $value): self |
|
| 3993 | |||
| 3994 | /** |
||
| 3995 | * Partitions this array in two array according to a predicate. |
||
| 3996 | * Keys are preserved in the resulting array. |
||
| 3997 | * |
||
| 3998 | * @param \Closure $closure |
||
| 3999 | * <p>The predicate on which to partition.</p> |
||
| 4000 | * |
||
| 4001 | * @return array<int, static> |
||
| 4002 | * <p>An array with two elements. The first element contains the array |
||
| 4003 | * of elements where the predicate returned TRUE, the second element |
||
| 4004 | * contains the array of elements where the predicate returned FALSE.</p> |
||
| 4005 | * |
||
| 4006 | * @psalm-return array<int, static<TKey,T>> |
||
| 4007 | */ |
||
| 4008 | 1 | public function partition(\Closure $closure): array |
|
| 4024 | |||
| 4025 | /** |
||
| 4026 | * Pop a specified value off the end of the current array. |
||
| 4027 | * |
||
| 4028 | * @return mixed|null |
||
| 4029 | * <p>(Mutable) The popped element from the current array or null if the array is e.g. empty.</p> |
||
| 4030 | */ |
||
| 4031 | 5 | public function pop() |
|
| 4037 | |||
| 4038 | /** |
||
| 4039 | * Prepend a (key) + value to the current array. |
||
| 4040 | * |
||
| 4041 | * @param mixed $value |
||
| 4042 | * @param mixed $key |
||
| 4043 | * |
||
| 4044 | * @return $this |
||
| 4045 | * <p>(Mutable) Return this Arrayy object, with the prepended value.</p> |
||
| 4046 | * |
||
| 4047 | * @psalm-return static<TKey,T> |
||
| 4048 | */ |
||
| 4049 | 11 | public function prepend($value, $key = null) |
|
| 4065 | |||
| 4066 | /** |
||
| 4067 | * Add a suffix to each key. |
||
| 4068 | * |
||
| 4069 | * @param mixed $suffix |
||
| 4070 | * |
||
| 4071 | * @return static |
||
| 4072 | * <p>(Immutable) Return an Arrayy object, with the prepended keys.</p> |
||
| 4073 | * |
||
| 4074 | * @psalm-return static<TKey,T> |
||
| 4075 | * @psalm-mutation-free |
||
| 4076 | */ |
||
| 4077 | 10 | View Code Duplication | public function prependToEachKey($suffix): self |
| 4103 | |||
| 4104 | /** |
||
| 4105 | * Add a suffix to each value. |
||
| 4106 | * |
||
| 4107 | * @param mixed $suffix |
||
| 4108 | * |
||
| 4109 | * @return static |
||
| 4110 | * <p>(Immutable) Return an Arrayy object, with the prepended values.</p> |
||
| 4111 | * |
||
| 4112 | * @psalm-return static<TKey,T> |
||
| 4113 | * @psalm-mutation-free |
||
| 4114 | */ |
||
| 4115 | 10 | View Code Duplication | public function prependToEachValue($suffix): self |
| 4143 | |||
| 4144 | /** |
||
| 4145 | * Return the value of a given key and |
||
| 4146 | * delete the key. |
||
| 4147 | * |
||
| 4148 | * @param int|int[]|string|string[]|null $keyOrKeys |
||
| 4149 | * @param mixed $fallback |
||
| 4150 | * |
||
| 4151 | * @return mixed |
||
| 4152 | */ |
||
| 4153 | 5 | public function pull($keyOrKeys = null, $fallback = null) |
|
| 4175 | |||
| 4176 | /** |
||
| 4177 | * Push one or more values onto the end of array at once. |
||
| 4178 | * |
||
| 4179 | * @param array ...$args |
||
| 4180 | * |
||
| 4181 | * @return $this |
||
| 4182 | * <p>(Mutable) Return this Arrayy object, with pushed elements to the end of array.</p> |
||
| 4183 | * |
||
| 4184 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
| 4185 | * |
||
| 4186 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$args |
||
| 4187 | * @psalm-return static<TKey,T> |
||
| 4188 | */ |
||
| 4189 | 7 | public function push(...$args) |
|
| 4207 | |||
| 4208 | /** |
||
| 4209 | * Get a random value from the current array. |
||
| 4210 | * |
||
| 4211 | * @param int|null $number <p>How many values you will take?</p> |
||
| 4212 | * |
||
| 4213 | * @return static |
||
| 4214 | * <p>(Immutable)</p> |
||
| 4215 | * |
||
| 4216 | * @psalm-return static<int|array-key,T> |
||
| 4217 | */ |
||
| 4218 | 19 | public function randomImmutable(int $number = null): self |
|
| 4251 | |||
| 4252 | /** |
||
| 4253 | * Pick a random key/index from the keys of this array. |
||
| 4254 | * |
||
| 4255 | * @throws \RangeException If array is empty |
||
| 4256 | * |
||
| 4257 | * @return mixed |
||
| 4258 | * <p>Get a key/index or null if there wasn't a key/index.</p> |
||
| 4259 | */ |
||
| 4260 | 4 | public function randomKey() |
|
| 4270 | |||
| 4271 | /** |
||
| 4272 | * Pick a given number of random keys/indexes out of this array. |
||
| 4273 | * |
||
| 4274 | * @param int $number <p>The number of keys/indexes (should be <= \count($this->array))</p> |
||
| 4275 | * |
||
| 4276 | * @throws \RangeException If array is empty |
||
| 4277 | * |
||
| 4278 | * @return static |
||
| 4279 | * <p>(Immutable)</p> |
||
| 4280 | * |
||
| 4281 | * @psalm-return static<TKey,T> |
||
| 4282 | */ |
||
| 4283 | 13 | public function randomKeys(int $number): self |
|
| 4311 | |||
| 4312 | /** |
||
| 4313 | * Get a random value from the current array. |
||
| 4314 | * |
||
| 4315 | * @param int|null $number <p>How many values you will take?</p> |
||
| 4316 | * |
||
| 4317 | * @return $this |
||
| 4318 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 4319 | * |
||
| 4320 | * @psalm-return static<TKey,T> |
||
| 4321 | */ |
||
| 4322 | 17 | public function randomMutable(int $number = null): self |
|
| 4347 | |||
| 4348 | /** |
||
| 4349 | * Pick a random value from the values of this array. |
||
| 4350 | * |
||
| 4351 | * @return mixed |
||
| 4352 | * <p>Get a random value or null if there wasn't a value.</p> |
||
| 4353 | */ |
||
| 4354 | 4 | public function randomValue() |
|
| 4364 | |||
| 4365 | /** |
||
| 4366 | * Pick a given number of random values out of this array. |
||
| 4367 | * |
||
| 4368 | * @param int $number |
||
| 4369 | * |
||
| 4370 | * @return static |
||
| 4371 | * <p>(Mutable)</p> |
||
| 4372 | * |
||
| 4373 | * @psalm-return static<TKey,T> |
||
| 4374 | */ |
||
| 4375 | 7 | public function randomValues(int $number): self |
|
| 4379 | |||
| 4380 | /** |
||
| 4381 | * Get a random value from an array, with the ability to skew the results. |
||
| 4382 | * |
||
| 4383 | * Example: randomWeighted(['foo' => 1, 'bar' => 2]) has a 66% chance of returning bar. |
||
| 4384 | * |
||
| 4385 | * @param array $array |
||
| 4386 | * @param int|null $number <p>How many values you will take?</p> |
||
| 4387 | * |
||
| 4388 | * @return static<int,mixed> |
||
| 4389 | * <p>(Immutable)</p> |
||
| 4390 | * |
||
| 4391 | * @psalm-param array<mixed,mixed> $array |
||
| 4392 | * @psalm-return static<int|array-key,T> |
||
| 4393 | */ |
||
| 4394 | 9 | public function randomWeighted(array $array, int $number = null): self |
|
| 4409 | |||
| 4410 | /** |
||
| 4411 | * Reduce the current array via callable e.g. anonymous-function. |
||
| 4412 | * |
||
| 4413 | * @param callable $callable |
||
| 4414 | * @param mixed $init |
||
| 4415 | * |
||
| 4416 | * @return static |
||
| 4417 | * <p>(Immutable)</p> |
||
| 4418 | * |
||
| 4419 | * @psalm-return static<TKey,T> |
||
| 4420 | * @psalm-mutation-free |
||
| 4421 | */ |
||
| 4422 | 18 | public function reduce($callable, $init = []): self |
|
| 4452 | |||
| 4453 | /** |
||
| 4454 | * @param bool $unique |
||
| 4455 | * |
||
| 4456 | * @return static |
||
| 4457 | * <p>(Immutable)</p> |
||
| 4458 | * |
||
| 4459 | * @psalm-return static<TKey,T> |
||
| 4460 | * @psalm-mutation-free |
||
| 4461 | */ |
||
| 4462 | 14 | public function reduce_dimension(bool $unique = true): self |
|
| 4485 | |||
| 4486 | /** |
||
| 4487 | * Create a numerically re-indexed Arrayy object. |
||
| 4488 | * |
||
| 4489 | * @return $this |
||
| 4490 | * <p>(Mutable) Return this Arrayy object, with re-indexed array-elements.</p> |
||
| 4491 | * |
||
| 4492 | * @psalm-return static<TKey,T> |
||
| 4493 | */ |
||
| 4494 | 9 | public function reindex(): self |
|
| 4502 | |||
| 4503 | /** |
||
| 4504 | * Return all items that fail the truth test. |
||
| 4505 | * |
||
| 4506 | * @param \Closure $closure |
||
| 4507 | * |
||
| 4508 | * @return static |
||
| 4509 | * <p>(Immutable)</p> |
||
| 4510 | * |
||
| 4511 | * @psalm-return static<TKey,T> |
||
| 4512 | * @psalm-mutation-free |
||
| 4513 | */ |
||
| 4514 | 1 | View Code Duplication | public function reject(\Closure $closure): self |
| 4531 | |||
| 4532 | /** |
||
| 4533 | * Remove a value from the current array (optional using dot-notation). |
||
| 4534 | * |
||
| 4535 | * @param mixed $key |
||
| 4536 | * |
||
| 4537 | * @return static |
||
| 4538 | * <p>(Mutable)</p> |
||
| 4539 | * |
||
| 4540 | * @psalm-param TKey $key |
||
| 4541 | * @psalm-return static<TKey,T> |
||
| 4542 | */ |
||
| 4543 | 21 | public function remove($key) |
|
| 4566 | |||
| 4567 | /** |
||
| 4568 | * alias: for "Arrayy->removeValue()" |
||
| 4569 | * |
||
| 4570 | * @param mixed $element |
||
| 4571 | * |
||
| 4572 | * @return static |
||
| 4573 | * <p>(Immutable)</p> |
||
| 4574 | * |
||
| 4575 | * @psalm-param T $element |
||
| 4576 | * @psalm-return static<TKey,T> |
||
| 4577 | * @psalm-mutation-free |
||
| 4578 | */ |
||
| 4579 | 8 | public function removeElement($element) |
|
| 4583 | |||
| 4584 | /** |
||
| 4585 | * Remove the first value from the current array. |
||
| 4586 | * |
||
| 4587 | * @return static |
||
| 4588 | * <p>(Immutable)</p> |
||
| 4589 | * |
||
| 4590 | * @psalm-return static<TKey,T> |
||
| 4591 | * @psalm-mutation-free |
||
| 4592 | */ |
||
| 4593 | 7 | View Code Duplication | public function removeFirst(): self |
| 4605 | |||
| 4606 | /** |
||
| 4607 | * Remove the last value from the current array. |
||
| 4608 | * |
||
| 4609 | * @return static |
||
| 4610 | * <p>(Immutable)</p> |
||
| 4611 | * |
||
| 4612 | * @psalm-return static<TKey,T> |
||
| 4613 | * @psalm-mutation-free |
||
| 4614 | */ |
||
| 4615 | 7 | View Code Duplication | public function removeLast(): self |
| 4627 | |||
| 4628 | /** |
||
| 4629 | * Removes a particular value from an array (numeric or associative). |
||
| 4630 | * |
||
| 4631 | * @param mixed $value |
||
| 4632 | * |
||
| 4633 | * @return static |
||
| 4634 | * <p>(Immutable)</p> |
||
| 4635 | * |
||
| 4636 | * @psalm-param T $value |
||
| 4637 | * @psalm-return static<TKey,T> |
||
| 4638 | * @psalm-mutation-free |
||
| 4639 | */ |
||
| 4640 | 8 | public function removeValue($value): self |
|
| 4663 | |||
| 4664 | /** |
||
| 4665 | * Generate array of repeated arrays. |
||
| 4666 | * |
||
| 4667 | * @param int $times <p>How many times has to be repeated.</p> |
||
| 4668 | * |
||
| 4669 | * @return static |
||
| 4670 | * <p>(Immutable)</p> |
||
| 4671 | * |
||
| 4672 | * @psalm-return static<TKey,T> |
||
| 4673 | * @psalm-mutation-free |
||
| 4674 | */ |
||
| 4675 | 1 | public function repeat($times): self |
|
| 4687 | |||
| 4688 | /** |
||
| 4689 | * Replace a key with a new key/value pair. |
||
| 4690 | * |
||
| 4691 | * @param mixed $oldKey |
||
| 4692 | * @param mixed $newKey |
||
| 4693 | * @param mixed $newValue |
||
| 4694 | * |
||
| 4695 | * @return static |
||
| 4696 | * <p>(Immutable)</p> |
||
| 4697 | * |
||
| 4698 | * @psalm-return static<TKey,T> |
||
| 4699 | * @psalm-mutation-free |
||
| 4700 | */ |
||
| 4701 | 5 | public function replace($oldKey, $newKey, $newValue): self |
|
| 4711 | |||
| 4712 | /** |
||
| 4713 | * Create an array using the current array as values and the other array as keys. |
||
| 4714 | * |
||
| 4715 | * @param array $keys <p>An array of keys.</p> |
||
| 4716 | * |
||
| 4717 | * @return static |
||
| 4718 | * <p>(Immutable) Arrayy object with keys from the other array.</p> |
||
| 4719 | * |
||
| 4720 | * @psalm-param array<mixed,mixed>|array<mixed,TKey> $keys |
||
| 4721 | * @psalm-return static<TKey,T> |
||
| 4722 | * @psalm-mutation-free |
||
| 4723 | */ |
||
| 4724 | 2 | public function replaceAllKeys(array $keys): self |
|
| 4732 | |||
| 4733 | /** |
||
| 4734 | * Create an array using the current array as keys and the other array as values. |
||
| 4735 | * |
||
| 4736 | * @param array $array <p>An array o values.</p> |
||
| 4737 | * |
||
| 4738 | * @return static |
||
| 4739 | * <p>(Immutable) Arrayy object with values from the other array.</p> |
||
| 4740 | * |
||
| 4741 | * @psalm-param array<mixed,T> $array |
||
| 4742 | * @psalm-return static<TKey,T> |
||
| 4743 | * @psalm-mutation-free |
||
| 4744 | */ |
||
| 4745 | 2 | public function replaceAllValues(array $array): self |
|
| 4753 | |||
| 4754 | /** |
||
| 4755 | * Replace the keys in an array with another set. |
||
| 4756 | * |
||
| 4757 | * @param array $keys <p>An array of keys matching the array's size</p> |
||
| 4758 | * |
||
| 4759 | * @return static |
||
| 4760 | * <p>(Immutable)</p> |
||
| 4761 | * |
||
| 4762 | * @psalm-param array<mixed,mixed>|array<mixed,TKey> $keys |
||
| 4763 | * @psalm-return static<TKey,T> |
||
| 4764 | * @psalm-mutation-free |
||
| 4765 | */ |
||
| 4766 | 1 | public function replaceKeys(array $keys): self |
|
| 4777 | |||
| 4778 | /** |
||
| 4779 | * Replace the first matched value in an array. |
||
| 4780 | * |
||
| 4781 | * @param mixed $search <p>The value to replace.</p> |
||
| 4782 | * @param mixed $replacement <p>The value to replace.</p> |
||
| 4783 | * |
||
| 4784 | * @return static |
||
| 4785 | * <p>(Immutable)</p> |
||
| 4786 | * |
||
| 4787 | * @psalm-return static<TKey,T> |
||
| 4788 | * @psalm-mutation-free |
||
| 4789 | */ |
||
| 4790 | 3 | public function replaceOneValue($search, $replacement = ''): self |
|
| 4805 | |||
| 4806 | /** |
||
| 4807 | * Replace values in the current array. |
||
| 4808 | * |
||
| 4809 | * @param mixed $search <p>The value to replace.</p> |
||
| 4810 | * @param mixed $replacement <p>What to replace it with.</p> |
||
| 4811 | * |
||
| 4812 | * @return static |
||
| 4813 | * <p>(Immutable)</p> |
||
| 4814 | * |
||
| 4815 | * @psalm-return static<TKey,T> |
||
| 4816 | * @psalm-mutation-free |
||
| 4817 | */ |
||
| 4818 | 1 | public function replaceValues($search, $replacement = ''): self |
|
| 4830 | |||
| 4831 | /** |
||
| 4832 | * Get the last elements from index $from until the end of this array. |
||
| 4833 | * |
||
| 4834 | * @param int $from |
||
| 4835 | * |
||
| 4836 | * @return static |
||
| 4837 | * <p>(Immutable)</p> |
||
| 4838 | * |
||
| 4839 | * @psalm-return static<TKey,T> |
||
| 4840 | * @psalm-mutation-free |
||
| 4841 | */ |
||
| 4842 | 15 | View Code Duplication | public function rest(int $from = 1): self |
| 4852 | |||
| 4853 | /** |
||
| 4854 | * Return the array in the reverse order. |
||
| 4855 | * |
||
| 4856 | * @return $this |
||
| 4857 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 4858 | * |
||
| 4859 | * @psalm-return static<TKey,T> |
||
| 4860 | */ |
||
| 4861 | 9 | public function reverse(): self |
|
| 4869 | |||
| 4870 | /** |
||
| 4871 | * Sort an array in reverse order. |
||
| 4872 | * |
||
| 4873 | * @param int $sort_flags [optional] <p> |
||
| 4874 | * You may modify the behavior of the sort using the optional |
||
| 4875 | * parameter sort_flags, for details |
||
| 4876 | * see sort. |
||
| 4877 | * </p> |
||
| 4878 | * |
||
| 4879 | * @return $this |
||
| 4880 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 4881 | * |
||
| 4882 | * @psalm-return static<TKey,T> |
||
| 4883 | */ |
||
| 4884 | 4 | public function rsort(int $sort_flags = 0): self |
|
| 4892 | |||
| 4893 | /** |
||
| 4894 | * Sort an array in reverse order. |
||
| 4895 | * |
||
| 4896 | * @param int $sort_flags [optional] <p> |
||
| 4897 | * You may modify the behavior of the sort using the optional |
||
| 4898 | * parameter sort_flags, for details |
||
| 4899 | * see sort. |
||
| 4900 | * </p> |
||
| 4901 | * |
||
| 4902 | * @return $this |
||
| 4903 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 4904 | * |
||
| 4905 | * @psalm-return static<TKey,T> |
||
| 4906 | * @psalm-mutation-free |
||
| 4907 | */ |
||
| 4908 | 4 | public function rsortImmutable(int $sort_flags = 0): self |
|
| 4919 | |||
| 4920 | /** |
||
| 4921 | * Search for the first index of the current array via $value. |
||
| 4922 | * |
||
| 4923 | * @param mixed $value |
||
| 4924 | * |
||
| 4925 | * @return false|float|int|string |
||
| 4926 | * <p>Will return <b>FALSE</b> if the value can't be found.</p> |
||
| 4927 | * @psalm-mutation-free |
||
| 4928 | */ |
||
| 4929 | 21 | public function searchIndex($value) |
|
| 4939 | |||
| 4940 | /** |
||
| 4941 | * Search for the value of the current array via $index. |
||
| 4942 | * |
||
| 4943 | * @param mixed $index |
||
| 4944 | * |
||
| 4945 | * @return static |
||
| 4946 | * <p>(Immutable) Will return a empty Arrayy if the value wasn't found.</p> |
||
| 4947 | * |
||
| 4948 | * @psalm-return static<TKey,T> |
||
| 4949 | * @psalm-mutation-free |
||
| 4950 | */ |
||
| 4951 | 9 | public function searchValue($index): self |
|
| 4981 | |||
| 4982 | /** |
||
| 4983 | * Set a value for the current array (optional using dot-notation). |
||
| 4984 | * |
||
| 4985 | * @param string $key <p>The key to set.</p> |
||
| 4986 | * @param mixed $value <p>Its value.</p> |
||
| 4987 | * |
||
| 4988 | * @return $this |
||
| 4989 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 4990 | * |
||
| 4991 | * @psalm-param TKey $key |
||
| 4992 | * @psalm-param T $value |
||
| 4993 | * @psalm-return static<TKey,T> |
||
| 4994 | */ |
||
| 4995 | 28 | public function set($key, $value): self |
|
| 5001 | |||
| 5002 | /** |
||
| 5003 | * Get a value from a array and set it if it was not. |
||
| 5004 | * |
||
| 5005 | * WARNING: this method only set the value, if the $key is not already set |
||
| 5006 | * |
||
| 5007 | * @param mixed $key <p>The key</p> |
||
| 5008 | * @param mixed $fallback <p>The default value to set if it isn't.</p> |
||
| 5009 | * |
||
| 5010 | * @return mixed |
||
| 5011 | * <p>(Mutable)</p> |
||
| 5012 | */ |
||
| 5013 | 11 | public function setAndGet($key, $fallback = null) |
|
| 5024 | |||
| 5025 | /** |
||
| 5026 | * Shifts a specified value off the beginning of array. |
||
| 5027 | * |
||
| 5028 | * @return mixed |
||
| 5029 | * <p>(Mutable) A shifted element from the current array.</p> |
||
| 5030 | */ |
||
| 5031 | 5 | public function shift() |
|
| 5037 | |||
| 5038 | /** |
||
| 5039 | * Shuffle the current array. |
||
| 5040 | * |
||
| 5041 | * @param bool $secure <p>using a CSPRNG | @link https://paragonie.com/b/JvICXzh_jhLyt4y3</p> |
||
| 5042 | * @param array $array [optional] |
||
| 5043 | * |
||
| 5044 | * @return static |
||
| 5045 | * <p>(Immutable)</p> |
||
| 5046 | * |
||
| 5047 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 5048 | * @psalm-return static<TKey,T> |
||
| 5049 | * |
||
| 5050 | * @noinspection BadExceptionsProcessingInspection |
||
| 5051 | * @noinspection RandomApiMigrationInspection |
||
| 5052 | * @noinspection NonSecureShuffleUsageInspection |
||
| 5053 | */ |
||
| 5054 | 2 | public function shuffle(bool $secure = false, array $array = null): self |
|
| 5092 | |||
| 5093 | /** |
||
| 5094 | * Count the values from the current array. |
||
| 5095 | * |
||
| 5096 | * alias: for "Arrayy->count()" |
||
| 5097 | * |
||
| 5098 | * @param int $mode |
||
| 5099 | * |
||
| 5100 | * @return int |
||
| 5101 | */ |
||
| 5102 | 20 | public function size(int $mode = \COUNT_NORMAL): int |
|
| 5106 | |||
| 5107 | /** |
||
| 5108 | * Checks whether array has exactly $size items. |
||
| 5109 | * |
||
| 5110 | * @param int $size |
||
| 5111 | * |
||
| 5112 | * @return bool |
||
| 5113 | */ |
||
| 5114 | 1 | View Code Duplication | public function sizeIs(int $size): bool |
| 5128 | |||
| 5129 | /** |
||
| 5130 | * Checks whether array has between $fromSize to $toSize items. $toSize can be |
||
| 5131 | * smaller than $fromSize. |
||
| 5132 | * |
||
| 5133 | * @param int $fromSize |
||
| 5134 | * @param int $toSize |
||
| 5135 | * |
||
| 5136 | * @return bool |
||
| 5137 | */ |
||
| 5138 | 1 | public function sizeIsBetween(int $fromSize, int $toSize): bool |
|
| 5158 | |||
| 5159 | /** |
||
| 5160 | * Checks whether array has more than $size items. |
||
| 5161 | * |
||
| 5162 | * @param int $size |
||
| 5163 | * |
||
| 5164 | * @return bool |
||
| 5165 | */ |
||
| 5166 | 1 | View Code Duplication | public function sizeIsGreaterThan(int $size): bool |
| 5180 | |||
| 5181 | /** |
||
| 5182 | * Checks whether array has less than $size items. |
||
| 5183 | * |
||
| 5184 | * @param int $size |
||
| 5185 | * |
||
| 5186 | * @return bool |
||
| 5187 | */ |
||
| 5188 | 1 | View Code Duplication | public function sizeIsLessThan(int $size): bool |
| 5202 | |||
| 5203 | /** |
||
| 5204 | * Counts all elements in an array, or something in an object. |
||
| 5205 | * |
||
| 5206 | * <p> |
||
| 5207 | * For objects, if you have SPL installed, you can hook into count() by implementing interface {@see Countable}. |
||
| 5208 | * The interface has exactly one method, {@see Countable::count()}, which returns the return value for the count() |
||
| 5209 | * function. Please see the {@see Array} section of the manual for a detailed explanation of how arrays are |
||
| 5210 | * implemented and used in PHP. |
||
| 5211 | * </p> |
||
| 5212 | * |
||
| 5213 | * @return int |
||
| 5214 | * <p> |
||
| 5215 | * The number of elements in var, which is |
||
| 5216 | * typically an array, since anything else will have one |
||
| 5217 | * element. |
||
| 5218 | * </p> |
||
| 5219 | * <p> |
||
| 5220 | * If var is not an array or an object with |
||
| 5221 | * implemented Countable interface, |
||
| 5222 | * 1 will be returned. |
||
| 5223 | * There is one exception, if var is &null;, |
||
| 5224 | * 0 will be returned. |
||
| 5225 | * </p> |
||
| 5226 | * <p> |
||
| 5227 | * Caution: count may return 0 for a variable that isn't set, |
||
| 5228 | * but it may also return 0 for a variable that has been initialized with an |
||
| 5229 | * empty array. Use isset to test if a variable is set. |
||
| 5230 | * </p> |
||
| 5231 | */ |
||
| 5232 | 10 | public function sizeRecursive(): int |
|
| 5236 | |||
| 5237 | /** |
||
| 5238 | * Extract a slice of the array. |
||
| 5239 | * |
||
| 5240 | * @param int $offset <p>Slice begin index.</p> |
||
| 5241 | * @param int|null $length <p>Length of the slice.</p> |
||
| 5242 | * @param bool $preserveKeys <p>Whether array keys are preserved or no.</p> |
||
| 5243 | * |
||
| 5244 | * @return static |
||
| 5245 | * <p>(Immutable) A slice of the original array with length $length.</p> |
||
| 5246 | * |
||
| 5247 | * @psalm-return static<TKey,T> |
||
| 5248 | * @psalm-mutation-free |
||
| 5249 | */ |
||
| 5250 | 5 | public function slice(int $offset, int $length = null, bool $preserveKeys = false) |
|
| 5263 | |||
| 5264 | /** |
||
| 5265 | * Sort the current array and optional you can keep the keys. |
||
| 5266 | * |
||
| 5267 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 5268 | * @param int $strategy <p>sort_flags => use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 5269 | * <strong>SORT_NATURAL</strong></p> |
||
| 5270 | * @param bool $keepKeys |
||
| 5271 | * |
||
| 5272 | * @return static |
||
| 5273 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 5274 | * |
||
| 5275 | * @psalm-return static<TKey,T> |
||
| 5276 | */ |
||
| 5277 | 20 | public function sort( |
|
| 5291 | |||
| 5292 | /** |
||
| 5293 | * Sort the current array and optional you can keep the keys. |
||
| 5294 | * |
||
| 5295 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 5296 | * @param int $strategy <p>sort_flags => use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 5297 | * <strong>SORT_NATURAL</strong></p> |
||
| 5298 | * @param bool $keepKeys |
||
| 5299 | * |
||
| 5300 | * @return static |
||
| 5301 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 5302 | * |
||
| 5303 | * @psalm-return static<TKey,T> |
||
| 5304 | */ |
||
| 5305 | 12 | public function sortImmutable( |
|
| 5321 | |||
| 5322 | /** |
||
| 5323 | * Sort the current array by key. |
||
| 5324 | * |
||
| 5325 | * @see http://php.net/manual/en/function.ksort.php |
||
| 5326 | * @see http://php.net/manual/en/function.krsort.php |
||
| 5327 | * |
||
| 5328 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 5329 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 5330 | * <strong>SORT_NATURAL</strong></p> |
||
| 5331 | * |
||
| 5332 | * @return $this |
||
| 5333 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 5334 | * |
||
| 5335 | * @psalm-return static<TKey,T> |
||
| 5336 | */ |
||
| 5337 | 18 | public function sortKeys( |
|
| 5347 | |||
| 5348 | /** |
||
| 5349 | * Sort the current array by key. |
||
| 5350 | * |
||
| 5351 | * @see http://php.net/manual/en/function.ksort.php |
||
| 5352 | * @see http://php.net/manual/en/function.krsort.php |
||
| 5353 | * |
||
| 5354 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 5355 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 5356 | * <strong>SORT_NATURAL</strong></p> |
||
| 5357 | * |
||
| 5358 | * @return $this |
||
| 5359 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 5360 | * |
||
| 5361 | * @psalm-return static<TKey,T> |
||
| 5362 | * @psalm-mutation-free |
||
| 5363 | */ |
||
| 5364 | 8 | public function sortKeysImmutable( |
|
| 5377 | |||
| 5378 | /** |
||
| 5379 | * Sort the current array by value. |
||
| 5380 | * |
||
| 5381 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 5382 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 5383 | * <strong>SORT_NATURAL</strong></p> |
||
| 5384 | * |
||
| 5385 | * @return static |
||
| 5386 | * <p>(Mutable)</p> |
||
| 5387 | * |
||
| 5388 | * @psalm-return static<TKey,T> |
||
| 5389 | */ |
||
| 5390 | 1 | public function sortValueKeepIndex( |
|
| 5396 | |||
| 5397 | /** |
||
| 5398 | * Sort the current array by value. |
||
| 5399 | * |
||
| 5400 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 5401 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 5402 | * <strong>SORT_NATURAL</strong></p> |
||
| 5403 | * |
||
| 5404 | * @return static |
||
| 5405 | * <p>(Mutable)</p> |
||
| 5406 | * |
||
| 5407 | * @psalm-return static<TKey,T> |
||
| 5408 | */ |
||
| 5409 | 1 | public function sortValueNewIndex($direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
| 5413 | |||
| 5414 | /** |
||
| 5415 | * Sort a array by value, by a closure or by a property. |
||
| 5416 | * |
||
| 5417 | * - If the sorter is null, the array is sorted naturally. |
||
| 5418 | * - Associative (string) keys will be maintained, but numeric keys will be re-indexed. |
||
| 5419 | * |
||
| 5420 | * @param callable|string|null $sorter |
||
| 5421 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or |
||
| 5422 | * <strong>SORT_DESC</strong></p> |
||
| 5423 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 5424 | * <strong>SORT_NATURAL</strong></p> |
||
| 5425 | * |
||
| 5426 | * @return static |
||
| 5427 | * <p>(Immutable)</p> |
||
| 5428 | * |
||
| 5429 | * @psalm-return static<TKey,T> |
||
| 5430 | * @psalm-mutation-free |
||
| 5431 | */ |
||
| 5432 | 1 | public function sorter($sorter = null, $direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
| 5473 | |||
| 5474 | /** |
||
| 5475 | * @param int $offset |
||
| 5476 | * @param int|null $length |
||
| 5477 | * @param array $replacement |
||
| 5478 | * |
||
| 5479 | * @return static |
||
| 5480 | * <p>(Immutable)</p> |
||
| 5481 | * |
||
| 5482 | * @psalm-param array<mixed,mixed>|array<mixed,T> $replacement |
||
| 5483 | * @psalm-return static<TKey,T> |
||
| 5484 | * @psalm-mutation-free |
||
| 5485 | */ |
||
| 5486 | 1 | public function splice(int $offset, int $length = null, $replacement = []): self |
|
| 5503 | |||
| 5504 | /** |
||
| 5505 | * Split an array in the given amount of pieces. |
||
| 5506 | * |
||
| 5507 | * @param int $numberOfPieces |
||
| 5508 | * @param bool $keepKeys |
||
| 5509 | * |
||
| 5510 | * @return static |
||
| 5511 | * <p>(Immutable)</p> |
||
| 5512 | * |
||
| 5513 | * @psalm-return static<TKey,T> |
||
| 5514 | * @psalm-mutation-free |
||
| 5515 | */ |
||
| 5516 | 1 | public function split(int $numberOfPieces = 2, bool $keepKeys = false): self |
|
| 5535 | |||
| 5536 | /** |
||
| 5537 | * Stripe all empty items. |
||
| 5538 | * |
||
| 5539 | * @return static |
||
| 5540 | * <p>(Immutable)</p> |
||
| 5541 | * |
||
| 5542 | * @psalm-return static<TKey,T> |
||
| 5543 | * @psalm-mutation-free |
||
| 5544 | */ |
||
| 5545 | 1 | public function stripEmpty(): self |
|
| 5557 | |||
| 5558 | /** |
||
| 5559 | * Swap two values between positions by key. |
||
| 5560 | * |
||
| 5561 | * @param int|string $swapA <p>a key in the array</p> |
||
| 5562 | * @param int|string $swapB <p>a key in the array</p> |
||
| 5563 | * |
||
| 5564 | * @return static |
||
| 5565 | * <p>(Immutable)</p> |
||
| 5566 | * |
||
| 5567 | * @psalm-return static<TKey,T> |
||
| 5568 | * @psalm-mutation-free |
||
| 5569 | */ |
||
| 5570 | 1 | public function swap($swapA, $swapB): self |
|
| 5582 | |||
| 5583 | /** |
||
| 5584 | * Get the current array from the "Arrayy"-object. |
||
| 5585 | * alias for "getArray()" |
||
| 5586 | * |
||
| 5587 | * @param bool $convertAllArrayyElements <p> |
||
| 5588 | * Convert all Child-"Arrayy" objects also to arrays. |
||
| 5589 | * </p> |
||
| 5590 | * @param bool $preserveKeys <p> |
||
| 5591 | * e.g.: A generator maybe return the same key more then once, |
||
| 5592 | * so maybe you will ignore the keys. |
||
| 5593 | * </p> |
||
| 5594 | * |
||
| 5595 | * @return array |
||
| 5596 | * |
||
| 5597 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 5598 | * @psalm-mutation-free |
||
| 5599 | */ |
||
| 5600 | 931 | public function toArray( |
|
| 5625 | |||
| 5626 | /** |
||
| 5627 | * Get the current array from the "Arrayy"-object as list. |
||
| 5628 | * |
||
| 5629 | * @param bool $convertAllArrayyElements <p> |
||
| 5630 | * Convert all Child-"Arrayy" objects also to arrays. |
||
| 5631 | * </p> |
||
| 5632 | * |
||
| 5633 | * @return array |
||
| 5634 | * |
||
| 5635 | * @psalm-return array<int,mixed>|array<int,T> |
||
| 5636 | * @psalm-mutation-free |
||
| 5637 | */ |
||
| 5638 | 1 | public function toList(bool $convertAllArrayyElements = false): array |
|
| 5645 | |||
| 5646 | /** |
||
| 5647 | * Convert the current array to JSON. |
||
| 5648 | * |
||
| 5649 | * @param int $options [optional] <p>e.g. JSON_PRETTY_PRINT</p> |
||
| 5650 | * @param int $depth [optional] <p>Set the maximum depth. Must be greater than zero.</p> |
||
| 5651 | * |
||
| 5652 | * @return string |
||
| 5653 | */ |
||
| 5654 | 11 | public function toJson(int $options = 0, int $depth = 512): string |
|
| 5663 | |||
| 5664 | /** |
||
| 5665 | * @param string[]|null $items [optional] |
||
| 5666 | * @param string[] $helper [optional] |
||
| 5667 | * |
||
| 5668 | * @return static|static[] |
||
| 5669 | * |
||
| 5670 | * @psalm-return static<int, static<TKey,T>> |
||
| 5671 | */ |
||
| 5672 | 1 | public function toPermutation(array $items = null, array $helper = []): self |
|
| 5706 | |||
| 5707 | /** |
||
| 5708 | * Implodes array to a string with specified separator. |
||
| 5709 | * |
||
| 5710 | * @param string $separator [optional] <p>The element's separator.</p> |
||
| 5711 | * |
||
| 5712 | * @return string |
||
| 5713 | * <p>The string representation of array, separated by ",".</p> |
||
| 5714 | */ |
||
| 5715 | 19 | public function toString(string $separator = ','): string |
|
| 5719 | |||
| 5720 | /** |
||
| 5721 | * Return a duplicate free copy of the current array. |
||
| 5722 | * |
||
| 5723 | * @return $this |
||
| 5724 | * <p>(Mutable)</p> |
||
| 5725 | * |
||
| 5726 | * @psalm-return static<TKey,T> |
||
| 5727 | */ |
||
| 5728 | 13 | public function unique(): self |
|
| 5750 | |||
| 5751 | /** |
||
| 5752 | * Return a duplicate free copy of the current array. (with the old keys) |
||
| 5753 | * |
||
| 5754 | * @return $this |
||
| 5755 | * <p>(Mutable)</p> |
||
| 5756 | * |
||
| 5757 | * @psalm-return static<TKey,T> |
||
| 5758 | */ |
||
| 5759 | 11 | public function uniqueKeepIndex(): self |
|
| 5785 | |||
| 5786 | /** |
||
| 5787 | * alias: for "Arrayy->unique()" |
||
| 5788 | * |
||
| 5789 | * @return static |
||
| 5790 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
| 5791 | * |
||
| 5792 | * @see Arrayy::unique() |
||
| 5793 | * |
||
| 5794 | * @psalm-return static<TKey,T> |
||
| 5795 | */ |
||
| 5796 | 10 | public function uniqueNewIndex(): self |
|
| 5800 | |||
| 5801 | /** |
||
| 5802 | * Prepends one or more values to the beginning of array at once. |
||
| 5803 | * |
||
| 5804 | * @param array ...$args |
||
| 5805 | * |
||
| 5806 | * @return $this |
||
| 5807 | * <p>(Mutable) Return this Arrayy object, with prepended elements to the beginning of array.</p> |
||
| 5808 | * |
||
| 5809 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$args |
||
| 5810 | * @psalm-return static<TKey,T> |
||
| 5811 | */ |
||
| 5812 | 4 | public function unshift(...$args): self |
|
| 5820 | |||
| 5821 | /** |
||
| 5822 | * Tests whether the given closure return something valid for all elements of this array. |
||
| 5823 | * |
||
| 5824 | * @param \Closure $closure the predicate |
||
| 5825 | * |
||
| 5826 | * @return bool |
||
| 5827 | * <p>TRUE, if the predicate yields TRUE for all elements, FALSE otherwise.</p> |
||
| 5828 | */ |
||
| 5829 | 1 | View Code Duplication | public function validate(\Closure $closure): bool |
| 5839 | |||
| 5840 | /** |
||
| 5841 | * Get all values from a array. |
||
| 5842 | * |
||
| 5843 | * @return static |
||
| 5844 | * <p>(Immutable)</p> |
||
| 5845 | * |
||
| 5846 | * @psalm-return static<TKey,T> |
||
| 5847 | * @psalm-mutation-free |
||
| 5848 | */ |
||
| 5849 | 2 | public function values(): self |
|
| 5862 | |||
| 5863 | /** |
||
| 5864 | * Apply the given function to every element in the array, discarding the results. |
||
| 5865 | * |
||
| 5866 | * @param callable $callable |
||
| 5867 | * @param bool $recursive <p>Whether array will be walked recursively or no</p> |
||
| 5868 | * |
||
| 5869 | * @return $this |
||
| 5870 | * <p>(Mutable) Return this Arrayy object, with modified elements.</p> |
||
| 5871 | * |
||
| 5872 | * @psalm-return static<TKey,T> |
||
| 5873 | */ |
||
| 5874 | 12 | public function walk($callable, bool $recursive = false): self |
|
| 5888 | |||
| 5889 | /** |
||
| 5890 | * Returns a collection of matching items. |
||
| 5891 | * |
||
| 5892 | * @param string $keyOrPropertyOrMethod the property or method to evaluate |
||
| 5893 | * @param mixed $value the value to match |
||
| 5894 | * |
||
| 5895 | * @throws \InvalidArgumentException if property or method is not defined |
||
| 5896 | * |
||
| 5897 | * @return static |
||
| 5898 | * |
||
| 5899 | * @psalm-param T $value |
||
| 5900 | * @psalm-return static<TKey,T> |
||
| 5901 | */ |
||
| 5902 | 1 | public function where(string $keyOrPropertyOrMethod, $value): self |
|
| 5915 | |||
| 5916 | /** |
||
| 5917 | * Convert an array into a object. |
||
| 5918 | * |
||
| 5919 | * @param array $array |
||
| 5920 | * |
||
| 5921 | * @return \stdClass |
||
| 5922 | * |
||
| 5923 | * @psalm-param array<mixed,mixed> $array |
||
| 5924 | */ |
||
| 5925 | 4 | final protected static function arrayToObject(array $array = []): \stdClass |
|
| 5944 | |||
| 5945 | /** |
||
| 5946 | * @param array|\Generator|null $input <p> |
||
| 5947 | * An array containing keys to return. |
||
| 5948 | * </p> |
||
| 5949 | * @param mixed|null $search_values [optional] <p> |
||
| 5950 | * If specified, then only keys containing these values are returned. |
||
| 5951 | * </p> |
||
| 5952 | * @param bool $strict [optional] <p> |
||
| 5953 | * Determines if strict comparison (===) should be used during the |
||
| 5954 | * search. |
||
| 5955 | * </p> |
||
| 5956 | * |
||
| 5957 | * @return array |
||
| 5958 | * <p>an array of all the keys in input</p> |
||
| 5959 | * |
||
| 5960 | * @psalm-param array<mixed,mixed>|\Generator<TKey,T>|null $input |
||
| 5961 | * @psalm-return array<TKey|mixed> |
||
| 5962 | * @psalm-mutation-free |
||
| 5963 | */ |
||
| 5964 | 11 | protected function array_keys_recursive( |
|
| 6025 | |||
| 6026 | /** |
||
| 6027 | * @param mixed $path |
||
| 6028 | * @param callable $callable |
||
| 6029 | * @param array|null $currentOffset |
||
| 6030 | * |
||
| 6031 | * @return void |
||
| 6032 | * |
||
| 6033 | * @psalm-param array<mixed,mixed>|array<TKey,T>|null $currentOffset |
||
| 6034 | * @psalm-mutation-free |
||
| 6035 | */ |
||
| 6036 | 11 | protected function callAtPath($path, $callable, &$currentOffset = null) |
|
| 6065 | |||
| 6066 | /** |
||
| 6067 | * Extracts the value of the given property or method from the object. |
||
| 6068 | * |
||
| 6069 | * @param static $object <p>The object to extract the value from.</p> |
||
| 6070 | * @param string $keyOrPropertyOrMethod <p>The property or method for which the |
||
| 6071 | * value should be extracted.</p> |
||
| 6072 | * |
||
| 6073 | * @throws \InvalidArgumentException if the method or property is not defined |
||
| 6074 | * |
||
| 6075 | * @return mixed |
||
| 6076 | * <p>The value extracted from the specified property or method.</p> |
||
| 6077 | * |
||
| 6078 | * @psalm-param self<TKey,T> $object |
||
| 6079 | */ |
||
| 6080 | 2 | final protected function extractValue(self $object, string $keyOrPropertyOrMethod) |
|
| 6102 | |||
| 6103 | /** |
||
| 6104 | * create a fallback for array |
||
| 6105 | * |
||
| 6106 | * 1. use the current array, if it's a array |
||
| 6107 | * 2. fallback to empty array, if there is nothing |
||
| 6108 | * 3. call "getArray()" on object, if there is a "Arrayy"-object |
||
| 6109 | * 4. call "createFromObject()" on object, if there is a "\Traversable"-object |
||
| 6110 | * 5. call "__toArray()" on object, if the method exists |
||
| 6111 | * 6. cast a string or object with "__toString()" into an array |
||
| 6112 | * 7. throw a "InvalidArgumentException"-Exception |
||
| 6113 | * |
||
| 6114 | * @param mixed $data |
||
| 6115 | * |
||
| 6116 | * @throws \InvalidArgumentException |
||
| 6117 | * |
||
| 6118 | * @return array |
||
| 6119 | * |
||
| 6120 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 6121 | */ |
||
| 6122 | 1173 | protected function fallbackForArray(&$data): array |
|
| 6132 | |||
| 6133 | /** |
||
| 6134 | * @param bool $preserveKeys <p> |
||
| 6135 | * e.g.: A generator maybe return the same key more then once, |
||
| 6136 | * so maybe you will ignore the keys. |
||
| 6137 | * </p> |
||
| 6138 | * |
||
| 6139 | * @return bool |
||
| 6140 | * |
||
| 6141 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
| 6142 | * @psalm-mutation-free :/ |
||
| 6143 | */ |
||
| 6144 | 1085 | protected function generatorToArray(bool $preserveKeys = true) |
|
| 6155 | |||
| 6156 | /** |
||
| 6157 | * Get correct PHP constant for direction. |
||
| 6158 | * |
||
| 6159 | * @param int|string $direction |
||
| 6160 | * |
||
| 6161 | * @return int |
||
| 6162 | * @psalm-mutation-free |
||
| 6163 | */ |
||
| 6164 | 43 | protected function getDirection($direction): int |
|
| 6186 | |||
| 6187 | /** |
||
| 6188 | * @return TypeCheckPhpDoc[] |
||
| 6189 | * |
||
| 6190 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
| 6191 | */ |
||
| 6192 | 16 | protected function getPropertiesFromPhpDoc() |
|
| 6217 | |||
| 6218 | /** |
||
| 6219 | * @param mixed $glue |
||
| 6220 | * @param mixed $pieces |
||
| 6221 | * @param bool $useKeys |
||
| 6222 | * |
||
| 6223 | * @return string |
||
| 6224 | * @psalm-mutation-free |
||
| 6225 | */ |
||
| 6226 | 36 | protected function implode_recursive( |
|
| 6259 | |||
| 6260 | /** |
||
| 6261 | * @param mixed $needle <p> |
||
| 6262 | * The searched value. |
||
| 6263 | * </p> |
||
| 6264 | * <p> |
||
| 6265 | * If needle is a string, the comparison is done |
||
| 6266 | * in a case-sensitive manner. |
||
| 6267 | * </p> |
||
| 6268 | * @param array|\Generator|null $haystack <p> |
||
| 6269 | * The array. |
||
| 6270 | * </p> |
||
| 6271 | * @param bool $strict [optional] <p> |
||
| 6272 | * If the third parameter strict is set to true |
||
| 6273 | * then the in_array function will also check the |
||
| 6274 | * types of the |
||
| 6275 | * needle in the haystack. |
||
| 6276 | * </p> |
||
| 6277 | * |
||
| 6278 | * @return bool |
||
| 6279 | * <p>true if needle is found in the array, false otherwise</p> |
||
| 6280 | * |
||
| 6281 | * @psalm-param array<mixed,mixed>|\Generator<TKey,T>|null $haystack |
||
| 6282 | * @psalm-mutation-free |
||
| 6283 | */ |
||
| 6284 | 18 | protected function in_array_recursive($needle, $haystack = null, $strict = true): bool |
|
| 6309 | |||
| 6310 | /** |
||
| 6311 | * @param mixed $data |
||
| 6312 | * |
||
| 6313 | * @return array|null |
||
| 6314 | * |
||
| 6315 | * @psalm-return array<mixed,mixed>|array<TKey,T>|null |
||
| 6316 | */ |
||
| 6317 | 1173 | protected function internalGetArray(&$data) |
|
| 6368 | |||
| 6369 | /** |
||
| 6370 | * Internal mechanics of remove method. |
||
| 6371 | * |
||
| 6372 | * @param mixed $key |
||
| 6373 | * |
||
| 6374 | * @return bool |
||
| 6375 | */ |
||
| 6376 | 21 | protected function internalRemove($key): bool |
|
| 6409 | |||
| 6410 | /** |
||
| 6411 | * Internal mechanic of set method. |
||
| 6412 | * |
||
| 6413 | * @param int|string|null $key |
||
| 6414 | * @param mixed $value |
||
| 6415 | * @param bool $checkProperties |
||
| 6416 | * |
||
| 6417 | * @return bool |
||
| 6418 | */ |
||
| 6419 | 1024 | protected function internalSet( |
|
| 6478 | |||
| 6479 | /** |
||
| 6480 | * Convert a object into an array. |
||
| 6481 | * |
||
| 6482 | * @param mixed|object $object |
||
| 6483 | * |
||
| 6484 | * @return array|mixed |
||
| 6485 | * |
||
| 6486 | * @psalm-mutation-free |
||
| 6487 | */ |
||
| 6488 | 5 | protected static function objectToArray($object) |
|
| 6501 | |||
| 6502 | /** |
||
| 6503 | * @param array $data |
||
| 6504 | * @param bool $checkPropertiesInConstructor |
||
| 6505 | * |
||
| 6506 | * @return void |
||
| 6507 | * |
||
| 6508 | * @psalm-param array<mixed,T> $data |
||
| 6509 | */ |
||
| 6510 | 1171 | protected function setInitialValuesAndProperties(array &$data, bool $checkPropertiesInConstructor) |
|
| 6555 | |||
| 6556 | /** |
||
| 6557 | * sorting keys |
||
| 6558 | * |
||
| 6559 | * @param array $elements |
||
| 6560 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 6561 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 6562 | * <strong>SORT_NATURAL</strong></p> |
||
| 6563 | * |
||
| 6564 | * @return $this |
||
| 6565 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 6566 | * |
||
| 6567 | * @psalm-param array<mixed,mixed>|array<mixed|TKey,T> $elements |
||
| 6568 | * @psalm-return static<TKey,T> |
||
| 6569 | */ |
||
| 6570 | 18 | protected function sorterKeys( |
|
| 6591 | |||
| 6592 | /** |
||
| 6593 | * @param array $elements <p>Warning: used as reference</p> |
||
| 6594 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 6595 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 6596 | * <strong>SORT_NATURAL</strong></p> |
||
| 6597 | * @param bool $keepKeys |
||
| 6598 | * |
||
| 6599 | * @return $this |
||
| 6600 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 6601 | * |
||
| 6602 | * @psalm-param array<mixed,mixed>|array<mixed|TKey,T> $elements |
||
| 6603 | * @psalm-return static<TKey,T> |
||
| 6604 | */ |
||
| 6605 | 24 | protected function sorting(array &$elements, $direction = \SORT_ASC, int $strategy = \SORT_REGULAR, bool $keepKeys = false): self |
|
| 6635 | |||
| 6636 | /** |
||
| 6637 | * @param array $array |
||
| 6638 | * |
||
| 6639 | * @return array |
||
| 6640 | * |
||
| 6641 | * @psalm-mutation-free |
||
| 6642 | */ |
||
| 6643 | 25 | private function getArrayRecursiveHelperArrayy(array $array) |
|
| 6665 | |||
| 6666 | /** |
||
| 6667 | * @param int|string|null $key |
||
| 6668 | * @param mixed $value |
||
| 6669 | * |
||
| 6670 | * @return void |
||
| 6671 | */ |
||
| 6672 | 87 | private function checkType($key, $value) |
|
| 6690 | } |
||
| 6691 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..