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 | 1197 | 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 | 3 | 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 | 8 | 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 | 13 | 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 | 20 | 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 | 148 | 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 | 27 | 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 | 26 | 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 | 10 | 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 | 157 | 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 | 126 | 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 | 26 | 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 | 1188 | 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 | 716 | 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 | 23 | 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 | 30 | 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 | 241 | public function get($key, $fallback = null, array $array = null) |
|
| 2562 | |||
| 2563 | /** |
||
| 2564 | * alias: for "Arrayy->toArray()" |
||
| 2565 | * |
||
| 2566 | * @return array |
||
| 2567 | * |
||
| 2568 | * @see Arrayy::getArray() |
||
| 2569 | * |
||
| 2570 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 2571 | */ |
||
| 2572 | 15 | public function getAll(): array |
|
| 2576 | |||
| 2577 | /** |
||
| 2578 | * Get the current array from the "Arrayy"-object. |
||
| 2579 | * |
||
| 2580 | * alias for "toArray()" |
||
| 2581 | * |
||
| 2582 | * @param bool $convertAllArrayyElements <p> |
||
| 2583 | * Convert all Child-"Arrayy" objects also to arrays. |
||
| 2584 | * </p> |
||
| 2585 | * @param bool $preserveKeys <p> |
||
| 2586 | * e.g.: A generator maybe return the same key more then once, |
||
| 2587 | * so maybe you will ignore the keys. |
||
| 2588 | * </p> |
||
| 2589 | * |
||
| 2590 | * @return array |
||
| 2591 | * |
||
| 2592 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 2593 | * @psalm-mutation-free |
||
| 2594 | * |
||
| 2595 | * @see Arrayy::toArray() |
||
| 2596 | */ |
||
| 2597 | 499 | public function getArray( |
|
| 2606 | |||
| 2607 | /** |
||
| 2608 | * @param string $json |
||
| 2609 | * |
||
| 2610 | * @return $this |
||
| 2611 | */ |
||
| 2612 | 3 | public static function createFromJsonMapper(string $json) |
|
| 2628 | |||
| 2629 | /** |
||
| 2630 | * @return array<int|string,TypeCheckInterface>|mixed|TypeCheckArray<int|string,TypeCheckInterface>|TypeInterface |
||
| 2631 | * |
||
| 2632 | * @internal |
||
| 2633 | */ |
||
| 2634 | 6 | public function getPhpDocPropertiesFromClass() |
|
| 2642 | |||
| 2643 | /** |
||
| 2644 | * Get the current array from the "Arrayy"-object as list. |
||
| 2645 | * |
||
| 2646 | * alias for "toList()" |
||
| 2647 | * |
||
| 2648 | * @param bool $convertAllArrayyElements <p> |
||
| 2649 | * Convert all Child-"Arrayy" objects also to arrays. |
||
| 2650 | * </p> |
||
| 2651 | * |
||
| 2652 | * @return array |
||
| 2653 | * |
||
| 2654 | * @psalm-return array<int,mixed>|array<int,T> |
||
| 2655 | * @psalm-mutation-free |
||
| 2656 | * |
||
| 2657 | * @see Arrayy::toList() |
||
| 2658 | */ |
||
| 2659 | 1 | public function getList(bool $convertAllArrayyElements = false): array |
|
| 2663 | |||
| 2664 | /** |
||
| 2665 | * Returns the values from a single column of the input array, identified by |
||
| 2666 | * the $columnKey, can be used to extract data-columns from multi-arrays. |
||
| 2667 | * |
||
| 2668 | * Info: Optionally, you may provide an $indexKey to index the values in the returned |
||
| 2669 | * array by the values from the $indexKey column in the input array. |
||
| 2670 | * |
||
| 2671 | * @param mixed $columnKey |
||
| 2672 | * @param mixed $indexKey |
||
| 2673 | * |
||
| 2674 | * @return static |
||
| 2675 | * <p>(Immutable)</p> |
||
| 2676 | * |
||
| 2677 | * @psalm-return static<TKey,T> |
||
| 2678 | * @psalm-mutation-free |
||
| 2679 | */ |
||
| 2680 | 1 | public function getColumn($columnKey = null, $indexKey = null): self |
|
| 2688 | |||
| 2689 | /** |
||
| 2690 | * Get the current array from the "Arrayy"-object as generator by reference. |
||
| 2691 | * |
||
| 2692 | * @return \Generator |
||
| 2693 | * |
||
| 2694 | * @psalm-return \Generator<mixed,T>|\Generator<TKey,T> |
||
| 2695 | */ |
||
| 2696 | 75 | public function &getGeneratorByReference(): \Generator |
|
| 2714 | |||
| 2715 | /** |
||
| 2716 | * Get the current array from the "Arrayy"-object as generator. |
||
| 2717 | * |
||
| 2718 | * @return \Generator |
||
| 2719 | * |
||
| 2720 | * @psalm-return \Generator<mixed,T>|\Generator<TKey,T> |
||
| 2721 | * @psalm-mutation-free |
||
| 2722 | */ |
||
| 2723 | 995 | public function getGenerator(): \Generator |
|
| 2733 | |||
| 2734 | /** |
||
| 2735 | * alias: for "Arrayy->keys()" |
||
| 2736 | * |
||
| 2737 | * @return static |
||
| 2738 | * <p>(Immutable)</p> |
||
| 2739 | * |
||
| 2740 | * @see Arrayy::keys() |
||
| 2741 | * |
||
| 2742 | * @psalm-return static<array-key,TKey> |
||
| 2743 | * @psalm-mutation-free |
||
| 2744 | */ |
||
| 2745 | 2 | public function getKeys() |
|
| 2749 | |||
| 2750 | /** |
||
| 2751 | * Get the current array from the "Arrayy"-object as object. |
||
| 2752 | * |
||
| 2753 | * @return \stdClass |
||
| 2754 | */ |
||
| 2755 | 4 | public function getObject(): \stdClass |
|
| 2759 | |||
| 2760 | /** |
||
| 2761 | * alias: for "Arrayy->randomImmutable()" |
||
| 2762 | * |
||
| 2763 | * @return static |
||
| 2764 | * <p>(Immutable)</p> |
||
| 2765 | * |
||
| 2766 | * @see Arrayy::randomImmutable() |
||
| 2767 | * |
||
| 2768 | * @psalm-return static<int|array-key,T> |
||
| 2769 | */ |
||
| 2770 | 4 | public function getRandom(): self |
|
| 2774 | |||
| 2775 | /** |
||
| 2776 | * alias: for "Arrayy->randomKey()" |
||
| 2777 | * |
||
| 2778 | * @return mixed |
||
| 2779 | * <p>Get a key/index or null if there wasn't a key/index.</p> |
||
| 2780 | * |
||
| 2781 | * @see Arrayy::randomKey() |
||
| 2782 | */ |
||
| 2783 | 3 | public function getRandomKey() |
|
| 2787 | |||
| 2788 | /** |
||
| 2789 | * alias: for "Arrayy->randomKeys()" |
||
| 2790 | * |
||
| 2791 | * @param int $number |
||
| 2792 | * |
||
| 2793 | * @return static |
||
| 2794 | * <p>(Immutable)</p> |
||
| 2795 | * |
||
| 2796 | * @see Arrayy::randomKeys() |
||
| 2797 | * |
||
| 2798 | * @psalm-return static<TKey,T> |
||
| 2799 | */ |
||
| 2800 | 8 | public function getRandomKeys(int $number): self |
|
| 2804 | |||
| 2805 | /** |
||
| 2806 | * alias: for "Arrayy->randomValue()" |
||
| 2807 | * |
||
| 2808 | * @return mixed |
||
| 2809 | * <p>Get a random value or null if there wasn't a value.</p> |
||
| 2810 | * |
||
| 2811 | * @see Arrayy::randomValue() |
||
| 2812 | */ |
||
| 2813 | 3 | public function getRandomValue() |
|
| 2817 | |||
| 2818 | /** |
||
| 2819 | * alias: for "Arrayy->randomValues()" |
||
| 2820 | * |
||
| 2821 | * @param int $number |
||
| 2822 | * |
||
| 2823 | * @return static |
||
| 2824 | * <p>(Immutable)</p> |
||
| 2825 | * |
||
| 2826 | * @see Arrayy::randomValues() |
||
| 2827 | * |
||
| 2828 | * @psalm-return static<TKey,T> |
||
| 2829 | */ |
||
| 2830 | 6 | public function getRandomValues(int $number): self |
|
| 2834 | |||
| 2835 | /** |
||
| 2836 | * Gets all values. |
||
| 2837 | * |
||
| 2838 | * @return static |
||
| 2839 | * <p>The values of all elements in this array, in the order they |
||
| 2840 | * appear in the array.</p> |
||
| 2841 | * |
||
| 2842 | * @psalm-return static<TKey,T> |
||
| 2843 | */ |
||
| 2844 | 4 | public function getValues() |
|
| 2854 | |||
| 2855 | /** |
||
| 2856 | * Gets all values via Generator. |
||
| 2857 | * |
||
| 2858 | * @return \Generator |
||
| 2859 | * <p>The values of all elements in this array, in the order they |
||
| 2860 | * appear in the array as Generator.</p> |
||
| 2861 | * |
||
| 2862 | * @psalm-return \Generator<TKey,T> |
||
| 2863 | */ |
||
| 2864 | 4 | public function getValuesYield(): \Generator |
|
| 2868 | |||
| 2869 | /** |
||
| 2870 | * Group values from a array according to the results of a closure. |
||
| 2871 | * |
||
| 2872 | * @param callable|string $grouper <p>A callable function name.</p> |
||
| 2873 | * @param bool $saveKeys |
||
| 2874 | * |
||
| 2875 | * @return static |
||
| 2876 | * <p>(Immutable)</p> |
||
| 2877 | * |
||
| 2878 | * @psalm-return static<TKey,T> |
||
| 2879 | * @psalm-mutation-free |
||
| 2880 | */ |
||
| 2881 | 4 | public function group($grouper, bool $saveKeys = false): self |
|
| 2922 | |||
| 2923 | /** |
||
| 2924 | * Check if an array has a given key. |
||
| 2925 | * |
||
| 2926 | * @param mixed $key |
||
| 2927 | * |
||
| 2928 | * @return bool |
||
| 2929 | */ |
||
| 2930 | 30 | public function has($key): bool |
|
| 2956 | |||
| 2957 | /** |
||
| 2958 | * Check if an array has a given value. |
||
| 2959 | * |
||
| 2960 | * INFO: if you need to search recursive please use ```contains()``` |
||
| 2961 | * |
||
| 2962 | * @param mixed $value |
||
| 2963 | * |
||
| 2964 | * @return bool |
||
| 2965 | */ |
||
| 2966 | 1 | public function hasValue($value): bool |
|
| 2970 | |||
| 2971 | /** |
||
| 2972 | * Implodes the values of this array. |
||
| 2973 | * |
||
| 2974 | * @param string $glue |
||
| 2975 | * |
||
| 2976 | * @return string |
||
| 2977 | * @psalm-mutation-free |
||
| 2978 | */ |
||
| 2979 | 28 | public function implode(string $glue = ''): string |
|
| 2983 | |||
| 2984 | /** |
||
| 2985 | * Implodes the keys of this array. |
||
| 2986 | * |
||
| 2987 | * @param string $glue |
||
| 2988 | * |
||
| 2989 | * @return string |
||
| 2990 | * @psalm-mutation-free |
||
| 2991 | */ |
||
| 2992 | 8 | public function implodeKeys(string $glue = ''): string |
|
| 2996 | |||
| 2997 | /** |
||
| 2998 | * Given a list and an iterate-function that returns |
||
| 2999 | * a key for each element in the list (or a property name), |
||
| 3000 | * returns an object with an index of each item. |
||
| 3001 | * |
||
| 3002 | * @param mixed $key |
||
| 3003 | * |
||
| 3004 | * @return static |
||
| 3005 | * <p>(Immutable)</p> |
||
| 3006 | * |
||
| 3007 | * @psalm-return static<TKey,T> |
||
| 3008 | * @psalm-mutation-free |
||
| 3009 | */ |
||
| 3010 | 4 | public function indexBy($key): self |
|
| 3027 | |||
| 3028 | /** |
||
| 3029 | * alias: for "Arrayy->searchIndex()" |
||
| 3030 | * |
||
| 3031 | * @param mixed $value <p>The value to search for.</p> |
||
| 3032 | * |
||
| 3033 | * @return false|mixed |
||
| 3034 | * |
||
| 3035 | * @see Arrayy::searchIndex() |
||
| 3036 | */ |
||
| 3037 | 4 | public function indexOf($value) |
|
| 3041 | |||
| 3042 | /** |
||
| 3043 | * Get everything but the last..$to items. |
||
| 3044 | * |
||
| 3045 | * @param int $to |
||
| 3046 | * |
||
| 3047 | * @return static |
||
| 3048 | * <p>(Immutable)</p> |
||
| 3049 | * |
||
| 3050 | * @psalm-return static<TKey,T> |
||
| 3051 | * @psalm-mutation-free |
||
| 3052 | */ |
||
| 3053 | 12 | public function initial(int $to = 1): self |
|
| 3057 | |||
| 3058 | /** |
||
| 3059 | * Return an array with all elements found in input array. |
||
| 3060 | * |
||
| 3061 | * @param array $search |
||
| 3062 | * @param bool $keepKeys |
||
| 3063 | * |
||
| 3064 | * @return static |
||
| 3065 | * <p>(Immutable)</p> |
||
| 3066 | * |
||
| 3067 | * @psalm-param array<mixed,mixed>|array<TKey,T> $search |
||
| 3068 | * @psalm-return static<TKey,T> |
||
| 3069 | * @psalm-mutation-free |
||
| 3070 | */ |
||
| 3071 | 4 | public function intersection(array $search, bool $keepKeys = false): self |
|
| 3097 | |||
| 3098 | /** |
||
| 3099 | * Return an array with all elements found in input array. |
||
| 3100 | * |
||
| 3101 | * @param array ...$array |
||
| 3102 | * |
||
| 3103 | * @return static |
||
| 3104 | * <p>(Immutable)</p> |
||
| 3105 | * |
||
| 3106 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$array |
||
| 3107 | * @psalm-return static<TKey,T> |
||
| 3108 | * @psalm-mutation-free |
||
| 3109 | */ |
||
| 3110 | 1 | public function intersectionMulti(...$array): self |
|
| 3118 | |||
| 3119 | /** |
||
| 3120 | * Return a boolean flag which indicates whether the two input arrays have any common elements. |
||
| 3121 | * |
||
| 3122 | * @param array $search |
||
| 3123 | * |
||
| 3124 | * @return bool |
||
| 3125 | * |
||
| 3126 | * @psalm-param array<mixed,mixed>|array<TKey,T> $search |
||
| 3127 | */ |
||
| 3128 | 1 | public function intersects(array $search): bool |
|
| 3132 | |||
| 3133 | /** |
||
| 3134 | * Invoke a function on all of an array's values. |
||
| 3135 | * |
||
| 3136 | * @param callable $callable |
||
| 3137 | * @param mixed $arguments |
||
| 3138 | * |
||
| 3139 | * @return static |
||
| 3140 | * <p>(Immutable)</p> |
||
| 3141 | * |
||
| 3142 | * @psalm-param callable(T=,mixed):mixed $callable |
||
| 3143 | * @psalm-return static<TKey,T> |
||
| 3144 | * @psalm-mutation-free |
||
| 3145 | */ |
||
| 3146 | 1 | View Code Duplication | public function invoke($callable, $arguments = []): self |
| 3170 | |||
| 3171 | /** |
||
| 3172 | * Check whether array is associative or not. |
||
| 3173 | * |
||
| 3174 | * @param bool $recursive |
||
| 3175 | * |
||
| 3176 | * @return bool |
||
| 3177 | * <p>Returns true if associative, false otherwise.</p> |
||
| 3178 | */ |
||
| 3179 | 15 | View Code Duplication | public function isAssoc(bool $recursive = false): bool |
| 3193 | |||
| 3194 | /** |
||
| 3195 | * Check if a given key or keys are empty. |
||
| 3196 | * |
||
| 3197 | * @param int|int[]|string|string[]|null $keys |
||
| 3198 | * |
||
| 3199 | * @return bool |
||
| 3200 | * <p>Returns true if empty, false otherwise.</p> |
||
| 3201 | * @psalm-mutation-free |
||
| 3202 | */ |
||
| 3203 | 45 | public function isEmpty($keys = null): bool |
|
| 3221 | |||
| 3222 | /** |
||
| 3223 | * Check if the current array is equal to the given "$array" or not. |
||
| 3224 | * |
||
| 3225 | * @param array $array |
||
| 3226 | * |
||
| 3227 | * @return bool |
||
| 3228 | * |
||
| 3229 | * @psalm-param array<mixed,mixed> $array |
||
| 3230 | */ |
||
| 3231 | 1 | public function isEqual(array $array): bool |
|
| 3235 | |||
| 3236 | /** |
||
| 3237 | * Check if the current array is a multi-array. |
||
| 3238 | * |
||
| 3239 | * @return bool |
||
| 3240 | */ |
||
| 3241 | 22 | public function isMultiArray(): bool |
|
| 3249 | |||
| 3250 | /** |
||
| 3251 | * Check whether array is numeric or not. |
||
| 3252 | * |
||
| 3253 | * @return bool |
||
| 3254 | * <p>Returns true if numeric, false otherwise.</p> |
||
| 3255 | */ |
||
| 3256 | 5 | View Code Duplication | public function isNumeric(): bool |
| 3270 | |||
| 3271 | /** |
||
| 3272 | * Check if the current array is sequential [0, 1, 2, 3, 4, 5 ...] or not. |
||
| 3273 | * |
||
| 3274 | * @param bool $recursive |
||
| 3275 | * |
||
| 3276 | * @return bool |
||
| 3277 | * @psalm-mutation-free |
||
| 3278 | */ |
||
| 3279 | 9 | public function isSequential(bool $recursive = false): bool |
|
| 3296 | |||
| 3297 | /** |
||
| 3298 | * @return array |
||
| 3299 | * |
||
| 3300 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 3301 | */ |
||
| 3302 | 2 | public function jsonSerialize(): array |
|
| 3306 | |||
| 3307 | /** |
||
| 3308 | * Gets the key/index of the element at the current internal iterator position. |
||
| 3309 | * |
||
| 3310 | * @return int|string|null |
||
| 3311 | */ |
||
| 3312 | public function key() |
||
| 3316 | |||
| 3317 | /** |
||
| 3318 | * Checks if the given key exists in the provided array. |
||
| 3319 | * |
||
| 3320 | * INFO: This method only use "array_key_exists()" if you want to use "dot"-notation, |
||
| 3321 | * then you need to use "Arrayy->offsetExists()". |
||
| 3322 | * |
||
| 3323 | * @param int|string $key the key to look for |
||
| 3324 | * |
||
| 3325 | * @return bool |
||
| 3326 | * @psalm-mutation-free |
||
| 3327 | */ |
||
| 3328 | 162 | public function keyExists($key): bool |
|
| 3332 | |||
| 3333 | /** |
||
| 3334 | * Get all keys from the current array. |
||
| 3335 | * |
||
| 3336 | * @param bool $recursive [optional] <p> |
||
| 3337 | * Get all keys, also from all sub-arrays from an multi-dimensional array. |
||
| 3338 | * </p> |
||
| 3339 | * @param mixed|null $search_values [optional] <p> |
||
| 3340 | * If specified, then only keys containing these values are returned. |
||
| 3341 | * </p> |
||
| 3342 | * @param bool $strict [optional] <p> |
||
| 3343 | * Determines if strict comparison (===) should be used during the search. |
||
| 3344 | * </p> |
||
| 3345 | * |
||
| 3346 | * @return static |
||
| 3347 | * <p>(Immutable) An array of all the keys in input.</p> |
||
| 3348 | * |
||
| 3349 | * @psalm-return static<array-key,TKey> |
||
| 3350 | * @psalm-mutation-free |
||
| 3351 | */ |
||
| 3352 | 29 | public function keys( |
|
| 3422 | |||
| 3423 | /** |
||
| 3424 | * Sort an array by key in reverse order. |
||
| 3425 | * |
||
| 3426 | * @param int $sort_flags [optional] <p> |
||
| 3427 | * You may modify the behavior of the sort using the optional |
||
| 3428 | * parameter sort_flags, for details |
||
| 3429 | * see sort. |
||
| 3430 | * </p> |
||
| 3431 | * |
||
| 3432 | * @return $this |
||
| 3433 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 3434 | * |
||
| 3435 | * @psalm-return static<TKey,T> |
||
| 3436 | */ |
||
| 3437 | 4 | public function krsort(int $sort_flags = 0): self |
|
| 3445 | |||
| 3446 | /** |
||
| 3447 | * Sort an array by key in reverse order. |
||
| 3448 | * |
||
| 3449 | * @param int $sort_flags [optional] <p> |
||
| 3450 | * You may modify the behavior of the sort using the optional |
||
| 3451 | * parameter sort_flags, for details |
||
| 3452 | * see sort. |
||
| 3453 | * </p> |
||
| 3454 | * |
||
| 3455 | * @return $this |
||
| 3456 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 3457 | * |
||
| 3458 | * @psalm-return static<TKey,T> |
||
| 3459 | * @psalm-mutation-free |
||
| 3460 | */ |
||
| 3461 | 4 | public function krsortImmutable(int $sort_flags = 0): self |
|
| 3472 | |||
| 3473 | /** |
||
| 3474 | * Get the last value from the current array. |
||
| 3475 | * |
||
| 3476 | * @return mixed|null |
||
| 3477 | * <p>Return null if there wasn't a element.</p> |
||
| 3478 | * @psalm-mutation-free |
||
| 3479 | */ |
||
| 3480 | 17 | public function last() |
|
| 3489 | |||
| 3490 | /** |
||
| 3491 | * Get the last key from the current array. |
||
| 3492 | * |
||
| 3493 | * @return mixed|null |
||
| 3494 | * <p>Return null if there wasn't a element.</p> |
||
| 3495 | * @psalm-mutation-free |
||
| 3496 | */ |
||
| 3497 | 21 | public function lastKey() |
|
| 3503 | |||
| 3504 | /** |
||
| 3505 | * Get the last value(s) from the current array. |
||
| 3506 | * |
||
| 3507 | * @param int|null $number |
||
| 3508 | * |
||
| 3509 | * @return static |
||
| 3510 | * <p>(Immutable)</p> |
||
| 3511 | * |
||
| 3512 | * @psalm-return static<TKey,T> |
||
| 3513 | * @psalm-mutation-free |
||
| 3514 | */ |
||
| 3515 | 13 | public function lastsImmutable(int $number = null): self |
|
| 3546 | |||
| 3547 | /** |
||
| 3548 | * Get the last value(s) from the current array. |
||
| 3549 | * |
||
| 3550 | * @param int|null $number |
||
| 3551 | * |
||
| 3552 | * @return $this |
||
| 3553 | * <p>(Mutable)</p> |
||
| 3554 | * |
||
| 3555 | * @psalm-return static<TKey,T> |
||
| 3556 | */ |
||
| 3557 | 13 | public function lastsMutable(int $number = null): self |
|
| 3586 | |||
| 3587 | /** |
||
| 3588 | * Count the values from the current array. |
||
| 3589 | * |
||
| 3590 | * alias: for "Arrayy->count()" |
||
| 3591 | * |
||
| 3592 | * @param int $mode |
||
| 3593 | * |
||
| 3594 | * @return int |
||
| 3595 | * |
||
| 3596 | * @see Arrayy::count() |
||
| 3597 | */ |
||
| 3598 | 20 | public function length(int $mode = \COUNT_NORMAL): int |
|
| 3602 | |||
| 3603 | /** |
||
| 3604 | * Apply the given function to the every element of the array, |
||
| 3605 | * collecting the results. |
||
| 3606 | * |
||
| 3607 | * @param callable $callable |
||
| 3608 | * @param bool $useKeyAsSecondParameter |
||
| 3609 | * @param mixed ...$arguments |
||
| 3610 | * |
||
| 3611 | * @return static |
||
| 3612 | * <p>(Immutable) Arrayy object with modified elements.</p> |
||
| 3613 | * |
||
| 3614 | * @psalm-param callable(T,TKey=,mixed=):mixed $callable |
||
| 3615 | * @psalm-return static<TKey,T> |
||
| 3616 | * @psalm-mutation-free |
||
| 3617 | */ |
||
| 3618 | 5 | public function map( |
|
| 3651 | |||
| 3652 | /** |
||
| 3653 | * Check if all items in current array match a truth test. |
||
| 3654 | * |
||
| 3655 | * @param \Closure $closure |
||
| 3656 | * |
||
| 3657 | * @return bool |
||
| 3658 | */ |
||
| 3659 | 15 | View Code Duplication | public function matches(\Closure $closure): bool |
| 3675 | |||
| 3676 | /** |
||
| 3677 | * Check if any item in the current array matches a truth test. |
||
| 3678 | * |
||
| 3679 | * @param \Closure $closure |
||
| 3680 | * |
||
| 3681 | * @return bool |
||
| 3682 | */ |
||
| 3683 | 14 | View Code Duplication | public function matchesAny(\Closure $closure): bool |
| 3699 | |||
| 3700 | /** |
||
| 3701 | * Get the max value from an array. |
||
| 3702 | * |
||
| 3703 | * @return false|mixed |
||
| 3704 | * <p>Will return false if there are no values.</p> |
||
| 3705 | */ |
||
| 3706 | 10 | View Code Duplication | public function max() |
| 3725 | |||
| 3726 | /** |
||
| 3727 | * Merge the new $array into the current array. |
||
| 3728 | * |
||
| 3729 | * - keep key,value from the current array, also if the index is in the new $array |
||
| 3730 | * |
||
| 3731 | * @param array $array |
||
| 3732 | * @param bool $recursive |
||
| 3733 | * |
||
| 3734 | * @return static |
||
| 3735 | * <p>(Immutable)</p> |
||
| 3736 | * |
||
| 3737 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 3738 | * @psalm-return static<int|TKey,T> |
||
| 3739 | * @psalm-mutation-free |
||
| 3740 | */ |
||
| 3741 | 32 | View Code Duplication | public function mergeAppendKeepIndex(array $array = [], bool $recursive = false): self |
| 3756 | |||
| 3757 | /** |
||
| 3758 | * Merge the new $array into the current array. |
||
| 3759 | * |
||
| 3760 | * - replace duplicate assoc-keys from the current array with the key,values from the new $array |
||
| 3761 | * - create new indexes |
||
| 3762 | * |
||
| 3763 | * @param array $array |
||
| 3764 | * @param bool $recursive |
||
| 3765 | * |
||
| 3766 | * @return static |
||
| 3767 | * <p>(Immutable)</p> |
||
| 3768 | * |
||
| 3769 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 3770 | * @psalm-return static<TKey,T> |
||
| 3771 | * @psalm-mutation-free |
||
| 3772 | */ |
||
| 3773 | 19 | View Code Duplication | public function mergeAppendNewIndex(array $array = [], bool $recursive = false): self |
| 3788 | |||
| 3789 | /** |
||
| 3790 | * Merge the the current array into the $array. |
||
| 3791 | * |
||
| 3792 | * - use key,value from the new $array, also if the index is in the current array |
||
| 3793 | * |
||
| 3794 | * @param array $array |
||
| 3795 | * @param bool $recursive |
||
| 3796 | * |
||
| 3797 | * @return static |
||
| 3798 | * <p>(Immutable)</p> |
||
| 3799 | * |
||
| 3800 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 3801 | * @psalm-return static<TKey,T> |
||
| 3802 | * @psalm-mutation-free |
||
| 3803 | */ |
||
| 3804 | 16 | View Code Duplication | public function mergePrependKeepIndex(array $array = [], bool $recursive = false): self |
| 3819 | |||
| 3820 | /** |
||
| 3821 | * Merge the current array into the new $array. |
||
| 3822 | * |
||
| 3823 | * - replace duplicate assoc-keys from new $array with the key,values from the current array |
||
| 3824 | * - create new indexes |
||
| 3825 | * |
||
| 3826 | * @param array $array |
||
| 3827 | * @param bool $recursive |
||
| 3828 | * |
||
| 3829 | * @return static |
||
| 3830 | * <p>(Immutable)</p> |
||
| 3831 | * |
||
| 3832 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 3833 | * @psalm-return static<TKey,T> |
||
| 3834 | * @psalm-mutation-free |
||
| 3835 | */ |
||
| 3836 | 20 | View Code Duplication | public function mergePrependNewIndex(array $array = [], bool $recursive = false): self |
| 3851 | |||
| 3852 | /** |
||
| 3853 | * @return ArrayyMeta|static |
||
| 3854 | */ |
||
| 3855 | 16 | public static function meta() |
|
| 3859 | |||
| 3860 | /** |
||
| 3861 | * Get the min value from an array. |
||
| 3862 | * |
||
| 3863 | * @return false|mixed |
||
| 3864 | * <p>Will return false if there are no values.</p> |
||
| 3865 | */ |
||
| 3866 | 10 | View Code Duplication | public function min() |
| 3885 | |||
| 3886 | /** |
||
| 3887 | * Get the most used value from the array. |
||
| 3888 | * |
||
| 3889 | * @return mixed|null |
||
| 3890 | * <p>(Immutable) Return null if there wasn't a element.</p> |
||
| 3891 | * @psalm-mutation-free |
||
| 3892 | */ |
||
| 3893 | 3 | public function mostUsedValue() |
|
| 3897 | |||
| 3898 | /** |
||
| 3899 | * Get the most used value from the array. |
||
| 3900 | * |
||
| 3901 | * @param int|null $number <p>How many values you will take?</p> |
||
| 3902 | * |
||
| 3903 | * @return static |
||
| 3904 | * <p>(Immutable)</p> |
||
| 3905 | * |
||
| 3906 | * @psalm-return static<TKey,T> |
||
| 3907 | * @psalm-mutation-free |
||
| 3908 | */ |
||
| 3909 | 3 | public function mostUsedValues(int $number = null): self |
|
| 3913 | |||
| 3914 | /** |
||
| 3915 | * Move an array element to a new index. |
||
| 3916 | * |
||
| 3917 | * cherry-picked from: http://stackoverflow.com/questions/12624153/move-an-array-element-to-a-new-index-in-php |
||
| 3918 | * |
||
| 3919 | * @param int|string $from |
||
| 3920 | * @param int $to |
||
| 3921 | * |
||
| 3922 | * @return static |
||
| 3923 | * <p>(Immutable)</p> |
||
| 3924 | * |
||
| 3925 | * @psalm-return static<TKey,T> |
||
| 3926 | * @psalm-mutation-free |
||
| 3927 | */ |
||
| 3928 | 1 | public function moveElement($from, $to): self |
|
| 3961 | |||
| 3962 | /** |
||
| 3963 | * Move an array element to the first place. |
||
| 3964 | * |
||
| 3965 | * INFO: Instead of "Arrayy->moveElement()" this method will NOT |
||
| 3966 | * loss the keys of an indexed array. |
||
| 3967 | * |
||
| 3968 | * @param int|string $key |
||
| 3969 | * |
||
| 3970 | * @return static |
||
| 3971 | * <p>(Immutable)</p> |
||
| 3972 | * |
||
| 3973 | * @psalm-return static<TKey,T> |
||
| 3974 | * @psalm-mutation-free |
||
| 3975 | */ |
||
| 3976 | 1 | View Code Duplication | public function moveElementToFirstPlace($key): self |
| 3992 | |||
| 3993 | /** |
||
| 3994 | * Move an array element to the last place. |
||
| 3995 | * |
||
| 3996 | * INFO: Instead of "Arrayy->moveElement()" this method will NOT |
||
| 3997 | * loss the keys of an indexed array. |
||
| 3998 | * |
||
| 3999 | * @param int|string $key |
||
| 4000 | * |
||
| 4001 | * @return static |
||
| 4002 | * <p>(Immutable)</p> |
||
| 4003 | * |
||
| 4004 | * @psalm-return static<TKey,T> |
||
| 4005 | * @psalm-mutation-free |
||
| 4006 | */ |
||
| 4007 | 1 | View Code Duplication | public function moveElementToLastPlace($key): self |
| 4023 | |||
| 4024 | /** |
||
| 4025 | * Moves the internal iterator position to the next element and returns this element. |
||
| 4026 | * |
||
| 4027 | * @return false|mixed |
||
| 4028 | * <p>(Mutable) Will return false if there are no values.</p> |
||
| 4029 | */ |
||
| 4030 | public function next() |
||
| 4034 | |||
| 4035 | /** |
||
| 4036 | * Get the next nth keys and values from the array. |
||
| 4037 | * |
||
| 4038 | * @param int $step |
||
| 4039 | * @param int $offset |
||
| 4040 | * |
||
| 4041 | * @return static |
||
| 4042 | * <p>(Immutable)</p> |
||
| 4043 | * |
||
| 4044 | * @psalm-return static<TKey,T> |
||
| 4045 | * @psalm-mutation-free |
||
| 4046 | */ |
||
| 4047 | 1 | public function nth(int $step, int $offset = 0): self |
|
| 4066 | |||
| 4067 | /** |
||
| 4068 | * Get a subset of the items from the given array. |
||
| 4069 | * |
||
| 4070 | * @param mixed[] $keys |
||
| 4071 | * |
||
| 4072 | * @return static |
||
| 4073 | * <p>(Immutable)</p> |
||
| 4074 | * |
||
| 4075 | * @psalm-return static<TKey,T> |
||
| 4076 | * @psalm-mutation-free |
||
| 4077 | */ |
||
| 4078 | 1 | public function only(array $keys): self |
|
| 4088 | |||
| 4089 | /** |
||
| 4090 | * Pad array to the specified size with a given value. |
||
| 4091 | * |
||
| 4092 | * @param int $size <p>Size of the result array.</p> |
||
| 4093 | * @param mixed $value <p>Empty value by default.</p> |
||
| 4094 | * |
||
| 4095 | * @return static |
||
| 4096 | * <p>(Immutable) Arrayy object padded to $size with $value.</p> |
||
| 4097 | * |
||
| 4098 | * @psalm-return static<TKey,T> |
||
| 4099 | * @psalm-mutation-free |
||
| 4100 | */ |
||
| 4101 | 5 | public function pad(int $size, $value): self |
|
| 4109 | |||
| 4110 | /** |
||
| 4111 | * Partitions this array in two array according to a predicate. |
||
| 4112 | * Keys are preserved in the resulting array. |
||
| 4113 | * |
||
| 4114 | * @param \Closure $closure |
||
| 4115 | * <p>The predicate on which to partition.</p> |
||
| 4116 | * |
||
| 4117 | * @return array<int, static> |
||
| 4118 | * <p>An array with two elements. The first element contains the array |
||
| 4119 | * of elements where the predicate returned TRUE, the second element |
||
| 4120 | * contains the array of elements where the predicate returned FALSE.</p> |
||
| 4121 | * |
||
| 4122 | * @psalm-return array<int, static<TKey,T>> |
||
| 4123 | */ |
||
| 4124 | 1 | public function partition(\Closure $closure): array |
|
| 4140 | |||
| 4141 | /** |
||
| 4142 | * Pop a specified value off the end of the current array. |
||
| 4143 | * |
||
| 4144 | * @return mixed|null |
||
| 4145 | * <p>(Mutable) The popped element from the current array or null if the array is e.g. empty.</p> |
||
| 4146 | */ |
||
| 4147 | 5 | public function pop() |
|
| 4153 | |||
| 4154 | /** |
||
| 4155 | * Prepend a (key) + value to the current array. |
||
| 4156 | * |
||
| 4157 | * @param mixed $value |
||
| 4158 | * @param mixed $key |
||
| 4159 | * |
||
| 4160 | * @return $this |
||
| 4161 | * <p>(Mutable) Return this Arrayy object, with the prepended value.</p> |
||
| 4162 | * |
||
| 4163 | * @psalm-return static<TKey,T> |
||
| 4164 | */ |
||
| 4165 | 11 | public function prepend($value, $key = null) |
|
| 4181 | |||
| 4182 | /** |
||
| 4183 | * Add a suffix to each key. |
||
| 4184 | * |
||
| 4185 | * @param mixed $suffix |
||
| 4186 | * |
||
| 4187 | * @return static |
||
| 4188 | * <p>(Immutable) Return an Arrayy object, with the prepended keys.</p> |
||
| 4189 | * |
||
| 4190 | * @psalm-return static<TKey,T> |
||
| 4191 | * @psalm-mutation-free |
||
| 4192 | */ |
||
| 4193 | 10 | View Code Duplication | public function prependToEachKey($suffix): self |
| 4219 | |||
| 4220 | /** |
||
| 4221 | * Add a suffix to each value. |
||
| 4222 | * |
||
| 4223 | * @param mixed $suffix |
||
| 4224 | * |
||
| 4225 | * @return static |
||
| 4226 | * <p>(Immutable) Return an Arrayy object, with the prepended values.</p> |
||
| 4227 | * |
||
| 4228 | * @psalm-return static<TKey,T> |
||
| 4229 | * @psalm-mutation-free |
||
| 4230 | */ |
||
| 4231 | 10 | View Code Duplication | public function prependToEachValue($suffix): self |
| 4259 | |||
| 4260 | /** |
||
| 4261 | * Return the value of a given key and |
||
| 4262 | * delete the key. |
||
| 4263 | * |
||
| 4264 | * @param int|int[]|string|string[]|null $keyOrKeys |
||
| 4265 | * @param mixed $fallback |
||
| 4266 | * |
||
| 4267 | * @return mixed |
||
| 4268 | */ |
||
| 4269 | 5 | public function pull($keyOrKeys = null, $fallback = null) |
|
| 4291 | |||
| 4292 | /** |
||
| 4293 | * Push one or more values onto the end of array at once. |
||
| 4294 | * |
||
| 4295 | * @param array ...$args |
||
| 4296 | * |
||
| 4297 | * @return $this |
||
| 4298 | * <p>(Mutable) Return this Arrayy object, with pushed elements to the end of array.</p> |
||
| 4299 | * |
||
| 4300 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
| 4301 | * |
||
| 4302 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$args |
||
| 4303 | * @psalm-return static<TKey,T> |
||
| 4304 | */ |
||
| 4305 | 7 | public function push(...$args) |
|
| 4323 | |||
| 4324 | /** |
||
| 4325 | * Get a random value from the current array. |
||
| 4326 | * |
||
| 4327 | * @param int|null $number <p>How many values you will take?</p> |
||
| 4328 | * |
||
| 4329 | * @return static |
||
| 4330 | * <p>(Immutable)</p> |
||
| 4331 | * |
||
| 4332 | * @psalm-return static<int|array-key,T> |
||
| 4333 | */ |
||
| 4334 | 19 | public function randomImmutable(int $number = null): self |
|
| 4367 | |||
| 4368 | /** |
||
| 4369 | * Pick a random key/index from the keys of this array. |
||
| 4370 | * |
||
| 4371 | * @throws \RangeException If array is empty |
||
| 4372 | * |
||
| 4373 | * @return mixed |
||
| 4374 | * <p>Get a key/index or null if there wasn't a key/index.</p> |
||
| 4375 | */ |
||
| 4376 | 4 | public function randomKey() |
|
| 4386 | |||
| 4387 | /** |
||
| 4388 | * Pick a given number of random keys/indexes out of this array. |
||
| 4389 | * |
||
| 4390 | * @param int $number <p>The number of keys/indexes (should be <= \count($this->array))</p> |
||
| 4391 | * |
||
| 4392 | * @throws \RangeException If array is empty |
||
| 4393 | * |
||
| 4394 | * @return static |
||
| 4395 | * <p>(Immutable)</p> |
||
| 4396 | * |
||
| 4397 | * @psalm-return static<TKey,T> |
||
| 4398 | */ |
||
| 4399 | 13 | public function randomKeys(int $number): self |
|
| 4427 | |||
| 4428 | /** |
||
| 4429 | * Get a random value from the current array. |
||
| 4430 | * |
||
| 4431 | * @param int|null $number <p>How many values you will take?</p> |
||
| 4432 | * |
||
| 4433 | * @return $this |
||
| 4434 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 4435 | * |
||
| 4436 | * @psalm-return static<TKey,T> |
||
| 4437 | */ |
||
| 4438 | 17 | public function randomMutable(int $number = null): self |
|
| 4463 | |||
| 4464 | /** |
||
| 4465 | * Pick a random value from the values of this array. |
||
| 4466 | * |
||
| 4467 | * @return mixed |
||
| 4468 | * <p>Get a random value or null if there wasn't a value.</p> |
||
| 4469 | */ |
||
| 4470 | 4 | public function randomValue() |
|
| 4480 | |||
| 4481 | /** |
||
| 4482 | * Pick a given number of random values out of this array. |
||
| 4483 | * |
||
| 4484 | * @param int $number |
||
| 4485 | * |
||
| 4486 | * @return static |
||
| 4487 | * <p>(Mutable)</p> |
||
| 4488 | * |
||
| 4489 | * @psalm-return static<TKey,T> |
||
| 4490 | */ |
||
| 4491 | 7 | public function randomValues(int $number): self |
|
| 4495 | |||
| 4496 | /** |
||
| 4497 | * Get a random value from an array, with the ability to skew the results. |
||
| 4498 | * |
||
| 4499 | * Example: randomWeighted(['foo' => 1, 'bar' => 2]) has a 66% chance of returning bar. |
||
| 4500 | * |
||
| 4501 | * @param array $array |
||
| 4502 | * @param int|null $number <p>How many values you will take?</p> |
||
| 4503 | * |
||
| 4504 | * @return static<int,mixed> |
||
| 4505 | * <p>(Immutable)</p> |
||
| 4506 | * |
||
| 4507 | * @psalm-param array<mixed,mixed> $array |
||
| 4508 | * @psalm-return static<int|array-key,T> |
||
| 4509 | */ |
||
| 4510 | 9 | public function randomWeighted(array $array, int $number = null): self |
|
| 4525 | |||
| 4526 | /** |
||
| 4527 | * Reduce the current array via callable e.g. anonymous-function. |
||
| 4528 | * |
||
| 4529 | * @param callable $callable |
||
| 4530 | * @param mixed $init |
||
| 4531 | * |
||
| 4532 | * @return static |
||
| 4533 | * <p>(Immutable)</p> |
||
| 4534 | * |
||
| 4535 | * @psalm-return static<TKey,T> |
||
| 4536 | * @psalm-mutation-free |
||
| 4537 | */ |
||
| 4538 | 18 | public function reduce($callable, $init = []): self |
|
| 4568 | |||
| 4569 | /** |
||
| 4570 | * @param bool $unique |
||
| 4571 | * |
||
| 4572 | * @return static |
||
| 4573 | * <p>(Immutable)</p> |
||
| 4574 | * |
||
| 4575 | * @psalm-return static<TKey,T> |
||
| 4576 | * @psalm-mutation-free |
||
| 4577 | */ |
||
| 4578 | 14 | public function reduce_dimension(bool $unique = true): self |
|
| 4601 | |||
| 4602 | /** |
||
| 4603 | * Create a numerically re-indexed Arrayy object. |
||
| 4604 | * |
||
| 4605 | * @return $this |
||
| 4606 | * <p>(Mutable) Return this Arrayy object, with re-indexed array-elements.</p> |
||
| 4607 | * |
||
| 4608 | * @psalm-return static<TKey,T> |
||
| 4609 | */ |
||
| 4610 | 9 | public function reindex(): self |
|
| 4618 | |||
| 4619 | /** |
||
| 4620 | * Return all items that fail the truth test. |
||
| 4621 | * |
||
| 4622 | * @param \Closure $closure |
||
| 4623 | * |
||
| 4624 | * @return static |
||
| 4625 | * <p>(Immutable)</p> |
||
| 4626 | * |
||
| 4627 | * @psalm-return static<TKey,T> |
||
| 4628 | * @psalm-mutation-free |
||
| 4629 | */ |
||
| 4630 | 1 | View Code Duplication | public function reject(\Closure $closure): self |
| 4647 | |||
| 4648 | /** |
||
| 4649 | * Remove a value from the current array (optional using dot-notation). |
||
| 4650 | * |
||
| 4651 | * @param mixed $key |
||
| 4652 | * |
||
| 4653 | * @return static |
||
| 4654 | * <p>(Mutable)</p> |
||
| 4655 | * |
||
| 4656 | * @psalm-param TKey $key |
||
| 4657 | * @psalm-return static<TKey,T> |
||
| 4658 | */ |
||
| 4659 | 21 | public function remove($key) |
|
| 4682 | |||
| 4683 | /** |
||
| 4684 | * alias: for "Arrayy->removeValue()" |
||
| 4685 | * |
||
| 4686 | * @param mixed $element |
||
| 4687 | * |
||
| 4688 | * @return static |
||
| 4689 | * <p>(Immutable)</p> |
||
| 4690 | * |
||
| 4691 | * @psalm-param T $element |
||
| 4692 | * @psalm-return static<TKey,T> |
||
| 4693 | * @psalm-mutation-free |
||
| 4694 | */ |
||
| 4695 | 8 | public function removeElement($element) |
|
| 4699 | |||
| 4700 | /** |
||
| 4701 | * Remove the first value from the current array. |
||
| 4702 | * |
||
| 4703 | * @return static |
||
| 4704 | * <p>(Immutable)</p> |
||
| 4705 | * |
||
| 4706 | * @psalm-return static<TKey,T> |
||
| 4707 | * @psalm-mutation-free |
||
| 4708 | */ |
||
| 4709 | 7 | View Code Duplication | public function removeFirst(): self |
| 4721 | |||
| 4722 | /** |
||
| 4723 | * Remove the last value from the current array. |
||
| 4724 | * |
||
| 4725 | * @return static |
||
| 4726 | * <p>(Immutable)</p> |
||
| 4727 | * |
||
| 4728 | * @psalm-return static<TKey,T> |
||
| 4729 | * @psalm-mutation-free |
||
| 4730 | */ |
||
| 4731 | 7 | View Code Duplication | public function removeLast(): self |
| 4743 | |||
| 4744 | /** |
||
| 4745 | * Removes a particular value from an array (numeric or associative). |
||
| 4746 | * |
||
| 4747 | * @param mixed $value |
||
| 4748 | * |
||
| 4749 | * @return static |
||
| 4750 | * <p>(Immutable)</p> |
||
| 4751 | * |
||
| 4752 | * @psalm-param T $value |
||
| 4753 | * @psalm-return static<TKey,T> |
||
| 4754 | * @psalm-mutation-free |
||
| 4755 | */ |
||
| 4756 | 8 | public function removeValue($value): self |
|
| 4779 | |||
| 4780 | /** |
||
| 4781 | * Generate array of repeated arrays. |
||
| 4782 | * |
||
| 4783 | * @param int $times <p>How many times has to be repeated.</p> |
||
| 4784 | * |
||
| 4785 | * @return static |
||
| 4786 | * <p>(Immutable)</p> |
||
| 4787 | * |
||
| 4788 | * @psalm-return static<TKey,T> |
||
| 4789 | * @psalm-mutation-free |
||
| 4790 | */ |
||
| 4791 | 1 | public function repeat($times): self |
|
| 4803 | |||
| 4804 | /** |
||
| 4805 | * Replace a key with a new key/value pair. |
||
| 4806 | * |
||
| 4807 | * @param mixed $oldKey |
||
| 4808 | * @param mixed $newKey |
||
| 4809 | * @param mixed $newValue |
||
| 4810 | * |
||
| 4811 | * @return static |
||
| 4812 | * <p>(Immutable)</p> |
||
| 4813 | * |
||
| 4814 | * @psalm-return static<TKey,T> |
||
| 4815 | * @psalm-mutation-free |
||
| 4816 | */ |
||
| 4817 | 5 | public function replace($oldKey, $newKey, $newValue): self |
|
| 4827 | |||
| 4828 | /** |
||
| 4829 | * Create an array using the current array as values and the other array as keys. |
||
| 4830 | * |
||
| 4831 | * @param array $keys <p>An array of keys.</p> |
||
| 4832 | * |
||
| 4833 | * @return static |
||
| 4834 | * <p>(Immutable) Arrayy object with keys from the other array.</p> |
||
| 4835 | * |
||
| 4836 | * @psalm-param array<mixed,mixed>|array<mixed,TKey> $keys |
||
| 4837 | * @psalm-return static<TKey,T> |
||
| 4838 | * @psalm-mutation-free |
||
| 4839 | */ |
||
| 4840 | 2 | public function replaceAllKeys(array $keys): self |
|
| 4848 | |||
| 4849 | /** |
||
| 4850 | * Create an array using the current array as keys and the other array as values. |
||
| 4851 | * |
||
| 4852 | * @param array $array <p>An array o values.</p> |
||
| 4853 | * |
||
| 4854 | * @return static |
||
| 4855 | * <p>(Immutable) Arrayy object with values from the other array.</p> |
||
| 4856 | * |
||
| 4857 | * @psalm-param array<mixed,T> $array |
||
| 4858 | * @psalm-return static<TKey,T> |
||
| 4859 | * @psalm-mutation-free |
||
| 4860 | */ |
||
| 4861 | 2 | public function replaceAllValues(array $array): self |
|
| 4869 | |||
| 4870 | /** |
||
| 4871 | * Replace the keys in an array with another set. |
||
| 4872 | * |
||
| 4873 | * @param array $keys <p>An array of keys matching the array's size</p> |
||
| 4874 | * |
||
| 4875 | * @return static |
||
| 4876 | * <p>(Immutable)</p> |
||
| 4877 | * |
||
| 4878 | * @psalm-param array<mixed,mixed>|array<mixed,TKey> $keys |
||
| 4879 | * @psalm-return static<TKey,T> |
||
| 4880 | * @psalm-mutation-free |
||
| 4881 | */ |
||
| 4882 | 1 | public function replaceKeys(array $keys): self |
|
| 4893 | |||
| 4894 | /** |
||
| 4895 | * Replace the first matched value in an array. |
||
| 4896 | * |
||
| 4897 | * @param mixed $search <p>The value to replace.</p> |
||
| 4898 | * @param mixed $replacement <p>The value to replace.</p> |
||
| 4899 | * |
||
| 4900 | * @return static |
||
| 4901 | * <p>(Immutable)</p> |
||
| 4902 | * |
||
| 4903 | * @psalm-return static<TKey,T> |
||
| 4904 | * @psalm-mutation-free |
||
| 4905 | */ |
||
| 4906 | 3 | public function replaceOneValue($search, $replacement = ''): self |
|
| 4921 | |||
| 4922 | /** |
||
| 4923 | * Replace values in the current array. |
||
| 4924 | * |
||
| 4925 | * @param mixed $search <p>The value to replace.</p> |
||
| 4926 | * @param mixed $replacement <p>What to replace it with.</p> |
||
| 4927 | * |
||
| 4928 | * @return static |
||
| 4929 | * <p>(Immutable)</p> |
||
| 4930 | * |
||
| 4931 | * @psalm-return static<TKey,T> |
||
| 4932 | * @psalm-mutation-free |
||
| 4933 | */ |
||
| 4934 | 1 | public function replaceValues($search, $replacement = ''): self |
|
| 4946 | |||
| 4947 | /** |
||
| 4948 | * Get the last elements from index $from until the end of this array. |
||
| 4949 | * |
||
| 4950 | * @param int $from |
||
| 4951 | * |
||
| 4952 | * @return static |
||
| 4953 | * <p>(Immutable)</p> |
||
| 4954 | * |
||
| 4955 | * @psalm-return static<TKey,T> |
||
| 4956 | * @psalm-mutation-free |
||
| 4957 | */ |
||
| 4958 | 15 | View Code Duplication | public function rest(int $from = 1): self |
| 4968 | |||
| 4969 | /** |
||
| 4970 | * Return the array in the reverse order. |
||
| 4971 | * |
||
| 4972 | * @return $this |
||
| 4973 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 4974 | * |
||
| 4975 | * @psalm-return static<TKey,T> |
||
| 4976 | */ |
||
| 4977 | 9 | public function reverse(): self |
|
| 4985 | |||
| 4986 | /** |
||
| 4987 | * Sort an array in reverse order. |
||
| 4988 | * |
||
| 4989 | * @param int $sort_flags [optional] <p> |
||
| 4990 | * You may modify the behavior of the sort using the optional |
||
| 4991 | * parameter sort_flags, for details |
||
| 4992 | * see sort. |
||
| 4993 | * </p> |
||
| 4994 | * |
||
| 4995 | * @return $this |
||
| 4996 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 4997 | * |
||
| 4998 | * @psalm-return static<TKey,T> |
||
| 4999 | */ |
||
| 5000 | 4 | public function rsort(int $sort_flags = 0): self |
|
| 5008 | |||
| 5009 | /** |
||
| 5010 | * Sort an array in reverse order. |
||
| 5011 | * |
||
| 5012 | * @param int $sort_flags [optional] <p> |
||
| 5013 | * You may modify the behavior of the sort using the optional |
||
| 5014 | * parameter sort_flags, for details |
||
| 5015 | * see sort. |
||
| 5016 | * </p> |
||
| 5017 | * |
||
| 5018 | * @return $this |
||
| 5019 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 5020 | * |
||
| 5021 | * @psalm-return static<TKey,T> |
||
| 5022 | * @psalm-mutation-free |
||
| 5023 | */ |
||
| 5024 | 4 | public function rsortImmutable(int $sort_flags = 0): self |
|
| 5035 | |||
| 5036 | /** |
||
| 5037 | * Search for the first index of the current array via $value. |
||
| 5038 | * |
||
| 5039 | * @param mixed $value |
||
| 5040 | * |
||
| 5041 | * @return false|float|int|string |
||
| 5042 | * <p>Will return <b>FALSE</b> if the value can't be found.</p> |
||
| 5043 | * @psalm-mutation-free |
||
| 5044 | */ |
||
| 5045 | 21 | public function searchIndex($value) |
|
| 5055 | |||
| 5056 | /** |
||
| 5057 | * Search for the value of the current array via $index. |
||
| 5058 | * |
||
| 5059 | * @param mixed $index |
||
| 5060 | * |
||
| 5061 | * @return static |
||
| 5062 | * <p>(Immutable) Will return a empty Arrayy if the value wasn't found.</p> |
||
| 5063 | * |
||
| 5064 | * @psalm-return static<TKey,T> |
||
| 5065 | * @psalm-mutation-free |
||
| 5066 | */ |
||
| 5067 | 9 | public function searchValue($index): self |
|
| 5097 | |||
| 5098 | /** |
||
| 5099 | * Set a value for the current array (optional using dot-notation). |
||
| 5100 | * |
||
| 5101 | * @param string $key <p>The key to set.</p> |
||
| 5102 | * @param mixed $value <p>Its value.</p> |
||
| 5103 | * |
||
| 5104 | * @return $this |
||
| 5105 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 5106 | * |
||
| 5107 | * @psalm-param TKey $key |
||
| 5108 | * @psalm-param T $value |
||
| 5109 | * @psalm-return static<TKey,T> |
||
| 5110 | */ |
||
| 5111 | 28 | public function set($key, $value): self |
|
| 5117 | |||
| 5118 | /** |
||
| 5119 | * Get a value from a array and set it if it was not. |
||
| 5120 | * |
||
| 5121 | * WARNING: this method only set the value, if the $key is not already set |
||
| 5122 | * |
||
| 5123 | * @param mixed $key <p>The key</p> |
||
| 5124 | * @param mixed $fallback <p>The default value to set if it isn't.</p> |
||
| 5125 | * |
||
| 5126 | * @return mixed |
||
| 5127 | * <p>(Mutable)</p> |
||
| 5128 | */ |
||
| 5129 | 11 | public function setAndGet($key, $fallback = null) |
|
| 5140 | |||
| 5141 | /** |
||
| 5142 | * Shifts a specified value off the beginning of array. |
||
| 5143 | * |
||
| 5144 | * @return mixed |
||
| 5145 | * <p>(Mutable) A shifted element from the current array.</p> |
||
| 5146 | */ |
||
| 5147 | 5 | public function shift() |
|
| 5153 | |||
| 5154 | /** |
||
| 5155 | * Shuffle the current array. |
||
| 5156 | * |
||
| 5157 | * @param bool $secure <p>using a CSPRNG | @link https://paragonie.com/b/JvICXzh_jhLyt4y3</p> |
||
| 5158 | * @param array $array [optional] |
||
| 5159 | * |
||
| 5160 | * @return static |
||
| 5161 | * <p>(Immutable)</p> |
||
| 5162 | * |
||
| 5163 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 5164 | * @psalm-return static<TKey,T> |
||
| 5165 | * |
||
| 5166 | * @noinspection BadExceptionsProcessingInspection |
||
| 5167 | * @noinspection RandomApiMigrationInspection |
||
| 5168 | * @noinspection NonSecureShuffleUsageInspection |
||
| 5169 | */ |
||
| 5170 | 2 | public function shuffle(bool $secure = false, array $array = null): self |
|
| 5208 | |||
| 5209 | /** |
||
| 5210 | * Count the values from the current array. |
||
| 5211 | * |
||
| 5212 | * alias: for "Arrayy->count()" |
||
| 5213 | * |
||
| 5214 | * @param int $mode |
||
| 5215 | * |
||
| 5216 | * @return int |
||
| 5217 | */ |
||
| 5218 | 20 | public function size(int $mode = \COUNT_NORMAL): int |
|
| 5222 | |||
| 5223 | /** |
||
| 5224 | * Checks whether array has exactly $size items. |
||
| 5225 | * |
||
| 5226 | * @param int $size |
||
| 5227 | * |
||
| 5228 | * @return bool |
||
| 5229 | */ |
||
| 5230 | 1 | public function sizeIs(int $size): bool |
|
| 5245 | |||
| 5246 | /** |
||
| 5247 | * Checks whether array has between $fromSize to $toSize items. $toSize can be |
||
| 5248 | * smaller than $fromSize. |
||
| 5249 | * |
||
| 5250 | * @param int $fromSize |
||
| 5251 | * @param int $toSize |
||
| 5252 | * |
||
| 5253 | * @return bool |
||
| 5254 | */ |
||
| 5255 | 1 | public function sizeIsBetween(int $fromSize, int $toSize): bool |
|
| 5275 | |||
| 5276 | /** |
||
| 5277 | * Checks whether array has more than $size items. |
||
| 5278 | * |
||
| 5279 | * @param int $size |
||
| 5280 | * |
||
| 5281 | * @return bool |
||
| 5282 | */ |
||
| 5283 | 1 | View Code Duplication | public function sizeIsGreaterThan(int $size): bool |
| 5297 | |||
| 5298 | /** |
||
| 5299 | * Checks whether array has less than $size items. |
||
| 5300 | * |
||
| 5301 | * @param int $size |
||
| 5302 | * |
||
| 5303 | * @return bool |
||
| 5304 | */ |
||
| 5305 | 1 | View Code Duplication | public function sizeIsLessThan(int $size): bool |
| 5319 | |||
| 5320 | /** |
||
| 5321 | * Counts all elements in an array, or something in an object. |
||
| 5322 | * |
||
| 5323 | * <p> |
||
| 5324 | * For objects, if you have SPL installed, you can hook into count() by implementing interface {@see Countable}. |
||
| 5325 | * The interface has exactly one method, {@see Countable::count()}, which returns the return value for the count() |
||
| 5326 | * function. Please see the {@see Array} section of the manual for a detailed explanation of how arrays are |
||
| 5327 | * implemented and used in PHP. |
||
| 5328 | * </p> |
||
| 5329 | * |
||
| 5330 | * @return int |
||
| 5331 | * <p> |
||
| 5332 | * The number of elements in var, which is |
||
| 5333 | * typically an array, since anything else will have one |
||
| 5334 | * element. |
||
| 5335 | * </p> |
||
| 5336 | * <p> |
||
| 5337 | * If var is not an array or an object with |
||
| 5338 | * implemented Countable interface, |
||
| 5339 | * 1 will be returned. |
||
| 5340 | * There is one exception, if var is &null;, |
||
| 5341 | * 0 will be returned. |
||
| 5342 | * </p> |
||
| 5343 | * <p> |
||
| 5344 | * Caution: count may return 0 for a variable that isn't set, |
||
| 5345 | * but it may also return 0 for a variable that has been initialized with an |
||
| 5346 | * empty array. Use isset to test if a variable is set. |
||
| 5347 | * </p> |
||
| 5348 | */ |
||
| 5349 | 10 | public function sizeRecursive(): int |
|
| 5353 | |||
| 5354 | /** |
||
| 5355 | * Extract a slice of the array. |
||
| 5356 | * |
||
| 5357 | * @param int $offset <p>Slice begin index.</p> |
||
| 5358 | * @param int|null $length <p>Length of the slice.</p> |
||
| 5359 | * @param bool $preserveKeys <p>Whether array keys are preserved or no.</p> |
||
| 5360 | * |
||
| 5361 | * @return static |
||
| 5362 | * <p>(Immutable) A slice of the original array with length $length.</p> |
||
| 5363 | * |
||
| 5364 | * @psalm-return static<TKey,T> |
||
| 5365 | * @psalm-mutation-free |
||
| 5366 | */ |
||
| 5367 | 5 | public function slice(int $offset, int $length = null, bool $preserveKeys = false) |
|
| 5380 | |||
| 5381 | /** |
||
| 5382 | * Sort the current array and optional you can keep the keys. |
||
| 5383 | * |
||
| 5384 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 5385 | * @param int $strategy <p>sort_flags => use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 5386 | * <strong>SORT_NATURAL</strong></p> |
||
| 5387 | * @param bool $keepKeys |
||
| 5388 | * |
||
| 5389 | * @return static |
||
| 5390 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 5391 | * |
||
| 5392 | * @psalm-return static<TKey,T> |
||
| 5393 | */ |
||
| 5394 | 20 | public function sort( |
|
| 5408 | |||
| 5409 | /** |
||
| 5410 | * Sort the current array and optional you can keep the keys. |
||
| 5411 | * |
||
| 5412 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 5413 | * @param int $strategy <p>sort_flags => use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 5414 | * <strong>SORT_NATURAL</strong></p> |
||
| 5415 | * @param bool $keepKeys |
||
| 5416 | * |
||
| 5417 | * @return static |
||
| 5418 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 5419 | * |
||
| 5420 | * @psalm-return static<TKey,T> |
||
| 5421 | */ |
||
| 5422 | 12 | public function sortImmutable( |
|
| 5438 | |||
| 5439 | /** |
||
| 5440 | * Sort the current array by key. |
||
| 5441 | * |
||
| 5442 | * @see http://php.net/manual/en/function.ksort.php |
||
| 5443 | * @see http://php.net/manual/en/function.krsort.php |
||
| 5444 | * |
||
| 5445 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 5446 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 5447 | * <strong>SORT_NATURAL</strong></p> |
||
| 5448 | * |
||
| 5449 | * @return $this |
||
| 5450 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 5451 | * |
||
| 5452 | * @psalm-return static<TKey,T> |
||
| 5453 | */ |
||
| 5454 | 18 | public function sortKeys( |
|
| 5464 | |||
| 5465 | /** |
||
| 5466 | * Sort the current array by key. |
||
| 5467 | * |
||
| 5468 | * @see http://php.net/manual/en/function.ksort.php |
||
| 5469 | * @see http://php.net/manual/en/function.krsort.php |
||
| 5470 | * |
||
| 5471 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 5472 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 5473 | * <strong>SORT_NATURAL</strong></p> |
||
| 5474 | * |
||
| 5475 | * @return $this |
||
| 5476 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 5477 | * |
||
| 5478 | * @psalm-return static<TKey,T> |
||
| 5479 | * @psalm-mutation-free |
||
| 5480 | */ |
||
| 5481 | 8 | public function sortKeysImmutable( |
|
| 5494 | |||
| 5495 | /** |
||
| 5496 | * Sort the current array by value. |
||
| 5497 | * |
||
| 5498 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 5499 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 5500 | * <strong>SORT_NATURAL</strong></p> |
||
| 5501 | * |
||
| 5502 | * @return static |
||
| 5503 | * <p>(Mutable)</p> |
||
| 5504 | * |
||
| 5505 | * @psalm-return static<TKey,T> |
||
| 5506 | */ |
||
| 5507 | 1 | public function sortValueKeepIndex( |
|
| 5513 | |||
| 5514 | /** |
||
| 5515 | * Sort the current array by value. |
||
| 5516 | * |
||
| 5517 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 5518 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 5519 | * <strong>SORT_NATURAL</strong></p> |
||
| 5520 | * |
||
| 5521 | * @return static |
||
| 5522 | * <p>(Mutable)</p> |
||
| 5523 | * |
||
| 5524 | * @psalm-return static<TKey,T> |
||
| 5525 | */ |
||
| 5526 | 1 | public function sortValueNewIndex($direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
| 5530 | |||
| 5531 | /** |
||
| 5532 | * Sort a array by value, by a closure or by a property. |
||
| 5533 | * |
||
| 5534 | * - If the sorter is null, the array is sorted naturally. |
||
| 5535 | * - Associative (string) keys will be maintained, but numeric keys will be re-indexed. |
||
| 5536 | * |
||
| 5537 | * @param callable|string|null $sorter |
||
| 5538 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or |
||
| 5539 | * <strong>SORT_DESC</strong></p> |
||
| 5540 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 5541 | * <strong>SORT_NATURAL</strong></p> |
||
| 5542 | * |
||
| 5543 | * @return static |
||
| 5544 | * <p>(Immutable)</p> |
||
| 5545 | * |
||
| 5546 | * @psalm-return static<TKey,T> |
||
| 5547 | * @psalm-mutation-free |
||
| 5548 | */ |
||
| 5549 | 1 | public function sorter($sorter = null, $direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
| 5590 | |||
| 5591 | /** |
||
| 5592 | * @param int $offset |
||
| 5593 | * @param int|null $length |
||
| 5594 | * @param array $replacement |
||
| 5595 | * |
||
| 5596 | * @return static |
||
| 5597 | * <p>(Immutable)</p> |
||
| 5598 | * |
||
| 5599 | * @psalm-param array<mixed,mixed>|array<mixed,T> $replacement |
||
| 5600 | * @psalm-return static<TKey,T> |
||
| 5601 | * @psalm-mutation-free |
||
| 5602 | */ |
||
| 5603 | 1 | public function splice(int $offset, int $length = null, $replacement = []): self |
|
| 5620 | |||
| 5621 | /** |
||
| 5622 | * Split an array in the given amount of pieces. |
||
| 5623 | * |
||
| 5624 | * @param int $numberOfPieces |
||
| 5625 | * @param bool $keepKeys |
||
| 5626 | * |
||
| 5627 | * @return static |
||
| 5628 | * <p>(Immutable)</p> |
||
| 5629 | * |
||
| 5630 | * @psalm-return static<TKey,T> |
||
| 5631 | * @psalm-mutation-free |
||
| 5632 | */ |
||
| 5633 | 1 | public function split(int $numberOfPieces = 2, bool $keepKeys = false): self |
|
| 5652 | |||
| 5653 | /** |
||
| 5654 | * Stripe all empty items. |
||
| 5655 | * |
||
| 5656 | * @return static |
||
| 5657 | * <p>(Immutable)</p> |
||
| 5658 | * |
||
| 5659 | * @psalm-return static<TKey,T> |
||
| 5660 | * @psalm-mutation-free |
||
| 5661 | */ |
||
| 5662 | 1 | public function stripEmpty(): self |
|
| 5674 | |||
| 5675 | /** |
||
| 5676 | * Swap two values between positions by key. |
||
| 5677 | * |
||
| 5678 | * @param int|string $swapA <p>a key in the array</p> |
||
| 5679 | * @param int|string $swapB <p>a key in the array</p> |
||
| 5680 | * |
||
| 5681 | * @return static |
||
| 5682 | * <p>(Immutable)</p> |
||
| 5683 | * |
||
| 5684 | * @psalm-return static<TKey,T> |
||
| 5685 | * @psalm-mutation-free |
||
| 5686 | */ |
||
| 5687 | 1 | public function swap($swapA, $swapB): self |
|
| 5699 | |||
| 5700 | /** |
||
| 5701 | * Get the current array from the "Arrayy"-object. |
||
| 5702 | * alias for "getArray()" |
||
| 5703 | * |
||
| 5704 | * @param bool $convertAllArrayyElements <p> |
||
| 5705 | * Convert all Child-"Arrayy" objects also to arrays. |
||
| 5706 | * </p> |
||
| 5707 | * @param bool $preserveKeys <p> |
||
| 5708 | * e.g.: A generator maybe return the same key more then once, |
||
| 5709 | * so maybe you will ignore the keys. |
||
| 5710 | * </p> |
||
| 5711 | * |
||
| 5712 | * @return array |
||
| 5713 | * |
||
| 5714 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 5715 | * @psalm-mutation-free |
||
| 5716 | */ |
||
| 5717 | 944 | public function toArray( |
|
| 5742 | |||
| 5743 | /** |
||
| 5744 | * Get the current array from the "Arrayy"-object as list. |
||
| 5745 | * |
||
| 5746 | * @param bool $convertAllArrayyElements <p> |
||
| 5747 | * Convert all Child-"Arrayy" objects also to arrays. |
||
| 5748 | * </p> |
||
| 5749 | * |
||
| 5750 | * @return array |
||
| 5751 | * |
||
| 5752 | * @psalm-return list<array<TKey,T>> |
||
| 5753 | * @psalm-mutation-free |
||
| 5754 | */ |
||
| 5755 | 1 | public function toList(bool $convertAllArrayyElements = false): array |
|
| 5762 | |||
| 5763 | /** |
||
| 5764 | * Convert the current array to JSON. |
||
| 5765 | * |
||
| 5766 | * @param int $options [optional] <p>e.g. JSON_PRETTY_PRINT</p> |
||
| 5767 | * @param int $depth [optional] <p>Set the maximum depth. Must be greater than zero.</p> |
||
| 5768 | * |
||
| 5769 | * @return string |
||
| 5770 | */ |
||
| 5771 | 12 | public function toJson(int $options = 0, int $depth = 512): string |
|
| 5780 | |||
| 5781 | /** |
||
| 5782 | * @param string[]|null $items [optional] |
||
| 5783 | * @param string[] $helper [optional] |
||
| 5784 | * |
||
| 5785 | * @return static|static[] |
||
| 5786 | * |
||
| 5787 | * @psalm-return static<int, static<TKey,T>> |
||
| 5788 | */ |
||
| 5789 | 1 | public function toPermutation(array $items = null, array $helper = []): self |
|
| 5823 | |||
| 5824 | /** |
||
| 5825 | * Implodes array to a string with specified separator. |
||
| 5826 | * |
||
| 5827 | * @param string $separator [optional] <p>The element's separator.</p> |
||
| 5828 | * |
||
| 5829 | * @return string |
||
| 5830 | * <p>The string representation of array, separated by ",".</p> |
||
| 5831 | */ |
||
| 5832 | 19 | public function toString(string $separator = ','): string |
|
| 5836 | |||
| 5837 | /** |
||
| 5838 | * Return a duplicate free copy of the current array. |
||
| 5839 | * |
||
| 5840 | * @return $this |
||
| 5841 | * <p>(Mutable)</p> |
||
| 5842 | * |
||
| 5843 | * @psalm-return static<TKey,T> |
||
| 5844 | */ |
||
| 5845 | 13 | public function unique(): self |
|
| 5867 | |||
| 5868 | /** |
||
| 5869 | * Return a duplicate free copy of the current array. (with the old keys) |
||
| 5870 | * |
||
| 5871 | * @return $this |
||
| 5872 | * <p>(Mutable)</p> |
||
| 5873 | * |
||
| 5874 | * @psalm-return static<TKey,T> |
||
| 5875 | */ |
||
| 5876 | 11 | public function uniqueKeepIndex(): self |
|
| 5902 | |||
| 5903 | /** |
||
| 5904 | * alias: for "Arrayy->unique()" |
||
| 5905 | * |
||
| 5906 | * @return static |
||
| 5907 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
| 5908 | * |
||
| 5909 | * @see Arrayy::unique() |
||
| 5910 | * |
||
| 5911 | * @psalm-return static<TKey,T> |
||
| 5912 | */ |
||
| 5913 | 10 | public function uniqueNewIndex(): self |
|
| 5917 | |||
| 5918 | /** |
||
| 5919 | * Prepends one or more values to the beginning of array at once. |
||
| 5920 | * |
||
| 5921 | * @param array ...$args |
||
| 5922 | * |
||
| 5923 | * @return $this |
||
| 5924 | * <p>(Mutable) Return this Arrayy object, with prepended elements to the beginning of array.</p> |
||
| 5925 | * |
||
| 5926 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$args |
||
| 5927 | * @psalm-return static<TKey,T> |
||
| 5928 | */ |
||
| 5929 | 4 | public function unshift(...$args): self |
|
| 5937 | |||
| 5938 | /** |
||
| 5939 | * Tests whether the given closure return something valid for all elements of this array. |
||
| 5940 | * |
||
| 5941 | * @param \Closure $closure the predicate |
||
| 5942 | * |
||
| 5943 | * @return bool |
||
| 5944 | * <p>TRUE, if the predicate yields TRUE for all elements, FALSE otherwise.</p> |
||
| 5945 | */ |
||
| 5946 | 1 | View Code Duplication | public function validate(\Closure $closure): bool |
| 5956 | |||
| 5957 | /** |
||
| 5958 | * Get all values from a array. |
||
| 5959 | * |
||
| 5960 | * @return static |
||
| 5961 | * <p>(Immutable)</p> |
||
| 5962 | * |
||
| 5963 | * @psalm-return static<TKey,T> |
||
| 5964 | * @psalm-mutation-free |
||
| 5965 | */ |
||
| 5966 | 2 | public function values(): self |
|
| 5979 | |||
| 5980 | /** |
||
| 5981 | * Apply the given function to every element in the array, discarding the results. |
||
| 5982 | * |
||
| 5983 | * @param callable $callable |
||
| 5984 | * @param bool $recursive <p>Whether array will be walked recursively or no</p> |
||
| 5985 | * |
||
| 5986 | * @return $this |
||
| 5987 | * <p>(Mutable) Return this Arrayy object, with modified elements.</p> |
||
| 5988 | * |
||
| 5989 | * @psalm-return static<TKey,T> |
||
| 5990 | */ |
||
| 5991 | 12 | public function walk($callable, bool $recursive = false): self |
|
| 6005 | |||
| 6006 | /** |
||
| 6007 | * Returns a collection of matching items. |
||
| 6008 | * |
||
| 6009 | * @param string $keyOrPropertyOrMethod the property or method to evaluate |
||
| 6010 | * @param mixed $value the value to match |
||
| 6011 | * |
||
| 6012 | * @throws \InvalidArgumentException if property or method is not defined |
||
| 6013 | * |
||
| 6014 | * @return static |
||
| 6015 | * |
||
| 6016 | * @psalm-param T $value |
||
| 6017 | * @psalm-return static<TKey,T> |
||
| 6018 | */ |
||
| 6019 | 1 | public function where(string $keyOrPropertyOrMethod, $value): self |
|
| 6032 | |||
| 6033 | /** |
||
| 6034 | * Convert an array into a object. |
||
| 6035 | * |
||
| 6036 | * @param array $array |
||
| 6037 | * |
||
| 6038 | * @return \stdClass |
||
| 6039 | * |
||
| 6040 | * @psalm-param array<mixed,mixed> $array |
||
| 6041 | */ |
||
| 6042 | 4 | final protected static function arrayToObject(array $array = []): \stdClass |
|
| 6061 | |||
| 6062 | /** |
||
| 6063 | * @param array|\Generator|null $input <p> |
||
| 6064 | * An array containing keys to return. |
||
| 6065 | * </p> |
||
| 6066 | * @param mixed|null $search_values [optional] <p> |
||
| 6067 | * If specified, then only keys containing these values are returned. |
||
| 6068 | * </p> |
||
| 6069 | * @param bool $strict [optional] <p> |
||
| 6070 | * Determines if strict comparison (===) should be used during the |
||
| 6071 | * search. |
||
| 6072 | * </p> |
||
| 6073 | * |
||
| 6074 | * @return array |
||
| 6075 | * <p>an array of all the keys in input</p> |
||
| 6076 | * |
||
| 6077 | * @psalm-param array<mixed,mixed>|\Generator<TKey,T>|null $input |
||
| 6078 | * @psalm-return array<TKey|mixed> |
||
| 6079 | * @psalm-mutation-free |
||
| 6080 | */ |
||
| 6081 | 11 | protected function array_keys_recursive( |
|
| 6142 | |||
| 6143 | /** |
||
| 6144 | * @param mixed $path |
||
| 6145 | * @param callable $callable |
||
| 6146 | * @param array|null $currentOffset |
||
| 6147 | * |
||
| 6148 | * @return void |
||
| 6149 | * |
||
| 6150 | * @psalm-param array<mixed,mixed>|array<TKey,T>|null $currentOffset |
||
| 6151 | * @psalm-mutation-free |
||
| 6152 | */ |
||
| 6153 | 11 | protected function callAtPath($path, $callable, &$currentOffset = null) |
|
| 6182 | |||
| 6183 | /** |
||
| 6184 | * Extracts the value of the given property or method from the object. |
||
| 6185 | * |
||
| 6186 | * @param static $object <p>The object to extract the value from.</p> |
||
| 6187 | * @param string $keyOrPropertyOrMethod <p>The property or method for which the |
||
| 6188 | * value should be extracted.</p> |
||
| 6189 | * |
||
| 6190 | * @throws \InvalidArgumentException if the method or property is not defined |
||
| 6191 | * |
||
| 6192 | * @return mixed |
||
| 6193 | * <p>The value extracted from the specified property or method.</p> |
||
| 6194 | * |
||
| 6195 | * @psalm-param self<TKey,T> $object |
||
| 6196 | */ |
||
| 6197 | 2 | final protected function extractValue(self $object, string $keyOrPropertyOrMethod) |
|
| 6219 | |||
| 6220 | /** |
||
| 6221 | * create a fallback for array |
||
| 6222 | * |
||
| 6223 | * 1. use the current array, if it's a array |
||
| 6224 | * 2. fallback to empty array, if there is nothing |
||
| 6225 | * 3. call "getArray()" on object, if there is a "Arrayy"-object |
||
| 6226 | * 4. call "createFromObject()" on object, if there is a "\Traversable"-object |
||
| 6227 | * 5. call "__toArray()" on object, if the method exists |
||
| 6228 | * 6. cast a string or object with "__toString()" into an array |
||
| 6229 | * 7. throw a "InvalidArgumentException"-Exception |
||
| 6230 | * |
||
| 6231 | * @param mixed $data |
||
| 6232 | * |
||
| 6233 | * @throws \InvalidArgumentException |
||
| 6234 | * |
||
| 6235 | * @return array |
||
| 6236 | * |
||
| 6237 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 6238 | */ |
||
| 6239 | 1197 | protected function fallbackForArray(&$data): array |
|
| 6249 | |||
| 6250 | /** |
||
| 6251 | * @param bool $preserveKeys <p> |
||
| 6252 | * e.g.: A generator maybe return the same key more then once, |
||
| 6253 | * so maybe you will ignore the keys. |
||
| 6254 | * </p> |
||
| 6255 | * |
||
| 6256 | * @return bool |
||
| 6257 | * |
||
| 6258 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
| 6259 | * @psalm-mutation-free :/ |
||
| 6260 | */ |
||
| 6261 | 1109 | protected function generatorToArray(bool $preserveKeys = true) |
|
| 6272 | |||
| 6273 | /** |
||
| 6274 | * Get correct PHP constant for direction. |
||
| 6275 | * |
||
| 6276 | * @param int|string $direction |
||
| 6277 | * |
||
| 6278 | * @return int |
||
| 6279 | * @psalm-mutation-free |
||
| 6280 | */ |
||
| 6281 | 43 | protected function getDirection($direction): int |
|
| 6303 | |||
| 6304 | /** |
||
| 6305 | * @return TypeCheckInterface[] |
||
| 6306 | * |
||
| 6307 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
| 6308 | */ |
||
| 6309 | 22 | protected function getPropertiesFromPhpDoc() |
|
| 6340 | |||
| 6341 | /** |
||
| 6342 | * @param mixed $glue |
||
| 6343 | * @param mixed $pieces |
||
| 6344 | * @param bool $useKeys |
||
| 6345 | * |
||
| 6346 | * @return string |
||
| 6347 | * @psalm-mutation-free |
||
| 6348 | */ |
||
| 6349 | 36 | protected function implode_recursive( |
|
| 6382 | |||
| 6383 | /** |
||
| 6384 | * @param mixed $needle <p> |
||
| 6385 | * The searched value. |
||
| 6386 | * </p> |
||
| 6387 | * <p> |
||
| 6388 | * If needle is a string, the comparison is done |
||
| 6389 | * in a case-sensitive manner. |
||
| 6390 | * </p> |
||
| 6391 | * @param array|\Generator|null $haystack <p> |
||
| 6392 | * The array. |
||
| 6393 | * </p> |
||
| 6394 | * @param bool $strict [optional] <p> |
||
| 6395 | * If the third parameter strict is set to true |
||
| 6396 | * then the in_array function will also check the |
||
| 6397 | * types of the |
||
| 6398 | * needle in the haystack. |
||
| 6399 | * </p> |
||
| 6400 | * |
||
| 6401 | * @return bool |
||
| 6402 | * <p>true if needle is found in the array, false otherwise</p> |
||
| 6403 | * |
||
| 6404 | * @psalm-param array<mixed,mixed>|\Generator<TKey,T>|null $haystack |
||
| 6405 | * @psalm-mutation-free |
||
| 6406 | */ |
||
| 6407 | 19 | protected function in_array_recursive($needle, $haystack = null, $strict = true): bool |
|
| 6432 | |||
| 6433 | /** |
||
| 6434 | * @param mixed $data |
||
| 6435 | * |
||
| 6436 | * @return array|null |
||
| 6437 | * |
||
| 6438 | * @psalm-return array<mixed,mixed>|array<TKey,T>|null |
||
| 6439 | */ |
||
| 6440 | 1197 | protected function internalGetArray(&$data) |
|
| 6491 | |||
| 6492 | /** |
||
| 6493 | * Internal mechanics of remove method. |
||
| 6494 | * |
||
| 6495 | * @param mixed $key |
||
| 6496 | * |
||
| 6497 | * @return bool |
||
| 6498 | */ |
||
| 6499 | 21 | protected function internalRemove($key): bool |
|
| 6532 | |||
| 6533 | /** |
||
| 6534 | * Internal mechanic of set method. |
||
| 6535 | * |
||
| 6536 | * @param int|string|null $key |
||
| 6537 | * @param mixed $value |
||
| 6538 | * @param bool $checkProperties |
||
| 6539 | * |
||
| 6540 | * @return bool |
||
| 6541 | */ |
||
| 6542 | 1047 | protected function internalSet( |
|
| 6601 | |||
| 6602 | /** |
||
| 6603 | * Convert a object into an array. |
||
| 6604 | * |
||
| 6605 | * @param mixed|object $object |
||
| 6606 | * |
||
| 6607 | * @return array|mixed |
||
| 6608 | * |
||
| 6609 | * @psalm-mutation-free |
||
| 6610 | */ |
||
| 6611 | 5 | protected static function objectToArray($object) |
|
| 6624 | |||
| 6625 | /** |
||
| 6626 | * @param array $data |
||
| 6627 | * @param bool $checkPropertiesInConstructor |
||
| 6628 | * |
||
| 6629 | * @return void |
||
| 6630 | * |
||
| 6631 | * @psalm-param array<mixed,T> $data |
||
| 6632 | */ |
||
| 6633 | 1195 | protected function setInitialValuesAndProperties(array &$data, bool $checkPropertiesInConstructor) |
|
| 6678 | |||
| 6679 | /** |
||
| 6680 | * sorting keys |
||
| 6681 | * |
||
| 6682 | * @param array $elements |
||
| 6683 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 6684 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 6685 | * <strong>SORT_NATURAL</strong></p> |
||
| 6686 | * |
||
| 6687 | * @return $this |
||
| 6688 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 6689 | * |
||
| 6690 | * @psalm-param array<mixed,mixed>|array<mixed|TKey,T> $elements |
||
| 6691 | * @psalm-return static<TKey,T> |
||
| 6692 | */ |
||
| 6693 | 18 | protected function sorterKeys( |
|
| 6714 | |||
| 6715 | /** |
||
| 6716 | * @param array $elements <p>Warning: used as reference</p> |
||
| 6717 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 6718 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 6719 | * <strong>SORT_NATURAL</strong></p> |
||
| 6720 | * @param bool $keepKeys |
||
| 6721 | * |
||
| 6722 | * @return $this |
||
| 6723 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 6724 | * |
||
| 6725 | * @psalm-param array<mixed,mixed>|array<mixed|TKey,T> $elements |
||
| 6726 | * @psalm-return static<TKey,T> |
||
| 6727 | */ |
||
| 6728 | 24 | protected function sorting(array &$elements, $direction = \SORT_ASC, int $strategy = \SORT_REGULAR, bool $keepKeys = false): self |
|
| 6758 | |||
| 6759 | /** |
||
| 6760 | * @param array $array |
||
| 6761 | * |
||
| 6762 | * @return array |
||
| 6763 | * |
||
| 6764 | * @psalm-mutation-free |
||
| 6765 | */ |
||
| 6766 | 25 | private function getArrayRecursiveHelperArrayy(array $array) |
|
| 6788 | |||
| 6789 | /** |
||
| 6790 | * @param int|string|null $key |
||
| 6791 | * @param mixed $value |
||
| 6792 | * |
||
| 6793 | * @return void |
||
| 6794 | */ |
||
| 6795 | 109 | private function checkType($key, $value) |
|
| 6813 | } |
||
| 6814 |
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..