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 | 51 | 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) |
|
| 218 | |||
| 219 | /** |
||
| 220 | * Add new values (optional using dot-notation). |
||
| 221 | * |
||
| 222 | * @param mixed $value |
||
| 223 | * @param int|string|null $key |
||
| 224 | * |
||
| 225 | * @return static |
||
| 226 | * <p>(Immutable) Return this Arrayy object, with the appended values.</p> |
||
| 227 | * |
||
| 228 | * @psalm-param T $value |
||
| 229 | * @psalm-return static<TKey,T> |
||
| 230 | * |
||
| 231 | * @psalm-mutation-free |
||
| 232 | */ |
||
| 233 | 13 | public function add($value, $key = null) |
|
| 251 | |||
| 252 | /** |
||
| 253 | * Append a (key) + value to the current array. |
||
| 254 | * |
||
| 255 | * EXAMPLE: <code> |
||
| 256 | * a(['fòô' => 'bàř'])->append('foo'); // Arrayy['fòô' => 'bàř', 0 => 'foo'] |
||
| 257 | * </code> |
||
| 258 | * |
||
| 259 | * @param mixed $value |
||
| 260 | * @param mixed $key |
||
| 261 | * |
||
| 262 | * @return $this |
||
| 263 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
| 264 | * |
||
| 265 | * @psalm-return static<TKey,T> |
||
| 266 | */ |
||
| 267 | 20 | public function append($value, $key = null): self |
|
| 291 | |||
| 292 | /** |
||
| 293 | * Append a (key) + value to the current array. |
||
| 294 | * |
||
| 295 | * EXAMPLE: <code> |
||
| 296 | * a(['fòô' => 'bàř'])->appendImmutable('foo')->getArray(); // ['fòô' => 'bàř', 0 => 'foo'] |
||
| 297 | * </code> |
||
| 298 | * |
||
| 299 | * @param mixed $value |
||
| 300 | * @param mixed $key |
||
| 301 | * |
||
| 302 | * @return $this |
||
| 303 | * <p>(Immutable) Return this Arrayy object, with the appended values.</p> |
||
| 304 | * |
||
| 305 | * @psalm-return static<TKey,T> |
||
| 306 | * @psalm-mutation-free |
||
| 307 | */ |
||
| 308 | 1 | View Code Duplication | public function appendImmutable($value, $key = null): self |
| 333 | |||
| 334 | /** |
||
| 335 | * Sort the entries by value. |
||
| 336 | * |
||
| 337 | * @param int $sort_flags [optional] <p> |
||
| 338 | * You may modify the behavior of the sort using the optional |
||
| 339 | * parameter sort_flags, for details |
||
| 340 | * see sort. |
||
| 341 | * </p> |
||
| 342 | * |
||
| 343 | * @return $this |
||
| 344 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 345 | * |
||
| 346 | * @psalm-return static<TKey,T> |
||
| 347 | */ |
||
| 348 | 4 | public function asort(int $sort_flags = 0): self |
|
| 356 | |||
| 357 | /** |
||
| 358 | * Sort the entries by value. |
||
| 359 | * |
||
| 360 | * @param int $sort_flags [optional] <p> |
||
| 361 | * You may modify the behavior of the sort using the optional |
||
| 362 | * parameter sort_flags, for details |
||
| 363 | * see sort. |
||
| 364 | * </p> |
||
| 365 | * |
||
| 366 | * @return $this |
||
| 367 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 368 | * |
||
| 369 | * @psalm-return static<TKey,T> |
||
| 370 | * @psalm-mutation-free |
||
| 371 | */ |
||
| 372 | 4 | public function asortImmutable(int $sort_flags = 0): self |
|
| 383 | |||
| 384 | /** |
||
| 385 | * Counts all elements in an array, or something in an object. |
||
| 386 | * |
||
| 387 | * EXAMPLE: <code> |
||
| 388 | * a([-9, -8, -7, 1.32])->count(); // 4 |
||
| 389 | * </code> |
||
| 390 | * |
||
| 391 | * <p> |
||
| 392 | * For objects, if you have SPL installed, you can hook into count() by implementing interface {@see Countable}. |
||
| 393 | * The interface has exactly one method, {@see Countable::count()}, which returns the return value for the count() |
||
| 394 | * function. Please see the {@see Array} section of the manual for a detailed explanation of how arrays are |
||
| 395 | * implemented and used in PHP. |
||
| 396 | * </p> |
||
| 397 | * |
||
| 398 | * @see http://php.net/manual/en/function.count.php |
||
| 399 | * |
||
| 400 | * @param int $mode [optional] If the optional mode parameter is set to |
||
| 401 | * COUNT_RECURSIVE (or 1), count |
||
| 402 | * will recursively count the array. This is particularly useful for |
||
| 403 | * counting all the elements of a multidimensional array. count does not detect infinite recursion. |
||
| 404 | * |
||
| 405 | * @return int |
||
| 406 | * <p> |
||
| 407 | * The number of elements in var, which is |
||
| 408 | * typically an array, since anything else will have one |
||
| 409 | * element. |
||
| 410 | * </p> |
||
| 411 | * <p> |
||
| 412 | * If var is not an array or an object with |
||
| 413 | * implemented Countable interface, |
||
| 414 | * 1 will be returned. |
||
| 415 | * There is one exception, if var is &null;, |
||
| 416 | * 0 will be returned. |
||
| 417 | * </p> |
||
| 418 | * <p> |
||
| 419 | * Caution: count may return 0 for a variable that isn't set, |
||
| 420 | * but it may also return 0 for a variable that has been initialized with an |
||
| 421 | * empty array. Use isset to test if a variable is set. |
||
| 422 | * </p> |
||
| 423 | * @psalm-mutation-free |
||
| 424 | */ |
||
| 425 | 147 | public function count(int $mode = \COUNT_NORMAL): int |
|
| 437 | |||
| 438 | /** |
||
| 439 | * Exchange the array for another one. |
||
| 440 | * |
||
| 441 | * @param array|mixed|static $data |
||
| 442 | * |
||
| 443 | * 1. use the current array, if it's a array |
||
| 444 | * 2. fallback to empty array, if there is nothing |
||
| 445 | * 3. call "getArray()" on object, if there is a "Arrayy"-object |
||
| 446 | * 4. call "createFromObject()" on object, if there is a "\Traversable"-object |
||
| 447 | * 5. call "__toArray()" on object, if the method exists |
||
| 448 | * 6. cast a string or object with "__toString()" into an array |
||
| 449 | * 7. throw a "InvalidArgumentException"-Exception |
||
| 450 | * |
||
| 451 | * @return array |
||
| 452 | * |
||
| 453 | * @psalm-param T,array<TKey,T>|self<TKey,T> $data |
||
| 454 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 455 | */ |
||
| 456 | 1 | public function exchangeArray($data): array |
|
| 462 | |||
| 463 | /** |
||
| 464 | * Creates a copy of the ArrayyObject. |
||
| 465 | * |
||
| 466 | * @return array |
||
| 467 | * |
||
| 468 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 469 | */ |
||
| 470 | 6 | public function getArrayCopy(): array |
|
| 476 | |||
| 477 | /** |
||
| 478 | * Returns a new iterator, thus implementing the \Iterator interface. |
||
| 479 | * |
||
| 480 | * EXAMPLE: <code> |
||
| 481 | * a(['foo', 'bar'])->getIterator(); // ArrayyIterator['foo', 'bar'] |
||
| 482 | * </code> |
||
| 483 | * |
||
| 484 | * @return \Iterator<mixed, mixed> |
||
| 485 | * <p>An iterator for the values in the array.</p> |
||
| 486 | * @psalm-return \Iterator<array-key|TKey, mixed|T> |
||
| 487 | */ |
||
| 488 | 28 | public function getIterator(): \Iterator |
|
| 505 | |||
| 506 | /** |
||
| 507 | * Gets the iterator classname for the ArrayObject. |
||
| 508 | * |
||
| 509 | * @return string |
||
| 510 | * |
||
| 511 | * @psalm-return class-string |
||
| 512 | */ |
||
| 513 | 27 | public function getIteratorClass(): string |
|
| 517 | |||
| 518 | /** |
||
| 519 | * Sort the entries by key. |
||
| 520 | * |
||
| 521 | * @param int $sort_flags [optional] <p> |
||
| 522 | * You may modify the behavior of the sort using the optional |
||
| 523 | * parameter sort_flags, for details |
||
| 524 | * see sort. |
||
| 525 | * </p> |
||
| 526 | * |
||
| 527 | * @return $this |
||
| 528 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 529 | * |
||
| 530 | * @psalm-return static<TKey,T> |
||
| 531 | */ |
||
| 532 | 4 | public function ksort(int $sort_flags = 0): self |
|
| 540 | |||
| 541 | /** |
||
| 542 | * Sort the entries by key. |
||
| 543 | * |
||
| 544 | * @param int $sort_flags [optional] <p> |
||
| 545 | * You may modify the behavior of the sort using the optional |
||
| 546 | * parameter sort_flags, for details |
||
| 547 | * see sort. |
||
| 548 | * </p> |
||
| 549 | * |
||
| 550 | * @return $this |
||
| 551 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 552 | * |
||
| 553 | * @psalm-return static<TKey,T> |
||
| 554 | */ |
||
| 555 | 4 | public function ksortImmutable(int $sort_flags = 0): self |
|
| 566 | |||
| 567 | /** |
||
| 568 | * Sort an array using a case insensitive "natural order" algorithm. |
||
| 569 | * |
||
| 570 | * @return $this |
||
| 571 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 572 | * |
||
| 573 | * @psalm-return static<TKey,T> |
||
| 574 | */ |
||
| 575 | 8 | public function natcasesort(): self |
|
| 583 | |||
| 584 | /** |
||
| 585 | * Sort an array using a case insensitive "natural order" algorithm. |
||
| 586 | * |
||
| 587 | * @return $this |
||
| 588 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 589 | * |
||
| 590 | * @psalm-return static<TKey,T> |
||
| 591 | * @psalm-mutation-free |
||
| 592 | */ |
||
| 593 | 4 | public function natcasesortImmutable(): self |
|
| 604 | |||
| 605 | /** |
||
| 606 | * Sort entries using a "natural order" algorithm. |
||
| 607 | * |
||
| 608 | * @return $this |
||
| 609 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 610 | * |
||
| 611 | * @psalm-return static<TKey,T> |
||
| 612 | */ |
||
| 613 | 10 | public function natsort(): self |
|
| 621 | |||
| 622 | /** |
||
| 623 | * Sort entries using a "natural order" algorithm. |
||
| 624 | * |
||
| 625 | * @return $this |
||
| 626 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 627 | * |
||
| 628 | * @psalm-return static<TKey,T> |
||
| 629 | * @psalm-mutation-free |
||
| 630 | */ |
||
| 631 | 4 | public function natsortImmutable(): self |
|
| 642 | |||
| 643 | /** |
||
| 644 | * Whether or not an offset exists. |
||
| 645 | * |
||
| 646 | * @param bool|int|string $offset |
||
| 647 | * |
||
| 648 | * @return bool |
||
| 649 | * |
||
| 650 | * @noinspection PhpSillyAssignmentInspection |
||
| 651 | * |
||
| 652 | * @psalm-mutation-free |
||
| 653 | */ |
||
| 654 | 164 | public function offsetExists($offset): bool |
|
| 701 | |||
| 702 | /** |
||
| 703 | * Returns the value at specified offset. |
||
| 704 | * |
||
| 705 | * @param int|string $offset |
||
| 706 | * |
||
| 707 | * @return mixed |
||
| 708 | * <p>Will return null if the offset did not exists.</p> |
||
| 709 | */ |
||
| 710 | 133 | public function &offsetGet($offset) |
|
| 721 | |||
| 722 | /** |
||
| 723 | * Assigns a value to the specified offset + check the type. |
||
| 724 | * |
||
| 725 | * @param int|string|null $offset |
||
| 726 | * @param mixed $value |
||
| 727 | * |
||
| 728 | * @return void |
||
| 729 | */ |
||
| 730 | 28 | public function offsetSet($offset, $value) |
|
| 748 | |||
| 749 | /** |
||
| 750 | * Unset an offset. |
||
| 751 | * |
||
| 752 | * @param int|string $offset |
||
| 753 | * |
||
| 754 | * @return void |
||
| 755 | * <p>(Mutable) Return nothing.</p> |
||
| 756 | */ |
||
| 757 | 26 | public function offsetUnset($offset) |
|
| 808 | |||
| 809 | /** |
||
| 810 | * Serialize the current "Arrayy"-object. |
||
| 811 | * |
||
| 812 | * EXAMPLE: <code> |
||
| 813 | * a([1, 4, 7])->serialize(); |
||
| 814 | * </code> |
||
| 815 | * |
||
| 816 | * @return string |
||
| 817 | */ |
||
| 818 | 2 | public function serialize(): string |
|
| 828 | |||
| 829 | /** |
||
| 830 | * Sets the iterator classname for the current "Arrayy"-object. |
||
| 831 | * |
||
| 832 | * @param string $iteratorClass |
||
| 833 | * |
||
| 834 | * @throws \InvalidArgumentException |
||
| 835 | * |
||
| 836 | * @return void |
||
| 837 | * |
||
| 838 | * @psalm-param class-string<\Arrayy\ArrayyIterator> $iteratorClass |
||
| 839 | */ |
||
| 840 | 1202 | public function setIteratorClass($iteratorClass) |
|
| 862 | |||
| 863 | /** |
||
| 864 | * Sort the entries with a user-defined comparison function and maintain key association. |
||
| 865 | * |
||
| 866 | * @param callable $function |
||
| 867 | * |
||
| 868 | * @throws \InvalidArgumentException |
||
| 869 | * |
||
| 870 | * @return $this |
||
| 871 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 872 | * |
||
| 873 | * @psalm-return static<TKey,T> |
||
| 874 | */ |
||
| 875 | 8 | View Code Duplication | public function uasort($function): self |
| 887 | |||
| 888 | /** |
||
| 889 | * Sort the entries with a user-defined comparison function and maintain key association. |
||
| 890 | * |
||
| 891 | * @param callable $function |
||
| 892 | * |
||
| 893 | * @throws \InvalidArgumentException |
||
| 894 | * |
||
| 895 | * @return $this |
||
| 896 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 897 | * |
||
| 898 | * @psalm-return static<TKey,T> |
||
| 899 | * @psalm-mutation-free |
||
| 900 | */ |
||
| 901 | 4 | public function uasortImmutable($function): self |
|
| 912 | |||
| 913 | /** |
||
| 914 | * Sort the entries by keys using a user-defined comparison function. |
||
| 915 | * |
||
| 916 | * @param callable $function |
||
| 917 | * |
||
| 918 | * @throws \InvalidArgumentException |
||
| 919 | * |
||
| 920 | * @return static |
||
| 921 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 922 | * |
||
| 923 | * @psalm-return static<TKey,T> |
||
| 924 | */ |
||
| 925 | 5 | public function uksort($function): self |
|
| 929 | |||
| 930 | /** |
||
| 931 | * Sort the entries by keys using a user-defined comparison function. |
||
| 932 | * |
||
| 933 | * @param callable $function |
||
| 934 | * |
||
| 935 | * @throws \InvalidArgumentException |
||
| 936 | * |
||
| 937 | * @return static |
||
| 938 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 939 | * |
||
| 940 | * @psalm-return static<TKey,T> |
||
| 941 | * @psalm-mutation-free |
||
| 942 | */ |
||
| 943 | 1 | public function uksortImmutable($function): self |
|
| 947 | |||
| 948 | /** |
||
| 949 | * Unserialize an string and return the instance of the "Arrayy"-class. |
||
| 950 | * |
||
| 951 | * EXAMPLE: <code> |
||
| 952 | * $serialized = a([1, 4, 7])->serialize(); |
||
| 953 | * a()->unserialize($serialized); |
||
| 954 | * </code> |
||
| 955 | * |
||
| 956 | * @param string $string |
||
| 957 | * |
||
| 958 | * @return $this |
||
| 959 | * |
||
| 960 | * @psalm-return static<TKey,T> |
||
| 961 | */ |
||
| 962 | 2 | public function unserialize($string): self |
|
| 972 | |||
| 973 | /** |
||
| 974 | * Append a (key) + values to the current array. |
||
| 975 | * |
||
| 976 | * EXAMPLE: <code> |
||
| 977 | * a(['fòô' => ['bàř']])->appendArrayValues(['foo1', 'foo2'], 'fòô'); // Arrayy['fòô' => ['bàř', 'foo1', 'foo2']] |
||
| 978 | * </code> |
||
| 979 | * |
||
| 980 | * @param array $values |
||
| 981 | * @param mixed $key |
||
| 982 | * |
||
| 983 | * @return $this |
||
| 984 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
| 985 | * |
||
| 986 | * @psalm-param array<mixed,T> $values |
||
| 987 | * @psalm-param TKey|null $key |
||
| 988 | * @psalm-return static<TKey,T> |
||
| 989 | */ |
||
| 990 | 1 | public function appendArrayValues(array $values, $key = null) |
|
| 1016 | |||
| 1017 | /** |
||
| 1018 | * Add a suffix to each key. |
||
| 1019 | * |
||
| 1020 | * @param mixed $prefix |
||
| 1021 | * |
||
| 1022 | * @return static |
||
| 1023 | * <p>(Immutable) Return an Arrayy object, with the prefixed keys.</p> |
||
| 1024 | * |
||
| 1025 | * @psalm-return static<TKey,T> |
||
| 1026 | * @psalm-mutation-free |
||
| 1027 | */ |
||
| 1028 | 10 | View Code Duplication | public function appendToEachKey($prefix): self |
| 1047 | |||
| 1048 | /** |
||
| 1049 | * Add a prefix to each value. |
||
| 1050 | * |
||
| 1051 | * @param mixed $prefix |
||
| 1052 | * |
||
| 1053 | * @return static |
||
| 1054 | * <p>(Immutable) Return an Arrayy object, with the prefixed values.</p> |
||
| 1055 | * |
||
| 1056 | * @psalm-return static<TKey,T> |
||
| 1057 | * @psalm-mutation-free |
||
| 1058 | */ |
||
| 1059 | 10 | View Code Duplication | public function appendToEachValue($prefix): self |
| 1078 | |||
| 1079 | /** |
||
| 1080 | * Sort an array in reverse order and maintain index association. |
||
| 1081 | * |
||
| 1082 | * @return $this |
||
| 1083 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1084 | * |
||
| 1085 | * @psalm-return static<TKey,T> |
||
| 1086 | */ |
||
| 1087 | 4 | public function arsort(): self |
|
| 1095 | |||
| 1096 | /** |
||
| 1097 | * Sort an array in reverse order and maintain index association. |
||
| 1098 | * |
||
| 1099 | * @return $this |
||
| 1100 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 1101 | * |
||
| 1102 | * @psalm-return static<TKey,T> |
||
| 1103 | * @psalm-mutation-free |
||
| 1104 | */ |
||
| 1105 | 10 | public function arsortImmutable(): self |
|
| 1115 | |||
| 1116 | /** |
||
| 1117 | * Iterate over the current array and execute a callback for each loop. |
||
| 1118 | * |
||
| 1119 | * EXAMPLE: <code> |
||
| 1120 | * $result = A::create(); |
||
| 1121 | * $closure = function ($value, $key) use ($result) { |
||
| 1122 | * $result[$key] = ':' . $value . ':'; |
||
| 1123 | * }; |
||
| 1124 | * a(['foo', 'bar' => 'bis'])->at($closure); // Arrayy[':foo:', 'bar' => ':bis:'] |
||
| 1125 | * </code> |
||
| 1126 | * |
||
| 1127 | * @param \Closure $closure |
||
| 1128 | * |
||
| 1129 | * @return static |
||
| 1130 | * <p>(Immutable)</p> |
||
| 1131 | * |
||
| 1132 | * @psalm-return static<TKey,T> |
||
| 1133 | * @psalm-mutation-free |
||
| 1134 | */ |
||
| 1135 | 3 | public function at(\Closure $closure): self |
|
| 1149 | |||
| 1150 | /** |
||
| 1151 | * Returns the average value of the current array. |
||
| 1152 | * |
||
| 1153 | * EXAMPLE: <code> |
||
| 1154 | * a([-9, -8, -7, 1.32])->average(2); // -5.67 |
||
| 1155 | * </code> |
||
| 1156 | * |
||
| 1157 | * @param int $decimals <p>The number of decimal-numbers to return.</p> |
||
| 1158 | * |
||
| 1159 | * @return float|int |
||
| 1160 | * <p>The average value.</p> |
||
| 1161 | * @psalm-mutation-free |
||
| 1162 | */ |
||
| 1163 | 10 | public function average($decimals = 0) |
|
| 1177 | |||
| 1178 | /** |
||
| 1179 | * Changes all keys in an array. |
||
| 1180 | * |
||
| 1181 | * @param int $case [optional] <p> Either <strong>CASE_UPPER</strong><br /> |
||
| 1182 | * or <strong>CASE_LOWER</strong> (default)</p> |
||
| 1183 | * |
||
| 1184 | * @return static |
||
| 1185 | * <p>(Immutable)</p> |
||
| 1186 | * |
||
| 1187 | * @psalm-return static<TKey,T> |
||
| 1188 | * @psalm-mutation-free |
||
| 1189 | */ |
||
| 1190 | 1 | public function changeKeyCase(int $case = \CASE_LOWER): self |
|
| 1219 | |||
| 1220 | /** |
||
| 1221 | * Change the path separator of the array wrapper. |
||
| 1222 | * |
||
| 1223 | * By default, the separator is: "." |
||
| 1224 | * |
||
| 1225 | * @param string $separator <p>Separator to set.</p> |
||
| 1226 | * |
||
| 1227 | * @return $this |
||
| 1228 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1229 | * |
||
| 1230 | * @psalm-return static<TKey,T> |
||
| 1231 | */ |
||
| 1232 | 11 | public function changeSeparator($separator): self |
|
| 1238 | |||
| 1239 | /** |
||
| 1240 | * Create a chunked version of the current array. |
||
| 1241 | * |
||
| 1242 | * EXAMPLE: <code> |
||
| 1243 | * a([-9, -8, -7, 1.32])->chunk(2); // Arrayy[[-9, -8], [-7, 1.32]] |
||
| 1244 | * </code> |
||
| 1245 | * |
||
| 1246 | * @param int $size <p>Size of each chunk.</p> |
||
| 1247 | * @param bool $preserveKeys <p>Whether array keys are preserved or no.</p> |
||
| 1248 | * |
||
| 1249 | * @return static |
||
| 1250 | * <p>(Immutable) A new array of chunks from the original array.</p> |
||
| 1251 | * |
||
| 1252 | * @psalm-return static<TKey,T> |
||
| 1253 | * @psalm-mutation-free |
||
| 1254 | */ |
||
| 1255 | 5 | public function chunk($size, $preserveKeys = false): self |
|
| 1305 | |||
| 1306 | /** |
||
| 1307 | * Clean all falsy values from the current array. |
||
| 1308 | * |
||
| 1309 | * EXAMPLE: <code> |
||
| 1310 | * a([-8 => -9, 1, 2 => false])->clean(); // Arrayy[-8 => -9, 1] |
||
| 1311 | * </code> |
||
| 1312 | * |
||
| 1313 | * @return static |
||
| 1314 | * <p>(Immutable)</p> |
||
| 1315 | * |
||
| 1316 | * @psalm-return static<TKey,T> |
||
| 1317 | * @psalm-mutation-free |
||
| 1318 | */ |
||
| 1319 | 8 | public function clean(): self |
|
| 1327 | |||
| 1328 | /** |
||
| 1329 | * WARNING!!! -> Clear the current full array or a $key of it. |
||
| 1330 | * |
||
| 1331 | * EXAMPLE: <code> |
||
| 1332 | * a([-8 => -9, 1, 2 => false])->clear(); // Arrayy[] |
||
| 1333 | * </code> |
||
| 1334 | * |
||
| 1335 | * @param int|int[]|string|string[]|null $key |
||
| 1336 | * |
||
| 1337 | * @return $this |
||
| 1338 | * <p>(Mutable) Return this Arrayy object, with an empty array.</p> |
||
| 1339 | * |
||
| 1340 | * @psalm-return static<TKey,T> |
||
| 1341 | */ |
||
| 1342 | 10 | public function clear($key = null): self |
|
| 1361 | |||
| 1362 | /** |
||
| 1363 | * Check if an item is in the current array. |
||
| 1364 | * |
||
| 1365 | * EXAMPLE: <code> |
||
| 1366 | * a([1, true])->contains(true); // true |
||
| 1367 | * </code> |
||
| 1368 | * |
||
| 1369 | * @param float|int|string $value |
||
| 1370 | * @param bool $recursive |
||
| 1371 | * @param bool $strict |
||
| 1372 | * |
||
| 1373 | * @return bool |
||
| 1374 | * @psalm-mutation-free |
||
| 1375 | */ |
||
| 1376 | 23 | public function contains($value, bool $recursive = false, bool $strict = true): bool |
|
| 1398 | |||
| 1399 | /** |
||
| 1400 | * Check if an (case-insensitive) string is in the current array. |
||
| 1401 | * |
||
| 1402 | * EXAMPLE: <code> |
||
| 1403 | * a(['E', 'é'])->containsCaseInsensitive('É'); // true |
||
| 1404 | * </code> |
||
| 1405 | * |
||
| 1406 | * @param mixed $value |
||
| 1407 | * @param bool $recursive |
||
| 1408 | * |
||
| 1409 | * @return bool |
||
| 1410 | * @psalm-mutation-free |
||
| 1411 | * |
||
| 1412 | * @psalm-suppress InvalidCast - hack for int|float|bool support |
||
| 1413 | */ |
||
| 1414 | 26 | public function containsCaseInsensitive($value, $recursive = false): bool |
|
| 1445 | |||
| 1446 | /** |
||
| 1447 | * Check if the given key/index exists in the array. |
||
| 1448 | * |
||
| 1449 | * EXAMPLE: <code> |
||
| 1450 | * a([1 => true])->containsKey(1); // true |
||
| 1451 | * </code> |
||
| 1452 | * |
||
| 1453 | * @param int|string $key <p>key/index to search for</p> |
||
| 1454 | * |
||
| 1455 | * @return bool |
||
| 1456 | * <p>Returns true if the given key/index exists in the array, false otherwise.</p> |
||
| 1457 | * |
||
| 1458 | * @psalm-mutation-free |
||
| 1459 | */ |
||
| 1460 | 4 | public function containsKey($key): bool |
|
| 1464 | |||
| 1465 | /** |
||
| 1466 | * Check if all given needles are present in the array as key/index. |
||
| 1467 | * |
||
| 1468 | * EXAMPLE: <code> |
||
| 1469 | * a([1 => true])->containsKeys(array(1 => 0)); // true |
||
| 1470 | * </code> |
||
| 1471 | * |
||
| 1472 | * @param array $needles <p>The keys you are searching for.</p> |
||
| 1473 | * @param bool $recursive |
||
| 1474 | * |
||
| 1475 | * @return bool |
||
| 1476 | * <p>Returns true if all the given keys/indexes exists in the array, false otherwise.</p> |
||
| 1477 | * |
||
| 1478 | * @psalm-param array<mixed,mixed>|array<TKey> $needles |
||
| 1479 | * @psalm-mutation-free |
||
| 1480 | */ |
||
| 1481 | 2 | public function containsKeys(array $needles, $recursive = false): bool |
|
| 1509 | |||
| 1510 | /** |
||
| 1511 | * Check if all given needles are present in the array as key/index. |
||
| 1512 | * |
||
| 1513 | * @param array $needles <p>The keys you are searching for.</p> |
||
| 1514 | * |
||
| 1515 | * @return bool |
||
| 1516 | * <p>Returns true if all the given keys/indexes exists in the array, false otherwise.</p> |
||
| 1517 | * |
||
| 1518 | * @psalm-param array<mixed,mixed>|array<TKey> $needles |
||
| 1519 | * @psalm-mutation-free |
||
| 1520 | */ |
||
| 1521 | 1 | public function containsKeysRecursive(array $needles): bool |
|
| 1525 | |||
| 1526 | /** |
||
| 1527 | * alias: for "Arrayy->contains()" |
||
| 1528 | * |
||
| 1529 | * @param float|int|string $value |
||
| 1530 | * |
||
| 1531 | * @return bool |
||
| 1532 | * |
||
| 1533 | * @see Arrayy::contains() |
||
| 1534 | * @psalm-mutation-free |
||
| 1535 | */ |
||
| 1536 | 9 | public function containsValue($value): bool |
|
| 1540 | |||
| 1541 | /** |
||
| 1542 | * alias: for "Arrayy->contains($value, true)" |
||
| 1543 | * |
||
| 1544 | * @param float|int|string $value |
||
| 1545 | * |
||
| 1546 | * @return bool |
||
| 1547 | * |
||
| 1548 | * @see Arrayy::contains() |
||
| 1549 | * @psalm-mutation-free |
||
| 1550 | */ |
||
| 1551 | 18 | public function containsValueRecursive($value): bool |
|
| 1555 | |||
| 1556 | /** |
||
| 1557 | * Check if all given needles are present in the array. |
||
| 1558 | * |
||
| 1559 | * EXAMPLE: <code> |
||
| 1560 | * a([1, true])->containsValues(array(1, true)); // true |
||
| 1561 | * </code> |
||
| 1562 | * |
||
| 1563 | * @param array $needles |
||
| 1564 | * |
||
| 1565 | * @return bool |
||
| 1566 | * <p>Returns true if all the given values exists in the array, false otherwise.</p> |
||
| 1567 | * |
||
| 1568 | * @psalm-param array<mixed>|array<T> $needles |
||
| 1569 | * @psalm-mutation-free |
||
| 1570 | */ |
||
| 1571 | 1 | public function containsValues(array $needles): bool |
|
| 1586 | |||
| 1587 | /** |
||
| 1588 | * Counts all the values of an array |
||
| 1589 | * |
||
| 1590 | * @see http://php.net/manual/en/function.array-count-values.php |
||
| 1591 | * |
||
| 1592 | * @return static |
||
| 1593 | * <p> |
||
| 1594 | * (Immutable) |
||
| 1595 | * An associative Arrayy-object of values from input as |
||
| 1596 | * keys and their count as value. |
||
| 1597 | * </p> |
||
| 1598 | * |
||
| 1599 | * @psalm-return static<TKey,T> |
||
| 1600 | * @psalm-mutation-free |
||
| 1601 | */ |
||
| 1602 | 7 | public function countValues(): self |
|
| 1606 | |||
| 1607 | /** |
||
| 1608 | * Creates an Arrayy object. |
||
| 1609 | * |
||
| 1610 | * @param mixed $data |
||
| 1611 | * @param string $iteratorClass |
||
| 1612 | * @param bool $checkPropertiesInConstructor |
||
| 1613 | * |
||
| 1614 | * @return static |
||
| 1615 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1616 | * |
||
| 1617 | * @psalm-param class-string<\Arrayy\ArrayyIterator> $iteratorClass |
||
| 1618 | * |
||
| 1619 | * @psalm-mutation-free |
||
| 1620 | */ |
||
| 1621 | 729 | public static function create( |
|
| 1632 | |||
| 1633 | /** |
||
| 1634 | * Flatten an array with the given character as a key delimiter. |
||
| 1635 | * |
||
| 1636 | * EXAMPLE: <code> |
||
| 1637 | * $dot = a(['foo' => ['abc' => 'xyz', 'bar' => ['baz']]]); |
||
| 1638 | * $flatten = $dot->flatten(); |
||
| 1639 | * $flatten['foo.abc']; // 'xyz' |
||
| 1640 | * $flatten['foo.bar.0']; // 'baz' |
||
| 1641 | * </code> |
||
| 1642 | * |
||
| 1643 | * @param string $delimiter |
||
| 1644 | * @param string $prepend |
||
| 1645 | * @param array|null $items |
||
| 1646 | * |
||
| 1647 | * @return array |
||
| 1648 | */ |
||
| 1649 | 2 | public function flatten($delimiter = '.', $prepend = '', $items = null) |
|
| 1672 | |||
| 1673 | /** |
||
| 1674 | * WARNING: Creates an Arrayy object by reference. |
||
| 1675 | * |
||
| 1676 | * @param array $array |
||
| 1677 | * |
||
| 1678 | * @return $this |
||
| 1679 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1680 | * |
||
| 1681 | * @psalm-param array<mixed,mixed>|array<array-key,mixed> $array |
||
| 1682 | */ |
||
| 1683 | 26 | public function createByReference(array &$array = []): self |
|
| 1691 | |||
| 1692 | /** |
||
| 1693 | * Create an new instance from a callable function which will return an Generator. |
||
| 1694 | * |
||
| 1695 | * @param callable $generatorFunction |
||
| 1696 | * |
||
| 1697 | * @return static |
||
| 1698 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1699 | * |
||
| 1700 | * @psalm-param callable():\Generator<array-key,mixed> $generatorFunction |
||
| 1701 | * |
||
| 1702 | * @psalm-mutation-free |
||
| 1703 | */ |
||
| 1704 | 7 | public static function createFromGeneratorFunction(callable $generatorFunction): self |
|
| 1708 | |||
| 1709 | /** |
||
| 1710 | * Create an new instance filled with a copy of values from a "Generator"-object. |
||
| 1711 | * |
||
| 1712 | * @param \Generator $generator |
||
| 1713 | * |
||
| 1714 | * @return static |
||
| 1715 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1716 | * |
||
| 1717 | * @psalm-param \Generator<array-key,mixed> $generator |
||
| 1718 | * |
||
| 1719 | * @psalm-mutation-free |
||
| 1720 | */ |
||
| 1721 | 4 | public static function createFromGeneratorImmutable(\Generator $generator): self |
|
| 1725 | |||
| 1726 | /** |
||
| 1727 | * Create an new Arrayy object via JSON. |
||
| 1728 | * |
||
| 1729 | * @param string $json |
||
| 1730 | * |
||
| 1731 | * @return static |
||
| 1732 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1733 | * |
||
| 1734 | * @psalm-mutation-free |
||
| 1735 | */ |
||
| 1736 | 5 | public static function createFromJson(string $json): self |
|
| 1740 | |||
| 1741 | /** |
||
| 1742 | * Create an new Arrayy object via JSON. |
||
| 1743 | * |
||
| 1744 | * @param array $array |
||
| 1745 | * |
||
| 1746 | * @return static |
||
| 1747 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1748 | * |
||
| 1749 | * @psalm-mutation-free |
||
| 1750 | */ |
||
| 1751 | 1 | public static function createFromArray(array $array): self |
|
| 1755 | |||
| 1756 | /** |
||
| 1757 | * Create an new instance filled with values from an object that is iterable. |
||
| 1758 | * |
||
| 1759 | * @param \Traversable $object <p>iterable object</p> |
||
| 1760 | * |
||
| 1761 | * @return static |
||
| 1762 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1763 | * |
||
| 1764 | * @psalm-param \Traversable<array-key,mixed> $object |
||
| 1765 | * |
||
| 1766 | * @psalm-mutation-free |
||
| 1767 | */ |
||
| 1768 | 4 | public static function createFromObject(\Traversable $object): self |
|
| 1788 | |||
| 1789 | /** |
||
| 1790 | * Create an new instance filled with values from an object. |
||
| 1791 | * |
||
| 1792 | * @param object $object |
||
| 1793 | * |
||
| 1794 | * @return static |
||
| 1795 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1796 | * |
||
| 1797 | * @psalm-mutation-free |
||
| 1798 | */ |
||
| 1799 | 5 | public static function createFromObjectVars($object): self |
|
| 1803 | |||
| 1804 | /** |
||
| 1805 | * Create an new Arrayy object via string. |
||
| 1806 | * |
||
| 1807 | * @param string $str <p>The input string.</p> |
||
| 1808 | * @param string|null $delimiter <p>The boundary string.</p> |
||
| 1809 | * @param string|null $regEx <p>Use the $delimiter or the $regEx, so if $pattern is null, $delimiter will be |
||
| 1810 | * used.</p> |
||
| 1811 | * |
||
| 1812 | * @return static |
||
| 1813 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1814 | * |
||
| 1815 | * @psalm-mutation-free |
||
| 1816 | */ |
||
| 1817 | 10 | public static function createFromString(string $str, string $delimiter = null, string $regEx = null): self |
|
| 1849 | |||
| 1850 | /** |
||
| 1851 | * Create an new instance filled with a copy of values from a "Traversable"-object. |
||
| 1852 | * |
||
| 1853 | * @param \Traversable $traversable |
||
| 1854 | * |
||
| 1855 | * @return static |
||
| 1856 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1857 | * |
||
| 1858 | * @psalm-param \Traversable<array-key,mixed> $traversable |
||
| 1859 | * |
||
| 1860 | * @psalm-mutation-free |
||
| 1861 | */ |
||
| 1862 | 1 | public static function createFromTraversableImmutable(\Traversable $traversable): self |
|
| 1866 | |||
| 1867 | /** |
||
| 1868 | * Create an new instance containing a range of elements. |
||
| 1869 | * |
||
| 1870 | * @param float|int|string $low <p>First value of the sequence.</p> |
||
| 1871 | * @param float|int|string $high <p>The sequence is ended upon reaching the end value.</p> |
||
| 1872 | * @param float|int $step <p>Used as the increment between elements in the sequence.</p> |
||
| 1873 | * |
||
| 1874 | * @return static |
||
| 1875 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1876 | * |
||
| 1877 | * @psalm-mutation-free |
||
| 1878 | */ |
||
| 1879 | 2 | public static function createWithRange($low, $high, $step = 1): self |
|
| 1883 | |||
| 1884 | /** |
||
| 1885 | * Gets the element of the array at the current internal iterator position. |
||
| 1886 | * |
||
| 1887 | * @return false|mixed |
||
| 1888 | */ |
||
| 1889 | public function current() |
||
| 1893 | |||
| 1894 | /** |
||
| 1895 | * Custom sort by index via "uksort". |
||
| 1896 | * |
||
| 1897 | * EXAMPLE: <code> |
||
| 1898 | * $callable = function ($a, $b) { |
||
| 1899 | * if ($a == $b) { |
||
| 1900 | * return 0; |
||
| 1901 | * } |
||
| 1902 | * return ($a > $b) ? 1 : -1; |
||
| 1903 | * }; |
||
| 1904 | * $arrayy = a(['three' => 3, 'one' => 1, 'two' => 2]); |
||
| 1905 | * $resultArrayy = $arrayy->customSortKeys($callable); // Arrayy['one' => 1, 'three' => 3, 'two' => 2] |
||
| 1906 | * </code> |
||
| 1907 | * |
||
| 1908 | * @see http://php.net/manual/en/function.uksort.php |
||
| 1909 | * |
||
| 1910 | * @param callable $function |
||
| 1911 | * |
||
| 1912 | * @throws \InvalidArgumentException |
||
| 1913 | * |
||
| 1914 | * @return $this |
||
| 1915 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1916 | * |
||
| 1917 | * @psalm-return static<TKey,T> |
||
| 1918 | */ |
||
| 1919 | 5 | public function customSortKeys(callable $function): self |
|
| 1927 | |||
| 1928 | /** |
||
| 1929 | * Custom sort by index via "uksort". |
||
| 1930 | * |
||
| 1931 | * @see http://php.net/manual/en/function.uksort.php |
||
| 1932 | * |
||
| 1933 | * @param callable $function |
||
| 1934 | * |
||
| 1935 | * @throws \InvalidArgumentException |
||
| 1936 | * |
||
| 1937 | * @return $this |
||
| 1938 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 1939 | * |
||
| 1940 | * @psalm-return static<TKey,T> |
||
| 1941 | * @psalm-mutation-free |
||
| 1942 | */ |
||
| 1943 | 1 | public function customSortKeysImmutable(callable $function): self |
|
| 1956 | |||
| 1957 | /** |
||
| 1958 | * Custom sort by value via "usort". |
||
| 1959 | * |
||
| 1960 | * EXAMPLE: <code> |
||
| 1961 | * $callable = function ($a, $b) { |
||
| 1962 | * if ($a == $b) { |
||
| 1963 | * return 0; |
||
| 1964 | * } |
||
| 1965 | * return ($a > $b) ? 1 : -1; |
||
| 1966 | * }; |
||
| 1967 | * $arrayy = a(['three' => 3, 'one' => 1, 'two' => 2]); |
||
| 1968 | * $resultArrayy = $arrayy->customSortValues($callable); // Arrayy['one' => 1, 'two' => 2, 'three' => 3] |
||
| 1969 | * </code> |
||
| 1970 | * |
||
| 1971 | * @see http://php.net/manual/en/function.usort.php |
||
| 1972 | * |
||
| 1973 | * @param callable $function |
||
| 1974 | * |
||
| 1975 | * @throws \InvalidArgumentException |
||
| 1976 | * |
||
| 1977 | * @return $this |
||
| 1978 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1979 | * |
||
| 1980 | * @psalm-return static<TKey,T> |
||
| 1981 | */ |
||
| 1982 | 10 | View Code Duplication | public function customSortValues($function): self |
| 1994 | |||
| 1995 | /** |
||
| 1996 | * Custom sort by value via "usort". |
||
| 1997 | * |
||
| 1998 | * @see http://php.net/manual/en/function.usort.php |
||
| 1999 | * |
||
| 2000 | * @param callable $function |
||
| 2001 | * |
||
| 2002 | * @throws \InvalidArgumentException |
||
| 2003 | * |
||
| 2004 | * @return $this |
||
| 2005 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 2006 | * |
||
| 2007 | * @psalm-return static<TKey,T> |
||
| 2008 | * @psalm-mutation-free |
||
| 2009 | */ |
||
| 2010 | 4 | public function customSortValuesImmutable($function): self |
|
| 2021 | |||
| 2022 | /** |
||
| 2023 | * Delete the given key or keys. |
||
| 2024 | * |
||
| 2025 | * @param int|int[]|string|string[] $keyOrKeys |
||
| 2026 | * |
||
| 2027 | * @return void |
||
| 2028 | */ |
||
| 2029 | 9 | public function delete($keyOrKeys) |
|
| 2037 | |||
| 2038 | /** |
||
| 2039 | * Return elements where the values that are only in the current array. |
||
| 2040 | * |
||
| 2041 | * EXAMPLE: <code> |
||
| 2042 | * a([1 => 1, 2 => 2])->diff([1 => 1]); // Arrayy[2 => 2] |
||
| 2043 | * </code> |
||
| 2044 | * |
||
| 2045 | * @param array ...$array |
||
| 2046 | * |
||
| 2047 | * @return static |
||
| 2048 | * <p>(Immutable)</p> |
||
| 2049 | * |
||
| 2050 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$array |
||
| 2051 | * @psalm-return static<TKey,T> |
||
| 2052 | * @psalm-mutation-free |
||
| 2053 | */ |
||
| 2054 | 13 | View Code Duplication | public function diff(array ...$array): self |
| 2076 | |||
| 2077 | /** |
||
| 2078 | * Return elements where the keys are only in the current array. |
||
| 2079 | * |
||
| 2080 | * @param array ...$array |
||
| 2081 | * |
||
| 2082 | * @return static |
||
| 2083 | * <p>(Immutable)</p> |
||
| 2084 | * |
||
| 2085 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$array |
||
| 2086 | * @psalm-return static<TKey,T> |
||
| 2087 | * @psalm-mutation-free |
||
| 2088 | */ |
||
| 2089 | 9 | View Code Duplication | public function diffKey(array ...$array): self |
| 2111 | |||
| 2112 | /** |
||
| 2113 | * Return elements where the values and keys are only in the current array. |
||
| 2114 | * |
||
| 2115 | * @param array ...$array |
||
| 2116 | * |
||
| 2117 | * @return static |
||
| 2118 | * <p>(Immutable)</p> |
||
| 2119 | * |
||
| 2120 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 2121 | * @psalm-return static<TKey,T> |
||
| 2122 | * @psalm-mutation-free |
||
| 2123 | */ |
||
| 2124 | 9 | public function diffKeyAndValue(array ...$array): self |
|
| 2132 | |||
| 2133 | /** |
||
| 2134 | * Return elements where the values are only in the current multi-dimensional array. |
||
| 2135 | * |
||
| 2136 | * EXAMPLE: <code> |
||
| 2137 | * a([1 => [1 => 1], 2 => [2 => 2]])->diffRecursive([1 => [1 => 1]]); // Arrayy[2 => [2 => 2]] |
||
| 2138 | * </code> |
||
| 2139 | * |
||
| 2140 | * @param array $array |
||
| 2141 | * @param array|\Generator|null $helperVariableForRecursion <p>(only for internal usage)</p> |
||
| 2142 | * |
||
| 2143 | * @return static |
||
| 2144 | * <p>(Immutable)</p> |
||
| 2145 | * |
||
| 2146 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 2147 | * @psalm-param null|array<TKey,T>|\Generator<TKey,T> $helperVariableForRecursion |
||
| 2148 | * @psalm-return static<TKey,T> |
||
| 2149 | * @psalm-mutation-free |
||
| 2150 | */ |
||
| 2151 | 1 | public function diffRecursive(array $array = [], $helperVariableForRecursion = null): self |
|
| 2186 | |||
| 2187 | /** |
||
| 2188 | * Return elements where the values that are only in the new $array. |
||
| 2189 | * |
||
| 2190 | * EXAMPLE: <code> |
||
| 2191 | * a([1 => 1])->diffReverse([1 => 1, 2 => 2]); // Arrayy[2 => 2] |
||
| 2192 | * </code> |
||
| 2193 | * |
||
| 2194 | * @param array $array |
||
| 2195 | * |
||
| 2196 | * @return static |
||
| 2197 | * <p>(Immutable)</p> |
||
| 2198 | * |
||
| 2199 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 2200 | * @psalm-return static<TKey,T> |
||
| 2201 | * @psalm-mutation-free |
||
| 2202 | */ |
||
| 2203 | 8 | public function diffReverse(array $array = []): self |
|
| 2211 | |||
| 2212 | /** |
||
| 2213 | * Divide an array into two arrays. One with keys and the other with values. |
||
| 2214 | * |
||
| 2215 | * EXAMPLE: <code> |
||
| 2216 | * a(['a' => 1, 'b' => ''])->divide(); // Arrayy[Arrayy['a', 'b'], Arrayy[1, '']] |
||
| 2217 | * </code> |
||
| 2218 | * |
||
| 2219 | * @return static |
||
| 2220 | * <p>(Immutable)</p> |
||
| 2221 | * |
||
| 2222 | * @psalm-return static<TKey,T> |
||
| 2223 | * @psalm-mutation-free |
||
| 2224 | */ |
||
| 2225 | 1 | public function divide(): self |
|
| 2236 | |||
| 2237 | /** |
||
| 2238 | * Iterate over the current array and modify the array's value. |
||
| 2239 | * |
||
| 2240 | * EXAMPLE: <code> |
||
| 2241 | * $result = A::create(); |
||
| 2242 | * $closure = function ($value) { |
||
| 2243 | * return ':' . $value . ':'; |
||
| 2244 | * }; |
||
| 2245 | * a(['foo', 'bar' => 'bis'])->each($closure); // Arrayy[':foo:', 'bar' => ':bis:'] |
||
| 2246 | * </code> |
||
| 2247 | * |
||
| 2248 | * @param \Closure $closure |
||
| 2249 | * |
||
| 2250 | * @return static |
||
| 2251 | * <p>(Immutable)</p> |
||
| 2252 | * |
||
| 2253 | * @psalm-return static<TKey,T> |
||
| 2254 | * @psalm-mutation-free |
||
| 2255 | */ |
||
| 2256 | 5 | View Code Duplication | public function each(\Closure $closure): self |
| 2271 | |||
| 2272 | /** |
||
| 2273 | * Sets the internal iterator to the last element in the array and returns this element. |
||
| 2274 | * |
||
| 2275 | * @return mixed |
||
| 2276 | */ |
||
| 2277 | public function end() |
||
| 2281 | |||
| 2282 | /** |
||
| 2283 | * Check if a value is in the current array using a closure. |
||
| 2284 | * |
||
| 2285 | * EXAMPLE: <code> |
||
| 2286 | * $callable = function ($value, $key) { |
||
| 2287 | * return 2 === $key and 'two' === $value; |
||
| 2288 | * }; |
||
| 2289 | * a(['foo', 2 => 'two'])->exists($callable); // true |
||
| 2290 | * </code> |
||
| 2291 | * |
||
| 2292 | * @param \Closure $closure |
||
| 2293 | * |
||
| 2294 | * @return bool |
||
| 2295 | * <p>Returns true if the given value is found, false otherwise.</p> |
||
| 2296 | */ |
||
| 2297 | 4 | public function exists(\Closure $closure): bool |
|
| 2312 | |||
| 2313 | /** |
||
| 2314 | * Fill the array until "$num" with "$default" values. |
||
| 2315 | * |
||
| 2316 | * EXAMPLE: <code> |
||
| 2317 | * a(['bar'])->fillWithDefaults(3, 'foo'); // Arrayy['bar', 'foo', 'foo'] |
||
| 2318 | * </code> |
||
| 2319 | * |
||
| 2320 | * @param int $num |
||
| 2321 | * @param mixed $default |
||
| 2322 | * |
||
| 2323 | * @return static |
||
| 2324 | * <p>(Immutable)</p> |
||
| 2325 | * |
||
| 2326 | * @psalm-return static<TKey,T> |
||
| 2327 | * @psalm-mutation-free |
||
| 2328 | */ |
||
| 2329 | 8 | public function fillWithDefaults(int $num, $default = null): self |
|
| 2352 | |||
| 2353 | /** |
||
| 2354 | * Find all items in an array that pass the truth test. |
||
| 2355 | * |
||
| 2356 | * EXAMPLE: <code> |
||
| 2357 | * $closure = function ($value) { |
||
| 2358 | * return $value % 2 !== 0; |
||
| 2359 | * } |
||
| 2360 | * a([1, 2, 3, 4])->filter($closure); // Arrayy[0 => 1, 2 => 3] |
||
| 2361 | * </code> |
||
| 2362 | * |
||
| 2363 | * @param \Closure|null $closure [optional] <p> |
||
| 2364 | * The callback function to use |
||
| 2365 | * </p> |
||
| 2366 | * <p> |
||
| 2367 | * If no callback is supplied, all entries of |
||
| 2368 | * input equal to false (see |
||
| 2369 | * converting to |
||
| 2370 | * boolean) will be removed. |
||
| 2371 | * </p> |
||
| 2372 | * @param int $flag [optional] <p> |
||
| 2373 | * Flag determining what arguments are sent to <i>callback</i>: |
||
| 2374 | * </p> |
||
| 2375 | * <ul> |
||
| 2376 | * <li> |
||
| 2377 | * <b>ARRAY_FILTER_USE_KEY</b> (1) - pass key as the only argument |
||
| 2378 | * to <i>callback</i> instead of the value |
||
| 2379 | * </li> |
||
| 2380 | * <li> |
||
| 2381 | * <b>ARRAY_FILTER_USE_BOTH</b> (2) - pass both value and key as |
||
| 2382 | * arguments to <i>callback</i> instead of the value |
||
| 2383 | * </li> |
||
| 2384 | * </ul> |
||
| 2385 | * |
||
| 2386 | * @return static |
||
| 2387 | * <p>(Immutable)</p> |
||
| 2388 | * |
||
| 2389 | * @psalm-param null|\Closure(T=,TKey=):bool|\Closure(T=):bool||\Closure(TKey=):bool $closure |
||
| 2390 | * @psalm-return static<TKey,T> |
||
| 2391 | * @psalm-mutation-free |
||
| 2392 | */ |
||
| 2393 | 12 | public function filter($closure = null, int $flag = \ARRAY_FILTER_USE_BOTH) |
|
| 2431 | |||
| 2432 | /** |
||
| 2433 | * Filters an array of objects (or a numeric array of associative arrays) based on the value of a particular |
||
| 2434 | * property within that. |
||
| 2435 | * |
||
| 2436 | * @param string $property |
||
| 2437 | * @param mixed $value |
||
| 2438 | * @param string $comparisonOp |
||
| 2439 | * <p> |
||
| 2440 | * 'eq' (equals),<br /> |
||
| 2441 | * 'gt' (greater),<br /> |
||
| 2442 | * 'gte' || 'ge' (greater or equals),<br /> |
||
| 2443 | * 'lt' (less),<br /> |
||
| 2444 | * 'lte' || 'le' (less or equals),<br /> |
||
| 2445 | * 'ne' (not equals),<br /> |
||
| 2446 | * 'contains',<br /> |
||
| 2447 | * 'notContains',<br /> |
||
| 2448 | * 'newer' (via strtotime),<br /> |
||
| 2449 | * 'older' (via strtotime),<br /> |
||
| 2450 | * </p> |
||
| 2451 | * |
||
| 2452 | * @return static |
||
| 2453 | * <p>(Immutable)</p> |
||
| 2454 | * |
||
| 2455 | * @psalm-param mixed|T $value |
||
| 2456 | * @psalm-return static<TKey,T> |
||
| 2457 | * @psalm-mutation-free |
||
| 2458 | * |
||
| 2459 | * @psalm-suppress MissingClosureReturnType |
||
| 2460 | * @psalm-suppress MissingClosureParamType |
||
| 2461 | */ |
||
| 2462 | 1 | public function filterBy( |
|
| 2534 | |||
| 2535 | /** |
||
| 2536 | * Find the first item in an array that passes the truth test, otherwise return false. |
||
| 2537 | * |
||
| 2538 | * EXAMPLE: <code> |
||
| 2539 | * $search = 'foo'; |
||
| 2540 | * $closure = function ($value, $key) use ($search) { |
||
| 2541 | * return $value === $search; |
||
| 2542 | * }; |
||
| 2543 | * a(['foo', 'bar', 'lall'])->find($closure); // 'foo' |
||
| 2544 | * </code> |
||
| 2545 | * |
||
| 2546 | * @param \Closure $closure |
||
| 2547 | * |
||
| 2548 | * @return false|mixed |
||
| 2549 | * <p>Return false if we did not find the value.</p> |
||
| 2550 | */ |
||
| 2551 | 8 | View Code Duplication | public function find(\Closure $closure) |
| 2561 | |||
| 2562 | /** |
||
| 2563 | * find by ... |
||
| 2564 | * |
||
| 2565 | * EXAMPLE: <code> |
||
| 2566 | * $array = [ |
||
| 2567 | * 0 => ['id' => 123, 'name' => 'foo', 'group' => 'primary', 'value' => 123456, 'when' => '2014-01-01'], |
||
| 2568 | * 1 => ['id' => 456, 'name' => 'bar', 'group' => 'primary', 'value' => 1468, 'when' => '2014-07-15'], |
||
| 2569 | * ]; |
||
| 2570 | * a($array)->filterBy('name', 'foo'); // Arrayy[0 => ['id' => 123, 'name' => 'foo', 'group' => 'primary', 'value' => 123456, 'when' => '2014-01-01']] |
||
| 2571 | * </code> |
||
| 2572 | * |
||
| 2573 | * @param string $property |
||
| 2574 | * @param mixed $value |
||
| 2575 | * @param string $comparisonOp |
||
| 2576 | * |
||
| 2577 | * @return static |
||
| 2578 | * <p>(Immutable)</p> |
||
| 2579 | * |
||
| 2580 | * @psalm-param mixed|T $value |
||
| 2581 | * @psalm-return static<TKey,T> |
||
| 2582 | * @psalm-mutation-free |
||
| 2583 | */ |
||
| 2584 | 1 | public function findBy(string $property, $value, string $comparisonOp = 'eq'): self |
|
| 2588 | |||
| 2589 | /** |
||
| 2590 | * Get the first value from the current array. |
||
| 2591 | * |
||
| 2592 | * EXAMPLE: <code> |
||
| 2593 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->first(); // 'foo' |
||
| 2594 | * </code> |
||
| 2595 | * |
||
| 2596 | * @return mixed |
||
| 2597 | * <p>Return null if there wasn't a element.</p> |
||
| 2598 | */ |
||
| 2599 | 22 | public function first() |
|
| 2608 | |||
| 2609 | /** |
||
| 2610 | * Get the first key from the current array. |
||
| 2611 | * |
||
| 2612 | * @return mixed |
||
| 2613 | * <p>Return null if there wasn't a element.</p> |
||
| 2614 | * @psalm-mutation-free |
||
| 2615 | */ |
||
| 2616 | 29 | public function firstKey() |
|
| 2622 | |||
| 2623 | /** |
||
| 2624 | * Get the first value(s) from the current array. |
||
| 2625 | * And will return an empty array if there was no first entry. |
||
| 2626 | * |
||
| 2627 | * EXAMPLE: <code> |
||
| 2628 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->firstsImmutable(2); // Arrayy[0 => 'foo', 1 => 'bar'] |
||
| 2629 | * </code> |
||
| 2630 | * |
||
| 2631 | * @param int|null $number <p>How many values you will take?</p> |
||
| 2632 | * |
||
| 2633 | * @return static |
||
| 2634 | * <p>(Immutable)</p> |
||
| 2635 | * |
||
| 2636 | * @psalm-return static<TKey,T> |
||
| 2637 | * @psalm-mutation-free |
||
| 2638 | */ |
||
| 2639 | 37 | public function firstsImmutable(int $number = null): self |
|
| 2655 | |||
| 2656 | /** |
||
| 2657 | * Get the first value(s) from the current array. |
||
| 2658 | * And will return an empty array if there was no first entry. |
||
| 2659 | * |
||
| 2660 | * @param int|null $number <p>How many values you will take?</p> |
||
| 2661 | * |
||
| 2662 | * @return static |
||
| 2663 | * <p>(Immutable)</p> |
||
| 2664 | * |
||
| 2665 | * @psalm-return static<TKey,T> |
||
| 2666 | * @psalm-mutation-free |
||
| 2667 | */ |
||
| 2668 | 3 | View Code Duplication | public function firstsKeys(int $number = null): self |
| 2684 | |||
| 2685 | /** |
||
| 2686 | * Get and remove the first value(s) from the current array. |
||
| 2687 | * And will return an empty array if there was no first entry. |
||
| 2688 | * |
||
| 2689 | * EXAMPLE: <code> |
||
| 2690 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->firstsMutable(); // 'foo' |
||
| 2691 | * </code> |
||
| 2692 | * |
||
| 2693 | * @param int|null $number <p>How many values you will take?</p> |
||
| 2694 | * |
||
| 2695 | * @return $this |
||
| 2696 | * <p>(Mutable)</p> |
||
| 2697 | * |
||
| 2698 | * @psalm-return static<TKey,T> |
||
| 2699 | */ |
||
| 2700 | 34 | public function firstsMutable(int $number = null): self |
|
| 2712 | |||
| 2713 | /** |
||
| 2714 | * Exchanges all keys with their associated values in an array. |
||
| 2715 | * |
||
| 2716 | * EXAMPLE: <code> |
||
| 2717 | * a([0 => 'foo', 1 => 'bar'])->flip(); // Arrayy['foo' => 0, 'bar' => 1] |
||
| 2718 | * </code> |
||
| 2719 | * |
||
| 2720 | * @return static |
||
| 2721 | * <p>(Immutable)</p> |
||
| 2722 | * |
||
| 2723 | * @psalm-return static<array-key,TKey> |
||
| 2724 | * @psalm-mutation-free |
||
| 2725 | */ |
||
| 2726 | 1 | public function flip(): self |
|
| 2740 | |||
| 2741 | /** |
||
| 2742 | * Get a value from an array (optional using dot-notation). |
||
| 2743 | * |
||
| 2744 | * EXAMPLE: <code> |
||
| 2745 | * $arrayy = a(['user' => ['lastname' => 'Moelleken']]); |
||
| 2746 | * $arrayy->get('user.lastname'); // 'Moelleken' |
||
| 2747 | * // --- |
||
| 2748 | * $arrayy = new A(); |
||
| 2749 | * $arrayy['user'] = ['lastname' => 'Moelleken']; |
||
| 2750 | * $arrayy['user.firstname'] = 'Lars'; |
||
| 2751 | * $arrayy['user']['lastname']; // Moelleken |
||
| 2752 | * $arrayy['user.lastname']; // Moelleken |
||
| 2753 | * $arrayy['user.firstname']; // Lars |
||
| 2754 | * </code> |
||
| 2755 | * |
||
| 2756 | * @param mixed $key <p>The key to look for.</p> |
||
| 2757 | * @param mixed $fallback <p>Value to fallback to.</p> |
||
| 2758 | * @param array $array <p>The array to get from, if it's set to "null" we use the current array from the |
||
| 2759 | * class.</p> |
||
| 2760 | * @param bool $useByReference |
||
| 2761 | * |
||
| 2762 | * @return mixed|static |
||
| 2763 | * |
||
| 2764 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 2765 | * @psalm-mutation-free |
||
| 2766 | */ |
||
| 2767 | 248 | public function get( |
|
| 2931 | |||
| 2932 | /** |
||
| 2933 | * alias: for "Arrayy->toArray()" |
||
| 2934 | * |
||
| 2935 | * @return array |
||
| 2936 | * |
||
| 2937 | * @see Arrayy::getArray() |
||
| 2938 | * |
||
| 2939 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 2940 | */ |
||
| 2941 | 15 | public function getAll(): array |
|
| 2945 | |||
| 2946 | /** |
||
| 2947 | * Get the current array from the "Arrayy"-object. |
||
| 2948 | * |
||
| 2949 | * alias for "toArray()" |
||
| 2950 | * |
||
| 2951 | * @param bool $convertAllArrayyElements <p> |
||
| 2952 | * Convert all Child-"Arrayy" objects also to arrays. |
||
| 2953 | * </p> |
||
| 2954 | * @param bool $preserveKeys <p> |
||
| 2955 | * e.g.: A generator maybe return the same key more then once, |
||
| 2956 | * so maybe you will ignore the keys. |
||
| 2957 | * </p> |
||
| 2958 | * |
||
| 2959 | * @return array |
||
| 2960 | * |
||
| 2961 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 2962 | * @psalm-mutation-free |
||
| 2963 | * |
||
| 2964 | * @see Arrayy::toArray() |
||
| 2965 | */ |
||
| 2966 | 503 | public function getArray( |
|
| 2975 | |||
| 2976 | /** |
||
| 2977 | * @param string $json |
||
| 2978 | * |
||
| 2979 | * @return $this |
||
| 2980 | */ |
||
| 2981 | 3 | public static function createFromJsonMapper(string $json) |
|
| 2997 | |||
| 2998 | /** |
||
| 2999 | * @return array<int|string,TypeCheckInterface>|mixed|TypeCheckArray<int|string,TypeCheckInterface>|TypeInterface |
||
| 3000 | * |
||
| 3001 | * @internal |
||
| 3002 | */ |
||
| 3003 | 6 | public function getPhpDocPropertiesFromClass() |
|
| 3011 | |||
| 3012 | /** |
||
| 3013 | * Get the current array from the "Arrayy"-object as list. |
||
| 3014 | * |
||
| 3015 | * alias for "toList()" |
||
| 3016 | * |
||
| 3017 | * @param bool $convertAllArrayyElements <p> |
||
| 3018 | * Convert all Child-"Arrayy" objects also to arrays. |
||
| 3019 | * </p> |
||
| 3020 | * |
||
| 3021 | * @return array |
||
| 3022 | * |
||
| 3023 | * @psalm-return array<int,mixed>|array<int,T> |
||
| 3024 | * @psalm-mutation-free |
||
| 3025 | * |
||
| 3026 | * @see Arrayy::toList() |
||
| 3027 | */ |
||
| 3028 | 1 | public function getList(bool $convertAllArrayyElements = false): array |
|
| 3032 | |||
| 3033 | /** |
||
| 3034 | * Returns the values from a single column of the input array, identified by |
||
| 3035 | * the $columnKey, can be used to extract data-columns from multi-arrays. |
||
| 3036 | * |
||
| 3037 | * EXAMPLE: <code> |
||
| 3038 | * a([['foo' => 'bar', 'id' => 1], ['foo => 'lall', 'id' => 2]])->getColumn('foo', 'id'); // Arrayy[1 => 'bar', 2 => 'lall'] |
||
| 3039 | * </code> |
||
| 3040 | * |
||
| 3041 | * INFO: Optionally, you may provide an $indexKey to index the values in the returned |
||
| 3042 | * array by the values from the $indexKey column in the input array. |
||
| 3043 | * |
||
| 3044 | * @param int|string|null $columnKey |
||
| 3045 | * @param int|string|null $indexKey |
||
| 3046 | * |
||
| 3047 | * @return static |
||
| 3048 | * <p>(Immutable)</p> |
||
| 3049 | * |
||
| 3050 | * @psalm-return static<TKey,T> |
||
| 3051 | * @psalm-mutation-free |
||
| 3052 | */ |
||
| 3053 | 1 | public function getColumn($columnKey = null, $indexKey = null): self |
|
| 3113 | |||
| 3114 | /** |
||
| 3115 | * Get the current array from the "Arrayy"-object as generator by reference. |
||
| 3116 | * |
||
| 3117 | * @return \Generator |
||
| 3118 | * |
||
| 3119 | * @psalm-return \Generator<mixed,T>|\Generator<TKey,T> |
||
| 3120 | */ |
||
| 3121 | 75 | public function &getGeneratorByReference(): \Generator |
|
| 3140 | |||
| 3141 | /** |
||
| 3142 | * Get the current array from the "Arrayy"-object as generator. |
||
| 3143 | * |
||
| 3144 | * @return \Generator |
||
| 3145 | * |
||
| 3146 | * @psalm-return \Generator<mixed,T>|\Generator<TKey,T> |
||
| 3147 | * @psalm-mutation-free |
||
| 3148 | */ |
||
| 3149 | 1069 | public function getGenerator(): \Generator |
|
| 3159 | |||
| 3160 | /** |
||
| 3161 | * alias: for "Arrayy->keys()" |
||
| 3162 | * |
||
| 3163 | * @return static |
||
| 3164 | * <p>(Immutable)</p> |
||
| 3165 | * |
||
| 3166 | * @see Arrayy::keys() |
||
| 3167 | * |
||
| 3168 | * @psalm-return static<array-key,TKey> |
||
| 3169 | * @psalm-mutation-free |
||
| 3170 | */ |
||
| 3171 | 2 | public function getKeys() |
|
| 3175 | |||
| 3176 | /** |
||
| 3177 | * Get the current array from the "Arrayy"-object as object. |
||
| 3178 | * |
||
| 3179 | * @return \stdClass |
||
| 3180 | */ |
||
| 3181 | 4 | public function getObject(): \stdClass |
|
| 3185 | |||
| 3186 | /** |
||
| 3187 | * alias: for "Arrayy->randomImmutable()" |
||
| 3188 | * |
||
| 3189 | * @return static |
||
| 3190 | * <p>(Immutable)</p> |
||
| 3191 | * |
||
| 3192 | * @see Arrayy::randomImmutable() |
||
| 3193 | * |
||
| 3194 | * @psalm-return static<int|array-key,T> |
||
| 3195 | */ |
||
| 3196 | 4 | public function getRandom(): self |
|
| 3200 | |||
| 3201 | /** |
||
| 3202 | * alias: for "Arrayy->randomKey()" |
||
| 3203 | * |
||
| 3204 | * @return mixed |
||
| 3205 | * <p>Get a key/index or null if there wasn't a key/index.</p> |
||
| 3206 | * |
||
| 3207 | * @see Arrayy::randomKey() |
||
| 3208 | */ |
||
| 3209 | 3 | public function getRandomKey() |
|
| 3213 | |||
| 3214 | /** |
||
| 3215 | * alias: for "Arrayy->randomKeys()" |
||
| 3216 | * |
||
| 3217 | * @param int $number |
||
| 3218 | * |
||
| 3219 | * @return static |
||
| 3220 | * <p>(Immutable)</p> |
||
| 3221 | * |
||
| 3222 | * @see Arrayy::randomKeys() |
||
| 3223 | * |
||
| 3224 | * @psalm-return static<TKey,T> |
||
| 3225 | */ |
||
| 3226 | 8 | public function getRandomKeys(int $number): self |
|
| 3230 | |||
| 3231 | /** |
||
| 3232 | * alias: for "Arrayy->randomValue()" |
||
| 3233 | * |
||
| 3234 | * @return mixed |
||
| 3235 | * <p>Get a random value or null if there wasn't a value.</p> |
||
| 3236 | * |
||
| 3237 | * @see Arrayy::randomValue() |
||
| 3238 | */ |
||
| 3239 | 3 | public function getRandomValue() |
|
| 3243 | |||
| 3244 | /** |
||
| 3245 | * alias: for "Arrayy->randomValues()" |
||
| 3246 | * |
||
| 3247 | * @param int $number |
||
| 3248 | * |
||
| 3249 | * @return static |
||
| 3250 | * <p>(Immutable)</p> |
||
| 3251 | * |
||
| 3252 | * @see Arrayy::randomValues() |
||
| 3253 | * |
||
| 3254 | * @psalm-return static<TKey,T> |
||
| 3255 | */ |
||
| 3256 | 6 | public function getRandomValues(int $number): self |
|
| 3260 | |||
| 3261 | /** |
||
| 3262 | * Gets all values. |
||
| 3263 | * |
||
| 3264 | * @return static |
||
| 3265 | * <p>The values of all elements in this array, in the order they |
||
| 3266 | * appear in the array.</p> |
||
| 3267 | * |
||
| 3268 | * @psalm-return static<TKey,T> |
||
| 3269 | */ |
||
| 3270 | 4 | public function getValues() |
|
| 3280 | |||
| 3281 | /** |
||
| 3282 | * Gets all values via Generator. |
||
| 3283 | * |
||
| 3284 | * @return \Generator |
||
| 3285 | * <p>The values of all elements in this array, in the order they |
||
| 3286 | * appear in the array as Generator.</p> |
||
| 3287 | * |
||
| 3288 | * @psalm-return \Generator<TKey,T> |
||
| 3289 | */ |
||
| 3290 | 4 | public function getValuesYield(): \Generator |
|
| 3294 | |||
| 3295 | /** |
||
| 3296 | * Group values from a array according to the results of a closure. |
||
| 3297 | * |
||
| 3298 | * @param callable|string $grouper <p>A callable function name.</p> |
||
| 3299 | * @param bool $saveKeys |
||
| 3300 | * |
||
| 3301 | * @return static |
||
| 3302 | * <p>(Immutable)</p> |
||
| 3303 | * |
||
| 3304 | * @psalm-return static<TKey,T> |
||
| 3305 | * @psalm-mutation-free |
||
| 3306 | */ |
||
| 3307 | 4 | public function group($grouper, bool $saveKeys = false): self |
|
| 3348 | |||
| 3349 | /** |
||
| 3350 | * Check if an array has a given key. |
||
| 3351 | * |
||
| 3352 | * @param mixed $key |
||
| 3353 | * |
||
| 3354 | * @return bool |
||
| 3355 | */ |
||
| 3356 | 30 | public function has($key): bool |
|
| 3382 | |||
| 3383 | /** |
||
| 3384 | * Check if an array has a given value. |
||
| 3385 | * |
||
| 3386 | * INFO: If you need to search recursive please use ```contains($value, true)```. |
||
| 3387 | * |
||
| 3388 | * @param mixed $value |
||
| 3389 | * |
||
| 3390 | * @return bool |
||
| 3391 | */ |
||
| 3392 | 1 | public function hasValue($value): bool |
|
| 3396 | |||
| 3397 | /** |
||
| 3398 | * Implodes the values of this array. |
||
| 3399 | * |
||
| 3400 | * EXAMPLE: <code> |
||
| 3401 | * a([0 => -9, 1, 2])->implode('|'); // '-9|1|2' |
||
| 3402 | * </code> |
||
| 3403 | * |
||
| 3404 | * @param string $glue |
||
| 3405 | * @param string $prefix |
||
| 3406 | * |
||
| 3407 | * @return string |
||
| 3408 | * @psalm-mutation-free |
||
| 3409 | */ |
||
| 3410 | 28 | public function implode(string $glue = '', string $prefix = ''): string |
|
| 3414 | |||
| 3415 | /** |
||
| 3416 | * Implodes the keys of this array. |
||
| 3417 | * |
||
| 3418 | * @param string $glue |
||
| 3419 | * |
||
| 3420 | * @return string |
||
| 3421 | * @psalm-mutation-free |
||
| 3422 | */ |
||
| 3423 | 8 | public function implodeKeys(string $glue = ''): string |
|
| 3427 | |||
| 3428 | /** |
||
| 3429 | * Given a list and an iterate-function that returns |
||
| 3430 | * a key for each element in the list (or a property name), |
||
| 3431 | * returns an object with an index of each item. |
||
| 3432 | * |
||
| 3433 | * @param mixed $key |
||
| 3434 | * |
||
| 3435 | * @return static |
||
| 3436 | * <p>(Immutable)</p> |
||
| 3437 | * |
||
| 3438 | * @psalm-return static<TKey,T> |
||
| 3439 | * @psalm-mutation-free |
||
| 3440 | */ |
||
| 3441 | 4 | View Code Duplication | public function indexBy($key): self |
| 3458 | |||
| 3459 | /** |
||
| 3460 | * alias: for "Arrayy->searchIndex()" |
||
| 3461 | * |
||
| 3462 | * @param mixed $value <p>The value to search for.</p> |
||
| 3463 | * |
||
| 3464 | * @return false|mixed |
||
| 3465 | * |
||
| 3466 | * @see Arrayy::searchIndex() |
||
| 3467 | */ |
||
| 3468 | 4 | public function indexOf($value) |
|
| 3472 | |||
| 3473 | /** |
||
| 3474 | * Get everything but the last..$to items. |
||
| 3475 | * |
||
| 3476 | * EXAMPLE: <code> |
||
| 3477 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->initial(2); // Arrayy[0 => 'foo'] |
||
| 3478 | * </code> |
||
| 3479 | * |
||
| 3480 | * @param int $to |
||
| 3481 | * |
||
| 3482 | * @return static |
||
| 3483 | * <p>(Immutable)</p> |
||
| 3484 | * |
||
| 3485 | * @psalm-return static<TKey,T> |
||
| 3486 | * @psalm-mutation-free |
||
| 3487 | */ |
||
| 3488 | 12 | public function initial(int $to = 1): self |
|
| 3492 | |||
| 3493 | /** |
||
| 3494 | * Return an array with all elements found in input array. |
||
| 3495 | * |
||
| 3496 | * EXAMPLE: <code> |
||
| 3497 | * a(['foo', 'bar'])->intersection(['bar', 'baz']); // Arrayy['bar'] |
||
| 3498 | * </code> |
||
| 3499 | * |
||
| 3500 | * @param array $search |
||
| 3501 | * @param bool $keepKeys |
||
| 3502 | * |
||
| 3503 | * @return static |
||
| 3504 | * <p>(Immutable)</p> |
||
| 3505 | * |
||
| 3506 | * @psalm-param array<mixed,mixed>|array<TKey,T> $search |
||
| 3507 | * @psalm-return static<TKey,T> |
||
| 3508 | * @psalm-mutation-free |
||
| 3509 | */ |
||
| 3510 | 4 | public function intersection(array $search, bool $keepKeys = false): self |
|
| 3536 | |||
| 3537 | /** |
||
| 3538 | * Return an array with all elements found in input array. |
||
| 3539 | * |
||
| 3540 | * @param array ...$array |
||
| 3541 | * |
||
| 3542 | * @return static |
||
| 3543 | * <p>(Immutable)</p> |
||
| 3544 | * |
||
| 3545 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$array |
||
| 3546 | * @psalm-return static<TKey,T> |
||
| 3547 | * @psalm-mutation-free |
||
| 3548 | */ |
||
| 3549 | 1 | public function intersectionMulti(...$array): self |
|
| 3557 | |||
| 3558 | /** |
||
| 3559 | * Return a boolean flag which indicates whether the two input arrays have any common elements. |
||
| 3560 | * |
||
| 3561 | * EXAMPLE: <code> |
||
| 3562 | * a(['foo', 'bar'])->intersects(['föö', 'bär']); // false |
||
| 3563 | * </code> |
||
| 3564 | * |
||
| 3565 | * @param array $search |
||
| 3566 | * |
||
| 3567 | * @return bool |
||
| 3568 | * |
||
| 3569 | * @psalm-param array<mixed,mixed>|array<TKey,T> $search |
||
| 3570 | */ |
||
| 3571 | 1 | public function intersects(array $search): bool |
|
| 3575 | |||
| 3576 | /** |
||
| 3577 | * Invoke a function on all of an array's values. |
||
| 3578 | * |
||
| 3579 | * @param callable $callable |
||
| 3580 | * @param mixed $arguments |
||
| 3581 | * |
||
| 3582 | * @return static |
||
| 3583 | * <p>(Immutable)</p> |
||
| 3584 | * |
||
| 3585 | * @psalm-param callable(T=,mixed):mixed $callable |
||
| 3586 | * @psalm-return static<TKey,T> |
||
| 3587 | * @psalm-mutation-free |
||
| 3588 | */ |
||
| 3589 | 1 | public function invoke($callable, $arguments = []): self |
|
| 3613 | |||
| 3614 | /** |
||
| 3615 | * Check whether array is associative or not. |
||
| 3616 | * |
||
| 3617 | * EXAMPLE: <code> |
||
| 3618 | * a(['foo' => 'bar', 2, 3])->isAssoc(); // true |
||
| 3619 | * </code> |
||
| 3620 | * |
||
| 3621 | * @param bool $recursive |
||
| 3622 | * |
||
| 3623 | * @return bool |
||
| 3624 | * <p>Returns true if associative, false otherwise.</p> |
||
| 3625 | */ |
||
| 3626 | 15 | View Code Duplication | public function isAssoc(bool $recursive = false): bool |
| 3641 | |||
| 3642 | /** |
||
| 3643 | * Check if a given key or keys are empty. |
||
| 3644 | * |
||
| 3645 | * @param int|int[]|string|string[]|null $keys |
||
| 3646 | * |
||
| 3647 | * @return bool |
||
| 3648 | * <p>Returns true if empty, false otherwise.</p> |
||
| 3649 | * @psalm-mutation-free |
||
| 3650 | */ |
||
| 3651 | 45 | public function isEmpty($keys = null): bool |
|
| 3669 | |||
| 3670 | /** |
||
| 3671 | * Check if the current array is equal to the given "$array" or not. |
||
| 3672 | * |
||
| 3673 | * EXAMPLE: <code> |
||
| 3674 | * a(['💩'])->isEqual(['💩']); // true |
||
| 3675 | * </code> |
||
| 3676 | * |
||
| 3677 | * @param array $array |
||
| 3678 | * |
||
| 3679 | * @return bool |
||
| 3680 | * |
||
| 3681 | * @psalm-param array<mixed,mixed> $array |
||
| 3682 | */ |
||
| 3683 | 1 | public function isEqual(array $array): bool |
|
| 3687 | |||
| 3688 | /** |
||
| 3689 | * Check if the current array is a multi-array. |
||
| 3690 | * |
||
| 3691 | * EXAMPLE: <code> |
||
| 3692 | * a(['foo' => [1, 2 , 3]])->isMultiArray(); // true |
||
| 3693 | * </code> |
||
| 3694 | * |
||
| 3695 | * @return bool |
||
| 3696 | */ |
||
| 3697 | 22 | public function isMultiArray(): bool |
|
| 3707 | |||
| 3708 | /** |
||
| 3709 | * Check whether array is numeric or not. |
||
| 3710 | * |
||
| 3711 | * @return bool |
||
| 3712 | * <p>Returns true if numeric, false otherwise.</p> |
||
| 3713 | */ |
||
| 3714 | 5 | View Code Duplication | public function isNumeric(): bool |
| 3729 | |||
| 3730 | /** |
||
| 3731 | * Check if the current array is sequential [0, 1, 2, 3, 4, 5 ...] or not. |
||
| 3732 | * |
||
| 3733 | * EXAMPLE: <code> |
||
| 3734 | * a([0 => 'foo', 1 => 'lall', 2 => 'foobar'])->isSequential(); // true |
||
| 3735 | * </code> |
||
| 3736 | * |
||
| 3737 | * INFO: If the array is empty we count it as non-sequential. |
||
| 3738 | * |
||
| 3739 | * @param bool $recursive |
||
| 3740 | * |
||
| 3741 | * @return bool |
||
| 3742 | * @psalm-mutation-free |
||
| 3743 | */ |
||
| 3744 | 10 | public function isSequential(bool $recursive = false): bool |
|
| 3774 | |||
| 3775 | /** |
||
| 3776 | * @return array |
||
| 3777 | * |
||
| 3778 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 3779 | */ |
||
| 3780 | 2 | public function jsonSerialize(): array |
|
| 3784 | |||
| 3785 | /** |
||
| 3786 | * Gets the key/index of the element at the current internal iterator position. |
||
| 3787 | * |
||
| 3788 | * @return int|string|null |
||
| 3789 | */ |
||
| 3790 | public function key() |
||
| 3794 | |||
| 3795 | /** |
||
| 3796 | * Checks if the given key exists in the provided array. |
||
| 3797 | * |
||
| 3798 | * INFO: This method only use "array_key_exists()" if you want to use "dot"-notation, |
||
| 3799 | * then you need to use "Arrayy->offsetExists()". |
||
| 3800 | * |
||
| 3801 | * @param int|string $key the key to look for |
||
| 3802 | * |
||
| 3803 | * @return bool |
||
| 3804 | * @psalm-mutation-free |
||
| 3805 | */ |
||
| 3806 | 174 | public function keyExists($key): bool |
|
| 3816 | |||
| 3817 | /** |
||
| 3818 | * Get all keys from the current array. |
||
| 3819 | * |
||
| 3820 | * EXAMPLE: <code> |
||
| 3821 | * a([1 => 'foo', 2 => 'foo2', 3 => 'bar'])->keys(); // Arrayy[1, 2, 3] |
||
| 3822 | * </code> |
||
| 3823 | * |
||
| 3824 | * @param bool $recursive [optional] <p> |
||
| 3825 | * Get all keys, also from all sub-arrays from an multi-dimensional array. |
||
| 3826 | * </p> |
||
| 3827 | * @param mixed|null $search_values [optional] <p> |
||
| 3828 | * If specified, then only keys containing these values are returned. |
||
| 3829 | * </p> |
||
| 3830 | * @param bool $strict [optional] <p> |
||
| 3831 | * Determines if strict comparison (===) should be used during the search. |
||
| 3832 | * </p> |
||
| 3833 | * |
||
| 3834 | * @return static |
||
| 3835 | * <p>(Immutable) An array of all the keys in input.</p> |
||
| 3836 | * |
||
| 3837 | * @psalm-return static<array-key,TKey> |
||
| 3838 | * @psalm-mutation-free |
||
| 3839 | */ |
||
| 3840 | 29 | public function keys( |
|
| 3911 | |||
| 3912 | /** |
||
| 3913 | * Sort an array by key in reverse order. |
||
| 3914 | * |
||
| 3915 | * @param int $sort_flags [optional] <p> |
||
| 3916 | * You may modify the behavior of the sort using the optional |
||
| 3917 | * parameter sort_flags, for details |
||
| 3918 | * see sort. |
||
| 3919 | * </p> |
||
| 3920 | * |
||
| 3921 | * @return $this |
||
| 3922 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 3923 | * |
||
| 3924 | * @psalm-return static<TKey,T> |
||
| 3925 | */ |
||
| 3926 | 4 | public function krsort(int $sort_flags = 0): self |
|
| 3934 | |||
| 3935 | /** |
||
| 3936 | * Sort an array by key in reverse order. |
||
| 3937 | * |
||
| 3938 | * @param int $sort_flags [optional] <p> |
||
| 3939 | * You may modify the behavior of the sort using the optional |
||
| 3940 | * parameter sort_flags, for details |
||
| 3941 | * see sort. |
||
| 3942 | * </p> |
||
| 3943 | * |
||
| 3944 | * @return $this |
||
| 3945 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 3946 | * |
||
| 3947 | * @psalm-return static<TKey,T> |
||
| 3948 | * @psalm-mutation-free |
||
| 3949 | */ |
||
| 3950 | 4 | public function krsortImmutable(int $sort_flags = 0): self |
|
| 3961 | |||
| 3962 | /** |
||
| 3963 | * Get the last value from the current array. |
||
| 3964 | * |
||
| 3965 | * EXAMPLE: <code> |
||
| 3966 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->last(); // 'lall' |
||
| 3967 | * </code> |
||
| 3968 | * |
||
| 3969 | * @return mixed|null |
||
| 3970 | * <p>Return null if there wasn't a element.</p> |
||
| 3971 | * @psalm-mutation-free |
||
| 3972 | */ |
||
| 3973 | 17 | public function last() |
|
| 3982 | |||
| 3983 | /** |
||
| 3984 | * Get the last key from the current array. |
||
| 3985 | * |
||
| 3986 | * @return mixed|null |
||
| 3987 | * <p>Return null if there wasn't a element.</p> |
||
| 3988 | * @psalm-mutation-free |
||
| 3989 | */ |
||
| 3990 | 21 | public function lastKey() |
|
| 3996 | |||
| 3997 | /** |
||
| 3998 | * Get the last value(s) from the current array. |
||
| 3999 | * |
||
| 4000 | * EXAMPLE: <code> |
||
| 4001 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->lasts(2); // Arrayy[0 => 'bar', 1 => 'lall'] |
||
| 4002 | * </code> |
||
| 4003 | * |
||
| 4004 | * @param int|null $number |
||
| 4005 | * |
||
| 4006 | * @return static |
||
| 4007 | * <p>(Immutable)</p> |
||
| 4008 | * |
||
| 4009 | * @psalm-return static<TKey,T> |
||
| 4010 | * @psalm-mutation-free |
||
| 4011 | */ |
||
| 4012 | 13 | public function lastsImmutable(int $number = null): self |
|
| 4042 | |||
| 4043 | /** |
||
| 4044 | * Get the last value(s) from the current array. |
||
| 4045 | * |
||
| 4046 | * EXAMPLE: <code> |
||
| 4047 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->lasts(2); // Arrayy[0 => 'bar', 1 => 'lall'] |
||
| 4048 | * </code> |
||
| 4049 | * |
||
| 4050 | * @param int|null $number |
||
| 4051 | * |
||
| 4052 | * @return $this |
||
| 4053 | * <p>(Mutable)</p> |
||
| 4054 | * |
||
| 4055 | * @psalm-return static<TKey,T> |
||
| 4056 | */ |
||
| 4057 | 13 | public function lastsMutable(int $number = null): self |
|
| 4068 | |||
| 4069 | /** |
||
| 4070 | * Count the values from the current array. |
||
| 4071 | * |
||
| 4072 | * alias: for "Arrayy->count()" |
||
| 4073 | * |
||
| 4074 | * @param int $mode |
||
| 4075 | * |
||
| 4076 | * @return int |
||
| 4077 | * |
||
| 4078 | * @see Arrayy::count() |
||
| 4079 | */ |
||
| 4080 | 20 | public function length(int $mode = \COUNT_NORMAL): int |
|
| 4084 | |||
| 4085 | /** |
||
| 4086 | * Apply the given function to the every element of the array, |
||
| 4087 | * collecting the results. |
||
| 4088 | * |
||
| 4089 | * EXAMPLE: <code> |
||
| 4090 | * a(['foo', 'Foo'])->map('mb_strtoupper'); // Arrayy['FOO', 'FOO'] |
||
| 4091 | * </code> |
||
| 4092 | * |
||
| 4093 | * @param callable $callable |
||
| 4094 | * @param bool $useKeyAsSecondParameter |
||
| 4095 | * @param mixed ...$arguments |
||
| 4096 | * |
||
| 4097 | * @return static |
||
| 4098 | * <p>(Immutable) Arrayy object with modified elements.</p> |
||
| 4099 | * |
||
| 4100 | * @psalm-param callable(T,TKey=,mixed=):mixed $callable |
||
| 4101 | * @psalm-return static<TKey,T> |
||
| 4102 | * @psalm-mutation-free |
||
| 4103 | */ |
||
| 4104 | 6 | public function map( |
|
| 4137 | |||
| 4138 | /** |
||
| 4139 | * Check if all items in current array match a truth test. |
||
| 4140 | * |
||
| 4141 | * EXAMPLE: <code> |
||
| 4142 | * $closure = function ($value, $key) { |
||
| 4143 | * return ($value % 2 === 0); |
||
| 4144 | * }; |
||
| 4145 | * a([2, 4, 8])->matches($closure); // true |
||
| 4146 | * </code> |
||
| 4147 | * |
||
| 4148 | * @param \Closure $closure |
||
| 4149 | * |
||
| 4150 | * @return bool |
||
| 4151 | */ |
||
| 4152 | 15 | View Code Duplication | public function matches(\Closure $closure): bool |
| 4168 | |||
| 4169 | /** |
||
| 4170 | * Check if any item in the current array matches a truth test. |
||
| 4171 | * |
||
| 4172 | * EXAMPLE: <code> |
||
| 4173 | * $closure = function ($value, $key) { |
||
| 4174 | * return ($value % 2 === 0); |
||
| 4175 | * }; |
||
| 4176 | * a([1, 4, 7])->matches($closure); // true |
||
| 4177 | * </code> |
||
| 4178 | * |
||
| 4179 | * @param \Closure $closure |
||
| 4180 | * |
||
| 4181 | * @return bool |
||
| 4182 | */ |
||
| 4183 | 14 | View Code Duplication | public function matchesAny(\Closure $closure): bool |
| 4199 | |||
| 4200 | /** |
||
| 4201 | * Get the max value from an array. |
||
| 4202 | * |
||
| 4203 | * EXAMPLE: <code> |
||
| 4204 | * a([-9, -8, -7, 1.32])->max(); // 1.32 |
||
| 4205 | * </code> |
||
| 4206 | * |
||
| 4207 | * @return false|mixed |
||
| 4208 | * <p>Will return false if there are no values.</p> |
||
| 4209 | */ |
||
| 4210 | 10 | View Code Duplication | public function max() |
| 4230 | |||
| 4231 | /** |
||
| 4232 | * Merge the new $array into the current array. |
||
| 4233 | * |
||
| 4234 | * - keep key,value from the current array, also if the index is in the new $array |
||
| 4235 | * |
||
| 4236 | * EXAMPLE: <code> |
||
| 4237 | * $array1 = [1 => 'one', 'foo' => 'bar1']; |
||
| 4238 | * $array2 = ['foo' => 'bar2', 3 => 'three']; |
||
| 4239 | * a($array1)->mergeAppendKeepIndex($array2); // Arrayy[1 => 'one', 'foo' => 'bar2', 3 => 'three'] |
||
| 4240 | * // --- |
||
| 4241 | * $array1 = [0 => 'one', 1 => 'foo']; |
||
| 4242 | * $array2 = [0 => 'foo', 1 => 'bar2']; |
||
| 4243 | * a($array1)->mergeAppendKeepIndex($array2); // Arrayy[0 => 'foo', 1 => 'bar2'] |
||
| 4244 | * </code> |
||
| 4245 | * |
||
| 4246 | * @param array $array |
||
| 4247 | * @param bool $recursive |
||
| 4248 | * |
||
| 4249 | * @return static |
||
| 4250 | * <p>(Immutable)</p> |
||
| 4251 | * |
||
| 4252 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 4253 | * @psalm-return static<int|TKey,T> |
||
| 4254 | * @psalm-mutation-free |
||
| 4255 | */ |
||
| 4256 | 33 | View Code Duplication | public function mergeAppendKeepIndex(array $array = [], bool $recursive = false): self |
| 4271 | |||
| 4272 | /** |
||
| 4273 | * Merge the new $array into the current array. |
||
| 4274 | * |
||
| 4275 | * - replace duplicate assoc-keys from the current array with the key,values from the new $array |
||
| 4276 | * - create new indexes |
||
| 4277 | * |
||
| 4278 | * EXAMPLE: <code> |
||
| 4279 | * $array1 = [1 => 'one', 'foo' => 'bar1']; |
||
| 4280 | * $array2 = ['foo' => 'bar2', 3 => 'three']; |
||
| 4281 | * a($array1)->mergeAppendNewIndex($array2); // Arrayy[0 => 'one', 'foo' => 'bar2', 1 => 'three'] |
||
| 4282 | * // --- |
||
| 4283 | * $array1 = [0 => 'one', 1 => 'foo']; |
||
| 4284 | * $array2 = [0 => 'foo', 1 => 'bar2']; |
||
| 4285 | * a($array1)->mergeAppendNewIndex($array2); // Arrayy[0 => 'one', 1 => 'foo', 2 => 'foo', 3 => 'bar2'] |
||
| 4286 | * </code> |
||
| 4287 | * |
||
| 4288 | * @param array $array |
||
| 4289 | * @param bool $recursive |
||
| 4290 | * |
||
| 4291 | * @return static |
||
| 4292 | * <p>(Immutable)</p> |
||
| 4293 | * |
||
| 4294 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 4295 | * @psalm-return static<TKey,T> |
||
| 4296 | * @psalm-mutation-free |
||
| 4297 | */ |
||
| 4298 | 20 | View Code Duplication | public function mergeAppendNewIndex(array $array = [], bool $recursive = false): self |
| 4313 | |||
| 4314 | /** |
||
| 4315 | * Merge the the current array into the $array. |
||
| 4316 | * |
||
| 4317 | * - use key,value from the new $array, also if the index is in the current array |
||
| 4318 | * |
||
| 4319 | * EXAMPLE: <code> |
||
| 4320 | * $array1 = [1 => 'one', 'foo' => 'bar1']; |
||
| 4321 | * $array2 = ['foo' => 'bar2', 3 => 'three']; |
||
| 4322 | * a($array1)->mergePrependKeepIndex($array2); // Arrayy['foo' => 'bar1', 3 => 'three', 1 => 'one'] |
||
| 4323 | * // --- |
||
| 4324 | * $array1 = [0 => 'one', 1 => 'foo']; |
||
| 4325 | * $array2 = [0 => 'foo', 1 => 'bar2']; |
||
| 4326 | * a($array1)->mergePrependKeepIndex($array2); // Arrayy[0 => 'one', 1 => 'foo'] |
||
| 4327 | * </code> |
||
| 4328 | * |
||
| 4329 | * @param array $array |
||
| 4330 | * @param bool $recursive |
||
| 4331 | * |
||
| 4332 | * @return static |
||
| 4333 | * <p>(Immutable)</p> |
||
| 4334 | * |
||
| 4335 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 4336 | * @psalm-return static<TKey,T> |
||
| 4337 | * @psalm-mutation-free |
||
| 4338 | */ |
||
| 4339 | 17 | View Code Duplication | public function mergePrependKeepIndex(array $array = [], bool $recursive = false): self |
| 4354 | |||
| 4355 | /** |
||
| 4356 | * Merge the current array into the new $array. |
||
| 4357 | * |
||
| 4358 | * - replace duplicate assoc-keys from new $array with the key,values from the current array |
||
| 4359 | * - create new indexes |
||
| 4360 | * |
||
| 4361 | * EXAMPLE: <code> |
||
| 4362 | * $array1 = [1 => 'one', 'foo' => 'bar1']; |
||
| 4363 | * $array2 = ['foo' => 'bar2', 3 => 'three']; |
||
| 4364 | * a($array1)->mergePrependNewIndex($array2); // Arrayy['foo' => 'bar1', 0 => 'three', 1 => 'one'] |
||
| 4365 | * // --- |
||
| 4366 | * $array1 = [0 => 'one', 1 => 'foo']; |
||
| 4367 | * $array2 = [0 => 'foo', 1 => 'bar2']; |
||
| 4368 | * a($array1)->mergePrependNewIndex($array2); // Arrayy[0 => 'foo', 1 => 'bar2', 2 => 'one', 3 => 'foo'] |
||
| 4369 | * </code> |
||
| 4370 | * |
||
| 4371 | * @param array $array |
||
| 4372 | * @param bool $recursive |
||
| 4373 | * |
||
| 4374 | * @return static |
||
| 4375 | * <p>(Immutable)</p> |
||
| 4376 | * |
||
| 4377 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 4378 | * @psalm-return static<TKey,T> |
||
| 4379 | * @psalm-mutation-free |
||
| 4380 | */ |
||
| 4381 | 21 | View Code Duplication | public function mergePrependNewIndex(array $array = [], bool $recursive = false): self |
| 4396 | |||
| 4397 | /** |
||
| 4398 | * @return ArrayyMeta|mixed|static |
||
| 4399 | */ |
||
| 4400 | 18 | public static function meta() |
|
| 4404 | |||
| 4405 | /** |
||
| 4406 | * Get the min value from an array. |
||
| 4407 | * |
||
| 4408 | * EXAMPLE: <code> |
||
| 4409 | * a([-9, -8, -7, 1.32])->min(); // -9 |
||
| 4410 | * </code> |
||
| 4411 | * |
||
| 4412 | * @return false|mixed |
||
| 4413 | * <p>Will return false if there are no values.</p> |
||
| 4414 | */ |
||
| 4415 | 10 | View Code Duplication | public function min() |
| 4435 | |||
| 4436 | /** |
||
| 4437 | * Get the most used value from the array. |
||
| 4438 | * |
||
| 4439 | * @return mixed|null |
||
| 4440 | * <p>(Immutable) Return null if there wasn't a element.</p> |
||
| 4441 | * @psalm-mutation-free |
||
| 4442 | */ |
||
| 4443 | 3 | public function mostUsedValue() |
|
| 4447 | |||
| 4448 | /** |
||
| 4449 | * Get the most used value from the array. |
||
| 4450 | * |
||
| 4451 | * @param int|null $number <p>How many values you will take?</p> |
||
| 4452 | * |
||
| 4453 | * @return static |
||
| 4454 | * <p>(Immutable)</p> |
||
| 4455 | * |
||
| 4456 | * @psalm-return static<TKey,T> |
||
| 4457 | * @psalm-mutation-free |
||
| 4458 | */ |
||
| 4459 | 3 | public function mostUsedValues(int $number = null): self |
|
| 4463 | |||
| 4464 | /** |
||
| 4465 | * Move an array element to a new index. |
||
| 4466 | * |
||
| 4467 | * EXAMPLE: <code> |
||
| 4468 | * $arr2 = new A(['A' => 'a', 'B' => 'b', 'C' => 'c', 'D' => 'd', 'E' => 'e']); |
||
| 4469 | * $newArr2 = $arr2->moveElement('D', 1); // Arrayy['A' => 'a', 'D' => 'd', 'B' => 'b', 'C' => 'c', 'E' => 'e'] |
||
| 4470 | * </code> |
||
| 4471 | * |
||
| 4472 | * @param int|string $from |
||
| 4473 | * @param int $to |
||
| 4474 | * |
||
| 4475 | * @return static |
||
| 4476 | * <p>(Immutable)</p> |
||
| 4477 | * |
||
| 4478 | * @psalm-return static<TKey,T> |
||
| 4479 | * @psalm-mutation-free |
||
| 4480 | */ |
||
| 4481 | 1 | public function moveElement($from, $to): self |
|
| 4514 | |||
| 4515 | /** |
||
| 4516 | * Move an array element to the first place. |
||
| 4517 | * |
||
| 4518 | * INFO: Instead of "Arrayy->moveElement()" this method will NOT |
||
| 4519 | * loss the keys of an indexed array. |
||
| 4520 | * |
||
| 4521 | * @param int|string $key |
||
| 4522 | * |
||
| 4523 | * @return static |
||
| 4524 | * <p>(Immutable)</p> |
||
| 4525 | * |
||
| 4526 | * @psalm-return static<TKey,T> |
||
| 4527 | * @psalm-mutation-free |
||
| 4528 | */ |
||
| 4529 | 1 | View Code Duplication | public function moveElementToFirstPlace($key): self |
| 4545 | |||
| 4546 | /** |
||
| 4547 | * Move an array element to the last place. |
||
| 4548 | * |
||
| 4549 | * INFO: Instead of "Arrayy->moveElement()" this method will NOT |
||
| 4550 | * loss the keys of an indexed array. |
||
| 4551 | * |
||
| 4552 | * @param int|string $key |
||
| 4553 | * |
||
| 4554 | * @return static |
||
| 4555 | * <p>(Immutable)</p> |
||
| 4556 | * |
||
| 4557 | * @psalm-return static<TKey,T> |
||
| 4558 | * @psalm-mutation-free |
||
| 4559 | */ |
||
| 4560 | 1 | View Code Duplication | public function moveElementToLastPlace($key): self |
| 4576 | |||
| 4577 | /** |
||
| 4578 | * Moves the internal iterator position to the next element and returns this element. |
||
| 4579 | * |
||
| 4580 | * @return false|mixed |
||
| 4581 | * <p>(Mutable) Will return false if there are no values.</p> |
||
| 4582 | */ |
||
| 4583 | public function next() |
||
| 4587 | |||
| 4588 | /** |
||
| 4589 | * Get the next nth keys and values from the array. |
||
| 4590 | * |
||
| 4591 | * @param int $step |
||
| 4592 | * @param int $offset |
||
| 4593 | * |
||
| 4594 | * @return static |
||
| 4595 | * <p>(Immutable)</p> |
||
| 4596 | * |
||
| 4597 | * @psalm-return static<TKey,T> |
||
| 4598 | * @psalm-mutation-free |
||
| 4599 | */ |
||
| 4600 | 1 | public function nth(int $step, int $offset = 0): self |
|
| 4619 | |||
| 4620 | /** |
||
| 4621 | * Get a subset of the items from the given array. |
||
| 4622 | * |
||
| 4623 | * @param int[]|string[] $keys |
||
| 4624 | * |
||
| 4625 | * @return static |
||
| 4626 | * <p>(Immutable)</p> |
||
| 4627 | * |
||
| 4628 | * @psalm-param array-key[] $keys |
||
| 4629 | * @psalm-return static<TKey,T> |
||
| 4630 | * @psalm-mutation-free |
||
| 4631 | */ |
||
| 4632 | 1 | View Code Duplication | public function only(array $keys): self |
| 4650 | |||
| 4651 | /** |
||
| 4652 | * Pad array to the specified size with a given value. |
||
| 4653 | * |
||
| 4654 | * @param int $size <p>Size of the result array.</p> |
||
| 4655 | * @param mixed $value <p>Empty value by default.</p> |
||
| 4656 | * |
||
| 4657 | * @return static |
||
| 4658 | * <p>(Immutable) Arrayy object padded to $size with $value.</p> |
||
| 4659 | * |
||
| 4660 | * @psalm-return static<TKey,T> |
||
| 4661 | * @psalm-mutation-free |
||
| 4662 | */ |
||
| 4663 | 5 | public function pad(int $size, $value): self |
|
| 4671 | |||
| 4672 | /** |
||
| 4673 | * Partitions this array in two array according to a predicate. |
||
| 4674 | * Keys are preserved in the resulting array. |
||
| 4675 | * |
||
| 4676 | * @param \Closure $closure |
||
| 4677 | * <p>The predicate on which to partition.</p> |
||
| 4678 | * |
||
| 4679 | * @return array<int, static> |
||
| 4680 | * <p>An array with two elements. The first element contains the array |
||
| 4681 | * of elements where the predicate returned TRUE, the second element |
||
| 4682 | * contains the array of elements where the predicate returned FALSE.</p> |
||
| 4683 | * |
||
| 4684 | * @psalm-return array<int, static<TKey,T>> |
||
| 4685 | */ |
||
| 4686 | 1 | public function partition(\Closure $closure): array |
|
| 4702 | |||
| 4703 | /** |
||
| 4704 | * Pop a specified value off the end of the current array. |
||
| 4705 | * |
||
| 4706 | * @return mixed|null |
||
| 4707 | * <p>(Mutable) The popped element from the current array or null if the array is e.g. empty.</p> |
||
| 4708 | */ |
||
| 4709 | 5 | public function pop() |
|
| 4715 | |||
| 4716 | /** |
||
| 4717 | * Prepend a (key) + value to the current array. |
||
| 4718 | * |
||
| 4719 | * EXAMPLE: <code> |
||
| 4720 | * a(['fòô' => 'bàř'])->prepend('foo'); // Arrayy[0 => 'foo', 'fòô' => 'bàř'] |
||
| 4721 | * </code> |
||
| 4722 | * |
||
| 4723 | * @param mixed $value |
||
| 4724 | * @param mixed $key |
||
| 4725 | * |
||
| 4726 | * @return $this |
||
| 4727 | * <p>(Mutable) Return this Arrayy object, with the prepended value.</p> |
||
| 4728 | * |
||
| 4729 | * @psalm-return static<TKey,T> |
||
| 4730 | */ |
||
| 4731 | 11 | public function prepend($value, $key = null) |
|
| 4747 | |||
| 4748 | /** |
||
| 4749 | * Prepend a (key) + value to the current array. |
||
| 4750 | * |
||
| 4751 | * EXAMPLE: <code> |
||
| 4752 | * a(['fòô' => 'bàř'])->prependImmutable('foo')->getArray(); // [0 => 'foo', 'fòô' => 'bàř'] |
||
| 4753 | * </code> |
||
| 4754 | * |
||
| 4755 | * @param mixed $value |
||
| 4756 | * @param mixed $key |
||
| 4757 | * |
||
| 4758 | * @return $this |
||
| 4759 | * <p>(Immutable) Return this Arrayy object, with the prepended value.</p> |
||
| 4760 | * |
||
| 4761 | * @psalm-return static<TKey,T> |
||
| 4762 | * @psalm-mutation-free |
||
| 4763 | */ |
||
| 4764 | 1 | View Code Duplication | public function prependImmutable($value, $key = null) |
| 4789 | |||
| 4790 | /** |
||
| 4791 | * Add a suffix to each key. |
||
| 4792 | * |
||
| 4793 | * @param mixed $suffix |
||
| 4794 | * |
||
| 4795 | * @return static |
||
| 4796 | * <p>(Immutable) Return an Arrayy object, with the prepended keys.</p> |
||
| 4797 | * |
||
| 4798 | * @psalm-return static<TKey,T> |
||
| 4799 | * @psalm-mutation-free |
||
| 4800 | */ |
||
| 4801 | 10 | View Code Duplication | public function prependToEachKey($suffix): self |
| 4827 | |||
| 4828 | /** |
||
| 4829 | * Add a suffix to each value. |
||
| 4830 | * |
||
| 4831 | * @param mixed $suffix |
||
| 4832 | * |
||
| 4833 | * @return static |
||
| 4834 | * <p>(Immutable) Return an Arrayy object, with the prepended values.</p> |
||
| 4835 | * |
||
| 4836 | * @psalm-return static<TKey,T> |
||
| 4837 | * @psalm-mutation-free |
||
| 4838 | */ |
||
| 4839 | 10 | View Code Duplication | public function prependToEachValue($suffix): self |
| 4867 | |||
| 4868 | /** |
||
| 4869 | * Return the value of a given key and |
||
| 4870 | * delete the key. |
||
| 4871 | * |
||
| 4872 | * @param int|int[]|string|string[]|null $keyOrKeys |
||
| 4873 | * @param mixed $fallback |
||
| 4874 | * |
||
| 4875 | * @return mixed |
||
| 4876 | */ |
||
| 4877 | 6 | public function pull($keyOrKeys = null, $fallback = null) |
|
| 4899 | |||
| 4900 | /** |
||
| 4901 | * Push one or more values onto the end of array at once. |
||
| 4902 | * |
||
| 4903 | * @param mixed ...$args |
||
| 4904 | * |
||
| 4905 | * @return $this |
||
| 4906 | * <p>(Mutable) Return this Arrayy object, with pushed elements to the end of array.</p> |
||
| 4907 | * |
||
| 4908 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
| 4909 | * |
||
| 4910 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$args |
||
| 4911 | * @psalm-return static<TKey,T> |
||
| 4912 | */ |
||
| 4913 | 9 | View Code Duplication | public function push(...$args) |
| 4931 | |||
| 4932 | /** |
||
| 4933 | * Get a random value from the current array. |
||
| 4934 | * |
||
| 4935 | * EXAMPLE: <code> |
||
| 4936 | * a([1, 2, 3, 4])->randomImmutable(2); // e.g.: Arrayy[1, 4] |
||
| 4937 | * </code> |
||
| 4938 | * |
||
| 4939 | * @param int|null $number <p>How many values you will take?</p> |
||
| 4940 | * |
||
| 4941 | * @return static |
||
| 4942 | * <p>(Immutable)</p> |
||
| 4943 | * |
||
| 4944 | * @psalm-return static<int|array-key,T> |
||
| 4945 | */ |
||
| 4946 | 19 | public function randomImmutable(int $number = null): self |
|
| 4979 | |||
| 4980 | /** |
||
| 4981 | * Pick a random key/index from the keys of this array. |
||
| 4982 | * |
||
| 4983 | * EXAMPLE: <code> |
||
| 4984 | * $arrayy = A::create([1 => 'one', 2 => 'two']); |
||
| 4985 | * $arrayy->randomKey(); // e.g. 2 |
||
| 4986 | * </code> |
||
| 4987 | * |
||
| 4988 | * @throws \RangeException If array is empty |
||
| 4989 | * |
||
| 4990 | * @return mixed |
||
| 4991 | * <p>Get a key/index or null if there wasn't a key/index.</p> |
||
| 4992 | */ |
||
| 4993 | 4 | public function randomKey() |
|
| 5003 | |||
| 5004 | /** |
||
| 5005 | * Pick a given number of random keys/indexes out of this array. |
||
| 5006 | * |
||
| 5007 | * EXAMPLE: <code> |
||
| 5008 | * a([1 => 'one', 2 => 'two'])->randomKeys(); // e.g. Arrayy[1, 2] |
||
| 5009 | * </code> |
||
| 5010 | * |
||
| 5011 | * @param int $number <p>The number of keys/indexes (should be <= \count($this->array))</p> |
||
| 5012 | * |
||
| 5013 | * @throws \RangeException If array is empty |
||
| 5014 | * |
||
| 5015 | * @return static |
||
| 5016 | * <p>(Immutable)</p> |
||
| 5017 | * |
||
| 5018 | * @psalm-return static<TKey,T> |
||
| 5019 | */ |
||
| 5020 | 13 | public function randomKeys(int $number): self |
|
| 5048 | |||
| 5049 | /** |
||
| 5050 | * Get a random value from the current array. |
||
| 5051 | * |
||
| 5052 | * EXAMPLE: <code> |
||
| 5053 | * a([1, 2, 3, 4])->randomMutable(2); // e.g.: Arrayy[1, 4] |
||
| 5054 | * </code> |
||
| 5055 | * |
||
| 5056 | * @param int|null $number <p>How many values you will take?</p> |
||
| 5057 | * |
||
| 5058 | * @return $this |
||
| 5059 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 5060 | * |
||
| 5061 | * @psalm-return static<TKey,T> |
||
| 5062 | */ |
||
| 5063 | 17 | public function randomMutable(int $number = null): self |
|
| 5088 | |||
| 5089 | /** |
||
| 5090 | * Pick a random value from the values of this array. |
||
| 5091 | * |
||
| 5092 | * EXAMPLE: <code> |
||
| 5093 | * a([1 => 'one', 2 => 'two'])->randomValue(); // e.g. 'one' |
||
| 5094 | * </code> |
||
| 5095 | * |
||
| 5096 | * @return mixed |
||
| 5097 | * <p>Get a random value or null if there wasn't a value.</p> |
||
| 5098 | */ |
||
| 5099 | 4 | public function randomValue() |
|
| 5109 | |||
| 5110 | /** |
||
| 5111 | * Pick a given number of random values out of this array. |
||
| 5112 | * |
||
| 5113 | * EXAMPLE: <code> |
||
| 5114 | * a([1 => 'one', 2 => 'two'])->randomValues(); // e.g. Arrayy['one', 'two'] |
||
| 5115 | * </code> |
||
| 5116 | * |
||
| 5117 | * @param int $number |
||
| 5118 | * |
||
| 5119 | * @return static |
||
| 5120 | * <p>(Mutable)</p> |
||
| 5121 | * |
||
| 5122 | * @psalm-return static<TKey,T> |
||
| 5123 | */ |
||
| 5124 | 7 | public function randomValues(int $number): self |
|
| 5128 | |||
| 5129 | /** |
||
| 5130 | * Get a random value from an array, with the ability to skew the results. |
||
| 5131 | * |
||
| 5132 | * EXAMPLE: <code> |
||
| 5133 | * a([0 => 3, 1 => 4])->randomWeighted([1 => 4]); // e.g.: Arrayy[4] (has a 66% chance of returning 4) |
||
| 5134 | * </code> |
||
| 5135 | * |
||
| 5136 | * @param array $array |
||
| 5137 | * @param int|null $number <p>How many values you will take?</p> |
||
| 5138 | * |
||
| 5139 | * @return static<int,mixed> |
||
| 5140 | * <p>(Immutable)</p> |
||
| 5141 | * |
||
| 5142 | * @psalm-param array<mixed,mixed> $array |
||
| 5143 | * @psalm-return static<int|array-key,T> |
||
| 5144 | */ |
||
| 5145 | 9 | public function randomWeighted(array $array, int $number = null): self |
|
| 5160 | |||
| 5161 | /** |
||
| 5162 | * Reduce the current array via callable e.g. anonymous-function and return the end result. |
||
| 5163 | * |
||
| 5164 | * EXAMPLE: <code> |
||
| 5165 | * a([1, 2, 3, 4])->reduce( |
||
| 5166 | * function ($carry, $item) { |
||
| 5167 | * return $carry * $item; |
||
| 5168 | * }, |
||
| 5169 | * 1 |
||
| 5170 | * ); // Arrayy[24] |
||
| 5171 | * </code> |
||
| 5172 | * |
||
| 5173 | * @param callable $callable |
||
| 5174 | * @param mixed $initial |
||
| 5175 | * |
||
| 5176 | * @return static |
||
| 5177 | * <p>(Immutable)</p> |
||
| 5178 | * |
||
| 5179 | * @psalm-return static<TKey,T> |
||
| 5180 | * @psalm-mutation-free |
||
| 5181 | */ |
||
| 5182 | 18 | View Code Duplication | public function reduce($callable, $initial = []): self |
| 5194 | |||
| 5195 | /** |
||
| 5196 | * @param bool $unique |
||
| 5197 | * |
||
| 5198 | * @return static |
||
| 5199 | * <p>(Immutable)</p> |
||
| 5200 | * |
||
| 5201 | * @psalm-return static<TKey,T> |
||
| 5202 | * @psalm-mutation-free |
||
| 5203 | */ |
||
| 5204 | 14 | public function reduce_dimension(bool $unique = true): self |
|
| 5227 | |||
| 5228 | /** |
||
| 5229 | * Create a numerically re-indexed Arrayy object. |
||
| 5230 | * |
||
| 5231 | * EXAMPLE: <code> |
||
| 5232 | * a([2 => 1, 3 => 2])->reindex(); // Arrayy[0 => 1, 1 => 2] |
||
| 5233 | * </code> |
||
| 5234 | * |
||
| 5235 | * @return $this |
||
| 5236 | * <p>(Mutable) Return this Arrayy object, with re-indexed array-elements.</p> |
||
| 5237 | * |
||
| 5238 | * @psalm-return static<TKey,T> |
||
| 5239 | */ |
||
| 5240 | 9 | public function reindex(): self |
|
| 5248 | |||
| 5249 | /** |
||
| 5250 | * Return all items that fail the truth test. |
||
| 5251 | * |
||
| 5252 | * EXAMPLE: <code> |
||
| 5253 | * $closure = function ($value) { |
||
| 5254 | * return $value % 2 !== 0; |
||
| 5255 | * } |
||
| 5256 | * a([1, 2, 3, 4])->reject($closure); // Arrayy[1 => 2, 3 => 4] |
||
| 5257 | * </code> |
||
| 5258 | * |
||
| 5259 | * @param \Closure $closure |
||
| 5260 | * |
||
| 5261 | * @return static |
||
| 5262 | * <p>(Immutable)</p> |
||
| 5263 | * |
||
| 5264 | * @psalm-return static<TKey,T> |
||
| 5265 | * @psalm-mutation-free |
||
| 5266 | */ |
||
| 5267 | 1 | View Code Duplication | public function reject(\Closure $closure): self |
| 5284 | |||
| 5285 | /** |
||
| 5286 | * Remove a value from the current array (optional using dot-notation). |
||
| 5287 | * |
||
| 5288 | * EXAMPLE: <code> |
||
| 5289 | * a([1 => 'bar', 'foo' => 'foo'])->remove(1); // Arrayy['foo' => 'foo'] |
||
| 5290 | * </code> |
||
| 5291 | * |
||
| 5292 | * @param mixed $key |
||
| 5293 | * |
||
| 5294 | * @return static |
||
| 5295 | * <p>(Mutable)</p> |
||
| 5296 | * |
||
| 5297 | * @psalm-param TKey $key |
||
| 5298 | * @psalm-return static<TKey,T> |
||
| 5299 | */ |
||
| 5300 | 22 | public function remove($key) |
|
| 5323 | |||
| 5324 | /** |
||
| 5325 | * alias: for "Arrayy->removeValue()" |
||
| 5326 | * |
||
| 5327 | * @param mixed $element |
||
| 5328 | * |
||
| 5329 | * @return static |
||
| 5330 | * <p>(Immutable)</p> |
||
| 5331 | * |
||
| 5332 | * @psalm-param T $element |
||
| 5333 | * @psalm-return static<TKey,T> |
||
| 5334 | * @psalm-mutation-free |
||
| 5335 | */ |
||
| 5336 | 8 | public function removeElement($element) |
|
| 5340 | |||
| 5341 | /** |
||
| 5342 | * Remove the first value from the current array. |
||
| 5343 | * |
||
| 5344 | * EXAMPLE: <code> |
||
| 5345 | * a([1 => 'bar', 'foo' => 'foo'])->removeFirst(); // Arrayy['foo' => 'foo'] |
||
| 5346 | * </code> |
||
| 5347 | * |
||
| 5348 | * @return static |
||
| 5349 | * <p>(Immutable)</p> |
||
| 5350 | * |
||
| 5351 | * @psalm-return static<TKey,T> |
||
| 5352 | * @psalm-mutation-free |
||
| 5353 | */ |
||
| 5354 | 7 | View Code Duplication | public function removeFirst(): self |
| 5366 | |||
| 5367 | /** |
||
| 5368 | * Remove the last value from the current array. |
||
| 5369 | * |
||
| 5370 | * EXAMPLE: <code> |
||
| 5371 | * a([1 => 'bar', 'foo' => 'foo'])->removeLast(); // Arrayy[1 => 'bar'] |
||
| 5372 | * </code> |
||
| 5373 | * |
||
| 5374 | * @return static |
||
| 5375 | * <p>(Immutable)</p> |
||
| 5376 | * |
||
| 5377 | * @psalm-return static<TKey,T> |
||
| 5378 | * @psalm-mutation-free |
||
| 5379 | */ |
||
| 5380 | 7 | View Code Duplication | public function removeLast(): self |
| 5392 | |||
| 5393 | /** |
||
| 5394 | * Removes a particular value from an array (numeric or associative). |
||
| 5395 | * |
||
| 5396 | * EXAMPLE: <code> |
||
| 5397 | * a([1 => 'bar', 'foo' => 'foo'])->removeValue('foo'); // Arrayy[1 => 'bar'] |
||
| 5398 | * </code> |
||
| 5399 | * |
||
| 5400 | * @param mixed $value |
||
| 5401 | * |
||
| 5402 | * @return static |
||
| 5403 | * <p>(Immutable)</p> |
||
| 5404 | * |
||
| 5405 | * @psalm-param T $value |
||
| 5406 | * @psalm-return static<TKey,T> |
||
| 5407 | * @psalm-mutation-free |
||
| 5408 | */ |
||
| 5409 | 8 | public function removeValue($value): self |
|
| 5432 | |||
| 5433 | /** |
||
| 5434 | * Generate array of repeated arrays. |
||
| 5435 | * |
||
| 5436 | * @param int $times <p>How many times has to be repeated.</p> |
||
| 5437 | * |
||
| 5438 | * @return static |
||
| 5439 | * <p>(Immutable)</p> |
||
| 5440 | * |
||
| 5441 | * @psalm-return static<TKey,T> |
||
| 5442 | * @psalm-mutation-free |
||
| 5443 | */ |
||
| 5444 | 1 | public function repeat($times): self |
|
| 5456 | |||
| 5457 | /** |
||
| 5458 | * Replace a key with a new key/value pair. |
||
| 5459 | * |
||
| 5460 | * EXAMPLE: <code> |
||
| 5461 | * $arrayy = a([1 => 'foo', 2 => 'foo2', 3 => 'bar']); |
||
| 5462 | * $arrayy->replace(2, 'notfoo', 'notbar'); // Arrayy[1 => 'foo', 'notfoo' => 'notbar', 3 => 'bar'] |
||
| 5463 | * </code> |
||
| 5464 | * |
||
| 5465 | * @param mixed $oldKey |
||
| 5466 | * @param mixed $newKey |
||
| 5467 | * @param mixed $newValue |
||
| 5468 | * |
||
| 5469 | * @return static |
||
| 5470 | * <p>(Immutable)</p> |
||
| 5471 | * |
||
| 5472 | * @psalm-return static<TKey,T> |
||
| 5473 | * @psalm-mutation-free |
||
| 5474 | */ |
||
| 5475 | 5 | public function replace($oldKey, $newKey, $newValue): self |
|
| 5485 | |||
| 5486 | /** |
||
| 5487 | * Create an array using the current array as values and the other array as keys. |
||
| 5488 | * |
||
| 5489 | * EXAMPLE: <code> |
||
| 5490 | * $firstArray = [ |
||
| 5491 | * 1 => 'one', |
||
| 5492 | * 2 => 'two', |
||
| 5493 | * 3 => 'three', |
||
| 5494 | * ]; |
||
| 5495 | * $secondArray = [ |
||
| 5496 | * 'one' => 1, |
||
| 5497 | * 1 => 'one', |
||
| 5498 | * 2 => 2, |
||
| 5499 | * ]; |
||
| 5500 | * $arrayy = a($firstArray); |
||
| 5501 | * $arrayy->replaceAllKeys($secondArray); // Arrayy[1 => "one", 'one' => "two", 2 => "three"] |
||
| 5502 | * </code> |
||
| 5503 | * |
||
| 5504 | * @param array $keys <p>An array of keys.</p> |
||
| 5505 | * |
||
| 5506 | * @return static |
||
| 5507 | * <p>(Immutable) Arrayy object with keys from the other array.</p> |
||
| 5508 | * |
||
| 5509 | * @psalm-param array<mixed,mixed>|array<mixed,TKey> $keys |
||
| 5510 | * @psalm-return static<TKey,T> |
||
| 5511 | * @psalm-mutation-free |
||
| 5512 | */ |
||
| 5513 | 2 | public function replaceAllKeys(array $keys): self |
|
| 5521 | |||
| 5522 | /** |
||
| 5523 | * Create an array using the current array as keys and the other array as values. |
||
| 5524 | * |
||
| 5525 | * EXAMPLE: <code> |
||
| 5526 | * $firstArray = [ |
||
| 5527 | * 1 => 'one', |
||
| 5528 | * 2 => 'two', |
||
| 5529 | * 3 => 'three', |
||
| 5530 | * ]; |
||
| 5531 | * $secondArray = [ |
||
| 5532 | * 'one' => 1, |
||
| 5533 | * 1 => 'one', |
||
| 5534 | * 2 => 2, |
||
| 5535 | * ]; |
||
| 5536 | * $arrayy = a($firstArray); |
||
| 5537 | * $arrayy->replaceAllValues($secondArray); // Arrayy['one' => 1, 'two' => 'one', 'three' => 2] |
||
| 5538 | * </code> |
||
| 5539 | * |
||
| 5540 | * @param array $array <p>An array of values.</p> |
||
| 5541 | * |
||
| 5542 | * @return static |
||
| 5543 | * <p>(Immutable) Arrayy object with values from the other array.</p> |
||
| 5544 | * |
||
| 5545 | * @psalm-param array<mixed,T> $array |
||
| 5546 | * @psalm-return static<TKey,T> |
||
| 5547 | * @psalm-mutation-free |
||
| 5548 | */ |
||
| 5549 | 2 | public function replaceAllValues(array $array): self |
|
| 5557 | |||
| 5558 | /** |
||
| 5559 | * Replace the keys in an array with another set. |
||
| 5560 | * |
||
| 5561 | * EXAMPLE: <code> |
||
| 5562 | * a([1 => 'bar', 'foo' => 'foo'])->replaceKeys([1 => 2, 'foo' => 'replaced']); // Arrayy[2 => 'bar', 'replaced' => 'foo'] |
||
| 5563 | * </code> |
||
| 5564 | * |
||
| 5565 | * @param array $keys <p>An array of keys matching the array's size</p> |
||
| 5566 | * |
||
| 5567 | * @return static |
||
| 5568 | * <p>(Immutable)</p> |
||
| 5569 | * |
||
| 5570 | * @psalm-param array<mixed,mixed>|array<mixed,TKey> $keys |
||
| 5571 | * @psalm-return static<TKey,T> |
||
| 5572 | * @psalm-mutation-free |
||
| 5573 | */ |
||
| 5574 | 1 | public function replaceKeys(array $keys): self |
|
| 5585 | |||
| 5586 | /** |
||
| 5587 | * Replace the first matched value in an array. |
||
| 5588 | * |
||
| 5589 | * EXAMPLE: <code> |
||
| 5590 | * $testArray = ['bar', 'foo' => 'foo', 'foobar' => 'foobar']; |
||
| 5591 | * a($testArray)->replaceOneValue('foo', 'replaced'); // Arrayy['bar', 'foo' => 'replaced', 'foobar' => 'foobar'] |
||
| 5592 | * </code> |
||
| 5593 | * |
||
| 5594 | * @param mixed $search <p>The value to replace.</p> |
||
| 5595 | * @param mixed $replacement <p>The value to replace.</p> |
||
| 5596 | * |
||
| 5597 | * @return static |
||
| 5598 | * <p>(Immutable)</p> |
||
| 5599 | * |
||
| 5600 | * @psalm-return static<TKey,T> |
||
| 5601 | * @psalm-mutation-free |
||
| 5602 | */ |
||
| 5603 | 3 | public function replaceOneValue($search, $replacement = ''): self |
|
| 5618 | |||
| 5619 | /** |
||
| 5620 | * Replace values in the current array. |
||
| 5621 | * |
||
| 5622 | * EXAMPLE: <code> |
||
| 5623 | * $testArray = ['bar', 'foo' => 'foo', 'foobar' => 'foobar']; |
||
| 5624 | * a($testArray)->replaceValues('foo', 'replaced'); // Arrayy['bar', 'foo' => 'replaced', 'foobar' => 'replacedbar'] |
||
| 5625 | * </code> |
||
| 5626 | * |
||
| 5627 | * @param mixed $search <p>The value to replace.</p> |
||
| 5628 | * @param mixed $replacement <p>What to replace it with.</p> |
||
| 5629 | * |
||
| 5630 | * @return static |
||
| 5631 | * <p>(Immutable)</p> |
||
| 5632 | * |
||
| 5633 | * @psalm-return static<TKey,T> |
||
| 5634 | * @psalm-mutation-free |
||
| 5635 | */ |
||
| 5636 | 1 | public function replaceValues($search, $replacement = ''): self |
|
| 5648 | |||
| 5649 | /** |
||
| 5650 | * Get the last elements from index $from until the end of this array. |
||
| 5651 | * |
||
| 5652 | * EXAMPLE: <code> |
||
| 5653 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->rest(2); // Arrayy[0 => 'lall'] |
||
| 5654 | * </code> |
||
| 5655 | * |
||
| 5656 | * @param int $from |
||
| 5657 | * |
||
| 5658 | * @return static |
||
| 5659 | * <p>(Immutable)</p> |
||
| 5660 | * |
||
| 5661 | * @psalm-return static<TKey,T> |
||
| 5662 | * @psalm-mutation-free |
||
| 5663 | */ |
||
| 5664 | 15 | View Code Duplication | public function rest(int $from = 1): self |
| 5674 | |||
| 5675 | /** |
||
| 5676 | * Return the array in the reverse order. |
||
| 5677 | * |
||
| 5678 | * EXAMPLE: <code> |
||
| 5679 | * a([1, 2, 3])->reverse(); // self[3, 2, 1] |
||
| 5680 | * </code> |
||
| 5681 | * |
||
| 5682 | * @return $this |
||
| 5683 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 5684 | * |
||
| 5685 | * @psalm-return static<TKey,T> |
||
| 5686 | */ |
||
| 5687 | 9 | public function reverse(): self |
|
| 5695 | |||
| 5696 | /** |
||
| 5697 | * Sort an array in reverse order. |
||
| 5698 | * |
||
| 5699 | * @param int $sort_flags [optional] <p> |
||
| 5700 | * You may modify the behavior of the sort using the optional |
||
| 5701 | * parameter sort_flags, for details |
||
| 5702 | * see sort. |
||
| 5703 | * </p> |
||
| 5704 | * |
||
| 5705 | * @return $this |
||
| 5706 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 5707 | * |
||
| 5708 | * @psalm-return static<TKey,T> |
||
| 5709 | */ |
||
| 5710 | 4 | public function rsort(int $sort_flags = 0): self |
|
| 5718 | |||
| 5719 | /** |
||
| 5720 | * Sort an array in reverse order. |
||
| 5721 | * |
||
| 5722 | * @param int $sort_flags [optional] <p> |
||
| 5723 | * You may modify the behavior of the sort using the optional |
||
| 5724 | * parameter sort_flags, for details |
||
| 5725 | * see sort. |
||
| 5726 | * </p> |
||
| 5727 | * |
||
| 5728 | * @return $this |
||
| 5729 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 5730 | * |
||
| 5731 | * @psalm-return static<TKey,T> |
||
| 5732 | * @psalm-mutation-free |
||
| 5733 | */ |
||
| 5734 | 4 | public function rsortImmutable(int $sort_flags = 0): self |
|
| 5745 | |||
| 5746 | /** |
||
| 5747 | * Search for the first index of the current array via $value. |
||
| 5748 | * |
||
| 5749 | * EXAMPLE: <code> |
||
| 5750 | * a(['fòô' => 'bàř', 'lall' => 'bàř'])->searchIndex('bàř'); // Arrayy[0 => 'fòô'] |
||
| 5751 | * </code> |
||
| 5752 | * |
||
| 5753 | * @param mixed $value |
||
| 5754 | * |
||
| 5755 | * @return false|float|int|string |
||
| 5756 | * <p>Will return <b>FALSE</b> if the value can't be found.</p> |
||
| 5757 | * @psalm-mutation-free |
||
| 5758 | */ |
||
| 5759 | 21 | public function searchIndex($value) |
|
| 5769 | |||
| 5770 | /** |
||
| 5771 | * Search for the value of the current array via $index. |
||
| 5772 | * |
||
| 5773 | * EXAMPLE: <code> |
||
| 5774 | * a(['fòô' => 'bàř'])->searchValue('fòô'); // Arrayy[0 => 'bàř'] |
||
| 5775 | * </code> |
||
| 5776 | * |
||
| 5777 | * @param mixed $index |
||
| 5778 | * |
||
| 5779 | * @return static |
||
| 5780 | * <p>(Immutable) Will return a empty Arrayy if the value wasn't found.</p> |
||
| 5781 | * |
||
| 5782 | * @psalm-return static<TKey,T> |
||
| 5783 | * @psalm-mutation-free |
||
| 5784 | */ |
||
| 5785 | 9 | public function searchValue($index): self |
|
| 5815 | |||
| 5816 | /** |
||
| 5817 | * Set a value for the current array (optional using dot-notation). |
||
| 5818 | * |
||
| 5819 | * EXAMPLE: <code> |
||
| 5820 | * $arrayy = a(['Lars' => ['lastname' => 'Moelleken']]); |
||
| 5821 | * $arrayy->set('Lars.lastname', 'Müller'); // Arrayy['Lars', ['lastname' => 'Müller']]] |
||
| 5822 | * </code> |
||
| 5823 | * |
||
| 5824 | * @param string $key <p>The key to set.</p> |
||
| 5825 | * @param mixed $value <p>Its value.</p> |
||
| 5826 | * |
||
| 5827 | * @return $this |
||
| 5828 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 5829 | * |
||
| 5830 | * @psalm-param TKey $key |
||
| 5831 | * @psalm-param T $value |
||
| 5832 | * @psalm-return static<TKey,T> |
||
| 5833 | */ |
||
| 5834 | 28 | public function set($key, $value): self |
|
| 5840 | |||
| 5841 | /** |
||
| 5842 | * Get a value from a array and set it if it was not. |
||
| 5843 | * |
||
| 5844 | * WARNING: this method only set the value, if the $key is not already set |
||
| 5845 | * |
||
| 5846 | * EXAMPLE: <code> |
||
| 5847 | * $arrayy = a([1 => 1, 2 => 2, 3 => 3]); |
||
| 5848 | * $arrayy->setAndGet(1, 4); // 1 |
||
| 5849 | * $arrayy->setAndGet(0, 4); // 4 |
||
| 5850 | * </code> |
||
| 5851 | * |
||
| 5852 | * @param mixed $key <p>The key</p> |
||
| 5853 | * @param mixed $fallback <p>The default value to set if it isn't.</p> |
||
| 5854 | * |
||
| 5855 | * @return mixed |
||
| 5856 | * <p>(Mutable)</p> |
||
| 5857 | */ |
||
| 5858 | 11 | public function setAndGet($key, $fallback = null) |
|
| 5869 | |||
| 5870 | /** |
||
| 5871 | * Shifts a specified value off the beginning of array. |
||
| 5872 | * |
||
| 5873 | * @return mixed |
||
| 5874 | * <p>(Mutable) A shifted element from the current array.</p> |
||
| 5875 | */ |
||
| 5876 | 5 | public function shift() |
|
| 5882 | |||
| 5883 | /** |
||
| 5884 | * Shuffle the current array. |
||
| 5885 | * |
||
| 5886 | * EXAMPLE: <code> |
||
| 5887 | * a([1 => 'bar', 'foo' => 'foo'])->shuffle(); // e.g.: Arrayy[['foo' => 'foo', 1 => 'bar']] |
||
| 5888 | * </code> |
||
| 5889 | * |
||
| 5890 | * @param bool $secure <p>using a CSPRNG | @link https://paragonie.com/b/JvICXzh_jhLyt4y3</p> |
||
| 5891 | * @param array $array [optional] |
||
| 5892 | * |
||
| 5893 | * @return static |
||
| 5894 | * <p>(Immutable)</p> |
||
| 5895 | * |
||
| 5896 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 5897 | * @psalm-return static<TKey,T> |
||
| 5898 | * |
||
| 5899 | * @noinspection BadExceptionsProcessingInspection |
||
| 5900 | * @noinspection NonSecureShuffleUsageInspection |
||
| 5901 | */ |
||
| 5902 | 2 | public function shuffle(bool $secure = false, array $array = null): self |
|
| 5903 | { |
||
| 5904 | 2 | if ($array === null) { |
|
| 5905 | 2 | $array = $this->toArray(false); |
|
| 5906 | } |
||
| 5907 | |||
| 5908 | 2 | if ($secure !== true) { |
|
| 5909 | 2 | \shuffle($array); |
|
| 5910 | } else { |
||
| 5911 | 1 | $size = \count($array, \COUNT_NORMAL); |
|
| 5912 | 1 | $keys = \array_keys($array); |
|
| 5913 | 1 | for ($i = $size - 1; $i > 0; --$i) { |
|
| 5914 | try { |
||
| 5915 | 1 | $r = \random_int(0, $i); |
|
| 5916 | } catch (\Exception $e) { |
||
| 5917 | $r = \mt_rand(0, $i); |
||
| 5918 | } |
||
| 5919 | 1 | if ($r !== $i) { |
|
| 5920 | 1 | $temp = $array[$keys[$r]]; |
|
| 5921 | 1 | $array[$keys[$r]] = $array[$keys[$i]]; |
|
| 5922 | 1 | $array[$keys[$i]] = $temp; |
|
| 5923 | } |
||
| 5924 | } |
||
| 5925 | } |
||
| 5926 | |||
| 5927 | 2 | foreach ($array as $key => $value) { |
|
| 5928 | // check if recursive is needed |
||
| 5929 | 2 | if (\is_array($value)) { |
|
| 5930 | $array[$key] = $this->shuffle($secure, $value); |
||
| 5931 | } |
||
| 5932 | } |
||
| 5933 | |||
| 5934 | 2 | return static::create( |
|
| 5935 | 2 | $array, |
|
| 5936 | 2 | $this->iteratorClass, |
|
| 5937 | 2 | false |
|
| 5938 | ); |
||
| 5939 | } |
||
| 5940 | |||
| 5941 | /** |
||
| 5942 | * Count the values from the current array. |
||
| 5943 | * |
||
| 5944 | * alias: for "Arrayy->count()" |
||
| 5945 | * |
||
| 5946 | * @param int $mode |
||
| 5947 | * |
||
| 5948 | * @return int |
||
| 5949 | */ |
||
| 5950 | 20 | public function size(int $mode = \COUNT_NORMAL): int |
|
| 5954 | |||
| 5955 | /** |
||
| 5956 | * Checks whether array has exactly $size items. |
||
| 5957 | * |
||
| 5958 | * @param int $size |
||
| 5959 | * |
||
| 5960 | * @return bool |
||
| 5961 | */ |
||
| 5962 | 1 | public function sizeIs(int $size): bool |
|
| 5978 | |||
| 5979 | /** |
||
| 5980 | * Checks whether array has between $fromSize to $toSize items. $toSize can be |
||
| 5981 | * smaller than $fromSize. |
||
| 5982 | * |
||
| 5983 | * @param int $fromSize |
||
| 5984 | * @param int $toSize |
||
| 5985 | * |
||
| 5986 | * @return bool |
||
| 5987 | */ |
||
| 5988 | 1 | public function sizeIsBetween(int $fromSize, int $toSize): bool |
|
| 6008 | |||
| 6009 | /** |
||
| 6010 | * Checks whether array has more than $size items. |
||
| 6011 | * |
||
| 6012 | * @param int $size |
||
| 6013 | * |
||
| 6014 | * @return bool |
||
| 6015 | */ |
||
| 6016 | 1 | View Code Duplication | public function sizeIsGreaterThan(int $size): bool |
| 6030 | |||
| 6031 | /** |
||
| 6032 | * Checks whether array has less than $size items. |
||
| 6033 | * |
||
| 6034 | * @param int $size |
||
| 6035 | * |
||
| 6036 | * @return bool |
||
| 6037 | */ |
||
| 6038 | 1 | View Code Duplication | public function sizeIsLessThan(int $size): bool |
| 6052 | |||
| 6053 | /** |
||
| 6054 | * Counts all elements in an array, or something in an object. |
||
| 6055 | * |
||
| 6056 | * <p> |
||
| 6057 | * For objects, if you have SPL installed, you can hook into count() by implementing interface {@see Countable}. |
||
| 6058 | * The interface has exactly one method, {@see Countable::count()}, which returns the return value for the count() |
||
| 6059 | * function. Please see the {@see Array} section of the manual for a detailed explanation of how arrays are |
||
| 6060 | * implemented and used in PHP. |
||
| 6061 | * </p> |
||
| 6062 | * |
||
| 6063 | * @return int |
||
| 6064 | * <p> |
||
| 6065 | * The number of elements in var, which is |
||
| 6066 | * typically an array, since anything else will have one |
||
| 6067 | * element. |
||
| 6068 | * </p> |
||
| 6069 | * <p> |
||
| 6070 | * If var is not an array or an object with |
||
| 6071 | * implemented Countable interface, |
||
| 6072 | * 1 will be returned. |
||
| 6073 | * There is one exception, if var is &null;, |
||
| 6074 | * 0 will be returned. |
||
| 6075 | * </p> |
||
| 6076 | * <p> |
||
| 6077 | * Caution: count may return 0 for a variable that isn't set, |
||
| 6078 | * but it may also return 0 for a variable that has been initialized with an |
||
| 6079 | * empty array. Use isset to test if a variable is set. |
||
| 6080 | * </p> |
||
| 6081 | */ |
||
| 6082 | 10 | public function sizeRecursive(): int |
|
| 6086 | |||
| 6087 | /** |
||
| 6088 | * Extract a slice of the array. |
||
| 6089 | * |
||
| 6090 | * @param int $offset <p>Slice begin index.</p> |
||
| 6091 | * @param int|null $length <p>Length of the slice.</p> |
||
| 6092 | * @param bool $preserveKeys <p>Whether array keys are preserved or no.</p> |
||
| 6093 | * |
||
| 6094 | * @return static |
||
| 6095 | * <p>(Immutable) A slice of the original array with length $length.</p> |
||
| 6096 | * |
||
| 6097 | * @psalm-return static<TKey,T> |
||
| 6098 | * @psalm-mutation-free |
||
| 6099 | */ |
||
| 6100 | 5 | public function slice(int $offset, int $length = null, bool $preserveKeys = false) |
|
| 6113 | |||
| 6114 | /** |
||
| 6115 | * Sort the current array and optional you can keep the keys. |
||
| 6116 | * |
||
| 6117 | * EXAMPLE: <code> |
||
| 6118 | * a(3 => 'd', 2 => 'f', 0 => 'a')->sort(SORT_ASC, SORT_NATURAL, false); // Arrayy[0 => 'a', 1 => 'd', 2 => 'f'] |
||
| 6119 | * </code> |
||
| 6120 | * |
||
| 6121 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 6122 | * @param int $strategy <p>sort_flags => use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 6123 | * <strong>SORT_NATURAL</strong></p> |
||
| 6124 | * @param bool $keepKeys |
||
| 6125 | * |
||
| 6126 | * @return static |
||
| 6127 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 6128 | * |
||
| 6129 | * @psalm-return static<TKey,T> |
||
| 6130 | */ |
||
| 6131 | 20 | public function sort( |
|
| 6145 | |||
| 6146 | /** |
||
| 6147 | * Sort the current array and optional you can keep the keys. |
||
| 6148 | * |
||
| 6149 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 6150 | * @param int $strategy <p>sort_flags => use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 6151 | * <strong>SORT_NATURAL</strong></p> |
||
| 6152 | * @param bool $keepKeys |
||
| 6153 | * |
||
| 6154 | * @return static |
||
| 6155 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 6156 | * |
||
| 6157 | * @psalm-return static<TKey,T> |
||
| 6158 | */ |
||
| 6159 | 12 | public function sortImmutable( |
|
| 6175 | |||
| 6176 | /** |
||
| 6177 | * Sort the current array by key. |
||
| 6178 | * |
||
| 6179 | * EXAMPLE: <code> |
||
| 6180 | * a([1 => 2, 0 => 1])->sortKeys(\SORT_ASC); // Arrayy[0 => 1, 1 => 2] |
||
| 6181 | * </code> |
||
| 6182 | * |
||
| 6183 | * @see http://php.net/manual/en/function.ksort.php |
||
| 6184 | * @see http://php.net/manual/en/function.krsort.php |
||
| 6185 | * |
||
| 6186 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 6187 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 6188 | * <strong>SORT_NATURAL</strong></p> |
||
| 6189 | * |
||
| 6190 | * @return $this |
||
| 6191 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 6192 | * |
||
| 6193 | * @psalm-return static<TKey,T> |
||
| 6194 | */ |
||
| 6195 | 18 | public function sortKeys( |
|
| 6205 | |||
| 6206 | /** |
||
| 6207 | * Sort the current array by key. |
||
| 6208 | * |
||
| 6209 | * @see http://php.net/manual/en/function.ksort.php |
||
| 6210 | * @see http://php.net/manual/en/function.krsort.php |
||
| 6211 | * |
||
| 6212 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 6213 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 6214 | * <strong>SORT_NATURAL</strong></p> |
||
| 6215 | * |
||
| 6216 | * @return $this |
||
| 6217 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 6218 | * |
||
| 6219 | * @psalm-return static<TKey,T> |
||
| 6220 | * @psalm-mutation-free |
||
| 6221 | */ |
||
| 6222 | 8 | public function sortKeysImmutable( |
|
| 6235 | |||
| 6236 | /** |
||
| 6237 | * Sort the current array by value. |
||
| 6238 | * |
||
| 6239 | * EXAMPLE: <code> |
||
| 6240 | * a(3 => 'd', 2 => 'f', 0 => 'a')->sortValueKeepIndex(SORT_ASC, SORT_REGULAR); // Arrayy[0 => 'a', 3 => 'd', 2 => 'f'] |
||
| 6241 | * </code> |
||
| 6242 | * |
||
| 6243 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 6244 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 6245 | * <strong>SORT_NATURAL</strong></p> |
||
| 6246 | * |
||
| 6247 | * @return static |
||
| 6248 | * <p>(Mutable)</p> |
||
| 6249 | * |
||
| 6250 | * @psalm-return static<TKey,T> |
||
| 6251 | */ |
||
| 6252 | 1 | public function sortValueKeepIndex( |
|
| 6258 | |||
| 6259 | /** |
||
| 6260 | * Sort the current array by value. |
||
| 6261 | * |
||
| 6262 | * EXAMPLE: <code> |
||
| 6263 | * a(3 => 'd', 2 => 'f', 0 => 'a')->sortValueNewIndex(SORT_ASC, SORT_NATURAL); // Arrayy[0 => 'a', 1 => 'd', 2 => 'f'] |
||
| 6264 | * </code> |
||
| 6265 | * |
||
| 6266 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 6267 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 6268 | * <strong>SORT_NATURAL</strong></p> |
||
| 6269 | * |
||
| 6270 | * @return static |
||
| 6271 | * <p>(Mutable)</p> |
||
| 6272 | * |
||
| 6273 | * @psalm-return static<TKey,T> |
||
| 6274 | */ |
||
| 6275 | 1 | public function sortValueNewIndex($direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
| 6279 | |||
| 6280 | /** |
||
| 6281 | * Sort a array by value or by a closure. |
||
| 6282 | * |
||
| 6283 | * - If the sorter is null, the array is sorted naturally. |
||
| 6284 | * - Associative (string) keys will be maintained, but numeric keys will be re-indexed. |
||
| 6285 | * |
||
| 6286 | * EXAMPLE: <code> |
||
| 6287 | * $testArray = range(1, 5); |
||
| 6288 | * $under = a($testArray)->sorter( |
||
| 6289 | * function ($value) { |
||
| 6290 | * return $value % 2 === 0; |
||
| 6291 | * } |
||
| 6292 | * ); |
||
| 6293 | * var_dump($under); // Arrayy[1, 3, 5, 2, 4] |
||
| 6294 | * </code> |
||
| 6295 | * |
||
| 6296 | * @param callable|mixed|null $sorter |
||
| 6297 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or |
||
| 6298 | * <strong>SORT_DESC</strong></p> |
||
| 6299 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 6300 | * <strong>SORT_NATURAL</strong></p> |
||
| 6301 | * |
||
| 6302 | * @return static |
||
| 6303 | * <p>(Immutable)</p> |
||
| 6304 | * |
||
| 6305 | * @pslam-param callable|T|null $sorter |
||
| 6306 | * @psalm-return static<TKey,T> |
||
| 6307 | * @psalm-mutation-free |
||
| 6308 | */ |
||
| 6309 | 1 | public function sorter($sorter = null, $direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
| 6350 | |||
| 6351 | /** |
||
| 6352 | * @param int $offset |
||
| 6353 | * @param int|null $length |
||
| 6354 | * @param array $replacement |
||
| 6355 | * |
||
| 6356 | * @return static |
||
| 6357 | * <p>(Immutable)</p> |
||
| 6358 | * |
||
| 6359 | * @psalm-param array<mixed,mixed>|array<mixed,T> $replacement |
||
| 6360 | * @psalm-return static<TKey,T> |
||
| 6361 | * @psalm-mutation-free |
||
| 6362 | */ |
||
| 6363 | 1 | public function splice(int $offset, int $length = null, $replacement = []): self |
|
| 6380 | |||
| 6381 | /** |
||
| 6382 | * Split an array in the given amount of pieces. |
||
| 6383 | * |
||
| 6384 | * EXAMPLE: <code> |
||
| 6385 | * a(['a' => 1, 'b' => 2])->split(2, true); // Arrayy[['a' => 1], ['b' => 2]] |
||
| 6386 | * </code> |
||
| 6387 | * |
||
| 6388 | * @param int $numberOfPieces |
||
| 6389 | * @param bool $keepKeys |
||
| 6390 | * |
||
| 6391 | * @return static |
||
| 6392 | * <p>(Immutable)</p> |
||
| 6393 | * |
||
| 6394 | * @psalm-return static<TKey,T> |
||
| 6395 | * @psalm-mutation-free |
||
| 6396 | */ |
||
| 6397 | 1 | public function split(int $numberOfPieces = 2, bool $keepKeys = false): self |
|
| 6453 | |||
| 6454 | /** |
||
| 6455 | * Strip all empty items from the current array. |
||
| 6456 | * |
||
| 6457 | * EXAMPLE: <code> |
||
| 6458 | * a(['a' => 1, 'b' => ''])->stripEmpty(); // Arrayy[['a' => 1]] |
||
| 6459 | * </code> |
||
| 6460 | * |
||
| 6461 | * @return static |
||
| 6462 | * <p>(Immutable)</p> |
||
| 6463 | * |
||
| 6464 | * @psalm-return static<TKey,T> |
||
| 6465 | * @psalm-mutation-free |
||
| 6466 | */ |
||
| 6467 | 1 | public function stripEmpty(): self |
|
| 6479 | |||
| 6480 | /** |
||
| 6481 | * Swap two values between positions by key. |
||
| 6482 | * |
||
| 6483 | * EXAMPLE: <code> |
||
| 6484 | * a(['a' => 1, 'b' => ''])->swap('a', 'b'); // Arrayy[['a' => '', 'b' => 1]] |
||
| 6485 | * </code> |
||
| 6486 | * |
||
| 6487 | * @param int|string $swapA <p>a key in the array</p> |
||
| 6488 | * @param int|string $swapB <p>a key in the array</p> |
||
| 6489 | * |
||
| 6490 | * @return static |
||
| 6491 | * <p>(Immutable)</p> |
||
| 6492 | * |
||
| 6493 | * @psalm-return static<TKey,T> |
||
| 6494 | * @psalm-mutation-free |
||
| 6495 | */ |
||
| 6496 | 1 | public function swap($swapA, $swapB): self |
|
| 6508 | |||
| 6509 | /** |
||
| 6510 | * Get the current array from the "Arrayy"-object. |
||
| 6511 | * alias for "getArray()" |
||
| 6512 | * |
||
| 6513 | * @param bool $convertAllArrayyElements <p> |
||
| 6514 | * Convert all Child-"Arrayy" objects also to arrays. |
||
| 6515 | * </p> |
||
| 6516 | * @param bool $preserveKeys <p> |
||
| 6517 | * e.g.: A generator maybe return the same key more then once, |
||
| 6518 | * so maybe you will ignore the keys. |
||
| 6519 | * </p> |
||
| 6520 | * |
||
| 6521 | * @return array |
||
| 6522 | * |
||
| 6523 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 6524 | * @psalm-mutation-free |
||
| 6525 | */ |
||
| 6526 | 934 | public function toArray( |
|
| 6554 | |||
| 6555 | /** |
||
| 6556 | * Get the current array from the "Arrayy"-object as list. |
||
| 6557 | * |
||
| 6558 | * @param bool $convertAllArrayyElements <p> |
||
| 6559 | * Convert all Child-"Arrayy" objects also to arrays. |
||
| 6560 | * </p> |
||
| 6561 | * |
||
| 6562 | * @return array |
||
| 6563 | * |
||
| 6564 | * @psalm-return list<array<TKey,T>> |
||
| 6565 | * @psalm-mutation-free |
||
| 6566 | */ |
||
| 6567 | 1 | public function toList(bool $convertAllArrayyElements = false): array |
|
| 6574 | |||
| 6575 | /** |
||
| 6576 | * Convert the current array to JSON. |
||
| 6577 | * |
||
| 6578 | * EXAMPLE: <code> |
||
| 6579 | * a(['bar', ['foo']])->toJson(); // '["bar",{"1":"foo"}]' |
||
| 6580 | * </code> |
||
| 6581 | * |
||
| 6582 | * @param int $options [optional] <p>e.g. JSON_PRETTY_PRINT</p> |
||
| 6583 | * @param int $depth [optional] <p>Set the maximum depth. Must be greater than zero.</p> |
||
| 6584 | * |
||
| 6585 | * @return string |
||
| 6586 | */ |
||
| 6587 | 12 | public function toJson(int $options = 0, int $depth = 512): string |
|
| 6596 | |||
| 6597 | /** |
||
| 6598 | * @param string[]|null $items [optional] |
||
| 6599 | * @param string[] $helper [optional] |
||
| 6600 | * |
||
| 6601 | * @return static|static[] |
||
| 6602 | * |
||
| 6603 | * @psalm-return static<int, static<TKey,T>> |
||
| 6604 | */ |
||
| 6605 | 1 | public function toPermutation(array $items = null, array $helper = []): self |
|
| 6638 | |||
| 6639 | /** |
||
| 6640 | * Implodes array to a string with specified separator. |
||
| 6641 | * |
||
| 6642 | * @param string $separator [optional] <p>The element's separator.</p> |
||
| 6643 | * |
||
| 6644 | * @return string |
||
| 6645 | * <p>The string representation of array, separated by ",".</p> |
||
| 6646 | */ |
||
| 6647 | 19 | public function toString(string $separator = ','): string |
|
| 6651 | |||
| 6652 | /** |
||
| 6653 | * Return a duplicate free copy of the current array. |
||
| 6654 | * |
||
| 6655 | * EXAMPLE: <code> |
||
| 6656 | * a([2 => 1, 3 => 2, 4 => 2])->uniqueNewIndex(); // Arrayy[1, 2] |
||
| 6657 | * </code> |
||
| 6658 | * |
||
| 6659 | * @return $this |
||
| 6660 | * <p>(Mutable)</p> |
||
| 6661 | * |
||
| 6662 | * @psalm-return static<TKey,T> |
||
| 6663 | */ |
||
| 6664 | 13 | public function uniqueNewIndex(): self |
|
| 6686 | |||
| 6687 | /** |
||
| 6688 | * Return a duplicate free copy of the current array. (with the old keys) |
||
| 6689 | * |
||
| 6690 | * EXAMPLE: <code> |
||
| 6691 | * a([2 => 1, 3 => 2, 4 => 2])->uniqueNewIndex(); // Arrayy[2 => 1, 3 => 2] |
||
| 6692 | * </code> |
||
| 6693 | * |
||
| 6694 | * @return $this |
||
| 6695 | * <p>(Mutable)</p> |
||
| 6696 | * |
||
| 6697 | * @psalm-return static<TKey,T> |
||
| 6698 | */ |
||
| 6699 | 11 | public function uniqueKeepIndex(): self |
|
| 6725 | |||
| 6726 | /** |
||
| 6727 | * alias: for "Arrayy->uniqueNewIndex()" |
||
| 6728 | * |
||
| 6729 | * @return static |
||
| 6730 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
| 6731 | * |
||
| 6732 | * @see Arrayy::unique() |
||
| 6733 | * |
||
| 6734 | * @psalm-return static<TKey,T> |
||
| 6735 | */ |
||
| 6736 | 13 | public function unique(): self |
|
| 6740 | |||
| 6741 | /** |
||
| 6742 | * Prepends one or more values to the beginning of array at once. |
||
| 6743 | * |
||
| 6744 | * @param mixed ...$args |
||
| 6745 | * |
||
| 6746 | * @return $this |
||
| 6747 | * <p>(Mutable) Return this Arrayy object, with prepended elements to the beginning of array.</p> |
||
| 6748 | * |
||
| 6749 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$args |
||
| 6750 | * @psalm-return static<TKey,T> |
||
| 6751 | */ |
||
| 6752 | 6 | View Code Duplication | public function unshift(...$args): self |
| 6770 | |||
| 6771 | /** |
||
| 6772 | * Tests whether the given closure return something valid for all elements of this array. |
||
| 6773 | * |
||
| 6774 | * @param \Closure $closure the predicate |
||
| 6775 | * |
||
| 6776 | * @return bool |
||
| 6777 | * <p>TRUE, if the predicate yields TRUE for all elements, FALSE otherwise.</p> |
||
| 6778 | */ |
||
| 6779 | 1 | View Code Duplication | public function validate(\Closure $closure): bool |
| 6789 | |||
| 6790 | /** |
||
| 6791 | * Get all values from a array. |
||
| 6792 | * |
||
| 6793 | * EXAMPLE: <code> |
||
| 6794 | * $arrayy = a([1 => 'foo', 2 => 'foo2', 3 => 'bar']); |
||
| 6795 | * $arrayyTmp->values(); // Arrayy[0 => 'foo', 1 => 'foo2', 2 => 'bar'] |
||
| 6796 | * </code> |
||
| 6797 | * |
||
| 6798 | * @return static |
||
| 6799 | * <p>(Immutable)</p> |
||
| 6800 | * |
||
| 6801 | * @psalm-return static<TKey,T> |
||
| 6802 | * @psalm-mutation-free |
||
| 6803 | */ |
||
| 6804 | 2 | public function values(): self |
|
| 6817 | |||
| 6818 | /** |
||
| 6819 | * Apply the given function to every element in the array, discarding the results. |
||
| 6820 | * |
||
| 6821 | * EXAMPLE: <code> |
||
| 6822 | * $callable = function (&$value, $key) { |
||
| 6823 | * $value = $key; |
||
| 6824 | * }; |
||
| 6825 | * $arrayy = a([1, 2, 3]); |
||
| 6826 | * $arrayy->walk($callable); // Arrayy[0, 1, 2] |
||
| 6827 | * </code> |
||
| 6828 | * |
||
| 6829 | * @param callable $callable |
||
| 6830 | * @param bool $recursive [optional] <p>Whether array will be walked recursively or no</p> |
||
| 6831 | * @param mixed $userData [optional] <p> |
||
| 6832 | * If the optional $userData parameter is supplied, |
||
| 6833 | * it will be passed as the third parameter to the $callable. |
||
| 6834 | * </p> |
||
| 6835 | * |
||
| 6836 | * @return $this |
||
| 6837 | * <p>(Mutable) Return this Arrayy object, with modified elements.</p> |
||
| 6838 | * |
||
| 6839 | * @psalm-return static<TKey,T> |
||
| 6840 | */ |
||
| 6841 | 12 | public function walk( |
|
| 6867 | |||
| 6868 | /** |
||
| 6869 | * Returns a collection of matching items. |
||
| 6870 | * |
||
| 6871 | * @param string $keyOrPropertyOrMethod the property or method to evaluate |
||
| 6872 | * @param mixed $value the value to match |
||
| 6873 | * |
||
| 6874 | * @throws \InvalidArgumentException if property or method is not defined |
||
| 6875 | * |
||
| 6876 | * @return static |
||
| 6877 | * |
||
| 6878 | * @psalm-return static<TKey,T> |
||
| 6879 | */ |
||
| 6880 | 1 | public function where(string $keyOrPropertyOrMethod, $value): self |
|
| 6893 | |||
| 6894 | /** |
||
| 6895 | * Convert an array into a object. |
||
| 6896 | * |
||
| 6897 | * @param array $array |
||
| 6898 | * |
||
| 6899 | * @return \stdClass |
||
| 6900 | * |
||
| 6901 | * @psalm-param array<mixed,mixed> $array |
||
| 6902 | */ |
||
| 6903 | 4 | final protected static function arrayToObject(array $array = []): \stdClass |
|
| 6922 | |||
| 6923 | /** |
||
| 6924 | * @param array|\Generator|null $input <p> |
||
| 6925 | * An array containing keys to return. |
||
| 6926 | * </p> |
||
| 6927 | * @param mixed|null $search_values [optional] <p> |
||
| 6928 | * If specified, then only keys containing these values are returned. |
||
| 6929 | * </p> |
||
| 6930 | * @param bool $strict [optional] <p> |
||
| 6931 | * Determines if strict comparison (===) should be used during the |
||
| 6932 | * search. |
||
| 6933 | * </p> |
||
| 6934 | * |
||
| 6935 | * @return array |
||
| 6936 | * <p>an array of all the keys in input</p> |
||
| 6937 | * |
||
| 6938 | * @psalm-param array<mixed,mixed>|\Generator<TKey,T>|null $input |
||
| 6939 | * @psalm-return array<TKey|mixed> |
||
| 6940 | * @psalm-mutation-free |
||
| 6941 | */ |
||
| 6942 | 11 | protected function array_keys_recursive( |
|
| 7003 | |||
| 7004 | /** |
||
| 7005 | * @param mixed $path |
||
| 7006 | * @param callable $callable |
||
| 7007 | * @param array|null $currentOffset |
||
| 7008 | * |
||
| 7009 | * @return void |
||
| 7010 | * |
||
| 7011 | * @psalm-param array<mixed,mixed>|array<TKey,T>|null $currentOffset |
||
| 7012 | * @psalm-mutation-free |
||
| 7013 | */ |
||
| 7014 | 10 | protected function callAtPath($path, $callable, &$currentOffset = null) |
|
| 7043 | |||
| 7044 | /** |
||
| 7045 | * Extracts the value of the given property or method from the object. |
||
| 7046 | * |
||
| 7047 | * @param static $object <p>The object to extract the value from.</p> |
||
| 7048 | * @param string $keyOrPropertyOrMethod <p>The property or method for which the |
||
| 7049 | * value should be extracted.</p> |
||
| 7050 | * |
||
| 7051 | * @throws \InvalidArgumentException if the method or property is not defined |
||
| 7052 | * |
||
| 7053 | * @return mixed |
||
| 7054 | * <p>The value extracted from the specified property or method.</p> |
||
| 7055 | * |
||
| 7056 | * @psalm-param self<TKey,T> $object |
||
| 7057 | */ |
||
| 7058 | 1 | final protected function extractValue(self $object, string $keyOrPropertyOrMethod) |
|
| 7080 | |||
| 7081 | /** |
||
| 7082 | * create a fallback for array |
||
| 7083 | * |
||
| 7084 | * 1. use the current array, if it's a array |
||
| 7085 | * 2. fallback to empty array, if there is nothing |
||
| 7086 | * 3. call "getArray()" on object, if there is a "Arrayy"-object |
||
| 7087 | * 4. call "createFromObject()" on object, if there is a "\Traversable"-object |
||
| 7088 | * 5. call "__toArray()" on object, if the method exists |
||
| 7089 | * 6. cast a string or object with "__toString()" into an array |
||
| 7090 | * 7. throw a "InvalidArgumentException"-Exception |
||
| 7091 | * |
||
| 7092 | * @param mixed $data |
||
| 7093 | * |
||
| 7094 | * @throws \InvalidArgumentException |
||
| 7095 | * |
||
| 7096 | * @return array |
||
| 7097 | * |
||
| 7098 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 7099 | */ |
||
| 7100 | 1212 | protected function fallbackForArray(&$data): array |
|
| 7110 | |||
| 7111 | /** |
||
| 7112 | * @param bool $preserveKeys <p> |
||
| 7113 | * e.g.: A generator maybe return the same key more then once, |
||
| 7114 | * so maybe you will ignore the keys. |
||
| 7115 | * </p> |
||
| 7116 | * |
||
| 7117 | * @return bool |
||
| 7118 | * |
||
| 7119 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
| 7120 | * @psalm-mutation-free :/ |
||
| 7121 | */ |
||
| 7122 | 1121 | protected function generatorToArray(bool $preserveKeys = true) |
|
| 7133 | |||
| 7134 | /** |
||
| 7135 | * Get correct PHP constant for direction. |
||
| 7136 | * |
||
| 7137 | * @param int|string $direction |
||
| 7138 | * |
||
| 7139 | * @return int |
||
| 7140 | * @psalm-mutation-free |
||
| 7141 | */ |
||
| 7142 | 43 | protected function getDirection($direction): int |
|
| 7164 | |||
| 7165 | /** |
||
| 7166 | * @return TypeCheckInterface[] |
||
| 7167 | * |
||
| 7168 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
| 7169 | */ |
||
| 7170 | 24 | protected function getPropertiesFromPhpDoc() |
|
| 7225 | |||
| 7226 | /** |
||
| 7227 | * @param mixed $glue |
||
| 7228 | * @param mixed $pieces |
||
| 7229 | * @param bool $useKeys |
||
| 7230 | * |
||
| 7231 | * @return string |
||
| 7232 | * @psalm-mutation-free |
||
| 7233 | */ |
||
| 7234 | 36 | protected function implode_recursive( |
|
| 7267 | |||
| 7268 | /** |
||
| 7269 | * @param mixed $needle <p> |
||
| 7270 | * The searched value. |
||
| 7271 | * </p> |
||
| 7272 | * <p> |
||
| 7273 | * If needle is a string, the comparison is done |
||
| 7274 | * in a case-sensitive manner. |
||
| 7275 | * </p> |
||
| 7276 | * @param array|\Generator|null $haystack <p> |
||
| 7277 | * The array. |
||
| 7278 | * </p> |
||
| 7279 | * @param bool $strict [optional] <p> |
||
| 7280 | * If the third parameter strict is set to true |
||
| 7281 | * then the in_array function will also check the |
||
| 7282 | * types of the |
||
| 7283 | * needle in the haystack. |
||
| 7284 | * </p> |
||
| 7285 | * |
||
| 7286 | * @return bool |
||
| 7287 | * <p>true if needle is found in the array, false otherwise</p> |
||
| 7288 | * |
||
| 7289 | * @psalm-param array<mixed,mixed>|\Generator<TKey,T>|null $haystack |
||
| 7290 | * @psalm-mutation-free |
||
| 7291 | */ |
||
| 7292 | 18 | protected function in_array_recursive($needle, $haystack = null, $strict = true): bool |
|
| 7317 | |||
| 7318 | /** |
||
| 7319 | * @param mixed $data |
||
| 7320 | * |
||
| 7321 | * @return array|null |
||
| 7322 | * |
||
| 7323 | * @psalm-return array<mixed,mixed>|array<TKey,T>|null |
||
| 7324 | */ |
||
| 7325 | 1212 | protected function internalGetArray(&$data) |
|
| 7376 | |||
| 7377 | /** |
||
| 7378 | * Internal mechanics of remove method. |
||
| 7379 | * |
||
| 7380 | * @param mixed $key |
||
| 7381 | * |
||
| 7382 | * @return bool |
||
| 7383 | */ |
||
| 7384 | 22 | protected function internalRemove($key): bool |
|
| 7417 | |||
| 7418 | /** |
||
| 7419 | * Internal mechanic of set method. |
||
| 7420 | * |
||
| 7421 | * @param int|string|null $key |
||
| 7422 | * @param mixed $value |
||
| 7423 | * @param bool $checkProperties |
||
| 7424 | * |
||
| 7425 | * @return bool |
||
| 7426 | */ |
||
| 7427 | 1062 | protected function internalSet( |
|
| 7486 | |||
| 7487 | /** |
||
| 7488 | * Convert a object into an array. |
||
| 7489 | * |
||
| 7490 | * @param mixed|object $object |
||
| 7491 | * |
||
| 7492 | * @return array|mixed |
||
| 7493 | * |
||
| 7494 | * @psalm-mutation-free |
||
| 7495 | */ |
||
| 7496 | 5 | protected static function objectToArray($object) |
|
| 7509 | |||
| 7510 | /** |
||
| 7511 | * @param array $data |
||
| 7512 | * @param bool $checkPropertiesInConstructor |
||
| 7513 | * |
||
| 7514 | * @return void |
||
| 7515 | * |
||
| 7516 | * @psalm-param array<mixed,T> $data |
||
| 7517 | */ |
||
| 7518 | 1210 | protected function setInitialValuesAndProperties(array &$data, bool $checkPropertiesInConstructor) |
|
| 7563 | |||
| 7564 | /** |
||
| 7565 | * sorting keys |
||
| 7566 | * |
||
| 7567 | * @param array $elements |
||
| 7568 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 7569 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 7570 | * <strong>SORT_NATURAL</strong></p> |
||
| 7571 | * |
||
| 7572 | * @return $this |
||
| 7573 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 7574 | * |
||
| 7575 | * @psalm-param array<mixed,mixed>|array<mixed|TKey,T> $elements |
||
| 7576 | * @psalm-return static<TKey,T> |
||
| 7577 | */ |
||
| 7578 | 18 | protected function sorterKeys( |
|
| 7599 | |||
| 7600 | /** |
||
| 7601 | * @param array $elements <p>Warning: used as reference</p> |
||
| 7602 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 7603 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 7604 | * <strong>SORT_NATURAL</strong></p> |
||
| 7605 | * @param bool $keepKeys |
||
| 7606 | * |
||
| 7607 | * @return $this |
||
| 7608 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 7609 | * |
||
| 7610 | * @psalm-param array<mixed,mixed>|array<mixed|TKey,T> $elements |
||
| 7611 | * @psalm-return static<TKey,T> |
||
| 7612 | */ |
||
| 7613 | 24 | protected function sorting( |
|
| 7647 | |||
| 7648 | /** |
||
| 7649 | * @param array $array |
||
| 7650 | * |
||
| 7651 | * @return array |
||
| 7652 | * |
||
| 7653 | * @psalm-mutation-free |
||
| 7654 | */ |
||
| 7655 | 25 | private function getArrayRecursiveHelperArrayy(array $array) |
|
| 7677 | |||
| 7678 | /** |
||
| 7679 | * @param int|string|null $key |
||
| 7680 | * @param mixed $value |
||
| 7681 | * |
||
| 7682 | * @return void |
||
| 7683 | */ |
||
| 7684 | 117 | private function checkType($key, $value) |
|
| 7702 | } |
||
| 7703 |
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..