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>|mixed|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 | 1185 | 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) |
|
| 247 | |||
| 248 | /** |
||
| 249 | * Append a (key) + value to the current array. |
||
| 250 | * |
||
| 251 | * @param mixed $value |
||
| 252 | * @param mixed $key |
||
| 253 | * |
||
| 254 | * @return $this |
||
| 255 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
| 256 | * |
||
| 257 | * @psalm-return static<TKey,T> |
||
| 258 | */ |
||
| 259 | 17 | public function append($value, $key = null): self |
|
| 283 | |||
| 284 | /** |
||
| 285 | * Sort the entries by value. |
||
| 286 | * |
||
| 287 | * @param int $sort_flags [optional] <p> |
||
| 288 | * You may modify the behavior of the sort using the optional |
||
| 289 | * parameter sort_flags, for details |
||
| 290 | * see sort. |
||
| 291 | * </p> |
||
| 292 | * |
||
| 293 | * @return $this |
||
| 294 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 295 | * |
||
| 296 | * @psalm-return static<TKey,T> |
||
| 297 | */ |
||
| 298 | 4 | public function asort(int $sort_flags = 0): self |
|
| 306 | |||
| 307 | /** |
||
| 308 | * Sort the entries by value. |
||
| 309 | * |
||
| 310 | * @param int $sort_flags [optional] <p> |
||
| 311 | * You may modify the behavior of the sort using the optional |
||
| 312 | * parameter sort_flags, for details |
||
| 313 | * see sort. |
||
| 314 | * </p> |
||
| 315 | * |
||
| 316 | * @return $this |
||
| 317 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 318 | * |
||
| 319 | * @psalm-return static<TKey,T> |
||
| 320 | * @psalm-mutation-free |
||
| 321 | */ |
||
| 322 | 4 | public function asortImmutable(int $sort_flags = 0): self |
|
| 333 | |||
| 334 | /** |
||
| 335 | * Counts all elements in an array, or something in an object. |
||
| 336 | * |
||
| 337 | * <p> |
||
| 338 | * For objects, if you have SPL installed, you can hook into count() by implementing interface {@see Countable}. |
||
| 339 | * The interface has exactly one method, {@see Countable::count()}, which returns the return value for the count() |
||
| 340 | * function. Please see the {@see Array} section of the manual for a detailed explanation of how arrays are |
||
| 341 | * implemented and used in PHP. |
||
| 342 | * </p> |
||
| 343 | * |
||
| 344 | * @see http://php.net/manual/en/function.count.php |
||
| 345 | * |
||
| 346 | * @param int $mode [optional] If the optional mode parameter is set to |
||
| 347 | * COUNT_RECURSIVE (or 1), count |
||
| 348 | * will recursively count the array. This is particularly useful for |
||
| 349 | * counting all the elements of a multidimensional array. count does not detect infinite recursion. |
||
| 350 | * |
||
| 351 | * @return int |
||
| 352 | * <p> |
||
| 353 | * The number of elements in var, which is |
||
| 354 | * typically an array, since anything else will have one |
||
| 355 | * element. |
||
| 356 | * </p> |
||
| 357 | * <p> |
||
| 358 | * If var is not an array or an object with |
||
| 359 | * implemented Countable interface, |
||
| 360 | * 1 will be returned. |
||
| 361 | * There is one exception, if var is &null;, |
||
| 362 | * 0 will be returned. |
||
| 363 | * </p> |
||
| 364 | * <p> |
||
| 365 | * Caution: count may return 0 for a variable that isn't set, |
||
| 366 | * but it may also return 0 for a variable that has been initialized with an |
||
| 367 | * empty array. Use isset to test if a variable is set. |
||
| 368 | * </p> |
||
| 369 | * @psalm-mutation-free |
||
| 370 | */ |
||
| 371 | 147 | public function count(int $mode = \COUNT_NORMAL): int |
|
| 383 | |||
| 384 | /** |
||
| 385 | * Exchange the array for another one. |
||
| 386 | * |
||
| 387 | * @param array|static $data |
||
| 388 | * |
||
| 389 | * @return array |
||
| 390 | * |
||
| 391 | * @psalm-param array<TKey,T>|self<TKey,T> $data |
||
| 392 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 393 | */ |
||
| 394 | 1 | public function exchangeArray($data): array |
|
| 400 | |||
| 401 | /** |
||
| 402 | * Creates a copy of the ArrayyObject. |
||
| 403 | * |
||
| 404 | * @return array |
||
| 405 | * |
||
| 406 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 407 | */ |
||
| 408 | 6 | public function getArrayCopy(): array |
|
| 414 | |||
| 415 | /** |
||
| 416 | * Returns a new iterator, thus implementing the \Iterator interface. |
||
| 417 | * |
||
| 418 | * @return \Iterator<mixed, mixed> |
||
| 419 | * <p>An iterator for the values in the array.</p> |
||
| 420 | * @psalm-return \Iterator<array-key|TKey, mixed|T> |
||
| 421 | */ |
||
| 422 | 26 | public function getIterator(): \Iterator |
|
| 439 | |||
| 440 | /** |
||
| 441 | * Gets the iterator classname for the ArrayObject. |
||
| 442 | * |
||
| 443 | * @return string |
||
| 444 | * |
||
| 445 | * @psalm-return class-string |
||
| 446 | */ |
||
| 447 | 25 | public function getIteratorClass(): string |
|
| 451 | |||
| 452 | /** |
||
| 453 | * Sort the entries by key. |
||
| 454 | * |
||
| 455 | * @param int $sort_flags [optional] <p> |
||
| 456 | * You may modify the behavior of the sort using the optional |
||
| 457 | * parameter sort_flags, for details |
||
| 458 | * see sort. |
||
| 459 | * </p> |
||
| 460 | * |
||
| 461 | * @return $this |
||
| 462 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 463 | * |
||
| 464 | * @psalm-return static<TKey,T> |
||
| 465 | */ |
||
| 466 | 4 | public function ksort(int $sort_flags = 0): self |
|
| 474 | |||
| 475 | /** |
||
| 476 | * Sort the entries by key. |
||
| 477 | * |
||
| 478 | * @param int $sort_flags [optional] <p> |
||
| 479 | * You may modify the behavior of the sort using the optional |
||
| 480 | * parameter sort_flags, for details |
||
| 481 | * see sort. |
||
| 482 | * </p> |
||
| 483 | * |
||
| 484 | * @return $this |
||
| 485 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 486 | * |
||
| 487 | * @psalm-return static<TKey,T> |
||
| 488 | */ |
||
| 489 | 4 | public function ksortImmutable(int $sort_flags = 0): self |
|
| 500 | |||
| 501 | /** |
||
| 502 | * Sort an array using a case insensitive "natural order" algorithm. |
||
| 503 | * |
||
| 504 | * @return $this |
||
| 505 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 506 | * |
||
| 507 | * @psalm-return static<TKey,T> |
||
| 508 | */ |
||
| 509 | 8 | public function natcasesort(): self |
|
| 517 | |||
| 518 | /** |
||
| 519 | * Sort an array using a case insensitive "natural order" algorithm. |
||
| 520 | * |
||
| 521 | * @return $this |
||
| 522 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 523 | * |
||
| 524 | * @psalm-return static<TKey,T> |
||
| 525 | * @psalm-mutation-free |
||
| 526 | */ |
||
| 527 | 4 | public function natcasesortImmutable(): self |
|
| 538 | |||
| 539 | /** |
||
| 540 | * Sort entries using a "natural order" algorithm. |
||
| 541 | * |
||
| 542 | * @return $this |
||
| 543 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 544 | * |
||
| 545 | * @psalm-return static<TKey,T> |
||
| 546 | */ |
||
| 547 | 9 | public function natsort(): self |
|
| 555 | |||
| 556 | /** |
||
| 557 | * Sort entries using a "natural order" algorithm. |
||
| 558 | * |
||
| 559 | * @return $this |
||
| 560 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 561 | * |
||
| 562 | * @psalm-return static<TKey,T> |
||
| 563 | * @psalm-mutation-free |
||
| 564 | */ |
||
| 565 | 4 | public function natsortImmutable(): self |
|
| 576 | |||
| 577 | /** |
||
| 578 | * Whether or not an offset exists. |
||
| 579 | * |
||
| 580 | * @param bool|int|string $offset |
||
| 581 | * |
||
| 582 | * @return bool |
||
| 583 | * |
||
| 584 | * @noinspection PhpSillyAssignmentInspection |
||
| 585 | * |
||
| 586 | * @psalm-mutation-free |
||
| 587 | */ |
||
| 588 | 149 | public function offsetExists($offset): bool |
|
| 650 | |||
| 651 | /** |
||
| 652 | * Returns the value at specified offset. |
||
| 653 | * |
||
| 654 | * @param int|string $offset |
||
| 655 | * |
||
| 656 | * @return mixed |
||
| 657 | * <p>Will return null if the offset did not exists.</p> |
||
| 658 | */ |
||
| 659 | 118 | public function offsetGet($offset) |
|
| 663 | |||
| 664 | /** |
||
| 665 | * Assigns a value to the specified offset + check the type. |
||
| 666 | * |
||
| 667 | * @param int|string|null $offset |
||
| 668 | * @param mixed $value |
||
| 669 | * |
||
| 670 | * @return void |
||
| 671 | */ |
||
| 672 | 20 | public function offsetSet($offset, $value) |
|
| 690 | |||
| 691 | /** |
||
| 692 | * Unset an offset. |
||
| 693 | * |
||
| 694 | * @param int|string $offset |
||
| 695 | * |
||
| 696 | * @return void |
||
| 697 | * <p>(Mutable) Return nothing.</p> |
||
| 698 | */ |
||
| 699 | 25 | public function offsetUnset($offset) |
|
| 750 | |||
| 751 | /** |
||
| 752 | * Serialize the current "Arrayy"-object. |
||
| 753 | * |
||
| 754 | * @return string |
||
| 755 | */ |
||
| 756 | 2 | public function serialize(): string |
|
| 766 | |||
| 767 | /** |
||
| 768 | * Sets the iterator classname for the current "Arrayy"-object. |
||
| 769 | * |
||
| 770 | * @param string $iteratorClass |
||
| 771 | * |
||
| 772 | * @throws \InvalidArgumentException |
||
| 773 | * |
||
| 774 | * @return void |
||
| 775 | * |
||
| 776 | * @psalm-param class-string<\Arrayy\ArrayyIterator> $iteratorClass |
||
| 777 | */ |
||
| 778 | 1176 | public function setIteratorClass($iteratorClass) |
|
| 800 | |||
| 801 | /** |
||
| 802 | * Sort the entries with a user-defined comparison function and maintain key association. |
||
| 803 | * |
||
| 804 | * @param callable $function |
||
| 805 | * |
||
| 806 | * @throws \InvalidArgumentException |
||
| 807 | * |
||
| 808 | * @return $this |
||
| 809 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 810 | * |
||
| 811 | * @psalm-return static<TKey,T> |
||
| 812 | */ |
||
| 813 | 8 | View Code Duplication | public function uasort($function): self |
| 825 | |||
| 826 | /** |
||
| 827 | * Sort the entries with a user-defined comparison function and maintain key association. |
||
| 828 | * |
||
| 829 | * @param callable $function |
||
| 830 | * |
||
| 831 | * @throws \InvalidArgumentException |
||
| 832 | * |
||
| 833 | * @return $this |
||
| 834 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 835 | * |
||
| 836 | * @psalm-return static<TKey,T> |
||
| 837 | * @psalm-mutation-free |
||
| 838 | */ |
||
| 839 | 4 | public function uasortImmutable($function): self |
|
| 850 | |||
| 851 | /** |
||
| 852 | * Sort the entries by keys using a user-defined comparison function. |
||
| 853 | * |
||
| 854 | * @param callable $function |
||
| 855 | * |
||
| 856 | * @throws \InvalidArgumentException |
||
| 857 | * |
||
| 858 | * @return static |
||
| 859 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 860 | * |
||
| 861 | * @psalm-return static<TKey,T> |
||
| 862 | */ |
||
| 863 | 5 | public function uksort($function): self |
|
| 867 | |||
| 868 | /** |
||
| 869 | * Sort the entries by keys using a user-defined comparison function. |
||
| 870 | * |
||
| 871 | * @param callable $function |
||
| 872 | * |
||
| 873 | * @throws \InvalidArgumentException |
||
| 874 | * |
||
| 875 | * @return static |
||
| 876 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 877 | * |
||
| 878 | * @psalm-return static<TKey,T> |
||
| 879 | * @psalm-mutation-free |
||
| 880 | */ |
||
| 881 | 1 | public function uksortImmutable($function): self |
|
| 885 | |||
| 886 | /** |
||
| 887 | * Unserialize an string and return the instance of the "Arrayy"-class. |
||
| 888 | * |
||
| 889 | * @param string $string |
||
| 890 | * |
||
| 891 | * @return $this |
||
| 892 | * |
||
| 893 | * @psalm-return static<TKey,T> |
||
| 894 | */ |
||
| 895 | 2 | public function unserialize($string): self |
|
| 905 | |||
| 906 | /** |
||
| 907 | * Append a (key) + values to the current array. |
||
| 908 | * |
||
| 909 | * @param array $values |
||
| 910 | * @param mixed $key |
||
| 911 | * |
||
| 912 | * @return $this |
||
| 913 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
| 914 | * |
||
| 915 | * @psalm-param array<mixed,T> $values |
||
| 916 | * @psalm-param TKey|null $key |
||
| 917 | * @psalm-return static<TKey,T> |
||
| 918 | */ |
||
| 919 | 1 | public function appendArrayValues(array $values, $key = null) |
|
| 945 | |||
| 946 | /** |
||
| 947 | * Add a suffix to each key. |
||
| 948 | * |
||
| 949 | * @param mixed $prefix |
||
| 950 | * |
||
| 951 | * @return static |
||
| 952 | * <p>(Immutable) Return an Arrayy object, with the prefixed keys.</p> |
||
| 953 | * |
||
| 954 | * @psalm-return static<TKey,T> |
||
| 955 | * @psalm-mutation-free |
||
| 956 | */ |
||
| 957 | 10 | View Code Duplication | public function appendToEachKey($prefix): self |
| 976 | |||
| 977 | /** |
||
| 978 | * Add a prefix to each value. |
||
| 979 | * |
||
| 980 | * @param mixed $prefix |
||
| 981 | * |
||
| 982 | * @return static |
||
| 983 | * <p>(Immutable) Return an Arrayy object, with the prefixed values.</p> |
||
| 984 | * |
||
| 985 | * @psalm-return static<TKey,T> |
||
| 986 | * @psalm-mutation-free |
||
| 987 | */ |
||
| 988 | 10 | View Code Duplication | public function appendToEachValue($prefix): self |
| 1007 | |||
| 1008 | /** |
||
| 1009 | * Sort an array in reverse order and maintain index association. |
||
| 1010 | * |
||
| 1011 | * @return $this |
||
| 1012 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1013 | * |
||
| 1014 | * @psalm-return static<TKey,T> |
||
| 1015 | */ |
||
| 1016 | 4 | public function arsort(): self |
|
| 1024 | |||
| 1025 | /** |
||
| 1026 | * Sort an array in reverse order and maintain index association. |
||
| 1027 | * |
||
| 1028 | * @return $this |
||
| 1029 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 1030 | * |
||
| 1031 | * @psalm-return static<TKey,T> |
||
| 1032 | * @psalm-mutation-free |
||
| 1033 | */ |
||
| 1034 | 10 | public function arsortImmutable(): self |
|
| 1044 | |||
| 1045 | /** |
||
| 1046 | * Iterate over the current array and execute a callback for each loop. |
||
| 1047 | * |
||
| 1048 | * @param \Closure $closure |
||
| 1049 | * |
||
| 1050 | * @return static |
||
| 1051 | * <p>(Immutable)</p> |
||
| 1052 | * |
||
| 1053 | * @psalm-return static<TKey,T> |
||
| 1054 | * @psalm-mutation-free |
||
| 1055 | */ |
||
| 1056 | 2 | public function at(\Closure $closure): self |
|
| 1070 | |||
| 1071 | /** |
||
| 1072 | * Returns the average value of the current array. |
||
| 1073 | * |
||
| 1074 | * @param int $decimals <p>The number of decimal-numbers to return.</p> |
||
| 1075 | * |
||
| 1076 | * @return float|int |
||
| 1077 | * <p>The average value.</p> |
||
| 1078 | * @psalm-mutation-free |
||
| 1079 | */ |
||
| 1080 | 10 | public function average($decimals = 0) |
|
| 1094 | |||
| 1095 | /** |
||
| 1096 | * Changes all keys in an array. |
||
| 1097 | * |
||
| 1098 | * @param int $case [optional] <p> Either <strong>CASE_UPPER</strong><br /> |
||
| 1099 | * or <strong>CASE_LOWER</strong> (default)</p> |
||
| 1100 | * |
||
| 1101 | * @return static |
||
| 1102 | * <p>(Immutable)</p> |
||
| 1103 | * |
||
| 1104 | * @psalm-return static<TKey,T> |
||
| 1105 | * @psalm-mutation-free |
||
| 1106 | */ |
||
| 1107 | 1 | public function changeKeyCase(int $case = \CASE_LOWER): self |
|
| 1136 | |||
| 1137 | /** |
||
| 1138 | * Change the path separator of the array wrapper. |
||
| 1139 | * |
||
| 1140 | * By default, the separator is: "." |
||
| 1141 | * |
||
| 1142 | * @param string $separator <p>Separator to set.</p> |
||
| 1143 | * |
||
| 1144 | * @return $this |
||
| 1145 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1146 | * |
||
| 1147 | * @psalm-return static<TKey,T> |
||
| 1148 | */ |
||
| 1149 | 11 | public function changeSeparator($separator): self |
|
| 1155 | |||
| 1156 | /** |
||
| 1157 | * Create a chunked version of the current array. |
||
| 1158 | * |
||
| 1159 | * @param int $size <p>Size of each chunk.</p> |
||
| 1160 | * @param bool $preserveKeys <p>Whether array keys are preserved or no.</p> |
||
| 1161 | * |
||
| 1162 | * @return static |
||
| 1163 | * <p>(Immutable) A new array of chunks from the original array.</p> |
||
| 1164 | * |
||
| 1165 | * @psalm-return static<TKey,T> |
||
| 1166 | * @psalm-mutation-free |
||
| 1167 | */ |
||
| 1168 | 5 | public function chunk($size, $preserveKeys = false): self |
|
| 1176 | |||
| 1177 | /** |
||
| 1178 | * Clean all falsy values from the current array. |
||
| 1179 | * |
||
| 1180 | * @return static |
||
| 1181 | * <p>(Immutable)</p> |
||
| 1182 | * |
||
| 1183 | * @psalm-return static<TKey,T> |
||
| 1184 | * @psalm-mutation-free |
||
| 1185 | */ |
||
| 1186 | 8 | public function clean(): self |
|
| 1194 | |||
| 1195 | /** |
||
| 1196 | * WARNING!!! -> Clear the current full array or a $key of it. |
||
| 1197 | * |
||
| 1198 | * @param int|int[]|string|string[]|null $key |
||
| 1199 | * |
||
| 1200 | * @return $this |
||
| 1201 | * <p>(Mutable) Return this Arrayy object, with an empty array.</p> |
||
| 1202 | * |
||
| 1203 | * @psalm-return static<TKey,T> |
||
| 1204 | */ |
||
| 1205 | 10 | public function clear($key = null): self |
|
| 1224 | |||
| 1225 | /** |
||
| 1226 | * Check if an item is in the current array. |
||
| 1227 | * |
||
| 1228 | * @param float|int|string $value |
||
| 1229 | * @param bool $recursive |
||
| 1230 | * @param bool $strict |
||
| 1231 | * |
||
| 1232 | * @return bool |
||
| 1233 | * @psalm-mutation-free |
||
| 1234 | */ |
||
| 1235 | 24 | public function contains($value, bool $recursive = false, bool $strict = true): bool |
|
| 1256 | |||
| 1257 | /** |
||
| 1258 | * Check if an (case-insensitive) string is in the current array. |
||
| 1259 | * |
||
| 1260 | * @param mixed $value |
||
| 1261 | * @param bool $recursive |
||
| 1262 | * |
||
| 1263 | * @return bool |
||
| 1264 | * @psalm-mutation-free |
||
| 1265 | * |
||
| 1266 | * @psalm-suppress InvalidCast - hack for int|float|bool support |
||
| 1267 | */ |
||
| 1268 | 26 | public function containsCaseInsensitive($value, $recursive = false): bool |
|
| 1297 | |||
| 1298 | /** |
||
| 1299 | * Check if the given key/index exists in the array. |
||
| 1300 | * |
||
| 1301 | * @param int|string $key <p>key/index to search for</p> |
||
| 1302 | * |
||
| 1303 | * @return bool |
||
| 1304 | * <p>Returns true if the given key/index exists in the array, false otherwise.</p> |
||
| 1305 | * |
||
| 1306 | * @psalm-mutation-free |
||
| 1307 | */ |
||
| 1308 | 4 | public function containsKey($key): bool |
|
| 1312 | |||
| 1313 | /** |
||
| 1314 | * Check if all given needles are present in the array as key/index. |
||
| 1315 | * |
||
| 1316 | * @param array $needles <p>The keys you are searching for.</p> |
||
| 1317 | * @param bool $recursive |
||
| 1318 | * |
||
| 1319 | * @return bool |
||
| 1320 | * <p>Returns true if all the given keys/indexes exists in the array, false otherwise.</p> |
||
| 1321 | * |
||
| 1322 | * @psalm-param array<mixed,mixed>|array<TKey> $needles |
||
| 1323 | * @psalm-mutation-free |
||
| 1324 | */ |
||
| 1325 | 2 | public function containsKeys(array $needles, $recursive = false): bool |
|
| 1353 | |||
| 1354 | /** |
||
| 1355 | * Check if all given needles are present in the array as key/index. |
||
| 1356 | * |
||
| 1357 | * @param array $needles <p>The keys you are searching for.</p> |
||
| 1358 | * |
||
| 1359 | * @return bool |
||
| 1360 | * <p>Returns true if all the given keys/indexes exists in the array, false otherwise.</p> |
||
| 1361 | * |
||
| 1362 | * @psalm-param array<mixed,mixed>|array<TKey> $needles |
||
| 1363 | * @psalm-mutation-free |
||
| 1364 | */ |
||
| 1365 | 1 | public function containsKeysRecursive(array $needles): bool |
|
| 1369 | |||
| 1370 | /** |
||
| 1371 | * alias: for "Arrayy->contains()" |
||
| 1372 | * |
||
| 1373 | * @param float|int|string $value |
||
| 1374 | * |
||
| 1375 | * @return bool |
||
| 1376 | * |
||
| 1377 | * @see Arrayy::contains() |
||
| 1378 | * @psalm-mutation-free |
||
| 1379 | */ |
||
| 1380 | 9 | public function containsValue($value): bool |
|
| 1384 | |||
| 1385 | /** |
||
| 1386 | * alias: for "Arrayy->contains($value, true)" |
||
| 1387 | * |
||
| 1388 | * @param float|int|string $value |
||
| 1389 | * |
||
| 1390 | * @return bool |
||
| 1391 | * |
||
| 1392 | * @see Arrayy::contains() |
||
| 1393 | * @psalm-mutation-free |
||
| 1394 | */ |
||
| 1395 | 18 | public function containsValueRecursive($value): bool |
|
| 1399 | |||
| 1400 | /** |
||
| 1401 | * Check if all given needles are present in the array. |
||
| 1402 | * |
||
| 1403 | * @param array $needles |
||
| 1404 | * |
||
| 1405 | * @return bool |
||
| 1406 | * <p>Returns true if all the given values exists in the array, false otherwise.</p> |
||
| 1407 | * |
||
| 1408 | * @psalm-param array<mixed>|array<T> $needles |
||
| 1409 | * @psalm-mutation-free |
||
| 1410 | */ |
||
| 1411 | 1 | public function containsValues(array $needles): bool |
|
| 1417 | |||
| 1418 | /** |
||
| 1419 | * Counts all the values of an array |
||
| 1420 | * |
||
| 1421 | * @see http://php.net/manual/en/function.array-count-values.php |
||
| 1422 | * |
||
| 1423 | * @return static |
||
| 1424 | * <p> |
||
| 1425 | * (Immutable) |
||
| 1426 | * An associative Arrayy-object of values from input as |
||
| 1427 | * keys and their count as value. |
||
| 1428 | * </p> |
||
| 1429 | * |
||
| 1430 | * @psalm-return static<TKey,T> |
||
| 1431 | * @psalm-mutation-free |
||
| 1432 | */ |
||
| 1433 | 7 | public function countValues(): self |
|
| 1437 | |||
| 1438 | /** |
||
| 1439 | * Creates an Arrayy object. |
||
| 1440 | * |
||
| 1441 | * @param mixed $data |
||
| 1442 | * @param string $iteratorClass |
||
| 1443 | * @param bool $checkPropertiesInConstructor |
||
| 1444 | * |
||
| 1445 | * @return static |
||
| 1446 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1447 | * |
||
| 1448 | * @psalm-param class-string<\Arrayy\ArrayyIterator> $iteratorClass |
||
| 1449 | * |
||
| 1450 | * @psalm-mutation-free |
||
| 1451 | */ |
||
| 1452 | 705 | public static function create( |
|
| 1463 | |||
| 1464 | /** |
||
| 1465 | * Flatten an array with the given character as a key delimiter |
||
| 1466 | * |
||
| 1467 | * @param string $delimiter |
||
| 1468 | * @param string $prepend |
||
| 1469 | * @param array|null $items |
||
| 1470 | * |
||
| 1471 | * @return array |
||
| 1472 | */ |
||
| 1473 | 2 | public function flatten($delimiter = '.', $prepend = '', $items = null) |
|
| 1496 | |||
| 1497 | /** |
||
| 1498 | * WARNING: Creates an Arrayy object by reference. |
||
| 1499 | * |
||
| 1500 | * @param array $array |
||
| 1501 | * |
||
| 1502 | * @return $this |
||
| 1503 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1504 | * |
||
| 1505 | * @psalm-param array<mixed,mixed>|array<array-key,mixed> $array |
||
| 1506 | */ |
||
| 1507 | 2 | public function createByReference(array &$array = []): self |
|
| 1515 | |||
| 1516 | /** |
||
| 1517 | * Create an new instance from a callable function which will return an Generator. |
||
| 1518 | * |
||
| 1519 | * @param callable $generatorFunction |
||
| 1520 | * |
||
| 1521 | * @return static |
||
| 1522 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1523 | * |
||
| 1524 | * @psalm-param callable():\Generator<array-key,mixed> $generatorFunction |
||
| 1525 | * |
||
| 1526 | * @psalm-mutation-free |
||
| 1527 | */ |
||
| 1528 | 7 | public static function createFromGeneratorFunction(callable $generatorFunction): self |
|
| 1532 | |||
| 1533 | /** |
||
| 1534 | * Create an new instance filled with a copy of values from a "Generator"-object. |
||
| 1535 | * |
||
| 1536 | * @param \Generator $generator |
||
| 1537 | * |
||
| 1538 | * @return static |
||
| 1539 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1540 | * |
||
| 1541 | * @psalm-param \Generator<array-key,mixed> $generator |
||
| 1542 | * |
||
| 1543 | * @psalm-mutation-free |
||
| 1544 | */ |
||
| 1545 | 4 | public static function createFromGeneratorImmutable(\Generator $generator): self |
|
| 1549 | |||
| 1550 | /** |
||
| 1551 | * Create an new Arrayy object via JSON. |
||
| 1552 | * |
||
| 1553 | * @param string $json |
||
| 1554 | * |
||
| 1555 | * @return static |
||
| 1556 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1557 | * |
||
| 1558 | * @psalm-mutation-free |
||
| 1559 | */ |
||
| 1560 | 5 | public static function createFromJson(string $json): self |
|
| 1564 | |||
| 1565 | /** |
||
| 1566 | * Create an new Arrayy object via JSON. |
||
| 1567 | * |
||
| 1568 | * @param array $array |
||
| 1569 | * |
||
| 1570 | * @return static |
||
| 1571 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1572 | * |
||
| 1573 | * @psalm-mutation-free |
||
| 1574 | */ |
||
| 1575 | 1 | public static function createFromArray(array $array): self |
|
| 1579 | |||
| 1580 | /** |
||
| 1581 | * Create an new instance filled with values from an object that is iterable. |
||
| 1582 | * |
||
| 1583 | * @param \Traversable $object <p>iterable object</p> |
||
| 1584 | * |
||
| 1585 | * @return static |
||
| 1586 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1587 | * |
||
| 1588 | * @psalm-param \Traversable<array-key,mixed> $object |
||
| 1589 | * |
||
| 1590 | * @psalm-mutation-free |
||
| 1591 | */ |
||
| 1592 | 4 | public static function createFromObject(\Traversable $object): self |
|
| 1612 | |||
| 1613 | /** |
||
| 1614 | * Create an new instance filled with values from an object. |
||
| 1615 | * |
||
| 1616 | * @param object $object |
||
| 1617 | * |
||
| 1618 | * @return static |
||
| 1619 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1620 | * |
||
| 1621 | * @psalm-mutation-free |
||
| 1622 | */ |
||
| 1623 | 5 | public static function createFromObjectVars($object): self |
|
| 1627 | |||
| 1628 | /** |
||
| 1629 | * Create an new Arrayy object via string. |
||
| 1630 | * |
||
| 1631 | * @param string $str <p>The input string.</p> |
||
| 1632 | * @param string|null $delimiter <p>The boundary string.</p> |
||
| 1633 | * @param string|null $regEx <p>Use the $delimiter or the $regEx, so if $pattern is null, $delimiter will be |
||
| 1634 | * used.</p> |
||
| 1635 | * |
||
| 1636 | * @return static |
||
| 1637 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1638 | * |
||
| 1639 | * @psalm-mutation-free |
||
| 1640 | */ |
||
| 1641 | 10 | public static function createFromString(string $str, string $delimiter = null, string $regEx = null): self |
|
| 1673 | |||
| 1674 | /** |
||
| 1675 | * Create an new instance filled with a copy of values from a "Traversable"-object. |
||
| 1676 | * |
||
| 1677 | * @param \Traversable $traversable |
||
| 1678 | * |
||
| 1679 | * @return static |
||
| 1680 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1681 | * |
||
| 1682 | * @psalm-param \Traversable<array-key,mixed> $traversable |
||
| 1683 | * |
||
| 1684 | * @psalm-mutation-free |
||
| 1685 | */ |
||
| 1686 | 1 | public static function createFromTraversableImmutable(\Traversable $traversable): self |
|
| 1690 | |||
| 1691 | /** |
||
| 1692 | * Create an new instance containing a range of elements. |
||
| 1693 | * |
||
| 1694 | * @param float|int|string $low <p>First value of the sequence.</p> |
||
| 1695 | * @param float|int|string $high <p>The sequence is ended upon reaching the end value.</p> |
||
| 1696 | * @param float|int $step <p>Used as the increment between elements in the sequence.</p> |
||
| 1697 | * |
||
| 1698 | * @return static |
||
| 1699 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1700 | * |
||
| 1701 | * @psalm-mutation-free |
||
| 1702 | */ |
||
| 1703 | 2 | public static function createWithRange($low, $high, $step = 1): self |
|
| 1707 | |||
| 1708 | /** |
||
| 1709 | * Gets the element of the array at the current internal iterator position. |
||
| 1710 | * |
||
| 1711 | * @return false|mixed |
||
| 1712 | */ |
||
| 1713 | public function current() |
||
| 1717 | |||
| 1718 | /** |
||
| 1719 | * Custom sort by index via "uksort". |
||
| 1720 | * |
||
| 1721 | * @see http://php.net/manual/en/function.uksort.php |
||
| 1722 | * |
||
| 1723 | * @param callable $function |
||
| 1724 | * |
||
| 1725 | * @throws \InvalidArgumentException |
||
| 1726 | * |
||
| 1727 | * @return $this |
||
| 1728 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1729 | * |
||
| 1730 | * @psalm-return static<TKey,T> |
||
| 1731 | */ |
||
| 1732 | 5 | public function customSortKeys(callable $function): self |
|
| 1740 | |||
| 1741 | /** |
||
| 1742 | * Custom sort by index via "uksort". |
||
| 1743 | * |
||
| 1744 | * @see http://php.net/manual/en/function.uksort.php |
||
| 1745 | * |
||
| 1746 | * @param callable $function |
||
| 1747 | * |
||
| 1748 | * @throws \InvalidArgumentException |
||
| 1749 | * |
||
| 1750 | * @return $this |
||
| 1751 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 1752 | * |
||
| 1753 | * @psalm-return static<TKey,T> |
||
| 1754 | * @psalm-mutation-free |
||
| 1755 | */ |
||
| 1756 | 1 | public function customSortKeysImmutable(callable $function): self |
|
| 1769 | |||
| 1770 | /** |
||
| 1771 | * Custom sort by value via "usort". |
||
| 1772 | * |
||
| 1773 | * @see http://php.net/manual/en/function.usort.php |
||
| 1774 | * |
||
| 1775 | * @param callable $function |
||
| 1776 | * |
||
| 1777 | * @throws \InvalidArgumentException |
||
| 1778 | * |
||
| 1779 | * @return $this |
||
| 1780 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1781 | * |
||
| 1782 | * @psalm-return static<TKey,T> |
||
| 1783 | */ |
||
| 1784 | 10 | View Code Duplication | public function customSortValues($function): self |
| 1796 | |||
| 1797 | /** |
||
| 1798 | * Custom sort by value via "usort". |
||
| 1799 | * |
||
| 1800 | * @see http://php.net/manual/en/function.usort.php |
||
| 1801 | * |
||
| 1802 | * @param callable $function |
||
| 1803 | * |
||
| 1804 | * @throws \InvalidArgumentException |
||
| 1805 | * |
||
| 1806 | * @return $this |
||
| 1807 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 1808 | * |
||
| 1809 | * @psalm-return static<TKey,T> |
||
| 1810 | * @psalm-mutation-free |
||
| 1811 | */ |
||
| 1812 | 4 | public function customSortValuesImmutable($function): self |
|
| 1823 | |||
| 1824 | /** |
||
| 1825 | * Delete the given key or keys. |
||
| 1826 | * |
||
| 1827 | * @param int|int[]|string|string[] $keyOrKeys |
||
| 1828 | * |
||
| 1829 | * @return void |
||
| 1830 | */ |
||
| 1831 | 9 | public function delete($keyOrKeys) |
|
| 1839 | |||
| 1840 | /** |
||
| 1841 | * Return values that are only in the current array. |
||
| 1842 | * |
||
| 1843 | * @param array ...$array |
||
| 1844 | * |
||
| 1845 | * @return static |
||
| 1846 | * <p>(Immutable)</p> |
||
| 1847 | * |
||
| 1848 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$array |
||
| 1849 | * @psalm-return static<TKey,T> |
||
| 1850 | * @psalm-mutation-free |
||
| 1851 | */ |
||
| 1852 | 13 | public function diff(...$array): self |
|
| 1860 | |||
| 1861 | /** |
||
| 1862 | * Return values that are only in the current array. |
||
| 1863 | * |
||
| 1864 | * @param array ...$array |
||
| 1865 | * |
||
| 1866 | * @return static |
||
| 1867 | * <p>(Immutable)</p> |
||
| 1868 | * |
||
| 1869 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$array |
||
| 1870 | * @psalm-return static<TKey,T> |
||
| 1871 | * @psalm-mutation-free |
||
| 1872 | */ |
||
| 1873 | 8 | public function diffKey(...$array): self |
|
| 1881 | |||
| 1882 | /** |
||
| 1883 | * Return values and Keys that are only in the current array. |
||
| 1884 | * |
||
| 1885 | * @param array $array |
||
| 1886 | * |
||
| 1887 | * @return static |
||
| 1888 | * <p>(Immutable)</p> |
||
| 1889 | * |
||
| 1890 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 1891 | * @psalm-return static<TKey,T> |
||
| 1892 | * @psalm-mutation-free |
||
| 1893 | */ |
||
| 1894 | 8 | public function diffKeyAndValue(array $array = []): self |
|
| 1902 | |||
| 1903 | /** |
||
| 1904 | * Return values that are only in the current multi-dimensional array. |
||
| 1905 | * |
||
| 1906 | * @param array $array |
||
| 1907 | * @param array|\Generator|null $helperVariableForRecursion <p>(only for internal usage)</p> |
||
| 1908 | * |
||
| 1909 | * @return static |
||
| 1910 | * <p>(Immutable)</p> |
||
| 1911 | * |
||
| 1912 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 1913 | * @psalm-param null|array<TKey,T>|\Generator<TKey,T> $helperVariableForRecursion |
||
| 1914 | * @psalm-return static<TKey,T> |
||
| 1915 | * @psalm-mutation-free |
||
| 1916 | */ |
||
| 1917 | 1 | public function diffRecursive(array $array = [], $helperVariableForRecursion = null): self |
|
| 1952 | |||
| 1953 | /** |
||
| 1954 | * Return values that are only in the new $array. |
||
| 1955 | * |
||
| 1956 | * @param array $array |
||
| 1957 | * |
||
| 1958 | * @return static |
||
| 1959 | * <p>(Immutable)</p> |
||
| 1960 | * |
||
| 1961 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 1962 | * @psalm-return static<TKey,T> |
||
| 1963 | * @psalm-mutation-free |
||
| 1964 | */ |
||
| 1965 | 8 | public function diffReverse(array $array = []): self |
|
| 1973 | |||
| 1974 | /** |
||
| 1975 | * Divide an array into two arrays. One with keys and the other with values. |
||
| 1976 | * |
||
| 1977 | * @return static |
||
| 1978 | * <p>(Immutable)</p> |
||
| 1979 | * |
||
| 1980 | * @psalm-return static<TKey,T> |
||
| 1981 | * @psalm-mutation-free |
||
| 1982 | */ |
||
| 1983 | 1 | public function divide(): self |
|
| 1994 | |||
| 1995 | /** |
||
| 1996 | * Iterate over the current array and modify the array's value. |
||
| 1997 | * |
||
| 1998 | * @param \Closure $closure |
||
| 1999 | * |
||
| 2000 | * @return static |
||
| 2001 | * <p>(Immutable)</p> |
||
| 2002 | * |
||
| 2003 | * @psalm-return static<TKey,T> |
||
| 2004 | * @psalm-mutation-free |
||
| 2005 | */ |
||
| 2006 | 5 | View Code Duplication | public function each(\Closure $closure): self |
| 2021 | |||
| 2022 | /** |
||
| 2023 | * Sets the internal iterator to the last element in the array and returns this element. |
||
| 2024 | * |
||
| 2025 | * @return mixed |
||
| 2026 | */ |
||
| 2027 | public function end() |
||
| 2031 | |||
| 2032 | /** |
||
| 2033 | * Check if a value is in the current array using a closure. |
||
| 2034 | * |
||
| 2035 | * @param \Closure $closure |
||
| 2036 | * |
||
| 2037 | * @return bool |
||
| 2038 | * <p>Returns true if the given value is found, false otherwise.</p> |
||
| 2039 | */ |
||
| 2040 | 4 | public function exists(\Closure $closure): bool |
|
| 2055 | |||
| 2056 | /** |
||
| 2057 | * Fill the array until "$num" with "$default" values. |
||
| 2058 | * |
||
| 2059 | * @param int $num |
||
| 2060 | * @param mixed $default |
||
| 2061 | * |
||
| 2062 | * @return static |
||
| 2063 | * <p>(Immutable)</p> |
||
| 2064 | * |
||
| 2065 | * @psalm-return static<TKey,T> |
||
| 2066 | * @psalm-mutation-free |
||
| 2067 | */ |
||
| 2068 | 8 | public function fillWithDefaults(int $num, $default = null): self |
|
| 2091 | |||
| 2092 | /** |
||
| 2093 | * Find all items in an array that pass the truth test. |
||
| 2094 | * |
||
| 2095 | * @param \Closure|null $closure [optional] <p> |
||
| 2096 | * The callback function to use |
||
| 2097 | * </p> |
||
| 2098 | * <p> |
||
| 2099 | * If no callback is supplied, all entries of |
||
| 2100 | * input equal to false (see |
||
| 2101 | * converting to |
||
| 2102 | * boolean) will be removed. |
||
| 2103 | * </p> |
||
| 2104 | * @param int $flag [optional] <p> |
||
| 2105 | * Flag determining what arguments are sent to <i>callback</i>: |
||
| 2106 | * </p><ul> |
||
| 2107 | * <li> |
||
| 2108 | * <b>ARRAY_FILTER_USE_KEY</b> [1] - pass key as the only argument |
||
| 2109 | * to <i>callback</i> instead of the value</span> |
||
| 2110 | * </li> |
||
| 2111 | * <li> |
||
| 2112 | * <b>ARRAY_FILTER_USE_BOTH</b> [2] - pass both value and key as |
||
| 2113 | * arguments to <i>callback</i> instead of the value</span> |
||
| 2114 | * </li> |
||
| 2115 | * </ul> |
||
| 2116 | * |
||
| 2117 | * @return static |
||
| 2118 | * <p>(Immutable)</p> |
||
| 2119 | * |
||
| 2120 | * @psalm-param \Closure(T=,TKey=):bool|\Closure(T=):bool $closure |
||
| 2121 | * @psalm-return static<TKey,T> |
||
| 2122 | * @psalm-mutation-free |
||
| 2123 | */ |
||
| 2124 | 12 | public function filter($closure = null, int $flag = \ARRAY_FILTER_USE_BOTH) |
|
| 2136 | |||
| 2137 | /** |
||
| 2138 | * Filters an array of objects (or a numeric array of associative arrays) based on the value of a particular |
||
| 2139 | * property within that. |
||
| 2140 | * |
||
| 2141 | * @param string $property |
||
| 2142 | * @param string|string[] $value |
||
| 2143 | * @param string $comparisonOp |
||
| 2144 | * <p> |
||
| 2145 | * 'eq' (equals),<br /> |
||
| 2146 | * 'gt' (greater),<br /> |
||
| 2147 | * 'gte' || 'ge' (greater or equals),<br /> |
||
| 2148 | * 'lt' (less),<br /> |
||
| 2149 | * 'lte' || 'le' (less or equals),<br /> |
||
| 2150 | * 'ne' (not equals),<br /> |
||
| 2151 | * 'contains',<br /> |
||
| 2152 | * 'notContains',<br /> |
||
| 2153 | * 'newer' (via strtotime),<br /> |
||
| 2154 | * 'older' (via strtotime),<br /> |
||
| 2155 | * </p> |
||
| 2156 | * |
||
| 2157 | * @return static |
||
| 2158 | * <p>(Immutable)</p> |
||
| 2159 | * |
||
| 2160 | * @psalm-return static<TKey,T> |
||
| 2161 | * @psalm-mutation-free |
||
| 2162 | * |
||
| 2163 | * @psalm-suppress MissingClosureReturnType |
||
| 2164 | * @psalm-suppress MissingClosureParamType |
||
| 2165 | */ |
||
| 2166 | 1 | public function filterBy( |
|
| 2238 | |||
| 2239 | /** |
||
| 2240 | * Find the first item in an array that passes the truth test, |
||
| 2241 | * otherwise return false |
||
| 2242 | * |
||
| 2243 | * @param \Closure $closure |
||
| 2244 | * |
||
| 2245 | * @return false|mixed |
||
| 2246 | * <p>Return false if we did not find the value.</p> |
||
| 2247 | */ |
||
| 2248 | 8 | View Code Duplication | public function find(\Closure $closure) |
| 2258 | |||
| 2259 | /** |
||
| 2260 | * find by ... |
||
| 2261 | * |
||
| 2262 | * @param string $property |
||
| 2263 | * @param string|string[] $value |
||
| 2264 | * @param string $comparisonOp |
||
| 2265 | * |
||
| 2266 | * @return static |
||
| 2267 | * <p>(Immutable)</p> |
||
| 2268 | * |
||
| 2269 | * @psalm-return static<TKey,T> |
||
| 2270 | * @psalm-mutation-free |
||
| 2271 | */ |
||
| 2272 | 1 | public function findBy(string $property, $value, string $comparisonOp = 'eq'): self |
|
| 2276 | |||
| 2277 | /** |
||
| 2278 | * Get the first value from the current array. |
||
| 2279 | * |
||
| 2280 | * @return mixed |
||
| 2281 | * <p>Return null if there wasn't a element.</p> |
||
| 2282 | */ |
||
| 2283 | 22 | public function first() |
|
| 2292 | |||
| 2293 | /** |
||
| 2294 | * Get the first key from the current array. |
||
| 2295 | * |
||
| 2296 | * @return mixed |
||
| 2297 | * <p>Return null if there wasn't a element.</p> |
||
| 2298 | * @psalm-mutation-free |
||
| 2299 | */ |
||
| 2300 | 29 | public function firstKey() |
|
| 2306 | |||
| 2307 | /** |
||
| 2308 | * Get the first value(s) from the current array. |
||
| 2309 | * And will return an empty array if there was no first entry. |
||
| 2310 | * |
||
| 2311 | * @param int|null $number <p>How many values you will take?</p> |
||
| 2312 | * |
||
| 2313 | * @return static |
||
| 2314 | * <p>(Immutable)</p> |
||
| 2315 | * |
||
| 2316 | * @psalm-return static<TKey,T> |
||
| 2317 | * @psalm-mutation-free |
||
| 2318 | */ |
||
| 2319 | 37 | View Code Duplication | public function firstsImmutable(int $number = null): self |
| 2336 | |||
| 2337 | /** |
||
| 2338 | * Get the first value(s) from the current array. |
||
| 2339 | * And will return an empty array if there was no first entry. |
||
| 2340 | * |
||
| 2341 | * @param int|null $number <p>How many values you will take?</p> |
||
| 2342 | * |
||
| 2343 | * @return static |
||
| 2344 | * <p>(Immutable)</p> |
||
| 2345 | * |
||
| 2346 | * @psalm-return static<TKey,T> |
||
| 2347 | * @psalm-mutation-free |
||
| 2348 | */ |
||
| 2349 | 3 | View Code Duplication | public function firstsKeys(int $number = null): self |
| 2366 | |||
| 2367 | /** |
||
| 2368 | * Get and rmove the first value(s) from the current array. |
||
| 2369 | * And will return an empty array if there was no first entry. |
||
| 2370 | * |
||
| 2371 | * @param int|null $number <p>How many values you will take?</p> |
||
| 2372 | * |
||
| 2373 | * @return $this |
||
| 2374 | * <p>(Mutable)</p> |
||
| 2375 | * |
||
| 2376 | * @psalm-return static<TKey,T> |
||
| 2377 | */ |
||
| 2378 | 34 | public function firstsMutable(int $number = null): self |
|
| 2391 | |||
| 2392 | /** |
||
| 2393 | * Exchanges all keys with their associated values in an array. |
||
| 2394 | * |
||
| 2395 | * @return static |
||
| 2396 | * <p>(Immutable)</p> |
||
| 2397 | * |
||
| 2398 | * @psalm-return static<TKey,T> |
||
| 2399 | * @psalm-mutation-free |
||
| 2400 | */ |
||
| 2401 | 1 | public function flip(): self |
|
| 2409 | |||
| 2410 | /** |
||
| 2411 | * Get a value from an array (optional using dot-notation). |
||
| 2412 | * |
||
| 2413 | * @param mixed $key <p>The key to look for.</p> |
||
| 2414 | * @param mixed $fallback <p>Value to fallback to.</p> |
||
| 2415 | * @param array $array <p>The array to get from, if it's set to "null" we use the current array from the |
||
| 2416 | * class.</p> |
||
| 2417 | * |
||
| 2418 | * @return mixed|static |
||
| 2419 | * |
||
| 2420 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 2421 | * @psalm-mutation-free |
||
| 2422 | */ |
||
| 2423 | 231 | public function get($key, $fallback = null, array $array = null) |
|
| 2515 | |||
| 2516 | /** |
||
| 2517 | * alias: for "Arrayy->toArray()" |
||
| 2518 | * |
||
| 2519 | * @return array |
||
| 2520 | * |
||
| 2521 | * @see Arrayy::getArray() |
||
| 2522 | * |
||
| 2523 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 2524 | */ |
||
| 2525 | 12 | public function getAll(): array |
|
| 2529 | |||
| 2530 | /** |
||
| 2531 | * Get the current array from the "Arrayy"-object. |
||
| 2532 | * |
||
| 2533 | * alias for "toArray()" |
||
| 2534 | * |
||
| 2535 | * @param bool $convertAllArrayyElements <p> |
||
| 2536 | * Convert all Child-"Arrayy" objects also to arrays. |
||
| 2537 | * </p> |
||
| 2538 | * @param bool $preserveKeys <p> |
||
| 2539 | * e.g.: A generator maybe return the same key more then once, |
||
| 2540 | * so maybe you will ignore the keys. |
||
| 2541 | * </p> |
||
| 2542 | * |
||
| 2543 | * @return array |
||
| 2544 | * |
||
| 2545 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 2546 | * @psalm-mutation-free |
||
| 2547 | * |
||
| 2548 | * @see Arrayy::toArray() |
||
| 2549 | */ |
||
| 2550 | 497 | public function getArray( |
|
| 2559 | |||
| 2560 | /** |
||
| 2561 | * Get the current array from the "Arrayy"-object as list. |
||
| 2562 | * |
||
| 2563 | * alias for "toList()" |
||
| 2564 | * |
||
| 2565 | * @param bool $convertAllArrayyElements <p> |
||
| 2566 | * Convert all Child-"Arrayy" objects also to arrays. |
||
| 2567 | * </p> |
||
| 2568 | * |
||
| 2569 | * @return array |
||
| 2570 | * |
||
| 2571 | * @psalm-return array<int,mixed>|array<int,T> |
||
| 2572 | * @psalm-mutation-free |
||
| 2573 | * |
||
| 2574 | * @see Arrayy::toList() |
||
| 2575 | */ |
||
| 2576 | 1 | public function getList(bool $convertAllArrayyElements = false): array |
|
| 2580 | |||
| 2581 | /** |
||
| 2582 | * Returns the values from a single column of the input array, identified by |
||
| 2583 | * the $columnKey, can be used to extract data-columns from multi-arrays. |
||
| 2584 | * |
||
| 2585 | * Info: Optionally, you may provide an $indexKey to index the values in the returned |
||
| 2586 | * array by the values from the $indexKey column in the input array. |
||
| 2587 | * |
||
| 2588 | * @param mixed $columnKey |
||
| 2589 | * @param mixed $indexKey |
||
| 2590 | * |
||
| 2591 | * @return static |
||
| 2592 | * <p>(Immutable)</p> |
||
| 2593 | * |
||
| 2594 | * @psalm-return static<TKey,T> |
||
| 2595 | * @psalm-mutation-free |
||
| 2596 | */ |
||
| 2597 | 1 | public function getColumn($columnKey = null, $indexKey = null): self |
|
| 2605 | |||
| 2606 | /** |
||
| 2607 | * Get the current array from the "Arrayy"-object as generator by reference. |
||
| 2608 | * |
||
| 2609 | * @return \Generator |
||
| 2610 | * |
||
| 2611 | * @psalm-return \Generator<mixed,T>|\Generator<TKey,T> |
||
| 2612 | */ |
||
| 2613 | 75 | public function &getGeneratorByReference(): \Generator |
|
| 2631 | |||
| 2632 | /** |
||
| 2633 | * Get the current array from the "Arrayy"-object as generator. |
||
| 2634 | * |
||
| 2635 | * @return \Generator |
||
| 2636 | * |
||
| 2637 | * @psalm-return \Generator<mixed,T>|\Generator<TKey,T> |
||
| 2638 | * @psalm-mutation-free |
||
| 2639 | */ |
||
| 2640 | 988 | public function getGenerator(): \Generator |
|
| 2650 | |||
| 2651 | /** |
||
| 2652 | * alias: for "Arrayy->keys()" |
||
| 2653 | * |
||
| 2654 | * @return static |
||
| 2655 | * <p>(Immutable)</p> |
||
| 2656 | * |
||
| 2657 | * @see Arrayy::keys() |
||
| 2658 | * |
||
| 2659 | * @psalm-return static<array-key,TKey> |
||
| 2660 | * @psalm-mutation-free |
||
| 2661 | */ |
||
| 2662 | 2 | public function getKeys() |
|
| 2666 | |||
| 2667 | /** |
||
| 2668 | * Get the current array from the "Arrayy"-object as object. |
||
| 2669 | * |
||
| 2670 | * @return \stdClass |
||
| 2671 | */ |
||
| 2672 | 4 | public function getObject(): \stdClass |
|
| 2676 | |||
| 2677 | /** |
||
| 2678 | * alias: for "Arrayy->randomImmutable()" |
||
| 2679 | * |
||
| 2680 | * @return static |
||
| 2681 | * <p>(Immutable)</p> |
||
| 2682 | * |
||
| 2683 | * @see Arrayy::randomImmutable() |
||
| 2684 | * |
||
| 2685 | * @psalm-return static<int|array-key,T> |
||
| 2686 | */ |
||
| 2687 | 4 | public function getRandom(): self |
|
| 2691 | |||
| 2692 | /** |
||
| 2693 | * alias: for "Arrayy->randomKey()" |
||
| 2694 | * |
||
| 2695 | * @return mixed |
||
| 2696 | * <p>Get a key/index or null if there wasn't a key/index.</p> |
||
| 2697 | * |
||
| 2698 | * @see Arrayy::randomKey() |
||
| 2699 | */ |
||
| 2700 | 3 | public function getRandomKey() |
|
| 2704 | |||
| 2705 | /** |
||
| 2706 | * alias: for "Arrayy->randomKeys()" |
||
| 2707 | * |
||
| 2708 | * @param int $number |
||
| 2709 | * |
||
| 2710 | * @return static |
||
| 2711 | * <p>(Immutable)</p> |
||
| 2712 | * |
||
| 2713 | * @see Arrayy::randomKeys() |
||
| 2714 | * |
||
| 2715 | * @psalm-return static<TKey,T> |
||
| 2716 | */ |
||
| 2717 | 8 | public function getRandomKeys(int $number): self |
|
| 2721 | |||
| 2722 | /** |
||
| 2723 | * alias: for "Arrayy->randomValue()" |
||
| 2724 | * |
||
| 2725 | * @return mixed |
||
| 2726 | * <p>Get a random value or null if there wasn't a value.</p> |
||
| 2727 | * |
||
| 2728 | * @see Arrayy::randomValue() |
||
| 2729 | */ |
||
| 2730 | 3 | public function getRandomValue() |
|
| 2734 | |||
| 2735 | /** |
||
| 2736 | * alias: for "Arrayy->randomValues()" |
||
| 2737 | * |
||
| 2738 | * @param int $number |
||
| 2739 | * |
||
| 2740 | * @return static |
||
| 2741 | * <p>(Immutable)</p> |
||
| 2742 | * |
||
| 2743 | * @see Arrayy::randomValues() |
||
| 2744 | * |
||
| 2745 | * @psalm-return static<TKey,T> |
||
| 2746 | */ |
||
| 2747 | 6 | public function getRandomValues(int $number): self |
|
| 2751 | |||
| 2752 | /** |
||
| 2753 | * Gets all values. |
||
| 2754 | * |
||
| 2755 | * @return static |
||
| 2756 | * <p>The values of all elements in this array, in the order they |
||
| 2757 | * appear in the array.</p> |
||
| 2758 | * |
||
| 2759 | * @psalm-return static<TKey,T> |
||
| 2760 | */ |
||
| 2761 | 4 | public function getValues() |
|
| 2771 | |||
| 2772 | /** |
||
| 2773 | * Gets all values via Generator. |
||
| 2774 | * |
||
| 2775 | * @return \Generator |
||
| 2776 | * <p>The values of all elements in this array, in the order they |
||
| 2777 | * appear in the array as Generator.</p> |
||
| 2778 | * |
||
| 2779 | * @psalm-return \Generator<TKey,T> |
||
| 2780 | */ |
||
| 2781 | 4 | public function getValuesYield(): \Generator |
|
| 2785 | |||
| 2786 | /** |
||
| 2787 | * Group values from a array according to the results of a closure. |
||
| 2788 | * |
||
| 2789 | * @param callable|string $grouper <p>A callable function name.</p> |
||
| 2790 | * @param bool $saveKeys |
||
| 2791 | * |
||
| 2792 | * @return static |
||
| 2793 | * <p>(Immutable)</p> |
||
| 2794 | * |
||
| 2795 | * @psalm-return static<TKey,T> |
||
| 2796 | * @psalm-mutation-free |
||
| 2797 | */ |
||
| 2798 | 4 | public function group($grouper, bool $saveKeys = false): self |
|
| 2839 | |||
| 2840 | /** |
||
| 2841 | * Check if an array has a given key. |
||
| 2842 | * |
||
| 2843 | * @param mixed $key |
||
| 2844 | * |
||
| 2845 | * @return bool |
||
| 2846 | */ |
||
| 2847 | 30 | public function has($key): bool |
|
| 2873 | |||
| 2874 | /** |
||
| 2875 | * Check if an array has a given value. |
||
| 2876 | * |
||
| 2877 | * INFO: if you need to search recursive please use ```contains()``` |
||
| 2878 | * |
||
| 2879 | * @param mixed $value |
||
| 2880 | * |
||
| 2881 | * @return bool |
||
| 2882 | */ |
||
| 2883 | 1 | public function hasValue($value): bool |
|
| 2887 | |||
| 2888 | /** |
||
| 2889 | * Implodes the values of this array. |
||
| 2890 | * |
||
| 2891 | * @param string $glue |
||
| 2892 | * |
||
| 2893 | * @return string |
||
| 2894 | * @psalm-mutation-free |
||
| 2895 | */ |
||
| 2896 | 28 | public function implode(string $glue = ''): string |
|
| 2900 | |||
| 2901 | /** |
||
| 2902 | * Implodes the keys of this array. |
||
| 2903 | * |
||
| 2904 | * @param string $glue |
||
| 2905 | * |
||
| 2906 | * @return string |
||
| 2907 | * @psalm-mutation-free |
||
| 2908 | */ |
||
| 2909 | 8 | public function implodeKeys(string $glue = ''): string |
|
| 2913 | |||
| 2914 | /** |
||
| 2915 | * Given a list and an iterate-function that returns |
||
| 2916 | * a key for each element in the list (or a property name), |
||
| 2917 | * returns an object with an index of each item. |
||
| 2918 | * |
||
| 2919 | * @param mixed $key |
||
| 2920 | * |
||
| 2921 | * @return static |
||
| 2922 | * <p>(Immutable)</p> |
||
| 2923 | * |
||
| 2924 | * @psalm-return static<TKey,T> |
||
| 2925 | * @psalm-mutation-free |
||
| 2926 | */ |
||
| 2927 | 4 | public function indexBy($key): self |
|
| 2944 | |||
| 2945 | /** |
||
| 2946 | * alias: for "Arrayy->searchIndex()" |
||
| 2947 | * |
||
| 2948 | * @param mixed $value <p>The value to search for.</p> |
||
| 2949 | * |
||
| 2950 | * @return false|mixed |
||
| 2951 | * |
||
| 2952 | * @see Arrayy::searchIndex() |
||
| 2953 | */ |
||
| 2954 | 4 | public function indexOf($value) |
|
| 2958 | |||
| 2959 | /** |
||
| 2960 | * Get everything but the last..$to items. |
||
| 2961 | * |
||
| 2962 | * @param int $to |
||
| 2963 | * |
||
| 2964 | * @return static |
||
| 2965 | * <p>(Immutable)</p> |
||
| 2966 | * |
||
| 2967 | * @psalm-return static<TKey,T> |
||
| 2968 | * @psalm-mutation-free |
||
| 2969 | */ |
||
| 2970 | 12 | public function initial(int $to = 1): self |
|
| 2974 | |||
| 2975 | /** |
||
| 2976 | * Return an array with all elements found in input array. |
||
| 2977 | * |
||
| 2978 | * @param array $search |
||
| 2979 | * @param bool $keepKeys |
||
| 2980 | * |
||
| 2981 | * @return static |
||
| 2982 | * <p>(Immutable)</p> |
||
| 2983 | * |
||
| 2984 | * @psalm-param array<mixed,mixed>|array<TKey,T> $search |
||
| 2985 | * @psalm-return static<TKey,T> |
||
| 2986 | * @psalm-mutation-free |
||
| 2987 | */ |
||
| 2988 | 4 | public function intersection(array $search, bool $keepKeys = false): self |
|
| 3014 | |||
| 3015 | /** |
||
| 3016 | * Return an array with all elements found in input array. |
||
| 3017 | * |
||
| 3018 | * @param array ...$array |
||
| 3019 | * |
||
| 3020 | * @return static |
||
| 3021 | * <p>(Immutable)</p> |
||
| 3022 | * |
||
| 3023 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$array |
||
| 3024 | * @psalm-return static<TKey,T> |
||
| 3025 | * @psalm-mutation-free |
||
| 3026 | */ |
||
| 3027 | 1 | public function intersectionMulti(...$array): self |
|
| 3035 | |||
| 3036 | /** |
||
| 3037 | * Return a boolean flag which indicates whether the two input arrays have any common elements. |
||
| 3038 | * |
||
| 3039 | * @param array $search |
||
| 3040 | * |
||
| 3041 | * @return bool |
||
| 3042 | * |
||
| 3043 | * @psalm-param array<mixed,mixed>|array<TKey,T> $search |
||
| 3044 | */ |
||
| 3045 | 1 | public function intersects(array $search): bool |
|
| 3049 | |||
| 3050 | /** |
||
| 3051 | * Invoke a function on all of an array's values. |
||
| 3052 | * |
||
| 3053 | * @param callable $callable |
||
| 3054 | * @param mixed $arguments |
||
| 3055 | * |
||
| 3056 | * @return static |
||
| 3057 | * <p>(Immutable)</p> |
||
| 3058 | * |
||
| 3059 | * @psalm-param callable(T=,mixed):mixed $callable |
||
| 3060 | * @psalm-return static<TKey,T> |
||
| 3061 | * @psalm-mutation-free |
||
| 3062 | */ |
||
| 3063 | 1 | View Code Duplication | public function invoke($callable, $arguments = []): self |
| 3087 | |||
| 3088 | /** |
||
| 3089 | * Check whether array is associative or not. |
||
| 3090 | * |
||
| 3091 | * @param bool $recursive |
||
| 3092 | * |
||
| 3093 | * @return bool |
||
| 3094 | * <p>Returns true if associative, false otherwise.</p> |
||
| 3095 | */ |
||
| 3096 | 15 | View Code Duplication | public function isAssoc(bool $recursive = false): bool |
| 3110 | |||
| 3111 | /** |
||
| 3112 | * Check if a given key or keys are empty. |
||
| 3113 | * |
||
| 3114 | * @param int|int[]|string|string[]|null $keys |
||
| 3115 | * |
||
| 3116 | * @return bool |
||
| 3117 | * <p>Returns true if empty, false otherwise.</p> |
||
| 3118 | * @psalm-mutation-free |
||
| 3119 | */ |
||
| 3120 | 45 | public function isEmpty($keys = null): bool |
|
| 3138 | |||
| 3139 | /** |
||
| 3140 | * Check if the current array is equal to the given "$array" or not. |
||
| 3141 | * |
||
| 3142 | * @param array $array |
||
| 3143 | * |
||
| 3144 | * @return bool |
||
| 3145 | * |
||
| 3146 | * @psalm-param array<mixed,mixed> $array |
||
| 3147 | */ |
||
| 3148 | 1 | public function isEqual(array $array): bool |
|
| 3152 | |||
| 3153 | /** |
||
| 3154 | * Check if the current array is a multi-array. |
||
| 3155 | * |
||
| 3156 | * @return bool |
||
| 3157 | */ |
||
| 3158 | 22 | public function isMultiArray(): bool |
|
| 3166 | |||
| 3167 | /** |
||
| 3168 | * Check whether array is numeric or not. |
||
| 3169 | * |
||
| 3170 | * @return bool |
||
| 3171 | * <p>Returns true if numeric, false otherwise.</p> |
||
| 3172 | */ |
||
| 3173 | 5 | View Code Duplication | public function isNumeric(): bool |
| 3187 | |||
| 3188 | /** |
||
| 3189 | * Check if the current array is sequential [0, 1, 2, 3, 4, 5 ...] or not. |
||
| 3190 | * |
||
| 3191 | * @param bool $recursive |
||
| 3192 | * |
||
| 3193 | * @return bool |
||
| 3194 | * @psalm-mutation-free |
||
| 3195 | */ |
||
| 3196 | 9 | public function isSequential(bool $recursive = false): bool |
|
| 3213 | |||
| 3214 | /** |
||
| 3215 | * @return array |
||
| 3216 | * |
||
| 3217 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 3218 | */ |
||
| 3219 | 1 | public function jsonSerialize(): array |
|
| 3223 | |||
| 3224 | /** |
||
| 3225 | * Gets the key/index of the element at the current internal iterator position. |
||
| 3226 | * |
||
| 3227 | * @return int|string|null |
||
| 3228 | */ |
||
| 3229 | public function key() |
||
| 3233 | |||
| 3234 | /** |
||
| 3235 | * Checks if the given key exists in the provided array. |
||
| 3236 | * |
||
| 3237 | * INFO: This method only use "array_key_exists()" if you want to use "dot"-notation, |
||
| 3238 | * then you need to use "Arrayy->offsetExists()". |
||
| 3239 | * |
||
| 3240 | * @param int|string $key the key to look for |
||
| 3241 | * |
||
| 3242 | * @return bool |
||
| 3243 | * @psalm-mutation-free |
||
| 3244 | */ |
||
| 3245 | 154 | public function keyExists($key): bool |
|
| 3249 | |||
| 3250 | /** |
||
| 3251 | * Get all keys from the current array. |
||
| 3252 | * |
||
| 3253 | * @param bool $recursive [optional] <p> |
||
| 3254 | * Get all keys, also from all sub-arrays from an multi-dimensional array. |
||
| 3255 | * </p> |
||
| 3256 | * @param mixed|null $search_values [optional] <p> |
||
| 3257 | * If specified, then only keys containing these values are returned. |
||
| 3258 | * </p> |
||
| 3259 | * @param bool $strict [optional] <p> |
||
| 3260 | * Determines if strict comparison (===) should be used during the search. |
||
| 3261 | * </p> |
||
| 3262 | * |
||
| 3263 | * @return static |
||
| 3264 | * <p>(Immutable) An array of all the keys in input.</p> |
||
| 3265 | * |
||
| 3266 | * @psalm-return static<array-key,TKey> |
||
| 3267 | * @psalm-mutation-free |
||
| 3268 | */ |
||
| 3269 | 29 | public function keys( |
|
| 3339 | |||
| 3340 | /** |
||
| 3341 | * Sort an array by key in reverse order. |
||
| 3342 | * |
||
| 3343 | * @param int $sort_flags [optional] <p> |
||
| 3344 | * You may modify the behavior of the sort using the optional |
||
| 3345 | * parameter sort_flags, for details |
||
| 3346 | * see sort. |
||
| 3347 | * </p> |
||
| 3348 | * |
||
| 3349 | * @return $this |
||
| 3350 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 3351 | * |
||
| 3352 | * @psalm-return static<TKey,T> |
||
| 3353 | */ |
||
| 3354 | 4 | public function krsort(int $sort_flags = 0): self |
|
| 3362 | |||
| 3363 | /** |
||
| 3364 | * Sort an array by key in reverse order. |
||
| 3365 | * |
||
| 3366 | * @param int $sort_flags [optional] <p> |
||
| 3367 | * You may modify the behavior of the sort using the optional |
||
| 3368 | * parameter sort_flags, for details |
||
| 3369 | * see sort. |
||
| 3370 | * </p> |
||
| 3371 | * |
||
| 3372 | * @return $this |
||
| 3373 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 3374 | * |
||
| 3375 | * @psalm-return static<TKey,T> |
||
| 3376 | * @psalm-mutation-free |
||
| 3377 | */ |
||
| 3378 | 4 | public function krsortImmutable(int $sort_flags = 0): self |
|
| 3389 | |||
| 3390 | /** |
||
| 3391 | * Get the last value from the current array. |
||
| 3392 | * |
||
| 3393 | * @return mixed|null |
||
| 3394 | * <p>Return null if there wasn't a element.</p> |
||
| 3395 | * @psalm-mutation-free |
||
| 3396 | */ |
||
| 3397 | 17 | public function last() |
|
| 3406 | |||
| 3407 | /** |
||
| 3408 | * Get the last key from the current array. |
||
| 3409 | * |
||
| 3410 | * @return mixed|null |
||
| 3411 | * <p>Return null if there wasn't a element.</p> |
||
| 3412 | * @psalm-mutation-free |
||
| 3413 | */ |
||
| 3414 | 21 | public function lastKey() |
|
| 3420 | |||
| 3421 | /** |
||
| 3422 | * Get the last value(s) from the current array. |
||
| 3423 | * |
||
| 3424 | * @param int|null $number |
||
| 3425 | * |
||
| 3426 | * @return static |
||
| 3427 | * <p>(Immutable)</p> |
||
| 3428 | * |
||
| 3429 | * @psalm-return static<TKey,T> |
||
| 3430 | * @psalm-mutation-free |
||
| 3431 | */ |
||
| 3432 | 13 | public function lastsImmutable(int $number = null): self |
|
| 3463 | |||
| 3464 | /** |
||
| 3465 | * Get the last value(s) from the current array. |
||
| 3466 | * |
||
| 3467 | * @param int|null $number |
||
| 3468 | * |
||
| 3469 | * @return $this |
||
| 3470 | * <p>(Mutable)</p> |
||
| 3471 | * |
||
| 3472 | * @psalm-return static<TKey,T> |
||
| 3473 | */ |
||
| 3474 | 13 | public function lastsMutable(int $number = null): self |
|
| 3503 | |||
| 3504 | /** |
||
| 3505 | * Count the values from the current array. |
||
| 3506 | * |
||
| 3507 | * alias: for "Arrayy->count()" |
||
| 3508 | * |
||
| 3509 | * @param int $mode |
||
| 3510 | * |
||
| 3511 | * @return int |
||
| 3512 | * |
||
| 3513 | * @see Arrayy::count() |
||
| 3514 | */ |
||
| 3515 | 20 | public function length(int $mode = \COUNT_NORMAL): int |
|
| 3519 | |||
| 3520 | /** |
||
| 3521 | * Apply the given function to the every element of the array, |
||
| 3522 | * collecting the results. |
||
| 3523 | * |
||
| 3524 | * @param callable $callable |
||
| 3525 | * @param bool $useKeyAsSecondParameter |
||
| 3526 | * @param mixed ...$arguments |
||
| 3527 | * |
||
| 3528 | * @return static |
||
| 3529 | * <p>(Immutable) Arrayy object with modified elements.</p> |
||
| 3530 | * |
||
| 3531 | * @psalm-param callable(T,TKey=,mixed=):mixed $callable |
||
| 3532 | * @psalm-return static<TKey,T> |
||
| 3533 | * @psalm-mutation-free |
||
| 3534 | */ |
||
| 3535 | 5 | public function map( |
|
| 3568 | |||
| 3569 | /** |
||
| 3570 | * Check if all items in current array match a truth test. |
||
| 3571 | * |
||
| 3572 | * @param \Closure $closure |
||
| 3573 | * |
||
| 3574 | * @return bool |
||
| 3575 | */ |
||
| 3576 | 15 | View Code Duplication | public function matches(\Closure $closure): bool |
| 3592 | |||
| 3593 | /** |
||
| 3594 | * Check if any item in the current array matches a truth test. |
||
| 3595 | * |
||
| 3596 | * @param \Closure $closure |
||
| 3597 | * |
||
| 3598 | * @return bool |
||
| 3599 | */ |
||
| 3600 | 14 | View Code Duplication | public function matchesAny(\Closure $closure): bool |
| 3616 | |||
| 3617 | /** |
||
| 3618 | * Get the max value from an array. |
||
| 3619 | * |
||
| 3620 | * @return false|mixed |
||
| 3621 | * <p>Will return false if there are no values.</p> |
||
| 3622 | */ |
||
| 3623 | 10 | View Code Duplication | public function max() |
| 3642 | |||
| 3643 | /** |
||
| 3644 | * Merge the new $array into the current array. |
||
| 3645 | * |
||
| 3646 | * - keep key,value from the current array, also if the index is in the new $array |
||
| 3647 | * |
||
| 3648 | * @param array $array |
||
| 3649 | * @param bool $recursive |
||
| 3650 | * |
||
| 3651 | * @return static |
||
| 3652 | * <p>(Immutable)</p> |
||
| 3653 | * |
||
| 3654 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 3655 | * @psalm-return static<int|TKey,T> |
||
| 3656 | * @psalm-mutation-free |
||
| 3657 | */ |
||
| 3658 | 32 | View Code Duplication | public function mergeAppendKeepIndex(array $array = [], bool $recursive = false): self |
| 3673 | |||
| 3674 | /** |
||
| 3675 | * Merge the new $array into the current array. |
||
| 3676 | * |
||
| 3677 | * - replace duplicate assoc-keys from the current array with the key,values from the new $array |
||
| 3678 | * - create new indexes |
||
| 3679 | * |
||
| 3680 | * @param array $array |
||
| 3681 | * @param bool $recursive |
||
| 3682 | * |
||
| 3683 | * @return static |
||
| 3684 | * <p>(Immutable)</p> |
||
| 3685 | * |
||
| 3686 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 3687 | * @psalm-return static<TKey,T> |
||
| 3688 | * @psalm-mutation-free |
||
| 3689 | */ |
||
| 3690 | 19 | View Code Duplication | public function mergeAppendNewIndex(array $array = [], bool $recursive = false): self |
| 3705 | |||
| 3706 | /** |
||
| 3707 | * Merge the the current array into the $array. |
||
| 3708 | * |
||
| 3709 | * - use key,value from the new $array, also if the index is in the current array |
||
| 3710 | * |
||
| 3711 | * @param array $array |
||
| 3712 | * @param bool $recursive |
||
| 3713 | * |
||
| 3714 | * @return static |
||
| 3715 | * <p>(Immutable)</p> |
||
| 3716 | * |
||
| 3717 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 3718 | * @psalm-return static<TKey,T> |
||
| 3719 | * @psalm-mutation-free |
||
| 3720 | */ |
||
| 3721 | 16 | View Code Duplication | public function mergePrependKeepIndex(array $array = [], bool $recursive = false): self |
| 3736 | |||
| 3737 | /** |
||
| 3738 | * Merge the current array into the new $array. |
||
| 3739 | * |
||
| 3740 | * - replace duplicate assoc-keys from new $array with the key,values from the current array |
||
| 3741 | * - create new indexes |
||
| 3742 | * |
||
| 3743 | * @param array $array |
||
| 3744 | * @param bool $recursive |
||
| 3745 | * |
||
| 3746 | * @return static |
||
| 3747 | * <p>(Immutable)</p> |
||
| 3748 | * |
||
| 3749 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 3750 | * @psalm-return static<TKey,T> |
||
| 3751 | * @psalm-mutation-free |
||
| 3752 | */ |
||
| 3753 | 20 | View Code Duplication | public function mergePrependNewIndex(array $array = [], bool $recursive = false): self |
| 3768 | |||
| 3769 | /** |
||
| 3770 | * @return ArrayyMeta|static |
||
| 3771 | */ |
||
| 3772 | 15 | public static function meta() |
|
| 3776 | |||
| 3777 | /** |
||
| 3778 | * Get the min value from an array. |
||
| 3779 | * |
||
| 3780 | * @return false|mixed |
||
| 3781 | * <p>Will return false if there are no values.</p> |
||
| 3782 | */ |
||
| 3783 | 10 | View Code Duplication | public function min() |
| 3802 | |||
| 3803 | /** |
||
| 3804 | * Get the most used value from the array. |
||
| 3805 | * |
||
| 3806 | * @return mixed|null |
||
| 3807 | * <p>(Immutable) Return null if there wasn't a element.</p> |
||
| 3808 | * @psalm-mutation-free |
||
| 3809 | */ |
||
| 3810 | 3 | public function mostUsedValue() |
|
| 3814 | |||
| 3815 | /** |
||
| 3816 | * Get the most used value from the array. |
||
| 3817 | * |
||
| 3818 | * @param int|null $number <p>How many values you will take?</p> |
||
| 3819 | * |
||
| 3820 | * @return static |
||
| 3821 | * <p>(Immutable)</p> |
||
| 3822 | * |
||
| 3823 | * @psalm-return static<TKey,T> |
||
| 3824 | * @psalm-mutation-free |
||
| 3825 | */ |
||
| 3826 | 3 | public function mostUsedValues(int $number = null): self |
|
| 3830 | |||
| 3831 | /** |
||
| 3832 | * Move an array element to a new index. |
||
| 3833 | * |
||
| 3834 | * cherry-picked from: http://stackoverflow.com/questions/12624153/move-an-array-element-to-a-new-index-in-php |
||
| 3835 | * |
||
| 3836 | * @param int|string $from |
||
| 3837 | * @param int $to |
||
| 3838 | * |
||
| 3839 | * @return static |
||
| 3840 | * <p>(Immutable)</p> |
||
| 3841 | * |
||
| 3842 | * @psalm-return static<TKey,T> |
||
| 3843 | * @psalm-mutation-free |
||
| 3844 | */ |
||
| 3845 | 1 | public function moveElement($from, $to): self |
|
| 3878 | |||
| 3879 | /** |
||
| 3880 | * Move an array element to the first place. |
||
| 3881 | * |
||
| 3882 | * INFO: Instead of "Arrayy->moveElement()" this method will NOT |
||
| 3883 | * loss the keys of an indexed array. |
||
| 3884 | * |
||
| 3885 | * @param int|string $key |
||
| 3886 | * |
||
| 3887 | * @return static |
||
| 3888 | * <p>(Immutable)</p> |
||
| 3889 | * |
||
| 3890 | * @psalm-return static<TKey,T> |
||
| 3891 | * @psalm-mutation-free |
||
| 3892 | */ |
||
| 3893 | 1 | View Code Duplication | public function moveElementToFirstPlace($key): self |
| 3909 | |||
| 3910 | /** |
||
| 3911 | * Move an array element to the last place. |
||
| 3912 | * |
||
| 3913 | * INFO: Instead of "Arrayy->moveElement()" this method will NOT |
||
| 3914 | * loss the keys of an indexed array. |
||
| 3915 | * |
||
| 3916 | * @param int|string $key |
||
| 3917 | * |
||
| 3918 | * @return static |
||
| 3919 | * <p>(Immutable)</p> |
||
| 3920 | * |
||
| 3921 | * @psalm-return static<TKey,T> |
||
| 3922 | * @psalm-mutation-free |
||
| 3923 | */ |
||
| 3924 | 1 | View Code Duplication | public function moveElementToLastPlace($key): self |
| 3940 | |||
| 3941 | /** |
||
| 3942 | * Moves the internal iterator position to the next element and returns this element. |
||
| 3943 | * |
||
| 3944 | * @return false|mixed |
||
| 3945 | * <p>(Mutable) Will return false if there are no values.</p> |
||
| 3946 | */ |
||
| 3947 | public function next() |
||
| 3951 | |||
| 3952 | /** |
||
| 3953 | * Get the next nth keys and values from the array. |
||
| 3954 | * |
||
| 3955 | * @param int $step |
||
| 3956 | * @param int $offset |
||
| 3957 | * |
||
| 3958 | * @return static |
||
| 3959 | * <p>(Immutable)</p> |
||
| 3960 | * |
||
| 3961 | * @psalm-return static<TKey,T> |
||
| 3962 | * @psalm-mutation-free |
||
| 3963 | */ |
||
| 3964 | 1 | public function nth(int $step, int $offset = 0): self |
|
| 3983 | |||
| 3984 | /** |
||
| 3985 | * Get a subset of the items from the given array. |
||
| 3986 | * |
||
| 3987 | * @param mixed[] $keys |
||
| 3988 | * |
||
| 3989 | * @return static |
||
| 3990 | * <p>(Immutable)</p> |
||
| 3991 | * |
||
| 3992 | * @psalm-return static<TKey,T> |
||
| 3993 | * @psalm-mutation-free |
||
| 3994 | */ |
||
| 3995 | 1 | public function only(array $keys): self |
|
| 4005 | |||
| 4006 | /** |
||
| 4007 | * Pad array to the specified size with a given value. |
||
| 4008 | * |
||
| 4009 | * @param int $size <p>Size of the result array.</p> |
||
| 4010 | * @param mixed $value <p>Empty value by default.</p> |
||
| 4011 | * |
||
| 4012 | * @return static |
||
| 4013 | * <p>(Immutable) Arrayy object padded to $size with $value.</p> |
||
| 4014 | * |
||
| 4015 | * @psalm-return static<TKey,T> |
||
| 4016 | * @psalm-mutation-free |
||
| 4017 | */ |
||
| 4018 | 5 | public function pad(int $size, $value): self |
|
| 4026 | |||
| 4027 | /** |
||
| 4028 | * Partitions this array in two array according to a predicate. |
||
| 4029 | * Keys are preserved in the resulting array. |
||
| 4030 | * |
||
| 4031 | * @param \Closure $closure |
||
| 4032 | * <p>The predicate on which to partition.</p> |
||
| 4033 | * |
||
| 4034 | * @return array<int, static> |
||
| 4035 | * <p>An array with two elements. The first element contains the array |
||
| 4036 | * of elements where the predicate returned TRUE, the second element |
||
| 4037 | * contains the array of elements where the predicate returned FALSE.</p> |
||
| 4038 | * |
||
| 4039 | * @psalm-return array<int, static<TKey,T>> |
||
| 4040 | */ |
||
| 4041 | 1 | public function partition(\Closure $closure): array |
|
| 4057 | |||
| 4058 | /** |
||
| 4059 | * Pop a specified value off the end of the current array. |
||
| 4060 | * |
||
| 4061 | * @return mixed|null |
||
| 4062 | * <p>(Mutable) The popped element from the current array or null if the array is e.g. empty.</p> |
||
| 4063 | */ |
||
| 4064 | 5 | public function pop() |
|
| 4070 | |||
| 4071 | /** |
||
| 4072 | * Prepend a (key) + value to the current array. |
||
| 4073 | * |
||
| 4074 | * @param mixed $value |
||
| 4075 | * @param mixed $key |
||
| 4076 | * |
||
| 4077 | * @return $this |
||
| 4078 | * <p>(Mutable) Return this Arrayy object, with the prepended value.</p> |
||
| 4079 | * |
||
| 4080 | * @psalm-return static<TKey,T> |
||
| 4081 | */ |
||
| 4082 | 11 | public function prepend($value, $key = null) |
|
| 4098 | |||
| 4099 | /** |
||
| 4100 | * Add a suffix to each key. |
||
| 4101 | * |
||
| 4102 | * @param mixed $suffix |
||
| 4103 | * |
||
| 4104 | * @return static |
||
| 4105 | * <p>(Immutable) Return an Arrayy object, with the prepended keys.</p> |
||
| 4106 | * |
||
| 4107 | * @psalm-return static<TKey,T> |
||
| 4108 | * @psalm-mutation-free |
||
| 4109 | */ |
||
| 4110 | 10 | View Code Duplication | public function prependToEachKey($suffix): self |
| 4136 | |||
| 4137 | /** |
||
| 4138 | * Add a suffix to each value. |
||
| 4139 | * |
||
| 4140 | * @param mixed $suffix |
||
| 4141 | * |
||
| 4142 | * @return static |
||
| 4143 | * <p>(Immutable) Return an Arrayy object, with the prepended values.</p> |
||
| 4144 | * |
||
| 4145 | * @psalm-return static<TKey,T> |
||
| 4146 | * @psalm-mutation-free |
||
| 4147 | */ |
||
| 4148 | 10 | View Code Duplication | public function prependToEachValue($suffix): self |
| 4176 | |||
| 4177 | /** |
||
| 4178 | * Return the value of a given key and |
||
| 4179 | * delete the key. |
||
| 4180 | * |
||
| 4181 | * @param int|int[]|string|string[]|null $keyOrKeys |
||
| 4182 | * @param mixed $fallback |
||
| 4183 | * |
||
| 4184 | * @return mixed |
||
| 4185 | */ |
||
| 4186 | 5 | public function pull($keyOrKeys = null, $fallback = null) |
|
| 4208 | |||
| 4209 | /** |
||
| 4210 | * Push one or more values onto the end of array at once. |
||
| 4211 | * |
||
| 4212 | * @param array ...$args |
||
| 4213 | * |
||
| 4214 | * @return $this |
||
| 4215 | * <p>(Mutable) Return this Arrayy object, with pushed elements to the end of array.</p> |
||
| 4216 | * |
||
| 4217 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
| 4218 | * |
||
| 4219 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$args |
||
| 4220 | * @psalm-return static<TKey,T> |
||
| 4221 | */ |
||
| 4222 | 7 | public function push(...$args) |
|
| 4240 | |||
| 4241 | /** |
||
| 4242 | * Get a random value from the current array. |
||
| 4243 | * |
||
| 4244 | * @param int|null $number <p>How many values you will take?</p> |
||
| 4245 | * |
||
| 4246 | * @return static |
||
| 4247 | * <p>(Immutable)</p> |
||
| 4248 | * |
||
| 4249 | * @psalm-return static<int|array-key,T> |
||
| 4250 | */ |
||
| 4251 | 19 | public function randomImmutable(int $number = null): self |
|
| 4284 | |||
| 4285 | /** |
||
| 4286 | * Pick a random key/index from the keys of this array. |
||
| 4287 | * |
||
| 4288 | * @throws \RangeException If array is empty |
||
| 4289 | * |
||
| 4290 | * @return mixed |
||
| 4291 | * <p>Get a key/index or null if there wasn't a key/index.</p> |
||
| 4292 | */ |
||
| 4293 | 4 | public function randomKey() |
|
| 4303 | |||
| 4304 | /** |
||
| 4305 | * Pick a given number of random keys/indexes out of this array. |
||
| 4306 | * |
||
| 4307 | * @param int $number <p>The number of keys/indexes (should be <= \count($this->array))</p> |
||
| 4308 | * |
||
| 4309 | * @throws \RangeException If array is empty |
||
| 4310 | * |
||
| 4311 | * @return static |
||
| 4312 | * <p>(Immutable)</p> |
||
| 4313 | * |
||
| 4314 | * @psalm-return static<TKey,T> |
||
| 4315 | */ |
||
| 4316 | 13 | public function randomKeys(int $number): self |
|
| 4344 | |||
| 4345 | /** |
||
| 4346 | * Get a random value from the current array. |
||
| 4347 | * |
||
| 4348 | * @param int|null $number <p>How many values you will take?</p> |
||
| 4349 | * |
||
| 4350 | * @return $this |
||
| 4351 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 4352 | * |
||
| 4353 | * @psalm-return static<TKey,T> |
||
| 4354 | */ |
||
| 4355 | 17 | public function randomMutable(int $number = null): self |
|
| 4380 | |||
| 4381 | /** |
||
| 4382 | * Pick a random value from the values of this array. |
||
| 4383 | * |
||
| 4384 | * @return mixed |
||
| 4385 | * <p>Get a random value or null if there wasn't a value.</p> |
||
| 4386 | */ |
||
| 4387 | 4 | public function randomValue() |
|
| 4397 | |||
| 4398 | /** |
||
| 4399 | * Pick a given number of random values out of this array. |
||
| 4400 | * |
||
| 4401 | * @param int $number |
||
| 4402 | * |
||
| 4403 | * @return static |
||
| 4404 | * <p>(Mutable)</p> |
||
| 4405 | * |
||
| 4406 | * @psalm-return static<TKey,T> |
||
| 4407 | */ |
||
| 4408 | 7 | public function randomValues(int $number): self |
|
| 4412 | |||
| 4413 | /** |
||
| 4414 | * Get a random value from an array, with the ability to skew the results. |
||
| 4415 | * |
||
| 4416 | * Example: randomWeighted(['foo' => 1, 'bar' => 2]) has a 66% chance of returning bar. |
||
| 4417 | * |
||
| 4418 | * @param array $array |
||
| 4419 | * @param int|null $number <p>How many values you will take?</p> |
||
| 4420 | * |
||
| 4421 | * @return static<int,mixed> |
||
| 4422 | * <p>(Immutable)</p> |
||
| 4423 | * |
||
| 4424 | * @psalm-param array<mixed,mixed> $array |
||
| 4425 | * @psalm-return static<int|array-key,T> |
||
| 4426 | */ |
||
| 4427 | 9 | public function randomWeighted(array $array, int $number = null): self |
|
| 4442 | |||
| 4443 | /** |
||
| 4444 | * Reduce the current array via callable e.g. anonymous-function. |
||
| 4445 | * |
||
| 4446 | * @param callable $callable |
||
| 4447 | * @param mixed $init |
||
| 4448 | * |
||
| 4449 | * @return static |
||
| 4450 | * <p>(Immutable)</p> |
||
| 4451 | * |
||
| 4452 | * @psalm-return static<TKey,T> |
||
| 4453 | * @psalm-mutation-free |
||
| 4454 | */ |
||
| 4455 | 18 | public function reduce($callable, $init = []): self |
|
| 4485 | |||
| 4486 | /** |
||
| 4487 | * @param bool $unique |
||
| 4488 | * |
||
| 4489 | * @return static |
||
| 4490 | * <p>(Immutable)</p> |
||
| 4491 | * |
||
| 4492 | * @psalm-return static<TKey,T> |
||
| 4493 | * @psalm-mutation-free |
||
| 4494 | */ |
||
| 4495 | 14 | public function reduce_dimension(bool $unique = true): self |
|
| 4518 | |||
| 4519 | /** |
||
| 4520 | * Create a numerically re-indexed Arrayy object. |
||
| 4521 | * |
||
| 4522 | * @return $this |
||
| 4523 | * <p>(Mutable) Return this Arrayy object, with re-indexed array-elements.</p> |
||
| 4524 | * |
||
| 4525 | * @psalm-return static<TKey,T> |
||
| 4526 | */ |
||
| 4527 | 9 | public function reindex(): self |
|
| 4535 | |||
| 4536 | /** |
||
| 4537 | * Return all items that fail the truth test. |
||
| 4538 | * |
||
| 4539 | * @param \Closure $closure |
||
| 4540 | * |
||
| 4541 | * @return static |
||
| 4542 | * <p>(Immutable)</p> |
||
| 4543 | * |
||
| 4544 | * @psalm-return static<TKey,T> |
||
| 4545 | * @psalm-mutation-free |
||
| 4546 | */ |
||
| 4547 | 1 | View Code Duplication | public function reject(\Closure $closure): self |
| 4564 | |||
| 4565 | /** |
||
| 4566 | * Remove a value from the current array (optional using dot-notation). |
||
| 4567 | * |
||
| 4568 | * @param mixed $key |
||
| 4569 | * |
||
| 4570 | * @return static |
||
| 4571 | * <p>(Mutable)</p> |
||
| 4572 | * |
||
| 4573 | * @psalm-param TKey $key |
||
| 4574 | * @psalm-return static<TKey,T> |
||
| 4575 | */ |
||
| 4576 | 21 | public function remove($key) |
|
| 4599 | |||
| 4600 | /** |
||
| 4601 | * alias: for "Arrayy->removeValue()" |
||
| 4602 | * |
||
| 4603 | * @param mixed $element |
||
| 4604 | * |
||
| 4605 | * @return static |
||
| 4606 | * <p>(Immutable)</p> |
||
| 4607 | * |
||
| 4608 | * @psalm-param T $element |
||
| 4609 | * @psalm-return static<TKey,T> |
||
| 4610 | * @psalm-mutation-free |
||
| 4611 | */ |
||
| 4612 | 8 | public function removeElement($element) |
|
| 4616 | |||
| 4617 | /** |
||
| 4618 | * Remove the first value from the current array. |
||
| 4619 | * |
||
| 4620 | * @return static |
||
| 4621 | * <p>(Immutable)</p> |
||
| 4622 | * |
||
| 4623 | * @psalm-return static<TKey,T> |
||
| 4624 | * @psalm-mutation-free |
||
| 4625 | */ |
||
| 4626 | 7 | View Code Duplication | public function removeFirst(): self |
| 4638 | |||
| 4639 | /** |
||
| 4640 | * Remove the last value from the current array. |
||
| 4641 | * |
||
| 4642 | * @return static |
||
| 4643 | * <p>(Immutable)</p> |
||
| 4644 | * |
||
| 4645 | * @psalm-return static<TKey,T> |
||
| 4646 | * @psalm-mutation-free |
||
| 4647 | */ |
||
| 4648 | 7 | View Code Duplication | public function removeLast(): self |
| 4660 | |||
| 4661 | /** |
||
| 4662 | * Removes a particular value from an array (numeric or associative). |
||
| 4663 | * |
||
| 4664 | * @param mixed $value |
||
| 4665 | * |
||
| 4666 | * @return static |
||
| 4667 | * <p>(Immutable)</p> |
||
| 4668 | * |
||
| 4669 | * @psalm-param T $value |
||
| 4670 | * @psalm-return static<TKey,T> |
||
| 4671 | * @psalm-mutation-free |
||
| 4672 | */ |
||
| 4673 | 8 | public function removeValue($value): self |
|
| 4696 | |||
| 4697 | /** |
||
| 4698 | * Generate array of repeated arrays. |
||
| 4699 | * |
||
| 4700 | * @param int $times <p>How many times has to be repeated.</p> |
||
| 4701 | * |
||
| 4702 | * @return static |
||
| 4703 | * <p>(Immutable)</p> |
||
| 4704 | * |
||
| 4705 | * @psalm-return static<TKey,T> |
||
| 4706 | * @psalm-mutation-free |
||
| 4707 | */ |
||
| 4708 | 1 | public function repeat($times): self |
|
| 4720 | |||
| 4721 | /** |
||
| 4722 | * Replace a key with a new key/value pair. |
||
| 4723 | * |
||
| 4724 | * @param mixed $oldKey |
||
| 4725 | * @param mixed $newKey |
||
| 4726 | * @param mixed $newValue |
||
| 4727 | * |
||
| 4728 | * @return static |
||
| 4729 | * <p>(Immutable)</p> |
||
| 4730 | * |
||
| 4731 | * @psalm-return static<TKey,T> |
||
| 4732 | * @psalm-mutation-free |
||
| 4733 | */ |
||
| 4734 | 5 | public function replace($oldKey, $newKey, $newValue): self |
|
| 4744 | |||
| 4745 | /** |
||
| 4746 | * Create an array using the current array as values and the other array as keys. |
||
| 4747 | * |
||
| 4748 | * @param array $keys <p>An array of keys.</p> |
||
| 4749 | * |
||
| 4750 | * @return static |
||
| 4751 | * <p>(Immutable) Arrayy object with keys from the other array.</p> |
||
| 4752 | * |
||
| 4753 | * @psalm-param array<mixed,mixed>|array<mixed,TKey> $keys |
||
| 4754 | * @psalm-return static<TKey,T> |
||
| 4755 | * @psalm-mutation-free |
||
| 4756 | */ |
||
| 4757 | 2 | public function replaceAllKeys(array $keys): self |
|
| 4765 | |||
| 4766 | /** |
||
| 4767 | * Create an array using the current array as keys and the other array as values. |
||
| 4768 | * |
||
| 4769 | * @param array $array <p>An array o values.</p> |
||
| 4770 | * |
||
| 4771 | * @return static |
||
| 4772 | * <p>(Immutable) Arrayy object with values from the other array.</p> |
||
| 4773 | * |
||
| 4774 | * @psalm-param array<mixed,T> $array |
||
| 4775 | * @psalm-return static<TKey,T> |
||
| 4776 | * @psalm-mutation-free |
||
| 4777 | */ |
||
| 4778 | 2 | public function replaceAllValues(array $array): self |
|
| 4786 | |||
| 4787 | /** |
||
| 4788 | * Replace the keys in an array with another set. |
||
| 4789 | * |
||
| 4790 | * @param array $keys <p>An array of keys matching the array's size</p> |
||
| 4791 | * |
||
| 4792 | * @return static |
||
| 4793 | * <p>(Immutable)</p> |
||
| 4794 | * |
||
| 4795 | * @psalm-param array<mixed,mixed>|array<mixed,TKey> $keys |
||
| 4796 | * @psalm-return static<TKey,T> |
||
| 4797 | * @psalm-mutation-free |
||
| 4798 | */ |
||
| 4799 | 1 | public function replaceKeys(array $keys): self |
|
| 4810 | |||
| 4811 | /** |
||
| 4812 | * Replace the first matched value in an array. |
||
| 4813 | * |
||
| 4814 | * @param mixed $search <p>The value to replace.</p> |
||
| 4815 | * @param mixed $replacement <p>The value to replace.</p> |
||
| 4816 | * |
||
| 4817 | * @return static |
||
| 4818 | * <p>(Immutable)</p> |
||
| 4819 | * |
||
| 4820 | * @psalm-return static<TKey,T> |
||
| 4821 | * @psalm-mutation-free |
||
| 4822 | */ |
||
| 4823 | 3 | public function replaceOneValue($search, $replacement = ''): self |
|
| 4838 | |||
| 4839 | /** |
||
| 4840 | * Replace values in the current array. |
||
| 4841 | * |
||
| 4842 | * @param mixed $search <p>The value to replace.</p> |
||
| 4843 | * @param mixed $replacement <p>What to replace it with.</p> |
||
| 4844 | * |
||
| 4845 | * @return static |
||
| 4846 | * <p>(Immutable)</p> |
||
| 4847 | * |
||
| 4848 | * @psalm-return static<TKey,T> |
||
| 4849 | * @psalm-mutation-free |
||
| 4850 | */ |
||
| 4851 | 1 | public function replaceValues($search, $replacement = ''): self |
|
| 4863 | |||
| 4864 | /** |
||
| 4865 | * Get the last elements from index $from until the end of this array. |
||
| 4866 | * |
||
| 4867 | * @param int $from |
||
| 4868 | * |
||
| 4869 | * @return static |
||
| 4870 | * <p>(Immutable)</p> |
||
| 4871 | * |
||
| 4872 | * @psalm-return static<TKey,T> |
||
| 4873 | * @psalm-mutation-free |
||
| 4874 | */ |
||
| 4875 | 15 | View Code Duplication | public function rest(int $from = 1): self |
| 4885 | |||
| 4886 | /** |
||
| 4887 | * Return the array in the reverse order. |
||
| 4888 | * |
||
| 4889 | * @return $this |
||
| 4890 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 4891 | * |
||
| 4892 | * @psalm-return static<TKey,T> |
||
| 4893 | */ |
||
| 4894 | 9 | public function reverse(): self |
|
| 4902 | |||
| 4903 | /** |
||
| 4904 | * Sort an array in reverse order. |
||
| 4905 | * |
||
| 4906 | * @param int $sort_flags [optional] <p> |
||
| 4907 | * You may modify the behavior of the sort using the optional |
||
| 4908 | * parameter sort_flags, for details |
||
| 4909 | * see sort. |
||
| 4910 | * </p> |
||
| 4911 | * |
||
| 4912 | * @return $this |
||
| 4913 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 4914 | * |
||
| 4915 | * @psalm-return static<TKey,T> |
||
| 4916 | */ |
||
| 4917 | 4 | public function rsort(int $sort_flags = 0): self |
|
| 4925 | |||
| 4926 | /** |
||
| 4927 | * Sort an array in reverse order. |
||
| 4928 | * |
||
| 4929 | * @param int $sort_flags [optional] <p> |
||
| 4930 | * You may modify the behavior of the sort using the optional |
||
| 4931 | * parameter sort_flags, for details |
||
| 4932 | * see sort. |
||
| 4933 | * </p> |
||
| 4934 | * |
||
| 4935 | * @return $this |
||
| 4936 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 4937 | * |
||
| 4938 | * @psalm-return static<TKey,T> |
||
| 4939 | * @psalm-mutation-free |
||
| 4940 | */ |
||
| 4941 | 4 | public function rsortImmutable(int $sort_flags = 0): self |
|
| 4952 | |||
| 4953 | /** |
||
| 4954 | * Search for the first index of the current array via $value. |
||
| 4955 | * |
||
| 4956 | * @param mixed $value |
||
| 4957 | * |
||
| 4958 | * @return false|float|int|string |
||
| 4959 | * <p>Will return <b>FALSE</b> if the value can't be found.</p> |
||
| 4960 | * @psalm-mutation-free |
||
| 4961 | */ |
||
| 4962 | 21 | public function searchIndex($value) |
|
| 4972 | |||
| 4973 | /** |
||
| 4974 | * Search for the value of the current array via $index. |
||
| 4975 | * |
||
| 4976 | * @param mixed $index |
||
| 4977 | * |
||
| 4978 | * @return static |
||
| 4979 | * <p>(Immutable) Will return a empty Arrayy if the value wasn't found.</p> |
||
| 4980 | * |
||
| 4981 | * @psalm-return static<TKey,T> |
||
| 4982 | * @psalm-mutation-free |
||
| 4983 | */ |
||
| 4984 | 9 | public function searchValue($index): self |
|
| 5014 | |||
| 5015 | /** |
||
| 5016 | * Set a value for the current array (optional using dot-notation). |
||
| 5017 | * |
||
| 5018 | * @param string $key <p>The key to set.</p> |
||
| 5019 | * @param mixed $value <p>Its value.</p> |
||
| 5020 | * |
||
| 5021 | * @return $this |
||
| 5022 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 5023 | * |
||
| 5024 | * @psalm-param TKey $key |
||
| 5025 | * @psalm-param T $value |
||
| 5026 | * @psalm-return static<TKey,T> |
||
| 5027 | */ |
||
| 5028 | 28 | public function set($key, $value): self |
|
| 5034 | |||
| 5035 | /** |
||
| 5036 | * Get a value from a array and set it if it was not. |
||
| 5037 | * |
||
| 5038 | * WARNING: this method only set the value, if the $key is not already set |
||
| 5039 | * |
||
| 5040 | * @param mixed $key <p>The key</p> |
||
| 5041 | * @param mixed $fallback <p>The default value to set if it isn't.</p> |
||
| 5042 | * |
||
| 5043 | * @return mixed |
||
| 5044 | * <p>(Mutable)</p> |
||
| 5045 | */ |
||
| 5046 | 11 | public function setAndGet($key, $fallback = null) |
|
| 5057 | |||
| 5058 | /** |
||
| 5059 | * Shifts a specified value off the beginning of array. |
||
| 5060 | * |
||
| 5061 | * @return mixed |
||
| 5062 | * <p>(Mutable) A shifted element from the current array.</p> |
||
| 5063 | */ |
||
| 5064 | 5 | public function shift() |
|
| 5070 | |||
| 5071 | /** |
||
| 5072 | * Shuffle the current array. |
||
| 5073 | * |
||
| 5074 | * @param bool $secure <p>using a CSPRNG | @link https://paragonie.com/b/JvICXzh_jhLyt4y3</p> |
||
| 5075 | * @param array $array [optional] |
||
| 5076 | * |
||
| 5077 | * @return static |
||
| 5078 | * <p>(Immutable)</p> |
||
| 5079 | * |
||
| 5080 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 5081 | * @psalm-return static<TKey,T> |
||
| 5082 | * |
||
| 5083 | * @noinspection BadExceptionsProcessingInspection |
||
| 5084 | * @noinspection RandomApiMigrationInspection |
||
| 5085 | * @noinspection NonSecureShuffleUsageInspection |
||
| 5086 | */ |
||
| 5087 | 2 | public function shuffle(bool $secure = false, array $array = null): self |
|
| 5125 | |||
| 5126 | /** |
||
| 5127 | * Count the values from the current array. |
||
| 5128 | * |
||
| 5129 | * alias: for "Arrayy->count()" |
||
| 5130 | * |
||
| 5131 | * @param int $mode |
||
| 5132 | * |
||
| 5133 | * @return int |
||
| 5134 | */ |
||
| 5135 | 20 | public function size(int $mode = \COUNT_NORMAL): int |
|
| 5139 | |||
| 5140 | /** |
||
| 5141 | * Checks whether array has exactly $size items. |
||
| 5142 | * |
||
| 5143 | * @param int $size |
||
| 5144 | * |
||
| 5145 | * @return bool |
||
| 5146 | */ |
||
| 5147 | 1 | public function sizeIs(int $size): bool |
|
| 5162 | |||
| 5163 | /** |
||
| 5164 | * Checks whether array has between $fromSize to $toSize items. $toSize can be |
||
| 5165 | * smaller than $fromSize. |
||
| 5166 | * |
||
| 5167 | * @param int $fromSize |
||
| 5168 | * @param int $toSize |
||
| 5169 | * |
||
| 5170 | * @return bool |
||
| 5171 | */ |
||
| 5172 | 1 | public function sizeIsBetween(int $fromSize, int $toSize): bool |
|
| 5192 | |||
| 5193 | /** |
||
| 5194 | * Checks whether array has more than $size items. |
||
| 5195 | * |
||
| 5196 | * @param int $size |
||
| 5197 | * |
||
| 5198 | * @return bool |
||
| 5199 | */ |
||
| 5200 | 1 | View Code Duplication | public function sizeIsGreaterThan(int $size): bool |
| 5214 | |||
| 5215 | /** |
||
| 5216 | * Checks whether array has less than $size items. |
||
| 5217 | * |
||
| 5218 | * @param int $size |
||
| 5219 | * |
||
| 5220 | * @return bool |
||
| 5221 | */ |
||
| 5222 | 1 | View Code Duplication | public function sizeIsLessThan(int $size): bool |
| 5236 | |||
| 5237 | /** |
||
| 5238 | * Counts all elements in an array, or something in an object. |
||
| 5239 | * |
||
| 5240 | * <p> |
||
| 5241 | * For objects, if you have SPL installed, you can hook into count() by implementing interface {@see Countable}. |
||
| 5242 | * The interface has exactly one method, {@see Countable::count()}, which returns the return value for the count() |
||
| 5243 | * function. Please see the {@see Array} section of the manual for a detailed explanation of how arrays are |
||
| 5244 | * implemented and used in PHP. |
||
| 5245 | * </p> |
||
| 5246 | * |
||
| 5247 | * @return int |
||
| 5248 | * <p> |
||
| 5249 | * The number of elements in var, which is |
||
| 5250 | * typically an array, since anything else will have one |
||
| 5251 | * element. |
||
| 5252 | * </p> |
||
| 5253 | * <p> |
||
| 5254 | * If var is not an array or an object with |
||
| 5255 | * implemented Countable interface, |
||
| 5256 | * 1 will be returned. |
||
| 5257 | * There is one exception, if var is &null;, |
||
| 5258 | * 0 will be returned. |
||
| 5259 | * </p> |
||
| 5260 | * <p> |
||
| 5261 | * Caution: count may return 0 for a variable that isn't set, |
||
| 5262 | * but it may also return 0 for a variable that has been initialized with an |
||
| 5263 | * empty array. Use isset to test if a variable is set. |
||
| 5264 | * </p> |
||
| 5265 | */ |
||
| 5266 | 10 | public function sizeRecursive(): int |
|
| 5270 | |||
| 5271 | /** |
||
| 5272 | * Extract a slice of the array. |
||
| 5273 | * |
||
| 5274 | * @param int $offset <p>Slice begin index.</p> |
||
| 5275 | * @param int|null $length <p>Length of the slice.</p> |
||
| 5276 | * @param bool $preserveKeys <p>Whether array keys are preserved or no.</p> |
||
| 5277 | * |
||
| 5278 | * @return static |
||
| 5279 | * <p>(Immutable) A slice of the original array with length $length.</p> |
||
| 5280 | * |
||
| 5281 | * @psalm-return static<TKey,T> |
||
| 5282 | * @psalm-mutation-free |
||
| 5283 | */ |
||
| 5284 | 5 | public function slice(int $offset, int $length = null, bool $preserveKeys = false) |
|
| 5297 | |||
| 5298 | /** |
||
| 5299 | * Sort the current array and optional you can keep the keys. |
||
| 5300 | * |
||
| 5301 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 5302 | * @param int $strategy <p>sort_flags => use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 5303 | * <strong>SORT_NATURAL</strong></p> |
||
| 5304 | * @param bool $keepKeys |
||
| 5305 | * |
||
| 5306 | * @return static |
||
| 5307 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 5308 | * |
||
| 5309 | * @psalm-return static<TKey,T> |
||
| 5310 | */ |
||
| 5311 | 20 | public function sort( |
|
| 5325 | |||
| 5326 | /** |
||
| 5327 | * Sort the current array and optional you can keep the keys. |
||
| 5328 | * |
||
| 5329 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 5330 | * @param int $strategy <p>sort_flags => use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 5331 | * <strong>SORT_NATURAL</strong></p> |
||
| 5332 | * @param bool $keepKeys |
||
| 5333 | * |
||
| 5334 | * @return static |
||
| 5335 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 5336 | * |
||
| 5337 | * @psalm-return static<TKey,T> |
||
| 5338 | */ |
||
| 5339 | 12 | public function sortImmutable( |
|
| 5355 | |||
| 5356 | /** |
||
| 5357 | * Sort the current array by key. |
||
| 5358 | * |
||
| 5359 | * @see http://php.net/manual/en/function.ksort.php |
||
| 5360 | * @see http://php.net/manual/en/function.krsort.php |
||
| 5361 | * |
||
| 5362 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 5363 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 5364 | * <strong>SORT_NATURAL</strong></p> |
||
| 5365 | * |
||
| 5366 | * @return $this |
||
| 5367 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 5368 | * |
||
| 5369 | * @psalm-return static<TKey,T> |
||
| 5370 | */ |
||
| 5371 | 18 | public function sortKeys( |
|
| 5381 | |||
| 5382 | /** |
||
| 5383 | * Sort the current array by key. |
||
| 5384 | * |
||
| 5385 | * @see http://php.net/manual/en/function.ksort.php |
||
| 5386 | * @see http://php.net/manual/en/function.krsort.php |
||
| 5387 | * |
||
| 5388 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 5389 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 5390 | * <strong>SORT_NATURAL</strong></p> |
||
| 5391 | * |
||
| 5392 | * @return $this |
||
| 5393 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 5394 | * |
||
| 5395 | * @psalm-return static<TKey,T> |
||
| 5396 | * @psalm-mutation-free |
||
| 5397 | */ |
||
| 5398 | 8 | public function sortKeysImmutable( |
|
| 5411 | |||
| 5412 | /** |
||
| 5413 | * Sort the current array by value. |
||
| 5414 | * |
||
| 5415 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 5416 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 5417 | * <strong>SORT_NATURAL</strong></p> |
||
| 5418 | * |
||
| 5419 | * @return static |
||
| 5420 | * <p>(Mutable)</p> |
||
| 5421 | * |
||
| 5422 | * @psalm-return static<TKey,T> |
||
| 5423 | */ |
||
| 5424 | 1 | public function sortValueKeepIndex( |
|
| 5430 | |||
| 5431 | /** |
||
| 5432 | * Sort the current array by value. |
||
| 5433 | * |
||
| 5434 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 5435 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 5436 | * <strong>SORT_NATURAL</strong></p> |
||
| 5437 | * |
||
| 5438 | * @return static |
||
| 5439 | * <p>(Mutable)</p> |
||
| 5440 | * |
||
| 5441 | * @psalm-return static<TKey,T> |
||
| 5442 | */ |
||
| 5443 | 1 | public function sortValueNewIndex($direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
| 5447 | |||
| 5448 | /** |
||
| 5449 | * Sort a array by value, by a closure or by a property. |
||
| 5450 | * |
||
| 5451 | * - If the sorter is null, the array is sorted naturally. |
||
| 5452 | * - Associative (string) keys will be maintained, but numeric keys will be re-indexed. |
||
| 5453 | * |
||
| 5454 | * @param callable|string|null $sorter |
||
| 5455 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or |
||
| 5456 | * <strong>SORT_DESC</strong></p> |
||
| 5457 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 5458 | * <strong>SORT_NATURAL</strong></p> |
||
| 5459 | * |
||
| 5460 | * @return static |
||
| 5461 | * <p>(Immutable)</p> |
||
| 5462 | * |
||
| 5463 | * @psalm-return static<TKey,T> |
||
| 5464 | * @psalm-mutation-free |
||
| 5465 | */ |
||
| 5466 | 1 | public function sorter($sorter = null, $direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
| 5507 | |||
| 5508 | /** |
||
| 5509 | * @param int $offset |
||
| 5510 | * @param int|null $length |
||
| 5511 | * @param array $replacement |
||
| 5512 | * |
||
| 5513 | * @return static |
||
| 5514 | * <p>(Immutable)</p> |
||
| 5515 | * |
||
| 5516 | * @psalm-param array<mixed,mixed>|array<mixed,T> $replacement |
||
| 5517 | * @psalm-return static<TKey,T> |
||
| 5518 | * @psalm-mutation-free |
||
| 5519 | */ |
||
| 5520 | 1 | public function splice(int $offset, int $length = null, $replacement = []): self |
|
| 5537 | |||
| 5538 | /** |
||
| 5539 | * Split an array in the given amount of pieces. |
||
| 5540 | * |
||
| 5541 | * @param int $numberOfPieces |
||
| 5542 | * @param bool $keepKeys |
||
| 5543 | * |
||
| 5544 | * @return static |
||
| 5545 | * <p>(Immutable)</p> |
||
| 5546 | * |
||
| 5547 | * @psalm-return static<TKey,T> |
||
| 5548 | * @psalm-mutation-free |
||
| 5549 | */ |
||
| 5550 | 1 | public function split(int $numberOfPieces = 2, bool $keepKeys = false): self |
|
| 5569 | |||
| 5570 | /** |
||
| 5571 | * Stripe all empty items. |
||
| 5572 | * |
||
| 5573 | * @return static |
||
| 5574 | * <p>(Immutable)</p> |
||
| 5575 | * |
||
| 5576 | * @psalm-return static<TKey,T> |
||
| 5577 | * @psalm-mutation-free |
||
| 5578 | */ |
||
| 5579 | 1 | public function stripEmpty(): self |
|
| 5591 | |||
| 5592 | /** |
||
| 5593 | * Swap two values between positions by key. |
||
| 5594 | * |
||
| 5595 | * @param int|string $swapA <p>a key in the array</p> |
||
| 5596 | * @param int|string $swapB <p>a key in the array</p> |
||
| 5597 | * |
||
| 5598 | * @return static |
||
| 5599 | * <p>(Immutable)</p> |
||
| 5600 | * |
||
| 5601 | * @psalm-return static<TKey,T> |
||
| 5602 | * @psalm-mutation-free |
||
| 5603 | */ |
||
| 5604 | 1 | public function swap($swapA, $swapB): self |
|
| 5616 | |||
| 5617 | /** |
||
| 5618 | * Get the current array from the "Arrayy"-object. |
||
| 5619 | * alias for "getArray()" |
||
| 5620 | * |
||
| 5621 | * @param bool $convertAllArrayyElements <p> |
||
| 5622 | * Convert all Child-"Arrayy" objects also to arrays. |
||
| 5623 | * </p> |
||
| 5624 | * @param bool $preserveKeys <p> |
||
| 5625 | * e.g.: A generator maybe return the same key more then once, |
||
| 5626 | * so maybe you will ignore the keys. |
||
| 5627 | * </p> |
||
| 5628 | * |
||
| 5629 | * @return array |
||
| 5630 | * |
||
| 5631 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 5632 | * @psalm-mutation-free |
||
| 5633 | */ |
||
| 5634 | 937 | public function toArray( |
|
| 5659 | |||
| 5660 | /** |
||
| 5661 | * Get the current array from the "Arrayy"-object as list. |
||
| 5662 | * |
||
| 5663 | * @param bool $convertAllArrayyElements <p> |
||
| 5664 | * Convert all Child-"Arrayy" objects also to arrays. |
||
| 5665 | * </p> |
||
| 5666 | * |
||
| 5667 | * @return array |
||
| 5668 | * |
||
| 5669 | * @psalm-return list<array<TKey,T>> |
||
| 5670 | * @psalm-mutation-free |
||
| 5671 | */ |
||
| 5672 | 1 | public function toList(bool $convertAllArrayyElements = false): array |
|
| 5679 | |||
| 5680 | /** |
||
| 5681 | * Convert the current array to JSON. |
||
| 5682 | * |
||
| 5683 | * @param int $options [optional] <p>e.g. JSON_PRETTY_PRINT</p> |
||
| 5684 | * @param int $depth [optional] <p>Set the maximum depth. Must be greater than zero.</p> |
||
| 5685 | * |
||
| 5686 | * @return string |
||
| 5687 | */ |
||
| 5688 | 11 | public function toJson(int $options = 0, int $depth = 512): string |
|
| 5697 | |||
| 5698 | /** |
||
| 5699 | * @param string[]|null $items [optional] |
||
| 5700 | * @param string[] $helper [optional] |
||
| 5701 | * |
||
| 5702 | * @return static|static[] |
||
| 5703 | * |
||
| 5704 | * @psalm-return static<int, static<TKey,T>> |
||
| 5705 | */ |
||
| 5706 | 1 | public function toPermutation(array $items = null, array $helper = []): self |
|
| 5740 | |||
| 5741 | /** |
||
| 5742 | * Implodes array to a string with specified separator. |
||
| 5743 | * |
||
| 5744 | * @param string $separator [optional] <p>The element's separator.</p> |
||
| 5745 | * |
||
| 5746 | * @return string |
||
| 5747 | * <p>The string representation of array, separated by ",".</p> |
||
| 5748 | */ |
||
| 5749 | 19 | public function toString(string $separator = ','): string |
|
| 5753 | |||
| 5754 | /** |
||
| 5755 | * Return a duplicate free copy of the current array. |
||
| 5756 | * |
||
| 5757 | * @return $this |
||
| 5758 | * <p>(Mutable)</p> |
||
| 5759 | * |
||
| 5760 | * @psalm-return static<TKey,T> |
||
| 5761 | */ |
||
| 5762 | 13 | public function unique(): self |
|
| 5784 | |||
| 5785 | /** |
||
| 5786 | * Return a duplicate free copy of the current array. (with the old keys) |
||
| 5787 | * |
||
| 5788 | * @return $this |
||
| 5789 | * <p>(Mutable)</p> |
||
| 5790 | * |
||
| 5791 | * @psalm-return static<TKey,T> |
||
| 5792 | */ |
||
| 5793 | 11 | public function uniqueKeepIndex(): self |
|
| 5819 | |||
| 5820 | /** |
||
| 5821 | * alias: for "Arrayy->unique()" |
||
| 5822 | * |
||
| 5823 | * @return static |
||
| 5824 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
| 5825 | * |
||
| 5826 | * @see Arrayy::unique() |
||
| 5827 | * |
||
| 5828 | * @psalm-return static<TKey,T> |
||
| 5829 | */ |
||
| 5830 | 10 | public function uniqueNewIndex(): self |
|
| 5834 | |||
| 5835 | /** |
||
| 5836 | * Prepends one or more values to the beginning of array at once. |
||
| 5837 | * |
||
| 5838 | * @param array ...$args |
||
| 5839 | * |
||
| 5840 | * @return $this |
||
| 5841 | * <p>(Mutable) Return this Arrayy object, with prepended elements to the beginning of array.</p> |
||
| 5842 | * |
||
| 5843 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$args |
||
| 5844 | * @psalm-return static<TKey,T> |
||
| 5845 | */ |
||
| 5846 | 4 | public function unshift(...$args): self |
|
| 5854 | |||
| 5855 | /** |
||
| 5856 | * Tests whether the given closure return something valid for all elements of this array. |
||
| 5857 | * |
||
| 5858 | * @param \Closure $closure the predicate |
||
| 5859 | * |
||
| 5860 | * @return bool |
||
| 5861 | * <p>TRUE, if the predicate yields TRUE for all elements, FALSE otherwise.</p> |
||
| 5862 | */ |
||
| 5863 | 1 | View Code Duplication | public function validate(\Closure $closure): bool |
| 5873 | |||
| 5874 | /** |
||
| 5875 | * Get all values from a array. |
||
| 5876 | * |
||
| 5877 | * @return static |
||
| 5878 | * <p>(Immutable)</p> |
||
| 5879 | * |
||
| 5880 | * @psalm-return static<TKey,T> |
||
| 5881 | * @psalm-mutation-free |
||
| 5882 | */ |
||
| 5883 | 2 | public function values(): self |
|
| 5896 | |||
| 5897 | /** |
||
| 5898 | * Apply the given function to every element in the array, discarding the results. |
||
| 5899 | * |
||
| 5900 | * @param callable $callable |
||
| 5901 | * @param bool $recursive <p>Whether array will be walked recursively or no</p> |
||
| 5902 | * |
||
| 5903 | * @return $this |
||
| 5904 | * <p>(Mutable) Return this Arrayy object, with modified elements.</p> |
||
| 5905 | * |
||
| 5906 | * @psalm-return static<TKey,T> |
||
| 5907 | */ |
||
| 5908 | 12 | public function walk($callable, bool $recursive = false): self |
|
| 5922 | |||
| 5923 | /** |
||
| 5924 | * Returns a collection of matching items. |
||
| 5925 | * |
||
| 5926 | * @param string $keyOrPropertyOrMethod the property or method to evaluate |
||
| 5927 | * @param mixed $value the value to match |
||
| 5928 | * |
||
| 5929 | * @throws \InvalidArgumentException if property or method is not defined |
||
| 5930 | * |
||
| 5931 | * @return static |
||
| 5932 | * |
||
| 5933 | * @psalm-param T $value |
||
| 5934 | * @psalm-return static<TKey,T> |
||
| 5935 | */ |
||
| 5936 | 1 | public function where(string $keyOrPropertyOrMethod, $value): self |
|
| 5949 | |||
| 5950 | /** |
||
| 5951 | * Convert an array into a object. |
||
| 5952 | * |
||
| 5953 | * @param array $array |
||
| 5954 | * |
||
| 5955 | * @return \stdClass |
||
| 5956 | * |
||
| 5957 | * @psalm-param array<mixed,mixed> $array |
||
| 5958 | */ |
||
| 5959 | 4 | final protected static function arrayToObject(array $array = []): \stdClass |
|
| 5978 | |||
| 5979 | /** |
||
| 5980 | * @param array|\Generator|null $input <p> |
||
| 5981 | * An array containing keys to return. |
||
| 5982 | * </p> |
||
| 5983 | * @param mixed|null $search_values [optional] <p> |
||
| 5984 | * If specified, then only keys containing these values are returned. |
||
| 5985 | * </p> |
||
| 5986 | * @param bool $strict [optional] <p> |
||
| 5987 | * Determines if strict comparison (===) should be used during the |
||
| 5988 | * search. |
||
| 5989 | * </p> |
||
| 5990 | * |
||
| 5991 | * @return array |
||
| 5992 | * <p>an array of all the keys in input</p> |
||
| 5993 | * |
||
| 5994 | * @psalm-param array<mixed,mixed>|\Generator<TKey,T>|null $input |
||
| 5995 | * @psalm-return array<TKey|mixed> |
||
| 5996 | * @psalm-mutation-free |
||
| 5997 | */ |
||
| 5998 | 11 | protected function array_keys_recursive( |
|
| 6059 | |||
| 6060 | /** |
||
| 6061 | * @param mixed $path |
||
| 6062 | * @param callable $callable |
||
| 6063 | * @param array|null $currentOffset |
||
| 6064 | * |
||
| 6065 | * @return void |
||
| 6066 | * |
||
| 6067 | * @psalm-param array<mixed,mixed>|array<TKey,T>|null $currentOffset |
||
| 6068 | * @psalm-mutation-free |
||
| 6069 | */ |
||
| 6070 | 11 | protected function callAtPath($path, $callable, &$currentOffset = null) |
|
| 6099 | |||
| 6100 | /** |
||
| 6101 | * Extracts the value of the given property or method from the object. |
||
| 6102 | * |
||
| 6103 | * @param static $object <p>The object to extract the value from.</p> |
||
| 6104 | * @param string $keyOrPropertyOrMethod <p>The property or method for which the |
||
| 6105 | * value should be extracted.</p> |
||
| 6106 | * |
||
| 6107 | * @throws \InvalidArgumentException if the method or property is not defined |
||
| 6108 | * |
||
| 6109 | * @return mixed |
||
| 6110 | * <p>The value extracted from the specified property or method.</p> |
||
| 6111 | * |
||
| 6112 | * @psalm-param self<TKey,T> $object |
||
| 6113 | */ |
||
| 6114 | 2 | final protected function extractValue(self $object, string $keyOrPropertyOrMethod) |
|
| 6136 | |||
| 6137 | /** |
||
| 6138 | * create a fallback for array |
||
| 6139 | * |
||
| 6140 | * 1. use the current array, if it's a array |
||
| 6141 | * 2. fallback to empty array, if there is nothing |
||
| 6142 | * 3. call "getArray()" on object, if there is a "Arrayy"-object |
||
| 6143 | * 4. call "createFromObject()" on object, if there is a "\Traversable"-object |
||
| 6144 | * 5. call "__toArray()" on object, if the method exists |
||
| 6145 | * 6. cast a string or object with "__toString()" into an array |
||
| 6146 | * 7. throw a "InvalidArgumentException"-Exception |
||
| 6147 | * |
||
| 6148 | * @param mixed $data |
||
| 6149 | * |
||
| 6150 | * @throws \InvalidArgumentException |
||
| 6151 | * |
||
| 6152 | * @return array |
||
| 6153 | * |
||
| 6154 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 6155 | */ |
||
| 6156 | 1185 | protected function fallbackForArray(&$data): array |
|
| 6166 | |||
| 6167 | /** |
||
| 6168 | * @param bool $preserveKeys <p> |
||
| 6169 | * e.g.: A generator maybe return the same key more then once, |
||
| 6170 | * so maybe you will ignore the keys. |
||
| 6171 | * </p> |
||
| 6172 | * |
||
| 6173 | * @return bool |
||
| 6174 | * |
||
| 6175 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
| 6176 | * @psalm-mutation-free :/ |
||
| 6177 | */ |
||
| 6178 | 1097 | protected function generatorToArray(bool $preserveKeys = true) |
|
| 6189 | |||
| 6190 | /** |
||
| 6191 | * Get correct PHP constant for direction. |
||
| 6192 | * |
||
| 6193 | * @param int|string $direction |
||
| 6194 | * |
||
| 6195 | * @return int |
||
| 6196 | * @psalm-mutation-free |
||
| 6197 | */ |
||
| 6198 | 43 | protected function getDirection($direction): int |
|
| 6220 | |||
| 6221 | /** |
||
| 6222 | * @return TypeCheckInterface[] |
||
| 6223 | * |
||
| 6224 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
| 6225 | */ |
||
| 6226 | 16 | protected function getPropertiesFromPhpDoc() |
|
| 6257 | |||
| 6258 | /** |
||
| 6259 | * @param mixed $glue |
||
| 6260 | * @param mixed $pieces |
||
| 6261 | * @param bool $useKeys |
||
| 6262 | * |
||
| 6263 | * @return string |
||
| 6264 | * @psalm-mutation-free |
||
| 6265 | */ |
||
| 6266 | 36 | protected function implode_recursive( |
|
| 6299 | |||
| 6300 | /** |
||
| 6301 | * @param mixed $needle <p> |
||
| 6302 | * The searched value. |
||
| 6303 | * </p> |
||
| 6304 | * <p> |
||
| 6305 | * If needle is a string, the comparison is done |
||
| 6306 | * in a case-sensitive manner. |
||
| 6307 | * </p> |
||
| 6308 | * @param array|\Generator|null $haystack <p> |
||
| 6309 | * The array. |
||
| 6310 | * </p> |
||
| 6311 | * @param bool $strict [optional] <p> |
||
| 6312 | * If the third parameter strict is set to true |
||
| 6313 | * then the in_array function will also check the |
||
| 6314 | * types of the |
||
| 6315 | * needle in the haystack. |
||
| 6316 | * </p> |
||
| 6317 | * |
||
| 6318 | * @return bool |
||
| 6319 | * <p>true if needle is found in the array, false otherwise</p> |
||
| 6320 | * |
||
| 6321 | * @psalm-param array<mixed,mixed>|\Generator<TKey,T>|null $haystack |
||
| 6322 | * @psalm-mutation-free |
||
| 6323 | */ |
||
| 6324 | 19 | protected function in_array_recursive($needle, $haystack = null, $strict = true): bool |
|
| 6349 | |||
| 6350 | /** |
||
| 6351 | * @param mixed $data |
||
| 6352 | * |
||
| 6353 | * @return array|null |
||
| 6354 | * |
||
| 6355 | * @psalm-return array<mixed,mixed>|array<TKey,T>|null |
||
| 6356 | */ |
||
| 6357 | 1185 | protected function internalGetArray(&$data) |
|
| 6408 | |||
| 6409 | /** |
||
| 6410 | * Internal mechanics of remove method. |
||
| 6411 | * |
||
| 6412 | * @param mixed $key |
||
| 6413 | * |
||
| 6414 | * @return bool |
||
| 6415 | */ |
||
| 6416 | 21 | protected function internalRemove($key): bool |
|
| 6449 | |||
| 6450 | /** |
||
| 6451 | * Internal mechanic of set method. |
||
| 6452 | * |
||
| 6453 | * @param int|string|null $key |
||
| 6454 | * @param mixed $value |
||
| 6455 | * @param bool $checkProperties |
||
| 6456 | * |
||
| 6457 | * @return bool |
||
| 6458 | */ |
||
| 6459 | 1036 | protected function internalSet( |
|
| 6518 | |||
| 6519 | /** |
||
| 6520 | * Convert a object into an array. |
||
| 6521 | * |
||
| 6522 | * @param mixed|object $object |
||
| 6523 | * |
||
| 6524 | * @return array|mixed |
||
| 6525 | * |
||
| 6526 | * @psalm-mutation-free |
||
| 6527 | */ |
||
| 6528 | 5 | protected static function objectToArray($object) |
|
| 6541 | |||
| 6542 | /** |
||
| 6543 | * @param array $data |
||
| 6544 | * @param bool $checkPropertiesInConstructor |
||
| 6545 | * |
||
| 6546 | * @return void |
||
| 6547 | * |
||
| 6548 | * @psalm-param array<mixed,T> $data |
||
| 6549 | */ |
||
| 6550 | 1183 | protected function setInitialValuesAndProperties(array &$data, bool $checkPropertiesInConstructor) |
|
| 6595 | |||
| 6596 | /** |
||
| 6597 | * sorting keys |
||
| 6598 | * |
||
| 6599 | * @param array $elements |
||
| 6600 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 6601 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 6602 | * <strong>SORT_NATURAL</strong></p> |
||
| 6603 | * |
||
| 6604 | * @return $this |
||
| 6605 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 6606 | * |
||
| 6607 | * @psalm-param array<mixed,mixed>|array<mixed|TKey,T> $elements |
||
| 6608 | * @psalm-return static<TKey,T> |
||
| 6609 | */ |
||
| 6610 | 18 | protected function sorterKeys( |
|
| 6631 | |||
| 6632 | /** |
||
| 6633 | * @param array $elements <p>Warning: used as reference</p> |
||
| 6634 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 6635 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 6636 | * <strong>SORT_NATURAL</strong></p> |
||
| 6637 | * @param bool $keepKeys |
||
| 6638 | * |
||
| 6639 | * @return $this |
||
| 6640 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 6641 | * |
||
| 6642 | * @psalm-param array<mixed,mixed>|array<mixed|TKey,T> $elements |
||
| 6643 | * @psalm-return static<TKey,T> |
||
| 6644 | */ |
||
| 6645 | 24 | protected function sorting(array &$elements, $direction = \SORT_ASC, int $strategy = \SORT_REGULAR, bool $keepKeys = false): self |
|
| 6675 | |||
| 6676 | /** |
||
| 6677 | * @param array $array |
||
| 6678 | * |
||
| 6679 | * @return array |
||
| 6680 | * |
||
| 6681 | * @psalm-mutation-free |
||
| 6682 | */ |
||
| 6683 | 25 | private function getArrayRecursiveHelperArrayy(array $array) |
|
| 6705 | |||
| 6706 | /** |
||
| 6707 | * @param int|string|null $key |
||
| 6708 | * @param mixed $value |
||
| 6709 | * |
||
| 6710 | * @return void |
||
| 6711 | */ |
||
| 6712 | 99 | private function checkType($key, $value) |
|
| 6730 | } |
||
| 6731 |
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..