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 | 1208 | 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 | 129 | 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 | 160 | public function offsetExists($offset): bool |
|
| 716 | |||
| 717 | /** |
||
| 718 | * Returns the value at specified offset. |
||
| 719 | * |
||
| 720 | * @param int|string $offset |
||
| 721 | * |
||
| 722 | * @return mixed |
||
| 723 | * <p>Will return null if the offset did not exists.</p> |
||
| 724 | */ |
||
| 725 | 129 | public function &offsetGet($offset) |
|
| 736 | |||
| 737 | /** |
||
| 738 | * Assigns a value to the specified offset + check the type. |
||
| 739 | * |
||
| 740 | * @param int|string|null $offset |
||
| 741 | * @param mixed $value |
||
| 742 | * |
||
| 743 | * @return void |
||
| 744 | */ |
||
| 745 | 28 | public function offsetSet($offset, $value) |
|
| 763 | |||
| 764 | /** |
||
| 765 | * Unset an offset. |
||
| 766 | * |
||
| 767 | * @param int|string $offset |
||
| 768 | * |
||
| 769 | * @return void |
||
| 770 | * <p>(Mutable) Return nothing.</p> |
||
| 771 | */ |
||
| 772 | 25 | public function offsetUnset($offset) |
|
| 823 | |||
| 824 | /** |
||
| 825 | * Serialize the current "Arrayy"-object. |
||
| 826 | * |
||
| 827 | * EXAMPLE: <code> |
||
| 828 | * a([1, 4, 7])->serialize(); |
||
| 829 | * </code> |
||
| 830 | * |
||
| 831 | * @return string |
||
| 832 | */ |
||
| 833 | 2 | public function serialize(): string |
|
| 843 | |||
| 844 | /** |
||
| 845 | * Sets the iterator classname for the current "Arrayy"-object. |
||
| 846 | * |
||
| 847 | * @param string $iteratorClass |
||
| 848 | * |
||
| 849 | * @throws \InvalidArgumentException |
||
| 850 | * |
||
| 851 | * @return void |
||
| 852 | * |
||
| 853 | * @psalm-param class-string<\Arrayy\ArrayyIterator> $iteratorClass |
||
| 854 | */ |
||
| 855 | 1198 | public function setIteratorClass($iteratorClass) |
|
| 877 | |||
| 878 | /** |
||
| 879 | * Sort the entries with a user-defined comparison function and maintain key association. |
||
| 880 | * |
||
| 881 | * @param callable $function |
||
| 882 | * |
||
| 883 | * @throws \InvalidArgumentException |
||
| 884 | * |
||
| 885 | * @return $this |
||
| 886 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 887 | * |
||
| 888 | * @psalm-return static<TKey,T> |
||
| 889 | */ |
||
| 890 | 8 | View Code Duplication | public function uasort($function): self |
| 902 | |||
| 903 | /** |
||
| 904 | * Sort the entries with a user-defined comparison function and maintain key association. |
||
| 905 | * |
||
| 906 | * @param callable $function |
||
| 907 | * |
||
| 908 | * @throws \InvalidArgumentException |
||
| 909 | * |
||
| 910 | * @return $this |
||
| 911 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 912 | * |
||
| 913 | * @psalm-return static<TKey,T> |
||
| 914 | * @psalm-mutation-free |
||
| 915 | */ |
||
| 916 | 4 | public function uasortImmutable($function): self |
|
| 927 | |||
| 928 | /** |
||
| 929 | * Sort the entries by keys using a user-defined comparison function. |
||
| 930 | * |
||
| 931 | * @param callable $function |
||
| 932 | * |
||
| 933 | * @throws \InvalidArgumentException |
||
| 934 | * |
||
| 935 | * @return static |
||
| 936 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 937 | * |
||
| 938 | * @psalm-return static<TKey,T> |
||
| 939 | */ |
||
| 940 | 5 | public function uksort($function): self |
|
| 944 | |||
| 945 | /** |
||
| 946 | * Sort the entries by keys using a user-defined comparison function. |
||
| 947 | * |
||
| 948 | * @param callable $function |
||
| 949 | * |
||
| 950 | * @throws \InvalidArgumentException |
||
| 951 | * |
||
| 952 | * @return static |
||
| 953 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 954 | * |
||
| 955 | * @psalm-return static<TKey,T> |
||
| 956 | * @psalm-mutation-free |
||
| 957 | */ |
||
| 958 | 1 | public function uksortImmutable($function): self |
|
| 962 | |||
| 963 | /** |
||
| 964 | * Unserialize an string and return the instance of the "Arrayy"-class. |
||
| 965 | * |
||
| 966 | * EXAMPLE: <code> |
||
| 967 | * $serialized = a([1, 4, 7])->serialize(); |
||
| 968 | * a()->unserialize($serialized); |
||
| 969 | * </code> |
||
| 970 | * |
||
| 971 | * @param string $string |
||
| 972 | * |
||
| 973 | * @return $this |
||
| 974 | * |
||
| 975 | * @psalm-return static<TKey,T> |
||
| 976 | */ |
||
| 977 | 2 | public function unserialize($string): self |
|
| 987 | |||
| 988 | /** |
||
| 989 | * Append a (key) + values to the current array. |
||
| 990 | * |
||
| 991 | * EXAMPLE: <code> |
||
| 992 | * a(['fòô' => ['bàř']])->appendArrayValues(['foo1', 'foo2'], 'fòô'); // Arrayy['fòô' => ['bàř', 'foo1', 'foo2']] |
||
| 993 | * </code> |
||
| 994 | * |
||
| 995 | * @param array $values |
||
| 996 | * @param mixed $key |
||
| 997 | * |
||
| 998 | * @return $this |
||
| 999 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
| 1000 | * |
||
| 1001 | * @psalm-param array<mixed,T> $values |
||
| 1002 | * @psalm-param TKey|null $key |
||
| 1003 | * @psalm-return static<TKey,T> |
||
| 1004 | */ |
||
| 1005 | 1 | public function appendArrayValues(array $values, $key = null) |
|
| 1031 | |||
| 1032 | /** |
||
| 1033 | * Add a suffix to each key. |
||
| 1034 | * |
||
| 1035 | * @param mixed $prefix |
||
| 1036 | * |
||
| 1037 | * @return static |
||
| 1038 | * <p>(Immutable) Return an Arrayy object, with the prefixed keys.</p> |
||
| 1039 | * |
||
| 1040 | * @psalm-return static<TKey,T> |
||
| 1041 | * @psalm-mutation-free |
||
| 1042 | */ |
||
| 1043 | 10 | View Code Duplication | public function appendToEachKey($prefix): self |
| 1062 | |||
| 1063 | /** |
||
| 1064 | * Add a prefix to each value. |
||
| 1065 | * |
||
| 1066 | * @param mixed $prefix |
||
| 1067 | * |
||
| 1068 | * @return static |
||
| 1069 | * <p>(Immutable) Return an Arrayy object, with the prefixed values.</p> |
||
| 1070 | * |
||
| 1071 | * @psalm-return static<TKey,T> |
||
| 1072 | * @psalm-mutation-free |
||
| 1073 | */ |
||
| 1074 | 10 | View Code Duplication | public function appendToEachValue($prefix): self |
| 1093 | |||
| 1094 | /** |
||
| 1095 | * Sort an array in reverse order and maintain index association. |
||
| 1096 | * |
||
| 1097 | * @return $this |
||
| 1098 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1099 | * |
||
| 1100 | * @psalm-return static<TKey,T> |
||
| 1101 | */ |
||
| 1102 | 4 | public function arsort(): self |
|
| 1110 | |||
| 1111 | /** |
||
| 1112 | * Sort an array in reverse order and maintain index association. |
||
| 1113 | * |
||
| 1114 | * @return $this |
||
| 1115 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 1116 | * |
||
| 1117 | * @psalm-return static<TKey,T> |
||
| 1118 | * @psalm-mutation-free |
||
| 1119 | */ |
||
| 1120 | 10 | public function arsortImmutable(): self |
|
| 1130 | |||
| 1131 | /** |
||
| 1132 | * Iterate over the current array and execute a callback for each loop. |
||
| 1133 | * |
||
| 1134 | * EXAMPLE: <code> |
||
| 1135 | * $result = A::create(); |
||
| 1136 | * $closure = function ($value, $key) use ($result) { |
||
| 1137 | * $result[$key] = ':' . $value . ':'; |
||
| 1138 | * }; |
||
| 1139 | * a(['foo', 'bar' => 'bis'])->at($closure); // Arrayy[':foo:', 'bar' => ':bis:'] |
||
| 1140 | * </code> |
||
| 1141 | * |
||
| 1142 | * @param \Closure $closure |
||
| 1143 | * |
||
| 1144 | * @return static |
||
| 1145 | * <p>(Immutable)</p> |
||
| 1146 | * |
||
| 1147 | * @psalm-return static<TKey,T> |
||
| 1148 | * @psalm-mutation-free |
||
| 1149 | */ |
||
| 1150 | 3 | public function at(\Closure $closure): self |
|
| 1164 | |||
| 1165 | /** |
||
| 1166 | * Returns the average value of the current array. |
||
| 1167 | * |
||
| 1168 | * EXAMPLE: <code> |
||
| 1169 | * a([-9, -8, -7, 1.32])->average(2); // -5.67 |
||
| 1170 | * </code> |
||
| 1171 | * |
||
| 1172 | * @param int $decimals <p>The number of decimal-numbers to return.</p> |
||
| 1173 | * |
||
| 1174 | * @return float|int |
||
| 1175 | * <p>The average value.</p> |
||
| 1176 | * @psalm-mutation-free |
||
| 1177 | */ |
||
| 1178 | 10 | public function average($decimals = 0) |
|
| 1192 | |||
| 1193 | /** |
||
| 1194 | * Changes all keys in an array. |
||
| 1195 | * |
||
| 1196 | * @param int $case [optional] <p> Either <strong>CASE_UPPER</strong><br /> |
||
| 1197 | * or <strong>CASE_LOWER</strong> (default)</p> |
||
| 1198 | * |
||
| 1199 | * @return static |
||
| 1200 | * <p>(Immutable)</p> |
||
| 1201 | * |
||
| 1202 | * @psalm-return static<TKey,T> |
||
| 1203 | * @psalm-mutation-free |
||
| 1204 | */ |
||
| 1205 | 1 | public function changeKeyCase(int $case = \CASE_LOWER): self |
|
| 1234 | |||
| 1235 | /** |
||
| 1236 | * Change the path separator of the array wrapper. |
||
| 1237 | * |
||
| 1238 | * By default, the separator is: "." |
||
| 1239 | * |
||
| 1240 | * @param string $separator <p>Separator to set.</p> |
||
| 1241 | * |
||
| 1242 | * @return $this |
||
| 1243 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1244 | * |
||
| 1245 | * @psalm-return static<TKey,T> |
||
| 1246 | */ |
||
| 1247 | 11 | public function changeSeparator($separator): self |
|
| 1253 | |||
| 1254 | /** |
||
| 1255 | * Create a chunked version of the current array. |
||
| 1256 | * |
||
| 1257 | * EXAMPLE: <code> |
||
| 1258 | * a([-9, -8, -7, 1.32])->chunk(2); // Arrayy[[-9, -8], [-7, 1.32]] |
||
| 1259 | * </code> |
||
| 1260 | * |
||
| 1261 | * @param int $size <p>Size of each chunk.</p> |
||
| 1262 | * @param bool $preserveKeys <p>Whether array keys are preserved or no.</p> |
||
| 1263 | * |
||
| 1264 | * @return static |
||
| 1265 | * <p>(Immutable) A new array of chunks from the original array.</p> |
||
| 1266 | * |
||
| 1267 | * @psalm-return static<TKey,T> |
||
| 1268 | * @psalm-mutation-free |
||
| 1269 | */ |
||
| 1270 | 5 | public function chunk($size, $preserveKeys = false): self |
|
| 1320 | |||
| 1321 | /** |
||
| 1322 | * Clean all falsy values from the current array. |
||
| 1323 | * |
||
| 1324 | * EXAMPLE: <code> |
||
| 1325 | * a([-8 => -9, 1, 2 => false])->clean(); // Arrayy[-8 => -9, 1] |
||
| 1326 | * </code> |
||
| 1327 | * |
||
| 1328 | * @return static |
||
| 1329 | * <p>(Immutable)</p> |
||
| 1330 | * |
||
| 1331 | * @psalm-return static<TKey,T> |
||
| 1332 | * @psalm-mutation-free |
||
| 1333 | */ |
||
| 1334 | 8 | public function clean(): self |
|
| 1342 | |||
| 1343 | /** |
||
| 1344 | * WARNING!!! -> Clear the current full array or a $key of it. |
||
| 1345 | * |
||
| 1346 | * EXAMPLE: <code> |
||
| 1347 | * a([-8 => -9, 1, 2 => false])->clear(); // Arrayy[] |
||
| 1348 | * </code> |
||
| 1349 | * |
||
| 1350 | * @param int|int[]|string|string[]|null $key |
||
| 1351 | * |
||
| 1352 | * @return $this |
||
| 1353 | * <p>(Mutable) Return this Arrayy object, with an empty array.</p> |
||
| 1354 | * |
||
| 1355 | * @psalm-return static<TKey,T> |
||
| 1356 | */ |
||
| 1357 | 10 | public function clear($key = null): self |
|
| 1376 | |||
| 1377 | /** |
||
| 1378 | * Check if an item is in the current array. |
||
| 1379 | * |
||
| 1380 | * EXAMPLE: <code> |
||
| 1381 | * a([1, true])->contains(true); // true |
||
| 1382 | * </code> |
||
| 1383 | * |
||
| 1384 | * @param float|int|string $value |
||
| 1385 | * @param bool $recursive |
||
| 1386 | * @param bool $strict |
||
| 1387 | * |
||
| 1388 | * @return bool |
||
| 1389 | * @psalm-mutation-free |
||
| 1390 | */ |
||
| 1391 | 23 | public function contains($value, bool $recursive = false, bool $strict = true): bool |
|
| 1392 | { |
||
| 1393 | 23 | if ($recursive === true) { |
|
| 1394 | 18 | return $this->in_array_recursive($value, $this->toArray(), $strict); |
|
| 1395 | } |
||
| 1396 | |||
| 1397 | /** @noinspection PhpParameterByRefIsNotUsedAsReferenceInspection */ |
||
| 1398 | 14 | foreach ($this->getGeneratorByReference() as &$valueFromArray) { |
|
| 1399 | 11 | if ($strict) { |
|
| 1400 | 11 | if ($value === $valueFromArray) { |
|
| 1401 | 11 | return true; |
|
| 1402 | } |
||
| 1403 | } else { |
||
| 1404 | /** @noinspection NestedPositiveIfStatementsInspection */ |
||
| 1405 | if ($value == $valueFromArray) { |
||
| 1406 | return true; |
||
| 1407 | } |
||
| 1408 | } |
||
| 1409 | } |
||
| 1410 | |||
| 1411 | 7 | return false; |
|
| 1412 | } |
||
| 1413 | |||
| 1414 | /** |
||
| 1415 | * Check if an (case-insensitive) string is in the current array. |
||
| 1416 | * |
||
| 1417 | * EXAMPLE: <code> |
||
| 1418 | * a(['E', 'é'])->containsCaseInsensitive('É'); // true |
||
| 1419 | * </code> |
||
| 1420 | * |
||
| 1421 | * @param mixed $value |
||
| 1422 | * @param bool $recursive |
||
| 1423 | * |
||
| 1424 | * @return bool |
||
| 1425 | * @psalm-mutation-free |
||
| 1426 | * |
||
| 1427 | * @psalm-suppress InvalidCast - hack for int|float|bool support |
||
| 1428 | */ |
||
| 1429 | 26 | public function containsCaseInsensitive($value, $recursive = false): bool |
|
| 1460 | |||
| 1461 | /** |
||
| 1462 | * Check if the given key/index exists in the array. |
||
| 1463 | * |
||
| 1464 | * EXAMPLE: <code> |
||
| 1465 | * a([1 => true])->containsKey(1); // true |
||
| 1466 | * </code> |
||
| 1467 | * |
||
| 1468 | * @param int|string $key <p>key/index to search for</p> |
||
| 1469 | * |
||
| 1470 | * @return bool |
||
| 1471 | * <p>Returns true if the given key/index exists in the array, false otherwise.</p> |
||
| 1472 | * |
||
| 1473 | * @psalm-mutation-free |
||
| 1474 | */ |
||
| 1475 | 4 | public function containsKey($key): bool |
|
| 1479 | |||
| 1480 | /** |
||
| 1481 | * Check if all given needles are present in the array as key/index. |
||
| 1482 | * |
||
| 1483 | * EXAMPLE: <code> |
||
| 1484 | * a([1 => true])->containsKeys(array(1 => 0)); // true |
||
| 1485 | * </code> |
||
| 1486 | * |
||
| 1487 | * @param array $needles <p>The keys you are searching for.</p> |
||
| 1488 | * @param bool $recursive |
||
| 1489 | * |
||
| 1490 | * @return bool |
||
| 1491 | * <p>Returns true if all the given keys/indexes exists in the array, false otherwise.</p> |
||
| 1492 | * |
||
| 1493 | * @psalm-param array<mixed,mixed>|array<TKey> $needles |
||
| 1494 | * @psalm-mutation-free |
||
| 1495 | */ |
||
| 1496 | 2 | public function containsKeys(array $needles, $recursive = false): bool |
|
| 1524 | |||
| 1525 | /** |
||
| 1526 | * Check if all given needles are present in the array as key/index. |
||
| 1527 | * |
||
| 1528 | * @param array $needles <p>The keys you are searching for.</p> |
||
| 1529 | * |
||
| 1530 | * @return bool |
||
| 1531 | * <p>Returns true if all the given keys/indexes exists in the array, false otherwise.</p> |
||
| 1532 | * |
||
| 1533 | * @psalm-param array<mixed,mixed>|array<TKey> $needles |
||
| 1534 | * @psalm-mutation-free |
||
| 1535 | */ |
||
| 1536 | 1 | public function containsKeysRecursive(array $needles): bool |
|
| 1540 | |||
| 1541 | /** |
||
| 1542 | * alias: for "Arrayy->contains()" |
||
| 1543 | * |
||
| 1544 | * @param float|int|string $value |
||
| 1545 | * |
||
| 1546 | * @return bool |
||
| 1547 | * |
||
| 1548 | * @see Arrayy::contains() |
||
| 1549 | * @psalm-mutation-free |
||
| 1550 | */ |
||
| 1551 | 9 | public function containsValue($value): bool |
|
| 1555 | |||
| 1556 | /** |
||
| 1557 | * alias: for "Arrayy->contains($value, true)" |
||
| 1558 | * |
||
| 1559 | * @param float|int|string $value |
||
| 1560 | * |
||
| 1561 | * @return bool |
||
| 1562 | * |
||
| 1563 | * @see Arrayy::contains() |
||
| 1564 | * @psalm-mutation-free |
||
| 1565 | */ |
||
| 1566 | 18 | public function containsValueRecursive($value): bool |
|
| 1570 | |||
| 1571 | /** |
||
| 1572 | * Check if all given needles are present in the array. |
||
| 1573 | * |
||
| 1574 | * EXAMPLE: <code> |
||
| 1575 | * a([1, true])->containsValues(array(1, true)); // true |
||
| 1576 | * </code> |
||
| 1577 | * |
||
| 1578 | * @param array $needles |
||
| 1579 | * |
||
| 1580 | * @return bool |
||
| 1581 | * <p>Returns true if all the given values exists in the array, false otherwise.</p> |
||
| 1582 | * |
||
| 1583 | * @psalm-param array<mixed>|array<T> $needles |
||
| 1584 | * @psalm-mutation-free |
||
| 1585 | */ |
||
| 1586 | 1 | public function containsValues(array $needles): bool |
|
| 1601 | |||
| 1602 | /** |
||
| 1603 | * Counts all the values of an array |
||
| 1604 | * |
||
| 1605 | * @see http://php.net/manual/en/function.array-count-values.php |
||
| 1606 | * |
||
| 1607 | * @return static |
||
| 1608 | * <p> |
||
| 1609 | * (Immutable) |
||
| 1610 | * An associative Arrayy-object of values from input as |
||
| 1611 | * keys and their count as value. |
||
| 1612 | * </p> |
||
| 1613 | * |
||
| 1614 | * @psalm-return static<TKey,T> |
||
| 1615 | * @psalm-mutation-free |
||
| 1616 | */ |
||
| 1617 | 7 | public function countValues(): self |
|
| 1621 | |||
| 1622 | /** |
||
| 1623 | * Creates an Arrayy object. |
||
| 1624 | * |
||
| 1625 | * @param mixed $data |
||
| 1626 | * @param string $iteratorClass |
||
| 1627 | * @param bool $checkPropertiesInConstructor |
||
| 1628 | * |
||
| 1629 | * @return static |
||
| 1630 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1631 | * |
||
| 1632 | * @psalm-param class-string<\Arrayy\ArrayyIterator> $iteratorClass |
||
| 1633 | * |
||
| 1634 | * @psalm-mutation-free |
||
| 1635 | */ |
||
| 1636 | 726 | public static function create( |
|
| 1647 | |||
| 1648 | /** |
||
| 1649 | * Flatten an array with the given character as a key delimiter. |
||
| 1650 | * |
||
| 1651 | * EXAMPLE: <code> |
||
| 1652 | * $callable = function ($a, $b) { |
||
| 1653 | * if ($a == $b) { |
||
| 1654 | * return 0; |
||
| 1655 | * } |
||
| 1656 | * return ($a > $b) ? 1 : -1; |
||
| 1657 | * }; |
||
| 1658 | * $arrayy = a(['three' => 3, 'one' => 1, 'two' => 2]); |
||
| 1659 | * $resultArrayy = $arrayy->customSortKeys($callable); // Arrayy['one' => 1, 'three' => 3, 'two' => 2] |
||
| 1660 | * </code> |
||
| 1661 | * |
||
| 1662 | * @param string $delimiter |
||
| 1663 | * @param string $prepend |
||
| 1664 | * @param array|null $items |
||
| 1665 | * |
||
| 1666 | * @return array |
||
| 1667 | */ |
||
| 1668 | 2 | public function flatten($delimiter = '.', $prepend = '', $items = null) |
|
| 1691 | |||
| 1692 | /** |
||
| 1693 | * WARNING: Creates an Arrayy object by reference. |
||
| 1694 | * |
||
| 1695 | * @param array $array |
||
| 1696 | * |
||
| 1697 | * @return $this |
||
| 1698 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1699 | * |
||
| 1700 | * @psalm-param array<mixed,mixed>|array<array-key,mixed> $array |
||
| 1701 | */ |
||
| 1702 | 26 | public function createByReference(array &$array = []): self |
|
| 1710 | |||
| 1711 | /** |
||
| 1712 | * Create an new instance from a callable function which will return an Generator. |
||
| 1713 | * |
||
| 1714 | * @param callable $generatorFunction |
||
| 1715 | * |
||
| 1716 | * @return static |
||
| 1717 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1718 | * |
||
| 1719 | * @psalm-param callable():\Generator<array-key,mixed> $generatorFunction |
||
| 1720 | * |
||
| 1721 | * @psalm-mutation-free |
||
| 1722 | */ |
||
| 1723 | 7 | public static function createFromGeneratorFunction(callable $generatorFunction): self |
|
| 1727 | |||
| 1728 | /** |
||
| 1729 | * Create an new instance filled with a copy of values from a "Generator"-object. |
||
| 1730 | * |
||
| 1731 | * @param \Generator $generator |
||
| 1732 | * |
||
| 1733 | * @return static |
||
| 1734 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1735 | * |
||
| 1736 | * @psalm-param \Generator<array-key,mixed> $generator |
||
| 1737 | * |
||
| 1738 | * @psalm-mutation-free |
||
| 1739 | */ |
||
| 1740 | 4 | public static function createFromGeneratorImmutable(\Generator $generator): self |
|
| 1744 | |||
| 1745 | /** |
||
| 1746 | * Create an new Arrayy object via JSON. |
||
| 1747 | * |
||
| 1748 | * @param string $json |
||
| 1749 | * |
||
| 1750 | * @return static |
||
| 1751 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1752 | * |
||
| 1753 | * @psalm-mutation-free |
||
| 1754 | */ |
||
| 1755 | 5 | public static function createFromJson(string $json): self |
|
| 1759 | |||
| 1760 | /** |
||
| 1761 | * Create an new Arrayy object via JSON. |
||
| 1762 | * |
||
| 1763 | * @param array $array |
||
| 1764 | * |
||
| 1765 | * @return static |
||
| 1766 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1767 | * |
||
| 1768 | * @psalm-mutation-free |
||
| 1769 | */ |
||
| 1770 | 1 | public static function createFromArray(array $array): self |
|
| 1774 | |||
| 1775 | /** |
||
| 1776 | * Create an new instance filled with values from an object that is iterable. |
||
| 1777 | * |
||
| 1778 | * @param \Traversable $object <p>iterable object</p> |
||
| 1779 | * |
||
| 1780 | * @return static |
||
| 1781 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1782 | * |
||
| 1783 | * @psalm-param \Traversable<array-key,mixed> $object |
||
| 1784 | * |
||
| 1785 | * @psalm-mutation-free |
||
| 1786 | */ |
||
| 1787 | 4 | public static function createFromObject(\Traversable $object): self |
|
| 1807 | |||
| 1808 | /** |
||
| 1809 | * Create an new instance filled with values from an object. |
||
| 1810 | * |
||
| 1811 | * @param object $object |
||
| 1812 | * |
||
| 1813 | * @return static |
||
| 1814 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1815 | * |
||
| 1816 | * @psalm-mutation-free |
||
| 1817 | */ |
||
| 1818 | 5 | public static function createFromObjectVars($object): self |
|
| 1822 | |||
| 1823 | /** |
||
| 1824 | * Create an new Arrayy object via string. |
||
| 1825 | * |
||
| 1826 | * @param string $str <p>The input string.</p> |
||
| 1827 | * @param string|null $delimiter <p>The boundary string.</p> |
||
| 1828 | * @param string|null $regEx <p>Use the $delimiter or the $regEx, so if $pattern is null, $delimiter will be |
||
| 1829 | * used.</p> |
||
| 1830 | * |
||
| 1831 | * @return static |
||
| 1832 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1833 | * |
||
| 1834 | * @psalm-mutation-free |
||
| 1835 | */ |
||
| 1836 | 10 | public static function createFromString(string $str, string $delimiter = null, string $regEx = null): self |
|
| 1868 | |||
| 1869 | /** |
||
| 1870 | * Create an new instance filled with a copy of values from a "Traversable"-object. |
||
| 1871 | * |
||
| 1872 | * @param \Traversable $traversable |
||
| 1873 | * |
||
| 1874 | * @return static |
||
| 1875 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1876 | * |
||
| 1877 | * @psalm-param \Traversable<array-key,mixed> $traversable |
||
| 1878 | * |
||
| 1879 | * @psalm-mutation-free |
||
| 1880 | */ |
||
| 1881 | 1 | public static function createFromTraversableImmutable(\Traversable $traversable): self |
|
| 1885 | |||
| 1886 | /** |
||
| 1887 | * Create an new instance containing a range of elements. |
||
| 1888 | * |
||
| 1889 | * @param float|int|string $low <p>First value of the sequence.</p> |
||
| 1890 | * @param float|int|string $high <p>The sequence is ended upon reaching the end value.</p> |
||
| 1891 | * @param float|int $step <p>Used as the increment between elements in the sequence.</p> |
||
| 1892 | * |
||
| 1893 | * @return static |
||
| 1894 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1895 | * |
||
| 1896 | * @psalm-mutation-free |
||
| 1897 | */ |
||
| 1898 | 2 | public static function createWithRange($low, $high, $step = 1): self |
|
| 1902 | |||
| 1903 | /** |
||
| 1904 | * Gets the element of the array at the current internal iterator position. |
||
| 1905 | * |
||
| 1906 | * @return false|mixed |
||
| 1907 | */ |
||
| 1908 | public function current() |
||
| 1912 | |||
| 1913 | /** |
||
| 1914 | * Custom sort by index via "uksort". |
||
| 1915 | * |
||
| 1916 | * EXAMPLE: <code> |
||
| 1917 | * $callable = function ($a, $b) { |
||
| 1918 | * if ($a == $b) { |
||
| 1919 | * return 0; |
||
| 1920 | * } |
||
| 1921 | * return ($a > $b) ? 1 : -1; |
||
| 1922 | * }; |
||
| 1923 | * $arrayy = a(['three' => 3, 'one' => 1, 'two' => 2]); |
||
| 1924 | * $resultArrayy = $arrayy->customSortKeys($callable); // Arrayy['one' => 1, 'three' => 3, 'two' => 2] |
||
| 1925 | * </code> |
||
| 1926 | * |
||
| 1927 | * @see http://php.net/manual/en/function.uksort.php |
||
| 1928 | * |
||
| 1929 | * @param callable $function |
||
| 1930 | * |
||
| 1931 | * @throws \InvalidArgumentException |
||
| 1932 | * |
||
| 1933 | * @return $this |
||
| 1934 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1935 | * |
||
| 1936 | * @psalm-return static<TKey,T> |
||
| 1937 | */ |
||
| 1938 | 5 | public function customSortKeys(callable $function): self |
|
| 1946 | |||
| 1947 | /** |
||
| 1948 | * Custom sort by index via "uksort". |
||
| 1949 | * |
||
| 1950 | * @see http://php.net/manual/en/function.uksort.php |
||
| 1951 | * |
||
| 1952 | * @param callable $function |
||
| 1953 | * |
||
| 1954 | * @throws \InvalidArgumentException |
||
| 1955 | * |
||
| 1956 | * @return $this |
||
| 1957 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 1958 | * |
||
| 1959 | * @psalm-return static<TKey,T> |
||
| 1960 | * @psalm-mutation-free |
||
| 1961 | */ |
||
| 1962 | 1 | public function customSortKeysImmutable(callable $function): self |
|
| 1975 | |||
| 1976 | /** |
||
| 1977 | * Custom sort by value via "usort". |
||
| 1978 | * |
||
| 1979 | * EXAMPLE: <code> |
||
| 1980 | * $callable = function ($a, $b) { |
||
| 1981 | * if ($a == $b) { |
||
| 1982 | * return 0; |
||
| 1983 | * } |
||
| 1984 | * return ($a > $b) ? 1 : -1; |
||
| 1985 | * }; |
||
| 1986 | * $arrayy = a(['three' => 3, 'one' => 1, 'two' => 2]); |
||
| 1987 | * $resultArrayy = $arrayy->customSortValues($callable); // Arrayy['one' => 1, 'two' => 2, 'three' => 3] |
||
| 1988 | * </code> |
||
| 1989 | * |
||
| 1990 | * @see http://php.net/manual/en/function.usort.php |
||
| 1991 | * |
||
| 1992 | * @param callable $function |
||
| 1993 | * |
||
| 1994 | * @throws \InvalidArgumentException |
||
| 1995 | * |
||
| 1996 | * @return $this |
||
| 1997 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1998 | * |
||
| 1999 | * @psalm-return static<TKey,T> |
||
| 2000 | */ |
||
| 2001 | 10 | View Code Duplication | public function customSortValues($function): self |
| 2013 | |||
| 2014 | /** |
||
| 2015 | * Custom sort by value via "usort". |
||
| 2016 | * |
||
| 2017 | * @see http://php.net/manual/en/function.usort.php |
||
| 2018 | * |
||
| 2019 | * @param callable $function |
||
| 2020 | * |
||
| 2021 | * @throws \InvalidArgumentException |
||
| 2022 | * |
||
| 2023 | * @return $this |
||
| 2024 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 2025 | * |
||
| 2026 | * @psalm-return static<TKey,T> |
||
| 2027 | * @psalm-mutation-free |
||
| 2028 | */ |
||
| 2029 | 4 | public function customSortValuesImmutable($function): self |
|
| 2040 | |||
| 2041 | /** |
||
| 2042 | * Delete the given key or keys. |
||
| 2043 | * |
||
| 2044 | * @param int|int[]|string|string[] $keyOrKeys |
||
| 2045 | * |
||
| 2046 | * @return void |
||
| 2047 | */ |
||
| 2048 | 9 | public function delete($keyOrKeys) |
|
| 2056 | |||
| 2057 | /** |
||
| 2058 | * Return values that are only in the current array. |
||
| 2059 | * |
||
| 2060 | * EXAMPLE: <code> |
||
| 2061 | * a([1 => 1, 2 => 2])->diff([1 => 1]); // Arrayy[2 => 2] |
||
| 2062 | * </code> |
||
| 2063 | * |
||
| 2064 | * @param array ...$array |
||
| 2065 | * |
||
| 2066 | * @return static |
||
| 2067 | * <p>(Immutable)</p> |
||
| 2068 | * |
||
| 2069 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$array |
||
| 2070 | * @psalm-return static<TKey,T> |
||
| 2071 | * @psalm-mutation-free |
||
| 2072 | */ |
||
| 2073 | 13 | public function diff(...$array): self |
|
| 2081 | |||
| 2082 | /** |
||
| 2083 | * Return values that are only in the current array. |
||
| 2084 | * |
||
| 2085 | * @param array ...$array |
||
| 2086 | * |
||
| 2087 | * @return static |
||
| 2088 | * <p>(Immutable)</p> |
||
| 2089 | * |
||
| 2090 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$array |
||
| 2091 | * @psalm-return static<TKey,T> |
||
| 2092 | * @psalm-mutation-free |
||
| 2093 | */ |
||
| 2094 | 8 | public function diffKey(...$array): self |
|
| 2102 | |||
| 2103 | /** |
||
| 2104 | * Return values and Keys that are only in the current array. |
||
| 2105 | * |
||
| 2106 | * @param array $array |
||
| 2107 | * |
||
| 2108 | * @return static |
||
| 2109 | * <p>(Immutable)</p> |
||
| 2110 | * |
||
| 2111 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 2112 | * @psalm-return static<TKey,T> |
||
| 2113 | * @psalm-mutation-free |
||
| 2114 | */ |
||
| 2115 | 8 | public function diffKeyAndValue(array $array = []): self |
|
| 2123 | |||
| 2124 | /** |
||
| 2125 | * Return values that are only in the current multi-dimensional array. |
||
| 2126 | * |
||
| 2127 | * EXAMPLE: <code> |
||
| 2128 | * a([1 => [1 => 1], 2 => [2 => 2]])->diffRecursive([1 => [1 => 1]]); // Arrayy[2 => [2 => 2]] |
||
| 2129 | * </code> |
||
| 2130 | * |
||
| 2131 | * @param array $array |
||
| 2132 | * @param array|\Generator|null $helperVariableForRecursion <p>(only for internal usage)</p> |
||
| 2133 | * |
||
| 2134 | * @return static |
||
| 2135 | * <p>(Immutable)</p> |
||
| 2136 | * |
||
| 2137 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 2138 | * @psalm-param null|array<TKey,T>|\Generator<TKey,T> $helperVariableForRecursion |
||
| 2139 | * @psalm-return static<TKey,T> |
||
| 2140 | * @psalm-mutation-free |
||
| 2141 | */ |
||
| 2142 | 1 | public function diffRecursive(array $array = [], $helperVariableForRecursion = null): self |
|
| 2177 | |||
| 2178 | /** |
||
| 2179 | * Return values that are only in the new $array. |
||
| 2180 | * |
||
| 2181 | * EXAMPLE: <code> |
||
| 2182 | * a([1 => 1])->diffReverse([1 => 1, 2 => 2]); // Arrayy[2 => 2] |
||
| 2183 | * </code> |
||
| 2184 | * |
||
| 2185 | * @param array $array |
||
| 2186 | * |
||
| 2187 | * @return static |
||
| 2188 | * <p>(Immutable)</p> |
||
| 2189 | * |
||
| 2190 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 2191 | * @psalm-return static<TKey,T> |
||
| 2192 | * @psalm-mutation-free |
||
| 2193 | */ |
||
| 2194 | 8 | public function diffReverse(array $array = []): self |
|
| 2202 | |||
| 2203 | /** |
||
| 2204 | * Divide an array into two arrays. One with keys and the other with values. |
||
| 2205 | * |
||
| 2206 | * EXAMPLE: <code> |
||
| 2207 | * a(['a' => 1, 'b' => ''])->divide(); // Arrayy[Arrayy['a', 'b'], Arrayy[1, '']] |
||
| 2208 | * </code> |
||
| 2209 | * |
||
| 2210 | * @return static |
||
| 2211 | * <p>(Immutable)</p> |
||
| 2212 | * |
||
| 2213 | * @psalm-return static<TKey,T> |
||
| 2214 | * @psalm-mutation-free |
||
| 2215 | */ |
||
| 2216 | 1 | public function divide(): self |
|
| 2227 | |||
| 2228 | /** |
||
| 2229 | * Iterate over the current array and modify the array's value. |
||
| 2230 | * |
||
| 2231 | * EXAMPLE: <code> |
||
| 2232 | * $result = A::create(); |
||
| 2233 | * $closure = function ($value) { |
||
| 2234 | * return ':' . $value . ':'; |
||
| 2235 | * }; |
||
| 2236 | * a(['foo', 'bar' => 'bis'])->each($closure); // Arrayy[':foo:', 'bar' => ':bis:'] |
||
| 2237 | * </code> |
||
| 2238 | * |
||
| 2239 | * @param \Closure $closure |
||
| 2240 | * |
||
| 2241 | * @return static |
||
| 2242 | * <p>(Immutable)</p> |
||
| 2243 | * |
||
| 2244 | * @psalm-return static<TKey,T> |
||
| 2245 | * @psalm-mutation-free |
||
| 2246 | */ |
||
| 2247 | 5 | View Code Duplication | public function each(\Closure $closure): self |
| 2262 | |||
| 2263 | /** |
||
| 2264 | * Sets the internal iterator to the last element in the array and returns this element. |
||
| 2265 | * |
||
| 2266 | * @return mixed |
||
| 2267 | */ |
||
| 2268 | public function end() |
||
| 2272 | |||
| 2273 | /** |
||
| 2274 | * Check if a value is in the current array using a closure. |
||
| 2275 | * |
||
| 2276 | * EXAMPLE: <code> |
||
| 2277 | * $callable = function ($value, $key) { |
||
| 2278 | * return 2 === $key and 'two' === $value; |
||
| 2279 | * }; |
||
| 2280 | * a(['foo', 2 => 'two'])->exists($callable); // true |
||
| 2281 | * </code> |
||
| 2282 | * |
||
| 2283 | * @param \Closure $closure |
||
| 2284 | * |
||
| 2285 | * @return bool |
||
| 2286 | * <p>Returns true if the given value is found, false otherwise.</p> |
||
| 2287 | */ |
||
| 2288 | 4 | public function exists(\Closure $closure): bool |
|
| 2303 | |||
| 2304 | /** |
||
| 2305 | * Fill the array until "$num" with "$default" values. |
||
| 2306 | * |
||
| 2307 | * EXAMPLE: <code> |
||
| 2308 | * a(['bar'])->fillWithDefaults(3, 'foo'); // Arrayy['bar', 'foo', 'foo'] |
||
| 2309 | * </code> |
||
| 2310 | * |
||
| 2311 | * @param int $num |
||
| 2312 | * @param mixed $default |
||
| 2313 | * |
||
| 2314 | * @return static |
||
| 2315 | * <p>(Immutable)</p> |
||
| 2316 | * |
||
| 2317 | * @psalm-return static<TKey,T> |
||
| 2318 | * @psalm-mutation-free |
||
| 2319 | */ |
||
| 2320 | 8 | public function fillWithDefaults(int $num, $default = null): self |
|
| 2343 | |||
| 2344 | /** |
||
| 2345 | * Find all items in an array that pass the truth test. |
||
| 2346 | * |
||
| 2347 | * EXAMPLE: <code> |
||
| 2348 | * $closure = function ($value) { |
||
| 2349 | * return $value % 2 !== 0; |
||
| 2350 | * } |
||
| 2351 | * a([1, 2, 3, 4])->filter($closure); // Arrayy[0 => 1, 2 => 3] |
||
| 2352 | * </code> |
||
| 2353 | * |
||
| 2354 | * @param \Closure|null $closure [optional] <p> |
||
| 2355 | * The callback function to use |
||
| 2356 | * </p> |
||
| 2357 | * <p> |
||
| 2358 | * If no callback is supplied, all entries of |
||
| 2359 | * input equal to false (see |
||
| 2360 | * converting to |
||
| 2361 | * boolean) will be removed. |
||
| 2362 | * </p> |
||
| 2363 | * @param int $flag [optional] <p> |
||
| 2364 | * Flag determining what arguments are sent to <i>callback</i>: |
||
| 2365 | * </p> |
||
| 2366 | * <ul> |
||
| 2367 | * <li> |
||
| 2368 | * <b>ARRAY_FILTER_USE_KEY</b> (1) - pass key as the only argument |
||
| 2369 | * to <i>callback</i> instead of the value |
||
| 2370 | * </li> |
||
| 2371 | * <li> |
||
| 2372 | * <b>ARRAY_FILTER_USE_BOTH</b> (2) - pass both value and key as |
||
| 2373 | * arguments to <i>callback</i> instead of the value |
||
| 2374 | * </li> |
||
| 2375 | * </ul> |
||
| 2376 | * |
||
| 2377 | * @return static |
||
| 2378 | * <p>(Immutable)</p> |
||
| 2379 | * |
||
| 2380 | * @psalm-param null|\Closure(T=,TKey=):bool|\Closure(T=):bool||\Closure(TKey=):bool $closure |
||
| 2381 | * @psalm-return static<TKey,T> |
||
| 2382 | * @psalm-mutation-free |
||
| 2383 | */ |
||
| 2384 | 12 | public function filter($closure = null, int $flag = \ARRAY_FILTER_USE_BOTH) |
|
| 2422 | |||
| 2423 | /** |
||
| 2424 | * Filters an array of objects (or a numeric array of associative arrays) based on the value of a particular |
||
| 2425 | * property within that. |
||
| 2426 | * |
||
| 2427 | * @param string $property |
||
| 2428 | * @param mixed $value |
||
| 2429 | * @param string $comparisonOp |
||
| 2430 | * <p> |
||
| 2431 | * 'eq' (equals),<br /> |
||
| 2432 | * 'gt' (greater),<br /> |
||
| 2433 | * 'gte' || 'ge' (greater or equals),<br /> |
||
| 2434 | * 'lt' (less),<br /> |
||
| 2435 | * 'lte' || 'le' (less or equals),<br /> |
||
| 2436 | * 'ne' (not equals),<br /> |
||
| 2437 | * 'contains',<br /> |
||
| 2438 | * 'notContains',<br /> |
||
| 2439 | * 'newer' (via strtotime),<br /> |
||
| 2440 | * 'older' (via strtotime),<br /> |
||
| 2441 | * </p> |
||
| 2442 | * |
||
| 2443 | * @return static |
||
| 2444 | * <p>(Immutable)</p> |
||
| 2445 | * |
||
| 2446 | * @psalm-param mixed|T $value |
||
| 2447 | * @psalm-return static<TKey,T> |
||
| 2448 | * @psalm-mutation-free |
||
| 2449 | * |
||
| 2450 | * @psalm-suppress MissingClosureReturnType |
||
| 2451 | * @psalm-suppress MissingClosureParamType |
||
| 2452 | */ |
||
| 2453 | 1 | public function filterBy( |
|
| 2525 | |||
| 2526 | /** |
||
| 2527 | * Find the first item in an array that passes the truth test, otherwise return false. |
||
| 2528 | * |
||
| 2529 | * EXAMPLE: <code> |
||
| 2530 | * $search = 'foo'; |
||
| 2531 | * $closure = function ($value, $key) use ($search) { |
||
| 2532 | * return $value === $search; |
||
| 2533 | * }; |
||
| 2534 | * a(['foo', 'bar', 'lall'])->find($closure); // 'foo' |
||
| 2535 | * </code> |
||
| 2536 | * |
||
| 2537 | * @param \Closure $closure |
||
| 2538 | * |
||
| 2539 | * @return false|mixed |
||
| 2540 | * <p>Return false if we did not find the value.</p> |
||
| 2541 | */ |
||
| 2542 | 8 | View Code Duplication | public function find(\Closure $closure) |
| 2552 | |||
| 2553 | /** |
||
| 2554 | * find by ... |
||
| 2555 | * |
||
| 2556 | * EXAMPLE: <code> |
||
| 2557 | * $array = [ |
||
| 2558 | * 0 => ['id' => 123, 'name' => 'foo', 'group' => 'primary', 'value' => 123456, 'when' => '2014-01-01'], |
||
| 2559 | * 1 => ['id' => 456, 'name' => 'bar', 'group' => 'primary', 'value' => 1468, 'when' => '2014-07-15'], |
||
| 2560 | * ]; |
||
| 2561 | * a($array)->filterBy('name', 'foo'); // Arrayy[0 => ['id' => 123, 'name' => 'foo', 'group' => 'primary', 'value' => 123456, 'when' => '2014-01-01']] |
||
| 2562 | * </code> |
||
| 2563 | * |
||
| 2564 | * @param string $property |
||
| 2565 | * @param mixed $value |
||
| 2566 | * @param string $comparisonOp |
||
| 2567 | * |
||
| 2568 | * @return static |
||
| 2569 | * <p>(Immutable)</p> |
||
| 2570 | * |
||
| 2571 | * @psalm-param mixed|T $value |
||
| 2572 | * @psalm-return static<TKey,T> |
||
| 2573 | * @psalm-mutation-free |
||
| 2574 | */ |
||
| 2575 | 1 | public function findBy(string $property, $value, string $comparisonOp = 'eq'): self |
|
| 2579 | |||
| 2580 | /** |
||
| 2581 | * Get the first value from the current array. |
||
| 2582 | * |
||
| 2583 | * EXAMPLE: <code> |
||
| 2584 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->first(); // 'foo' |
||
| 2585 | * </code> |
||
| 2586 | * |
||
| 2587 | * @return mixed |
||
| 2588 | * <p>Return null if there wasn't a element.</p> |
||
| 2589 | */ |
||
| 2590 | 22 | public function first() |
|
| 2599 | |||
| 2600 | /** |
||
| 2601 | * Get the first key from the current array. |
||
| 2602 | * |
||
| 2603 | * @return mixed |
||
| 2604 | * <p>Return null if there wasn't a element.</p> |
||
| 2605 | * @psalm-mutation-free |
||
| 2606 | */ |
||
| 2607 | 29 | public function firstKey() |
|
| 2613 | |||
| 2614 | /** |
||
| 2615 | * Get the first value(s) from the current array. |
||
| 2616 | * And will return an empty array if there was no first entry. |
||
| 2617 | * |
||
| 2618 | * EXAMPLE: <code> |
||
| 2619 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->firstsImmutable(2); // Arrayy[0 => 'foo', 1 => 'bar'] |
||
| 2620 | * </code> |
||
| 2621 | * |
||
| 2622 | * @param int|null $number <p>How many values you will take?</p> |
||
| 2623 | * |
||
| 2624 | * @return static |
||
| 2625 | * <p>(Immutable)</p> |
||
| 2626 | * |
||
| 2627 | * @psalm-return static<TKey,T> |
||
| 2628 | * @psalm-mutation-free |
||
| 2629 | */ |
||
| 2630 | 37 | public function firstsImmutable(int $number = null): self |
|
| 2646 | |||
| 2647 | /** |
||
| 2648 | * Get the first value(s) from the current array. |
||
| 2649 | * And will return an empty array if there was no first entry. |
||
| 2650 | * |
||
| 2651 | * @param int|null $number <p>How many values you will take?</p> |
||
| 2652 | * |
||
| 2653 | * @return static |
||
| 2654 | * <p>(Immutable)</p> |
||
| 2655 | * |
||
| 2656 | * @psalm-return static<TKey,T> |
||
| 2657 | * @psalm-mutation-free |
||
| 2658 | */ |
||
| 2659 | 3 | View Code Duplication | public function firstsKeys(int $number = null): self |
| 2675 | |||
| 2676 | /** |
||
| 2677 | * Get and remove the first value(s) from the current array. |
||
| 2678 | * And will return an empty array if there was no first entry. |
||
| 2679 | * |
||
| 2680 | * EXAMPLE: <code> |
||
| 2681 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->firstsMutable(); // 'foo' |
||
| 2682 | * </code> |
||
| 2683 | * |
||
| 2684 | * @param int|null $number <p>How many values you will take?</p> |
||
| 2685 | * |
||
| 2686 | * @return $this |
||
| 2687 | * <p>(Mutable)</p> |
||
| 2688 | * |
||
| 2689 | * @psalm-return static<TKey,T> |
||
| 2690 | */ |
||
| 2691 | 34 | public function firstsMutable(int $number = null): self |
|
| 2703 | |||
| 2704 | /** |
||
| 2705 | * Exchanges all keys with their associated values in an array. |
||
| 2706 | * |
||
| 2707 | * EXAMPLE: <code> |
||
| 2708 | * a([0 => 'foo', 1 => 'bar'])->flip(); // Arrayy['foo' => 0, 'bar' => 1] |
||
| 2709 | * </code> |
||
| 2710 | * |
||
| 2711 | * @return static |
||
| 2712 | * <p>(Immutable)</p> |
||
| 2713 | * |
||
| 2714 | * @psalm-return static<array-key,TKey> |
||
| 2715 | * @psalm-mutation-free |
||
| 2716 | */ |
||
| 2717 | 1 | public function flip(): self |
|
| 2731 | |||
| 2732 | /** |
||
| 2733 | * Get a value from an array (optional using dot-notation). |
||
| 2734 | * |
||
| 2735 | * EXAMPLE: <code> |
||
| 2736 | * $arrayy = a(['user' => ['lastname' => 'Moelleken']]); |
||
| 2737 | * $arrayy->get('user.lastname'); // 'Moelleken' |
||
| 2738 | * // --- |
||
| 2739 | * $arrayy = new A(); |
||
| 2740 | * $arrayy['user'] = ['lastname' => 'Moelleken']; |
||
| 2741 | * $arrayy['user.firstname'] = 'Lars'; |
||
| 2742 | * $arrayy['user']['lastname']; // Moelleken |
||
| 2743 | * $arrayy['user.lastname']; // Moelleken |
||
| 2744 | * $arrayy['user.firstname']; // Lars |
||
| 2745 | * </code> |
||
| 2746 | * |
||
| 2747 | * @param mixed $key <p>The key to look for.</p> |
||
| 2748 | * @param mixed $fallback <p>Value to fallback to.</p> |
||
| 2749 | * @param array $array <p>The array to get from, if it's set to "null" we use the current array from the |
||
| 2750 | * class.</p> |
||
| 2751 | * @param bool $useByReference |
||
| 2752 | * |
||
| 2753 | * @return mixed|static |
||
| 2754 | * |
||
| 2755 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 2756 | * @psalm-mutation-free |
||
| 2757 | */ |
||
| 2758 | 244 | public function get( |
|
| 2922 | |||
| 2923 | /** |
||
| 2924 | * alias: for "Arrayy->toArray()" |
||
| 2925 | * |
||
| 2926 | * @return array |
||
| 2927 | * |
||
| 2928 | * @see Arrayy::getArray() |
||
| 2929 | * |
||
| 2930 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 2931 | */ |
||
| 2932 | 15 | public function getAll(): array |
|
| 2936 | |||
| 2937 | /** |
||
| 2938 | * Get the current array from the "Arrayy"-object. |
||
| 2939 | * |
||
| 2940 | * alias for "toArray()" |
||
| 2941 | * |
||
| 2942 | * @param bool $convertAllArrayyElements <p> |
||
| 2943 | * Convert all Child-"Arrayy" objects also to arrays. |
||
| 2944 | * </p> |
||
| 2945 | * @param bool $preserveKeys <p> |
||
| 2946 | * e.g.: A generator maybe return the same key more then once, |
||
| 2947 | * so maybe you will ignore the keys. |
||
| 2948 | * </p> |
||
| 2949 | * |
||
| 2950 | * @return array |
||
| 2951 | * |
||
| 2952 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 2953 | * @psalm-mutation-free |
||
| 2954 | * |
||
| 2955 | * @see Arrayy::toArray() |
||
| 2956 | */ |
||
| 2957 | 502 | public function getArray( |
|
| 2966 | |||
| 2967 | /** |
||
| 2968 | * @param string $json |
||
| 2969 | * |
||
| 2970 | * @return $this |
||
| 2971 | */ |
||
| 2972 | 3 | public static function createFromJsonMapper(string $json) |
|
| 2988 | |||
| 2989 | /** |
||
| 2990 | * @return array<int|string,TypeCheckInterface>|mixed|TypeCheckArray<int|string,TypeCheckInterface>|TypeInterface |
||
| 2991 | * |
||
| 2992 | * @internal |
||
| 2993 | */ |
||
| 2994 | 6 | public function getPhpDocPropertiesFromClass() |
|
| 3002 | |||
| 3003 | /** |
||
| 3004 | * Get the current array from the "Arrayy"-object as list. |
||
| 3005 | * |
||
| 3006 | * alias for "toList()" |
||
| 3007 | * |
||
| 3008 | * @param bool $convertAllArrayyElements <p> |
||
| 3009 | * Convert all Child-"Arrayy" objects also to arrays. |
||
| 3010 | * </p> |
||
| 3011 | * |
||
| 3012 | * @return array |
||
| 3013 | * |
||
| 3014 | * @psalm-return array<int,mixed>|array<int,T> |
||
| 3015 | * @psalm-mutation-free |
||
| 3016 | * |
||
| 3017 | * @see Arrayy::toList() |
||
| 3018 | */ |
||
| 3019 | 1 | public function getList(bool $convertAllArrayyElements = false): array |
|
| 3023 | |||
| 3024 | /** |
||
| 3025 | * Returns the values from a single column of the input array, identified by |
||
| 3026 | * the $columnKey, can be used to extract data-columns from multi-arrays. |
||
| 3027 | * |
||
| 3028 | * EXAMPLE: <code> |
||
| 3029 | * a([['foo' => 'bar', 'id' => 1], ['foo => 'lall', 'id' => 2]])->getColumn('foo', 'id'); // Arrayy[1 => 'bar', 2 => 'lall'] |
||
| 3030 | * </code> |
||
| 3031 | * |
||
| 3032 | * INFO: Optionally, you may provide an $indexKey to index the values in the returned |
||
| 3033 | * array by the values from the $indexKey column in the input array. |
||
| 3034 | * |
||
| 3035 | * @param int|string|null $columnKey |
||
| 3036 | * @param int|string|null $indexKey |
||
| 3037 | * |
||
| 3038 | * @return static |
||
| 3039 | * <p>(Immutable)</p> |
||
| 3040 | * |
||
| 3041 | * @psalm-return static<TKey,T> |
||
| 3042 | * @psalm-mutation-free |
||
| 3043 | */ |
||
| 3044 | 1 | public function getColumn($columnKey = null, $indexKey = null): self |
|
| 3104 | |||
| 3105 | /** |
||
| 3106 | * Get the current array from the "Arrayy"-object as generator by reference. |
||
| 3107 | * |
||
| 3108 | * @return \Generator |
||
| 3109 | * |
||
| 3110 | * @psalm-return \Generator<mixed,T>|\Generator<TKey,T> |
||
| 3111 | */ |
||
| 3112 | 75 | public function &getGeneratorByReference(): \Generator |
|
| 3131 | |||
| 3132 | /** |
||
| 3133 | * Get the current array from the "Arrayy"-object as generator. |
||
| 3134 | * |
||
| 3135 | * @return \Generator |
||
| 3136 | * |
||
| 3137 | * @psalm-return \Generator<mixed,T>|\Generator<TKey,T> |
||
| 3138 | * @psalm-mutation-free |
||
| 3139 | */ |
||
| 3140 | 1001 | public function getGenerator(): \Generator |
|
| 3150 | |||
| 3151 | /** |
||
| 3152 | * alias: for "Arrayy->keys()" |
||
| 3153 | * |
||
| 3154 | * @return static |
||
| 3155 | * <p>(Immutable)</p> |
||
| 3156 | * |
||
| 3157 | * @see Arrayy::keys() |
||
| 3158 | * |
||
| 3159 | * @psalm-return static<array-key,TKey> |
||
| 3160 | * @psalm-mutation-free |
||
| 3161 | */ |
||
| 3162 | 2 | public function getKeys() |
|
| 3166 | |||
| 3167 | /** |
||
| 3168 | * Get the current array from the "Arrayy"-object as object. |
||
| 3169 | * |
||
| 3170 | * @return \stdClass |
||
| 3171 | */ |
||
| 3172 | 4 | public function getObject(): \stdClass |
|
| 3176 | |||
| 3177 | /** |
||
| 3178 | * alias: for "Arrayy->randomImmutable()" |
||
| 3179 | * |
||
| 3180 | * @return static |
||
| 3181 | * <p>(Immutable)</p> |
||
| 3182 | * |
||
| 3183 | * @see Arrayy::randomImmutable() |
||
| 3184 | * |
||
| 3185 | * @psalm-return static<int|array-key,T> |
||
| 3186 | */ |
||
| 3187 | 4 | public function getRandom(): self |
|
| 3191 | |||
| 3192 | /** |
||
| 3193 | * alias: for "Arrayy->randomKey()" |
||
| 3194 | * |
||
| 3195 | * @return mixed |
||
| 3196 | * <p>Get a key/index or null if there wasn't a key/index.</p> |
||
| 3197 | * |
||
| 3198 | * @see Arrayy::randomKey() |
||
| 3199 | */ |
||
| 3200 | 3 | public function getRandomKey() |
|
| 3204 | |||
| 3205 | /** |
||
| 3206 | * alias: for "Arrayy->randomKeys()" |
||
| 3207 | * |
||
| 3208 | * @param int $number |
||
| 3209 | * |
||
| 3210 | * @return static |
||
| 3211 | * <p>(Immutable)</p> |
||
| 3212 | * |
||
| 3213 | * @see Arrayy::randomKeys() |
||
| 3214 | * |
||
| 3215 | * @psalm-return static<TKey,T> |
||
| 3216 | */ |
||
| 3217 | 8 | public function getRandomKeys(int $number): self |
|
| 3221 | |||
| 3222 | /** |
||
| 3223 | * alias: for "Arrayy->randomValue()" |
||
| 3224 | * |
||
| 3225 | * @return mixed |
||
| 3226 | * <p>Get a random value or null if there wasn't a value.</p> |
||
| 3227 | * |
||
| 3228 | * @see Arrayy::randomValue() |
||
| 3229 | */ |
||
| 3230 | 3 | public function getRandomValue() |
|
| 3234 | |||
| 3235 | /** |
||
| 3236 | * alias: for "Arrayy->randomValues()" |
||
| 3237 | * |
||
| 3238 | * @param int $number |
||
| 3239 | * |
||
| 3240 | * @return static |
||
| 3241 | * <p>(Immutable)</p> |
||
| 3242 | * |
||
| 3243 | * @see Arrayy::randomValues() |
||
| 3244 | * |
||
| 3245 | * @psalm-return static<TKey,T> |
||
| 3246 | */ |
||
| 3247 | 6 | public function getRandomValues(int $number): self |
|
| 3251 | |||
| 3252 | /** |
||
| 3253 | * Gets all values. |
||
| 3254 | * |
||
| 3255 | * @return static |
||
| 3256 | * <p>The values of all elements in this array, in the order they |
||
| 3257 | * appear in the array.</p> |
||
| 3258 | * |
||
| 3259 | * @psalm-return static<TKey,T> |
||
| 3260 | */ |
||
| 3261 | 4 | public function getValues() |
|
| 3271 | |||
| 3272 | /** |
||
| 3273 | * Gets all values via Generator. |
||
| 3274 | * |
||
| 3275 | * @return \Generator |
||
| 3276 | * <p>The values of all elements in this array, in the order they |
||
| 3277 | * appear in the array as Generator.</p> |
||
| 3278 | * |
||
| 3279 | * @psalm-return \Generator<TKey,T> |
||
| 3280 | */ |
||
| 3281 | 4 | public function getValuesYield(): \Generator |
|
| 3285 | |||
| 3286 | /** |
||
| 3287 | * Group values from a array according to the results of a closure. |
||
| 3288 | * |
||
| 3289 | * @param callable|string $grouper <p>A callable function name.</p> |
||
| 3290 | * @param bool $saveKeys |
||
| 3291 | * |
||
| 3292 | * @return static |
||
| 3293 | * <p>(Immutable)</p> |
||
| 3294 | * |
||
| 3295 | * @psalm-return static<TKey,T> |
||
| 3296 | * @psalm-mutation-free |
||
| 3297 | */ |
||
| 3298 | 4 | public function group($grouper, bool $saveKeys = false): self |
|
| 3339 | |||
| 3340 | /** |
||
| 3341 | * Check if an array has a given key. |
||
| 3342 | * |
||
| 3343 | * @param mixed $key |
||
| 3344 | * |
||
| 3345 | * @return bool |
||
| 3346 | */ |
||
| 3347 | 30 | public function has($key): bool |
|
| 3373 | |||
| 3374 | /** |
||
| 3375 | * Check if an array has a given value. |
||
| 3376 | * |
||
| 3377 | * INFO: If you need to search recursive please use ```contains($value, true)```. |
||
| 3378 | * |
||
| 3379 | * @param mixed $value |
||
| 3380 | * |
||
| 3381 | * @return bool |
||
| 3382 | */ |
||
| 3383 | 1 | public function hasValue($value): bool |
|
| 3387 | |||
| 3388 | /** |
||
| 3389 | * Implodes the values of this array. |
||
| 3390 | * |
||
| 3391 | * EXAMPLE: <code> |
||
| 3392 | * a([0 => -9, 1, 2])->implode('|'); // '-9|1|2' |
||
| 3393 | * </code> |
||
| 3394 | * |
||
| 3395 | * @param string $glue |
||
| 3396 | * @param string $prefix |
||
| 3397 | * |
||
| 3398 | * @return string |
||
| 3399 | * @psalm-mutation-free |
||
| 3400 | */ |
||
| 3401 | 28 | public function implode(string $glue = '', string $prefix = ''): string |
|
| 3405 | |||
| 3406 | /** |
||
| 3407 | * Implodes the keys of this array. |
||
| 3408 | * |
||
| 3409 | * @param string $glue |
||
| 3410 | * |
||
| 3411 | * @return string |
||
| 3412 | * @psalm-mutation-free |
||
| 3413 | */ |
||
| 3414 | 8 | public function implodeKeys(string $glue = ''): string |
|
| 3418 | |||
| 3419 | /** |
||
| 3420 | * Given a list and an iterate-function that returns |
||
| 3421 | * a key for each element in the list (or a property name), |
||
| 3422 | * returns an object with an index of each item. |
||
| 3423 | * |
||
| 3424 | * @param mixed $key |
||
| 3425 | * |
||
| 3426 | * @return static |
||
| 3427 | * <p>(Immutable)</p> |
||
| 3428 | * |
||
| 3429 | * @psalm-return static<TKey,T> |
||
| 3430 | * @psalm-mutation-free |
||
| 3431 | */ |
||
| 3432 | 4 | View Code Duplication | public function indexBy($key): self |
| 3449 | |||
| 3450 | /** |
||
| 3451 | * alias: for "Arrayy->searchIndex()" |
||
| 3452 | * |
||
| 3453 | * @param mixed $value <p>The value to search for.</p> |
||
| 3454 | * |
||
| 3455 | * @return false|mixed |
||
| 3456 | * |
||
| 3457 | * @see Arrayy::searchIndex() |
||
| 3458 | */ |
||
| 3459 | 4 | public function indexOf($value) |
|
| 3463 | |||
| 3464 | /** |
||
| 3465 | * Get everything but the last..$to items. |
||
| 3466 | * |
||
| 3467 | * EXAMPLE: <code> |
||
| 3468 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->initial(2); // Arrayy[0 => 'foo'] |
||
| 3469 | * </code> |
||
| 3470 | * |
||
| 3471 | * @param int $to |
||
| 3472 | * |
||
| 3473 | * @return static |
||
| 3474 | * <p>(Immutable)</p> |
||
| 3475 | * |
||
| 3476 | * @psalm-return static<TKey,T> |
||
| 3477 | * @psalm-mutation-free |
||
| 3478 | */ |
||
| 3479 | 12 | public function initial(int $to = 1): self |
|
| 3483 | |||
| 3484 | /** |
||
| 3485 | * Return an array with all elements found in input array. |
||
| 3486 | * |
||
| 3487 | * EXAMPLE: <code> |
||
| 3488 | * a(['foo', 'bar'])->intersection(['bar', 'baz']); // Arrayy['bar'] |
||
| 3489 | * </code> |
||
| 3490 | * |
||
| 3491 | * @param array $search |
||
| 3492 | * @param bool $keepKeys |
||
| 3493 | * |
||
| 3494 | * @return static |
||
| 3495 | * <p>(Immutable)</p> |
||
| 3496 | * |
||
| 3497 | * @psalm-param array<mixed,mixed>|array<TKey,T> $search |
||
| 3498 | * @psalm-return static<TKey,T> |
||
| 3499 | * @psalm-mutation-free |
||
| 3500 | */ |
||
| 3501 | 4 | public function intersection(array $search, bool $keepKeys = false): self |
|
| 3527 | |||
| 3528 | /** |
||
| 3529 | * Return an array with all elements found in input array. |
||
| 3530 | * |
||
| 3531 | * @param array ...$array |
||
| 3532 | * |
||
| 3533 | * @return static |
||
| 3534 | * <p>(Immutable)</p> |
||
| 3535 | * |
||
| 3536 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$array |
||
| 3537 | * @psalm-return static<TKey,T> |
||
| 3538 | * @psalm-mutation-free |
||
| 3539 | */ |
||
| 3540 | 1 | public function intersectionMulti(...$array): self |
|
| 3548 | |||
| 3549 | /** |
||
| 3550 | * Return a boolean flag which indicates whether the two input arrays have any common elements. |
||
| 3551 | * |
||
| 3552 | * EXAMPLE: <code> |
||
| 3553 | * a(['foo', 'bar'])->intersects(['föö', 'bär']); // false |
||
| 3554 | * </code> |
||
| 3555 | * |
||
| 3556 | * @param array $search |
||
| 3557 | * |
||
| 3558 | * @return bool |
||
| 3559 | * |
||
| 3560 | * @psalm-param array<mixed,mixed>|array<TKey,T> $search |
||
| 3561 | */ |
||
| 3562 | 1 | public function intersects(array $search): bool |
|
| 3566 | |||
| 3567 | /** |
||
| 3568 | * Invoke a function on all of an array's values. |
||
| 3569 | * |
||
| 3570 | * @param callable $callable |
||
| 3571 | * @param mixed $arguments |
||
| 3572 | * |
||
| 3573 | * @return static |
||
| 3574 | * <p>(Immutable)</p> |
||
| 3575 | * |
||
| 3576 | * @psalm-param callable(T=,mixed):mixed $callable |
||
| 3577 | * @psalm-return static<TKey,T> |
||
| 3578 | * @psalm-mutation-free |
||
| 3579 | */ |
||
| 3580 | 1 | public function invoke($callable, $arguments = []): self |
|
| 3604 | |||
| 3605 | /** |
||
| 3606 | * Check whether array is associative or not. |
||
| 3607 | * |
||
| 3608 | * EXAMPLE: <code> |
||
| 3609 | * a(['foo' => 'bar', 2, 3])->isAssoc(); // true |
||
| 3610 | * </code> |
||
| 3611 | * |
||
| 3612 | * @param bool $recursive |
||
| 3613 | * |
||
| 3614 | * @return bool |
||
| 3615 | * <p>Returns true if associative, false otherwise.</p> |
||
| 3616 | */ |
||
| 3617 | 15 | View Code Duplication | public function isAssoc(bool $recursive = false): bool |
| 3632 | |||
| 3633 | /** |
||
| 3634 | * Check if a given key or keys are empty. |
||
| 3635 | * |
||
| 3636 | * @param int|int[]|string|string[]|null $keys |
||
| 3637 | * |
||
| 3638 | * @return bool |
||
| 3639 | * <p>Returns true if empty, false otherwise.</p> |
||
| 3640 | * @psalm-mutation-free |
||
| 3641 | */ |
||
| 3642 | 45 | public function isEmpty($keys = null): bool |
|
| 3660 | |||
| 3661 | /** |
||
| 3662 | * Check if the current array is equal to the given "$array" or not. |
||
| 3663 | * |
||
| 3664 | * EXAMPLE: <code> |
||
| 3665 | * a(['💩'])->isEqual(['💩']); // true |
||
| 3666 | * </code> |
||
| 3667 | * |
||
| 3668 | * @param array $array |
||
| 3669 | * |
||
| 3670 | * @return bool |
||
| 3671 | * |
||
| 3672 | * @psalm-param array<mixed,mixed> $array |
||
| 3673 | */ |
||
| 3674 | 1 | public function isEqual(array $array): bool |
|
| 3678 | |||
| 3679 | /** |
||
| 3680 | * Check if the current array is a multi-array. |
||
| 3681 | * |
||
| 3682 | * EXAMPLE: <code> |
||
| 3683 | * a(['foo' => [1, 2 , 3]])->isMultiArray(); // true |
||
| 3684 | * </code> |
||
| 3685 | * |
||
| 3686 | * @return bool |
||
| 3687 | */ |
||
| 3688 | 22 | public function isMultiArray(): bool |
|
| 3698 | |||
| 3699 | /** |
||
| 3700 | * Check whether array is numeric or not. |
||
| 3701 | * |
||
| 3702 | * @return bool |
||
| 3703 | * <p>Returns true if numeric, false otherwise.</p> |
||
| 3704 | */ |
||
| 3705 | 5 | View Code Duplication | public function isNumeric(): bool |
| 3720 | |||
| 3721 | /** |
||
| 3722 | * Check if the current array is sequential [0, 1, 2, 3, 4, 5 ...] or not. |
||
| 3723 | * |
||
| 3724 | * EXAMPLE: <code> |
||
| 3725 | * a([0 => 'foo', 1 => 'lall', 2 => 'foobar'])->isSequential(); // true |
||
| 3726 | * </code> |
||
| 3727 | * |
||
| 3728 | * INFO: If the array is empty we count it as non-sequential. |
||
| 3729 | * |
||
| 3730 | * @param bool $recursive |
||
| 3731 | * |
||
| 3732 | * @return bool |
||
| 3733 | * @psalm-mutation-free |
||
| 3734 | */ |
||
| 3735 | 10 | public function isSequential(bool $recursive = false): bool |
|
| 3763 | |||
| 3764 | /** |
||
| 3765 | * @return array |
||
| 3766 | * |
||
| 3767 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 3768 | */ |
||
| 3769 | 2 | public function jsonSerialize(): array |
|
| 3773 | |||
| 3774 | /** |
||
| 3775 | * Gets the key/index of the element at the current internal iterator position. |
||
| 3776 | * |
||
| 3777 | * @return int|string|null |
||
| 3778 | */ |
||
| 3779 | public function key() |
||
| 3783 | |||
| 3784 | /** |
||
| 3785 | * Checks if the given key exists in the provided array. |
||
| 3786 | * |
||
| 3787 | * INFO: This method only use "array_key_exists()" if you want to use "dot"-notation, |
||
| 3788 | * then you need to use "Arrayy->offsetExists()". |
||
| 3789 | * |
||
| 3790 | * @param int|string $key the key to look for |
||
| 3791 | * |
||
| 3792 | * @return bool |
||
| 3793 | * @psalm-mutation-free |
||
| 3794 | */ |
||
| 3795 | 165 | public function keyExists($key): bool |
|
| 3799 | |||
| 3800 | /** |
||
| 3801 | * Get all keys from the current array. |
||
| 3802 | * |
||
| 3803 | * EXAMPLE: <code> |
||
| 3804 | * a([1 => 'foo', 2 => 'foo2', 3 => 'bar'])->keys(); // Arrayy[1, 2, 3] |
||
| 3805 | * </code> |
||
| 3806 | * |
||
| 3807 | * @param bool $recursive [optional] <p> |
||
| 3808 | * Get all keys, also from all sub-arrays from an multi-dimensional array. |
||
| 3809 | * </p> |
||
| 3810 | * @param mixed|null $search_values [optional] <p> |
||
| 3811 | * If specified, then only keys containing these values are returned. |
||
| 3812 | * </p> |
||
| 3813 | * @param bool $strict [optional] <p> |
||
| 3814 | * Determines if strict comparison (===) should be used during the search. |
||
| 3815 | * </p> |
||
| 3816 | * |
||
| 3817 | * @return static |
||
| 3818 | * <p>(Immutable) An array of all the keys in input.</p> |
||
| 3819 | * |
||
| 3820 | * @psalm-return static<array-key,TKey> |
||
| 3821 | * @psalm-mutation-free |
||
| 3822 | */ |
||
| 3823 | 29 | public function keys( |
|
| 3894 | |||
| 3895 | /** |
||
| 3896 | * Sort an array by key in reverse order. |
||
| 3897 | * |
||
| 3898 | * @param int $sort_flags [optional] <p> |
||
| 3899 | * You may modify the behavior of the sort using the optional |
||
| 3900 | * parameter sort_flags, for details |
||
| 3901 | * see sort. |
||
| 3902 | * </p> |
||
| 3903 | * |
||
| 3904 | * @return $this |
||
| 3905 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 3906 | * |
||
| 3907 | * @psalm-return static<TKey,T> |
||
| 3908 | */ |
||
| 3909 | 4 | public function krsort(int $sort_flags = 0): self |
|
| 3917 | |||
| 3918 | /** |
||
| 3919 | * Sort an array by key in reverse order. |
||
| 3920 | * |
||
| 3921 | * @param int $sort_flags [optional] <p> |
||
| 3922 | * You may modify the behavior of the sort using the optional |
||
| 3923 | * parameter sort_flags, for details |
||
| 3924 | * see sort. |
||
| 3925 | * </p> |
||
| 3926 | * |
||
| 3927 | * @return $this |
||
| 3928 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 3929 | * |
||
| 3930 | * @psalm-return static<TKey,T> |
||
| 3931 | * @psalm-mutation-free |
||
| 3932 | */ |
||
| 3933 | 4 | public function krsortImmutable(int $sort_flags = 0): self |
|
| 3944 | |||
| 3945 | /** |
||
| 3946 | * Get the last value from the current array. |
||
| 3947 | * |
||
| 3948 | * EXAMPLE: <code> |
||
| 3949 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->last(); // 'lall' |
||
| 3950 | * </code> |
||
| 3951 | * |
||
| 3952 | * @return mixed|null |
||
| 3953 | * <p>Return null if there wasn't a element.</p> |
||
| 3954 | * @psalm-mutation-free |
||
| 3955 | */ |
||
| 3956 | 17 | public function last() |
|
| 3965 | |||
| 3966 | /** |
||
| 3967 | * Get the last key from the current array. |
||
| 3968 | * |
||
| 3969 | * @return mixed|null |
||
| 3970 | * <p>Return null if there wasn't a element.</p> |
||
| 3971 | * @psalm-mutation-free |
||
| 3972 | */ |
||
| 3973 | 21 | public function lastKey() |
|
| 3979 | |||
| 3980 | /** |
||
| 3981 | * Get the last value(s) from the current array. |
||
| 3982 | * |
||
| 3983 | * EXAMPLE: <code> |
||
| 3984 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->lasts(2); // Arrayy[0 => 'bar', 1 => 'lall'] |
||
| 3985 | * </code> |
||
| 3986 | * |
||
| 3987 | * @param int|null $number |
||
| 3988 | * |
||
| 3989 | * @return static |
||
| 3990 | * <p>(Immutable)</p> |
||
| 3991 | * |
||
| 3992 | * @psalm-return static<TKey,T> |
||
| 3993 | * @psalm-mutation-free |
||
| 3994 | */ |
||
| 3995 | 13 | public function lastsImmutable(int $number = null): self |
|
| 4025 | |||
| 4026 | /** |
||
| 4027 | * Get the last value(s) from the current array. |
||
| 4028 | * |
||
| 4029 | * EXAMPLE: <code> |
||
| 4030 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->lasts(2); // Arrayy[0 => 'bar', 1 => 'lall'] |
||
| 4031 | * </code> |
||
| 4032 | * |
||
| 4033 | * @param int|null $number |
||
| 4034 | * |
||
| 4035 | * @return $this |
||
| 4036 | * <p>(Mutable)</p> |
||
| 4037 | * |
||
| 4038 | * @psalm-return static<TKey,T> |
||
| 4039 | */ |
||
| 4040 | 13 | public function lastsMutable(int $number = null): self |
|
| 4051 | |||
| 4052 | /** |
||
| 4053 | * Count the values from the current array. |
||
| 4054 | * |
||
| 4055 | * alias: for "Arrayy->count()" |
||
| 4056 | * |
||
| 4057 | * @param int $mode |
||
| 4058 | * |
||
| 4059 | * @return int |
||
| 4060 | * |
||
| 4061 | * @see Arrayy::count() |
||
| 4062 | */ |
||
| 4063 | 20 | public function length(int $mode = \COUNT_NORMAL): int |
|
| 4067 | |||
| 4068 | /** |
||
| 4069 | * Apply the given function to the every element of the array, |
||
| 4070 | * collecting the results. |
||
| 4071 | * |
||
| 4072 | * EXAMPLE: <code> |
||
| 4073 | * a(['foo', 'Foo'])->map('mb_strtoupper'); // Arrayy['FOO', 'FOO'] |
||
| 4074 | * </code> |
||
| 4075 | * |
||
| 4076 | * @param callable $callable |
||
| 4077 | * @param bool $useKeyAsSecondParameter |
||
| 4078 | * @param mixed ...$arguments |
||
| 4079 | * |
||
| 4080 | * @return static |
||
| 4081 | * <p>(Immutable) Arrayy object with modified elements.</p> |
||
| 4082 | * |
||
| 4083 | * @psalm-param callable(T,TKey=,mixed=):mixed $callable |
||
| 4084 | * @psalm-return static<TKey,T> |
||
| 4085 | * @psalm-mutation-free |
||
| 4086 | */ |
||
| 4087 | 6 | public function map( |
|
| 4120 | |||
| 4121 | /** |
||
| 4122 | * Check if all items in current array match a truth test. |
||
| 4123 | * |
||
| 4124 | * EXAMPLE: <code> |
||
| 4125 | * $closure = function ($value, $key) { |
||
| 4126 | * return ($value % 2 === 0); |
||
| 4127 | * }; |
||
| 4128 | * a([2, 4, 8])->matches($closure); // true |
||
| 4129 | * </code> |
||
| 4130 | * |
||
| 4131 | * @param \Closure $closure |
||
| 4132 | * |
||
| 4133 | * @return bool |
||
| 4134 | */ |
||
| 4135 | 15 | View Code Duplication | public function matches(\Closure $closure): bool |
| 4151 | |||
| 4152 | /** |
||
| 4153 | * Check if any item in the current array matches a truth test. |
||
| 4154 | * |
||
| 4155 | * EXAMPLE: <code> |
||
| 4156 | * $closure = function ($value, $key) { |
||
| 4157 | * return ($value % 2 === 0); |
||
| 4158 | * }; |
||
| 4159 | * a([1, 4, 7])->matches($closure); // true |
||
| 4160 | * </code> |
||
| 4161 | * |
||
| 4162 | * @param \Closure $closure |
||
| 4163 | * |
||
| 4164 | * @return bool |
||
| 4165 | */ |
||
| 4166 | 14 | View Code Duplication | public function matchesAny(\Closure $closure): bool |
| 4182 | |||
| 4183 | /** |
||
| 4184 | * Get the max value from an array. |
||
| 4185 | * |
||
| 4186 | * EXAMPLE: <code> |
||
| 4187 | * a([-9, -8, -7, 1.32])->max(); // 1.32 |
||
| 4188 | * </code> |
||
| 4189 | * |
||
| 4190 | * @return false|mixed |
||
| 4191 | * <p>Will return false if there are no values.</p> |
||
| 4192 | */ |
||
| 4193 | 10 | View Code Duplication | public function max() |
| 4213 | |||
| 4214 | /** |
||
| 4215 | * Merge the new $array into the current array. |
||
| 4216 | * |
||
| 4217 | * - keep key,value from the current array, also if the index is in the new $array |
||
| 4218 | * |
||
| 4219 | * EXAMPLE: <code> |
||
| 4220 | * $array1 = [1 => 'one', 'foo' => 'bar1']; |
||
| 4221 | * $array2 = ['foo' => 'bar2', 3 => 'three']; |
||
| 4222 | * a($array1)->mergeAppendKeepIndex($array2); // Arrayy[1 => 'one', 'foo' => 'bar2', 3 => 'three'] |
||
| 4223 | * // --- |
||
| 4224 | * $array1 = [0 => 'one', 1 => 'foo']; |
||
| 4225 | * $array2 = [0 => 'foo', 1 => 'bar2']; |
||
| 4226 | * a($array1)->mergeAppendKeepIndex($array2); // Arrayy[0 => 'foo', 1 => 'bar2'] |
||
| 4227 | * </code> |
||
| 4228 | * |
||
| 4229 | * @param array $array |
||
| 4230 | * @param bool $recursive |
||
| 4231 | * |
||
| 4232 | * @return static |
||
| 4233 | * <p>(Immutable)</p> |
||
| 4234 | * |
||
| 4235 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 4236 | * @psalm-return static<int|TKey,T> |
||
| 4237 | * @psalm-mutation-free |
||
| 4238 | */ |
||
| 4239 | 33 | View Code Duplication | public function mergeAppendKeepIndex(array $array = [], bool $recursive = false): self |
| 4254 | |||
| 4255 | /** |
||
| 4256 | * Merge the new $array into the current array. |
||
| 4257 | * |
||
| 4258 | * - replace duplicate assoc-keys from the current array with the key,values from the new $array |
||
| 4259 | * - create new indexes |
||
| 4260 | * |
||
| 4261 | * EXAMPLE: <code> |
||
| 4262 | * $array1 = [1 => 'one', 'foo' => 'bar1']; |
||
| 4263 | * $array2 = ['foo' => 'bar2', 3 => 'three']; |
||
| 4264 | * a($array1)->mergeAppendNewIndex($array2); // Arrayy[0 => 'one', 'foo' => 'bar2', 1 => 'three'] |
||
| 4265 | * // --- |
||
| 4266 | * $array1 = [0 => 'one', 1 => 'foo']; |
||
| 4267 | * $array2 = [0 => 'foo', 1 => 'bar2']; |
||
| 4268 | * a($array1)->mergeAppendNewIndex($array2); // Arrayy[0 => 'one', 1 => 'foo', 2 => 'foo', 3 => 'bar2'] |
||
| 4269 | * </code> |
||
| 4270 | * |
||
| 4271 | * @param array $array |
||
| 4272 | * @param bool $recursive |
||
| 4273 | * |
||
| 4274 | * @return static |
||
| 4275 | * <p>(Immutable)</p> |
||
| 4276 | * |
||
| 4277 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 4278 | * @psalm-return static<TKey,T> |
||
| 4279 | * @psalm-mutation-free |
||
| 4280 | */ |
||
| 4281 | 20 | View Code Duplication | public function mergeAppendNewIndex(array $array = [], bool $recursive = false): self |
| 4296 | |||
| 4297 | /** |
||
| 4298 | * Merge the the current array into the $array. |
||
| 4299 | * |
||
| 4300 | * - use key,value from the new $array, also if the index is in the current array |
||
| 4301 | * |
||
| 4302 | * EXAMPLE: <code> |
||
| 4303 | * $array1 = [1 => 'one', 'foo' => 'bar1']; |
||
| 4304 | * $array2 = ['foo' => 'bar2', 3 => 'three']; |
||
| 4305 | * a($array1)->mergePrependKeepIndex($array2); // Arrayy['foo' => 'bar1', 3 => 'three', 1 => 'one'] |
||
| 4306 | * // --- |
||
| 4307 | * $array1 = [0 => 'one', 1 => 'foo']; |
||
| 4308 | * $array2 = [0 => 'foo', 1 => 'bar2']; |
||
| 4309 | * a($array1)->mergePrependKeepIndex($array2); // Arrayy[0 => 'one', 1 => 'foo'] |
||
| 4310 | * </code> |
||
| 4311 | * |
||
| 4312 | * @param array $array |
||
| 4313 | * @param bool $recursive |
||
| 4314 | * |
||
| 4315 | * @return static |
||
| 4316 | * <p>(Immutable)</p> |
||
| 4317 | * |
||
| 4318 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 4319 | * @psalm-return static<TKey,T> |
||
| 4320 | * @psalm-mutation-free |
||
| 4321 | */ |
||
| 4322 | 17 | View Code Duplication | public function mergePrependKeepIndex(array $array = [], bool $recursive = false): self |
| 4337 | |||
| 4338 | /** |
||
| 4339 | * Merge the current array into the new $array. |
||
| 4340 | * |
||
| 4341 | * - replace duplicate assoc-keys from new $array with the key,values from the current array |
||
| 4342 | * - create new indexes |
||
| 4343 | * |
||
| 4344 | * EXAMPLE: <code> |
||
| 4345 | * $array1 = [1 => 'one', 'foo' => 'bar1']; |
||
| 4346 | * $array2 = ['foo' => 'bar2', 3 => 'three']; |
||
| 4347 | * a($array1)->mergePrependNewIndex($array2); // Arrayy['foo' => 'bar1', 0 => 'three', 1 => 'one'] |
||
| 4348 | * // --- |
||
| 4349 | * $array1 = [0 => 'one', 1 => 'foo']; |
||
| 4350 | * $array2 = [0 => 'foo', 1 => 'bar2']; |
||
| 4351 | * a($array1)->mergePrependNewIndex($array2); // Arrayy[0 => 'foo', 1 => 'bar2', 2 => 'one', 3 => 'foo'] |
||
| 4352 | * </code> |
||
| 4353 | * |
||
| 4354 | * @param array $array |
||
| 4355 | * @param bool $recursive |
||
| 4356 | * |
||
| 4357 | * @return static |
||
| 4358 | * <p>(Immutable)</p> |
||
| 4359 | * |
||
| 4360 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 4361 | * @psalm-return static<TKey,T> |
||
| 4362 | * @psalm-mutation-free |
||
| 4363 | */ |
||
| 4364 | 21 | View Code Duplication | public function mergePrependNewIndex(array $array = [], bool $recursive = false): self |
| 4379 | |||
| 4380 | /** |
||
| 4381 | * @return ArrayyMeta|mixed|static |
||
| 4382 | */ |
||
| 4383 | 18 | public static function meta() |
|
| 4387 | |||
| 4388 | /** |
||
| 4389 | * Get the min value from an array. |
||
| 4390 | * |
||
| 4391 | * EXAMPLE: <code> |
||
| 4392 | * a([-9, -8, -7, 1.32])->min(); // -9 |
||
| 4393 | * </code> |
||
| 4394 | * |
||
| 4395 | * @return false|mixed |
||
| 4396 | * <p>Will return false if there are no values.</p> |
||
| 4397 | */ |
||
| 4398 | 10 | View Code Duplication | public function min() |
| 4418 | |||
| 4419 | /** |
||
| 4420 | * Get the most used value from the array. |
||
| 4421 | * |
||
| 4422 | * @return mixed|null |
||
| 4423 | * <p>(Immutable) Return null if there wasn't a element.</p> |
||
| 4424 | * @psalm-mutation-free |
||
| 4425 | */ |
||
| 4426 | 3 | public function mostUsedValue() |
|
| 4430 | |||
| 4431 | /** |
||
| 4432 | * Get the most used value from the array. |
||
| 4433 | * |
||
| 4434 | * @param int|null $number <p>How many values you will take?</p> |
||
| 4435 | * |
||
| 4436 | * @return static |
||
| 4437 | * <p>(Immutable)</p> |
||
| 4438 | * |
||
| 4439 | * @psalm-return static<TKey,T> |
||
| 4440 | * @psalm-mutation-free |
||
| 4441 | */ |
||
| 4442 | 3 | public function mostUsedValues(int $number = null): self |
|
| 4446 | |||
| 4447 | /** |
||
| 4448 | * Move an array element to a new index. |
||
| 4449 | * |
||
| 4450 | * EXAMPLE: <code> |
||
| 4451 | * $arr2 = new A(['A' => 'a', 'B' => 'b', 'C' => 'c', 'D' => 'd', 'E' => 'e']); |
||
| 4452 | * $newArr2 = $arr2->moveElement('D', 1); // Arrayy['A' => 'a', 'D' => 'd', 'B' => 'b', 'C' => 'c', 'E' => 'e'] |
||
| 4453 | * </code> |
||
| 4454 | * |
||
| 4455 | * @param int|string $from |
||
| 4456 | * @param int $to |
||
| 4457 | * |
||
| 4458 | * @return static |
||
| 4459 | * <p>(Immutable)</p> |
||
| 4460 | * |
||
| 4461 | * @psalm-return static<TKey,T> |
||
| 4462 | * @psalm-mutation-free |
||
| 4463 | */ |
||
| 4464 | 1 | public function moveElement($from, $to): self |
|
| 4497 | |||
| 4498 | /** |
||
| 4499 | * Move an array element to the first place. |
||
| 4500 | * |
||
| 4501 | * INFO: Instead of "Arrayy->moveElement()" this method will NOT |
||
| 4502 | * loss the keys of an indexed array. |
||
| 4503 | * |
||
| 4504 | * @param int|string $key |
||
| 4505 | * |
||
| 4506 | * @return static |
||
| 4507 | * <p>(Immutable)</p> |
||
| 4508 | * |
||
| 4509 | * @psalm-return static<TKey,T> |
||
| 4510 | * @psalm-mutation-free |
||
| 4511 | */ |
||
| 4512 | 1 | View Code Duplication | public function moveElementToFirstPlace($key): self |
| 4528 | |||
| 4529 | /** |
||
| 4530 | * Move an array element to the last place. |
||
| 4531 | * |
||
| 4532 | * INFO: Instead of "Arrayy->moveElement()" this method will NOT |
||
| 4533 | * loss the keys of an indexed array. |
||
| 4534 | * |
||
| 4535 | * @param int|string $key |
||
| 4536 | * |
||
| 4537 | * @return static |
||
| 4538 | * <p>(Immutable)</p> |
||
| 4539 | * |
||
| 4540 | * @psalm-return static<TKey,T> |
||
| 4541 | * @psalm-mutation-free |
||
| 4542 | */ |
||
| 4543 | 1 | View Code Duplication | public function moveElementToLastPlace($key): self |
| 4559 | |||
| 4560 | /** |
||
| 4561 | * Moves the internal iterator position to the next element and returns this element. |
||
| 4562 | * |
||
| 4563 | * @return false|mixed |
||
| 4564 | * <p>(Mutable) Will return false if there are no values.</p> |
||
| 4565 | */ |
||
| 4566 | public function next() |
||
| 4570 | |||
| 4571 | /** |
||
| 4572 | * Get the next nth keys and values from the array. |
||
| 4573 | * |
||
| 4574 | * @param int $step |
||
| 4575 | * @param int $offset |
||
| 4576 | * |
||
| 4577 | * @return static |
||
| 4578 | * <p>(Immutable)</p> |
||
| 4579 | * |
||
| 4580 | * @psalm-return static<TKey,T> |
||
| 4581 | * @psalm-mutation-free |
||
| 4582 | */ |
||
| 4583 | 1 | public function nth(int $step, int $offset = 0): self |
|
| 4602 | |||
| 4603 | /** |
||
| 4604 | * Get a subset of the items from the given array. |
||
| 4605 | * |
||
| 4606 | * @param int[]|string[] $keys |
||
| 4607 | * |
||
| 4608 | * @return static |
||
| 4609 | * <p>(Immutable)</p> |
||
| 4610 | * |
||
| 4611 | * @psalm-param array-key[] $keys |
||
| 4612 | * @psalm-return static<TKey,T> |
||
| 4613 | * @psalm-mutation-free |
||
| 4614 | */ |
||
| 4615 | 1 | View Code Duplication | public function only(array $keys): self |
| 4633 | |||
| 4634 | /** |
||
| 4635 | * Pad array to the specified size with a given value. |
||
| 4636 | * |
||
| 4637 | * @param int $size <p>Size of the result array.</p> |
||
| 4638 | * @param mixed $value <p>Empty value by default.</p> |
||
| 4639 | * |
||
| 4640 | * @return static |
||
| 4641 | * <p>(Immutable) Arrayy object padded to $size with $value.</p> |
||
| 4642 | * |
||
| 4643 | * @psalm-return static<TKey,T> |
||
| 4644 | * @psalm-mutation-free |
||
| 4645 | */ |
||
| 4646 | 5 | public function pad(int $size, $value): self |
|
| 4654 | |||
| 4655 | /** |
||
| 4656 | * Partitions this array in two array according to a predicate. |
||
| 4657 | * Keys are preserved in the resulting array. |
||
| 4658 | * |
||
| 4659 | * @param \Closure $closure |
||
| 4660 | * <p>The predicate on which to partition.</p> |
||
| 4661 | * |
||
| 4662 | * @return array<int, static> |
||
| 4663 | * <p>An array with two elements. The first element contains the array |
||
| 4664 | * of elements where the predicate returned TRUE, the second element |
||
| 4665 | * contains the array of elements where the predicate returned FALSE.</p> |
||
| 4666 | * |
||
| 4667 | * @psalm-return array<int, static<TKey,T>> |
||
| 4668 | */ |
||
| 4669 | 1 | public function partition(\Closure $closure): array |
|
| 4685 | |||
| 4686 | /** |
||
| 4687 | * Pop a specified value off the end of the current array. |
||
| 4688 | * |
||
| 4689 | * @return mixed|null |
||
| 4690 | * <p>(Mutable) The popped element from the current array or null if the array is e.g. empty.</p> |
||
| 4691 | */ |
||
| 4692 | 5 | public function pop() |
|
| 4698 | |||
| 4699 | /** |
||
| 4700 | * Prepend a (key) + value to the current array. |
||
| 4701 | * |
||
| 4702 | * EXAMPLE: <code> |
||
| 4703 | * a(['fòô' => 'bàř'])->prepend('foo'); // Arrayy[0 => 'foo', 'fòô' => 'bàř'] |
||
| 4704 | * </code> |
||
| 4705 | * |
||
| 4706 | * @param mixed $value |
||
| 4707 | * @param mixed $key |
||
| 4708 | * |
||
| 4709 | * @return $this |
||
| 4710 | * <p>(Mutable) Return this Arrayy object, with the prepended value.</p> |
||
| 4711 | * |
||
| 4712 | * @psalm-return static<TKey,T> |
||
| 4713 | */ |
||
| 4714 | 11 | public function prepend($value, $key = null) |
|
| 4730 | |||
| 4731 | /** |
||
| 4732 | * Prepend a (key) + value to the current array. |
||
| 4733 | * |
||
| 4734 | * EXAMPLE: <code> |
||
| 4735 | * a(['fòô' => 'bàř'])->prependImmutable('foo')->getArray(); // [0 => 'foo', 'fòô' => 'bàř'] |
||
| 4736 | * </code> |
||
| 4737 | * |
||
| 4738 | * @param mixed $value |
||
| 4739 | * @param mixed $key |
||
| 4740 | * |
||
| 4741 | * @return $this |
||
| 4742 | * <p>(Immutable) Return this Arrayy object, with the prepended value.</p> |
||
| 4743 | * |
||
| 4744 | * @psalm-return static<TKey,T> |
||
| 4745 | * @psalm-mutation-free |
||
| 4746 | */ |
||
| 4747 | 1 | View Code Duplication | public function prependImmutable($value, $key = null) |
| 4772 | |||
| 4773 | /** |
||
| 4774 | * Add a suffix to each key. |
||
| 4775 | * |
||
| 4776 | * @param mixed $suffix |
||
| 4777 | * |
||
| 4778 | * @return static |
||
| 4779 | * <p>(Immutable) Return an Arrayy object, with the prepended keys.</p> |
||
| 4780 | * |
||
| 4781 | * @psalm-return static<TKey,T> |
||
| 4782 | * @psalm-mutation-free |
||
| 4783 | */ |
||
| 4784 | 10 | View Code Duplication | public function prependToEachKey($suffix): self |
| 4810 | |||
| 4811 | /** |
||
| 4812 | * Add a suffix to each value. |
||
| 4813 | * |
||
| 4814 | * @param mixed $suffix |
||
| 4815 | * |
||
| 4816 | * @return static |
||
| 4817 | * <p>(Immutable) Return an Arrayy object, with the prepended values.</p> |
||
| 4818 | * |
||
| 4819 | * @psalm-return static<TKey,T> |
||
| 4820 | * @psalm-mutation-free |
||
| 4821 | */ |
||
| 4822 | 10 | View Code Duplication | public function prependToEachValue($suffix): self |
| 4850 | |||
| 4851 | /** |
||
| 4852 | * Return the value of a given key and |
||
| 4853 | * delete the key. |
||
| 4854 | * |
||
| 4855 | * @param int|int[]|string|string[]|null $keyOrKeys |
||
| 4856 | * @param mixed $fallback |
||
| 4857 | * |
||
| 4858 | * @return mixed |
||
| 4859 | */ |
||
| 4860 | 5 | public function pull($keyOrKeys = null, $fallback = null) |
|
| 4882 | |||
| 4883 | /** |
||
| 4884 | * Push one or more values onto the end of array at once. |
||
| 4885 | * |
||
| 4886 | * @param mixed ...$args |
||
| 4887 | * |
||
| 4888 | * @return $this |
||
| 4889 | * <p>(Mutable) Return this Arrayy object, with pushed elements to the end of array.</p> |
||
| 4890 | * |
||
| 4891 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
| 4892 | * |
||
| 4893 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$args |
||
| 4894 | * @psalm-return static<TKey,T> |
||
| 4895 | */ |
||
| 4896 | 7 | public function push(...$args) |
|
| 4914 | |||
| 4915 | /** |
||
| 4916 | * Get a random value from the current array. |
||
| 4917 | * |
||
| 4918 | * EXAMPLE: <code> |
||
| 4919 | * a([1, 2, 3, 4])->randomImmutable(2); // e.g.: Arrayy[1, 4] |
||
| 4920 | * </code> |
||
| 4921 | * |
||
| 4922 | * @param int|null $number <p>How many values you will take?</p> |
||
| 4923 | * |
||
| 4924 | * @return static |
||
| 4925 | * <p>(Immutable)</p> |
||
| 4926 | * |
||
| 4927 | * @psalm-return static<int|array-key,T> |
||
| 4928 | */ |
||
| 4929 | 19 | public function randomImmutable(int $number = null): self |
|
| 4962 | |||
| 4963 | /** |
||
| 4964 | * Pick a random key/index from the keys of this array. |
||
| 4965 | * |
||
| 4966 | * EXAMPLE: <code> |
||
| 4967 | * $arrayy = A::create([1 => 'one', 2 => 'two']); |
||
| 4968 | * $arrayy->randomKey(); // e.g. 2 |
||
| 4969 | * </code> |
||
| 4970 | * |
||
| 4971 | * @throws \RangeException If array is empty |
||
| 4972 | * |
||
| 4973 | * @return mixed |
||
| 4974 | * <p>Get a key/index or null if there wasn't a key/index.</p> |
||
| 4975 | */ |
||
| 4976 | 4 | public function randomKey() |
|
| 4986 | |||
| 4987 | /** |
||
| 4988 | * Pick a given number of random keys/indexes out of this array. |
||
| 4989 | * |
||
| 4990 | * EXAMPLE: <code> |
||
| 4991 | * a([1 => 'one', 2 => 'two'])->randomKeys(); // e.g. Arrayy[1, 2] |
||
| 4992 | * </code> |
||
| 4993 | * |
||
| 4994 | * @param int $number <p>The number of keys/indexes (should be <= \count($this->array))</p> |
||
| 4995 | * |
||
| 4996 | * @throws \RangeException If array is empty |
||
| 4997 | * |
||
| 4998 | * @return static |
||
| 4999 | * <p>(Immutable)</p> |
||
| 5000 | * |
||
| 5001 | * @psalm-return static<TKey,T> |
||
| 5002 | */ |
||
| 5003 | 13 | public function randomKeys(int $number): self |
|
| 5031 | |||
| 5032 | /** |
||
| 5033 | * Get a random value from the current array. |
||
| 5034 | * |
||
| 5035 | * EXAMPLE: <code> |
||
| 5036 | * a([1, 2, 3, 4])->randomMutable(2); // e.g.: Arrayy[1, 4] |
||
| 5037 | * </code> |
||
| 5038 | * |
||
| 5039 | * @param int|null $number <p>How many values you will take?</p> |
||
| 5040 | * |
||
| 5041 | * @return $this |
||
| 5042 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 5043 | * |
||
| 5044 | * @psalm-return static<TKey,T> |
||
| 5045 | */ |
||
| 5046 | 17 | public function randomMutable(int $number = null): self |
|
| 5071 | |||
| 5072 | /** |
||
| 5073 | * Pick a random value from the values of this array. |
||
| 5074 | * |
||
| 5075 | * EXAMPLE: <code> |
||
| 5076 | * a([1 => 'one', 2 => 'two'])->randomValue(); // e.g. 'one' |
||
| 5077 | * </code> |
||
| 5078 | * |
||
| 5079 | * @return mixed |
||
| 5080 | * <p>Get a random value or null if there wasn't a value.</p> |
||
| 5081 | */ |
||
| 5082 | 4 | public function randomValue() |
|
| 5092 | |||
| 5093 | /** |
||
| 5094 | * Pick a given number of random values out of this array. |
||
| 5095 | * |
||
| 5096 | * EXAMPLE: <code> |
||
| 5097 | * a([1 => 'one', 2 => 'two'])->randomValues(); // e.g. Arrayy['one', 'two'] |
||
| 5098 | * </code> |
||
| 5099 | * |
||
| 5100 | * @param int $number |
||
| 5101 | * |
||
| 5102 | * @return static |
||
| 5103 | * <p>(Mutable)</p> |
||
| 5104 | * |
||
| 5105 | * @psalm-return static<TKey,T> |
||
| 5106 | */ |
||
| 5107 | 7 | public function randomValues(int $number): self |
|
| 5111 | |||
| 5112 | /** |
||
| 5113 | * Get a random value from an array, with the ability to skew the results. |
||
| 5114 | * |
||
| 5115 | * EXAMPLE: <code> |
||
| 5116 | * a([0 => 3, 1 => 4])->randomWeighted([1 => 4]); // e.g.: Arrayy[4] (has a 66% chance of returning 4) |
||
| 5117 | * </code> |
||
| 5118 | * |
||
| 5119 | * @param array $array |
||
| 5120 | * @param int|null $number <p>How many values you will take?</p> |
||
| 5121 | * |
||
| 5122 | * @return static<int,mixed> |
||
| 5123 | * <p>(Immutable)</p> |
||
| 5124 | * |
||
| 5125 | * @psalm-param array<mixed,mixed> $array |
||
| 5126 | * @psalm-return static<int|array-key,T> |
||
| 5127 | */ |
||
| 5128 | 9 | public function randomWeighted(array $array, int $number = null): self |
|
| 5143 | |||
| 5144 | /** |
||
| 5145 | * Reduce the current array via callable e.g. anonymous-function and return the end result. |
||
| 5146 | * |
||
| 5147 | * EXAMPLE: <code> |
||
| 5148 | * a([1, 2, 3, 4])->reduce( |
||
| 5149 | * function ($carry, $item) { |
||
| 5150 | * return $carry * $item; |
||
| 5151 | * }, |
||
| 5152 | * 1 |
||
| 5153 | * ); // Arrayy[24] |
||
| 5154 | * </code> |
||
| 5155 | * |
||
| 5156 | * @param callable $callable |
||
| 5157 | * @param mixed $initial |
||
| 5158 | * |
||
| 5159 | * @return static |
||
| 5160 | * <p>(Immutable)</p> |
||
| 5161 | * |
||
| 5162 | * @psalm-return static<TKey,T> |
||
| 5163 | * @psalm-mutation-free |
||
| 5164 | */ |
||
| 5165 | 18 | View Code Duplication | public function reduce($callable, $initial = []): self |
| 5177 | |||
| 5178 | /** |
||
| 5179 | * @param bool $unique |
||
| 5180 | * |
||
| 5181 | * @return static |
||
| 5182 | * <p>(Immutable)</p> |
||
| 5183 | * |
||
| 5184 | * @psalm-return static<TKey,T> |
||
| 5185 | * @psalm-mutation-free |
||
| 5186 | */ |
||
| 5187 | 14 | public function reduce_dimension(bool $unique = true): self |
|
| 5210 | |||
| 5211 | /** |
||
| 5212 | * Create a numerically re-indexed Arrayy object. |
||
| 5213 | * |
||
| 5214 | * EXAMPLE: <code> |
||
| 5215 | * a([2 => 1, 3 => 2])->reindex(); // Arrayy[0 => 1, 1 => 2] |
||
| 5216 | * </code> |
||
| 5217 | * |
||
| 5218 | * @return $this |
||
| 5219 | * <p>(Mutable) Return this Arrayy object, with re-indexed array-elements.</p> |
||
| 5220 | * |
||
| 5221 | * @psalm-return static<TKey,T> |
||
| 5222 | */ |
||
| 5223 | 9 | public function reindex(): self |
|
| 5231 | |||
| 5232 | /** |
||
| 5233 | * Return all items that fail the truth test. |
||
| 5234 | * |
||
| 5235 | * EXAMPLE: <code> |
||
| 5236 | * $closure = function ($value) { |
||
| 5237 | * return $value % 2 !== 0; |
||
| 5238 | * } |
||
| 5239 | * a([1, 2, 3, 4])->reject($closure); // Arrayy[1 => 2, 3 => 4] |
||
| 5240 | * </code> |
||
| 5241 | * |
||
| 5242 | * @param \Closure $closure |
||
| 5243 | * |
||
| 5244 | * @return static |
||
| 5245 | * <p>(Immutable)</p> |
||
| 5246 | * |
||
| 5247 | * @psalm-return static<TKey,T> |
||
| 5248 | * @psalm-mutation-free |
||
| 5249 | */ |
||
| 5250 | 1 | View Code Duplication | public function reject(\Closure $closure): self |
| 5267 | |||
| 5268 | /** |
||
| 5269 | * Remove a value from the current array (optional using dot-notation). |
||
| 5270 | * |
||
| 5271 | * EXAMPLE: <code> |
||
| 5272 | * a([1 => 'bar', 'foo' => 'foo'])->remove(1); // Arrayy['foo' => 'foo'] |
||
| 5273 | * </code> |
||
| 5274 | * |
||
| 5275 | * @param mixed $key |
||
| 5276 | * |
||
| 5277 | * @return static |
||
| 5278 | * <p>(Mutable)</p> |
||
| 5279 | * |
||
| 5280 | * @psalm-param TKey $key |
||
| 5281 | * @psalm-return static<TKey,T> |
||
| 5282 | */ |
||
| 5283 | 22 | public function remove($key) |
|
| 5306 | |||
| 5307 | /** |
||
| 5308 | * alias: for "Arrayy->removeValue()" |
||
| 5309 | * |
||
| 5310 | * @param mixed $element |
||
| 5311 | * |
||
| 5312 | * @return static |
||
| 5313 | * <p>(Immutable)</p> |
||
| 5314 | * |
||
| 5315 | * @psalm-param T $element |
||
| 5316 | * @psalm-return static<TKey,T> |
||
| 5317 | * @psalm-mutation-free |
||
| 5318 | */ |
||
| 5319 | 8 | public function removeElement($element) |
|
| 5323 | |||
| 5324 | /** |
||
| 5325 | * Remove the first value from the current array. |
||
| 5326 | * |
||
| 5327 | * EXAMPLE: <code> |
||
| 5328 | * a([1 => 'bar', 'foo' => 'foo'])->removeFirst(); // Arrayy['foo' => 'foo'] |
||
| 5329 | * </code> |
||
| 5330 | * |
||
| 5331 | * @return static |
||
| 5332 | * <p>(Immutable)</p> |
||
| 5333 | * |
||
| 5334 | * @psalm-return static<TKey,T> |
||
| 5335 | * @psalm-mutation-free |
||
| 5336 | */ |
||
| 5337 | 7 | View Code Duplication | public function removeFirst(): self |
| 5349 | |||
| 5350 | /** |
||
| 5351 | * Remove the last value from the current array. |
||
| 5352 | * |
||
| 5353 | * EXAMPLE: <code> |
||
| 5354 | * a([1 => 'bar', 'foo' => 'foo'])->removeLast(); // Arrayy[1 => 'bar'] |
||
| 5355 | * </code> |
||
| 5356 | * |
||
| 5357 | * @return static |
||
| 5358 | * <p>(Immutable)</p> |
||
| 5359 | * |
||
| 5360 | * @psalm-return static<TKey,T> |
||
| 5361 | * @psalm-mutation-free |
||
| 5362 | */ |
||
| 5363 | 7 | View Code Duplication | public function removeLast(): self |
| 5375 | |||
| 5376 | /** |
||
| 5377 | * Removes a particular value from an array (numeric or associative). |
||
| 5378 | * |
||
| 5379 | * EXAMPLE: <code> |
||
| 5380 | * a([1 => 'bar', 'foo' => 'foo'])->removeValue('foo'); // Arrayy[1 => 'bar'] |
||
| 5381 | * </code> |
||
| 5382 | * |
||
| 5383 | * @param mixed $value |
||
| 5384 | * |
||
| 5385 | * @return static |
||
| 5386 | * <p>(Immutable)</p> |
||
| 5387 | * |
||
| 5388 | * @psalm-param T $value |
||
| 5389 | * @psalm-return static<TKey,T> |
||
| 5390 | * @psalm-mutation-free |
||
| 5391 | */ |
||
| 5392 | 8 | public function removeValue($value): self |
|
| 5415 | |||
| 5416 | /** |
||
| 5417 | * Generate array of repeated arrays. |
||
| 5418 | * |
||
| 5419 | * @param int $times <p>How many times has to be repeated.</p> |
||
| 5420 | * |
||
| 5421 | * @return static |
||
| 5422 | * <p>(Immutable)</p> |
||
| 5423 | * |
||
| 5424 | * @psalm-return static<TKey,T> |
||
| 5425 | * @psalm-mutation-free |
||
| 5426 | */ |
||
| 5427 | 1 | public function repeat($times): self |
|
| 5439 | |||
| 5440 | /** |
||
| 5441 | * Replace a key with a new key/value pair. |
||
| 5442 | * |
||
| 5443 | * EXAMPLE: <code> |
||
| 5444 | * $arrayy = a([1 => 'foo', 2 => 'foo2', 3 => 'bar']); |
||
| 5445 | * $arrayy->replace(2, 'notfoo', 'notbar'); // Arrayy[1 => 'foo', 'notfoo' => 'notbar', 3 => 'bar'] |
||
| 5446 | * </code> |
||
| 5447 | * |
||
| 5448 | * @param mixed $oldKey |
||
| 5449 | * @param mixed $newKey |
||
| 5450 | * @param mixed $newValue |
||
| 5451 | * |
||
| 5452 | * @return static |
||
| 5453 | * <p>(Immutable)</p> |
||
| 5454 | * |
||
| 5455 | * @psalm-return static<TKey,T> |
||
| 5456 | * @psalm-mutation-free |
||
| 5457 | */ |
||
| 5458 | 5 | public function replace($oldKey, $newKey, $newValue): self |
|
| 5468 | |||
| 5469 | /** |
||
| 5470 | * Create an array using the current array as values and the other array as keys. |
||
| 5471 | * |
||
| 5472 | * EXAMPLE: <code> |
||
| 5473 | * $firstArray = [ |
||
| 5474 | * 1 => 'one', |
||
| 5475 | * 2 => 'two', |
||
| 5476 | * 3 => 'three', |
||
| 5477 | * ]; |
||
| 5478 | * $secondArray = [ |
||
| 5479 | * 'one' => 1, |
||
| 5480 | * 1 => 'one', |
||
| 5481 | * 2 => 2, |
||
| 5482 | * ]; |
||
| 5483 | * $arrayy = a($firstArray); |
||
| 5484 | * $arrayy->replaceAllKeys($secondArray); // Arrayy[1 => "one", 'one' => "two", 2 => "three"] |
||
| 5485 | * </code> |
||
| 5486 | * |
||
| 5487 | * @param array $keys <p>An array of keys.</p> |
||
| 5488 | * |
||
| 5489 | * @return static |
||
| 5490 | * <p>(Immutable) Arrayy object with keys from the other array.</p> |
||
| 5491 | * |
||
| 5492 | * @psalm-param array<mixed,mixed>|array<mixed,TKey> $keys |
||
| 5493 | * @psalm-return static<TKey,T> |
||
| 5494 | * @psalm-mutation-free |
||
| 5495 | */ |
||
| 5496 | 2 | public function replaceAllKeys(array $keys): self |
|
| 5504 | |||
| 5505 | /** |
||
| 5506 | * Create an array using the current array as keys and the other array as values. |
||
| 5507 | * |
||
| 5508 | * EXAMPLE: <code> |
||
| 5509 | * $firstArray = [ |
||
| 5510 | * 1 => 'one', |
||
| 5511 | * 2 => 'two', |
||
| 5512 | * 3 => 'three', |
||
| 5513 | * ]; |
||
| 5514 | * $secondArray = [ |
||
| 5515 | * 'one' => 1, |
||
| 5516 | * 1 => 'one', |
||
| 5517 | * 2 => 2, |
||
| 5518 | * ]; |
||
| 5519 | * $arrayy = a($firstArray); |
||
| 5520 | * $arrayy->replaceAllValues($secondArray); // Arrayy['one' => 1, 'two' => 'one', 'three' => 2] |
||
| 5521 | * </code> |
||
| 5522 | * |
||
| 5523 | * @param array $array <p>An array of values.</p> |
||
| 5524 | * |
||
| 5525 | * @return static |
||
| 5526 | * <p>(Immutable) Arrayy object with values from the other array.</p> |
||
| 5527 | * |
||
| 5528 | * @psalm-param array<mixed,T> $array |
||
| 5529 | * @psalm-return static<TKey,T> |
||
| 5530 | * @psalm-mutation-free |
||
| 5531 | */ |
||
| 5532 | 2 | public function replaceAllValues(array $array): self |
|
| 5540 | |||
| 5541 | /** |
||
| 5542 | * Replace the keys in an array with another set. |
||
| 5543 | * |
||
| 5544 | * EXAMPLE: <code> |
||
| 5545 | * a([1 => 'bar', 'foo' => 'foo'])->replaceKeys([1 => 2, 'foo' => 'replaced']); // Arrayy[2 => 'bar', 'replaced' => 'foo'] |
||
| 5546 | * </code> |
||
| 5547 | * |
||
| 5548 | * @param array $keys <p>An array of keys matching the array's size</p> |
||
| 5549 | * |
||
| 5550 | * @return static |
||
| 5551 | * <p>(Immutable)</p> |
||
| 5552 | * |
||
| 5553 | * @psalm-param array<mixed,mixed>|array<mixed,TKey> $keys |
||
| 5554 | * @psalm-return static<TKey,T> |
||
| 5555 | * @psalm-mutation-free |
||
| 5556 | */ |
||
| 5557 | 1 | public function replaceKeys(array $keys): self |
|
| 5568 | |||
| 5569 | /** |
||
| 5570 | * Replace the first matched value in an array. |
||
| 5571 | * |
||
| 5572 | * EXAMPLE: <code> |
||
| 5573 | * $testArray = ['bar', 'foo' => 'foo', 'foobar' => 'foobar']; |
||
| 5574 | * a($testArray)->replaceOneValue('foo', 'replaced'); // Arrayy['bar', 'foo' => 'replaced', 'foobar' => 'foobar'] |
||
| 5575 | * </code> |
||
| 5576 | * |
||
| 5577 | * @param mixed $search <p>The value to replace.</p> |
||
| 5578 | * @param mixed $replacement <p>The value to replace.</p> |
||
| 5579 | * |
||
| 5580 | * @return static |
||
| 5581 | * <p>(Immutable)</p> |
||
| 5582 | * |
||
| 5583 | * @psalm-return static<TKey,T> |
||
| 5584 | * @psalm-mutation-free |
||
| 5585 | */ |
||
| 5586 | 3 | public function replaceOneValue($search, $replacement = ''): self |
|
| 5601 | |||
| 5602 | /** |
||
| 5603 | * Replace values in the current array. |
||
| 5604 | * |
||
| 5605 | * EXAMPLE: <code> |
||
| 5606 | * $testArray = ['bar', 'foo' => 'foo', 'foobar' => 'foobar']; |
||
| 5607 | * a($testArray)->replaceValues('foo', 'replaced'); // Arrayy['bar', 'foo' => 'replaced', 'foobar' => 'replacedbar'] |
||
| 5608 | * </code> |
||
| 5609 | * |
||
| 5610 | * @param mixed $search <p>The value to replace.</p> |
||
| 5611 | * @param mixed $replacement <p>What to replace it with.</p> |
||
| 5612 | * |
||
| 5613 | * @return static |
||
| 5614 | * <p>(Immutable)</p> |
||
| 5615 | * |
||
| 5616 | * @psalm-return static<TKey,T> |
||
| 5617 | * @psalm-mutation-free |
||
| 5618 | */ |
||
| 5619 | 1 | public function replaceValues($search, $replacement = ''): self |
|
| 5631 | |||
| 5632 | /** |
||
| 5633 | * Get the last elements from index $from until the end of this array. |
||
| 5634 | * |
||
| 5635 | * EXAMPLE: <code> |
||
| 5636 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->rest(2); // Arrayy[0 => 'lall'] |
||
| 5637 | * </code> |
||
| 5638 | * |
||
| 5639 | * @param int $from |
||
| 5640 | * |
||
| 5641 | * @return static |
||
| 5642 | * <p>(Immutable)</p> |
||
| 5643 | * |
||
| 5644 | * @psalm-return static<TKey,T> |
||
| 5645 | * @psalm-mutation-free |
||
| 5646 | */ |
||
| 5647 | 15 | View Code Duplication | public function rest(int $from = 1): self |
| 5657 | |||
| 5658 | /** |
||
| 5659 | * Return the array in the reverse order. |
||
| 5660 | * |
||
| 5661 | * EXAMPLE: <code> |
||
| 5662 | * a([1, 2, 3])->reverse(); // self[3, 2, 1] |
||
| 5663 | * </code> |
||
| 5664 | * |
||
| 5665 | * @return $this |
||
| 5666 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 5667 | * |
||
| 5668 | * @psalm-return static<TKey,T> |
||
| 5669 | */ |
||
| 5670 | 9 | public function reverse(): self |
|
| 5678 | |||
| 5679 | /** |
||
| 5680 | * Sort an array in reverse order. |
||
| 5681 | * |
||
| 5682 | * @param int $sort_flags [optional] <p> |
||
| 5683 | * You may modify the behavior of the sort using the optional |
||
| 5684 | * parameter sort_flags, for details |
||
| 5685 | * see sort. |
||
| 5686 | * </p> |
||
| 5687 | * |
||
| 5688 | * @return $this |
||
| 5689 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 5690 | * |
||
| 5691 | * @psalm-return static<TKey,T> |
||
| 5692 | */ |
||
| 5693 | 4 | public function rsort(int $sort_flags = 0): self |
|
| 5701 | |||
| 5702 | /** |
||
| 5703 | * Sort an array in reverse order. |
||
| 5704 | * |
||
| 5705 | * @param int $sort_flags [optional] <p> |
||
| 5706 | * You may modify the behavior of the sort using the optional |
||
| 5707 | * parameter sort_flags, for details |
||
| 5708 | * see sort. |
||
| 5709 | * </p> |
||
| 5710 | * |
||
| 5711 | * @return $this |
||
| 5712 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 5713 | * |
||
| 5714 | * @psalm-return static<TKey,T> |
||
| 5715 | * @psalm-mutation-free |
||
| 5716 | */ |
||
| 5717 | 4 | public function rsortImmutable(int $sort_flags = 0): self |
|
| 5728 | |||
| 5729 | /** |
||
| 5730 | * Search for the first index of the current array via $value. |
||
| 5731 | * |
||
| 5732 | * EXAMPLE: <code> |
||
| 5733 | * a(['fòô' => 'bàř', 'lall' => 'bàř'])->searchIndex('bàř'); // Arrayy[0 => 'fòô'] |
||
| 5734 | * </code> |
||
| 5735 | * |
||
| 5736 | * @param mixed $value |
||
| 5737 | * |
||
| 5738 | * @return false|float|int|string |
||
| 5739 | * <p>Will return <b>FALSE</b> if the value can't be found.</p> |
||
| 5740 | * @psalm-mutation-free |
||
| 5741 | */ |
||
| 5742 | 21 | public function searchIndex($value) |
|
| 5752 | |||
| 5753 | /** |
||
| 5754 | * Search for the value of the current array via $index. |
||
| 5755 | * |
||
| 5756 | * EXAMPLE: <code> |
||
| 5757 | * a(['fòô' => 'bàř'])->searchValue('fòô'); // Arrayy[0 => 'bàř'] |
||
| 5758 | * </code> |
||
| 5759 | * |
||
| 5760 | * @param mixed $index |
||
| 5761 | * |
||
| 5762 | * @return static |
||
| 5763 | * <p>(Immutable) Will return a empty Arrayy if the value wasn't found.</p> |
||
| 5764 | * |
||
| 5765 | * @psalm-return static<TKey,T> |
||
| 5766 | * @psalm-mutation-free |
||
| 5767 | */ |
||
| 5768 | 9 | public function searchValue($index): self |
|
| 5798 | |||
| 5799 | /** |
||
| 5800 | * Set a value for the current array (optional using dot-notation). |
||
| 5801 | * |
||
| 5802 | * EXAMPLE: <code> |
||
| 5803 | * $arrayy = a(['Lars' => ['lastname' => 'Moelleken']]); |
||
| 5804 | * $arrayy->set('Lars.lastname', 'Müller'); // Arrayy['Lars', ['lastname' => 'Müller']]] |
||
| 5805 | * </code> |
||
| 5806 | * |
||
| 5807 | * @param string $key <p>The key to set.</p> |
||
| 5808 | * @param mixed $value <p>Its value.</p> |
||
| 5809 | * |
||
| 5810 | * @return $this |
||
| 5811 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 5812 | * |
||
| 5813 | * @psalm-param TKey $key |
||
| 5814 | * @psalm-param T $value |
||
| 5815 | * @psalm-return static<TKey,T> |
||
| 5816 | */ |
||
| 5817 | 28 | public function set($key, $value): self |
|
| 5823 | |||
| 5824 | /** |
||
| 5825 | * Get a value from a array and set it if it was not. |
||
| 5826 | * |
||
| 5827 | * WARNING: this method only set the value, if the $key is not already set |
||
| 5828 | * |
||
| 5829 | * EXAMPLE: <code> |
||
| 5830 | * $arrayy = a([1 => 1, 2 => 2, 3 => 3]); |
||
| 5831 | * $arrayy->setAndGet(1, 4); // 1 |
||
| 5832 | * $arrayy->setAndGet(0, 4); // 4 |
||
| 5833 | * </code> |
||
| 5834 | * |
||
| 5835 | * @param mixed $key <p>The key</p> |
||
| 5836 | * @param mixed $fallback <p>The default value to set if it isn't.</p> |
||
| 5837 | * |
||
| 5838 | * @return mixed |
||
| 5839 | * <p>(Mutable)</p> |
||
| 5840 | */ |
||
| 5841 | 11 | public function setAndGet($key, $fallback = null) |
|
| 5852 | |||
| 5853 | /** |
||
| 5854 | * Shifts a specified value off the beginning of array. |
||
| 5855 | * |
||
| 5856 | * @return mixed |
||
| 5857 | * <p>(Mutable) A shifted element from the current array.</p> |
||
| 5858 | */ |
||
| 5859 | 5 | public function shift() |
|
| 5865 | |||
| 5866 | /** |
||
| 5867 | * Shuffle the current array. |
||
| 5868 | * |
||
| 5869 | * EXAMPLE: <code> |
||
| 5870 | * a([1 => 'bar', 'foo' => 'foo'])->shuffle(); // e.g.: Arrayy[['foo' => 'foo', 1 => 'bar']] |
||
| 5871 | * </code> |
||
| 5872 | * |
||
| 5873 | * @param bool $secure <p>using a CSPRNG | @link https://paragonie.com/b/JvICXzh_jhLyt4y3</p> |
||
| 5874 | * @param array $array [optional] |
||
| 5875 | * |
||
| 5876 | * @return static |
||
| 5877 | * <p>(Immutable)</p> |
||
| 5878 | * |
||
| 5879 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 5880 | * @psalm-return static<TKey,T> |
||
| 5881 | * |
||
| 5882 | * @noinspection BadExceptionsProcessingInspection |
||
| 5883 | * @noinspection NonSecureShuffleUsageInspection |
||
| 5884 | */ |
||
| 5885 | 2 | public function shuffle(bool $secure = false, array $array = null): self |
|
| 5886 | { |
||
| 5887 | 2 | if ($array === null) { |
|
| 5888 | 2 | $array = $this->toArray(false); |
|
| 5889 | } |
||
| 5890 | |||
| 5891 | 2 | if ($secure !== true) { |
|
| 5892 | 2 | \shuffle($array); |
|
| 5893 | } else { |
||
| 5894 | 1 | $size = \count($array, \COUNT_NORMAL); |
|
| 5895 | 1 | $keys = \array_keys($array); |
|
| 5896 | 1 | for ($i = $size - 1; $i > 0; --$i) { |
|
| 5897 | try { |
||
| 5898 | 1 | $r = \random_int(0, $i); |
|
| 5899 | } catch (\Exception $e) { |
||
| 5900 | $r = \mt_rand(0, $i); |
||
| 5901 | } |
||
| 5902 | 1 | if ($r !== $i) { |
|
| 5903 | $temp = $array[$keys[$r]]; |
||
| 5904 | $array[$keys[$r]] = $array[$keys[$i]]; |
||
| 5905 | $array[$keys[$i]] = $temp; |
||
| 5906 | } |
||
| 5907 | } |
||
| 5908 | } |
||
| 5909 | |||
| 5910 | 2 | foreach ($array as $key => $value) { |
|
| 5911 | // check if recursive is needed |
||
| 5912 | 2 | if (\is_array($value)) { |
|
| 5913 | $array[$key] = $this->shuffle($secure, $value); |
||
| 5914 | } |
||
| 5915 | } |
||
| 5916 | |||
| 5917 | 2 | return static::create( |
|
| 5918 | 2 | $array, |
|
| 5919 | 2 | $this->iteratorClass, |
|
| 5920 | 2 | false |
|
| 5921 | ); |
||
| 5922 | } |
||
| 5923 | |||
| 5924 | /** |
||
| 5925 | * Count the values from the current array. |
||
| 5926 | * |
||
| 5927 | * alias: for "Arrayy->count()" |
||
| 5928 | * |
||
| 5929 | * @param int $mode |
||
| 5930 | * |
||
| 5931 | * @return int |
||
| 5932 | */ |
||
| 5933 | 20 | public function size(int $mode = \COUNT_NORMAL): int |
|
| 5937 | |||
| 5938 | /** |
||
| 5939 | * Checks whether array has exactly $size items. |
||
| 5940 | * |
||
| 5941 | * @param int $size |
||
| 5942 | * |
||
| 5943 | * @return bool |
||
| 5944 | */ |
||
| 5945 | 1 | public function sizeIs(int $size): bool |
|
| 5961 | |||
| 5962 | /** |
||
| 5963 | * Checks whether array has between $fromSize to $toSize items. $toSize can be |
||
| 5964 | * smaller than $fromSize. |
||
| 5965 | * |
||
| 5966 | * @param int $fromSize |
||
| 5967 | * @param int $toSize |
||
| 5968 | * |
||
| 5969 | * @return bool |
||
| 5970 | */ |
||
| 5971 | 1 | public function sizeIsBetween(int $fromSize, int $toSize): bool |
|
| 5991 | |||
| 5992 | /** |
||
| 5993 | * Checks whether array has more than $size items. |
||
| 5994 | * |
||
| 5995 | * @param int $size |
||
| 5996 | * |
||
| 5997 | * @return bool |
||
| 5998 | */ |
||
| 5999 | 1 | View Code Duplication | public function sizeIsGreaterThan(int $size): bool |
| 6013 | |||
| 6014 | /** |
||
| 6015 | * Checks whether array has less than $size items. |
||
| 6016 | * |
||
| 6017 | * @param int $size |
||
| 6018 | * |
||
| 6019 | * @return bool |
||
| 6020 | */ |
||
| 6021 | 1 | View Code Duplication | public function sizeIsLessThan(int $size): bool |
| 6035 | |||
| 6036 | /** |
||
| 6037 | * Counts all elements in an array, or something in an object. |
||
| 6038 | * |
||
| 6039 | * <p> |
||
| 6040 | * For objects, if you have SPL installed, you can hook into count() by implementing interface {@see Countable}. |
||
| 6041 | * The interface has exactly one method, {@see Countable::count()}, which returns the return value for the count() |
||
| 6042 | * function. Please see the {@see Array} section of the manual for a detailed explanation of how arrays are |
||
| 6043 | * implemented and used in PHP. |
||
| 6044 | * </p> |
||
| 6045 | * |
||
| 6046 | * @return int |
||
| 6047 | * <p> |
||
| 6048 | * The number of elements in var, which is |
||
| 6049 | * typically an array, since anything else will have one |
||
| 6050 | * element. |
||
| 6051 | * </p> |
||
| 6052 | * <p> |
||
| 6053 | * If var is not an array or an object with |
||
| 6054 | * implemented Countable interface, |
||
| 6055 | * 1 will be returned. |
||
| 6056 | * There is one exception, if var is &null;, |
||
| 6057 | * 0 will be returned. |
||
| 6058 | * </p> |
||
| 6059 | * <p> |
||
| 6060 | * Caution: count may return 0 for a variable that isn't set, |
||
| 6061 | * but it may also return 0 for a variable that has been initialized with an |
||
| 6062 | * empty array. Use isset to test if a variable is set. |
||
| 6063 | * </p> |
||
| 6064 | */ |
||
| 6065 | 10 | public function sizeRecursive(): int |
|
| 6069 | |||
| 6070 | /** |
||
| 6071 | * Extract a slice of the array. |
||
| 6072 | * |
||
| 6073 | * @param int $offset <p>Slice begin index.</p> |
||
| 6074 | * @param int|null $length <p>Length of the slice.</p> |
||
| 6075 | * @param bool $preserveKeys <p>Whether array keys are preserved or no.</p> |
||
| 6076 | * |
||
| 6077 | * @return static |
||
| 6078 | * <p>(Immutable) A slice of the original array with length $length.</p> |
||
| 6079 | * |
||
| 6080 | * @psalm-return static<TKey,T> |
||
| 6081 | * @psalm-mutation-free |
||
| 6082 | */ |
||
| 6083 | 5 | public function slice(int $offset, int $length = null, bool $preserveKeys = false) |
|
| 6096 | |||
| 6097 | /** |
||
| 6098 | * Sort the current array and optional you can keep the keys. |
||
| 6099 | * |
||
| 6100 | * EXAMPLE: <code> |
||
| 6101 | * a(3 => 'd', 2 => 'f', 0 => 'a')->sort(SORT_ASC, SORT_NATURAL, false); // Arrayy[0 => 'a', 1 => 'd', 2 => 'f'] |
||
| 6102 | * </code> |
||
| 6103 | * |
||
| 6104 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 6105 | * @param int $strategy <p>sort_flags => use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 6106 | * <strong>SORT_NATURAL</strong></p> |
||
| 6107 | * @param bool $keepKeys |
||
| 6108 | * |
||
| 6109 | * @return static |
||
| 6110 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 6111 | * |
||
| 6112 | * @psalm-return static<TKey,T> |
||
| 6113 | */ |
||
| 6114 | 20 | public function sort( |
|
| 6128 | |||
| 6129 | /** |
||
| 6130 | * Sort the current array and optional you can keep the keys. |
||
| 6131 | * |
||
| 6132 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 6133 | * @param int $strategy <p>sort_flags => use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 6134 | * <strong>SORT_NATURAL</strong></p> |
||
| 6135 | * @param bool $keepKeys |
||
| 6136 | * |
||
| 6137 | * @return static |
||
| 6138 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 6139 | * |
||
| 6140 | * @psalm-return static<TKey,T> |
||
| 6141 | */ |
||
| 6142 | 12 | public function sortImmutable( |
|
| 6158 | |||
| 6159 | /** |
||
| 6160 | * Sort the current array by key. |
||
| 6161 | * |
||
| 6162 | * EXAMPLE: <code> |
||
| 6163 | * a([1 => 2, 0 => 1])->sortKeys(\SORT_ASC); // Arrayy[0 => 1, 1 => 2] |
||
| 6164 | * </code> |
||
| 6165 | * |
||
| 6166 | * @see http://php.net/manual/en/function.ksort.php |
||
| 6167 | * @see http://php.net/manual/en/function.krsort.php |
||
| 6168 | * |
||
| 6169 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 6170 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 6171 | * <strong>SORT_NATURAL</strong></p> |
||
| 6172 | * |
||
| 6173 | * @return $this |
||
| 6174 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 6175 | * |
||
| 6176 | * @psalm-return static<TKey,T> |
||
| 6177 | */ |
||
| 6178 | 18 | public function sortKeys( |
|
| 6188 | |||
| 6189 | /** |
||
| 6190 | * Sort the current array by key. |
||
| 6191 | * |
||
| 6192 | * @see http://php.net/manual/en/function.ksort.php |
||
| 6193 | * @see http://php.net/manual/en/function.krsort.php |
||
| 6194 | * |
||
| 6195 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 6196 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 6197 | * <strong>SORT_NATURAL</strong></p> |
||
| 6198 | * |
||
| 6199 | * @return $this |
||
| 6200 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 6201 | * |
||
| 6202 | * @psalm-return static<TKey,T> |
||
| 6203 | * @psalm-mutation-free |
||
| 6204 | */ |
||
| 6205 | 8 | public function sortKeysImmutable( |
|
| 6218 | |||
| 6219 | /** |
||
| 6220 | * Sort the current array by value. |
||
| 6221 | * |
||
| 6222 | * EXAMPLE: <code> |
||
| 6223 | * a(3 => 'd', 2 => 'f', 0 => 'a')->sortValueKeepIndex(SORT_ASC, SORT_REGULAR); // Arrayy[0 => 'a', 3 => 'd', 2 => 'f'] |
||
| 6224 | * </code> |
||
| 6225 | * |
||
| 6226 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 6227 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 6228 | * <strong>SORT_NATURAL</strong></p> |
||
| 6229 | * |
||
| 6230 | * @return static |
||
| 6231 | * <p>(Mutable)</p> |
||
| 6232 | * |
||
| 6233 | * @psalm-return static<TKey,T> |
||
| 6234 | */ |
||
| 6235 | 1 | public function sortValueKeepIndex( |
|
| 6241 | |||
| 6242 | /** |
||
| 6243 | * Sort the current array by value. |
||
| 6244 | * |
||
| 6245 | * EXAMPLE: <code> |
||
| 6246 | * a(3 => 'd', 2 => 'f', 0 => 'a')->sortValueNewIndex(SORT_ASC, SORT_NATURAL); // Arrayy[0 => 'a', 1 => 'd', 2 => 'f'] |
||
| 6247 | * </code> |
||
| 6248 | * |
||
| 6249 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 6250 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 6251 | * <strong>SORT_NATURAL</strong></p> |
||
| 6252 | * |
||
| 6253 | * @return static |
||
| 6254 | * <p>(Mutable)</p> |
||
| 6255 | * |
||
| 6256 | * @psalm-return static<TKey,T> |
||
| 6257 | */ |
||
| 6258 | 1 | public function sortValueNewIndex($direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
| 6262 | |||
| 6263 | /** |
||
| 6264 | * Sort a array by value or by a closure. |
||
| 6265 | * |
||
| 6266 | * - If the sorter is null, the array is sorted naturally. |
||
| 6267 | * - Associative (string) keys will be maintained, but numeric keys will be re-indexed. |
||
| 6268 | * |
||
| 6269 | * EXAMPLE: <code> |
||
| 6270 | * $testArray = range(1, 5); |
||
| 6271 | * $under = a($testArray)->sorter( |
||
| 6272 | * function ($value) { |
||
| 6273 | * return $value % 2 === 0; |
||
| 6274 | * } |
||
| 6275 | * ); |
||
| 6276 | * var_dump($under); // Arrayy[1, 3, 5, 2, 4] |
||
| 6277 | * </code> |
||
| 6278 | * |
||
| 6279 | * @param callable|mixed|null $sorter |
||
| 6280 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or |
||
| 6281 | * <strong>SORT_DESC</strong></p> |
||
| 6282 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 6283 | * <strong>SORT_NATURAL</strong></p> |
||
| 6284 | * |
||
| 6285 | * @return static |
||
| 6286 | * <p>(Immutable)</p> |
||
| 6287 | * |
||
| 6288 | * @pslam-param callable|T|null $sorter |
||
| 6289 | * @psalm-return static<TKey,T> |
||
| 6290 | * @psalm-mutation-free |
||
| 6291 | */ |
||
| 6292 | 1 | public function sorter($sorter = null, $direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
| 6333 | |||
| 6334 | /** |
||
| 6335 | * @param int $offset |
||
| 6336 | * @param int|null $length |
||
| 6337 | * @param array $replacement |
||
| 6338 | * |
||
| 6339 | * @return static |
||
| 6340 | * <p>(Immutable)</p> |
||
| 6341 | * |
||
| 6342 | * @psalm-param array<mixed,mixed>|array<mixed,T> $replacement |
||
| 6343 | * @psalm-return static<TKey,T> |
||
| 6344 | * @psalm-mutation-free |
||
| 6345 | */ |
||
| 6346 | 1 | public function splice(int $offset, int $length = null, $replacement = []): self |
|
| 6363 | |||
| 6364 | /** |
||
| 6365 | * Split an array in the given amount of pieces. |
||
| 6366 | * |
||
| 6367 | * EXAMPLE: <code> |
||
| 6368 | * a(['a' => 1, 'b' => 2])->split(2, true); // Arrayy[['a' => 1], ['b' => 2]] |
||
| 6369 | * </code> |
||
| 6370 | * |
||
| 6371 | * @param int $numberOfPieces |
||
| 6372 | * @param bool $keepKeys |
||
| 6373 | * |
||
| 6374 | * @return static |
||
| 6375 | * <p>(Immutable)</p> |
||
| 6376 | * |
||
| 6377 | * @psalm-return static<TKey,T> |
||
| 6378 | * @psalm-mutation-free |
||
| 6379 | */ |
||
| 6380 | 1 | public function split(int $numberOfPieces = 2, bool $keepKeys = false): self |
|
| 6436 | |||
| 6437 | /** |
||
| 6438 | * Strip all empty items from the current array. |
||
| 6439 | * |
||
| 6440 | * EXAMPLE: <code> |
||
| 6441 | * a(['a' => 1, 'b' => ''])->stripEmpty(); // Arrayy[['a' => 1]] |
||
| 6442 | * </code> |
||
| 6443 | * |
||
| 6444 | * @return static |
||
| 6445 | * <p>(Immutable)</p> |
||
| 6446 | * |
||
| 6447 | * @psalm-return static<TKey,T> |
||
| 6448 | * @psalm-mutation-free |
||
| 6449 | */ |
||
| 6450 | 1 | public function stripEmpty(): self |
|
| 6462 | |||
| 6463 | /** |
||
| 6464 | * Swap two values between positions by key. |
||
| 6465 | * |
||
| 6466 | * EXAMPLE: <code> |
||
| 6467 | * a(['a' => 1, 'b' => ''])->swap('a', 'b'); // Arrayy[['a' => '', 'b' => 1]] |
||
| 6468 | * </code> |
||
| 6469 | * |
||
| 6470 | * @param int|string $swapA <p>a key in the array</p> |
||
| 6471 | * @param int|string $swapB <p>a key in the array</p> |
||
| 6472 | * |
||
| 6473 | * @return static |
||
| 6474 | * <p>(Immutable)</p> |
||
| 6475 | * |
||
| 6476 | * @psalm-return static<TKey,T> |
||
| 6477 | * @psalm-mutation-free |
||
| 6478 | */ |
||
| 6479 | 1 | public function swap($swapA, $swapB): self |
|
| 6491 | |||
| 6492 | /** |
||
| 6493 | * Get the current array from the "Arrayy"-object. |
||
| 6494 | * alias for "getArray()" |
||
| 6495 | * |
||
| 6496 | * @param bool $convertAllArrayyElements <p> |
||
| 6497 | * Convert all Child-"Arrayy" objects also to arrays. |
||
| 6498 | * </p> |
||
| 6499 | * @param bool $preserveKeys <p> |
||
| 6500 | * e.g.: A generator maybe return the same key more then once, |
||
| 6501 | * so maybe you will ignore the keys. |
||
| 6502 | * </p> |
||
| 6503 | * |
||
| 6504 | * @return array |
||
| 6505 | * |
||
| 6506 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 6507 | * @psalm-mutation-free |
||
| 6508 | */ |
||
| 6509 | 932 | public function toArray( |
|
| 6537 | |||
| 6538 | /** |
||
| 6539 | * Get the current array from the "Arrayy"-object as list. |
||
| 6540 | * |
||
| 6541 | * @param bool $convertAllArrayyElements <p> |
||
| 6542 | * Convert all Child-"Arrayy" objects also to arrays. |
||
| 6543 | * </p> |
||
| 6544 | * |
||
| 6545 | * @return array |
||
| 6546 | * |
||
| 6547 | * @psalm-return list<array<TKey,T>> |
||
| 6548 | * @psalm-mutation-free |
||
| 6549 | */ |
||
| 6550 | 1 | public function toList(bool $convertAllArrayyElements = false): array |
|
| 6557 | |||
| 6558 | /** |
||
| 6559 | * Convert the current array to JSON. |
||
| 6560 | * |
||
| 6561 | * EXAMPLE: <code> |
||
| 6562 | * a(['bar', ['foo']])->toJson(); // '["bar",{"1":"foo"}]' |
||
| 6563 | * </code> |
||
| 6564 | * |
||
| 6565 | * @param int $options [optional] <p>e.g. JSON_PRETTY_PRINT</p> |
||
| 6566 | * @param int $depth [optional] <p>Set the maximum depth. Must be greater than zero.</p> |
||
| 6567 | * |
||
| 6568 | * @return string |
||
| 6569 | */ |
||
| 6570 | 12 | public function toJson(int $options = 0, int $depth = 512): string |
|
| 6579 | |||
| 6580 | /** |
||
| 6581 | * @param string[]|null $items [optional] |
||
| 6582 | * @param string[] $helper [optional] |
||
| 6583 | * |
||
| 6584 | * @return static|static[] |
||
| 6585 | * |
||
| 6586 | * @psalm-return static<int, static<TKey,T>> |
||
| 6587 | */ |
||
| 6588 | 1 | public function toPermutation(array $items = null, array $helper = []): self |
|
| 6621 | |||
| 6622 | /** |
||
| 6623 | * Implodes array to a string with specified separator. |
||
| 6624 | * |
||
| 6625 | * @param string $separator [optional] <p>The element's separator.</p> |
||
| 6626 | * |
||
| 6627 | * @return string |
||
| 6628 | * <p>The string representation of array, separated by ",".</p> |
||
| 6629 | */ |
||
| 6630 | 19 | public function toString(string $separator = ','): string |
|
| 6634 | |||
| 6635 | /** |
||
| 6636 | * Return a duplicate free copy of the current array. |
||
| 6637 | * |
||
| 6638 | * EXAMPLE: <code> |
||
| 6639 | * a([2 => 1, 3 => 2, 4 => 2])->uniqueNewIndex(); // Arrayy[1, 2] |
||
| 6640 | * </code> |
||
| 6641 | * |
||
| 6642 | * @return $this |
||
| 6643 | * <p>(Mutable)</p> |
||
| 6644 | * |
||
| 6645 | * @psalm-return static<TKey,T> |
||
| 6646 | */ |
||
| 6647 | 13 | public function uniqueNewIndex(): self |
|
| 6669 | |||
| 6670 | /** |
||
| 6671 | * Return a duplicate free copy of the current array. (with the old keys) |
||
| 6672 | * |
||
| 6673 | * EXAMPLE: <code> |
||
| 6674 | * a([2 => 1, 3 => 2, 4 => 2])->uniqueNewIndex(); // Arrayy[2 => 1, 3 => 2] |
||
| 6675 | * </code> |
||
| 6676 | * |
||
| 6677 | * @return $this |
||
| 6678 | * <p>(Mutable)</p> |
||
| 6679 | * |
||
| 6680 | * @psalm-return static<TKey,T> |
||
| 6681 | */ |
||
| 6682 | 11 | public function uniqueKeepIndex(): self |
|
| 6708 | |||
| 6709 | /** |
||
| 6710 | * alias: for "Arrayy->uniqueNewIndex()" |
||
| 6711 | * |
||
| 6712 | * @return static |
||
| 6713 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
| 6714 | * |
||
| 6715 | * @see Arrayy::unique() |
||
| 6716 | * |
||
| 6717 | * @psalm-return static<TKey,T> |
||
| 6718 | */ |
||
| 6719 | 13 | public function unique(): self |
|
| 6723 | |||
| 6724 | /** |
||
| 6725 | * Prepends one or more values to the beginning of array at once. |
||
| 6726 | * |
||
| 6727 | * @param mixed ...$args |
||
| 6728 | * |
||
| 6729 | * @return $this |
||
| 6730 | * <p>(Mutable) Return this Arrayy object, with prepended elements to the beginning of array.</p> |
||
| 6731 | * |
||
| 6732 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$args |
||
| 6733 | * @psalm-return static<TKey,T> |
||
| 6734 | */ |
||
| 6735 | 4 | public function unshift(...$args): self |
|
| 6743 | |||
| 6744 | /** |
||
| 6745 | * Tests whether the given closure return something valid for all elements of this array. |
||
| 6746 | * |
||
| 6747 | * @param \Closure $closure the predicate |
||
| 6748 | * |
||
| 6749 | * @return bool |
||
| 6750 | * <p>TRUE, if the predicate yields TRUE for all elements, FALSE otherwise.</p> |
||
| 6751 | */ |
||
| 6752 | 1 | View Code Duplication | public function validate(\Closure $closure): bool |
| 6762 | |||
| 6763 | /** |
||
| 6764 | * Get all values from a array. |
||
| 6765 | * |
||
| 6766 | * EXAMPLE: <code> |
||
| 6767 | * $arrayy = a([1 => 'foo', 2 => 'foo2', 3 => 'bar']); |
||
| 6768 | * $arrayyTmp->values(); // Arrayy[0 => 'foo', 1 => 'foo2', 2 => 'bar'] |
||
| 6769 | * </code> |
||
| 6770 | * |
||
| 6771 | * @return static |
||
| 6772 | * <p>(Immutable)</p> |
||
| 6773 | * |
||
| 6774 | * @psalm-return static<TKey,T> |
||
| 6775 | * @psalm-mutation-free |
||
| 6776 | */ |
||
| 6777 | 2 | public function values(): self |
|
| 6790 | |||
| 6791 | /** |
||
| 6792 | * Apply the given function to every element in the array, discarding the results. |
||
| 6793 | * |
||
| 6794 | * EXAMPLE: <code> |
||
| 6795 | * $callable = function (&$value, $key) { |
||
| 6796 | * $value = $key; |
||
| 6797 | * }; |
||
| 6798 | * $arrayy = a([1, 2, 3]); |
||
| 6799 | * $arrayy->walk($callable); // Arrayy[0, 1, 2] |
||
| 6800 | * </code> |
||
| 6801 | * |
||
| 6802 | * @param callable $callable |
||
| 6803 | * @param bool $recursive [optional] <p>Whether array will be walked recursively or no</p> |
||
| 6804 | * @param mixed $userData [optional] <p> |
||
| 6805 | * If the optional $userData parameter is supplied, |
||
| 6806 | * it will be passed as the third parameter to the $callable. |
||
| 6807 | * </p> |
||
| 6808 | * |
||
| 6809 | * @return $this |
||
| 6810 | * <p>(Mutable) Return this Arrayy object, with modified elements.</p> |
||
| 6811 | * |
||
| 6812 | * @psalm-return static<TKey,T> |
||
| 6813 | */ |
||
| 6814 | 12 | public function walk( |
|
| 6840 | |||
| 6841 | /** |
||
| 6842 | * Returns a collection of matching items. |
||
| 6843 | * |
||
| 6844 | * @param string $keyOrPropertyOrMethod the property or method to evaluate |
||
| 6845 | * @param mixed $value the value to match |
||
| 6846 | * |
||
| 6847 | * @throws \InvalidArgumentException if property or method is not defined |
||
| 6848 | * |
||
| 6849 | * @return static |
||
| 6850 | * |
||
| 6851 | * @psalm-return static<TKey,T> |
||
| 6852 | */ |
||
| 6853 | 1 | public function where(string $keyOrPropertyOrMethod, $value): self |
|
| 6866 | |||
| 6867 | /** |
||
| 6868 | * Convert an array into a object. |
||
| 6869 | * |
||
| 6870 | * @param array $array |
||
| 6871 | * |
||
| 6872 | * @return \stdClass |
||
| 6873 | * |
||
| 6874 | * @psalm-param array<mixed,mixed> $array |
||
| 6875 | */ |
||
| 6876 | 4 | final protected static function arrayToObject(array $array = []): \stdClass |
|
| 6895 | |||
| 6896 | /** |
||
| 6897 | * @param array|\Generator|null $input <p> |
||
| 6898 | * An array containing keys to return. |
||
| 6899 | * </p> |
||
| 6900 | * @param mixed|null $search_values [optional] <p> |
||
| 6901 | * If specified, then only keys containing these values are returned. |
||
| 6902 | * </p> |
||
| 6903 | * @param bool $strict [optional] <p> |
||
| 6904 | * Determines if strict comparison (===) should be used during the |
||
| 6905 | * search. |
||
| 6906 | * </p> |
||
| 6907 | * |
||
| 6908 | * @return array |
||
| 6909 | * <p>an array of all the keys in input</p> |
||
| 6910 | * |
||
| 6911 | * @psalm-param array<mixed,mixed>|\Generator<TKey,T>|null $input |
||
| 6912 | * @psalm-return array<TKey|mixed> |
||
| 6913 | * @psalm-mutation-free |
||
| 6914 | */ |
||
| 6915 | 11 | protected function array_keys_recursive( |
|
| 6976 | |||
| 6977 | /** |
||
| 6978 | * @param mixed $path |
||
| 6979 | * @param callable $callable |
||
| 6980 | * @param array|null $currentOffset |
||
| 6981 | * |
||
| 6982 | * @return void |
||
| 6983 | * |
||
| 6984 | * @psalm-param array<mixed,mixed>|array<TKey,T>|null $currentOffset |
||
| 6985 | * @psalm-mutation-free |
||
| 6986 | */ |
||
| 6987 | 10 | protected function callAtPath($path, $callable, &$currentOffset = null) |
|
| 7016 | |||
| 7017 | /** |
||
| 7018 | * Extracts the value of the given property or method from the object. |
||
| 7019 | * |
||
| 7020 | * @param static $object <p>The object to extract the value from.</p> |
||
| 7021 | * @param string $keyOrPropertyOrMethod <p>The property or method for which the |
||
| 7022 | * value should be extracted.</p> |
||
| 7023 | * |
||
| 7024 | * @throws \InvalidArgumentException if the method or property is not defined |
||
| 7025 | * |
||
| 7026 | * @return mixed |
||
| 7027 | * <p>The value extracted from the specified property or method.</p> |
||
| 7028 | * |
||
| 7029 | * @psalm-param self<TKey,T> $object |
||
| 7030 | */ |
||
| 7031 | 1 | final protected function extractValue(self $object, string $keyOrPropertyOrMethod) |
|
| 7053 | |||
| 7054 | /** |
||
| 7055 | * create a fallback for array |
||
| 7056 | * |
||
| 7057 | * 1. use the current array, if it's a array |
||
| 7058 | * 2. fallback to empty array, if there is nothing |
||
| 7059 | * 3. call "getArray()" on object, if there is a "Arrayy"-object |
||
| 7060 | * 4. call "createFromObject()" on object, if there is a "\Traversable"-object |
||
| 7061 | * 5. call "__toArray()" on object, if the method exists |
||
| 7062 | * 6. cast a string or object with "__toString()" into an array |
||
| 7063 | * 7. throw a "InvalidArgumentException"-Exception |
||
| 7064 | * |
||
| 7065 | * @param mixed $data |
||
| 7066 | * |
||
| 7067 | * @throws \InvalidArgumentException |
||
| 7068 | * |
||
| 7069 | * @return array |
||
| 7070 | * |
||
| 7071 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 7072 | */ |
||
| 7073 | 1208 | protected function fallbackForArray(&$data): array |
|
| 7083 | |||
| 7084 | /** |
||
| 7085 | * @param bool $preserveKeys <p> |
||
| 7086 | * e.g.: A generator maybe return the same key more then once, |
||
| 7087 | * so maybe you will ignore the keys. |
||
| 7088 | * </p> |
||
| 7089 | * |
||
| 7090 | * @return bool |
||
| 7091 | * |
||
| 7092 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
| 7093 | * @psalm-mutation-free :/ |
||
| 7094 | */ |
||
| 7095 | 1120 | protected function generatorToArray(bool $preserveKeys = true) |
|
| 7106 | |||
| 7107 | /** |
||
| 7108 | * Get correct PHP constant for direction. |
||
| 7109 | * |
||
| 7110 | * @param int|string $direction |
||
| 7111 | * |
||
| 7112 | * @return int |
||
| 7113 | * @psalm-mutation-free |
||
| 7114 | */ |
||
| 7115 | 43 | protected function getDirection($direction): int |
|
| 7137 | |||
| 7138 | /** |
||
| 7139 | * @return TypeCheckInterface[] |
||
| 7140 | * |
||
| 7141 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
| 7142 | */ |
||
| 7143 | 24 | protected function getPropertiesFromPhpDoc() |
|
| 7198 | |||
| 7199 | /** |
||
| 7200 | * @param mixed $glue |
||
| 7201 | * @param mixed $pieces |
||
| 7202 | * @param bool $useKeys |
||
| 7203 | * |
||
| 7204 | * @return string |
||
| 7205 | * @psalm-mutation-free |
||
| 7206 | */ |
||
| 7207 | 36 | protected function implode_recursive( |
|
| 7240 | |||
| 7241 | /** |
||
| 7242 | * @param mixed $needle <p> |
||
| 7243 | * The searched value. |
||
| 7244 | * </p> |
||
| 7245 | * <p> |
||
| 7246 | * If needle is a string, the comparison is done |
||
| 7247 | * in a case-sensitive manner. |
||
| 7248 | * </p> |
||
| 7249 | * @param array|\Generator|null $haystack <p> |
||
| 7250 | * The array. |
||
| 7251 | * </p> |
||
| 7252 | * @param bool $strict [optional] <p> |
||
| 7253 | * If the third parameter strict is set to true |
||
| 7254 | * then the in_array function will also check the |
||
| 7255 | * types of the |
||
| 7256 | * needle in the haystack. |
||
| 7257 | * </p> |
||
| 7258 | * |
||
| 7259 | * @return bool |
||
| 7260 | * <p>true if needle is found in the array, false otherwise</p> |
||
| 7261 | * |
||
| 7262 | * @psalm-param array<mixed,mixed>|\Generator<TKey,T>|null $haystack |
||
| 7263 | * @psalm-mutation-free |
||
| 7264 | */ |
||
| 7265 | 18 | protected function in_array_recursive($needle, $haystack = null, $strict = true): bool |
|
| 7290 | |||
| 7291 | /** |
||
| 7292 | * @param mixed $data |
||
| 7293 | * |
||
| 7294 | * @return array|null |
||
| 7295 | * |
||
| 7296 | * @psalm-return array<mixed,mixed>|array<TKey,T>|null |
||
| 7297 | */ |
||
| 7298 | 1208 | protected function internalGetArray(&$data) |
|
| 7349 | |||
| 7350 | /** |
||
| 7351 | * Internal mechanics of remove method. |
||
| 7352 | * |
||
| 7353 | * @param mixed $key |
||
| 7354 | * |
||
| 7355 | * @return bool |
||
| 7356 | */ |
||
| 7357 | 22 | protected function internalRemove($key): bool |
|
| 7390 | |||
| 7391 | /** |
||
| 7392 | * Internal mechanic of set method. |
||
| 7393 | * |
||
| 7394 | * @param int|string|null $key |
||
| 7395 | * @param mixed $value |
||
| 7396 | * @param bool $checkProperties |
||
| 7397 | * |
||
| 7398 | * @return bool |
||
| 7399 | */ |
||
| 7400 | 1058 | protected function internalSet( |
|
| 7459 | |||
| 7460 | /** |
||
| 7461 | * Convert a object into an array. |
||
| 7462 | * |
||
| 7463 | * @param mixed|object $object |
||
| 7464 | * |
||
| 7465 | * @return array|mixed |
||
| 7466 | * |
||
| 7467 | * @psalm-mutation-free |
||
| 7468 | */ |
||
| 7469 | 5 | protected static function objectToArray($object) |
|
| 7482 | |||
| 7483 | /** |
||
| 7484 | * @param array $data |
||
| 7485 | * @param bool $checkPropertiesInConstructor |
||
| 7486 | * |
||
| 7487 | * @return void |
||
| 7488 | * |
||
| 7489 | * @psalm-param array<mixed,T> $data |
||
| 7490 | */ |
||
| 7491 | 1206 | protected function setInitialValuesAndProperties(array &$data, bool $checkPropertiesInConstructor) |
|
| 7536 | |||
| 7537 | /** |
||
| 7538 | * sorting keys |
||
| 7539 | * |
||
| 7540 | * @param array $elements |
||
| 7541 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 7542 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 7543 | * <strong>SORT_NATURAL</strong></p> |
||
| 7544 | * |
||
| 7545 | * @return $this |
||
| 7546 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 7547 | * |
||
| 7548 | * @psalm-param array<mixed,mixed>|array<mixed|TKey,T> $elements |
||
| 7549 | * @psalm-return static<TKey,T> |
||
| 7550 | */ |
||
| 7551 | 18 | protected function sorterKeys( |
|
| 7572 | |||
| 7573 | /** |
||
| 7574 | * @param array $elements <p>Warning: used as reference</p> |
||
| 7575 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 7576 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 7577 | * <strong>SORT_NATURAL</strong></p> |
||
| 7578 | * @param bool $keepKeys |
||
| 7579 | * |
||
| 7580 | * @return $this |
||
| 7581 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 7582 | * |
||
| 7583 | * @psalm-param array<mixed,mixed>|array<mixed|TKey,T> $elements |
||
| 7584 | * @psalm-return static<TKey,T> |
||
| 7585 | */ |
||
| 7586 | 24 | protected function sorting( |
|
| 7620 | |||
| 7621 | /** |
||
| 7622 | * @param array $array |
||
| 7623 | * |
||
| 7624 | * @return array |
||
| 7625 | * |
||
| 7626 | * @psalm-mutation-free |
||
| 7627 | */ |
||
| 7628 | 25 | private function getArrayRecursiveHelperArrayy(array $array) |
|
| 7650 | |||
| 7651 | /** |
||
| 7652 | * @param int|string|null $key |
||
| 7653 | * @param mixed $value |
||
| 7654 | * |
||
| 7655 | * @return void |
||
| 7656 | */ |
||
| 7657 | 113 | private function checkType($key, $value) |
|
| 7675 | } |
||
| 7676 |
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..