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 | const ARRAYY_HELPER_WALK = '!!!!Arrayy_Helper_Walk!!!!'; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var array |
||
| 35 | * |
||
| 36 | * @psalm-var array<mixed,mixed>|array<TKey,T> |
||
| 37 | */ |
||
| 38 | protected $array = []; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @var \Arrayy\ArrayyRewindableGenerator|null |
||
| 42 | * |
||
| 43 | * @psalm-var \Arrayy\ArrayyRewindableGenerator<TKey,T>|null |
||
| 44 | */ |
||
| 45 | protected $generator; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @var string |
||
| 49 | * |
||
| 50 | * @psalm-var class-string<\Arrayy\ArrayyIterator> |
||
| 51 | */ |
||
| 52 | protected $iteratorClass = ArrayyIterator::class; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @var string |
||
| 56 | */ |
||
| 57 | protected $pathSeparator = '.'; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @var bool |
||
| 61 | */ |
||
| 62 | protected $checkPropertyTypes = false; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @var bool |
||
| 66 | */ |
||
| 67 | protected $checkForMissingPropertiesInConstructor = false; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @var bool |
||
| 71 | */ |
||
| 72 | protected $checkPropertiesMismatchInConstructor = false; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @var bool |
||
| 76 | */ |
||
| 77 | protected $checkPropertiesMismatch = true; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @var array<int|string,TypeCheckInterface>|mixed|TypeCheckArray<int|string,TypeCheckInterface>|TypeInterface |
||
| 81 | */ |
||
| 82 | protected $properties = []; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Initializes |
||
| 86 | * |
||
| 87 | * @param mixed $data <p> |
||
| 88 | * Should be an array or a generator, otherwise it will try |
||
| 89 | * to convert it into an array. |
||
| 90 | * </p> |
||
| 91 | * @param string $iteratorClass optional <p> |
||
| 92 | * You can overwrite the ArrayyIterator, but mostly you don't |
||
| 93 | * need this option. |
||
| 94 | * </p> |
||
| 95 | * @param bool $checkPropertiesInConstructor optional <p> |
||
| 96 | * You need to extend the "Arrayy"-class and you need to set |
||
| 97 | * the $checkPropertiesMismatchInConstructor class property |
||
| 98 | * to |
||
| 99 | * true, otherwise this option didn't not work anyway. |
||
| 100 | * </p> |
||
| 101 | * |
||
| 102 | * @psalm-param class-string<\Arrayy\ArrayyIterator> $iteratorClass |
||
| 103 | */ |
||
| 104 | 1212 | public function __construct( |
|
| 121 | |||
| 122 | /** |
||
| 123 | * @return void |
||
| 124 | */ |
||
| 125 | 52 | public function __clone() |
|
| 135 | |||
| 136 | /** |
||
| 137 | * Call object as function. |
||
| 138 | * |
||
| 139 | * @param mixed $key |
||
| 140 | * |
||
| 141 | * @return mixed |
||
| 142 | */ |
||
| 143 | 1 | public function __invoke($key = null) |
|
| 153 | |||
| 154 | /** |
||
| 155 | * Whether or not an element exists by key. |
||
| 156 | * |
||
| 157 | * @param mixed $key |
||
| 158 | * |
||
| 159 | * @return bool |
||
| 160 | * <p>True is the key/index exists, otherwise false.</p> |
||
| 161 | */ |
||
| 162 | public function __isset($key): bool |
||
| 166 | |||
| 167 | /** |
||
| 168 | * Assigns a value to the specified element. |
||
| 169 | * |
||
| 170 | * @param mixed $key |
||
| 171 | * @param mixed $value |
||
| 172 | * |
||
| 173 | * @return void |
||
| 174 | */ |
||
| 175 | 3 | public function __set($key, $value) |
|
| 179 | |||
| 180 | /** |
||
| 181 | * magic to string |
||
| 182 | * |
||
| 183 | * @return string |
||
| 184 | */ |
||
| 185 | 15 | public function __toString(): string |
|
| 189 | |||
| 190 | /** |
||
| 191 | * Unset element by key. |
||
| 192 | * |
||
| 193 | * @param mixed $key |
||
| 194 | */ |
||
| 195 | public function __unset($key) |
||
| 199 | |||
| 200 | /** |
||
| 201 | * Get a value by key. |
||
| 202 | * |
||
| 203 | * @param mixed $key |
||
| 204 | * |
||
| 205 | * @return mixed |
||
| 206 | * <p>Get a Value from the current array.</p> |
||
| 207 | */ |
||
| 208 | 133 | public function &__get($key) |
|
| 222 | |||
| 223 | /** |
||
| 224 | * Add new values (optional using dot-notation). |
||
| 225 | * |
||
| 226 | * @param mixed $value |
||
| 227 | * @param int|string|null $key |
||
| 228 | * |
||
| 229 | * @return static |
||
| 230 | * <p>(Immutable) Return this Arrayy object, with the appended values.</p> |
||
| 231 | * |
||
| 232 | * @psalm-param T $value |
||
| 233 | * @psalm-return static<TKey,T> |
||
| 234 | * |
||
| 235 | * @psalm-param T $value |
||
| 236 | * @psalm-param TKey $key |
||
| 237 | * @psalm-mutation-free |
||
| 238 | */ |
||
| 239 | 13 | public function add($value, $key = null) |
|
| 257 | |||
| 258 | /** |
||
| 259 | * Append a (key) + value to the current array. |
||
| 260 | * |
||
| 261 | * EXAMPLE: <code> |
||
| 262 | * a(['fòô' => 'bàř'])->append('foo'); // Arrayy['fòô' => 'bàř', 0 => 'foo'] |
||
| 263 | * </code> |
||
| 264 | * |
||
| 265 | * @param mixed $value |
||
| 266 | * @param mixed $key |
||
| 267 | * |
||
| 268 | * @return $this |
||
| 269 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
| 270 | * |
||
| 271 | * @psalm-param T $value |
||
| 272 | * @psalm-param TKey|null $key |
||
| 273 | * @psalm-return static<TKey,T> |
||
| 274 | */ |
||
| 275 | 20 | public function append($value, $key = null): self |
|
| 299 | |||
| 300 | /** |
||
| 301 | * Append a (key) + value to the current array. |
||
| 302 | * |
||
| 303 | * EXAMPLE: <code> |
||
| 304 | * a(['fòô' => 'bàř'])->appendImmutable('foo')->getArray(); // ['fòô' => 'bàř', 0 => 'foo'] |
||
| 305 | * </code> |
||
| 306 | * |
||
| 307 | * @param mixed $value |
||
| 308 | * @param mixed $key |
||
| 309 | * |
||
| 310 | * @return $this |
||
| 311 | * <p>(Immutable) Return this Arrayy object, with the appended values.</p> |
||
| 312 | * |
||
| 313 | * @psalm-param T $value |
||
| 314 | * @psalm-param TKey $key |
||
| 315 | * @psalm-return static<TKey,T> |
||
| 316 | * @psalm-mutation-free |
||
| 317 | */ |
||
| 318 | 1 | View Code Duplication | public function appendImmutable($value, $key = null): self |
| 343 | |||
| 344 | /** |
||
| 345 | * Sort the entries by value. |
||
| 346 | * |
||
| 347 | * @param int $sort_flags [optional] <p> |
||
| 348 | * You may modify the behavior of the sort using the optional |
||
| 349 | * parameter sort_flags, for details |
||
| 350 | * see sort. |
||
| 351 | * </p> |
||
| 352 | * |
||
| 353 | * @return $this |
||
| 354 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 355 | * |
||
| 356 | * @psalm-return static<TKey,T> |
||
| 357 | */ |
||
| 358 | 4 | public function asort(int $sort_flags = 0): self |
|
| 366 | |||
| 367 | /** |
||
| 368 | * Sort the entries by value. |
||
| 369 | * |
||
| 370 | * @param int $sort_flags [optional] <p> |
||
| 371 | * You may modify the behavior of the sort using the optional |
||
| 372 | * parameter sort_flags, for details |
||
| 373 | * see sort. |
||
| 374 | * </p> |
||
| 375 | * |
||
| 376 | * @return $this |
||
| 377 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 378 | * |
||
| 379 | * @psalm-return static<TKey,T> |
||
| 380 | * @psalm-mutation-free |
||
| 381 | */ |
||
| 382 | 4 | public function asortImmutable(int $sort_flags = 0): self |
|
| 393 | |||
| 394 | /** |
||
| 395 | * Counts all elements in an array, or something in an object. |
||
| 396 | * |
||
| 397 | * EXAMPLE: <code> |
||
| 398 | * a([-9, -8, -7, 1.32])->count(); // 4 |
||
| 399 | * </code> |
||
| 400 | * |
||
| 401 | * <p> |
||
| 402 | * For objects, if you have SPL installed, you can hook into count() by implementing interface {@see Countable}. |
||
| 403 | * The interface has exactly one method, {@see Countable::count()}, which returns the return value for the count() |
||
| 404 | * function. Please see the {@see Array} section of the manual for a detailed explanation of how arrays are |
||
| 405 | * implemented and used in PHP. |
||
| 406 | * </p> |
||
| 407 | * |
||
| 408 | * @see http://php.net/manual/en/function.count.php |
||
| 409 | * |
||
| 410 | * @param int $mode [optional] If the optional mode parameter is set to |
||
| 411 | * COUNT_RECURSIVE (or 1), count |
||
| 412 | * will recursively count the array. This is particularly useful for |
||
| 413 | * counting all the elements of a multidimensional array. count does not detect infinite recursion. |
||
| 414 | * |
||
| 415 | * @return int |
||
| 416 | * <p> |
||
| 417 | * The number of elements in var, which is |
||
| 418 | * typically an array, since anything else will have one |
||
| 419 | * element. |
||
| 420 | * </p> |
||
| 421 | * <p> |
||
| 422 | * If var is not an array or an object with |
||
| 423 | * implemented Countable interface, |
||
| 424 | * 1 will be returned. |
||
| 425 | * There is one exception, if var is &null;, |
||
| 426 | * 0 will be returned. |
||
| 427 | * </p> |
||
| 428 | * <p> |
||
| 429 | * Caution: count may return 0 for a variable that isn't set, |
||
| 430 | * but it may also return 0 for a variable that has been initialized with an |
||
| 431 | * empty array. Use isset to test if a variable is set. |
||
| 432 | * </p> |
||
| 433 | * @psalm-mutation-free |
||
| 434 | */ |
||
| 435 | 147 | public function count(int $mode = \COUNT_NORMAL): int |
|
| 447 | |||
| 448 | /** |
||
| 449 | * Exchange the array for another one. |
||
| 450 | * |
||
| 451 | * @param array|mixed|static $data |
||
| 452 | * |
||
| 453 | * 1. use the current array, if it's a array |
||
| 454 | * 2. fallback to empty array, if there is nothing |
||
| 455 | * 3. call "getArray()" on object, if there is a "Arrayy"-object |
||
| 456 | * 4. call "createFromObject()" on object, if there is a "\Traversable"-object |
||
| 457 | * 5. call "__toArray()" on object, if the method exists |
||
| 458 | * 6. cast a string or object with "__toString()" into an array |
||
| 459 | * 7. throw a "InvalidArgumentException"-Exception |
||
| 460 | * |
||
| 461 | * @return array |
||
| 462 | * |
||
| 463 | * @psalm-param T,array<TKey,T>|self<TKey,T> $data |
||
| 464 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 465 | */ |
||
| 466 | 1 | public function exchangeArray($data): array |
|
| 473 | |||
| 474 | /** |
||
| 475 | * Creates a copy of the ArrayyObject. |
||
| 476 | * |
||
| 477 | * @return array |
||
| 478 | * |
||
| 479 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 480 | */ |
||
| 481 | 6 | public function getArrayCopy(): array |
|
| 487 | |||
| 488 | /** |
||
| 489 | * Returns a new iterator, thus implementing the \Iterator interface. |
||
| 490 | * |
||
| 491 | * EXAMPLE: <code> |
||
| 492 | * a(['foo', 'bar'])->getIterator(); // ArrayyIterator['foo', 'bar'] |
||
| 493 | * </code> |
||
| 494 | * |
||
| 495 | * @return \Iterator<mixed, mixed> |
||
| 496 | * <p>An iterator for the values in the array.</p> |
||
| 497 | * @psalm-return \Iterator<array-key|TKey, mixed|T> |
||
| 498 | */ |
||
| 499 | 28 | public function getIterator(): \Iterator |
|
| 525 | |||
| 526 | /** |
||
| 527 | * Gets the iterator classname for the ArrayObject. |
||
| 528 | * |
||
| 529 | * @return string |
||
| 530 | * |
||
| 531 | * @psalm-return class-string |
||
| 532 | */ |
||
| 533 | 27 | public function getIteratorClass(): string |
|
| 537 | |||
| 538 | /** |
||
| 539 | * Sort the entries by key. |
||
| 540 | * |
||
| 541 | * @param int $sort_flags [optional] <p> |
||
| 542 | * You may modify the behavior of the sort using the optional |
||
| 543 | * parameter sort_flags, for details |
||
| 544 | * see sort. |
||
| 545 | * </p> |
||
| 546 | * |
||
| 547 | * @return $this |
||
| 548 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 549 | * |
||
| 550 | * @psalm-return static<TKey,T> |
||
| 551 | */ |
||
| 552 | 4 | public function ksort(int $sort_flags = 0): self |
|
| 560 | |||
| 561 | /** |
||
| 562 | * Sort the entries by key. |
||
| 563 | * |
||
| 564 | * @param int $sort_flags [optional] <p> |
||
| 565 | * You may modify the behavior of the sort using the optional |
||
| 566 | * parameter sort_flags, for details |
||
| 567 | * see sort. |
||
| 568 | * </p> |
||
| 569 | * |
||
| 570 | * @return $this |
||
| 571 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 572 | * |
||
| 573 | * @psalm-return static<TKey,T> |
||
| 574 | */ |
||
| 575 | 4 | public function ksortImmutable(int $sort_flags = 0): self |
|
| 586 | |||
| 587 | /** |
||
| 588 | * Sort an array using a case insensitive "natural order" algorithm. |
||
| 589 | * |
||
| 590 | * @return $this |
||
| 591 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 592 | * |
||
| 593 | * @psalm-return static<TKey,T> |
||
| 594 | */ |
||
| 595 | 8 | public function natcasesort(): self |
|
| 603 | |||
| 604 | /** |
||
| 605 | * Sort an array using a case insensitive "natural order" algorithm. |
||
| 606 | * |
||
| 607 | * @return $this |
||
| 608 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 609 | * |
||
| 610 | * @psalm-return static<TKey,T> |
||
| 611 | * @psalm-mutation-free |
||
| 612 | */ |
||
| 613 | 4 | public function natcasesortImmutable(): self |
|
| 624 | |||
| 625 | /** |
||
| 626 | * Sort entries using a "natural order" algorithm. |
||
| 627 | * |
||
| 628 | * @return $this |
||
| 629 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 630 | * |
||
| 631 | * @psalm-return static<TKey,T> |
||
| 632 | */ |
||
| 633 | 10 | public function natsort(): self |
|
| 641 | |||
| 642 | /** |
||
| 643 | * Sort entries using a "natural order" algorithm. |
||
| 644 | * |
||
| 645 | * @return $this |
||
| 646 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 647 | * |
||
| 648 | * @psalm-return static<TKey,T> |
||
| 649 | * @psalm-mutation-free |
||
| 650 | */ |
||
| 651 | 4 | public function natsortImmutable(): self |
|
| 662 | |||
| 663 | /** |
||
| 664 | * Whether or not an offset exists. |
||
| 665 | * |
||
| 666 | * @param bool|int|string $offset |
||
| 667 | * |
||
| 668 | * @return bool |
||
| 669 | * |
||
| 670 | * @noinspection PhpSillyAssignmentInspection |
||
| 671 | * |
||
| 672 | * @psalm-mutation-free |
||
| 673 | */ |
||
| 674 | 164 | public function offsetExists($offset): bool |
|
| 721 | |||
| 722 | /** |
||
| 723 | * Returns the value at specified offset. |
||
| 724 | * |
||
| 725 | * @param int|string $offset |
||
| 726 | * |
||
| 727 | * @return mixed |
||
| 728 | * <p>Will return null if the offset did not exists.</p> |
||
| 729 | */ |
||
| 730 | 133 | public function &offsetGet($offset) |
|
| 741 | |||
| 742 | /** |
||
| 743 | * Assigns a value to the specified offset + check the type. |
||
| 744 | * |
||
| 745 | * @param int|string|null $offset |
||
| 746 | * @param mixed $value |
||
| 747 | * |
||
| 748 | * @return void |
||
| 749 | */ |
||
| 750 | 28 | public function offsetSet($offset, $value) |
|
| 768 | |||
| 769 | /** |
||
| 770 | * Unset an offset. |
||
| 771 | * |
||
| 772 | * @param int|string $offset |
||
| 773 | * |
||
| 774 | * @return void |
||
| 775 | * <p>(Mutable) Return nothing.</p> |
||
| 776 | */ |
||
| 777 | 26 | public function offsetUnset($offset) |
|
| 828 | |||
| 829 | /** |
||
| 830 | * Serialize the current "Arrayy"-object. |
||
| 831 | * |
||
| 832 | * EXAMPLE: <code> |
||
| 833 | * a([1, 4, 7])->serialize(); |
||
| 834 | * </code> |
||
| 835 | * |
||
| 836 | * @return string |
||
| 837 | */ |
||
| 838 | 2 | public function serialize(): string |
|
| 848 | |||
| 849 | /** |
||
| 850 | * Sets the iterator classname for the current "Arrayy"-object. |
||
| 851 | * |
||
| 852 | * @param string $iteratorClass |
||
| 853 | * |
||
| 854 | * @throws \InvalidArgumentException |
||
| 855 | * |
||
| 856 | * @return void |
||
| 857 | * |
||
| 858 | * @psalm-param class-string<\Arrayy\ArrayyIterator> $iteratorClass |
||
| 859 | */ |
||
| 860 | 1202 | public function setIteratorClass($iteratorClass) |
|
| 882 | |||
| 883 | /** |
||
| 884 | * Sort the entries with a user-defined comparison function and maintain key association. |
||
| 885 | * |
||
| 886 | * @param callable $function |
||
| 887 | * |
||
| 888 | * @throws \InvalidArgumentException |
||
| 889 | * |
||
| 890 | * @return $this |
||
| 891 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 892 | * |
||
| 893 | * @psalm-return static<TKey,T> |
||
| 894 | */ |
||
| 895 | 8 | View Code Duplication | public function uasort($function): self |
| 907 | |||
| 908 | /** |
||
| 909 | * Sort the entries with a user-defined comparison function and maintain key association. |
||
| 910 | * |
||
| 911 | * @param callable $function |
||
| 912 | * |
||
| 913 | * @throws \InvalidArgumentException |
||
| 914 | * |
||
| 915 | * @return $this |
||
| 916 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 917 | * |
||
| 918 | * @psalm-return static<TKey,T> |
||
| 919 | * @psalm-mutation-free |
||
| 920 | */ |
||
| 921 | 4 | public function uasortImmutable($function): self |
|
| 932 | |||
| 933 | /** |
||
| 934 | * Sort the entries by keys using a user-defined comparison function. |
||
| 935 | * |
||
| 936 | * @param callable $function |
||
| 937 | * |
||
| 938 | * @throws \InvalidArgumentException |
||
| 939 | * |
||
| 940 | * @return static |
||
| 941 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 942 | * |
||
| 943 | * @psalm-return static<TKey,T> |
||
| 944 | */ |
||
| 945 | 5 | public function uksort($function): self |
|
| 949 | |||
| 950 | /** |
||
| 951 | * Sort the entries by keys using a user-defined comparison function. |
||
| 952 | * |
||
| 953 | * @param callable $function |
||
| 954 | * |
||
| 955 | * @throws \InvalidArgumentException |
||
| 956 | * |
||
| 957 | * @return static |
||
| 958 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 959 | * |
||
| 960 | * @psalm-return static<TKey,T> |
||
| 961 | * @psalm-mutation-free |
||
| 962 | */ |
||
| 963 | 1 | public function uksortImmutable($function): self |
|
| 967 | |||
| 968 | /** |
||
| 969 | * Unserialize an string and return the instance of the "Arrayy"-class. |
||
| 970 | * |
||
| 971 | * EXAMPLE: <code> |
||
| 972 | * $serialized = a([1, 4, 7])->serialize(); |
||
| 973 | * a()->unserialize($serialized); |
||
| 974 | * </code> |
||
| 975 | * |
||
| 976 | * @param string $string |
||
| 977 | * |
||
| 978 | * @return $this |
||
| 979 | * |
||
| 980 | * @psalm-return static<TKey,T> |
||
| 981 | */ |
||
| 982 | 2 | public function unserialize($string): self |
|
| 992 | |||
| 993 | /** |
||
| 994 | * Append a (key) + values to the current array. |
||
| 995 | * |
||
| 996 | * EXAMPLE: <code> |
||
| 997 | * a(['fòô' => ['bàř']])->appendArrayValues(['foo1', 'foo2'], 'fòô'); // Arrayy['fòô' => ['bàř', 'foo1', 'foo2']] |
||
| 998 | * </code> |
||
| 999 | * |
||
| 1000 | * @param array $values |
||
| 1001 | * @param mixed $key |
||
| 1002 | * |
||
| 1003 | * @return $this |
||
| 1004 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
| 1005 | * |
||
| 1006 | * @psalm-param array<array-key,T> $values |
||
| 1007 | * @psalm-param TKey|null $key |
||
| 1008 | * @psalm-return static<TKey,T> |
||
| 1009 | */ |
||
| 1010 | 1 | public function appendArrayValues(array $values, $key = null) |
|
| 1036 | |||
| 1037 | /** |
||
| 1038 | * Add a suffix to each key. |
||
| 1039 | * |
||
| 1040 | * @param int|string $prefix |
||
| 1041 | * |
||
| 1042 | * @return static |
||
| 1043 | * <p>(Immutable) Return an Arrayy object, with the prefixed keys.</p> |
||
| 1044 | * |
||
| 1045 | * @psalm-return static<TKey,T> |
||
| 1046 | * @psalm-mutation-free |
||
| 1047 | */ |
||
| 1048 | 10 | View Code Duplication | public function appendToEachKey($prefix): self |
| 1071 | |||
| 1072 | /** |
||
| 1073 | * Add a prefix to each value. |
||
| 1074 | * |
||
| 1075 | * @param mixed $prefix |
||
| 1076 | * |
||
| 1077 | * @return static |
||
| 1078 | * <p>(Immutable) Return an Arrayy object, with the prefixed values.</p> |
||
| 1079 | * |
||
| 1080 | * @psalm-return static<TKey,T> |
||
| 1081 | * @psalm-mutation-free |
||
| 1082 | */ |
||
| 1083 | 10 | View Code Duplication | public function appendToEachValue($prefix): self |
| 1102 | |||
| 1103 | /** |
||
| 1104 | * Sort an array in reverse order and maintain index association. |
||
| 1105 | * |
||
| 1106 | * @return $this |
||
| 1107 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1108 | * |
||
| 1109 | * @psalm-return static<TKey,T> |
||
| 1110 | */ |
||
| 1111 | 4 | public function arsort(): self |
|
| 1119 | |||
| 1120 | /** |
||
| 1121 | * Sort an array in reverse order and maintain index association. |
||
| 1122 | * |
||
| 1123 | * @return $this |
||
| 1124 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 1125 | * |
||
| 1126 | * @psalm-return static<TKey,T> |
||
| 1127 | * @psalm-mutation-free |
||
| 1128 | */ |
||
| 1129 | 10 | public function arsortImmutable(): self |
|
| 1139 | |||
| 1140 | /** |
||
| 1141 | * Iterate over the current array and execute a callback for each loop. |
||
| 1142 | * |
||
| 1143 | * EXAMPLE: <code> |
||
| 1144 | * $result = A::create(); |
||
| 1145 | * $closure = function ($value, $key) use ($result) { |
||
| 1146 | * $result[$key] = ':' . $value . ':'; |
||
| 1147 | * }; |
||
| 1148 | * a(['foo', 'bar' => 'bis'])->at($closure); // Arrayy[':foo:', 'bar' => ':bis:'] |
||
| 1149 | * </code> |
||
| 1150 | * |
||
| 1151 | * @param \Closure $closure |
||
| 1152 | * |
||
| 1153 | * @return static |
||
| 1154 | * <p>(Immutable)</p> |
||
| 1155 | * |
||
| 1156 | * @psalm-return static<TKey,T> |
||
| 1157 | * @psalm-mutation-free |
||
| 1158 | */ |
||
| 1159 | 3 | public function at(\Closure $closure): self |
|
| 1173 | |||
| 1174 | /** |
||
| 1175 | * Returns the average value of the current array. |
||
| 1176 | * |
||
| 1177 | * EXAMPLE: <code> |
||
| 1178 | * a([-9, -8, -7, 1.32])->average(2); // -5.67 |
||
| 1179 | * </code> |
||
| 1180 | * |
||
| 1181 | * @param int $decimals <p>The number of decimal-numbers to return.</p> |
||
| 1182 | * |
||
| 1183 | * @return float|int |
||
| 1184 | * <p>The average value.</p> |
||
| 1185 | * @psalm-mutation-free |
||
| 1186 | */ |
||
| 1187 | 10 | public function average($decimals = 0) |
|
| 1201 | |||
| 1202 | /** |
||
| 1203 | * Changes all keys in an array. |
||
| 1204 | * |
||
| 1205 | * @param int $case [optional] <p> Either <strong>CASE_UPPER</strong><br /> |
||
| 1206 | * or <strong>CASE_LOWER</strong> (default)</p> |
||
| 1207 | * |
||
| 1208 | * @return static |
||
| 1209 | * <p>(Immutable)</p> |
||
| 1210 | * |
||
| 1211 | * @psalm-return static<TKey,T> |
||
| 1212 | * @psalm-mutation-free |
||
| 1213 | */ |
||
| 1214 | 1 | public function changeKeyCase(int $case = \CASE_LOWER): self |
|
| 1243 | |||
| 1244 | /** |
||
| 1245 | * Change the path separator of the array wrapper. |
||
| 1246 | * |
||
| 1247 | * By default, the separator is: "." |
||
| 1248 | * |
||
| 1249 | * @param string $separator <p>Separator to set.</p> |
||
| 1250 | * |
||
| 1251 | * @return $this |
||
| 1252 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1253 | * |
||
| 1254 | * @psalm-return static<TKey,T> |
||
| 1255 | */ |
||
| 1256 | 11 | public function changeSeparator($separator): self |
|
| 1262 | |||
| 1263 | /** |
||
| 1264 | * Create a chunked version of the current array. |
||
| 1265 | * |
||
| 1266 | * EXAMPLE: <code> |
||
| 1267 | * a([-9, -8, -7, 1.32])->chunk(2); // Arrayy[[-9, -8], [-7, 1.32]] |
||
| 1268 | * </code> |
||
| 1269 | * |
||
| 1270 | * @param int $size <p>Size of each chunk.</p> |
||
| 1271 | * @param bool $preserveKeys <p>Whether array keys are preserved or no.</p> |
||
| 1272 | * |
||
| 1273 | * @return static |
||
| 1274 | * <p>(Immutable) A new array of chunks from the original array.</p> |
||
| 1275 | * |
||
| 1276 | * @psalm-return static<TKey,T> |
||
| 1277 | * @psalm-mutation-free |
||
| 1278 | */ |
||
| 1279 | 5 | public function chunk($size, $preserveKeys = false): self |
|
| 1329 | |||
| 1330 | /** |
||
| 1331 | * Clean all falsy values from the current array. |
||
| 1332 | * |
||
| 1333 | * EXAMPLE: <code> |
||
| 1334 | * a([-8 => -9, 1, 2 => false])->clean(); // Arrayy[-8 => -9, 1] |
||
| 1335 | * </code> |
||
| 1336 | * |
||
| 1337 | * @return static |
||
| 1338 | * <p>(Immutable)</p> |
||
| 1339 | * |
||
| 1340 | * @psalm-return static<TKey,T> |
||
| 1341 | * @psalm-mutation-free |
||
| 1342 | */ |
||
| 1343 | 8 | public function clean(): self |
|
| 1351 | |||
| 1352 | /** |
||
| 1353 | * WARNING!!! -> Clear the current full array or a $key of it. |
||
| 1354 | * |
||
| 1355 | * EXAMPLE: <code> |
||
| 1356 | * a([-8 => -9, 1, 2 => false])->clear(); // Arrayy[] |
||
| 1357 | * </code> |
||
| 1358 | * |
||
| 1359 | * @param int|int[]|string|string[]|null $key |
||
| 1360 | * |
||
| 1361 | * @return $this |
||
| 1362 | * <p>(Mutable) Return this Arrayy object, with an empty array.</p> |
||
| 1363 | * |
||
| 1364 | * @psalm-return static<TKey,T> |
||
| 1365 | */ |
||
| 1366 | 10 | public function clear($key = null): self |
|
| 1385 | |||
| 1386 | /** |
||
| 1387 | * Check if an item is in the current array. |
||
| 1388 | * |
||
| 1389 | * EXAMPLE: <code> |
||
| 1390 | * a([1, true])->contains(true); // true |
||
| 1391 | * </code> |
||
| 1392 | * |
||
| 1393 | * @param float|int|string $value |
||
| 1394 | * @param bool $recursive |
||
| 1395 | * @param bool $strict |
||
| 1396 | * |
||
| 1397 | * @return bool |
||
| 1398 | * @psalm-mutation-free |
||
| 1399 | */ |
||
| 1400 | 23 | public function contains($value, bool $recursive = false, bool $strict = true): bool |
|
| 1401 | { |
||
| 1402 | 23 | if ($recursive === true) { |
|
| 1403 | 18 | return $this->in_array_recursive($value, $this->toArray(), $strict); |
|
| 1404 | } |
||
| 1405 | |||
| 1406 | /** @noinspection PhpParameterByRefIsNotUsedAsReferenceInspection */ |
||
| 1407 | 14 | foreach ($this->getGeneratorByReference() as &$valueFromArray) { |
|
| 1408 | 11 | if ($strict) { |
|
| 1409 | 11 | if ($value === $valueFromArray) { |
|
| 1410 | 11 | return true; |
|
| 1411 | } |
||
| 1412 | } else { |
||
| 1413 | /** @noinspection NestedPositiveIfStatementsInspection */ |
||
| 1414 | if ($value == $valueFromArray) { |
||
| 1415 | return true; |
||
| 1416 | } |
||
| 1417 | } |
||
| 1418 | } |
||
| 1419 | |||
| 1420 | 7 | return false; |
|
| 1421 | } |
||
| 1422 | |||
| 1423 | /** |
||
| 1424 | * Check if an (case-insensitive) string is in the current array. |
||
| 1425 | * |
||
| 1426 | * EXAMPLE: <code> |
||
| 1427 | * a(['E', 'é'])->containsCaseInsensitive('É'); // true |
||
| 1428 | * </code> |
||
| 1429 | * |
||
| 1430 | * @param mixed $value |
||
| 1431 | * @param bool $recursive |
||
| 1432 | * |
||
| 1433 | * @return bool |
||
| 1434 | * @psalm-mutation-free |
||
| 1435 | * |
||
| 1436 | * @psalm-suppress InvalidCast - hack for int|float|bool support |
||
| 1437 | */ |
||
| 1438 | 26 | public function containsCaseInsensitive($value, $recursive = false): bool |
|
| 1469 | |||
| 1470 | /** |
||
| 1471 | * Check if the given key/index exists in the array. |
||
| 1472 | * |
||
| 1473 | * EXAMPLE: <code> |
||
| 1474 | * a([1 => true])->containsKey(1); // true |
||
| 1475 | * </code> |
||
| 1476 | * |
||
| 1477 | * @param int|string $key <p>key/index to search for</p> |
||
| 1478 | * |
||
| 1479 | * @return bool |
||
| 1480 | * <p>Returns true if the given key/index exists in the array, false otherwise.</p> |
||
| 1481 | * |
||
| 1482 | * @psalm-mutation-free |
||
| 1483 | */ |
||
| 1484 | 4 | public function containsKey($key): bool |
|
| 1488 | |||
| 1489 | /** |
||
| 1490 | * Check if all given needles are present in the array as key/index. |
||
| 1491 | * |
||
| 1492 | * EXAMPLE: <code> |
||
| 1493 | * a([1 => true])->containsKeys(array(1 => 0)); // true |
||
| 1494 | * </code> |
||
| 1495 | * |
||
| 1496 | * @param array $needles <p>The keys you are searching for.</p> |
||
| 1497 | * @param bool $recursive |
||
| 1498 | * |
||
| 1499 | * @return bool |
||
| 1500 | * <p>Returns true if all the given keys/indexes exists in the array, false otherwise.</p> |
||
| 1501 | * |
||
| 1502 | * @psalm-param array<array-key>|array<TKey> $needles |
||
| 1503 | * @psalm-mutation-free |
||
| 1504 | */ |
||
| 1505 | 2 | public function containsKeys(array $needles, $recursive = false): bool |
|
| 1533 | |||
| 1534 | /** |
||
| 1535 | * Check if all given needles are present in the array as key/index. |
||
| 1536 | * |
||
| 1537 | * @param array $needles <p>The keys you are searching for.</p> |
||
| 1538 | * |
||
| 1539 | * @return bool |
||
| 1540 | * <p>Returns true if all the given keys/indexes exists in the array, false otherwise.</p> |
||
| 1541 | * |
||
| 1542 | * @psalm-param array<array-key>|array<TKey> $needles |
||
| 1543 | * @psalm-mutation-free |
||
| 1544 | */ |
||
| 1545 | 1 | public function containsKeysRecursive(array $needles): bool |
|
| 1549 | |||
| 1550 | /** |
||
| 1551 | * alias: for "Arrayy->contains()" |
||
| 1552 | * |
||
| 1553 | * @param float|int|string $value |
||
| 1554 | * |
||
| 1555 | * @return bool |
||
| 1556 | * |
||
| 1557 | * @see Arrayy::contains() |
||
| 1558 | * @psalm-mutation-free |
||
| 1559 | */ |
||
| 1560 | 9 | public function containsValue($value): bool |
|
| 1564 | |||
| 1565 | /** |
||
| 1566 | * alias: for "Arrayy->contains($value, true)" |
||
| 1567 | * |
||
| 1568 | * @param float|int|string $value |
||
| 1569 | * |
||
| 1570 | * @return bool |
||
| 1571 | * |
||
| 1572 | * @see Arrayy::contains() |
||
| 1573 | * @psalm-mutation-free |
||
| 1574 | */ |
||
| 1575 | 18 | public function containsValueRecursive($value): bool |
|
| 1579 | |||
| 1580 | /** |
||
| 1581 | * Check if all given needles are present in the array. |
||
| 1582 | * |
||
| 1583 | * EXAMPLE: <code> |
||
| 1584 | * a([1, true])->containsValues(array(1, true)); // true |
||
| 1585 | * </code> |
||
| 1586 | * |
||
| 1587 | * @param array $needles |
||
| 1588 | * |
||
| 1589 | * @return bool |
||
| 1590 | * <p>Returns true if all the given values exists in the array, false otherwise.</p> |
||
| 1591 | * |
||
| 1592 | * @psalm-param array<mixed>|array<T> $needles |
||
| 1593 | * @psalm-mutation-free |
||
| 1594 | */ |
||
| 1595 | 1 | public function containsValues(array $needles): bool |
|
| 1610 | |||
| 1611 | /** |
||
| 1612 | * Counts all the values of an array |
||
| 1613 | * |
||
| 1614 | * @see http://php.net/manual/en/function.array-count-values.php |
||
| 1615 | * |
||
| 1616 | * @return static |
||
| 1617 | * <p> |
||
| 1618 | * (Immutable) |
||
| 1619 | * An associative Arrayy-object of values from input as |
||
| 1620 | * keys and their count as value. |
||
| 1621 | * </p> |
||
| 1622 | * |
||
| 1623 | * @psalm-return static<TKey,T> |
||
| 1624 | * @psalm-mutation-free |
||
| 1625 | */ |
||
| 1626 | 7 | public function countValues(): self |
|
| 1630 | |||
| 1631 | /** |
||
| 1632 | * Creates an Arrayy object. |
||
| 1633 | * |
||
| 1634 | * @param mixed $data |
||
| 1635 | * @param string $iteratorClass |
||
| 1636 | * @param bool $checkPropertiesInConstructor |
||
| 1637 | * |
||
| 1638 | * @return static |
||
| 1639 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1640 | * |
||
| 1641 | * @psalm-param array<array-key,T>|\Traversable<array-key,T>|callable():\Generator<TKey,T>|(T&\Traversable) $data |
||
| 1642 | * @psalm-param class-string<\Arrayy\ArrayyIterator> $iteratorClass |
||
| 1643 | * @psalm-return static<TKey,T> |
||
| 1644 | * @psalm-mutation-free |
||
| 1645 | */ |
||
| 1646 | 729 | public static function create( |
|
| 1657 | |||
| 1658 | /** |
||
| 1659 | * Flatten an array with the given character as a key delimiter. |
||
| 1660 | * |
||
| 1661 | * EXAMPLE: <code> |
||
| 1662 | * $dot = a(['foo' => ['abc' => 'xyz', 'bar' => ['baz']]]); |
||
| 1663 | * $flatten = $dot->flatten(); |
||
| 1664 | * $flatten['foo.abc']; // 'xyz' |
||
| 1665 | * $flatten['foo.bar.0']; // 'baz' |
||
| 1666 | * </code> |
||
| 1667 | * |
||
| 1668 | * @param string $delimiter |
||
| 1669 | * @param string $prepend |
||
| 1670 | * @param array|null $items |
||
| 1671 | * |
||
| 1672 | * @return array |
||
| 1673 | */ |
||
| 1674 | 2 | public function flatten($delimiter = '.', $prepend = '', $items = null) |
|
| 1697 | |||
| 1698 | /** |
||
| 1699 | * WARNING: Creates an Arrayy object by reference. |
||
| 1700 | * |
||
| 1701 | * @param array $array |
||
| 1702 | * |
||
| 1703 | * @return $this |
||
| 1704 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1705 | * |
||
| 1706 | * @psalm-param array<TKey,T> $array |
||
| 1707 | * @psalm-return $this<TKey,T> |
||
| 1708 | * |
||
| 1709 | * @internal this will not check any types because it's set directly as reference |
||
| 1710 | */ |
||
| 1711 | 26 | public function createByReference(array &$array = []): self |
|
| 1718 | |||
| 1719 | /** |
||
| 1720 | * Create an new instance from a callable function which will return an Generator. |
||
| 1721 | * |
||
| 1722 | * @param callable $generatorFunction |
||
| 1723 | * |
||
| 1724 | * @return static |
||
| 1725 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1726 | * |
||
| 1727 | * @psalm-param callable():\Generator<TKey,T> $generatorFunction |
||
| 1728 | * @psalm-return static<TKey,T> |
||
| 1729 | * @psalm-mutation-free |
||
| 1730 | */ |
||
| 1731 | 7 | public static function createFromGeneratorFunction(callable $generatorFunction): self |
|
| 1735 | |||
| 1736 | /** |
||
| 1737 | * Create an new instance filled with a copy of values from a "Generator"-object. |
||
| 1738 | * |
||
| 1739 | * @param \Generator $generator |
||
| 1740 | * |
||
| 1741 | * @return static |
||
| 1742 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1743 | * |
||
| 1744 | * @psalm-param \Generator<TKey,T> $generator |
||
| 1745 | * @psalm-return static<TKey,T> |
||
| 1746 | * @psalm-mutation-free |
||
| 1747 | */ |
||
| 1748 | 4 | public static function createFromGeneratorImmutable(\Generator $generator): self |
|
| 1752 | |||
| 1753 | /** |
||
| 1754 | * Create an new Arrayy object via JSON. |
||
| 1755 | * |
||
| 1756 | * @param string $json |
||
| 1757 | * |
||
| 1758 | * @return static |
||
| 1759 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1760 | * |
||
| 1761 | * @psalm-return static<mixed,mixed> |
||
| 1762 | * @psalm-mutation-free |
||
| 1763 | */ |
||
| 1764 | 5 | public static function createFromJson(string $json): self |
|
| 1768 | |||
| 1769 | /** |
||
| 1770 | * Create an new Arrayy object via JSON. |
||
| 1771 | * |
||
| 1772 | * @param array $array |
||
| 1773 | * |
||
| 1774 | * @return static |
||
| 1775 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1776 | * |
||
| 1777 | * @psalm-param array<TKey,T> $array |
||
| 1778 | * @psalm-return static<TKey,T> |
||
| 1779 | * @psalm-mutation-free |
||
| 1780 | */ |
||
| 1781 | 1 | public static function createFromArray(array $array): self |
|
| 1785 | |||
| 1786 | /** |
||
| 1787 | * Create an new instance filled with values from an object that is iterable. |
||
| 1788 | * |
||
| 1789 | * @param \Traversable $object <p>iterable object</p> |
||
| 1790 | * |
||
| 1791 | * @return static |
||
| 1792 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1793 | * |
||
| 1794 | * @psalm-param \Traversable<array-key,T> $object |
||
| 1795 | * @psalm-return static<array-key,T> |
||
| 1796 | * @psalm-mutation-free |
||
| 1797 | */ |
||
| 1798 | 4 | public static function createFromObject(\Traversable $object): self |
|
| 1818 | |||
| 1819 | /** |
||
| 1820 | * Create an new instance filled with values from an object. |
||
| 1821 | * |
||
| 1822 | * @param object $object |
||
| 1823 | * |
||
| 1824 | * @return static |
||
| 1825 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1826 | * |
||
| 1827 | * @psalm-return static<array-key,mixed> |
||
| 1828 | * @psalm-mutation-free |
||
| 1829 | */ |
||
| 1830 | 5 | public static function createFromObjectVars($object): self |
|
| 1834 | |||
| 1835 | /** |
||
| 1836 | * Create an new Arrayy object via string. |
||
| 1837 | * |
||
| 1838 | * @param string $str <p>The input string.</p> |
||
| 1839 | * @param string|null $delimiter <p>The boundary string.</p> |
||
| 1840 | * @param string|null $regEx <p>Use the $delimiter or the $regEx, so if $pattern is null, $delimiter will be |
||
| 1841 | * used.</p> |
||
| 1842 | * |
||
| 1843 | * @return static |
||
| 1844 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1845 | * |
||
| 1846 | * @psalm-return static<int,string> |
||
| 1847 | * @psalm-mutation-free |
||
| 1848 | */ |
||
| 1849 | 10 | public static function createFromString(string $str, string $delimiter = null, string $regEx = null): self |
|
| 1881 | |||
| 1882 | /** |
||
| 1883 | * Create an new instance filled with a copy of values from a "Traversable"-object. |
||
| 1884 | * |
||
| 1885 | * @param \Traversable $traversable |
||
| 1886 | * @param bool $use_keys [optional] <p> |
||
| 1887 | * Whether to use the iterator element keys as index. |
||
| 1888 | * </p> |
||
| 1889 | * |
||
| 1890 | * @return static |
||
| 1891 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1892 | * |
||
| 1893 | * @psalm-param \Traversable<array-key|TKey,T> $traversable |
||
| 1894 | * @psalm-return static<int|TKey,T> |
||
| 1895 | * @psalm-mutation-free |
||
| 1896 | */ |
||
| 1897 | 1 | public static function createFromTraversableImmutable(\Traversable $traversable, bool $use_keys = true): self |
|
| 1901 | |||
| 1902 | /** |
||
| 1903 | * Create an new instance containing a range of elements. |
||
| 1904 | * |
||
| 1905 | * @param float|int|string $low <p>First value of the sequence.</p> |
||
| 1906 | * @param float|int|string $high <p>The sequence is ended upon reaching the end value.</p> |
||
| 1907 | * @param float|int $step <p>Used as the increment between elements in the sequence.</p> |
||
| 1908 | * |
||
| 1909 | * @return static |
||
| 1910 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1911 | * |
||
| 1912 | * @psalm-return static<int,int|string> |
||
| 1913 | * @psalm-mutation-free |
||
| 1914 | */ |
||
| 1915 | 2 | public static function createWithRange($low, $high, $step = 1): self |
|
| 1919 | |||
| 1920 | /** |
||
| 1921 | * Gets the element of the array at the current internal iterator position. |
||
| 1922 | * |
||
| 1923 | * @return false|mixed |
||
| 1924 | * |
||
| 1925 | * @psalm-return false|T |
||
| 1926 | */ |
||
| 1927 | public function current() |
||
| 1935 | |||
| 1936 | /** |
||
| 1937 | * Custom sort by index via "uksort". |
||
| 1938 | * |
||
| 1939 | * EXAMPLE: <code> |
||
| 1940 | * $callable = function ($a, $b) { |
||
| 1941 | * if ($a == $b) { |
||
| 1942 | * return 0; |
||
| 1943 | * } |
||
| 1944 | * return ($a > $b) ? 1 : -1; |
||
| 1945 | * }; |
||
| 1946 | * $arrayy = a(['three' => 3, 'one' => 1, 'two' => 2]); |
||
| 1947 | * $resultArrayy = $arrayy->customSortKeys($callable); // Arrayy['one' => 1, 'three' => 3, 'two' => 2] |
||
| 1948 | * </code> |
||
| 1949 | * |
||
| 1950 | * @see http://php.net/manual/en/function.uksort.php |
||
| 1951 | * |
||
| 1952 | * @param callable $function |
||
| 1953 | * |
||
| 1954 | * @throws \InvalidArgumentException |
||
| 1955 | * |
||
| 1956 | * @return $this |
||
| 1957 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1958 | * |
||
| 1959 | * @psalm-return static<TKey,T> |
||
| 1960 | */ |
||
| 1961 | 5 | public function customSortKeys(callable $function): self |
|
| 1969 | |||
| 1970 | /** |
||
| 1971 | * Custom sort by index via "uksort". |
||
| 1972 | * |
||
| 1973 | * @see http://php.net/manual/en/function.uksort.php |
||
| 1974 | * |
||
| 1975 | * @param callable $function |
||
| 1976 | * |
||
| 1977 | * @throws \InvalidArgumentException |
||
| 1978 | * |
||
| 1979 | * @return $this |
||
| 1980 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 1981 | * |
||
| 1982 | * @psalm-return static<TKey,T> |
||
| 1983 | * @psalm-mutation-free |
||
| 1984 | */ |
||
| 1985 | 1 | public function customSortKeysImmutable(callable $function): self |
|
| 1998 | |||
| 1999 | /** |
||
| 2000 | * Custom sort by value via "usort". |
||
| 2001 | * |
||
| 2002 | * EXAMPLE: <code> |
||
| 2003 | * $callable = function ($a, $b) { |
||
| 2004 | * if ($a == $b) { |
||
| 2005 | * return 0; |
||
| 2006 | * } |
||
| 2007 | * return ($a > $b) ? 1 : -1; |
||
| 2008 | * }; |
||
| 2009 | * $arrayy = a(['three' => 3, 'one' => 1, 'two' => 2]); |
||
| 2010 | * $resultArrayy = $arrayy->customSortValues($callable); // Arrayy['one' => 1, 'two' => 2, 'three' => 3] |
||
| 2011 | * </code> |
||
| 2012 | * |
||
| 2013 | * @see http://php.net/manual/en/function.usort.php |
||
| 2014 | * |
||
| 2015 | * @param callable $function |
||
| 2016 | * |
||
| 2017 | * @throws \InvalidArgumentException |
||
| 2018 | * |
||
| 2019 | * @return $this |
||
| 2020 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 2021 | * |
||
| 2022 | * @psalm-return static<TKey,T> |
||
| 2023 | */ |
||
| 2024 | 10 | View Code Duplication | public function customSortValues($function): self |
| 2036 | |||
| 2037 | /** |
||
| 2038 | * Custom sort by value via "usort". |
||
| 2039 | * |
||
| 2040 | * @see http://php.net/manual/en/function.usort.php |
||
| 2041 | * |
||
| 2042 | * @param callable $function |
||
| 2043 | * |
||
| 2044 | * @throws \InvalidArgumentException |
||
| 2045 | * |
||
| 2046 | * @return $this |
||
| 2047 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 2048 | * |
||
| 2049 | * @psalm-return static<TKey,T> |
||
| 2050 | * @psalm-mutation-free |
||
| 2051 | */ |
||
| 2052 | 4 | public function customSortValuesImmutable($function): self |
|
| 2063 | |||
| 2064 | /** |
||
| 2065 | * Delete the given key or keys. |
||
| 2066 | * |
||
| 2067 | * @param int|int[]|string|string[] $keyOrKeys |
||
| 2068 | * |
||
| 2069 | * @return void |
||
| 2070 | */ |
||
| 2071 | 9 | public function delete($keyOrKeys) |
|
| 2079 | |||
| 2080 | /** |
||
| 2081 | * Return elements where the values that are only in the current array. |
||
| 2082 | * |
||
| 2083 | * EXAMPLE: <code> |
||
| 2084 | * a([1 => 1, 2 => 2])->diff([1 => 1]); // Arrayy[2 => 2] |
||
| 2085 | * </code> |
||
| 2086 | * |
||
| 2087 | * @param array ...$array |
||
| 2088 | * |
||
| 2089 | * @return static |
||
| 2090 | * <p>(Immutable)</p> |
||
| 2091 | * |
||
| 2092 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$array |
||
| 2093 | * @psalm-return static<TKey,T> |
||
| 2094 | * @psalm-mutation-free |
||
| 2095 | */ |
||
| 2096 | 13 | View Code Duplication | public function diff(array ...$array): self |
| 2118 | |||
| 2119 | /** |
||
| 2120 | * Return elements where the keys are only in the current array. |
||
| 2121 | * |
||
| 2122 | * @param array ...$array |
||
| 2123 | * |
||
| 2124 | * @return static |
||
| 2125 | * <p>(Immutable)</p> |
||
| 2126 | * |
||
| 2127 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$array |
||
| 2128 | * @psalm-return static<TKey,T> |
||
| 2129 | * @psalm-mutation-free |
||
| 2130 | */ |
||
| 2131 | 9 | View Code Duplication | public function diffKey(array ...$array): self |
| 2153 | |||
| 2154 | /** |
||
| 2155 | * Return elements where the values and keys are only in the current array. |
||
| 2156 | * |
||
| 2157 | * @param array ...$array |
||
| 2158 | * |
||
| 2159 | * @return static |
||
| 2160 | * <p>(Immutable)</p> |
||
| 2161 | * |
||
| 2162 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 2163 | * @psalm-return static<TKey,T> |
||
| 2164 | * @psalm-mutation-free |
||
| 2165 | */ |
||
| 2166 | 9 | public function diffKeyAndValue(array ...$array): self |
|
| 2174 | |||
| 2175 | /** |
||
| 2176 | * Return elements where the values are only in the current multi-dimensional array. |
||
| 2177 | * |
||
| 2178 | * EXAMPLE: <code> |
||
| 2179 | * a([1 => [1 => 1], 2 => [2 => 2]])->diffRecursive([1 => [1 => 1]]); // Arrayy[2 => [2 => 2]] |
||
| 2180 | * </code> |
||
| 2181 | * |
||
| 2182 | * @param array $array |
||
| 2183 | * @param array|\Generator|null $helperVariableForRecursion <p>(only for internal usage)</p> |
||
| 2184 | * |
||
| 2185 | * @return static |
||
| 2186 | * <p>(Immutable)</p> |
||
| 2187 | * |
||
| 2188 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 2189 | * @psalm-param null|array<TKey,T>|\Generator<TKey,T> $helperVariableForRecursion |
||
| 2190 | * @psalm-return static<TKey,T> |
||
| 2191 | * @psalm-mutation-free |
||
| 2192 | */ |
||
| 2193 | 1 | public function diffRecursive(array $array = [], $helperVariableForRecursion = null): self |
|
| 2228 | |||
| 2229 | /** |
||
| 2230 | * Return elements where the values that are only in the new $array. |
||
| 2231 | * |
||
| 2232 | * EXAMPLE: <code> |
||
| 2233 | * a([1 => 1])->diffReverse([1 => 1, 2 => 2]); // Arrayy[2 => 2] |
||
| 2234 | * </code> |
||
| 2235 | * |
||
| 2236 | * @param array $array |
||
| 2237 | * |
||
| 2238 | * @return static |
||
| 2239 | * <p>(Immutable)</p> |
||
| 2240 | * |
||
| 2241 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 2242 | * @psalm-return static<TKey,T> |
||
| 2243 | * @psalm-mutation-free |
||
| 2244 | */ |
||
| 2245 | 8 | public function diffReverse(array $array = []): self |
|
| 2253 | |||
| 2254 | /** |
||
| 2255 | * Divide an array into two arrays. One with keys and the other with values. |
||
| 2256 | * |
||
| 2257 | * EXAMPLE: <code> |
||
| 2258 | * a(['a' => 1, 'b' => ''])->divide(); // Arrayy[Arrayy['a', 'b'], Arrayy[1, '']] |
||
| 2259 | * </code> |
||
| 2260 | * |
||
| 2261 | * @return static |
||
| 2262 | * <p>(Immutable)</p> |
||
| 2263 | * |
||
| 2264 | * @psalm-return static<TKey,T> |
||
| 2265 | * @psalm-mutation-free |
||
| 2266 | */ |
||
| 2267 | 1 | public function divide(): self |
|
| 2278 | |||
| 2279 | /** |
||
| 2280 | * Iterate over the current array and modify the array's value. |
||
| 2281 | * |
||
| 2282 | * EXAMPLE: <code> |
||
| 2283 | * $result = A::create(); |
||
| 2284 | * $closure = function ($value) { |
||
| 2285 | * return ':' . $value . ':'; |
||
| 2286 | * }; |
||
| 2287 | * a(['foo', 'bar' => 'bis'])->each($closure); // Arrayy[':foo:', 'bar' => ':bis:'] |
||
| 2288 | * </code> |
||
| 2289 | * |
||
| 2290 | * @param \Closure $closure |
||
| 2291 | * |
||
| 2292 | * @return static |
||
| 2293 | * <p>(Immutable)</p> |
||
| 2294 | * |
||
| 2295 | * @psalm-return static<TKey,T> |
||
| 2296 | * @psalm-mutation-free |
||
| 2297 | */ |
||
| 2298 | 5 | View Code Duplication | public function each(\Closure $closure): self |
| 2313 | |||
| 2314 | /** |
||
| 2315 | * Sets the internal iterator to the last element in the array and returns this element. |
||
| 2316 | * |
||
| 2317 | * @return false|mixed |
||
| 2318 | * |
||
| 2319 | * @psalm-return T|false |
||
| 2320 | */ |
||
| 2321 | public function end() |
||
| 2339 | |||
| 2340 | /** |
||
| 2341 | * Check if a value is in the current array using a closure. |
||
| 2342 | * |
||
| 2343 | * EXAMPLE: <code> |
||
| 2344 | * $callable = function ($value, $key) { |
||
| 2345 | * return 2 === $key and 'two' === $value; |
||
| 2346 | * }; |
||
| 2347 | * a(['foo', 2 => 'two'])->exists($callable); // true |
||
| 2348 | * </code> |
||
| 2349 | * |
||
| 2350 | * @param \Closure $closure |
||
| 2351 | * |
||
| 2352 | * @return bool |
||
| 2353 | * <p>Returns true if the given value is found, false otherwise.</p> |
||
| 2354 | */ |
||
| 2355 | 4 | public function exists(\Closure $closure): bool |
|
| 2370 | |||
| 2371 | /** |
||
| 2372 | * Fill the array until "$num" with "$default" values. |
||
| 2373 | * |
||
| 2374 | * EXAMPLE: <code> |
||
| 2375 | * a(['bar'])->fillWithDefaults(3, 'foo'); // Arrayy['bar', 'foo', 'foo'] |
||
| 2376 | * </code> |
||
| 2377 | * |
||
| 2378 | * @param int $num |
||
| 2379 | * @param mixed $default |
||
| 2380 | * |
||
| 2381 | * @return static |
||
| 2382 | * <p>(Immutable)</p> |
||
| 2383 | * |
||
| 2384 | * @psalm-return static<TKey,T> |
||
| 2385 | * @psalm-mutation-free |
||
| 2386 | */ |
||
| 2387 | 8 | public function fillWithDefaults(int $num, $default = null): self |
|
| 2410 | |||
| 2411 | /** |
||
| 2412 | * Find all items in an array that pass the truth test. |
||
| 2413 | * |
||
| 2414 | * EXAMPLE: <code> |
||
| 2415 | * $closure = function ($value) { |
||
| 2416 | * return $value % 2 !== 0; |
||
| 2417 | * } |
||
| 2418 | * a([1, 2, 3, 4])->filter($closure); // Arrayy[0 => 1, 2 => 3] |
||
| 2419 | * </code> |
||
| 2420 | * |
||
| 2421 | * @param \Closure|null $closure [optional] <p> |
||
| 2422 | * The callback function to use |
||
| 2423 | * </p> |
||
| 2424 | * <p> |
||
| 2425 | * If no callback is supplied, all entries of |
||
| 2426 | * input equal to false (see |
||
| 2427 | * converting to |
||
| 2428 | * boolean) will be removed. |
||
| 2429 | * </p> |
||
| 2430 | * @param int $flag [optional] <p> |
||
| 2431 | * Flag determining what arguments are sent to <i>callback</i>: |
||
| 2432 | * </p> |
||
| 2433 | * <ul> |
||
| 2434 | * <li> |
||
| 2435 | * <b>ARRAY_FILTER_USE_KEY</b> (1) - pass key as the only argument |
||
| 2436 | * to <i>callback</i> instead of the value |
||
| 2437 | * </li> |
||
| 2438 | * <li> |
||
| 2439 | * <b>ARRAY_FILTER_USE_BOTH</b> (2) - pass both value and key as |
||
| 2440 | * arguments to <i>callback</i> instead of the value |
||
| 2441 | * </li> |
||
| 2442 | * </ul> |
||
| 2443 | * |
||
| 2444 | * @return static |
||
| 2445 | * <p>(Immutable)</p> |
||
| 2446 | * |
||
| 2447 | * @psalm-param null|\Closure(T=,TKey=):bool|\Closure(T=):bool||\Closure(TKey=):bool $closure |
||
| 2448 | * @psalm-return static<TKey,T> |
||
| 2449 | * @psalm-mutation-free |
||
| 2450 | */ |
||
| 2451 | 12 | public function filter($closure = null, int $flag = \ARRAY_FILTER_USE_BOTH) |
|
| 2489 | |||
| 2490 | /** |
||
| 2491 | * Filters an array of objects (or a numeric array of associative arrays) based on the value of a particular |
||
| 2492 | * property within that. |
||
| 2493 | * |
||
| 2494 | * @param string $property |
||
| 2495 | * @param mixed $value |
||
| 2496 | * @param string $comparisonOp |
||
| 2497 | * <p> |
||
| 2498 | * 'eq' (equals),<br /> |
||
| 2499 | * 'gt' (greater),<br /> |
||
| 2500 | * 'gte' || 'ge' (greater or equals),<br /> |
||
| 2501 | * 'lt' (less),<br /> |
||
| 2502 | * 'lte' || 'le' (less or equals),<br /> |
||
| 2503 | * 'ne' (not equals),<br /> |
||
| 2504 | * 'contains',<br /> |
||
| 2505 | * 'notContains',<br /> |
||
| 2506 | * 'newer' (via strtotime),<br /> |
||
| 2507 | * 'older' (via strtotime),<br /> |
||
| 2508 | * </p> |
||
| 2509 | * |
||
| 2510 | * @return static |
||
| 2511 | * <p>(Immutable)</p> |
||
| 2512 | * |
||
| 2513 | * @psalm-param mixed|T $value |
||
| 2514 | * @psalm-return static<TKey,T> |
||
| 2515 | * @psalm-mutation-free |
||
| 2516 | * |
||
| 2517 | * @psalm-suppress MissingClosureReturnType |
||
| 2518 | * @psalm-suppress MissingClosureParamType |
||
| 2519 | */ |
||
| 2520 | 1 | public function filterBy( |
|
| 2592 | |||
| 2593 | /** |
||
| 2594 | * Find the first item in an array that passes the truth test, otherwise return false. |
||
| 2595 | * |
||
| 2596 | * EXAMPLE: <code> |
||
| 2597 | * $search = 'foo'; |
||
| 2598 | * $closure = function ($value, $key) use ($search) { |
||
| 2599 | * return $value === $search; |
||
| 2600 | * }; |
||
| 2601 | * a(['foo', 'bar', 'lall'])->find($closure); // 'foo' |
||
| 2602 | * </code> |
||
| 2603 | * |
||
| 2604 | * @param \Closure $closure |
||
| 2605 | * |
||
| 2606 | * @return false|mixed |
||
| 2607 | * <p>Return false if we did not find the value.</p> |
||
| 2608 | */ |
||
| 2609 | 8 | View Code Duplication | public function find(\Closure $closure) |
| 2619 | |||
| 2620 | /** |
||
| 2621 | * find by ... |
||
| 2622 | * |
||
| 2623 | * EXAMPLE: <code> |
||
| 2624 | * $array = [ |
||
| 2625 | * 0 => ['id' => 123, 'name' => 'foo', 'group' => 'primary', 'value' => 123456, 'when' => '2014-01-01'], |
||
| 2626 | * 1 => ['id' => 456, 'name' => 'bar', 'group' => 'primary', 'value' => 1468, 'when' => '2014-07-15'], |
||
| 2627 | * ]; |
||
| 2628 | * a($array)->filterBy('name', 'foo'); // Arrayy[0 => ['id' => 123, 'name' => 'foo', 'group' => 'primary', 'value' => 123456, 'when' => '2014-01-01']] |
||
| 2629 | * </code> |
||
| 2630 | * |
||
| 2631 | * @param string $property |
||
| 2632 | * @param mixed $value |
||
| 2633 | * @param string $comparisonOp |
||
| 2634 | * |
||
| 2635 | * @return static |
||
| 2636 | * <p>(Immutable)</p> |
||
| 2637 | * |
||
| 2638 | * @psalm-param mixed|T $value |
||
| 2639 | * @psalm-return static<TKey,T> |
||
| 2640 | * @psalm-mutation-free |
||
| 2641 | */ |
||
| 2642 | 1 | public function findBy(string $property, $value, string $comparisonOp = 'eq'): self |
|
| 2646 | |||
| 2647 | /** |
||
| 2648 | * Get the first value from the current array. |
||
| 2649 | * |
||
| 2650 | * EXAMPLE: <code> |
||
| 2651 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->first(); // 'foo' |
||
| 2652 | * </code> |
||
| 2653 | * |
||
| 2654 | * @return mixed |
||
| 2655 | * <p>Return null if there wasn't a element.</p> |
||
| 2656 | */ |
||
| 2657 | 22 | public function first() |
|
| 2666 | |||
| 2667 | /** |
||
| 2668 | * Get the first key from the current array. |
||
| 2669 | * |
||
| 2670 | * @return mixed |
||
| 2671 | * <p>Return null if there wasn't a element.</p> |
||
| 2672 | * @psalm-mutation-free |
||
| 2673 | */ |
||
| 2674 | 29 | public function firstKey() |
|
| 2680 | |||
| 2681 | /** |
||
| 2682 | * Get the first value(s) from the current array. |
||
| 2683 | * And will return an empty array if there was no first entry. |
||
| 2684 | * |
||
| 2685 | * EXAMPLE: <code> |
||
| 2686 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->firstsImmutable(2); // Arrayy[0 => 'foo', 1 => 'bar'] |
||
| 2687 | * </code> |
||
| 2688 | * |
||
| 2689 | * @param int|null $number <p>How many values you will take?</p> |
||
| 2690 | * |
||
| 2691 | * @return static |
||
| 2692 | * <p>(Immutable)</p> |
||
| 2693 | * |
||
| 2694 | * @psalm-return static<TKey,T> |
||
| 2695 | * @psalm-mutation-free |
||
| 2696 | */ |
||
| 2697 | 37 | public function firstsImmutable(int $number = null): self |
|
| 2713 | |||
| 2714 | /** |
||
| 2715 | * Get the first value(s) from the current array. |
||
| 2716 | * And will return an empty array if there was no first entry. |
||
| 2717 | * |
||
| 2718 | * @param int|null $number <p>How many values you will take?</p> |
||
| 2719 | * |
||
| 2720 | * @return static |
||
| 2721 | * <p>(Immutable)</p> |
||
| 2722 | * |
||
| 2723 | * @psalm-return static<TKey,T> |
||
| 2724 | * @psalm-mutation-free |
||
| 2725 | */ |
||
| 2726 | 3 | View Code Duplication | public function firstsKeys(int $number = null): self |
| 2742 | |||
| 2743 | /** |
||
| 2744 | * Get and remove the first value(s) from the current array. |
||
| 2745 | * And will return an empty array if there was no first entry. |
||
| 2746 | * |
||
| 2747 | * EXAMPLE: <code> |
||
| 2748 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->firstsMutable(); // 'foo' |
||
| 2749 | * </code> |
||
| 2750 | * |
||
| 2751 | * @param int|null $number <p>How many values you will take?</p> |
||
| 2752 | * |
||
| 2753 | * @return $this |
||
| 2754 | * <p>(Mutable)</p> |
||
| 2755 | * |
||
| 2756 | * @psalm-return static<TKey,T> |
||
| 2757 | */ |
||
| 2758 | 34 | public function firstsMutable(int $number = null): self |
|
| 2770 | |||
| 2771 | /** |
||
| 2772 | * Exchanges all keys with their associated values in an array. |
||
| 2773 | * |
||
| 2774 | * EXAMPLE: <code> |
||
| 2775 | * a([0 => 'foo', 1 => 'bar'])->flip(); // Arrayy['foo' => 0, 'bar' => 1] |
||
| 2776 | * </code> |
||
| 2777 | * |
||
| 2778 | * @return static |
||
| 2779 | * <p>(Immutable)</p> |
||
| 2780 | * |
||
| 2781 | * @psalm-return static<array-key,TKey> |
||
| 2782 | * @psalm-mutation-free |
||
| 2783 | */ |
||
| 2784 | 1 | public function flip(): self |
|
| 2798 | |||
| 2799 | /** |
||
| 2800 | * Get a value from an array (optional using dot-notation). |
||
| 2801 | * |
||
| 2802 | * EXAMPLE: <code> |
||
| 2803 | * $arrayy = a(['user' => ['lastname' => 'Moelleken']]); |
||
| 2804 | * $arrayy->get('user.lastname'); // 'Moelleken' |
||
| 2805 | * // --- |
||
| 2806 | * $arrayy = new A(); |
||
| 2807 | * $arrayy['user'] = ['lastname' => 'Moelleken']; |
||
| 2808 | * $arrayy['user.firstname'] = 'Lars'; |
||
| 2809 | * $arrayy['user']['lastname']; // Moelleken |
||
| 2810 | * $arrayy['user.lastname']; // Moelleken |
||
| 2811 | * $arrayy['user.firstname']; // Lars |
||
| 2812 | * </code> |
||
| 2813 | * |
||
| 2814 | * @param mixed $key <p>The key to look for.</p> |
||
| 2815 | * @param mixed $fallback <p>Value to fallback to.</p> |
||
| 2816 | * @param array $array <p>The array to get from, if it's set to "null" we use the current array from the |
||
| 2817 | * class.</p> |
||
| 2818 | * @param bool $useByReference |
||
| 2819 | * |
||
| 2820 | * @return mixed|static |
||
| 2821 | * |
||
| 2822 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 2823 | * @psalm-mutation-free |
||
| 2824 | */ |
||
| 2825 | 248 | public function get( |
|
| 2997 | |||
| 2998 | /** |
||
| 2999 | * alias: for "Arrayy->toArray()" |
||
| 3000 | * |
||
| 3001 | * @return array |
||
| 3002 | * |
||
| 3003 | * @see Arrayy::getArray() |
||
| 3004 | * |
||
| 3005 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 3006 | */ |
||
| 3007 | 15 | public function getAll(): array |
|
| 3011 | |||
| 3012 | /** |
||
| 3013 | * Get the current array from the "Arrayy"-object. |
||
| 3014 | * |
||
| 3015 | * alias for "toArray()" |
||
| 3016 | * |
||
| 3017 | * @param bool $convertAllArrayyElements <p> |
||
| 3018 | * Convert all Child-"Arrayy" objects also to arrays. |
||
| 3019 | * </p> |
||
| 3020 | * @param bool $preserveKeys <p> |
||
| 3021 | * e.g.: A generator maybe return the same key more then once, |
||
| 3022 | * so maybe you will ignore the keys. |
||
| 3023 | * </p> |
||
| 3024 | * |
||
| 3025 | * @return array |
||
| 3026 | * |
||
| 3027 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 3028 | * @psalm-mutation-free |
||
| 3029 | * |
||
| 3030 | * @see Arrayy::toArray() |
||
| 3031 | */ |
||
| 3032 | 512 | public function getArray( |
|
| 3041 | |||
| 3042 | /** |
||
| 3043 | * @param string $json |
||
| 3044 | * |
||
| 3045 | * @return $this |
||
| 3046 | */ |
||
| 3047 | 3 | public static function createFromJsonMapper(string $json) |
|
| 3063 | |||
| 3064 | /** |
||
| 3065 | * @return array<int|string,TypeCheckInterface>|mixed|TypeCheckArray<int|string,TypeCheckInterface>|TypeInterface |
||
| 3066 | * |
||
| 3067 | * @internal |
||
| 3068 | */ |
||
| 3069 | 6 | public function getPhpDocPropertiesFromClass() |
|
| 3077 | |||
| 3078 | /** |
||
| 3079 | * Get the current array from the "Arrayy"-object as list. |
||
| 3080 | * |
||
| 3081 | * alias for "toList()" |
||
| 3082 | * |
||
| 3083 | * @param bool $convertAllArrayyElements <p> |
||
| 3084 | * Convert all Child-"Arrayy" objects also to arrays. |
||
| 3085 | * </p> |
||
| 3086 | * |
||
| 3087 | * @return array |
||
| 3088 | * |
||
| 3089 | * @psalm-return array<int,mixed>|array<int,T> |
||
| 3090 | * @psalm-mutation-free |
||
| 3091 | * |
||
| 3092 | * @see Arrayy::toList() |
||
| 3093 | */ |
||
| 3094 | 1 | public function getList(bool $convertAllArrayyElements = false): array |
|
| 3098 | |||
| 3099 | /** |
||
| 3100 | * Returns the values from a single column of the input array, identified by |
||
| 3101 | * the $columnKey, can be used to extract data-columns from multi-arrays. |
||
| 3102 | * |
||
| 3103 | * EXAMPLE: <code> |
||
| 3104 | * a([['foo' => 'bar', 'id' => 1], ['foo => 'lall', 'id' => 2]])->getColumn('foo', 'id'); // Arrayy[1 => 'bar', 2 => 'lall'] |
||
| 3105 | * </code> |
||
| 3106 | * |
||
| 3107 | * INFO: Optionally, you may provide an $indexKey to index the values in the returned |
||
| 3108 | * array by the values from the $indexKey column in the input array. |
||
| 3109 | * |
||
| 3110 | * @param int|string|null $columnKey |
||
| 3111 | * @param int|string|null $indexKey |
||
| 3112 | * |
||
| 3113 | * @return static |
||
| 3114 | * <p>(Immutable)</p> |
||
| 3115 | * |
||
| 3116 | * @psalm-return static<TKey,T> |
||
| 3117 | * @psalm-mutation-free |
||
| 3118 | */ |
||
| 3119 | 1 | public function getColumn($columnKey = null, $indexKey = null): self |
|
| 3179 | |||
| 3180 | /** |
||
| 3181 | * Get the current array from the "Arrayy"-object as generator by reference. |
||
| 3182 | * |
||
| 3183 | * @return \Generator |
||
| 3184 | * |
||
| 3185 | * @psalm-return \Generator<mixed,T>|\Generator<TKey,T> |
||
| 3186 | */ |
||
| 3187 | 75 | public function &getGeneratorByReference(): \Generator |
|
| 3206 | |||
| 3207 | /** |
||
| 3208 | * Get the current array from the "Arrayy"-object as generator. |
||
| 3209 | * |
||
| 3210 | * @return \Generator |
||
| 3211 | * |
||
| 3212 | * @psalm-return \Generator<mixed,T>|\Generator<TKey,T> |
||
| 3213 | * @psalm-mutation-free |
||
| 3214 | */ |
||
| 3215 | 1072 | public function getGenerator(): \Generator |
|
| 3225 | |||
| 3226 | /** |
||
| 3227 | * alias: for "Arrayy->keys()" |
||
| 3228 | * |
||
| 3229 | * @return static |
||
| 3230 | * <p>(Immutable)</p> |
||
| 3231 | * |
||
| 3232 | * @see Arrayy::keys() |
||
| 3233 | * |
||
| 3234 | * @psalm-return static<int,TKey> |
||
| 3235 | * @psalm-mutation-free |
||
| 3236 | */ |
||
| 3237 | 2 | public function getKeys() |
|
| 3241 | |||
| 3242 | /** |
||
| 3243 | * Get the current array from the "Arrayy"-object as object. |
||
| 3244 | * |
||
| 3245 | * @return \stdClass |
||
| 3246 | */ |
||
| 3247 | 4 | public function getObject(): \stdClass |
|
| 3251 | |||
| 3252 | /** |
||
| 3253 | * alias: for "Arrayy->randomImmutable()" |
||
| 3254 | * |
||
| 3255 | * @return static |
||
| 3256 | * <p>(Immutable)</p> |
||
| 3257 | * |
||
| 3258 | * @see Arrayy::randomImmutable() |
||
| 3259 | * |
||
| 3260 | * @psalm-return static<int|array-key,T> |
||
| 3261 | */ |
||
| 3262 | 4 | public function getRandom(): self |
|
| 3266 | |||
| 3267 | /** |
||
| 3268 | * alias: for "Arrayy->randomKey()" |
||
| 3269 | * |
||
| 3270 | * @return mixed |
||
| 3271 | * <p>Get a key/index or null if there wasn't a key/index.</p> |
||
| 3272 | * |
||
| 3273 | * @see Arrayy::randomKey() |
||
| 3274 | */ |
||
| 3275 | 3 | public function getRandomKey() |
|
| 3279 | |||
| 3280 | /** |
||
| 3281 | * alias: for "Arrayy->randomKeys()" |
||
| 3282 | * |
||
| 3283 | * @param int $number |
||
| 3284 | * |
||
| 3285 | * @return static |
||
| 3286 | * <p>(Immutable)</p> |
||
| 3287 | * |
||
| 3288 | * @see Arrayy::randomKeys() |
||
| 3289 | * |
||
| 3290 | * @psalm-return static<TKey,T> |
||
| 3291 | */ |
||
| 3292 | 8 | public function getRandomKeys(int $number): self |
|
| 3296 | |||
| 3297 | /** |
||
| 3298 | * alias: for "Arrayy->randomValue()" |
||
| 3299 | * |
||
| 3300 | * @return mixed |
||
| 3301 | * <p>Get a random value or null if there wasn't a value.</p> |
||
| 3302 | * |
||
| 3303 | * @see Arrayy::randomValue() |
||
| 3304 | */ |
||
| 3305 | 3 | public function getRandomValue() |
|
| 3309 | |||
| 3310 | /** |
||
| 3311 | * alias: for "Arrayy->randomValues()" |
||
| 3312 | * |
||
| 3313 | * @param int $number |
||
| 3314 | * |
||
| 3315 | * @return static |
||
| 3316 | * <p>(Immutable)</p> |
||
| 3317 | * |
||
| 3318 | * @see Arrayy::randomValues() |
||
| 3319 | * |
||
| 3320 | * @psalm-return static<TKey,T> |
||
| 3321 | */ |
||
| 3322 | 6 | public function getRandomValues(int $number): self |
|
| 3326 | |||
| 3327 | /** |
||
| 3328 | * Gets all values. |
||
| 3329 | * |
||
| 3330 | * @return static |
||
| 3331 | * <p>The values of all elements in this array, in the order they |
||
| 3332 | * appear in the array.</p> |
||
| 3333 | * |
||
| 3334 | * @psalm-return static<TKey,T> |
||
| 3335 | */ |
||
| 3336 | 4 | public function getValues() |
|
| 3346 | |||
| 3347 | /** |
||
| 3348 | * Gets all values via Generator. |
||
| 3349 | * |
||
| 3350 | * @return \Generator |
||
| 3351 | * <p>The values of all elements in this array, in the order they |
||
| 3352 | * appear in the array as Generator.</p> |
||
| 3353 | * |
||
| 3354 | * @psalm-return \Generator<TKey,T> |
||
| 3355 | */ |
||
| 3356 | 4 | public function getValuesYield(): \Generator |
|
| 3360 | |||
| 3361 | /** |
||
| 3362 | * Group values from a array according to the results of a closure. |
||
| 3363 | * |
||
| 3364 | * @param callable|string $grouper <p>A callable function name.</p> |
||
| 3365 | * @param bool $saveKeys |
||
| 3366 | * |
||
| 3367 | * @return static |
||
| 3368 | * <p>(Immutable)</p> |
||
| 3369 | * |
||
| 3370 | * @psalm-return static<TKey,T> |
||
| 3371 | * @psalm-mutation-free |
||
| 3372 | */ |
||
| 3373 | 4 | public function group($grouper, bool $saveKeys = false): self |
|
| 3414 | |||
| 3415 | /** |
||
| 3416 | * Check if an array has a given key. |
||
| 3417 | * |
||
| 3418 | * @param mixed $key |
||
| 3419 | * |
||
| 3420 | * @return bool |
||
| 3421 | */ |
||
| 3422 | 30 | public function has($key): bool |
|
| 3448 | |||
| 3449 | /** |
||
| 3450 | * Check if an array has a given value. |
||
| 3451 | * |
||
| 3452 | * INFO: If you need to search recursive please use ```contains($value, true)```. |
||
| 3453 | * |
||
| 3454 | * @param mixed $value |
||
| 3455 | * |
||
| 3456 | * @return bool |
||
| 3457 | */ |
||
| 3458 | 1 | public function hasValue($value): bool |
|
| 3462 | |||
| 3463 | /** |
||
| 3464 | * Implodes the values of this array. |
||
| 3465 | * |
||
| 3466 | * EXAMPLE: <code> |
||
| 3467 | * a([0 => -9, 1, 2])->implode('|'); // '-9|1|2' |
||
| 3468 | * </code> |
||
| 3469 | * |
||
| 3470 | * @param string $glue |
||
| 3471 | * @param string $prefix |
||
| 3472 | * |
||
| 3473 | * @return string |
||
| 3474 | * @psalm-mutation-free |
||
| 3475 | */ |
||
| 3476 | 28 | public function implode(string $glue = '', string $prefix = ''): string |
|
| 3480 | |||
| 3481 | /** |
||
| 3482 | * Implodes the keys of this array. |
||
| 3483 | * |
||
| 3484 | * @param string $glue |
||
| 3485 | * |
||
| 3486 | * @return string |
||
| 3487 | * @psalm-mutation-free |
||
| 3488 | */ |
||
| 3489 | 8 | public function implodeKeys(string $glue = ''): string |
|
| 3493 | |||
| 3494 | /** |
||
| 3495 | * Given a list and an iterate-function that returns |
||
| 3496 | * a key for each element in the list (or a property name), |
||
| 3497 | * returns an object with an index of each item. |
||
| 3498 | * |
||
| 3499 | * @param mixed $key |
||
| 3500 | * |
||
| 3501 | * @return static |
||
| 3502 | * <p>(Immutable)</p> |
||
| 3503 | * |
||
| 3504 | * @psalm-return static<TKey,T> |
||
| 3505 | * @psalm-mutation-free |
||
| 3506 | */ |
||
| 3507 | 4 | View Code Duplication | public function indexBy($key): self |
| 3524 | |||
| 3525 | /** |
||
| 3526 | * alias: for "Arrayy->searchIndex()" |
||
| 3527 | * |
||
| 3528 | * @param mixed $value <p>The value to search for.</p> |
||
| 3529 | * |
||
| 3530 | * @return false|mixed |
||
| 3531 | * |
||
| 3532 | * @see Arrayy::searchIndex() |
||
| 3533 | */ |
||
| 3534 | 4 | public function indexOf($value) |
|
| 3538 | |||
| 3539 | /** |
||
| 3540 | * Get everything but the last..$to items. |
||
| 3541 | * |
||
| 3542 | * EXAMPLE: <code> |
||
| 3543 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->initial(2); // Arrayy[0 => 'foo'] |
||
| 3544 | * </code> |
||
| 3545 | * |
||
| 3546 | * @param int $to |
||
| 3547 | * |
||
| 3548 | * @return static |
||
| 3549 | * <p>(Immutable)</p> |
||
| 3550 | * |
||
| 3551 | * @psalm-return static<TKey,T> |
||
| 3552 | * @psalm-mutation-free |
||
| 3553 | */ |
||
| 3554 | 12 | public function initial(int $to = 1): self |
|
| 3558 | |||
| 3559 | /** |
||
| 3560 | * Return an array with all elements found in input array. |
||
| 3561 | * |
||
| 3562 | * EXAMPLE: <code> |
||
| 3563 | * a(['foo', 'bar'])->intersection(['bar', 'baz']); // Arrayy['bar'] |
||
| 3564 | * </code> |
||
| 3565 | * |
||
| 3566 | * @param array $search |
||
| 3567 | * @param bool $keepKeys |
||
| 3568 | * |
||
| 3569 | * @return static |
||
| 3570 | * <p>(Immutable)</p> |
||
| 3571 | * |
||
| 3572 | * @psalm-param array<mixed,mixed>|array<TKey,T> $search |
||
| 3573 | * @psalm-return static<TKey,T> |
||
| 3574 | * @psalm-mutation-free |
||
| 3575 | */ |
||
| 3576 | 4 | public function intersection(array $search, bool $keepKeys = false): self |
|
| 3602 | |||
| 3603 | /** |
||
| 3604 | * Return an array with all elements found in input array. |
||
| 3605 | * |
||
| 3606 | * @param array ...$array |
||
| 3607 | * |
||
| 3608 | * @return static |
||
| 3609 | * <p>(Immutable)</p> |
||
| 3610 | * |
||
| 3611 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$array |
||
| 3612 | * @psalm-return static<TKey,T> |
||
| 3613 | * @psalm-mutation-free |
||
| 3614 | */ |
||
| 3615 | 1 | public function intersectionMulti(...$array): self |
|
| 3623 | |||
| 3624 | /** |
||
| 3625 | * Return a boolean flag which indicates whether the two input arrays have any common elements. |
||
| 3626 | * |
||
| 3627 | * EXAMPLE: <code> |
||
| 3628 | * a(['foo', 'bar'])->intersects(['föö', 'bär']); // false |
||
| 3629 | * </code> |
||
| 3630 | * |
||
| 3631 | * @param array $search |
||
| 3632 | * |
||
| 3633 | * @return bool |
||
| 3634 | * |
||
| 3635 | * @psalm-param array<mixed,mixed>|array<TKey,T> $search |
||
| 3636 | */ |
||
| 3637 | 1 | public function intersects(array $search): bool |
|
| 3641 | |||
| 3642 | /** |
||
| 3643 | * Invoke a function on all of an array's values. |
||
| 3644 | * |
||
| 3645 | * @param callable $callable |
||
| 3646 | * @param mixed $arguments |
||
| 3647 | * |
||
| 3648 | * @return static |
||
| 3649 | * <p>(Immutable)</p> |
||
| 3650 | * |
||
| 3651 | * @psalm-param callable(T=,mixed):mixed $callable |
||
| 3652 | * @psalm-return static<TKey,T> |
||
| 3653 | * @psalm-mutation-free |
||
| 3654 | */ |
||
| 3655 | 1 | public function invoke($callable, $arguments = []): self |
|
| 3679 | |||
| 3680 | /** |
||
| 3681 | * Check whether array is associative or not. |
||
| 3682 | * |
||
| 3683 | * EXAMPLE: <code> |
||
| 3684 | * a(['foo' => 'bar', 2, 3])->isAssoc(); // true |
||
| 3685 | * </code> |
||
| 3686 | * |
||
| 3687 | * @param bool $recursive |
||
| 3688 | * |
||
| 3689 | * @return bool |
||
| 3690 | * <p>Returns true if associative, false otherwise.</p> |
||
| 3691 | */ |
||
| 3692 | 15 | View Code Duplication | public function isAssoc(bool $recursive = false): bool |
| 3707 | |||
| 3708 | /** |
||
| 3709 | * Check if a given key or keys are empty. |
||
| 3710 | * |
||
| 3711 | * @param int|int[]|string|string[]|null $keys |
||
| 3712 | * |
||
| 3713 | * @return bool |
||
| 3714 | * <p>Returns true if empty, false otherwise.</p> |
||
| 3715 | * @psalm-mutation-free |
||
| 3716 | */ |
||
| 3717 | 45 | public function isEmpty($keys = null): bool |
|
| 3735 | |||
| 3736 | /** |
||
| 3737 | * Check if the current array is equal to the given "$array" or not. |
||
| 3738 | * |
||
| 3739 | * EXAMPLE: <code> |
||
| 3740 | * a(['💩'])->isEqual(['💩']); // true |
||
| 3741 | * </code> |
||
| 3742 | * |
||
| 3743 | * @param array $array |
||
| 3744 | * |
||
| 3745 | * @return bool |
||
| 3746 | * |
||
| 3747 | * @psalm-param array<mixed,mixed> $array |
||
| 3748 | */ |
||
| 3749 | 1 | public function isEqual(array $array): bool |
|
| 3753 | |||
| 3754 | /** |
||
| 3755 | * Check if the current array is a multi-array. |
||
| 3756 | * |
||
| 3757 | * EXAMPLE: <code> |
||
| 3758 | * a(['foo' => [1, 2 , 3]])->isMultiArray(); // true |
||
| 3759 | * </code> |
||
| 3760 | * |
||
| 3761 | * @return bool |
||
| 3762 | */ |
||
| 3763 | 22 | public function isMultiArray(): bool |
|
| 3773 | |||
| 3774 | /** |
||
| 3775 | * Check whether array is numeric or not. |
||
| 3776 | * |
||
| 3777 | * @return bool |
||
| 3778 | * <p>Returns true if numeric, false otherwise.</p> |
||
| 3779 | */ |
||
| 3780 | 5 | View Code Duplication | public function isNumeric(): bool |
| 3795 | |||
| 3796 | /** |
||
| 3797 | * Check if the current array is sequential [0, 1, 2, 3, 4, 5 ...] or not. |
||
| 3798 | * |
||
| 3799 | * EXAMPLE: <code> |
||
| 3800 | * a([0 => 'foo', 1 => 'lall', 2 => 'foobar'])->isSequential(); // true |
||
| 3801 | * </code> |
||
| 3802 | * |
||
| 3803 | * INFO: If the array is empty we count it as non-sequential. |
||
| 3804 | * |
||
| 3805 | * @param bool $recursive |
||
| 3806 | * |
||
| 3807 | * @return bool |
||
| 3808 | * @psalm-mutation-free |
||
| 3809 | */ |
||
| 3810 | 10 | public function isSequential(bool $recursive = false): bool |
|
| 3839 | |||
| 3840 | /** |
||
| 3841 | * @return array |
||
| 3842 | * |
||
| 3843 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 3844 | */ |
||
| 3845 | 2 | public function jsonSerialize(): array |
|
| 3849 | |||
| 3850 | /** |
||
| 3851 | * Gets the key/index of the element at the current internal iterator position. |
||
| 3852 | * |
||
| 3853 | * @return int|string|null |
||
| 3854 | * @psalm-return array-key|null |
||
| 3855 | */ |
||
| 3856 | public function key() |
||
| 3864 | |||
| 3865 | /** |
||
| 3866 | * Checks if the given key exists in the provided array. |
||
| 3867 | * |
||
| 3868 | * INFO: This method only use "array_key_exists()" if you want to use "dot"-notation, |
||
| 3869 | * then you need to use "Arrayy->offsetExists()". |
||
| 3870 | * |
||
| 3871 | * @param int|string $key the key to look for |
||
| 3872 | * |
||
| 3873 | * @return bool |
||
| 3874 | * @psalm-mutation-free |
||
| 3875 | */ |
||
| 3876 | 174 | public function keyExists($key): bool |
|
| 3886 | |||
| 3887 | /** |
||
| 3888 | * Get all keys from the current array. |
||
| 3889 | * |
||
| 3890 | * EXAMPLE: <code> |
||
| 3891 | * a([1 => 'foo', 2 => 'foo2', 3 => 'bar'])->keys(); // Arrayy[1, 2, 3] |
||
| 3892 | * </code> |
||
| 3893 | * |
||
| 3894 | * @param bool $recursive [optional] <p> |
||
| 3895 | * Get all keys, also from all sub-arrays from an multi-dimensional array. |
||
| 3896 | * </p> |
||
| 3897 | * @param mixed|null $search_values [optional] <p> |
||
| 3898 | * If specified, then only keys containing these values are returned. |
||
| 3899 | * </p> |
||
| 3900 | * @param bool $strict [optional] <p> |
||
| 3901 | * Determines if strict comparison (===) should be used during the search. |
||
| 3902 | * </p> |
||
| 3903 | * |
||
| 3904 | * @return static |
||
| 3905 | * <p>(Immutable) An array of all the keys in input.</p> |
||
| 3906 | * |
||
| 3907 | * @psalm-return static<int,TKey> |
||
| 3908 | * @psalm-mutation-free |
||
| 3909 | */ |
||
| 3910 | 29 | public function keys( |
|
| 3981 | |||
| 3982 | /** |
||
| 3983 | * Sort an array by key in reverse order. |
||
| 3984 | * |
||
| 3985 | * @param int $sort_flags [optional] <p> |
||
| 3986 | * You may modify the behavior of the sort using the optional |
||
| 3987 | * parameter sort_flags, for details |
||
| 3988 | * see sort. |
||
| 3989 | * </p> |
||
| 3990 | * |
||
| 3991 | * @return $this |
||
| 3992 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 3993 | * |
||
| 3994 | * @psalm-return static<TKey,T> |
||
| 3995 | */ |
||
| 3996 | 4 | public function krsort(int $sort_flags = 0): self |
|
| 4004 | |||
| 4005 | /** |
||
| 4006 | * Sort an array by key in reverse order. |
||
| 4007 | * |
||
| 4008 | * @param int $sort_flags [optional] <p> |
||
| 4009 | * You may modify the behavior of the sort using the optional |
||
| 4010 | * parameter sort_flags, for details |
||
| 4011 | * see sort. |
||
| 4012 | * </p> |
||
| 4013 | * |
||
| 4014 | * @return $this |
||
| 4015 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 4016 | * |
||
| 4017 | * @psalm-return static<TKey,T> |
||
| 4018 | * @psalm-mutation-free |
||
| 4019 | */ |
||
| 4020 | 4 | public function krsortImmutable(int $sort_flags = 0): self |
|
| 4031 | |||
| 4032 | /** |
||
| 4033 | * Get the last value from the current array. |
||
| 4034 | * |
||
| 4035 | * EXAMPLE: <code> |
||
| 4036 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->last(); // 'lall' |
||
| 4037 | * </code> |
||
| 4038 | * |
||
| 4039 | * @return mixed|null |
||
| 4040 | * <p>Return null if there wasn't a element.</p> |
||
| 4041 | * @psalm-mutation-free |
||
| 4042 | */ |
||
| 4043 | 17 | public function last() |
|
| 4052 | |||
| 4053 | /** |
||
| 4054 | * Get the last key from the current array. |
||
| 4055 | * |
||
| 4056 | * @return mixed|null |
||
| 4057 | * <p>Return null if there wasn't a element.</p> |
||
| 4058 | * @psalm-mutation-free |
||
| 4059 | */ |
||
| 4060 | 21 | public function lastKey() |
|
| 4066 | |||
| 4067 | /** |
||
| 4068 | * Get the last value(s) from the current array. |
||
| 4069 | * |
||
| 4070 | * EXAMPLE: <code> |
||
| 4071 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->lasts(2); // Arrayy[0 => 'bar', 1 => 'lall'] |
||
| 4072 | * </code> |
||
| 4073 | * |
||
| 4074 | * @param int|null $number |
||
| 4075 | * |
||
| 4076 | * @return static |
||
| 4077 | * <p>(Immutable)</p> |
||
| 4078 | * |
||
| 4079 | * @psalm-return static<TKey,T> |
||
| 4080 | * @psalm-mutation-free |
||
| 4081 | */ |
||
| 4082 | 13 | public function lastsImmutable(int $number = null): self |
|
| 4112 | |||
| 4113 | /** |
||
| 4114 | * Get the last value(s) from the current array. |
||
| 4115 | * |
||
| 4116 | * EXAMPLE: <code> |
||
| 4117 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->lasts(2); // Arrayy[0 => 'bar', 1 => 'lall'] |
||
| 4118 | * </code> |
||
| 4119 | * |
||
| 4120 | * @param int|null $number |
||
| 4121 | * |
||
| 4122 | * @return $this |
||
| 4123 | * <p>(Mutable)</p> |
||
| 4124 | * |
||
| 4125 | * @psalm-return static<TKey,T> |
||
| 4126 | */ |
||
| 4127 | 13 | public function lastsMutable(int $number = null): self |
|
| 4138 | |||
| 4139 | /** |
||
| 4140 | * Count the values from the current array. |
||
| 4141 | * |
||
| 4142 | * alias: for "Arrayy->count()" |
||
| 4143 | * |
||
| 4144 | * @param int $mode |
||
| 4145 | * |
||
| 4146 | * @return int |
||
| 4147 | * |
||
| 4148 | * @see Arrayy::count() |
||
| 4149 | */ |
||
| 4150 | 20 | public function length(int $mode = \COUNT_NORMAL): int |
|
| 4154 | |||
| 4155 | /** |
||
| 4156 | * Apply the given function to the every element of the array, |
||
| 4157 | * collecting the results. |
||
| 4158 | * |
||
| 4159 | * EXAMPLE: <code> |
||
| 4160 | * a(['foo', 'Foo'])->map('mb_strtoupper'); // Arrayy['FOO', 'FOO'] |
||
| 4161 | * </code> |
||
| 4162 | * |
||
| 4163 | * @param callable $callable |
||
| 4164 | * @param bool $useKeyAsSecondParameter |
||
| 4165 | * @param mixed ...$arguments |
||
| 4166 | * |
||
| 4167 | * @return static |
||
| 4168 | * <p>(Immutable) Arrayy object with modified elements.</p> |
||
| 4169 | * |
||
| 4170 | * @psalm-param callable(T,TKey=,mixed=):mixed $callable |
||
| 4171 | * @psalm-return static<TKey,T> |
||
| 4172 | * @psalm-mutation-free |
||
| 4173 | */ |
||
| 4174 | 6 | public function map( |
|
| 4207 | |||
| 4208 | /** |
||
| 4209 | * Check if all items in current array match a truth test. |
||
| 4210 | * |
||
| 4211 | * EXAMPLE: <code> |
||
| 4212 | * $closure = function ($value, $key) { |
||
| 4213 | * return ($value % 2 === 0); |
||
| 4214 | * }; |
||
| 4215 | * a([2, 4, 8])->matches($closure); // true |
||
| 4216 | * </code> |
||
| 4217 | * |
||
| 4218 | * @param \Closure $closure |
||
| 4219 | * |
||
| 4220 | * @return bool |
||
| 4221 | */ |
||
| 4222 | 15 | View Code Duplication | public function matches(\Closure $closure): bool |
| 4238 | |||
| 4239 | /** |
||
| 4240 | * Check if any item in the current array matches a truth test. |
||
| 4241 | * |
||
| 4242 | * EXAMPLE: <code> |
||
| 4243 | * $closure = function ($value, $key) { |
||
| 4244 | * return ($value % 2 === 0); |
||
| 4245 | * }; |
||
| 4246 | * a([1, 4, 7])->matches($closure); // true |
||
| 4247 | * </code> |
||
| 4248 | * |
||
| 4249 | * @param \Closure $closure |
||
| 4250 | * |
||
| 4251 | * @return bool |
||
| 4252 | */ |
||
| 4253 | 14 | View Code Duplication | public function matchesAny(\Closure $closure): bool |
| 4269 | |||
| 4270 | /** |
||
| 4271 | * Get the max value from an array. |
||
| 4272 | * |
||
| 4273 | * EXAMPLE: <code> |
||
| 4274 | * a([-9, -8, -7, 1.32])->max(); // 1.32 |
||
| 4275 | * </code> |
||
| 4276 | * |
||
| 4277 | * @return false|mixed |
||
| 4278 | * <p>Will return false if there are no values.</p> |
||
| 4279 | */ |
||
| 4280 | 10 | View Code Duplication | public function max() |
| 4300 | |||
| 4301 | /** |
||
| 4302 | * Merge the new $array into the current array. |
||
| 4303 | * |
||
| 4304 | * - keep key,value from the current array, also if the index is in the new $array |
||
| 4305 | * |
||
| 4306 | * EXAMPLE: <code> |
||
| 4307 | * $array1 = [1 => 'one', 'foo' => 'bar1']; |
||
| 4308 | * $array2 = ['foo' => 'bar2', 3 => 'three']; |
||
| 4309 | * a($array1)->mergeAppendKeepIndex($array2); // Arrayy[1 => 'one', 'foo' => 'bar2', 3 => 'three'] |
||
| 4310 | * // --- |
||
| 4311 | * $array1 = [0 => 'one', 1 => 'foo']; |
||
| 4312 | * $array2 = [0 => 'foo', 1 => 'bar2']; |
||
| 4313 | * a($array1)->mergeAppendKeepIndex($array2); // Arrayy[0 => 'foo', 1 => 'bar2'] |
||
| 4314 | * </code> |
||
| 4315 | * |
||
| 4316 | * @param array $array |
||
| 4317 | * @param bool $recursive |
||
| 4318 | * |
||
| 4319 | * @return static |
||
| 4320 | * <p>(Immutable)</p> |
||
| 4321 | * |
||
| 4322 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 4323 | * @psalm-return static<int|TKey,T> |
||
| 4324 | * @psalm-mutation-free |
||
| 4325 | */ |
||
| 4326 | 33 | View Code Duplication | public function mergeAppendKeepIndex(array $array = [], bool $recursive = false): self |
| 4341 | |||
| 4342 | /** |
||
| 4343 | * Merge the new $array into the current array. |
||
| 4344 | * |
||
| 4345 | * - replace duplicate assoc-keys from the current array with the key,values from the new $array |
||
| 4346 | * - create new indexes |
||
| 4347 | * |
||
| 4348 | * EXAMPLE: <code> |
||
| 4349 | * $array1 = [1 => 'one', 'foo' => 'bar1']; |
||
| 4350 | * $array2 = ['foo' => 'bar2', 3 => 'three']; |
||
| 4351 | * a($array1)->mergeAppendNewIndex($array2); // Arrayy[0 => 'one', 'foo' => 'bar2', 1 => 'three'] |
||
| 4352 | * // --- |
||
| 4353 | * $array1 = [0 => 'one', 1 => 'foo']; |
||
| 4354 | * $array2 = [0 => 'foo', 1 => 'bar2']; |
||
| 4355 | * a($array1)->mergeAppendNewIndex($array2); // Arrayy[0 => 'one', 1 => 'foo', 2 => 'foo', 3 => 'bar2'] |
||
| 4356 | * </code> |
||
| 4357 | * |
||
| 4358 | * @param array $array |
||
| 4359 | * @param bool $recursive |
||
| 4360 | * |
||
| 4361 | * @return static |
||
| 4362 | * <p>(Immutable)</p> |
||
| 4363 | * |
||
| 4364 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 4365 | * @psalm-return static<int,T> |
||
| 4366 | * @psalm-mutation-free |
||
| 4367 | */ |
||
| 4368 | 20 | View Code Duplication | public function mergeAppendNewIndex(array $array = [], bool $recursive = false): self |
| 4383 | |||
| 4384 | /** |
||
| 4385 | * Merge the the current array into the $array. |
||
| 4386 | * |
||
| 4387 | * - use key,value from the new $array, also if the index is in the current array |
||
| 4388 | * |
||
| 4389 | * EXAMPLE: <code> |
||
| 4390 | * $array1 = [1 => 'one', 'foo' => 'bar1']; |
||
| 4391 | * $array2 = ['foo' => 'bar2', 3 => 'three']; |
||
| 4392 | * a($array1)->mergePrependKeepIndex($array2); // Arrayy['foo' => 'bar1', 3 => 'three', 1 => 'one'] |
||
| 4393 | * // --- |
||
| 4394 | * $array1 = [0 => 'one', 1 => 'foo']; |
||
| 4395 | * $array2 = [0 => 'foo', 1 => 'bar2']; |
||
| 4396 | * a($array1)->mergePrependKeepIndex($array2); // Arrayy[0 => 'one', 1 => 'foo'] |
||
| 4397 | * </code> |
||
| 4398 | * |
||
| 4399 | * @param array $array |
||
| 4400 | * @param bool $recursive |
||
| 4401 | * |
||
| 4402 | * @return static |
||
| 4403 | * <p>(Immutable)</p> |
||
| 4404 | * |
||
| 4405 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 4406 | * @psalm-return static<TKey,T> |
||
| 4407 | * @psalm-mutation-free |
||
| 4408 | */ |
||
| 4409 | 17 | View Code Duplication | public function mergePrependKeepIndex(array $array = [], bool $recursive = false): self |
| 4424 | |||
| 4425 | /** |
||
| 4426 | * Merge the current array into the new $array. |
||
| 4427 | * |
||
| 4428 | * - replace duplicate assoc-keys from new $array with the key,values from the current array |
||
| 4429 | * - create new indexes |
||
| 4430 | * |
||
| 4431 | * EXAMPLE: <code> |
||
| 4432 | * $array1 = [1 => 'one', 'foo' => 'bar1']; |
||
| 4433 | * $array2 = ['foo' => 'bar2', 3 => 'three']; |
||
| 4434 | * a($array1)->mergePrependNewIndex($array2); // Arrayy['foo' => 'bar1', 0 => 'three', 1 => 'one'] |
||
| 4435 | * // --- |
||
| 4436 | * $array1 = [0 => 'one', 1 => 'foo']; |
||
| 4437 | * $array2 = [0 => 'foo', 1 => 'bar2']; |
||
| 4438 | * a($array1)->mergePrependNewIndex($array2); // Arrayy[0 => 'foo', 1 => 'bar2', 2 => 'one', 3 => 'foo'] |
||
| 4439 | * </code> |
||
| 4440 | * |
||
| 4441 | * @param array $array |
||
| 4442 | * @param bool $recursive |
||
| 4443 | * |
||
| 4444 | * @return static |
||
| 4445 | * <p>(Immutable)</p> |
||
| 4446 | * |
||
| 4447 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 4448 | * @psalm-return static<int,T> |
||
| 4449 | * @psalm-mutation-free |
||
| 4450 | */ |
||
| 4451 | 21 | View Code Duplication | public function mergePrependNewIndex(array $array = [], bool $recursive = false): self |
| 4466 | |||
| 4467 | /** |
||
| 4468 | * @return ArrayyMeta|mixed|static |
||
| 4469 | */ |
||
| 4470 | 18 | public static function meta() |
|
| 4474 | |||
| 4475 | /** |
||
| 4476 | * Get the min value from an array. |
||
| 4477 | * |
||
| 4478 | * EXAMPLE: <code> |
||
| 4479 | * a([-9, -8, -7, 1.32])->min(); // -9 |
||
| 4480 | * </code> |
||
| 4481 | * |
||
| 4482 | * @return false|mixed |
||
| 4483 | * <p>Will return false if there are no values.</p> |
||
| 4484 | */ |
||
| 4485 | 10 | View Code Duplication | public function min() |
| 4505 | |||
| 4506 | /** |
||
| 4507 | * Get the most used value from the array. |
||
| 4508 | * |
||
| 4509 | * @return mixed|null |
||
| 4510 | * <p>(Immutable) Return null if there wasn't a element.</p> |
||
| 4511 | * @psalm-mutation-free |
||
| 4512 | */ |
||
| 4513 | 3 | public function mostUsedValue() |
|
| 4517 | |||
| 4518 | /** |
||
| 4519 | * Get the most used value from the array. |
||
| 4520 | * |
||
| 4521 | * @param int|null $number <p>How many values you will take?</p> |
||
| 4522 | * |
||
| 4523 | * @return static |
||
| 4524 | * <p>(Immutable)</p> |
||
| 4525 | * |
||
| 4526 | * @psalm-return static<TKey,T> |
||
| 4527 | * @psalm-mutation-free |
||
| 4528 | */ |
||
| 4529 | 3 | public function mostUsedValues(int $number = null): self |
|
| 4533 | |||
| 4534 | /** |
||
| 4535 | * Move an array element to a new index. |
||
| 4536 | * |
||
| 4537 | * EXAMPLE: <code> |
||
| 4538 | * $arr2 = new A(['A' => 'a', 'B' => 'b', 'C' => 'c', 'D' => 'd', 'E' => 'e']); |
||
| 4539 | * $newArr2 = $arr2->moveElement('D', 1); // Arrayy['A' => 'a', 'D' => 'd', 'B' => 'b', 'C' => 'c', 'E' => 'e'] |
||
| 4540 | * </code> |
||
| 4541 | * |
||
| 4542 | * @param int|string $from |
||
| 4543 | * @param int $to |
||
| 4544 | * |
||
| 4545 | * @return static |
||
| 4546 | * <p>(Immutable)</p> |
||
| 4547 | * |
||
| 4548 | * @psalm-return static<TKey,T> |
||
| 4549 | * @psalm-mutation-free |
||
| 4550 | */ |
||
| 4551 | 1 | public function moveElement($from, $to): self |
|
| 4584 | |||
| 4585 | /** |
||
| 4586 | * Move an array element to the first place. |
||
| 4587 | * |
||
| 4588 | * INFO: Instead of "Arrayy->moveElement()" this method will NOT |
||
| 4589 | * loss the keys of an indexed array. |
||
| 4590 | * |
||
| 4591 | * @param int|string $key |
||
| 4592 | * |
||
| 4593 | * @return static |
||
| 4594 | * <p>(Immutable)</p> |
||
| 4595 | * |
||
| 4596 | * @psalm-return static<TKey,T> |
||
| 4597 | * @psalm-mutation-free |
||
| 4598 | */ |
||
| 4599 | 1 | View Code Duplication | public function moveElementToFirstPlace($key): self |
| 4615 | |||
| 4616 | /** |
||
| 4617 | * Move an array element to the last place. |
||
| 4618 | * |
||
| 4619 | * INFO: Instead of "Arrayy->moveElement()" this method will NOT |
||
| 4620 | * loss the keys of an indexed array. |
||
| 4621 | * |
||
| 4622 | * @param int|string $key |
||
| 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 moveElementToLastPlace($key): self |
| 4646 | |||
| 4647 | /** |
||
| 4648 | * Moves the internal iterator position to the next element and returns this element. |
||
| 4649 | * |
||
| 4650 | * @return false|mixed |
||
| 4651 | * <p>(Mutable) Will return false if there are no values.</p> |
||
| 4652 | * |
||
| 4653 | * @psalm-return false|T |
||
| 4654 | */ |
||
| 4655 | public function next() |
||
| 4665 | |||
| 4666 | /** |
||
| 4667 | * Get the next nth keys and values from the array. |
||
| 4668 | * |
||
| 4669 | * @param int $step |
||
| 4670 | * @param int $offset |
||
| 4671 | * |
||
| 4672 | * @return static |
||
| 4673 | * <p>(Immutable)</p> |
||
| 4674 | * |
||
| 4675 | * @psalm-return static<TKey,T> |
||
| 4676 | * @psalm-mutation-free |
||
| 4677 | */ |
||
| 4678 | 1 | public function nth(int $step, int $offset = 0): self |
|
| 4697 | |||
| 4698 | /** |
||
| 4699 | * Get a subset of the items from the given array. |
||
| 4700 | * |
||
| 4701 | * @param int[]|string[] $keys |
||
| 4702 | * |
||
| 4703 | * @return static |
||
| 4704 | * <p>(Immutable)</p> |
||
| 4705 | * |
||
| 4706 | * @psalm-param array-key[] $keys |
||
| 4707 | * @psalm-return static<TKey,T> |
||
| 4708 | * @psalm-mutation-free |
||
| 4709 | */ |
||
| 4710 | 1 | View Code Duplication | public function only(array $keys): self |
| 4728 | |||
| 4729 | /** |
||
| 4730 | * Pad array to the specified size with a given value. |
||
| 4731 | * |
||
| 4732 | * @param int $size <p>Size of the result array.</p> |
||
| 4733 | * @param mixed $value <p>Empty value by default.</p> |
||
| 4734 | * |
||
| 4735 | * @return static |
||
| 4736 | * <p>(Immutable) Arrayy object padded to $size with $value.</p> |
||
| 4737 | * |
||
| 4738 | * @psalm-return static<TKey,T> |
||
| 4739 | * @psalm-mutation-free |
||
| 4740 | */ |
||
| 4741 | 5 | public function pad(int $size, $value): self |
|
| 4749 | |||
| 4750 | /** |
||
| 4751 | * Partitions this array in two array according to a predicate. |
||
| 4752 | * Keys are preserved in the resulting array. |
||
| 4753 | * |
||
| 4754 | * @param \Closure $closure |
||
| 4755 | * <p>The predicate on which to partition.</p> |
||
| 4756 | * |
||
| 4757 | * @return array<int, static> |
||
| 4758 | * <p>An array with two elements. The first element contains the array |
||
| 4759 | * of elements where the predicate returned TRUE, the second element |
||
| 4760 | * contains the array of elements where the predicate returned FALSE.</p> |
||
| 4761 | * |
||
| 4762 | * @psalm-return array<int, static<TKey,T>> |
||
| 4763 | */ |
||
| 4764 | 1 | public function partition(\Closure $closure): array |
|
| 4780 | |||
| 4781 | /** |
||
| 4782 | * Pop a specified value off the end of the current array. |
||
| 4783 | * |
||
| 4784 | * @return mixed|null |
||
| 4785 | * <p>(Mutable) The popped element from the current array or null if the array is e.g. empty.</p> |
||
| 4786 | */ |
||
| 4787 | 5 | public function pop() |
|
| 4793 | |||
| 4794 | /** |
||
| 4795 | * Prepend a (key) + value to the current array. |
||
| 4796 | * |
||
| 4797 | * EXAMPLE: <code> |
||
| 4798 | * a(['fòô' => 'bàř'])->prepend('foo'); // Arrayy[0 => 'foo', 'fòô' => 'bàř'] |
||
| 4799 | * </code> |
||
| 4800 | * |
||
| 4801 | * @param mixed $value |
||
| 4802 | * @param mixed $key |
||
| 4803 | * |
||
| 4804 | * @return $this |
||
| 4805 | * <p>(Mutable) Return this Arrayy object, with the prepended value.</p> |
||
| 4806 | * |
||
| 4807 | * @psalm-param T $value |
||
| 4808 | * @psalm-param TKey|null $key |
||
| 4809 | * @psalm-return static<TKey,T> |
||
| 4810 | */ |
||
| 4811 | 11 | public function prepend($value, $key = null) |
|
| 4827 | |||
| 4828 | /** |
||
| 4829 | * Prepend a (key) + value to the current array. |
||
| 4830 | * |
||
| 4831 | * EXAMPLE: <code> |
||
| 4832 | * a(['fòô' => 'bàř'])->prependImmutable('foo')->getArray(); // [0 => 'foo', 'fòô' => 'bàř'] |
||
| 4833 | * </code> |
||
| 4834 | * |
||
| 4835 | * @param mixed $value |
||
| 4836 | * @param mixed $key |
||
| 4837 | * |
||
| 4838 | * @return $this |
||
| 4839 | * <p>(Immutable) Return this Arrayy object, with the prepended value.</p> |
||
| 4840 | * |
||
| 4841 | * @psalm-param T $value |
||
| 4842 | * @psalm-param TKey $key |
||
| 4843 | * @psalm-return static<TKey,T> |
||
| 4844 | * @psalm-mutation-free |
||
| 4845 | */ |
||
| 4846 | 1 | View Code Duplication | public function prependImmutable($value, $key = null) |
| 4871 | |||
| 4872 | /** |
||
| 4873 | * Add a suffix to each key. |
||
| 4874 | * |
||
| 4875 | * @param mixed $suffix |
||
| 4876 | * |
||
| 4877 | * @return static |
||
| 4878 | * <p>(Immutable) Return an Arrayy object, with the prepended keys.</p> |
||
| 4879 | * |
||
| 4880 | * @psalm-return static<TKey,T> |
||
| 4881 | * @psalm-mutation-free |
||
| 4882 | */ |
||
| 4883 | 10 | View Code Duplication | public function prependToEachKey($suffix): self |
| 4909 | |||
| 4910 | /** |
||
| 4911 | * Add a suffix to each value. |
||
| 4912 | * |
||
| 4913 | * @param mixed $suffix |
||
| 4914 | * |
||
| 4915 | * @return static |
||
| 4916 | * <p>(Immutable) Return an Arrayy object, with the prepended values.</p> |
||
| 4917 | * |
||
| 4918 | * @psalm-return static<TKey,T> |
||
| 4919 | * @psalm-mutation-free |
||
| 4920 | */ |
||
| 4921 | 10 | View Code Duplication | public function prependToEachValue($suffix): self |
| 4949 | |||
| 4950 | /** |
||
| 4951 | * Return the value of a given key and |
||
| 4952 | * delete the key. |
||
| 4953 | * |
||
| 4954 | * @param int|int[]|string|string[]|null $keyOrKeys |
||
| 4955 | * @param mixed $fallback |
||
| 4956 | * |
||
| 4957 | * @return mixed |
||
| 4958 | */ |
||
| 4959 | 6 | public function pull($keyOrKeys = null, $fallback = null) |
|
| 4981 | |||
| 4982 | /** |
||
| 4983 | * Push one or more values onto the end of array at once. |
||
| 4984 | * |
||
| 4985 | * @param mixed ...$args |
||
| 4986 | * |
||
| 4987 | * @return $this |
||
| 4988 | * <p>(Mutable) Return this Arrayy object, with pushed elements to the end of array.</p> |
||
| 4989 | * |
||
| 4990 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
| 4991 | * |
||
| 4992 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$args |
||
| 4993 | * @psalm-return static<TKey,T> |
||
| 4994 | */ |
||
| 4995 | 9 | View Code Duplication | public function push(...$args) |
| 5013 | |||
| 5014 | /** |
||
| 5015 | * Get a random value from the current array. |
||
| 5016 | * |
||
| 5017 | * EXAMPLE: <code> |
||
| 5018 | * a([1, 2, 3, 4])->randomImmutable(2); // e.g.: Arrayy[1, 4] |
||
| 5019 | * </code> |
||
| 5020 | * |
||
| 5021 | * @param int|null $number <p>How many values you will take?</p> |
||
| 5022 | * |
||
| 5023 | * @return static |
||
| 5024 | * <p>(Immutable)</p> |
||
| 5025 | * |
||
| 5026 | * @psalm-return static<int|array-key,T> |
||
| 5027 | */ |
||
| 5028 | 19 | public function randomImmutable(int $number = null): self |
|
| 5061 | |||
| 5062 | /** |
||
| 5063 | * Pick a random key/index from the keys of this array. |
||
| 5064 | * |
||
| 5065 | * EXAMPLE: <code> |
||
| 5066 | * $arrayy = A::create([1 => 'one', 2 => 'two']); |
||
| 5067 | * $arrayy->randomKey(); // e.g. 2 |
||
| 5068 | * </code> |
||
| 5069 | * |
||
| 5070 | * @throws \RangeException If array is empty |
||
| 5071 | * |
||
| 5072 | * @return mixed |
||
| 5073 | * <p>Get a key/index or null if there wasn't a key/index.</p> |
||
| 5074 | */ |
||
| 5075 | 4 | public function randomKey() |
|
| 5085 | |||
| 5086 | /** |
||
| 5087 | * Pick a given number of random keys/indexes out of this array. |
||
| 5088 | * |
||
| 5089 | * EXAMPLE: <code> |
||
| 5090 | * a([1 => 'one', 2 => 'two'])->randomKeys(); // e.g. Arrayy[1, 2] |
||
| 5091 | * </code> |
||
| 5092 | * |
||
| 5093 | * @param int $number <p>The number of keys/indexes (should be <= \count($this->array))</p> |
||
| 5094 | * |
||
| 5095 | * @throws \RangeException If array is empty |
||
| 5096 | * |
||
| 5097 | * @return static |
||
| 5098 | * <p>(Immutable)</p> |
||
| 5099 | * |
||
| 5100 | * @psalm-return static<TKey,T> |
||
| 5101 | */ |
||
| 5102 | 13 | public function randomKeys(int $number): self |
|
| 5130 | |||
| 5131 | /** |
||
| 5132 | * Get a random value from the current array. |
||
| 5133 | * |
||
| 5134 | * EXAMPLE: <code> |
||
| 5135 | * a([1, 2, 3, 4])->randomMutable(2); // e.g.: Arrayy[1, 4] |
||
| 5136 | * </code> |
||
| 5137 | * |
||
| 5138 | * @param int|null $number <p>How many values you will take?</p> |
||
| 5139 | * |
||
| 5140 | * @return $this |
||
| 5141 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 5142 | * |
||
| 5143 | * @psalm-return static<TKey,T> |
||
| 5144 | */ |
||
| 5145 | 17 | public function randomMutable(int $number = null): self |
|
| 5170 | |||
| 5171 | /** |
||
| 5172 | * Pick a random value from the values of this array. |
||
| 5173 | * |
||
| 5174 | * EXAMPLE: <code> |
||
| 5175 | * a([1 => 'one', 2 => 'two'])->randomValue(); // e.g. 'one' |
||
| 5176 | * </code> |
||
| 5177 | * |
||
| 5178 | * @return mixed |
||
| 5179 | * <p>Get a random value or null if there wasn't a value.</p> |
||
| 5180 | */ |
||
| 5181 | 4 | public function randomValue() |
|
| 5191 | |||
| 5192 | /** |
||
| 5193 | * Pick a given number of random values out of this array. |
||
| 5194 | * |
||
| 5195 | * EXAMPLE: <code> |
||
| 5196 | * a([1 => 'one', 2 => 'two'])->randomValues(); // e.g. Arrayy['one', 'two'] |
||
| 5197 | * </code> |
||
| 5198 | * |
||
| 5199 | * @param int $number |
||
| 5200 | * |
||
| 5201 | * @return static |
||
| 5202 | * <p>(Mutable)</p> |
||
| 5203 | * |
||
| 5204 | * @psalm-return static<TKey,T> |
||
| 5205 | */ |
||
| 5206 | 7 | public function randomValues(int $number): self |
|
| 5210 | |||
| 5211 | /** |
||
| 5212 | * Get a random value from an array, with the ability to skew the results. |
||
| 5213 | * |
||
| 5214 | * EXAMPLE: <code> |
||
| 5215 | * a([0 => 3, 1 => 4])->randomWeighted([1 => 4]); // e.g.: Arrayy[4] (has a 66% chance of returning 4) |
||
| 5216 | * </code> |
||
| 5217 | * |
||
| 5218 | * @param array $array |
||
| 5219 | * @param int|null $number <p>How many values you will take?</p> |
||
| 5220 | * |
||
| 5221 | * @return static<int,mixed> |
||
| 5222 | * <p>(Immutable)</p> |
||
| 5223 | * |
||
| 5224 | * @psalm-param array<mixed,mixed> $array |
||
| 5225 | * @psalm-return static<int|array-key,T> |
||
| 5226 | */ |
||
| 5227 | 9 | public function randomWeighted(array $array, int $number = null): self |
|
| 5242 | |||
| 5243 | /** |
||
| 5244 | * Reduce the current array via callable e.g. anonymous-function and return the end result. |
||
| 5245 | * |
||
| 5246 | * EXAMPLE: <code> |
||
| 5247 | * a([1, 2, 3, 4])->reduce( |
||
| 5248 | * function ($carry, $item) { |
||
| 5249 | * return $carry * $item; |
||
| 5250 | * }, |
||
| 5251 | * 1 |
||
| 5252 | * ); // Arrayy[24] |
||
| 5253 | * </code> |
||
| 5254 | * |
||
| 5255 | * @param callable $callable |
||
| 5256 | * @param mixed $initial |
||
| 5257 | * |
||
| 5258 | * @return static |
||
| 5259 | * <p>(Immutable)</p> |
||
| 5260 | * |
||
| 5261 | * @psalm-return static<TKey,T> |
||
| 5262 | * @psalm-mutation-free |
||
| 5263 | */ |
||
| 5264 | 18 | View Code Duplication | public function reduce($callable, $initial = []): self |
| 5276 | |||
| 5277 | /** |
||
| 5278 | * @param bool $unique |
||
| 5279 | * |
||
| 5280 | * @return static |
||
| 5281 | * <p>(Immutable)</p> |
||
| 5282 | * |
||
| 5283 | * @psalm-return static<int,mixed> |
||
| 5284 | * @psalm-mutation-free |
||
| 5285 | */ |
||
| 5286 | 14 | public function reduce_dimension(bool $unique = true): self |
|
| 5309 | |||
| 5310 | /** |
||
| 5311 | * Create a numerically re-indexed Arrayy object. |
||
| 5312 | * |
||
| 5313 | * EXAMPLE: <code> |
||
| 5314 | * a([2 => 1, 3 => 2])->reindex(); // Arrayy[0 => 1, 1 => 2] |
||
| 5315 | * </code> |
||
| 5316 | * |
||
| 5317 | * @return $this |
||
| 5318 | * <p>(Mutable) Return this Arrayy object, with re-indexed array-elements.</p> |
||
| 5319 | * |
||
| 5320 | * @psalm-return static<TKey,T> |
||
| 5321 | */ |
||
| 5322 | 9 | public function reindex(): self |
|
| 5330 | |||
| 5331 | /** |
||
| 5332 | * Return all items that fail the truth test. |
||
| 5333 | * |
||
| 5334 | * EXAMPLE: <code> |
||
| 5335 | * $closure = function ($value) { |
||
| 5336 | * return $value % 2 !== 0; |
||
| 5337 | * } |
||
| 5338 | * a([1, 2, 3, 4])->reject($closure); // Arrayy[1 => 2, 3 => 4] |
||
| 5339 | * </code> |
||
| 5340 | * |
||
| 5341 | * @param \Closure $closure |
||
| 5342 | * |
||
| 5343 | * @return static |
||
| 5344 | * <p>(Immutable)</p> |
||
| 5345 | * |
||
| 5346 | * @psalm-return static<TKey,T> |
||
| 5347 | * @psalm-mutation-free |
||
| 5348 | */ |
||
| 5349 | 1 | View Code Duplication | public function reject(\Closure $closure): self |
| 5366 | |||
| 5367 | /** |
||
| 5368 | * Remove a value from the current array (optional using dot-notation). |
||
| 5369 | * |
||
| 5370 | * EXAMPLE: <code> |
||
| 5371 | * a([1 => 'bar', 'foo' => 'foo'])->remove(1); // Arrayy['foo' => 'foo'] |
||
| 5372 | * </code> |
||
| 5373 | * |
||
| 5374 | * @param mixed $key |
||
| 5375 | * |
||
| 5376 | * @return static |
||
| 5377 | * <p>(Mutable)</p> |
||
| 5378 | * |
||
| 5379 | * @psalm-param TKey $key |
||
| 5380 | * @psalm-return static<TKey,T> |
||
| 5381 | */ |
||
| 5382 | 22 | public function remove($key) |
|
| 5405 | |||
| 5406 | /** |
||
| 5407 | * alias: for "Arrayy->removeValue()" |
||
| 5408 | * |
||
| 5409 | * @param mixed $element |
||
| 5410 | * |
||
| 5411 | * @return static |
||
| 5412 | * <p>(Immutable)</p> |
||
| 5413 | * |
||
| 5414 | * @psalm-param T $element |
||
| 5415 | * @psalm-return static<TKey,T> |
||
| 5416 | * @psalm-mutation-free |
||
| 5417 | */ |
||
| 5418 | 8 | public function removeElement($element) |
|
| 5422 | |||
| 5423 | /** |
||
| 5424 | * Remove the first value from the current array. |
||
| 5425 | * |
||
| 5426 | * EXAMPLE: <code> |
||
| 5427 | * a([1 => 'bar', 'foo' => 'foo'])->removeFirst(); // Arrayy['foo' => 'foo'] |
||
| 5428 | * </code> |
||
| 5429 | * |
||
| 5430 | * @return static |
||
| 5431 | * <p>(Immutable)</p> |
||
| 5432 | * |
||
| 5433 | * @psalm-return static<TKey,T> |
||
| 5434 | * @psalm-mutation-free |
||
| 5435 | */ |
||
| 5436 | 7 | View Code Duplication | public function removeFirst(): self |
| 5448 | |||
| 5449 | /** |
||
| 5450 | * Remove the last value from the current array. |
||
| 5451 | * |
||
| 5452 | * EXAMPLE: <code> |
||
| 5453 | * a([1 => 'bar', 'foo' => 'foo'])->removeLast(); // Arrayy[1 => 'bar'] |
||
| 5454 | * </code> |
||
| 5455 | * |
||
| 5456 | * @return static |
||
| 5457 | * <p>(Immutable)</p> |
||
| 5458 | * |
||
| 5459 | * @psalm-return static<TKey,T> |
||
| 5460 | * @psalm-mutation-free |
||
| 5461 | */ |
||
| 5462 | 7 | View Code Duplication | public function removeLast(): self |
| 5474 | |||
| 5475 | /** |
||
| 5476 | * Removes a particular value from an array (numeric or associative). |
||
| 5477 | * |
||
| 5478 | * EXAMPLE: <code> |
||
| 5479 | * a([1 => 'bar', 'foo' => 'foo'])->removeValue('foo'); // Arrayy[1 => 'bar'] |
||
| 5480 | * </code> |
||
| 5481 | * |
||
| 5482 | * @param mixed $value |
||
| 5483 | * |
||
| 5484 | * @return static |
||
| 5485 | * <p>(Immutable)</p> |
||
| 5486 | * |
||
| 5487 | * @psalm-param T $value |
||
| 5488 | * @psalm-return static<TKey,T> |
||
| 5489 | * @psalm-mutation-free |
||
| 5490 | */ |
||
| 5491 | 8 | public function removeValue($value): self |
|
| 5514 | |||
| 5515 | /** |
||
| 5516 | * Generate array of repeated arrays. |
||
| 5517 | * |
||
| 5518 | * @param int $times <p>How many times has to be repeated.</p> |
||
| 5519 | * |
||
| 5520 | * @return static |
||
| 5521 | * <p>(Immutable)</p> |
||
| 5522 | * |
||
| 5523 | * @psalm-return static<TKey,T> |
||
| 5524 | * @psalm-mutation-free |
||
| 5525 | */ |
||
| 5526 | 1 | public function repeat($times): self |
|
| 5538 | |||
| 5539 | /** |
||
| 5540 | * Replace a key with a new key/value pair. |
||
| 5541 | * |
||
| 5542 | * EXAMPLE: <code> |
||
| 5543 | * $arrayy = a([1 => 'foo', 2 => 'foo2', 3 => 'bar']); |
||
| 5544 | * $arrayy->replace(2, 'notfoo', 'notbar'); // Arrayy[1 => 'foo', 'notfoo' => 'notbar', 3 => 'bar'] |
||
| 5545 | * </code> |
||
| 5546 | * |
||
| 5547 | * @param mixed $oldKey |
||
| 5548 | * @param mixed $newKey |
||
| 5549 | * @param mixed $newValue |
||
| 5550 | * |
||
| 5551 | * @return static |
||
| 5552 | * <p>(Immutable)</p> |
||
| 5553 | * |
||
| 5554 | * @psalm-return static<TKey,T> |
||
| 5555 | * @psalm-mutation-free |
||
| 5556 | */ |
||
| 5557 | 5 | public function replace($oldKey, $newKey, $newValue): self |
|
| 5567 | |||
| 5568 | /** |
||
| 5569 | * Create an array using the current array as values and the other array as keys. |
||
| 5570 | * |
||
| 5571 | * EXAMPLE: <code> |
||
| 5572 | * $firstArray = [ |
||
| 5573 | * 1 => 'one', |
||
| 5574 | * 2 => 'two', |
||
| 5575 | * 3 => 'three', |
||
| 5576 | * ]; |
||
| 5577 | * $secondArray = [ |
||
| 5578 | * 'one' => 1, |
||
| 5579 | * 1 => 'one', |
||
| 5580 | * 2 => 2, |
||
| 5581 | * ]; |
||
| 5582 | * $arrayy = a($firstArray); |
||
| 5583 | * $arrayy->replaceAllKeys($secondArray); // Arrayy[1 => "one", 'one' => "two", 2 => "three"] |
||
| 5584 | * </code> |
||
| 5585 | * |
||
| 5586 | * @param int[]|string[] $keys <p>An array of keys.</p> |
||
| 5587 | * |
||
| 5588 | * @return static |
||
| 5589 | * <p>(Immutable) Arrayy object with keys from the other array, empty Arrayy object if the number of elements |
||
| 5590 | * for each array isn't equal or if the arrays are empty. |
||
| 5591 | * </p> |
||
| 5592 | * |
||
| 5593 | * @psalm-param array<array-key,TKey> $keys |
||
| 5594 | * @psalm-return static<TKey,T> |
||
| 5595 | * @psalm-mutation-free |
||
| 5596 | */ |
||
| 5597 | 2 | View Code Duplication | public function replaceAllKeys(array $keys): self |
| 5610 | |||
| 5611 | /** |
||
| 5612 | * Create an array using the current array as keys and the other array as values. |
||
| 5613 | * |
||
| 5614 | * EXAMPLE: <code> |
||
| 5615 | * $firstArray = [ |
||
| 5616 | * 1 => 'one', |
||
| 5617 | * 2 => 'two', |
||
| 5618 | * 3 => 'three', |
||
| 5619 | * ]; |
||
| 5620 | * $secondArray = [ |
||
| 5621 | * 'one' => 1, |
||
| 5622 | * 1 => 'one', |
||
| 5623 | * 2 => 2, |
||
| 5624 | * ]; |
||
| 5625 | * $arrayy = a($firstArray); |
||
| 5626 | * $arrayy->replaceAllValues($secondArray); // Arrayy['one' => 1, 'two' => 'one', 'three' => 2] |
||
| 5627 | * </code> |
||
| 5628 | * |
||
| 5629 | * @param array $array <p>An array of values.</p> |
||
| 5630 | * |
||
| 5631 | * @return static |
||
| 5632 | * <p>(Immutable) Arrayy object with values from the other array, empty Arrayy object if the number of elements |
||
| 5633 | * for each array isn't equal or if the arrays are empty. |
||
| 5634 | * </p> |
||
| 5635 | * |
||
| 5636 | * @psalm-param array<array-key,T> $array |
||
| 5637 | * @psalm-return static<TKey,T> |
||
| 5638 | * @psalm-mutation-free |
||
| 5639 | */ |
||
| 5640 | 2 | View Code Duplication | public function replaceAllValues(array $array): self |
| 5653 | |||
| 5654 | /** |
||
| 5655 | * Replace the keys in an array with another set. |
||
| 5656 | * |
||
| 5657 | * EXAMPLE: <code> |
||
| 5658 | * a([1 => 'bar', 'foo' => 'foo'])->replaceKeys([1 => 2, 'foo' => 'replaced']); // Arrayy[2 => 'bar', 'replaced' => 'foo'] |
||
| 5659 | * </code> |
||
| 5660 | * |
||
| 5661 | * @param array $keys <p>An array of keys matching the array's size</p> |
||
| 5662 | * |
||
| 5663 | * @return static |
||
| 5664 | * <p>(Immutable)</p> |
||
| 5665 | * |
||
| 5666 | * @psalm-param array<array-key,TKey> $keys |
||
| 5667 | * @psalm-return static<TKey,T> |
||
| 5668 | * @psalm-mutation-free |
||
| 5669 | */ |
||
| 5670 | 1 | View Code Duplication | public function replaceKeys(array $keys): self |
| 5684 | |||
| 5685 | /** |
||
| 5686 | * Replace the first matched value in an array. |
||
| 5687 | * |
||
| 5688 | * EXAMPLE: <code> |
||
| 5689 | * $testArray = ['bar', 'foo' => 'foo', 'foobar' => 'foobar']; |
||
| 5690 | * a($testArray)->replaceOneValue('foo', 'replaced'); // Arrayy['bar', 'foo' => 'replaced', 'foobar' => 'foobar'] |
||
| 5691 | * </code> |
||
| 5692 | * |
||
| 5693 | * @param mixed $search <p>The value to replace.</p> |
||
| 5694 | * @param mixed $replacement <p>The value to replace.</p> |
||
| 5695 | * |
||
| 5696 | * @return static |
||
| 5697 | * <p>(Immutable)</p> |
||
| 5698 | * |
||
| 5699 | * @psalm-return static<TKey,T> |
||
| 5700 | * @psalm-mutation-free |
||
| 5701 | */ |
||
| 5702 | 3 | public function replaceOneValue($search, $replacement = ''): self |
|
| 5717 | |||
| 5718 | /** |
||
| 5719 | * Replace values in the current array. |
||
| 5720 | * |
||
| 5721 | * EXAMPLE: <code> |
||
| 5722 | * $testArray = ['bar', 'foo' => 'foo', 'foobar' => 'foobar']; |
||
| 5723 | * a($testArray)->replaceValues('foo', 'replaced'); // Arrayy['bar', 'foo' => 'replaced', 'foobar' => 'replacedbar'] |
||
| 5724 | * </code> |
||
| 5725 | * |
||
| 5726 | * @param mixed $search <p>The value to replace.</p> |
||
| 5727 | * @param mixed $replacement <p>What to replace it with.</p> |
||
| 5728 | * |
||
| 5729 | * @return static |
||
| 5730 | * <p>(Immutable)</p> |
||
| 5731 | * |
||
| 5732 | * @psalm-return static<TKey,T> |
||
| 5733 | * @psalm-mutation-free |
||
| 5734 | */ |
||
| 5735 | 1 | public function replaceValues($search, $replacement = ''): self |
|
| 5747 | |||
| 5748 | /** |
||
| 5749 | * Get the last elements from index $from until the end of this array. |
||
| 5750 | * |
||
| 5751 | * EXAMPLE: <code> |
||
| 5752 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->rest(2); // Arrayy[0 => 'lall'] |
||
| 5753 | * </code> |
||
| 5754 | * |
||
| 5755 | * @param int $from |
||
| 5756 | * |
||
| 5757 | * @return static |
||
| 5758 | * <p>(Immutable)</p> |
||
| 5759 | * |
||
| 5760 | * @psalm-return static<TKey,T> |
||
| 5761 | * @psalm-mutation-free |
||
| 5762 | */ |
||
| 5763 | 15 | View Code Duplication | public function rest(int $from = 1): self |
| 5773 | |||
| 5774 | /** |
||
| 5775 | * Return the array in the reverse order. |
||
| 5776 | * |
||
| 5777 | * EXAMPLE: <code> |
||
| 5778 | * a([1, 2, 3])->reverse(); // self[3, 2, 1] |
||
| 5779 | * </code> |
||
| 5780 | * |
||
| 5781 | * @return $this |
||
| 5782 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 5783 | * |
||
| 5784 | * @psalm-return static<TKey,T> |
||
| 5785 | */ |
||
| 5786 | 9 | public function reverse(): self |
|
| 5794 | |||
| 5795 | /** |
||
| 5796 | * Sort an array in reverse order. |
||
| 5797 | * |
||
| 5798 | * @param int $sort_flags [optional] <p> |
||
| 5799 | * You may modify the behavior of the sort using the optional |
||
| 5800 | * parameter sort_flags, for details |
||
| 5801 | * see sort. |
||
| 5802 | * </p> |
||
| 5803 | * |
||
| 5804 | * @return $this |
||
| 5805 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 5806 | * |
||
| 5807 | * @psalm-return static<TKey,T> |
||
| 5808 | */ |
||
| 5809 | 4 | public function rsort(int $sort_flags = 0): self |
|
| 5817 | |||
| 5818 | /** |
||
| 5819 | * Sort an array in reverse order. |
||
| 5820 | * |
||
| 5821 | * @param int $sort_flags [optional] <p> |
||
| 5822 | * You may modify the behavior of the sort using the optional |
||
| 5823 | * parameter sort_flags, for details |
||
| 5824 | * see sort. |
||
| 5825 | * </p> |
||
| 5826 | * |
||
| 5827 | * @return $this |
||
| 5828 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 5829 | * |
||
| 5830 | * @psalm-return static<TKey,T> |
||
| 5831 | * @psalm-mutation-free |
||
| 5832 | */ |
||
| 5833 | 4 | public function rsortImmutable(int $sort_flags = 0): self |
|
| 5844 | |||
| 5845 | /** |
||
| 5846 | * Search for the first index of the current array via $value. |
||
| 5847 | * |
||
| 5848 | * EXAMPLE: <code> |
||
| 5849 | * a(['fòô' => 'bàř', 'lall' => 'bàř'])->searchIndex('bàř'); // Arrayy[0 => 'fòô'] |
||
| 5850 | * </code> |
||
| 5851 | * |
||
| 5852 | * @param mixed $value |
||
| 5853 | * |
||
| 5854 | * @return false|float|int|string |
||
| 5855 | * <p>Will return <b>FALSE</b> if the value can't be found.</p> |
||
| 5856 | * @psalm-mutation-free |
||
| 5857 | */ |
||
| 5858 | 21 | public function searchIndex($value) |
|
| 5868 | |||
| 5869 | /** |
||
| 5870 | * Search for the value of the current array via $index. |
||
| 5871 | * |
||
| 5872 | * EXAMPLE: <code> |
||
| 5873 | * a(['fòô' => 'bàř'])->searchValue('fòô'); // Arrayy[0 => 'bàř'] |
||
| 5874 | * </code> |
||
| 5875 | * |
||
| 5876 | * @param mixed $index |
||
| 5877 | * |
||
| 5878 | * @return static |
||
| 5879 | * <p>(Immutable) Will return a empty Arrayy if the value wasn't found.</p> |
||
| 5880 | * |
||
| 5881 | * @psalm-return static<TKey,T> |
||
| 5882 | * @psalm-mutation-free |
||
| 5883 | */ |
||
| 5884 | 9 | public function searchValue($index): self |
|
| 5914 | |||
| 5915 | /** |
||
| 5916 | * Set a value for the current array (optional using dot-notation). |
||
| 5917 | * |
||
| 5918 | * EXAMPLE: <code> |
||
| 5919 | * $arrayy = a(['Lars' => ['lastname' => 'Moelleken']]); |
||
| 5920 | * $arrayy->set('Lars.lastname', 'Müller'); // Arrayy['Lars', ['lastname' => 'Müller']]] |
||
| 5921 | * </code> |
||
| 5922 | * |
||
| 5923 | * @param string $key <p>The key to set.</p> |
||
| 5924 | * @param mixed $value <p>Its value.</p> |
||
| 5925 | * |
||
| 5926 | * @return $this |
||
| 5927 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 5928 | * |
||
| 5929 | * @psalm-param TKey $key |
||
| 5930 | * @psalm-param T $value |
||
| 5931 | * @psalm-return static<TKey,T> |
||
| 5932 | */ |
||
| 5933 | 28 | public function set($key, $value): self |
|
| 5939 | |||
| 5940 | /** |
||
| 5941 | * Get a value from a array and set it if it was not. |
||
| 5942 | * |
||
| 5943 | * WARNING: this method only set the value, if the $key is not already set |
||
| 5944 | * |
||
| 5945 | * EXAMPLE: <code> |
||
| 5946 | * $arrayy = a([1 => 1, 2 => 2, 3 => 3]); |
||
| 5947 | * $arrayy->setAndGet(1, 4); // 1 |
||
| 5948 | * $arrayy->setAndGet(0, 4); // 4 |
||
| 5949 | * </code> |
||
| 5950 | * |
||
| 5951 | * @param mixed $key <p>The key</p> |
||
| 5952 | * @param mixed $fallback <p>The default value to set if it isn't.</p> |
||
| 5953 | * |
||
| 5954 | * @return mixed |
||
| 5955 | * <p>(Mutable)</p> |
||
| 5956 | */ |
||
| 5957 | 11 | public function setAndGet($key, $fallback = null) |
|
| 5968 | |||
| 5969 | /** |
||
| 5970 | * Shifts a specified value off the beginning of array. |
||
| 5971 | * |
||
| 5972 | * @return mixed |
||
| 5973 | * <p>(Mutable) A shifted element from the current array.</p> |
||
| 5974 | */ |
||
| 5975 | 5 | public function shift() |
|
| 5981 | |||
| 5982 | /** |
||
| 5983 | * Shuffle the current array. |
||
| 5984 | * |
||
| 5985 | * EXAMPLE: <code> |
||
| 5986 | * a([1 => 'bar', 'foo' => 'foo'])->shuffle(); // e.g.: Arrayy[['foo' => 'foo', 1 => 'bar']] |
||
| 5987 | * </code> |
||
| 5988 | * |
||
| 5989 | * @param bool $secure <p>using a CSPRNG | @link https://paragonie.com/b/JvICXzh_jhLyt4y3</p> |
||
| 5990 | * @param array $array [optional] |
||
| 5991 | * |
||
| 5992 | * @return static |
||
| 5993 | * <p>(Immutable)</p> |
||
| 5994 | * |
||
| 5995 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 5996 | * @psalm-return static<TKey,T> |
||
| 5997 | * |
||
| 5998 | * @noinspection BadExceptionsProcessingInspection |
||
| 5999 | * @noinspection NonSecureShuffleUsageInspection |
||
| 6000 | */ |
||
| 6001 | 2 | public function shuffle(bool $secure = false, array $array = null): self |
|
| 6002 | { |
||
| 6003 | 2 | if ($array === null) { |
|
| 6004 | 2 | $array = $this->toArray(false); |
|
| 6005 | } |
||
| 6006 | |||
| 6007 | 2 | if ($secure !== true) { |
|
| 6008 | 2 | \shuffle($array); |
|
| 6009 | } else { |
||
| 6010 | 1 | $size = \count($array, \COUNT_NORMAL); |
|
| 6011 | 1 | $keys = \array_keys($array); |
|
| 6012 | 1 | for ($i = $size - 1; $i > 0; --$i) { |
|
| 6013 | try { |
||
| 6014 | 1 | $r = \random_int(0, $i); |
|
| 6015 | } catch (\Exception $e) { |
||
| 6016 | $r = \mt_rand(0, $i); |
||
| 6017 | } |
||
| 6018 | 1 | if ($r !== $i) { |
|
| 6019 | $temp = $array[$keys[$r]]; |
||
| 6020 | $array[$keys[$r]] = $array[$keys[$i]]; |
||
| 6021 | $array[$keys[$i]] = $temp; |
||
| 6022 | } |
||
| 6023 | } |
||
| 6024 | } |
||
| 6025 | |||
| 6026 | 2 | foreach ($array as $key => $value) { |
|
| 6027 | // check if recursive is needed |
||
| 6028 | 2 | if (\is_array($value)) { |
|
| 6029 | $array[$key] = $this->shuffle($secure, $value); |
||
| 6030 | } |
||
| 6031 | } |
||
| 6032 | |||
| 6033 | 2 | return static::create( |
|
| 6034 | 2 | $array, |
|
| 6035 | 2 | $this->iteratorClass, |
|
| 6036 | 2 | false |
|
| 6037 | ); |
||
| 6038 | } |
||
| 6039 | |||
| 6040 | /** |
||
| 6041 | * Count the values from the current array. |
||
| 6042 | * |
||
| 6043 | * alias: for "Arrayy->count()" |
||
| 6044 | * |
||
| 6045 | * @param int $mode |
||
| 6046 | * |
||
| 6047 | * @return int |
||
| 6048 | */ |
||
| 6049 | 20 | public function size(int $mode = \COUNT_NORMAL): int |
|
| 6053 | |||
| 6054 | /** |
||
| 6055 | * Checks whether array has exactly $size items. |
||
| 6056 | * |
||
| 6057 | * @param int $size |
||
| 6058 | * |
||
| 6059 | * @return bool |
||
| 6060 | */ |
||
| 6061 | 1 | public function sizeIs(int $size): bool |
|
| 6077 | |||
| 6078 | /** |
||
| 6079 | * Checks whether array has between $fromSize to $toSize items. $toSize can be |
||
| 6080 | * smaller than $fromSize. |
||
| 6081 | * |
||
| 6082 | * @param int $fromSize |
||
| 6083 | * @param int $toSize |
||
| 6084 | * |
||
| 6085 | * @return bool |
||
| 6086 | */ |
||
| 6087 | 1 | public function sizeIsBetween(int $fromSize, int $toSize): bool |
|
| 6107 | |||
| 6108 | /** |
||
| 6109 | * Checks whether array has more than $size items. |
||
| 6110 | * |
||
| 6111 | * @param int $size |
||
| 6112 | * |
||
| 6113 | * @return bool |
||
| 6114 | */ |
||
| 6115 | 1 | View Code Duplication | public function sizeIsGreaterThan(int $size): bool |
| 6129 | |||
| 6130 | /** |
||
| 6131 | * Checks whether array has less than $size items. |
||
| 6132 | * |
||
| 6133 | * @param int $size |
||
| 6134 | * |
||
| 6135 | * @return bool |
||
| 6136 | */ |
||
| 6137 | 1 | View Code Duplication | public function sizeIsLessThan(int $size): bool |
| 6151 | |||
| 6152 | /** |
||
| 6153 | * Counts all elements in an array, or something in an object. |
||
| 6154 | * |
||
| 6155 | * <p> |
||
| 6156 | * For objects, if you have SPL installed, you can hook into count() by implementing interface {@see Countable}. |
||
| 6157 | * The interface has exactly one method, {@see Countable::count()}, which returns the return value for the count() |
||
| 6158 | * function. Please see the {@see Array} section of the manual for a detailed explanation of how arrays are |
||
| 6159 | * implemented and used in PHP. |
||
| 6160 | * </p> |
||
| 6161 | * |
||
| 6162 | * @return int |
||
| 6163 | * <p> |
||
| 6164 | * The number of elements in var, which is |
||
| 6165 | * typically an array, since anything else will have one |
||
| 6166 | * element. |
||
| 6167 | * </p> |
||
| 6168 | * <p> |
||
| 6169 | * If var is not an array or an object with |
||
| 6170 | * implemented Countable interface, |
||
| 6171 | * 1 will be returned. |
||
| 6172 | * There is one exception, if var is &null;, |
||
| 6173 | * 0 will be returned. |
||
| 6174 | * </p> |
||
| 6175 | * <p> |
||
| 6176 | * Caution: count may return 0 for a variable that isn't set, |
||
| 6177 | * but it may also return 0 for a variable that has been initialized with an |
||
| 6178 | * empty array. Use isset to test if a variable is set. |
||
| 6179 | * </p> |
||
| 6180 | */ |
||
| 6181 | 10 | public function sizeRecursive(): int |
|
| 6185 | |||
| 6186 | /** |
||
| 6187 | * Extract a slice of the array. |
||
| 6188 | * |
||
| 6189 | * @param int $offset <p>Slice begin index.</p> |
||
| 6190 | * @param int|null $length <p>Length of the slice.</p> |
||
| 6191 | * @param bool $preserveKeys <p>Whether array keys are preserved or no.</p> |
||
| 6192 | * |
||
| 6193 | * @return static |
||
| 6194 | * <p>(Immutable) A slice of the original array with length $length.</p> |
||
| 6195 | * |
||
| 6196 | * @psalm-return static<TKey,T> |
||
| 6197 | * @psalm-mutation-free |
||
| 6198 | */ |
||
| 6199 | 5 | public function slice(int $offset, int $length = null, bool $preserveKeys = false) |
|
| 6212 | |||
| 6213 | /** |
||
| 6214 | * Sort the current array and optional you can keep the keys. |
||
| 6215 | * |
||
| 6216 | * EXAMPLE: <code> |
||
| 6217 | * a(3 => 'd', 2 => 'f', 0 => 'a')->sort(SORT_ASC, SORT_NATURAL, false); // Arrayy[0 => 'a', 1 => 'd', 2 => 'f'] |
||
| 6218 | * </code> |
||
| 6219 | * |
||
| 6220 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 6221 | * @param int $strategy <p>sort_flags => use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 6222 | * <strong>SORT_NATURAL</strong></p> |
||
| 6223 | * @param bool $keepKeys |
||
| 6224 | * |
||
| 6225 | * @return static |
||
| 6226 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 6227 | * |
||
| 6228 | * @psalm-return static<int|TKey,T> |
||
| 6229 | */ |
||
| 6230 | 20 | public function sort( |
|
| 6244 | |||
| 6245 | /** |
||
| 6246 | * Sort the current array and optional you can keep the keys. |
||
| 6247 | * |
||
| 6248 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 6249 | * @param int $strategy <p>sort_flags => use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 6250 | * <strong>SORT_NATURAL</strong></p> |
||
| 6251 | * @param bool $keepKeys |
||
| 6252 | * |
||
| 6253 | * @return static |
||
| 6254 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 6255 | * |
||
| 6256 | * @psalm-return static<int|TKey,T> |
||
| 6257 | */ |
||
| 6258 | 12 | public function sortImmutable( |
|
| 6274 | |||
| 6275 | /** |
||
| 6276 | * Sort the current array by key. |
||
| 6277 | * |
||
| 6278 | * EXAMPLE: <code> |
||
| 6279 | * a([1 => 2, 0 => 1])->sortKeys(\SORT_ASC); // Arrayy[0 => 1, 1 => 2] |
||
| 6280 | * </code> |
||
| 6281 | * |
||
| 6282 | * @see http://php.net/manual/en/function.ksort.php |
||
| 6283 | * @see http://php.net/manual/en/function.krsort.php |
||
| 6284 | * |
||
| 6285 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 6286 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 6287 | * <strong>SORT_NATURAL</strong></p> |
||
| 6288 | * |
||
| 6289 | * @return $this |
||
| 6290 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 6291 | * |
||
| 6292 | * @psalm-return static<TKey,T> |
||
| 6293 | */ |
||
| 6294 | 18 | public function sortKeys( |
|
| 6304 | |||
| 6305 | /** |
||
| 6306 | * Sort the current array by key. |
||
| 6307 | * |
||
| 6308 | * @see http://php.net/manual/en/function.ksort.php |
||
| 6309 | * @see http://php.net/manual/en/function.krsort.php |
||
| 6310 | * |
||
| 6311 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 6312 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 6313 | * <strong>SORT_NATURAL</strong></p> |
||
| 6314 | * |
||
| 6315 | * @return $this |
||
| 6316 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 6317 | * |
||
| 6318 | * @psalm-return static<TKey,T> |
||
| 6319 | * @psalm-mutation-free |
||
| 6320 | */ |
||
| 6321 | 8 | public function sortKeysImmutable( |
|
| 6334 | |||
| 6335 | /** |
||
| 6336 | * Sort the current array by value. |
||
| 6337 | * |
||
| 6338 | * EXAMPLE: <code> |
||
| 6339 | * a(3 => 'd', 2 => 'f', 0 => 'a')->sortValueKeepIndex(SORT_ASC, SORT_REGULAR); // Arrayy[0 => 'a', 3 => 'd', 2 => 'f'] |
||
| 6340 | * </code> |
||
| 6341 | * |
||
| 6342 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 6343 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 6344 | * <strong>SORT_NATURAL</strong></p> |
||
| 6345 | * |
||
| 6346 | * @return static |
||
| 6347 | * <p>(Mutable)</p> |
||
| 6348 | * |
||
| 6349 | * @psalm-return static<TKey,T> |
||
| 6350 | */ |
||
| 6351 | 1 | public function sortValueKeepIndex( |
|
| 6357 | |||
| 6358 | /** |
||
| 6359 | * Sort the current array by value. |
||
| 6360 | * |
||
| 6361 | * EXAMPLE: <code> |
||
| 6362 | * a(3 => 'd', 2 => 'f', 0 => 'a')->sortValueNewIndex(SORT_ASC, SORT_NATURAL); // Arrayy[0 => 'a', 1 => 'd', 2 => 'f'] |
||
| 6363 | * </code> |
||
| 6364 | * |
||
| 6365 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 6366 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 6367 | * <strong>SORT_NATURAL</strong></p> |
||
| 6368 | * |
||
| 6369 | * @return static |
||
| 6370 | * <p>(Mutable)</p> |
||
| 6371 | * |
||
| 6372 | * @psalm-return static<int,T> |
||
| 6373 | */ |
||
| 6374 | 1 | public function sortValueNewIndex($direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
| 6378 | |||
| 6379 | /** |
||
| 6380 | * Sort a array by value or by a closure. |
||
| 6381 | * |
||
| 6382 | * - If the sorter is null, the array is sorted naturally. |
||
| 6383 | * - Associative (string) keys will be maintained, but numeric keys will be re-indexed. |
||
| 6384 | * |
||
| 6385 | * EXAMPLE: <code> |
||
| 6386 | * $testArray = range(1, 5); |
||
| 6387 | * $under = a($testArray)->sorter( |
||
| 6388 | * function ($value) { |
||
| 6389 | * return $value % 2 === 0; |
||
| 6390 | * } |
||
| 6391 | * ); |
||
| 6392 | * var_dump($under); // Arrayy[1, 3, 5, 2, 4] |
||
| 6393 | * </code> |
||
| 6394 | * |
||
| 6395 | * @param callable|mixed|null $sorter |
||
| 6396 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or |
||
| 6397 | * <strong>SORT_DESC</strong></p> |
||
| 6398 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 6399 | * <strong>SORT_NATURAL</strong></p> |
||
| 6400 | * |
||
| 6401 | * @return static |
||
| 6402 | * <p>(Immutable)</p> |
||
| 6403 | * |
||
| 6404 | * @pslam-param callable|T|null $sorter |
||
| 6405 | * @psalm-return static<TKey,T> |
||
| 6406 | * @psalm-mutation-free |
||
| 6407 | */ |
||
| 6408 | 1 | public function sorter($sorter = null, $direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
| 6449 | |||
| 6450 | /** |
||
| 6451 | * @param int $offset |
||
| 6452 | * @param int|null $length |
||
| 6453 | * @param array $replacement |
||
| 6454 | * |
||
| 6455 | * @return static |
||
| 6456 | * <p>(Immutable)</p> |
||
| 6457 | * |
||
| 6458 | * @psalm-param array<mixed,mixed>|array<mixed,T> $replacement |
||
| 6459 | * @psalm-return static<TKey,T> |
||
| 6460 | * @psalm-mutation-free |
||
| 6461 | */ |
||
| 6462 | 1 | public function splice(int $offset, int $length = null, $replacement = []): self |
|
| 6479 | |||
| 6480 | /** |
||
| 6481 | * Split an array in the given amount of pieces. |
||
| 6482 | * |
||
| 6483 | * EXAMPLE: <code> |
||
| 6484 | * a(['a' => 1, 'b' => 2])->split(2, true); // Arrayy[['a' => 1], ['b' => 2]] |
||
| 6485 | * </code> |
||
| 6486 | * |
||
| 6487 | * @param int $numberOfPieces |
||
| 6488 | * @param bool $keepKeys |
||
| 6489 | * |
||
| 6490 | * @return static |
||
| 6491 | * <p>(Immutable)</p> |
||
| 6492 | * |
||
| 6493 | * @psalm-return static<TKey,T> |
||
| 6494 | * @psalm-mutation-free |
||
| 6495 | */ |
||
| 6496 | 1 | public function split(int $numberOfPieces = 2, bool $keepKeys = false): self |
|
| 6552 | |||
| 6553 | /** |
||
| 6554 | * Strip all empty items from the current array. |
||
| 6555 | * |
||
| 6556 | * EXAMPLE: <code> |
||
| 6557 | * a(['a' => 1, 'b' => ''])->stripEmpty(); // Arrayy[['a' => 1]] |
||
| 6558 | * </code> |
||
| 6559 | * |
||
| 6560 | * @return static |
||
| 6561 | * <p>(Immutable)</p> |
||
| 6562 | * |
||
| 6563 | * @psalm-return static<TKey,T> |
||
| 6564 | * @psalm-mutation-free |
||
| 6565 | */ |
||
| 6566 | 1 | public function stripEmpty(): self |
|
| 6578 | |||
| 6579 | /** |
||
| 6580 | * Swap two values between positions by key. |
||
| 6581 | * |
||
| 6582 | * EXAMPLE: <code> |
||
| 6583 | * a(['a' => 1, 'b' => ''])->swap('a', 'b'); // Arrayy[['a' => '', 'b' => 1]] |
||
| 6584 | * </code> |
||
| 6585 | * |
||
| 6586 | * @param int|string $swapA <p>a key in the array</p> |
||
| 6587 | * @param int|string $swapB <p>a key in the array</p> |
||
| 6588 | * |
||
| 6589 | * @return static |
||
| 6590 | * <p>(Immutable)</p> |
||
| 6591 | * |
||
| 6592 | * @psalm-return static<TKey,T> |
||
| 6593 | * @psalm-mutation-free |
||
| 6594 | */ |
||
| 6595 | 1 | public function swap($swapA, $swapB): self |
|
| 6607 | |||
| 6608 | /** |
||
| 6609 | * Get the current array from the "Arrayy"-object. |
||
| 6610 | * alias for "getArray()" |
||
| 6611 | * |
||
| 6612 | * @param bool $convertAllArrayyElements <p> |
||
| 6613 | * Convert all Child-"Arrayy" objects also to arrays. |
||
| 6614 | * </p> |
||
| 6615 | * @param bool $preserveKeys <p> |
||
| 6616 | * e.g.: A generator maybe return the same key more then once, |
||
| 6617 | * so maybe you will ignore the keys. |
||
| 6618 | * </p> |
||
| 6619 | * |
||
| 6620 | * @return array |
||
| 6621 | * |
||
| 6622 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 6623 | * @psalm-mutation-free |
||
| 6624 | */ |
||
| 6625 | 941 | public function toArray( |
|
| 6653 | |||
| 6654 | /** |
||
| 6655 | * Get the current array from the "Arrayy"-object as list. |
||
| 6656 | * |
||
| 6657 | * @param bool $convertAllArrayyElements <p> |
||
| 6658 | * Convert all Child-"Arrayy" objects also to arrays. |
||
| 6659 | * </p> |
||
| 6660 | * |
||
| 6661 | * @return array |
||
| 6662 | * |
||
| 6663 | * @psalm-return list<array<TKey,T>> |
||
| 6664 | * @psalm-mutation-free |
||
| 6665 | */ |
||
| 6666 | 1 | public function toList(bool $convertAllArrayyElements = false): array |
|
| 6673 | |||
| 6674 | /** |
||
| 6675 | * Convert the current array to JSON. |
||
| 6676 | * |
||
| 6677 | * EXAMPLE: <code> |
||
| 6678 | * a(['bar', ['foo']])->toJson(); // '["bar",{"1":"foo"}]' |
||
| 6679 | * </code> |
||
| 6680 | * |
||
| 6681 | * @param int $options [optional] <p>e.g. JSON_PRETTY_PRINT</p> |
||
| 6682 | * @param int $depth [optional] <p>Set the maximum depth. Must be greater than zero.</p> |
||
| 6683 | * |
||
| 6684 | * @return string |
||
| 6685 | */ |
||
| 6686 | 12 | public function toJson(int $options = 0, int $depth = 512): string |
|
| 6695 | |||
| 6696 | /** |
||
| 6697 | * @param string[]|null $items [optional] |
||
| 6698 | * @param string[] $helper [optional] |
||
| 6699 | * |
||
| 6700 | * @return static|static[] |
||
| 6701 | * |
||
| 6702 | * @psalm-return static<int, static<TKey,T>> |
||
| 6703 | */ |
||
| 6704 | 1 | public function toPermutation(array $items = null, array $helper = []): self |
|
| 6737 | |||
| 6738 | /** |
||
| 6739 | * Implodes array to a string with specified separator. |
||
| 6740 | * |
||
| 6741 | * @param string $separator [optional] <p>The element's separator.</p> |
||
| 6742 | * |
||
| 6743 | * @return string |
||
| 6744 | * <p>The string representation of array, separated by ",".</p> |
||
| 6745 | */ |
||
| 6746 | 19 | public function toString(string $separator = ','): string |
|
| 6750 | |||
| 6751 | /** |
||
| 6752 | * Return a duplicate free copy of the current array. |
||
| 6753 | * |
||
| 6754 | * EXAMPLE: <code> |
||
| 6755 | * a([2 => 1, 3 => 2, 4 => 2])->uniqueNewIndex(); // Arrayy[1, 2] |
||
| 6756 | * </code> |
||
| 6757 | * |
||
| 6758 | * @return $this |
||
| 6759 | * <p>(Mutable)</p> |
||
| 6760 | * |
||
| 6761 | * @psalm-return static<int,T> |
||
| 6762 | */ |
||
| 6763 | 13 | public function uniqueNewIndex(): self |
|
| 6785 | |||
| 6786 | /** |
||
| 6787 | * Return a duplicate free copy of the current array. (with the old keys) |
||
| 6788 | * |
||
| 6789 | * EXAMPLE: <code> |
||
| 6790 | * a([2 => 1, 3 => 2, 4 => 2])->uniqueNewIndex(); // Arrayy[2 => 1, 3 => 2] |
||
| 6791 | * </code> |
||
| 6792 | * |
||
| 6793 | * @return $this |
||
| 6794 | * <p>(Mutable)</p> |
||
| 6795 | * |
||
| 6796 | * @psalm-return static<TKey,T> |
||
| 6797 | */ |
||
| 6798 | 11 | public function uniqueKeepIndex(): self |
|
| 6824 | |||
| 6825 | /** |
||
| 6826 | * alias: for "Arrayy->uniqueNewIndex()" |
||
| 6827 | * |
||
| 6828 | * @return static |
||
| 6829 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
| 6830 | * |
||
| 6831 | * @see Arrayy::unique() |
||
| 6832 | * |
||
| 6833 | * @psalm-return static<int,T> |
||
| 6834 | */ |
||
| 6835 | 13 | public function unique(): self |
|
| 6839 | |||
| 6840 | /** |
||
| 6841 | * Prepends one or more values to the beginning of array at once. |
||
| 6842 | * |
||
| 6843 | * @param mixed ...$args |
||
| 6844 | * |
||
| 6845 | * @return $this |
||
| 6846 | * <p>(Mutable) Return this Arrayy object, with prepended elements to the beginning of array.</p> |
||
| 6847 | * |
||
| 6848 | * @psalm-param array<TKey,T> ...$args |
||
| 6849 | * @psalm-return static<TKey,T> |
||
| 6850 | */ |
||
| 6851 | 6 | View Code Duplication | public function unshift(...$args): self |
| 6869 | |||
| 6870 | /** |
||
| 6871 | * Tests whether the given closure return something valid for all elements of this array. |
||
| 6872 | * |
||
| 6873 | * @param \Closure $closure the predicate |
||
| 6874 | * |
||
| 6875 | * @return bool |
||
| 6876 | * <p>TRUE, if the predicate yields TRUE for all elements, FALSE otherwise.</p> |
||
| 6877 | */ |
||
| 6878 | 1 | View Code Duplication | public function validate(\Closure $closure): bool |
| 6888 | |||
| 6889 | /** |
||
| 6890 | * Get all values from a array. |
||
| 6891 | * |
||
| 6892 | * EXAMPLE: <code> |
||
| 6893 | * $arrayy = a([1 => 'foo', 2 => 'foo2', 3 => 'bar']); |
||
| 6894 | * $arrayyTmp->values(); // Arrayy[0 => 'foo', 1 => 'foo2', 2 => 'bar'] |
||
| 6895 | * </code> |
||
| 6896 | * |
||
| 6897 | * @return static |
||
| 6898 | * <p>(Immutable)</p> |
||
| 6899 | * |
||
| 6900 | * @psalm-return static<TKey,T> |
||
| 6901 | * @psalm-mutation-free |
||
| 6902 | */ |
||
| 6903 | 2 | public function values(): self |
|
| 6916 | |||
| 6917 | /** |
||
| 6918 | * Apply the given function to every element in the array, discarding the results. |
||
| 6919 | * |
||
| 6920 | * EXAMPLE: <code> |
||
| 6921 | * $callable = function (&$value, $key) { |
||
| 6922 | * $value = $key; |
||
| 6923 | * }; |
||
| 6924 | * $arrayy = a([1, 2, 3]); |
||
| 6925 | * $arrayy->walk($callable); // Arrayy[0, 1, 2] |
||
| 6926 | * </code> |
||
| 6927 | * |
||
| 6928 | * @param callable $callable |
||
| 6929 | * @param bool $recursive [optional] <p>Whether array will be walked recursively or no</p> |
||
| 6930 | * @param mixed $userData [optional] <p> |
||
| 6931 | * If the optional $userData parameter is supplied, |
||
| 6932 | * it will be passed as the third parameter to the $callable. |
||
| 6933 | * </p> |
||
| 6934 | * |
||
| 6935 | * @return $this |
||
| 6936 | * <p>(Mutable) Return this Arrayy object, with modified elements.</p> |
||
| 6937 | * |
||
| 6938 | * @psalm-return static<TKey,T> |
||
| 6939 | */ |
||
| 6940 | 12 | public function walk( |
|
| 6966 | |||
| 6967 | /** |
||
| 6968 | * Returns a collection of matching items. |
||
| 6969 | * |
||
| 6970 | * @param string $keyOrPropertyOrMethod the property or method to evaluate |
||
| 6971 | * @param mixed $value the value to match |
||
| 6972 | * |
||
| 6973 | * @throws \InvalidArgumentException if property or method is not defined |
||
| 6974 | * |
||
| 6975 | * @return static |
||
| 6976 | * |
||
| 6977 | * @psalm-return static<TKey,T> |
||
| 6978 | */ |
||
| 6979 | 1 | public function where(string $keyOrPropertyOrMethod, $value): self |
|
| 6992 | |||
| 6993 | /** |
||
| 6994 | * Convert an array into a object. |
||
| 6995 | * |
||
| 6996 | * @param array $array |
||
| 6997 | * |
||
| 6998 | * @return \stdClass |
||
| 6999 | * |
||
| 7000 | * @psalm-param array<mixed,mixed> $array |
||
| 7001 | */ |
||
| 7002 | 4 | final protected static function arrayToObject(array $array = []): \stdClass |
|
| 7021 | |||
| 7022 | /** |
||
| 7023 | * @param array|\Generator|null $input <p> |
||
| 7024 | * An array containing keys to return. |
||
| 7025 | * </p> |
||
| 7026 | * @param mixed|null $search_values [optional] <p> |
||
| 7027 | * If specified, then only keys containing these values are returned. |
||
| 7028 | * </p> |
||
| 7029 | * @param bool $strict [optional] <p> |
||
| 7030 | * Determines if strict comparison (===) should be used during the |
||
| 7031 | * search. |
||
| 7032 | * </p> |
||
| 7033 | * |
||
| 7034 | * @return array |
||
| 7035 | * <p>an array of all the keys in input</p> |
||
| 7036 | * |
||
| 7037 | * @psalm-param array<mixed,mixed>|\Generator<TKey,T>|null $input |
||
| 7038 | * @psalm-return array<TKey|mixed> |
||
| 7039 | * @psalm-mutation-free |
||
| 7040 | */ |
||
| 7041 | 11 | protected function array_keys_recursive( |
|
| 7102 | |||
| 7103 | /** |
||
| 7104 | * @param mixed $path |
||
| 7105 | * @param callable $callable |
||
| 7106 | * @param array|null $currentOffset |
||
| 7107 | * |
||
| 7108 | * @return void |
||
| 7109 | * |
||
| 7110 | * @psalm-param array<mixed,mixed>|array<TKey,T>|null $currentOffset |
||
| 7111 | * @psalm-mutation-free |
||
| 7112 | */ |
||
| 7113 | 10 | protected function callAtPath($path, $callable, &$currentOffset = null) |
|
| 7142 | |||
| 7143 | /** |
||
| 7144 | * Extracts the value of the given property or method from the object. |
||
| 7145 | * |
||
| 7146 | * @param static $object <p>The object to extract the value from.</p> |
||
| 7147 | * @param string $keyOrPropertyOrMethod <p>The property or method for which the |
||
| 7148 | * value should be extracted.</p> |
||
| 7149 | * |
||
| 7150 | * @throws \InvalidArgumentException if the method or property is not defined |
||
| 7151 | * |
||
| 7152 | * @return mixed |
||
| 7153 | * <p>The value extracted from the specified property or method.</p> |
||
| 7154 | * |
||
| 7155 | * @psalm-param self<TKey,T> $object |
||
| 7156 | */ |
||
| 7157 | 1 | final protected function extractValue(self $object, string $keyOrPropertyOrMethod) |
|
| 7179 | |||
| 7180 | /** |
||
| 7181 | * create a fallback for array |
||
| 7182 | * |
||
| 7183 | * 1. use the current array, if it's a array |
||
| 7184 | * 2. fallback to empty array, if there is nothing |
||
| 7185 | * 3. call "getArray()" on object, if there is a "Arrayy"-object |
||
| 7186 | * 4. call "createFromObject()" on object, if there is a "\Traversable"-object |
||
| 7187 | * 5. call "__toArray()" on object, if the method exists |
||
| 7188 | * 6. cast a string or object with "__toString()" into an array |
||
| 7189 | * 7. throw a "InvalidArgumentException"-Exception |
||
| 7190 | * |
||
| 7191 | * @param mixed $data |
||
| 7192 | * |
||
| 7193 | * @throws \InvalidArgumentException |
||
| 7194 | * |
||
| 7195 | * @return array |
||
| 7196 | * |
||
| 7197 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 7198 | */ |
||
| 7199 | 1212 | protected function fallbackForArray(&$data): array |
|
| 7209 | |||
| 7210 | /** |
||
| 7211 | * @param bool $preserveKeys <p> |
||
| 7212 | * e.g.: A generator maybe return the same key more then once, |
||
| 7213 | * so maybe you will ignore the keys. |
||
| 7214 | * </p> |
||
| 7215 | * |
||
| 7216 | * @return bool |
||
| 7217 | * |
||
| 7218 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
| 7219 | * @psalm-mutation-free :/ |
||
| 7220 | */ |
||
| 7221 | 1121 | protected function generatorToArray(bool $preserveKeys = true) |
|
| 7232 | |||
| 7233 | /** |
||
| 7234 | * Get correct PHP constant for direction. |
||
| 7235 | * |
||
| 7236 | * @param int|string $direction |
||
| 7237 | * |
||
| 7238 | * @return int |
||
| 7239 | * @psalm-mutation-free |
||
| 7240 | */ |
||
| 7241 | 43 | protected function getDirection($direction): int |
|
| 7263 | |||
| 7264 | /** |
||
| 7265 | * @return TypeCheckInterface[] |
||
| 7266 | * |
||
| 7267 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
| 7268 | */ |
||
| 7269 | 24 | protected function getPropertiesFromPhpDoc() |
|
| 7324 | |||
| 7325 | /** |
||
| 7326 | * @param mixed $glue |
||
| 7327 | * @param mixed $pieces |
||
| 7328 | * @param bool $useKeys |
||
| 7329 | * |
||
| 7330 | * @return string |
||
| 7331 | * @psalm-mutation-free |
||
| 7332 | */ |
||
| 7333 | 36 | protected function implode_recursive( |
|
| 7366 | |||
| 7367 | /** |
||
| 7368 | * @param mixed $needle <p> |
||
| 7369 | * The searched value. |
||
| 7370 | * </p> |
||
| 7371 | * <p> |
||
| 7372 | * If needle is a string, the comparison is done |
||
| 7373 | * in a case-sensitive manner. |
||
| 7374 | * </p> |
||
| 7375 | * @param array|\Generator|null $haystack <p> |
||
| 7376 | * The array. |
||
| 7377 | * </p> |
||
| 7378 | * @param bool $strict [optional] <p> |
||
| 7379 | * If the third parameter strict is set to true |
||
| 7380 | * then the in_array function will also check the |
||
| 7381 | * types of the |
||
| 7382 | * needle in the haystack. |
||
| 7383 | * </p> |
||
| 7384 | * |
||
| 7385 | * @return bool |
||
| 7386 | * <p>true if needle is found in the array, false otherwise</p> |
||
| 7387 | * |
||
| 7388 | * @psalm-param array<mixed,mixed>|\Generator<TKey,T>|null $haystack |
||
| 7389 | * @psalm-mutation-free |
||
| 7390 | */ |
||
| 7391 | 18 | protected function in_array_recursive($needle, $haystack = null, $strict = true): bool |
|
| 7416 | |||
| 7417 | /** |
||
| 7418 | * @param mixed $data |
||
| 7419 | * |
||
| 7420 | * @return array|null |
||
| 7421 | * |
||
| 7422 | * @psalm-return array<mixed,mixed>|array<TKey,T>|null |
||
| 7423 | */ |
||
| 7424 | 1212 | protected function internalGetArray(&$data) |
|
| 7475 | |||
| 7476 | /** |
||
| 7477 | * Internal mechanics of remove method. |
||
| 7478 | * |
||
| 7479 | * @param mixed $key |
||
| 7480 | * |
||
| 7481 | * @return bool |
||
| 7482 | */ |
||
| 7483 | 22 | protected function internalRemove($key): bool |
|
| 7516 | |||
| 7517 | /** |
||
| 7518 | * Internal mechanic of set method. |
||
| 7519 | * |
||
| 7520 | * @param int|string|null $key |
||
| 7521 | * @param mixed $value |
||
| 7522 | * @param bool $checkProperties |
||
| 7523 | * |
||
| 7524 | * @return bool |
||
| 7525 | */ |
||
| 7526 | 1062 | protected function internalSet( |
|
| 7585 | |||
| 7586 | /** |
||
| 7587 | * Convert a object into an array. |
||
| 7588 | * |
||
| 7589 | * @param mixed|object $object |
||
| 7590 | * |
||
| 7591 | * @return array|mixed |
||
| 7592 | * |
||
| 7593 | * @psalm-mutation-free |
||
| 7594 | */ |
||
| 7595 | 5 | protected static function objectToArray($object) |
|
| 7608 | |||
| 7609 | /** |
||
| 7610 | * @param array $data |
||
| 7611 | * @param bool $checkPropertiesInConstructor |
||
| 7612 | * |
||
| 7613 | * @return void |
||
| 7614 | * |
||
| 7615 | * @psalm-param array<mixed,T> $data |
||
| 7616 | */ |
||
| 7617 | 1210 | protected function setInitialValuesAndProperties(array &$data, bool $checkPropertiesInConstructor) |
|
| 7662 | |||
| 7663 | /** |
||
| 7664 | * sorting keys |
||
| 7665 | * |
||
| 7666 | * @param array $elements |
||
| 7667 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 7668 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 7669 | * <strong>SORT_NATURAL</strong></p> |
||
| 7670 | * |
||
| 7671 | * @return $this |
||
| 7672 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 7673 | * |
||
| 7674 | * @psalm-param array<mixed,mixed>|array<mixed|TKey,T> $elements |
||
| 7675 | * @psalm-return static<TKey,T> |
||
| 7676 | */ |
||
| 7677 | 18 | protected function sorterKeys( |
|
| 7698 | |||
| 7699 | /** |
||
| 7700 | * @param array $elements <p>Warning: used as reference</p> |
||
| 7701 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 7702 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 7703 | * <strong>SORT_NATURAL</strong></p> |
||
| 7704 | * @param bool $keepKeys |
||
| 7705 | * |
||
| 7706 | * @return $this |
||
| 7707 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 7708 | * |
||
| 7709 | * @psalm-param array<mixed,mixed>|array<mixed|TKey,T> $elements |
||
| 7710 | * @psalm-return static<int|TKey,T> |
||
| 7711 | */ |
||
| 7712 | 24 | protected function sorting( |
|
| 7746 | |||
| 7747 | /** |
||
| 7748 | * @param array $array |
||
| 7749 | * |
||
| 7750 | * @return array |
||
| 7751 | * |
||
| 7752 | * @psalm-mutation-free |
||
| 7753 | */ |
||
| 7754 | 25 | private function getArrayRecursiveHelperArrayy(array $array) |
|
| 7776 | |||
| 7777 | /** |
||
| 7778 | * @param int|string|null $key |
||
| 7779 | * @param mixed $value |
||
| 7780 | * |
||
| 7781 | * @return void |
||
| 7782 | */ |
||
| 7783 | 117 | private function checkType($key, $value) |
|
| 7801 | } |
||
| 7802 |
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..