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 | 1205 | 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 | 128 | 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|static $data |
||
| 442 | * |
||
| 443 | * @return array |
||
| 444 | * |
||
| 445 | * @psalm-param array<TKey,T>|self<TKey,T> $data |
||
| 446 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 447 | */ |
||
| 448 | 1 | public function exchangeArray($data): array |
|
| 454 | |||
| 455 | /** |
||
| 456 | * Creates a copy of the ArrayyObject. |
||
| 457 | * |
||
| 458 | * @return array |
||
| 459 | * |
||
| 460 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 461 | */ |
||
| 462 | 6 | public function getArrayCopy(): array |
|
| 468 | |||
| 469 | /** |
||
| 470 | * Returns a new iterator, thus implementing the \Iterator interface. |
||
| 471 | * |
||
| 472 | * EXAMPLE: <code> |
||
| 473 | * a(['foo', 'bar'])->getIterator(); // ArrayyIterator['foo', 'bar'] |
||
| 474 | * </code> |
||
| 475 | * |
||
| 476 | * @return \Iterator<mixed, mixed> |
||
| 477 | * <p>An iterator for the values in the array.</p> |
||
| 478 | * @psalm-return \Iterator<array-key|TKey, mixed|T> |
||
| 479 | */ |
||
| 480 | 27 | public function getIterator(): \Iterator |
|
| 497 | |||
| 498 | /** |
||
| 499 | * Gets the iterator classname for the ArrayObject. |
||
| 500 | * |
||
| 501 | * @return string |
||
| 502 | * |
||
| 503 | * @psalm-return class-string |
||
| 504 | */ |
||
| 505 | 26 | public function getIteratorClass(): string |
|
| 509 | |||
| 510 | /** |
||
| 511 | * Sort the entries by key. |
||
| 512 | * |
||
| 513 | * @param int $sort_flags [optional] <p> |
||
| 514 | * You may modify the behavior of the sort using the optional |
||
| 515 | * parameter sort_flags, for details |
||
| 516 | * see sort. |
||
| 517 | * </p> |
||
| 518 | * |
||
| 519 | * @return $this |
||
| 520 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 521 | * |
||
| 522 | * @psalm-return static<TKey,T> |
||
| 523 | */ |
||
| 524 | 4 | public function ksort(int $sort_flags = 0): self |
|
| 532 | |||
| 533 | /** |
||
| 534 | * Sort the entries by key. |
||
| 535 | * |
||
| 536 | * @param int $sort_flags [optional] <p> |
||
| 537 | * You may modify the behavior of the sort using the optional |
||
| 538 | * parameter sort_flags, for details |
||
| 539 | * see sort. |
||
| 540 | * </p> |
||
| 541 | * |
||
| 542 | * @return $this |
||
| 543 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 544 | * |
||
| 545 | * @psalm-return static<TKey,T> |
||
| 546 | */ |
||
| 547 | 4 | public function ksortImmutable(int $sort_flags = 0): self |
|
| 558 | |||
| 559 | /** |
||
| 560 | * Sort an array using a case insensitive "natural order" algorithm. |
||
| 561 | * |
||
| 562 | * @return $this |
||
| 563 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 564 | * |
||
| 565 | * @psalm-return static<TKey,T> |
||
| 566 | */ |
||
| 567 | 8 | public function natcasesort(): self |
|
| 575 | |||
| 576 | /** |
||
| 577 | * Sort an array using a case insensitive "natural order" algorithm. |
||
| 578 | * |
||
| 579 | * @return $this |
||
| 580 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 581 | * |
||
| 582 | * @psalm-return static<TKey,T> |
||
| 583 | * @psalm-mutation-free |
||
| 584 | */ |
||
| 585 | 4 | public function natcasesortImmutable(): self |
|
| 596 | |||
| 597 | /** |
||
| 598 | * Sort entries using a "natural order" algorithm. |
||
| 599 | * |
||
| 600 | * @return $this |
||
| 601 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 602 | * |
||
| 603 | * @psalm-return static<TKey,T> |
||
| 604 | */ |
||
| 605 | 10 | public function natsort(): self |
|
| 613 | |||
| 614 | /** |
||
| 615 | * Sort entries using a "natural order" algorithm. |
||
| 616 | * |
||
| 617 | * @return $this |
||
| 618 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 619 | * |
||
| 620 | * @psalm-return static<TKey,T> |
||
| 621 | * @psalm-mutation-free |
||
| 622 | */ |
||
| 623 | 4 | public function natsortImmutable(): self |
|
| 634 | |||
| 635 | /** |
||
| 636 | * Whether or not an offset exists. |
||
| 637 | * |
||
| 638 | * @param bool|int|string $offset |
||
| 639 | * |
||
| 640 | * @return bool |
||
| 641 | * |
||
| 642 | * @noinspection PhpSillyAssignmentInspection |
||
| 643 | * |
||
| 644 | * @psalm-mutation-free |
||
| 645 | */ |
||
| 646 | 159 | public function offsetExists($offset): bool |
|
| 708 | |||
| 709 | /** |
||
| 710 | * Returns the value at specified offset. |
||
| 711 | * |
||
| 712 | * @param int|string $offset |
||
| 713 | * |
||
| 714 | * @return mixed |
||
| 715 | * <p>Will return null if the offset did not exists.</p> |
||
| 716 | */ |
||
| 717 | 128 | public function &offsetGet($offset) |
|
| 728 | |||
| 729 | /** |
||
| 730 | * Assigns a value to the specified offset + check the type. |
||
| 731 | * |
||
| 732 | * @param int|string|null $offset |
||
| 733 | * @param mixed $value |
||
| 734 | * |
||
| 735 | * @return void |
||
| 736 | */ |
||
| 737 | 28 | public function offsetSet($offset, $value) |
|
| 755 | |||
| 756 | /** |
||
| 757 | * Unset an offset. |
||
| 758 | * |
||
| 759 | * @param int|string $offset |
||
| 760 | * |
||
| 761 | * @return void |
||
| 762 | * <p>(Mutable) Return nothing.</p> |
||
| 763 | */ |
||
| 764 | 25 | public function offsetUnset($offset) |
|
| 815 | |||
| 816 | /** |
||
| 817 | * Serialize the current "Arrayy"-object. |
||
| 818 | * |
||
| 819 | * EXAMPLE: <code> |
||
| 820 | * a([1, 4, 7])->serialize(); |
||
| 821 | * </code> |
||
| 822 | * |
||
| 823 | * @return string |
||
| 824 | */ |
||
| 825 | 2 | public function serialize(): string |
|
| 835 | |||
| 836 | /** |
||
| 837 | * Sets the iterator classname for the current "Arrayy"-object. |
||
| 838 | * |
||
| 839 | * @param string $iteratorClass |
||
| 840 | * |
||
| 841 | * @throws \InvalidArgumentException |
||
| 842 | * |
||
| 843 | * @return void |
||
| 844 | * |
||
| 845 | * @psalm-param class-string<\Arrayy\ArrayyIterator> $iteratorClass |
||
| 846 | */ |
||
| 847 | 1195 | public function setIteratorClass($iteratorClass) |
|
| 869 | |||
| 870 | /** |
||
| 871 | * Sort the entries with a user-defined comparison function and maintain key association. |
||
| 872 | * |
||
| 873 | * @param callable $function |
||
| 874 | * |
||
| 875 | * @throws \InvalidArgumentException |
||
| 876 | * |
||
| 877 | * @return $this |
||
| 878 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 879 | * |
||
| 880 | * @psalm-return static<TKey,T> |
||
| 881 | */ |
||
| 882 | 8 | View Code Duplication | public function uasort($function): self |
| 894 | |||
| 895 | /** |
||
| 896 | * Sort the entries with a user-defined comparison function and maintain key association. |
||
| 897 | * |
||
| 898 | * @param callable $function |
||
| 899 | * |
||
| 900 | * @throws \InvalidArgumentException |
||
| 901 | * |
||
| 902 | * @return $this |
||
| 903 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 904 | * |
||
| 905 | * @psalm-return static<TKey,T> |
||
| 906 | * @psalm-mutation-free |
||
| 907 | */ |
||
| 908 | 4 | public function uasortImmutable($function): self |
|
| 919 | |||
| 920 | /** |
||
| 921 | * Sort the entries by keys using a user-defined comparison function. |
||
| 922 | * |
||
| 923 | * @param callable $function |
||
| 924 | * |
||
| 925 | * @throws \InvalidArgumentException |
||
| 926 | * |
||
| 927 | * @return static |
||
| 928 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 929 | * |
||
| 930 | * @psalm-return static<TKey,T> |
||
| 931 | */ |
||
| 932 | 5 | public function uksort($function): self |
|
| 936 | |||
| 937 | /** |
||
| 938 | * Sort the entries by keys using a user-defined comparison function. |
||
| 939 | * |
||
| 940 | * @param callable $function |
||
| 941 | * |
||
| 942 | * @throws \InvalidArgumentException |
||
| 943 | * |
||
| 944 | * @return static |
||
| 945 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 946 | * |
||
| 947 | * @psalm-return static<TKey,T> |
||
| 948 | * @psalm-mutation-free |
||
| 949 | */ |
||
| 950 | 1 | public function uksortImmutable($function): self |
|
| 954 | |||
| 955 | /** |
||
| 956 | * Unserialize an string and return the instance of the "Arrayy"-class. |
||
| 957 | * |
||
| 958 | * EXAMPLE: <code> |
||
| 959 | * $serialized = a([1, 4, 7])->serialize(); |
||
| 960 | * a()->unserialize($serialized); |
||
| 961 | * </code> |
||
| 962 | * |
||
| 963 | * @param string $string |
||
| 964 | * |
||
| 965 | * @return $this |
||
| 966 | * |
||
| 967 | * @psalm-return static<TKey,T> |
||
| 968 | */ |
||
| 969 | 2 | public function unserialize($string): self |
|
| 979 | |||
| 980 | /** |
||
| 981 | * Append a (key) + values to the current array. |
||
| 982 | * |
||
| 983 | * EXAMPLE: <code> |
||
| 984 | * a(['fòô' => ['bàř']])->appendArrayValues(['foo1', 'foo2'], 'fòô'); // Arrayy['fòô' => ['bàř', 'foo1', 'foo2']] |
||
| 985 | * </code> |
||
| 986 | * |
||
| 987 | * @param array $values |
||
| 988 | * @param mixed $key |
||
| 989 | * |
||
| 990 | * @return $this |
||
| 991 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
| 992 | * |
||
| 993 | * @psalm-param array<mixed,T> $values |
||
| 994 | * @psalm-param TKey|null $key |
||
| 995 | * @psalm-return static<TKey,T> |
||
| 996 | */ |
||
| 997 | 1 | public function appendArrayValues(array $values, $key = null) |
|
| 1023 | |||
| 1024 | /** |
||
| 1025 | * Add a suffix to each key. |
||
| 1026 | * |
||
| 1027 | * @param mixed $prefix |
||
| 1028 | * |
||
| 1029 | * @return static |
||
| 1030 | * <p>(Immutable) Return an Arrayy object, with the prefixed keys.</p> |
||
| 1031 | * |
||
| 1032 | * @psalm-return static<TKey,T> |
||
| 1033 | * @psalm-mutation-free |
||
| 1034 | */ |
||
| 1035 | 10 | View Code Duplication | public function appendToEachKey($prefix): self |
| 1054 | |||
| 1055 | /** |
||
| 1056 | * Add a prefix to each value. |
||
| 1057 | * |
||
| 1058 | * @param mixed $prefix |
||
| 1059 | * |
||
| 1060 | * @return static |
||
| 1061 | * <p>(Immutable) Return an Arrayy object, with the prefixed values.</p> |
||
| 1062 | * |
||
| 1063 | * @psalm-return static<TKey,T> |
||
| 1064 | * @psalm-mutation-free |
||
| 1065 | */ |
||
| 1066 | 10 | View Code Duplication | public function appendToEachValue($prefix): self |
| 1085 | |||
| 1086 | /** |
||
| 1087 | * Sort an array in reverse order and maintain index association. |
||
| 1088 | * |
||
| 1089 | * @return $this |
||
| 1090 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1091 | * |
||
| 1092 | * @psalm-return static<TKey,T> |
||
| 1093 | */ |
||
| 1094 | 4 | public function arsort(): self |
|
| 1102 | |||
| 1103 | /** |
||
| 1104 | * Sort an array in reverse order and maintain index association. |
||
| 1105 | * |
||
| 1106 | * @return $this |
||
| 1107 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 1108 | * |
||
| 1109 | * @psalm-return static<TKey,T> |
||
| 1110 | * @psalm-mutation-free |
||
| 1111 | */ |
||
| 1112 | 10 | public function arsortImmutable(): self |
|
| 1122 | |||
| 1123 | /** |
||
| 1124 | * Iterate over the current array and execute a callback for each loop. |
||
| 1125 | * |
||
| 1126 | * EXAMPLE: <code> |
||
| 1127 | * $result = A::create(); |
||
| 1128 | * $closure = function ($value, $key) use ($result) { |
||
| 1129 | * $result[$key] = ':' . $value . ':'; |
||
| 1130 | * }; |
||
| 1131 | * a(['foo', 'bar' => 'bis'])->at($closure); // Arrayy[':foo:', 'bar' => ':bis:'] |
||
| 1132 | * </code> |
||
| 1133 | * |
||
| 1134 | * @param \Closure $closure |
||
| 1135 | * |
||
| 1136 | * @return static |
||
| 1137 | * <p>(Immutable)</p> |
||
| 1138 | * |
||
| 1139 | * @psalm-return static<TKey,T> |
||
| 1140 | * @psalm-mutation-free |
||
| 1141 | */ |
||
| 1142 | 3 | public function at(\Closure $closure): self |
|
| 1156 | |||
| 1157 | /** |
||
| 1158 | * Returns the average value of the current array. |
||
| 1159 | * |
||
| 1160 | * EXAMPLE: <code> |
||
| 1161 | * a([-9, -8, -7, 1.32])->average(2); // -5.67 |
||
| 1162 | * </code> |
||
| 1163 | * |
||
| 1164 | * @param int $decimals <p>The number of decimal-numbers to return.</p> |
||
| 1165 | * |
||
| 1166 | * @return float|int |
||
| 1167 | * <p>The average value.</p> |
||
| 1168 | * @psalm-mutation-free |
||
| 1169 | */ |
||
| 1170 | 10 | public function average($decimals = 0) |
|
| 1184 | |||
| 1185 | /** |
||
| 1186 | * Changes all keys in an array. |
||
| 1187 | * |
||
| 1188 | * @param int $case [optional] <p> Either <strong>CASE_UPPER</strong><br /> |
||
| 1189 | * or <strong>CASE_LOWER</strong> (default)</p> |
||
| 1190 | * |
||
| 1191 | * @return static |
||
| 1192 | * <p>(Immutable)</p> |
||
| 1193 | * |
||
| 1194 | * @psalm-return static<TKey,T> |
||
| 1195 | * @psalm-mutation-free |
||
| 1196 | */ |
||
| 1197 | 1 | public function changeKeyCase(int $case = \CASE_LOWER): self |
|
| 1226 | |||
| 1227 | /** |
||
| 1228 | * Change the path separator of the array wrapper. |
||
| 1229 | * |
||
| 1230 | * By default, the separator is: "." |
||
| 1231 | * |
||
| 1232 | * @param string $separator <p>Separator to set.</p> |
||
| 1233 | * |
||
| 1234 | * @return $this |
||
| 1235 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1236 | * |
||
| 1237 | * @psalm-return static<TKey,T> |
||
| 1238 | */ |
||
| 1239 | 11 | public function changeSeparator($separator): self |
|
| 1245 | |||
| 1246 | /** |
||
| 1247 | * Create a chunked version of the current array. |
||
| 1248 | * |
||
| 1249 | * EXAMPLE: <code> |
||
| 1250 | * a([-9, -8, -7, 1.32])->chunk(2); // Arrayy[[-9, -8], [-7, 1.32]] |
||
| 1251 | * </code> |
||
| 1252 | * |
||
| 1253 | * @param int $size <p>Size of each chunk.</p> |
||
| 1254 | * @param bool $preserveKeys <p>Whether array keys are preserved or no.</p> |
||
| 1255 | * |
||
| 1256 | * @return static |
||
| 1257 | * <p>(Immutable) A new array of chunks from the original array.</p> |
||
| 1258 | * |
||
| 1259 | * @psalm-return static<TKey,T> |
||
| 1260 | * @psalm-mutation-free |
||
| 1261 | */ |
||
| 1262 | 5 | public function chunk($size, $preserveKeys = false): self |
|
| 1270 | |||
| 1271 | /** |
||
| 1272 | * Clean all falsy values from the current array. |
||
| 1273 | * |
||
| 1274 | * EXAMPLE: <code> |
||
| 1275 | * a([-8 => -9, 1, 2 => false])->clean(); // Arrayy[-8 => -9, 1] |
||
| 1276 | * </code> |
||
| 1277 | * |
||
| 1278 | * @return static |
||
| 1279 | * <p>(Immutable)</p> |
||
| 1280 | * |
||
| 1281 | * @psalm-return static<TKey,T> |
||
| 1282 | * @psalm-mutation-free |
||
| 1283 | */ |
||
| 1284 | 8 | public function clean(): self |
|
| 1292 | |||
| 1293 | /** |
||
| 1294 | * WARNING!!! -> Clear the current full array or a $key of it. |
||
| 1295 | * |
||
| 1296 | * EXAMPLE: <code> |
||
| 1297 | * a([-8 => -9, 1, 2 => false])->clear(); // Arrayy[] |
||
| 1298 | * </code> |
||
| 1299 | * |
||
| 1300 | * @param int|int[]|string|string[]|null $key |
||
| 1301 | * |
||
| 1302 | * @return $this |
||
| 1303 | * <p>(Mutable) Return this Arrayy object, with an empty array.</p> |
||
| 1304 | * |
||
| 1305 | * @psalm-return static<TKey,T> |
||
| 1306 | */ |
||
| 1307 | 10 | public function clear($key = null): self |
|
| 1326 | |||
| 1327 | /** |
||
| 1328 | * Check if an item is in the current array. |
||
| 1329 | * |
||
| 1330 | * EXAMPLE: <code> |
||
| 1331 | * a([1, true])->contains(true); // true |
||
| 1332 | * </code> |
||
| 1333 | * |
||
| 1334 | * @param float|int|string $value |
||
| 1335 | * @param bool $recursive |
||
| 1336 | * @param bool $strict |
||
| 1337 | * |
||
| 1338 | * @return bool |
||
| 1339 | * @psalm-mutation-free |
||
| 1340 | */ |
||
| 1341 | 24 | public function contains($value, bool $recursive = false, bool $strict = true): bool |
|
| 1342 | { |
||
| 1343 | 24 | if ($recursive === true) { |
|
| 1344 | 19 | return $this->in_array_recursive($value, $this->toArray(), $strict); |
|
| 1345 | } |
||
| 1346 | |||
| 1347 | /** @noinspection PhpParameterByRefIsNotUsedAsReferenceInspection */ |
||
| 1348 | 14 | foreach ($this->getGeneratorByReference() as &$valueFromArray) { |
|
| 1349 | 11 | if ($strict) { |
|
| 1350 | 11 | if ($value === $valueFromArray) { |
|
| 1351 | 11 | return true; |
|
| 1352 | } |
||
| 1353 | } else { |
||
| 1354 | /** @noinspection NestedPositiveIfStatementsInspection */ |
||
| 1355 | if ($value == $valueFromArray) { |
||
| 1356 | 7 | return true; |
|
| 1357 | } |
||
| 1358 | } |
||
| 1359 | } |
||
| 1360 | |||
| 1361 | 7 | return false; |
|
| 1362 | } |
||
| 1363 | |||
| 1364 | /** |
||
| 1365 | * Check if an (case-insensitive) string is in the current array. |
||
| 1366 | * |
||
| 1367 | * EXAMPLE: <code> |
||
| 1368 | * a(['E', 'é'])->containsCaseInsensitive('É'); // true |
||
| 1369 | * </code> |
||
| 1370 | * |
||
| 1371 | * @param mixed $value |
||
| 1372 | * @param bool $recursive |
||
| 1373 | * |
||
| 1374 | * @return bool |
||
| 1375 | * @psalm-mutation-free |
||
| 1376 | * |
||
| 1377 | * @psalm-suppress InvalidCast - hack for int|float|bool support |
||
| 1378 | */ |
||
| 1379 | 26 | public function containsCaseInsensitive($value, $recursive = false): bool |
|
| 1410 | |||
| 1411 | /** |
||
| 1412 | * Check if the given key/index exists in the array. |
||
| 1413 | * |
||
| 1414 | * EXAMPLE: <code> |
||
| 1415 | * a([1 => true])->containsKey(1); // true |
||
| 1416 | * </code> |
||
| 1417 | * |
||
| 1418 | * @param int|string $key <p>key/index to search for</p> |
||
| 1419 | * |
||
| 1420 | * @return bool |
||
| 1421 | * <p>Returns true if the given key/index exists in the array, false otherwise.</p> |
||
| 1422 | * |
||
| 1423 | * @psalm-mutation-free |
||
| 1424 | */ |
||
| 1425 | 4 | public function containsKey($key): bool |
|
| 1429 | |||
| 1430 | /** |
||
| 1431 | * Check if all given needles are present in the array as key/index. |
||
| 1432 | * |
||
| 1433 | * EXAMPLE: <code> |
||
| 1434 | * a([1 => true])->containsKeys(array(1 => 0)); // true |
||
| 1435 | * </code> |
||
| 1436 | * |
||
| 1437 | * @param array $needles <p>The keys you are searching for.</p> |
||
| 1438 | * @param bool $recursive |
||
| 1439 | * |
||
| 1440 | * @return bool |
||
| 1441 | * <p>Returns true if all the given keys/indexes exists in the array, false otherwise.</p> |
||
| 1442 | * |
||
| 1443 | * @psalm-param array<mixed,mixed>|array<TKey> $needles |
||
| 1444 | * @psalm-mutation-free |
||
| 1445 | */ |
||
| 1446 | 2 | public function containsKeys(array $needles, $recursive = false): bool |
|
| 1474 | |||
| 1475 | /** |
||
| 1476 | * Check if all given needles are present in the array as key/index. |
||
| 1477 | * |
||
| 1478 | * @param array $needles <p>The keys you are searching for.</p> |
||
| 1479 | * |
||
| 1480 | * @return bool |
||
| 1481 | * <p>Returns true if all the given keys/indexes exists in the array, false otherwise.</p> |
||
| 1482 | * |
||
| 1483 | * @psalm-param array<mixed,mixed>|array<TKey> $needles |
||
| 1484 | * @psalm-mutation-free |
||
| 1485 | */ |
||
| 1486 | 1 | public function containsKeysRecursive(array $needles): bool |
|
| 1490 | |||
| 1491 | /** |
||
| 1492 | * alias: for "Arrayy->contains()" |
||
| 1493 | * |
||
| 1494 | * @param float|int|string $value |
||
| 1495 | * |
||
| 1496 | * @return bool |
||
| 1497 | * |
||
| 1498 | * @see Arrayy::contains() |
||
| 1499 | * @psalm-mutation-free |
||
| 1500 | */ |
||
| 1501 | 9 | public function containsValue($value): bool |
|
| 1505 | |||
| 1506 | /** |
||
| 1507 | * alias: for "Arrayy->contains($value, true)" |
||
| 1508 | * |
||
| 1509 | * @param float|int|string $value |
||
| 1510 | * |
||
| 1511 | * @return bool |
||
| 1512 | * |
||
| 1513 | * @see Arrayy::contains() |
||
| 1514 | * @psalm-mutation-free |
||
| 1515 | */ |
||
| 1516 | 18 | public function containsValueRecursive($value): bool |
|
| 1520 | |||
| 1521 | /** |
||
| 1522 | * Check if all given needles are present in the array. |
||
| 1523 | * |
||
| 1524 | * EXAMPLE: <code> |
||
| 1525 | * a([1, true])->containsValues(array(1, true)); // true |
||
| 1526 | * </code> |
||
| 1527 | * |
||
| 1528 | * @param array $needles |
||
| 1529 | * |
||
| 1530 | * @return bool |
||
| 1531 | * <p>Returns true if all the given values exists in the array, false otherwise.</p> |
||
| 1532 | * |
||
| 1533 | * @psalm-param array<mixed>|array<T> $needles |
||
| 1534 | * @psalm-mutation-free |
||
| 1535 | */ |
||
| 1536 | 1 | public function containsValues(array $needles): bool |
|
| 1551 | |||
| 1552 | /** |
||
| 1553 | * Counts all the values of an array |
||
| 1554 | * |
||
| 1555 | * @see http://php.net/manual/en/function.array-count-values.php |
||
| 1556 | * |
||
| 1557 | * @return static |
||
| 1558 | * <p> |
||
| 1559 | * (Immutable) |
||
| 1560 | * An associative Arrayy-object of values from input as |
||
| 1561 | * keys and their count as value. |
||
| 1562 | * </p> |
||
| 1563 | * |
||
| 1564 | * @psalm-return static<TKey,T> |
||
| 1565 | * @psalm-mutation-free |
||
| 1566 | */ |
||
| 1567 | 7 | public function countValues(): self |
|
| 1571 | |||
| 1572 | /** |
||
| 1573 | * Creates an Arrayy object. |
||
| 1574 | * |
||
| 1575 | * @param mixed $data |
||
| 1576 | * @param string $iteratorClass |
||
| 1577 | * @param bool $checkPropertiesInConstructor |
||
| 1578 | * |
||
| 1579 | * @return static |
||
| 1580 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1581 | * |
||
| 1582 | * @psalm-param class-string<\Arrayy\ArrayyIterator> $iteratorClass |
||
| 1583 | * |
||
| 1584 | * @psalm-mutation-free |
||
| 1585 | */ |
||
| 1586 | 723 | public static function create( |
|
| 1597 | |||
| 1598 | /** |
||
| 1599 | * Flatten an array with the given character as a key delimiter |
||
| 1600 | * |
||
| 1601 | * @param string $delimiter |
||
| 1602 | * @param string $prepend |
||
| 1603 | * @param array|null $items |
||
| 1604 | * |
||
| 1605 | * @return array |
||
| 1606 | */ |
||
| 1607 | 2 | public function flatten($delimiter = '.', $prepend = '', $items = null) |
|
| 1630 | |||
| 1631 | /** |
||
| 1632 | * WARNING: Creates an Arrayy object by reference. |
||
| 1633 | * |
||
| 1634 | * @param array $array |
||
| 1635 | * |
||
| 1636 | * @return $this |
||
| 1637 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1638 | * |
||
| 1639 | * @psalm-param array<mixed,mixed>|array<array-key,mixed> $array |
||
| 1640 | */ |
||
| 1641 | 27 | public function createByReference(array &$array = []): self |
|
| 1649 | |||
| 1650 | /** |
||
| 1651 | * Create an new instance from a callable function which will return an Generator. |
||
| 1652 | * |
||
| 1653 | * @param callable $generatorFunction |
||
| 1654 | * |
||
| 1655 | * @return static |
||
| 1656 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1657 | * |
||
| 1658 | * @psalm-param callable():\Generator<array-key,mixed> $generatorFunction |
||
| 1659 | * |
||
| 1660 | * @psalm-mutation-free |
||
| 1661 | */ |
||
| 1662 | 7 | public static function createFromGeneratorFunction(callable $generatorFunction): self |
|
| 1666 | |||
| 1667 | /** |
||
| 1668 | * Create an new instance filled with a copy of values from a "Generator"-object. |
||
| 1669 | * |
||
| 1670 | * @param \Generator $generator |
||
| 1671 | * |
||
| 1672 | * @return static |
||
| 1673 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1674 | * |
||
| 1675 | * @psalm-param \Generator<array-key,mixed> $generator |
||
| 1676 | * |
||
| 1677 | * @psalm-mutation-free |
||
| 1678 | */ |
||
| 1679 | 4 | public static function createFromGeneratorImmutable(\Generator $generator): self |
|
| 1683 | |||
| 1684 | /** |
||
| 1685 | * Create an new Arrayy object via JSON. |
||
| 1686 | * |
||
| 1687 | * @param string $json |
||
| 1688 | * |
||
| 1689 | * @return static |
||
| 1690 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1691 | * |
||
| 1692 | * @psalm-mutation-free |
||
| 1693 | */ |
||
| 1694 | 5 | public static function createFromJson(string $json): self |
|
| 1698 | |||
| 1699 | /** |
||
| 1700 | * Create an new Arrayy object via JSON. |
||
| 1701 | * |
||
| 1702 | * @param array $array |
||
| 1703 | * |
||
| 1704 | * @return static |
||
| 1705 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1706 | * |
||
| 1707 | * @psalm-mutation-free |
||
| 1708 | */ |
||
| 1709 | 1 | public static function createFromArray(array $array): self |
|
| 1713 | |||
| 1714 | /** |
||
| 1715 | * Create an new instance filled with values from an object that is iterable. |
||
| 1716 | * |
||
| 1717 | * @param \Traversable $object <p>iterable object</p> |
||
| 1718 | * |
||
| 1719 | * @return static |
||
| 1720 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1721 | * |
||
| 1722 | * @psalm-param \Traversable<array-key,mixed> $object |
||
| 1723 | * |
||
| 1724 | * @psalm-mutation-free |
||
| 1725 | */ |
||
| 1726 | 4 | public static function createFromObject(\Traversable $object): self |
|
| 1746 | |||
| 1747 | /** |
||
| 1748 | * Create an new instance filled with values from an object. |
||
| 1749 | * |
||
| 1750 | * @param object $object |
||
| 1751 | * |
||
| 1752 | * @return static |
||
| 1753 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1754 | * |
||
| 1755 | * @psalm-mutation-free |
||
| 1756 | */ |
||
| 1757 | 5 | public static function createFromObjectVars($object): self |
|
| 1761 | |||
| 1762 | /** |
||
| 1763 | * Create an new Arrayy object via string. |
||
| 1764 | * |
||
| 1765 | * @param string $str <p>The input string.</p> |
||
| 1766 | * @param string|null $delimiter <p>The boundary string.</p> |
||
| 1767 | * @param string|null $regEx <p>Use the $delimiter or the $regEx, so if $pattern is null, $delimiter will be |
||
| 1768 | * used.</p> |
||
| 1769 | * |
||
| 1770 | * @return static |
||
| 1771 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1772 | * |
||
| 1773 | * @psalm-mutation-free |
||
| 1774 | */ |
||
| 1775 | 10 | public static function createFromString(string $str, string $delimiter = null, string $regEx = null): self |
|
| 1807 | |||
| 1808 | /** |
||
| 1809 | * Create an new instance filled with a copy of values from a "Traversable"-object. |
||
| 1810 | * |
||
| 1811 | * @param \Traversable $traversable |
||
| 1812 | * |
||
| 1813 | * @return static |
||
| 1814 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1815 | * |
||
| 1816 | * @psalm-param \Traversable<array-key,mixed> $traversable |
||
| 1817 | * |
||
| 1818 | * @psalm-mutation-free |
||
| 1819 | */ |
||
| 1820 | 1 | public static function createFromTraversableImmutable(\Traversable $traversable): self |
|
| 1824 | |||
| 1825 | /** |
||
| 1826 | * Create an new instance containing a range of elements. |
||
| 1827 | * |
||
| 1828 | * @param float|int|string $low <p>First value of the sequence.</p> |
||
| 1829 | * @param float|int|string $high <p>The sequence is ended upon reaching the end value.</p> |
||
| 1830 | * @param float|int $step <p>Used as the increment between elements in the sequence.</p> |
||
| 1831 | * |
||
| 1832 | * @return static |
||
| 1833 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1834 | * |
||
| 1835 | * @psalm-mutation-free |
||
| 1836 | */ |
||
| 1837 | 2 | public static function createWithRange($low, $high, $step = 1): self |
|
| 1841 | |||
| 1842 | /** |
||
| 1843 | * Gets the element of the array at the current internal iterator position. |
||
| 1844 | * |
||
| 1845 | * @return false|mixed |
||
| 1846 | */ |
||
| 1847 | public function current() |
||
| 1851 | |||
| 1852 | /** |
||
| 1853 | * Custom sort by index via "uksort". |
||
| 1854 | * |
||
| 1855 | * EXAMPLE: <code> |
||
| 1856 | * $callable = function ($a, $b) { |
||
| 1857 | * if ($a == $b) { |
||
| 1858 | * return 0; |
||
| 1859 | * } |
||
| 1860 | * return ($a > $b) ? 1 : -1; |
||
| 1861 | * }; |
||
| 1862 | * $arrayy = a(['three' => 3, 'one' => 1, 'two' => 2]); |
||
| 1863 | * $resultArrayy = $arrayy->customSortKeys($callable); // Arrayy['one' => 1, 'three' => 3, 'two' => 2] |
||
| 1864 | * </code> |
||
| 1865 | * |
||
| 1866 | * @see http://php.net/manual/en/function.uksort.php |
||
| 1867 | * |
||
| 1868 | * @param callable $function |
||
| 1869 | * |
||
| 1870 | * @throws \InvalidArgumentException |
||
| 1871 | * |
||
| 1872 | * @return $this |
||
| 1873 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1874 | * |
||
| 1875 | * @psalm-return static<TKey,T> |
||
| 1876 | */ |
||
| 1877 | 5 | public function customSortKeys(callable $function): self |
|
| 1885 | |||
| 1886 | /** |
||
| 1887 | * Custom sort by index via "uksort". |
||
| 1888 | * |
||
| 1889 | * @see http://php.net/manual/en/function.uksort.php |
||
| 1890 | * |
||
| 1891 | * @param callable $function |
||
| 1892 | * |
||
| 1893 | * @throws \InvalidArgumentException |
||
| 1894 | * |
||
| 1895 | * @return $this |
||
| 1896 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 1897 | * |
||
| 1898 | * @psalm-return static<TKey,T> |
||
| 1899 | * @psalm-mutation-free |
||
| 1900 | */ |
||
| 1901 | 1 | public function customSortKeysImmutable(callable $function): self |
|
| 1914 | |||
| 1915 | /** |
||
| 1916 | * Custom sort by value via "usort". |
||
| 1917 | * |
||
| 1918 | * EXAMPLE: <code> |
||
| 1919 | * $callable = function ($a, $b) { |
||
| 1920 | * if ($a == $b) { |
||
| 1921 | * return 0; |
||
| 1922 | * } |
||
| 1923 | * return ($a > $b) ? 1 : -1; |
||
| 1924 | * }; |
||
| 1925 | * $arrayy = a(['three' => 3, 'one' => 1, 'two' => 2]); |
||
| 1926 | * $resultArrayy = $arrayy->customSortValues($callable); // Arrayy['one' => 1, 'two' => 2, 'three' => 3] |
||
| 1927 | * </code> |
||
| 1928 | * |
||
| 1929 | * @see http://php.net/manual/en/function.usort.php |
||
| 1930 | * |
||
| 1931 | * @param callable $function |
||
| 1932 | * |
||
| 1933 | * @throws \InvalidArgumentException |
||
| 1934 | * |
||
| 1935 | * @return $this |
||
| 1936 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1937 | * |
||
| 1938 | * @psalm-return static<TKey,T> |
||
| 1939 | */ |
||
| 1940 | 10 | View Code Duplication | public function customSortValues($function): self |
| 1952 | |||
| 1953 | /** |
||
| 1954 | * Custom sort by value via "usort". |
||
| 1955 | * |
||
| 1956 | * @see http://php.net/manual/en/function.usort.php |
||
| 1957 | * |
||
| 1958 | * @param callable $function |
||
| 1959 | * |
||
| 1960 | * @throws \InvalidArgumentException |
||
| 1961 | * |
||
| 1962 | * @return $this |
||
| 1963 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 1964 | * |
||
| 1965 | * @psalm-return static<TKey,T> |
||
| 1966 | * @psalm-mutation-free |
||
| 1967 | */ |
||
| 1968 | 4 | public function customSortValuesImmutable($function): self |
|
| 1979 | |||
| 1980 | /** |
||
| 1981 | * Delete the given key or keys. |
||
| 1982 | * |
||
| 1983 | * @param int|int[]|string|string[] $keyOrKeys |
||
| 1984 | * |
||
| 1985 | * @return void |
||
| 1986 | */ |
||
| 1987 | 9 | public function delete($keyOrKeys) |
|
| 1995 | |||
| 1996 | /** |
||
| 1997 | * Return values that are only in the current array. |
||
| 1998 | * |
||
| 1999 | * EXAMPLE: <code> |
||
| 2000 | * a([1 => 1, 2 => 2])->diff([1 => 1]); // Arrayy[2 => 2] |
||
| 2001 | * </code> |
||
| 2002 | * |
||
| 2003 | * @param array ...$array |
||
| 2004 | * |
||
| 2005 | * @return static |
||
| 2006 | * <p>(Immutable)</p> |
||
| 2007 | * |
||
| 2008 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$array |
||
| 2009 | * @psalm-return static<TKey,T> |
||
| 2010 | * @psalm-mutation-free |
||
| 2011 | */ |
||
| 2012 | 13 | public function diff(...$array): self |
|
| 2020 | |||
| 2021 | /** |
||
| 2022 | * Return values that are only in the current array. |
||
| 2023 | * |
||
| 2024 | * @param array ...$array |
||
| 2025 | * |
||
| 2026 | * @return static |
||
| 2027 | * <p>(Immutable)</p> |
||
| 2028 | * |
||
| 2029 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$array |
||
| 2030 | * @psalm-return static<TKey,T> |
||
| 2031 | * @psalm-mutation-free |
||
| 2032 | */ |
||
| 2033 | 8 | public function diffKey(...$array): self |
|
| 2041 | |||
| 2042 | /** |
||
| 2043 | * Return values and Keys that are only in the current array. |
||
| 2044 | * |
||
| 2045 | * @param array $array |
||
| 2046 | * |
||
| 2047 | * @return static |
||
| 2048 | * <p>(Immutable)</p> |
||
| 2049 | * |
||
| 2050 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 2051 | * @psalm-return static<TKey,T> |
||
| 2052 | * @psalm-mutation-free |
||
| 2053 | */ |
||
| 2054 | 8 | public function diffKeyAndValue(array $array = []): self |
|
| 2062 | |||
| 2063 | /** |
||
| 2064 | * Return values that are only in the current multi-dimensional array. |
||
| 2065 | * |
||
| 2066 | * EXAMPLE: <code> |
||
| 2067 | * a([1 => [1 => 1], 2 => [2 => 2]])->diffRecursive([1 => [1 => 1]]); // Arrayy[2 => [2 => 2]] |
||
| 2068 | * </code> |
||
| 2069 | * |
||
| 2070 | * @param array $array |
||
| 2071 | * @param array|\Generator|null $helperVariableForRecursion <p>(only for internal usage)</p> |
||
| 2072 | * |
||
| 2073 | * @return static |
||
| 2074 | * <p>(Immutable)</p> |
||
| 2075 | * |
||
| 2076 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 2077 | * @psalm-param null|array<TKey,T>|\Generator<TKey,T> $helperVariableForRecursion |
||
| 2078 | * @psalm-return static<TKey,T> |
||
| 2079 | * @psalm-mutation-free |
||
| 2080 | */ |
||
| 2081 | 1 | public function diffRecursive(array $array = [], $helperVariableForRecursion = null): self |
|
| 2116 | |||
| 2117 | /** |
||
| 2118 | * Return values that are only in the new $array. |
||
| 2119 | * |
||
| 2120 | * EXAMPLE: <code> |
||
| 2121 | * a([1 => 1])->diffReverse([1 => 1, 2 => 2]); // Arrayy[2 => 2] |
||
| 2122 | * </code> |
||
| 2123 | * |
||
| 2124 | * @param array $array |
||
| 2125 | * |
||
| 2126 | * @return static |
||
| 2127 | * <p>(Immutable)</p> |
||
| 2128 | * |
||
| 2129 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 2130 | * @psalm-return static<TKey,T> |
||
| 2131 | * @psalm-mutation-free |
||
| 2132 | */ |
||
| 2133 | 8 | public function diffReverse(array $array = []): self |
|
| 2141 | |||
| 2142 | /** |
||
| 2143 | * Divide an array into two arrays. One with keys and the other with values. |
||
| 2144 | * |
||
| 2145 | * EXAMPLE: <code> |
||
| 2146 | * a(['a' => 1, 'b' => ''])->divide(); // Arrayy[Arrayy['a', 'b'], Arrayy[1, '']] |
||
| 2147 | * </code> |
||
| 2148 | * |
||
| 2149 | * @return static |
||
| 2150 | * <p>(Immutable)</p> |
||
| 2151 | * |
||
| 2152 | * @psalm-return static<TKey,T> |
||
| 2153 | * @psalm-mutation-free |
||
| 2154 | */ |
||
| 2155 | 1 | public function divide(): self |
|
| 2166 | |||
| 2167 | /** |
||
| 2168 | * Iterate over the current array and modify the array's value. |
||
| 2169 | * |
||
| 2170 | * EXAMPLE: <code> |
||
| 2171 | * $result = A::create(); |
||
| 2172 | * $closure = function ($value) { |
||
| 2173 | * return ':' . $value . ':'; |
||
| 2174 | * }; |
||
| 2175 | * a(['foo', 'bar' => 'bis'])->each($closure); // Arrayy[':foo:', 'bar' => ':bis:'] |
||
| 2176 | * </code> |
||
| 2177 | * |
||
| 2178 | * @param \Closure $closure |
||
| 2179 | * |
||
| 2180 | * @return static |
||
| 2181 | * <p>(Immutable)</p> |
||
| 2182 | * |
||
| 2183 | * @psalm-return static<TKey,T> |
||
| 2184 | * @psalm-mutation-free |
||
| 2185 | */ |
||
| 2186 | 5 | View Code Duplication | public function each(\Closure $closure): self |
| 2201 | |||
| 2202 | /** |
||
| 2203 | * Sets the internal iterator to the last element in the array and returns this element. |
||
| 2204 | * |
||
| 2205 | * @return mixed |
||
| 2206 | */ |
||
| 2207 | public function end() |
||
| 2211 | |||
| 2212 | /** |
||
| 2213 | * Check if a value is in the current array using a closure. |
||
| 2214 | * |
||
| 2215 | * EXAMPLE: <code> |
||
| 2216 | * $callable = function ($value, $key) { |
||
| 2217 | * return 2 === $key and 'two' === $value; |
||
| 2218 | * }; |
||
| 2219 | * a(['foo', 2 => 'two'])->exists($callable); // true |
||
| 2220 | * </code> |
||
| 2221 | * |
||
| 2222 | * @param \Closure $closure |
||
| 2223 | * |
||
| 2224 | * @return bool |
||
| 2225 | * <p>Returns true if the given value is found, false otherwise.</p> |
||
| 2226 | */ |
||
| 2227 | 4 | public function exists(\Closure $closure): bool |
|
| 2242 | |||
| 2243 | /** |
||
| 2244 | * Fill the array until "$num" with "$default" values. |
||
| 2245 | * |
||
| 2246 | * EXAMPLE: <code> |
||
| 2247 | * a(['bar'])->fillWithDefaults(3, 'foo'); // Arrayy['bar', 'foo', 'foo'] |
||
| 2248 | * </code> |
||
| 2249 | * |
||
| 2250 | * @param int $num |
||
| 2251 | * @param mixed $default |
||
| 2252 | * |
||
| 2253 | * @return static |
||
| 2254 | * <p>(Immutable)</p> |
||
| 2255 | * |
||
| 2256 | * @psalm-return static<TKey,T> |
||
| 2257 | * @psalm-mutation-free |
||
| 2258 | */ |
||
| 2259 | 8 | public function fillWithDefaults(int $num, $default = null): self |
|
| 2282 | |||
| 2283 | /** |
||
| 2284 | * Find all items in an array that pass the truth test. |
||
| 2285 | * |
||
| 2286 | * EXAMPLE: <code> |
||
| 2287 | * $closure = function ($value) { |
||
| 2288 | * return $value % 2 !== 0; |
||
| 2289 | * } |
||
| 2290 | * a([1, 2, 3, 4])->filter($closure); // Arrayy[0 => 1, 2 => 3] |
||
| 2291 | * </code> |
||
| 2292 | * |
||
| 2293 | * @param \Closure|null $closure [optional] <p> |
||
| 2294 | * The callback function to use |
||
| 2295 | * </p> |
||
| 2296 | * <p> |
||
| 2297 | * If no callback is supplied, all entries of |
||
| 2298 | * input equal to false (see |
||
| 2299 | * converting to |
||
| 2300 | * boolean) will be removed. |
||
| 2301 | * </p> |
||
| 2302 | * @param int $flag [optional] <p> |
||
| 2303 | * Flag determining what arguments are sent to <i>callback</i>: |
||
| 2304 | * </p> |
||
| 2305 | * <ul> |
||
| 2306 | * <li> |
||
| 2307 | * <b>ARRAY_FILTER_USE_KEY</b> (1) - pass key as the only argument |
||
| 2308 | * to <i>callback</i> instead of the value |
||
| 2309 | * </li> |
||
| 2310 | * <li> |
||
| 2311 | * <b>ARRAY_FILTER_USE_BOTH</b> (2) - pass both value and key as |
||
| 2312 | * arguments to <i>callback</i> instead of the value |
||
| 2313 | * </li> |
||
| 2314 | * </ul> |
||
| 2315 | * |
||
| 2316 | * @return static |
||
| 2317 | * <p>(Immutable)</p> |
||
| 2318 | * |
||
| 2319 | * @psalm-param null|\Closure(T=,TKey=):bool|\Closure(T=):bool||\Closure(TKey=):bool $closure |
||
| 2320 | * @psalm-return static<TKey,T> |
||
| 2321 | * @psalm-mutation-free |
||
| 2322 | */ |
||
| 2323 | 12 | public function filter($closure = null, int $flag = \ARRAY_FILTER_USE_BOTH) |
|
| 2361 | |||
| 2362 | /** |
||
| 2363 | * Filters an array of objects (or a numeric array of associative arrays) based on the value of a particular |
||
| 2364 | * property within that. |
||
| 2365 | * |
||
| 2366 | * @param string $property |
||
| 2367 | * @param string|string[] $value |
||
| 2368 | * @param string $comparisonOp |
||
| 2369 | * <p> |
||
| 2370 | * 'eq' (equals),<br /> |
||
| 2371 | * 'gt' (greater),<br /> |
||
| 2372 | * 'gte' || 'ge' (greater or equals),<br /> |
||
| 2373 | * 'lt' (less),<br /> |
||
| 2374 | * 'lte' || 'le' (less or equals),<br /> |
||
| 2375 | * 'ne' (not equals),<br /> |
||
| 2376 | * 'contains',<br /> |
||
| 2377 | * 'notContains',<br /> |
||
| 2378 | * 'newer' (via strtotime),<br /> |
||
| 2379 | * 'older' (via strtotime),<br /> |
||
| 2380 | * </p> |
||
| 2381 | * |
||
| 2382 | * @return static |
||
| 2383 | * <p>(Immutable)</p> |
||
| 2384 | * |
||
| 2385 | * @psalm-return static<TKey,T> |
||
| 2386 | * @psalm-mutation-free |
||
| 2387 | * |
||
| 2388 | * @psalm-suppress MissingClosureReturnType |
||
| 2389 | * @psalm-suppress MissingClosureParamType |
||
| 2390 | */ |
||
| 2391 | 1 | public function filterBy( |
|
| 2463 | |||
| 2464 | /** |
||
| 2465 | * Find the first item in an array that passes the truth test, otherwise return false. |
||
| 2466 | * |
||
| 2467 | * EXAMPLE: <code> |
||
| 2468 | * $search = 'foo'; |
||
| 2469 | * $closure = function ($value, $key) use ($search) { |
||
| 2470 | * return $value === $search; |
||
| 2471 | * }; |
||
| 2472 | * a(['foo', 'bar', 'lall'])->find($closure); // 'foo' |
||
| 2473 | * </code> |
||
| 2474 | * |
||
| 2475 | * @param \Closure $closure |
||
| 2476 | * |
||
| 2477 | * @return false|mixed |
||
| 2478 | * <p>Return false if we did not find the value.</p> |
||
| 2479 | */ |
||
| 2480 | 8 | View Code Duplication | public function find(\Closure $closure) |
| 2490 | |||
| 2491 | /** |
||
| 2492 | * find by ... |
||
| 2493 | * |
||
| 2494 | * EXAMPLE: <code> |
||
| 2495 | * $array = [ |
||
| 2496 | * 0 => ['id' => 123, 'name' => 'foo', 'group' => 'primary', 'value' => 123456, 'when' => '2014-01-01'], |
||
| 2497 | * 1 => ['id' => 456, 'name' => 'bar', 'group' => 'primary', 'value' => 1468, 'when' => '2014-07-15'], |
||
| 2498 | * ]; |
||
| 2499 | * a($array)->filterBy('name', 'foo'); // Arrayy[0 => ['id' => 123, 'name' => 'foo', 'group' => 'primary', 'value' => 123456, 'when' => '2014-01-01']] |
||
| 2500 | * </code> |
||
| 2501 | * |
||
| 2502 | * @param string $property |
||
| 2503 | * @param string|string[] $value |
||
| 2504 | * @param string $comparisonOp |
||
| 2505 | * |
||
| 2506 | * @return static |
||
| 2507 | * <p>(Immutable)</p> |
||
| 2508 | * |
||
| 2509 | * @psalm-return static<TKey,T> |
||
| 2510 | * @psalm-mutation-free |
||
| 2511 | */ |
||
| 2512 | 1 | public function findBy(string $property, $value, string $comparisonOp = 'eq'): self |
|
| 2516 | |||
| 2517 | /** |
||
| 2518 | * Get the first value from the current array. |
||
| 2519 | * |
||
| 2520 | * EXAMPLE: <code> |
||
| 2521 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->first(); // 'foo' |
||
| 2522 | * </code> |
||
| 2523 | * |
||
| 2524 | * @return mixed |
||
| 2525 | * <p>Return null if there wasn't a element.</p> |
||
| 2526 | */ |
||
| 2527 | 23 | public function first() |
|
| 2536 | |||
| 2537 | /** |
||
| 2538 | * Get the first key from the current array. |
||
| 2539 | * |
||
| 2540 | * @return mixed |
||
| 2541 | * <p>Return null if there wasn't a element.</p> |
||
| 2542 | * @psalm-mutation-free |
||
| 2543 | */ |
||
| 2544 | 30 | public function firstKey() |
|
| 2550 | |||
| 2551 | /** |
||
| 2552 | * Get the first value(s) from the current array. |
||
| 2553 | * And will return an empty array if there was no first entry. |
||
| 2554 | * |
||
| 2555 | * EXAMPLE: <code> |
||
| 2556 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->firstsImmutable(2); // Arrayy[0 => 'foo', 1 => 'bar'] |
||
| 2557 | * </code> |
||
| 2558 | * |
||
| 2559 | * @param int|null $number <p>How many values you will take?</p> |
||
| 2560 | * |
||
| 2561 | * @return static |
||
| 2562 | * <p>(Immutable)</p> |
||
| 2563 | * |
||
| 2564 | * @psalm-return static<TKey,T> |
||
| 2565 | * @psalm-mutation-free |
||
| 2566 | */ |
||
| 2567 | 37 | View Code Duplication | public function firstsImmutable(int $number = null): self |
| 2583 | |||
| 2584 | /** |
||
| 2585 | * Get the first value(s) from the current array. |
||
| 2586 | * And will return an empty array if there was no first entry. |
||
| 2587 | * |
||
| 2588 | * @param int|null $number <p>How many values you will take?</p> |
||
| 2589 | * |
||
| 2590 | * @return static |
||
| 2591 | * <p>(Immutable)</p> |
||
| 2592 | * |
||
| 2593 | * @psalm-return static<TKey,T> |
||
| 2594 | * @psalm-mutation-free |
||
| 2595 | */ |
||
| 2596 | 3 | View Code Duplication | public function firstsKeys(int $number = null): self |
| 2612 | |||
| 2613 | /** |
||
| 2614 | * Get and remove the first value(s) from the current array. |
||
| 2615 | * And will return an empty array if there was no first entry. |
||
| 2616 | * |
||
| 2617 | * EXAMPLE: <code> |
||
| 2618 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->firstsMutable(); // 'foo' |
||
| 2619 | * </code> |
||
| 2620 | * |
||
| 2621 | * @param int|null $number <p>How many values you will take?</p> |
||
| 2622 | * |
||
| 2623 | * @return $this |
||
| 2624 | * <p>(Mutable)</p> |
||
| 2625 | * |
||
| 2626 | * @psalm-return static<TKey,T> |
||
| 2627 | */ |
||
| 2628 | 34 | public function firstsMutable(int $number = null): self |
|
| 2640 | |||
| 2641 | /** |
||
| 2642 | * Exchanges all keys with their associated values in an array. |
||
| 2643 | * |
||
| 2644 | * EXAMPLE: <code> |
||
| 2645 | * a([0 => 'foo', 1 => 'bar'])->flip(); // Arrayy['foo' => 0, 'bar' => 1] |
||
| 2646 | * </code> |
||
| 2647 | * |
||
| 2648 | * @return static |
||
| 2649 | * <p>(Immutable)</p> |
||
| 2650 | * |
||
| 2651 | * @psalm-return static<array-key,TKey> |
||
| 2652 | * @psalm-mutation-free |
||
| 2653 | */ |
||
| 2654 | 1 | public function flip(): self |
|
| 2668 | |||
| 2669 | /** |
||
| 2670 | * Get a value from an array (optional using dot-notation). |
||
| 2671 | * |
||
| 2672 | * EXAMPLE: <code> |
||
| 2673 | * $arrayy = a(['user' => ['lastname' => 'Moelleken']]); |
||
| 2674 | * $arrayy->get('user.lastname'); // 'Moelleken' |
||
| 2675 | * // --- |
||
| 2676 | * $arrayy = new A(); |
||
| 2677 | * $arrayy['user'] = ['lastname' => 'Moelleken']; |
||
| 2678 | * $arrayy['user.firstname'] = 'Lars'; |
||
| 2679 | * $arrayy['user']['lastname']; // Moelleken |
||
| 2680 | * $arrayy['user.lastname']; // Moelleken |
||
| 2681 | * $arrayy['user.firstname']; // Lars |
||
| 2682 | * </code> |
||
| 2683 | * |
||
| 2684 | * @param mixed $key <p>The key to look for.</p> |
||
| 2685 | * @param mixed $fallback <p>Value to fallback to.</p> |
||
| 2686 | * @param array $array <p>The array to get from, if it's set to "null" we use the current array from the |
||
| 2687 | * class.</p> |
||
| 2688 | * @param bool $useByReference |
||
| 2689 | * |
||
| 2690 | * @return mixed|static |
||
| 2691 | * |
||
| 2692 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 2693 | * @psalm-mutation-free |
||
| 2694 | */ |
||
| 2695 | 243 | public function get( |
|
| 2859 | |||
| 2860 | /** |
||
| 2861 | * alias: for "Arrayy->toArray()" |
||
| 2862 | * |
||
| 2863 | * @return array |
||
| 2864 | * |
||
| 2865 | * @see Arrayy::getArray() |
||
| 2866 | * |
||
| 2867 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 2868 | */ |
||
| 2869 | 15 | public function getAll(): array |
|
| 2873 | |||
| 2874 | /** |
||
| 2875 | * Get the current array from the "Arrayy"-object. |
||
| 2876 | * |
||
| 2877 | * alias for "toArray()" |
||
| 2878 | * |
||
| 2879 | * @param bool $convertAllArrayyElements <p> |
||
| 2880 | * Convert all Child-"Arrayy" objects also to arrays. |
||
| 2881 | * </p> |
||
| 2882 | * @param bool $preserveKeys <p> |
||
| 2883 | * e.g.: A generator maybe return the same key more then once, |
||
| 2884 | * so maybe you will ignore the keys. |
||
| 2885 | * </p> |
||
| 2886 | * |
||
| 2887 | * @return array |
||
| 2888 | * |
||
| 2889 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 2890 | * @psalm-mutation-free |
||
| 2891 | * |
||
| 2892 | * @see Arrayy::toArray() |
||
| 2893 | */ |
||
| 2894 | 501 | public function getArray( |
|
| 2903 | |||
| 2904 | /** |
||
| 2905 | * @param string $json |
||
| 2906 | * |
||
| 2907 | * @return $this |
||
| 2908 | */ |
||
| 2909 | 3 | public static function createFromJsonMapper(string $json) |
|
| 2925 | |||
| 2926 | /** |
||
| 2927 | * @return array<int|string,TypeCheckInterface>|mixed|TypeCheckArray<int|string,TypeCheckInterface>|TypeInterface |
||
| 2928 | * |
||
| 2929 | * @internal |
||
| 2930 | */ |
||
| 2931 | 6 | public function getPhpDocPropertiesFromClass() |
|
| 2939 | |||
| 2940 | /** |
||
| 2941 | * Get the current array from the "Arrayy"-object as list. |
||
| 2942 | * |
||
| 2943 | * alias for "toList()" |
||
| 2944 | * |
||
| 2945 | * @param bool $convertAllArrayyElements <p> |
||
| 2946 | * Convert all Child-"Arrayy" objects also to arrays. |
||
| 2947 | * </p> |
||
| 2948 | * |
||
| 2949 | * @return array |
||
| 2950 | * |
||
| 2951 | * @psalm-return array<int,mixed>|array<int,T> |
||
| 2952 | * @psalm-mutation-free |
||
| 2953 | * |
||
| 2954 | * @see Arrayy::toList() |
||
| 2955 | */ |
||
| 2956 | 1 | public function getList(bool $convertAllArrayyElements = false): array |
|
| 2960 | |||
| 2961 | /** |
||
| 2962 | * Returns the values from a single column of the input array, identified by |
||
| 2963 | * the $columnKey, can be used to extract data-columns from multi-arrays. |
||
| 2964 | * |
||
| 2965 | * EXAMPLE: <code> |
||
| 2966 | * a([['foo' => 'bar', 'id' => 1], ['foo => 'lall', 'id' => 2]])->getColumn('foo', 'id'); // Arrayy[1 => 'bar', 2 => 'lall'] |
||
| 2967 | * </code> |
||
| 2968 | * |
||
| 2969 | * INFO: Optionally, you may provide an $indexKey to index the values in the returned |
||
| 2970 | * array by the values from the $indexKey column in the input array. |
||
| 2971 | * |
||
| 2972 | * @param mixed $columnKey |
||
| 2973 | * @param mixed $indexKey |
||
| 2974 | * |
||
| 2975 | * @return static |
||
| 2976 | * <p>(Immutable)</p> |
||
| 2977 | * |
||
| 2978 | * @psalm-return static<TKey,T> |
||
| 2979 | * @psalm-mutation-free |
||
| 2980 | */ |
||
| 2981 | 1 | public function getColumn($columnKey = null, $indexKey = null): self |
|
| 2989 | |||
| 2990 | /** |
||
| 2991 | * Get the current array from the "Arrayy"-object as generator by reference. |
||
| 2992 | * |
||
| 2993 | * @return \Generator |
||
| 2994 | * |
||
| 2995 | * @psalm-return \Generator<mixed,T>|\Generator<TKey,T> |
||
| 2996 | */ |
||
| 2997 | 75 | public function &getGeneratorByReference(): \Generator |
|
| 3016 | |||
| 3017 | /** |
||
| 3018 | * Get the current array from the "Arrayy"-object as generator. |
||
| 3019 | * |
||
| 3020 | * @return \Generator |
||
| 3021 | * |
||
| 3022 | * @psalm-return \Generator<mixed,T>|\Generator<TKey,T> |
||
| 3023 | * @psalm-mutation-free |
||
| 3024 | */ |
||
| 3025 | 999 | public function getGenerator(): \Generator |
|
| 3035 | |||
| 3036 | /** |
||
| 3037 | * alias: for "Arrayy->keys()" |
||
| 3038 | * |
||
| 3039 | * @return static |
||
| 3040 | * <p>(Immutable)</p> |
||
| 3041 | * |
||
| 3042 | * @see Arrayy::keys() |
||
| 3043 | * |
||
| 3044 | * @psalm-return static<array-key,TKey> |
||
| 3045 | * @psalm-mutation-free |
||
| 3046 | */ |
||
| 3047 | 2 | public function getKeys() |
|
| 3051 | |||
| 3052 | /** |
||
| 3053 | * Get the current array from the "Arrayy"-object as object. |
||
| 3054 | * |
||
| 3055 | * @return \stdClass |
||
| 3056 | */ |
||
| 3057 | 4 | public function getObject(): \stdClass |
|
| 3061 | |||
| 3062 | /** |
||
| 3063 | * alias: for "Arrayy->randomImmutable()" |
||
| 3064 | * |
||
| 3065 | * @return static |
||
| 3066 | * <p>(Immutable)</p> |
||
| 3067 | * |
||
| 3068 | * @see Arrayy::randomImmutable() |
||
| 3069 | * |
||
| 3070 | * @psalm-return static<int|array-key,T> |
||
| 3071 | */ |
||
| 3072 | 4 | public function getRandom(): self |
|
| 3076 | |||
| 3077 | /** |
||
| 3078 | * alias: for "Arrayy->randomKey()" |
||
| 3079 | * |
||
| 3080 | * @return mixed |
||
| 3081 | * <p>Get a key/index or null if there wasn't a key/index.</p> |
||
| 3082 | * |
||
| 3083 | * @see Arrayy::randomKey() |
||
| 3084 | */ |
||
| 3085 | 3 | public function getRandomKey() |
|
| 3089 | |||
| 3090 | /** |
||
| 3091 | * alias: for "Arrayy->randomKeys()" |
||
| 3092 | * |
||
| 3093 | * @param int $number |
||
| 3094 | * |
||
| 3095 | * @return static |
||
| 3096 | * <p>(Immutable)</p> |
||
| 3097 | * |
||
| 3098 | * @see Arrayy::randomKeys() |
||
| 3099 | * |
||
| 3100 | * @psalm-return static<TKey,T> |
||
| 3101 | */ |
||
| 3102 | 8 | public function getRandomKeys(int $number): self |
|
| 3106 | |||
| 3107 | /** |
||
| 3108 | * alias: for "Arrayy->randomValue()" |
||
| 3109 | * |
||
| 3110 | * @return mixed |
||
| 3111 | * <p>Get a random value or null if there wasn't a value.</p> |
||
| 3112 | * |
||
| 3113 | * @see Arrayy::randomValue() |
||
| 3114 | */ |
||
| 3115 | 3 | public function getRandomValue() |
|
| 3119 | |||
| 3120 | /** |
||
| 3121 | * alias: for "Arrayy->randomValues()" |
||
| 3122 | * |
||
| 3123 | * @param int $number |
||
| 3124 | * |
||
| 3125 | * @return static |
||
| 3126 | * <p>(Immutable)</p> |
||
| 3127 | * |
||
| 3128 | * @see Arrayy::randomValues() |
||
| 3129 | * |
||
| 3130 | * @psalm-return static<TKey,T> |
||
| 3131 | */ |
||
| 3132 | 6 | public function getRandomValues(int $number): self |
|
| 3136 | |||
| 3137 | /** |
||
| 3138 | * Gets all values. |
||
| 3139 | * |
||
| 3140 | * @return static |
||
| 3141 | * <p>The values of all elements in this array, in the order they |
||
| 3142 | * appear in the array.</p> |
||
| 3143 | * |
||
| 3144 | * @psalm-return static<TKey,T> |
||
| 3145 | */ |
||
| 3146 | 4 | public function getValues() |
|
| 3156 | |||
| 3157 | /** |
||
| 3158 | * Gets all values via Generator. |
||
| 3159 | * |
||
| 3160 | * @return \Generator |
||
| 3161 | * <p>The values of all elements in this array, in the order they |
||
| 3162 | * appear in the array as Generator.</p> |
||
| 3163 | * |
||
| 3164 | * @psalm-return \Generator<TKey,T> |
||
| 3165 | */ |
||
| 3166 | 4 | public function getValuesYield(): \Generator |
|
| 3170 | |||
| 3171 | /** |
||
| 3172 | * Group values from a array according to the results of a closure. |
||
| 3173 | * |
||
| 3174 | * @param callable|string $grouper <p>A callable function name.</p> |
||
| 3175 | * @param bool $saveKeys |
||
| 3176 | * |
||
| 3177 | * @return static |
||
| 3178 | * <p>(Immutable)</p> |
||
| 3179 | * |
||
| 3180 | * @psalm-return static<TKey,T> |
||
| 3181 | * @psalm-mutation-free |
||
| 3182 | */ |
||
| 3183 | 4 | public function group($grouper, bool $saveKeys = false): self |
|
| 3224 | |||
| 3225 | /** |
||
| 3226 | * Check if an array has a given key. |
||
| 3227 | * |
||
| 3228 | * @param mixed $key |
||
| 3229 | * |
||
| 3230 | * @return bool |
||
| 3231 | */ |
||
| 3232 | 30 | public function has($key): bool |
|
| 3258 | |||
| 3259 | /** |
||
| 3260 | * Check if an array has a given value. |
||
| 3261 | * |
||
| 3262 | * INFO: If you need to search recursive please use ```contains($value, true)```. |
||
| 3263 | * |
||
| 3264 | * @param mixed $value |
||
| 3265 | * |
||
| 3266 | * @return bool |
||
| 3267 | */ |
||
| 3268 | 1 | public function hasValue($value): bool |
|
| 3272 | |||
| 3273 | /** |
||
| 3274 | * Implodes the values of this array. |
||
| 3275 | * |
||
| 3276 | * EXAMPLE: <code> |
||
| 3277 | * a([0 => -9, 1, 2])->implode('|'); // '-9|1|2' |
||
| 3278 | * </code> |
||
| 3279 | * |
||
| 3280 | * @param string $glue |
||
| 3281 | * @param string $prefix |
||
| 3282 | * |
||
| 3283 | * @return string |
||
| 3284 | * @psalm-mutation-free |
||
| 3285 | */ |
||
| 3286 | 28 | public function implode(string $glue = '', string $prefix = ''): string |
|
| 3290 | |||
| 3291 | /** |
||
| 3292 | * Implodes the keys of this array. |
||
| 3293 | * |
||
| 3294 | * @param string $glue |
||
| 3295 | * |
||
| 3296 | * @return string |
||
| 3297 | * @psalm-mutation-free |
||
| 3298 | */ |
||
| 3299 | 8 | public function implodeKeys(string $glue = ''): string |
|
| 3303 | |||
| 3304 | /** |
||
| 3305 | * Given a list and an iterate-function that returns |
||
| 3306 | * a key for each element in the list (or a property name), |
||
| 3307 | * returns an object with an index of each item. |
||
| 3308 | * |
||
| 3309 | * @param mixed $key |
||
| 3310 | * |
||
| 3311 | * @return static |
||
| 3312 | * <p>(Immutable)</p> |
||
| 3313 | * |
||
| 3314 | * @psalm-return static<TKey,T> |
||
| 3315 | * @psalm-mutation-free |
||
| 3316 | */ |
||
| 3317 | 4 | View Code Duplication | public function indexBy($key): self |
| 3334 | |||
| 3335 | /** |
||
| 3336 | * alias: for "Arrayy->searchIndex()" |
||
| 3337 | * |
||
| 3338 | * @param mixed $value <p>The value to search for.</p> |
||
| 3339 | * |
||
| 3340 | * @return false|mixed |
||
| 3341 | * |
||
| 3342 | * @see Arrayy::searchIndex() |
||
| 3343 | */ |
||
| 3344 | 4 | public function indexOf($value) |
|
| 3348 | |||
| 3349 | /** |
||
| 3350 | * Get everything but the last..$to items. |
||
| 3351 | * |
||
| 3352 | * EXAMPLE: <code> |
||
| 3353 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->initial(2); // Arrayy[0 => 'foo'] |
||
| 3354 | * </code> |
||
| 3355 | * |
||
| 3356 | * @param int $to |
||
| 3357 | * |
||
| 3358 | * @return static |
||
| 3359 | * <p>(Immutable)</p> |
||
| 3360 | * |
||
| 3361 | * @psalm-return static<TKey,T> |
||
| 3362 | * @psalm-mutation-free |
||
| 3363 | */ |
||
| 3364 | 12 | public function initial(int $to = 1): self |
|
| 3368 | |||
| 3369 | /** |
||
| 3370 | * Return an array with all elements found in input array. |
||
| 3371 | * |
||
| 3372 | * EXAMPLE: <code> |
||
| 3373 | * a(['foo', 'bar'])->intersection(['bar', 'baz']); // Arrayy['bar'] |
||
| 3374 | * </code> |
||
| 3375 | * |
||
| 3376 | * @param array $search |
||
| 3377 | * @param bool $keepKeys |
||
| 3378 | * |
||
| 3379 | * @return static |
||
| 3380 | * <p>(Immutable)</p> |
||
| 3381 | * |
||
| 3382 | * @psalm-param array<mixed,mixed>|array<TKey,T> $search |
||
| 3383 | * @psalm-return static<TKey,T> |
||
| 3384 | * @psalm-mutation-free |
||
| 3385 | */ |
||
| 3386 | 4 | public function intersection(array $search, bool $keepKeys = false): self |
|
| 3412 | |||
| 3413 | /** |
||
| 3414 | * Return an array with all elements found in input array. |
||
| 3415 | * |
||
| 3416 | * @param array ...$array |
||
| 3417 | * |
||
| 3418 | * @return static |
||
| 3419 | * <p>(Immutable)</p> |
||
| 3420 | * |
||
| 3421 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$array |
||
| 3422 | * @psalm-return static<TKey,T> |
||
| 3423 | * @psalm-mutation-free |
||
| 3424 | */ |
||
| 3425 | 1 | public function intersectionMulti(...$array): self |
|
| 3433 | |||
| 3434 | /** |
||
| 3435 | * Return a boolean flag which indicates whether the two input arrays have any common elements. |
||
| 3436 | * |
||
| 3437 | * EXAMPLE: <code> |
||
| 3438 | * a(['foo', 'bar'])->intersects(['föö', 'bär']); // false |
||
| 3439 | * </code> |
||
| 3440 | * |
||
| 3441 | * @param array $search |
||
| 3442 | * |
||
| 3443 | * @return bool |
||
| 3444 | * |
||
| 3445 | * @psalm-param array<mixed,mixed>|array<TKey,T> $search |
||
| 3446 | */ |
||
| 3447 | 1 | public function intersects(array $search): bool |
|
| 3451 | |||
| 3452 | /** |
||
| 3453 | * Invoke a function on all of an array's values. |
||
| 3454 | * |
||
| 3455 | * @param callable $callable |
||
| 3456 | * @param mixed $arguments |
||
| 3457 | * |
||
| 3458 | * @return static |
||
| 3459 | * <p>(Immutable)</p> |
||
| 3460 | * |
||
| 3461 | * @psalm-param callable(T=,mixed):mixed $callable |
||
| 3462 | * @psalm-return static<TKey,T> |
||
| 3463 | * @psalm-mutation-free |
||
| 3464 | */ |
||
| 3465 | 1 | public function invoke($callable, $arguments = []): self |
|
| 3489 | |||
| 3490 | /** |
||
| 3491 | * Check whether array is associative or not. |
||
| 3492 | * |
||
| 3493 | * EXAMPLE: <code> |
||
| 3494 | * a(['foo' => 'bar', 2, 3])->isAssoc(); // true |
||
| 3495 | * </code> |
||
| 3496 | * |
||
| 3497 | * @param bool $recursive |
||
| 3498 | * |
||
| 3499 | * @return bool |
||
| 3500 | * <p>Returns true if associative, false otherwise.</p> |
||
| 3501 | */ |
||
| 3502 | 15 | View Code Duplication | public function isAssoc(bool $recursive = false): bool |
| 3517 | |||
| 3518 | /** |
||
| 3519 | * Check if a given key or keys are empty. |
||
| 3520 | * |
||
| 3521 | * @param int|int[]|string|string[]|null $keys |
||
| 3522 | * |
||
| 3523 | * @return bool |
||
| 3524 | * <p>Returns true if empty, false otherwise.</p> |
||
| 3525 | * @psalm-mutation-free |
||
| 3526 | */ |
||
| 3527 | 45 | public function isEmpty($keys = null): bool |
|
| 3545 | |||
| 3546 | /** |
||
| 3547 | * Check if the current array is equal to the given "$array" or not. |
||
| 3548 | * |
||
| 3549 | * EXAMPLE: <code> |
||
| 3550 | * a(['💩'])->isEqual(['💩']); // true |
||
| 3551 | * </code> |
||
| 3552 | * |
||
| 3553 | * @param array $array |
||
| 3554 | * |
||
| 3555 | * @return bool |
||
| 3556 | * |
||
| 3557 | * @psalm-param array<mixed,mixed> $array |
||
| 3558 | */ |
||
| 3559 | 1 | public function isEqual(array $array): bool |
|
| 3563 | |||
| 3564 | /** |
||
| 3565 | * Check if the current array is a multi-array. |
||
| 3566 | * |
||
| 3567 | * EXAMPLE: <code> |
||
| 3568 | * a(['foo' => [1, 2 , 3]])->isMultiArray(); // true |
||
| 3569 | * </code> |
||
| 3570 | * |
||
| 3571 | * @return bool |
||
| 3572 | */ |
||
| 3573 | 22 | public function isMultiArray(): bool |
|
| 3583 | |||
| 3584 | /** |
||
| 3585 | * Check whether array is numeric or not. |
||
| 3586 | * |
||
| 3587 | * @return bool |
||
| 3588 | * <p>Returns true if numeric, false otherwise.</p> |
||
| 3589 | */ |
||
| 3590 | 5 | View Code Duplication | public function isNumeric(): bool |
| 3605 | |||
| 3606 | /** |
||
| 3607 | * Check if the current array is sequential [0, 1, 2, 3, 4, 5 ...] or not. |
||
| 3608 | * |
||
| 3609 | * EXAMPLE: <code> |
||
| 3610 | * a([0 => 'foo', 1 => 'lall', 2 => 'foobar'])->isSequential(); // true |
||
| 3611 | * </code> |
||
| 3612 | * |
||
| 3613 | * INFO: If the array is empty we count it as non-sequential. |
||
| 3614 | * |
||
| 3615 | * @param bool $recursive |
||
| 3616 | * |
||
| 3617 | * @return bool |
||
| 3618 | * @psalm-mutation-free |
||
| 3619 | */ |
||
| 3620 | 10 | public function isSequential(bool $recursive = false): bool |
|
| 3648 | |||
| 3649 | /** |
||
| 3650 | * @return array |
||
| 3651 | * |
||
| 3652 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 3653 | */ |
||
| 3654 | 2 | public function jsonSerialize(): array |
|
| 3658 | |||
| 3659 | /** |
||
| 3660 | * Gets the key/index of the element at the current internal iterator position. |
||
| 3661 | * |
||
| 3662 | * @return int|string|null |
||
| 3663 | */ |
||
| 3664 | public function key() |
||
| 3668 | |||
| 3669 | /** |
||
| 3670 | * Checks if the given key exists in the provided array. |
||
| 3671 | * |
||
| 3672 | * INFO: This method only use "array_key_exists()" if you want to use "dot"-notation, |
||
| 3673 | * then you need to use "Arrayy->offsetExists()". |
||
| 3674 | * |
||
| 3675 | * @param int|string $key the key to look for |
||
| 3676 | * |
||
| 3677 | * @return bool |
||
| 3678 | * @psalm-mutation-free |
||
| 3679 | */ |
||
| 3680 | 164 | public function keyExists($key): bool |
|
| 3684 | |||
| 3685 | /** |
||
| 3686 | * Get all keys from the current array. |
||
| 3687 | * |
||
| 3688 | * EXAMPLE: <code> |
||
| 3689 | * a([1 => 'foo', 2 => 'foo2', 3 => 'bar'])->keys(); // Arrayy[1, 2, 3] |
||
| 3690 | * </code> |
||
| 3691 | * |
||
| 3692 | * @param bool $recursive [optional] <p> |
||
| 3693 | * Get all keys, also from all sub-arrays from an multi-dimensional array. |
||
| 3694 | * </p> |
||
| 3695 | * @param mixed|null $search_values [optional] <p> |
||
| 3696 | * If specified, then only keys containing these values are returned. |
||
| 3697 | * </p> |
||
| 3698 | * @param bool $strict [optional] <p> |
||
| 3699 | * Determines if strict comparison (===) should be used during the search. |
||
| 3700 | * </p> |
||
| 3701 | * |
||
| 3702 | * @return static |
||
| 3703 | * <p>(Immutable) An array of all the keys in input.</p> |
||
| 3704 | * |
||
| 3705 | * @psalm-return static<array-key,TKey> |
||
| 3706 | * @psalm-mutation-free |
||
| 3707 | */ |
||
| 3708 | 29 | public function keys( |
|
| 3779 | |||
| 3780 | /** |
||
| 3781 | * Sort an array by key in reverse order. |
||
| 3782 | * |
||
| 3783 | * @param int $sort_flags [optional] <p> |
||
| 3784 | * You may modify the behavior of the sort using the optional |
||
| 3785 | * parameter sort_flags, for details |
||
| 3786 | * see sort. |
||
| 3787 | * </p> |
||
| 3788 | * |
||
| 3789 | * @return $this |
||
| 3790 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 3791 | * |
||
| 3792 | * @psalm-return static<TKey,T> |
||
| 3793 | */ |
||
| 3794 | 4 | public function krsort(int $sort_flags = 0): self |
|
| 3802 | |||
| 3803 | /** |
||
| 3804 | * Sort an array by key in reverse order. |
||
| 3805 | * |
||
| 3806 | * @param int $sort_flags [optional] <p> |
||
| 3807 | * You may modify the behavior of the sort using the optional |
||
| 3808 | * parameter sort_flags, for details |
||
| 3809 | * see sort. |
||
| 3810 | * </p> |
||
| 3811 | * |
||
| 3812 | * @return $this |
||
| 3813 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 3814 | * |
||
| 3815 | * @psalm-return static<TKey,T> |
||
| 3816 | * @psalm-mutation-free |
||
| 3817 | */ |
||
| 3818 | 4 | public function krsortImmutable(int $sort_flags = 0): self |
|
| 3829 | |||
| 3830 | /** |
||
| 3831 | * Get the last value from the current array. |
||
| 3832 | * |
||
| 3833 | * EXAMPLE: <code> |
||
| 3834 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->last(); // 'lall' |
||
| 3835 | * </code> |
||
| 3836 | * |
||
| 3837 | * @return mixed|null |
||
| 3838 | * <p>Return null if there wasn't a element.</p> |
||
| 3839 | * @psalm-mutation-free |
||
| 3840 | */ |
||
| 3841 | 17 | public function last() |
|
| 3850 | |||
| 3851 | /** |
||
| 3852 | * Get the last key from the current array. |
||
| 3853 | * |
||
| 3854 | * @return mixed|null |
||
| 3855 | * <p>Return null if there wasn't a element.</p> |
||
| 3856 | * @psalm-mutation-free |
||
| 3857 | */ |
||
| 3858 | 21 | public function lastKey() |
|
| 3864 | |||
| 3865 | /** |
||
| 3866 | * Get the last value(s) from the current array. |
||
| 3867 | * |
||
| 3868 | * EXAMPLE: <code> |
||
| 3869 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->lasts(2); // Arrayy[0 => 'bar', 1 => 'lall'] |
||
| 3870 | * </code> |
||
| 3871 | * |
||
| 3872 | * @param int|null $number |
||
| 3873 | * |
||
| 3874 | * @return static |
||
| 3875 | * <p>(Immutable)</p> |
||
| 3876 | * |
||
| 3877 | * @psalm-return static<TKey,T> |
||
| 3878 | * @psalm-mutation-free |
||
| 3879 | */ |
||
| 3880 | 13 | public function lastsImmutable(int $number = null): self |
|
| 3910 | |||
| 3911 | /** |
||
| 3912 | * Get the last value(s) from the current array. |
||
| 3913 | * |
||
| 3914 | * EXAMPLE: <code> |
||
| 3915 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->lasts(2); // Arrayy[0 => 'bar', 1 => 'lall'] |
||
| 3916 | * </code> |
||
| 3917 | * |
||
| 3918 | * @param int|null $number |
||
| 3919 | * |
||
| 3920 | * @return $this |
||
| 3921 | * <p>(Mutable)</p> |
||
| 3922 | * |
||
| 3923 | * @psalm-return static<TKey,T> |
||
| 3924 | */ |
||
| 3925 | 13 | public function lastsMutable(int $number = null): self |
|
| 3936 | |||
| 3937 | /** |
||
| 3938 | * Count the values from the current array. |
||
| 3939 | * |
||
| 3940 | * alias: for "Arrayy->count()" |
||
| 3941 | * |
||
| 3942 | * @param int $mode |
||
| 3943 | * |
||
| 3944 | * @return int |
||
| 3945 | * |
||
| 3946 | * @see Arrayy::count() |
||
| 3947 | */ |
||
| 3948 | 20 | public function length(int $mode = \COUNT_NORMAL): int |
|
| 3952 | |||
| 3953 | /** |
||
| 3954 | * Apply the given function to the every element of the array, |
||
| 3955 | * collecting the results. |
||
| 3956 | * |
||
| 3957 | * @param callable $callable |
||
| 3958 | * @param bool $useKeyAsSecondParameter |
||
| 3959 | * @param mixed ...$arguments |
||
| 3960 | * |
||
| 3961 | * @return static |
||
| 3962 | * <p>(Immutable) Arrayy object with modified elements.</p> |
||
| 3963 | * |
||
| 3964 | * @psalm-param callable(T,TKey=,mixed=):mixed $callable |
||
| 3965 | * @psalm-return static<TKey,T> |
||
| 3966 | * @psalm-mutation-free |
||
| 3967 | */ |
||
| 3968 | 5 | public function map( |
|
| 4001 | |||
| 4002 | /** |
||
| 4003 | * Check if all items in current array match a truth test. |
||
| 4004 | * |
||
| 4005 | * EXAMPLE: <code> |
||
| 4006 | * $closure = function ($value, $key) { |
||
| 4007 | * return ($value % 2 === 0); |
||
| 4008 | * }; |
||
| 4009 | * a([2, 4, 8])->matches($closure); // true |
||
| 4010 | * </code> |
||
| 4011 | * |
||
| 4012 | * @param \Closure $closure |
||
| 4013 | * |
||
| 4014 | * @return bool |
||
| 4015 | */ |
||
| 4016 | 15 | View Code Duplication | public function matches(\Closure $closure): bool |
| 4032 | |||
| 4033 | /** |
||
| 4034 | * Check if any item in the current array matches a truth test. |
||
| 4035 | * |
||
| 4036 | * EXAMPLE: <code> |
||
| 4037 | * $closure = function ($value, $key) { |
||
| 4038 | * return ($value % 2 === 0); |
||
| 4039 | * }; |
||
| 4040 | * a([1, 4, 7])->matches($closure); // true |
||
| 4041 | * </code> |
||
| 4042 | * |
||
| 4043 | * @param \Closure $closure |
||
| 4044 | * |
||
| 4045 | * @return bool |
||
| 4046 | */ |
||
| 4047 | 14 | View Code Duplication | public function matchesAny(\Closure $closure): bool |
| 4063 | |||
| 4064 | /** |
||
| 4065 | * Get the max value from an array. |
||
| 4066 | * |
||
| 4067 | * EXAMPLE: <code> |
||
| 4068 | * a([-9, -8, -7, 1.32])->max(); // 1.32 |
||
| 4069 | * </code> |
||
| 4070 | * |
||
| 4071 | * @return false|mixed |
||
| 4072 | * <p>Will return false if there are no values.</p> |
||
| 4073 | */ |
||
| 4074 | 10 | View Code Duplication | public function max() |
| 4094 | |||
| 4095 | /** |
||
| 4096 | * Merge the new $array into the current array. |
||
| 4097 | * |
||
| 4098 | * - keep key,value from the current array, also if the index is in the new $array |
||
| 4099 | * |
||
| 4100 | * EXAMPLE: <code> |
||
| 4101 | * $array1 = [1 => 'one', 'foo' => 'bar1']; |
||
| 4102 | * $array2 = ['foo' => 'bar2', 3 => 'three']; |
||
| 4103 | * a($array1)->mergeAppendKeepIndex($array2); // Arrayy[1 => 'one', 'foo' => 'bar2', 3 => 'three'] |
||
| 4104 | * </code> |
||
| 4105 | * |
||
| 4106 | * @param array $array |
||
| 4107 | * @param bool $recursive |
||
| 4108 | * |
||
| 4109 | * @return static |
||
| 4110 | * <p>(Immutable)</p> |
||
| 4111 | * |
||
| 4112 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 4113 | * @psalm-return static<int|TKey,T> |
||
| 4114 | * @psalm-mutation-free |
||
| 4115 | */ |
||
| 4116 | 32 | View Code Duplication | public function mergeAppendKeepIndex(array $array = [], bool $recursive = false): self |
| 4131 | |||
| 4132 | /** |
||
| 4133 | * Merge the new $array into the current array. |
||
| 4134 | * |
||
| 4135 | * - replace duplicate assoc-keys from the current array with the key,values from the new $array |
||
| 4136 | * - create new indexes |
||
| 4137 | * |
||
| 4138 | * EXAMPLE: <code> |
||
| 4139 | * $array1 = [1 => 'one', 'foo' => 'bar1']; |
||
| 4140 | * $array2 = ['foo' => 'bar2', 3 => 'three']; |
||
| 4141 | * a($array1)->mergeAppendNewIndex($array2); // Arrayy[0 => 'one', 'foo' => 'bar2', 1 => three'] |
||
| 4142 | * </code> |
||
| 4143 | * |
||
| 4144 | * @param array $array |
||
| 4145 | * @param bool $recursive |
||
| 4146 | * |
||
| 4147 | * @return static |
||
| 4148 | * <p>(Immutable)</p> |
||
| 4149 | * |
||
| 4150 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 4151 | * @psalm-return static<TKey,T> |
||
| 4152 | * @psalm-mutation-free |
||
| 4153 | */ |
||
| 4154 | 19 | View Code Duplication | public function mergeAppendNewIndex(array $array = [], bool $recursive = false): self |
| 4169 | |||
| 4170 | /** |
||
| 4171 | * Merge the the current array into the $array. |
||
| 4172 | * |
||
| 4173 | * - use key,value from the new $array, also if the index is in the current array |
||
| 4174 | * |
||
| 4175 | * EXAMPLE: <code> |
||
| 4176 | * $array1 = [1 => 'one', 'foo' => 'bar1']; |
||
| 4177 | * $array2 = ['foo' => 'bar2', 3 => 'three']; |
||
| 4178 | * a($array1)->mergePrependKeepIndex($array2); // Arrayy['foo' => 'bar1', 3 => 'three', 1 => 'one'] |
||
| 4179 | * </code> |
||
| 4180 | * |
||
| 4181 | * @param array $array |
||
| 4182 | * @param bool $recursive |
||
| 4183 | * |
||
| 4184 | * @return static |
||
| 4185 | * <p>(Immutable)</p> |
||
| 4186 | * |
||
| 4187 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 4188 | * @psalm-return static<TKey,T> |
||
| 4189 | * @psalm-mutation-free |
||
| 4190 | */ |
||
| 4191 | 16 | View Code Duplication | public function mergePrependKeepIndex(array $array = [], bool $recursive = false): self |
| 4206 | |||
| 4207 | /** |
||
| 4208 | * Merge the current array into the new $array. |
||
| 4209 | * |
||
| 4210 | * - replace duplicate assoc-keys from new $array with the key,values from the current array |
||
| 4211 | * - create new indexes |
||
| 4212 | * |
||
| 4213 | * EXAMPLE: <code> |
||
| 4214 | * $array1 = [1 => 'one', 'foo' => 'bar1']; |
||
| 4215 | * $array2 = ['foo' => 'bar2', 3 => 'three']; |
||
| 4216 | * a($array1)->mergePrependNewIndex($array2); // Arrayy['foo' => 'bar1', 0 => 'three', 1 => 'one'] |
||
| 4217 | * </code> |
||
| 4218 | * |
||
| 4219 | * @param array $array |
||
| 4220 | * @param bool $recursive |
||
| 4221 | * |
||
| 4222 | * @return static |
||
| 4223 | * <p>(Immutable)</p> |
||
| 4224 | * |
||
| 4225 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 4226 | * @psalm-return static<TKey,T> |
||
| 4227 | * @psalm-mutation-free |
||
| 4228 | */ |
||
| 4229 | 20 | View Code Duplication | public function mergePrependNewIndex(array $array = [], bool $recursive = false): self |
| 4244 | |||
| 4245 | /** |
||
| 4246 | * @return ArrayyMeta|static |
||
| 4247 | */ |
||
| 4248 | 18 | public static function meta() |
|
| 4252 | |||
| 4253 | /** |
||
| 4254 | * Get the min value from an array. |
||
| 4255 | * |
||
| 4256 | * EXAMPLE: <code> |
||
| 4257 | * a([-9, -8, -7, 1.32])->min(); // -9 |
||
| 4258 | * </code> |
||
| 4259 | * |
||
| 4260 | * @return false|mixed |
||
| 4261 | * <p>Will return false if there are no values.</p> |
||
| 4262 | */ |
||
| 4263 | 10 | View Code Duplication | public function min() |
| 4283 | |||
| 4284 | /** |
||
| 4285 | * Get the most used value from the array. |
||
| 4286 | * |
||
| 4287 | * @return mixed|null |
||
| 4288 | * <p>(Immutable) Return null if there wasn't a element.</p> |
||
| 4289 | * @psalm-mutation-free |
||
| 4290 | */ |
||
| 4291 | 3 | public function mostUsedValue() |
|
| 4295 | |||
| 4296 | /** |
||
| 4297 | * Get the most used value from the array. |
||
| 4298 | * |
||
| 4299 | * @param int|null $number <p>How many values you will take?</p> |
||
| 4300 | * |
||
| 4301 | * @return static |
||
| 4302 | * <p>(Immutable)</p> |
||
| 4303 | * |
||
| 4304 | * @psalm-return static<TKey,T> |
||
| 4305 | * @psalm-mutation-free |
||
| 4306 | */ |
||
| 4307 | 3 | public function mostUsedValues(int $number = null): self |
|
| 4311 | |||
| 4312 | /** |
||
| 4313 | * Move an array element to a new index. |
||
| 4314 | * |
||
| 4315 | * EXAMPLE: <code> |
||
| 4316 | * $arr2 = new A(['A' => 'a', 'B' => 'b', 'C' => 'c', 'D' => 'd', 'E' => 'e']); |
||
| 4317 | * $newArr2 = $arr2->moveElement('D', 1); // Arrayy['A' => 'a', 'D' => 'd', 'B' => 'b', 'C' => 'c', 'E' => 'e'] |
||
| 4318 | * </code> |
||
| 4319 | * |
||
| 4320 | * @param int|string $from |
||
| 4321 | * @param int $to |
||
| 4322 | * |
||
| 4323 | * @return static |
||
| 4324 | * <p>(Immutable)</p> |
||
| 4325 | * |
||
| 4326 | * @psalm-return static<TKey,T> |
||
| 4327 | * @psalm-mutation-free |
||
| 4328 | */ |
||
| 4329 | 1 | public function moveElement($from, $to): self |
|
| 4362 | |||
| 4363 | /** |
||
| 4364 | * Move an array element to the first place. |
||
| 4365 | * |
||
| 4366 | * INFO: Instead of "Arrayy->moveElement()" this method will NOT |
||
| 4367 | * loss the keys of an indexed array. |
||
| 4368 | * |
||
| 4369 | * @param int|string $key |
||
| 4370 | * |
||
| 4371 | * @return static |
||
| 4372 | * <p>(Immutable)</p> |
||
| 4373 | * |
||
| 4374 | * @psalm-return static<TKey,T> |
||
| 4375 | * @psalm-mutation-free |
||
| 4376 | */ |
||
| 4377 | 1 | View Code Duplication | public function moveElementToFirstPlace($key): self |
| 4393 | |||
| 4394 | /** |
||
| 4395 | * Move an array element to the last place. |
||
| 4396 | * |
||
| 4397 | * INFO: Instead of "Arrayy->moveElement()" this method will NOT |
||
| 4398 | * loss the keys of an indexed array. |
||
| 4399 | * |
||
| 4400 | * @param int|string $key |
||
| 4401 | * |
||
| 4402 | * @return static |
||
| 4403 | * <p>(Immutable)</p> |
||
| 4404 | * |
||
| 4405 | * @psalm-return static<TKey,T> |
||
| 4406 | * @psalm-mutation-free |
||
| 4407 | */ |
||
| 4408 | 1 | View Code Duplication | public function moveElementToLastPlace($key): self |
| 4424 | |||
| 4425 | /** |
||
| 4426 | * Moves the internal iterator position to the next element and returns this element. |
||
| 4427 | * |
||
| 4428 | * @return false|mixed |
||
| 4429 | * <p>(Mutable) Will return false if there are no values.</p> |
||
| 4430 | */ |
||
| 4431 | public function next() |
||
| 4435 | |||
| 4436 | /** |
||
| 4437 | * Get the next nth keys and values from the array. |
||
| 4438 | * |
||
| 4439 | * @param int $step |
||
| 4440 | * @param int $offset |
||
| 4441 | * |
||
| 4442 | * @return static |
||
| 4443 | * <p>(Immutable)</p> |
||
| 4444 | * |
||
| 4445 | * @psalm-return static<TKey,T> |
||
| 4446 | * @psalm-mutation-free |
||
| 4447 | */ |
||
| 4448 | 1 | public function nth(int $step, int $offset = 0): self |
|
| 4467 | |||
| 4468 | /** |
||
| 4469 | * Get a subset of the items from the given array. |
||
| 4470 | * |
||
| 4471 | * @param int[]|string[] $keys |
||
| 4472 | * |
||
| 4473 | * @return static |
||
| 4474 | * <p>(Immutable)</p> |
||
| 4475 | * |
||
| 4476 | * @psalm-param array-key[] $keys |
||
| 4477 | * @psalm-return static<TKey,T> |
||
| 4478 | * @psalm-mutation-free |
||
| 4479 | */ |
||
| 4480 | 1 | View Code Duplication | public function only(array $keys): self |
| 4498 | |||
| 4499 | /** |
||
| 4500 | * Pad array to the specified size with a given value. |
||
| 4501 | * |
||
| 4502 | * @param int $size <p>Size of the result array.</p> |
||
| 4503 | * @param mixed $value <p>Empty value by default.</p> |
||
| 4504 | * |
||
| 4505 | * @return static |
||
| 4506 | * <p>(Immutable) Arrayy object padded to $size with $value.</p> |
||
| 4507 | * |
||
| 4508 | * @psalm-return static<TKey,T> |
||
| 4509 | * @psalm-mutation-free |
||
| 4510 | */ |
||
| 4511 | 5 | public function pad(int $size, $value): self |
|
| 4519 | |||
| 4520 | /** |
||
| 4521 | * Partitions this array in two array according to a predicate. |
||
| 4522 | * Keys are preserved in the resulting array. |
||
| 4523 | * |
||
| 4524 | * @param \Closure $closure |
||
| 4525 | * <p>The predicate on which to partition.</p> |
||
| 4526 | * |
||
| 4527 | * @return array<int, static> |
||
| 4528 | * <p>An array with two elements. The first element contains the array |
||
| 4529 | * of elements where the predicate returned TRUE, the second element |
||
| 4530 | * contains the array of elements where the predicate returned FALSE.</p> |
||
| 4531 | * |
||
| 4532 | * @psalm-return array<int, static<TKey,T>> |
||
| 4533 | */ |
||
| 4534 | 1 | public function partition(\Closure $closure): array |
|
| 4550 | |||
| 4551 | /** |
||
| 4552 | * Pop a specified value off the end of the current array. |
||
| 4553 | * |
||
| 4554 | * @return mixed|null |
||
| 4555 | * <p>(Mutable) The popped element from the current array or null if the array is e.g. empty.</p> |
||
| 4556 | */ |
||
| 4557 | 5 | public function pop() |
|
| 4563 | |||
| 4564 | /** |
||
| 4565 | * Prepend a (key) + value to the current array. |
||
| 4566 | * |
||
| 4567 | * EXAMPLE: <code> |
||
| 4568 | * a(['fòô' => 'bàř'])->prepend('foo'); // Arrayy[0 => 'foo', 'fòô' => 'bàř'] |
||
| 4569 | * </code> |
||
| 4570 | * |
||
| 4571 | * @param mixed $value |
||
| 4572 | * @param mixed $key |
||
| 4573 | * |
||
| 4574 | * @return $this |
||
| 4575 | * <p>(Mutable) Return this Arrayy object, with the prepended value.</p> |
||
| 4576 | * |
||
| 4577 | * @psalm-return static<TKey,T> |
||
| 4578 | */ |
||
| 4579 | 11 | public function prepend($value, $key = null) |
|
| 4595 | |||
| 4596 | /** |
||
| 4597 | * Prepend a (key) + value to the current array. |
||
| 4598 | * |
||
| 4599 | * EXAMPLE: <code> |
||
| 4600 | * a(['fòô' => 'bàř'])->prependImmutable('foo')->getArray(); // [0 => 'foo', 'fòô' => 'bàř'] |
||
| 4601 | * </code> |
||
| 4602 | * |
||
| 4603 | * @param mixed $value |
||
| 4604 | * @param mixed $key |
||
| 4605 | * |
||
| 4606 | * @return $this |
||
| 4607 | * <p>(Immutable) Return this Arrayy object, with the prepended value.</p> |
||
| 4608 | * |
||
| 4609 | * @psalm-return static<TKey,T> |
||
| 4610 | * @psalm-mutation-free |
||
| 4611 | */ |
||
| 4612 | 1 | View Code Duplication | public function prependImmutable($value, $key = null) |
| 4637 | |||
| 4638 | /** |
||
| 4639 | * Add a suffix to each key. |
||
| 4640 | * |
||
| 4641 | * @param mixed $suffix |
||
| 4642 | * |
||
| 4643 | * @return static |
||
| 4644 | * <p>(Immutable) Return an Arrayy object, with the prepended keys.</p> |
||
| 4645 | * |
||
| 4646 | * @psalm-return static<TKey,T> |
||
| 4647 | * @psalm-mutation-free |
||
| 4648 | */ |
||
| 4649 | 10 | View Code Duplication | public function prependToEachKey($suffix): self |
| 4675 | |||
| 4676 | /** |
||
| 4677 | * Add a suffix to each value. |
||
| 4678 | * |
||
| 4679 | * @param mixed $suffix |
||
| 4680 | * |
||
| 4681 | * @return static |
||
| 4682 | * <p>(Immutable) Return an Arrayy object, with the prepended values.</p> |
||
| 4683 | * |
||
| 4684 | * @psalm-return static<TKey,T> |
||
| 4685 | * @psalm-mutation-free |
||
| 4686 | */ |
||
| 4687 | 10 | View Code Duplication | public function prependToEachValue($suffix): self |
| 4715 | |||
| 4716 | /** |
||
| 4717 | * Return the value of a given key and |
||
| 4718 | * delete the key. |
||
| 4719 | * |
||
| 4720 | * @param int|int[]|string|string[]|null $keyOrKeys |
||
| 4721 | * @param mixed $fallback |
||
| 4722 | * |
||
| 4723 | * @return mixed |
||
| 4724 | */ |
||
| 4725 | 5 | public function pull($keyOrKeys = null, $fallback = null) |
|
| 4747 | |||
| 4748 | /** |
||
| 4749 | * Push one or more values onto the end of array at once. |
||
| 4750 | * |
||
| 4751 | * @param array ...$args |
||
| 4752 | * |
||
| 4753 | * @return $this |
||
| 4754 | * <p>(Mutable) Return this Arrayy object, with pushed elements to the end of array.</p> |
||
| 4755 | * |
||
| 4756 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
| 4757 | * |
||
| 4758 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$args |
||
| 4759 | * @psalm-return static<TKey,T> |
||
| 4760 | */ |
||
| 4761 | 7 | public function push(...$args) |
|
| 4779 | |||
| 4780 | /** |
||
| 4781 | * Get a random value from the current array. |
||
| 4782 | * |
||
| 4783 | * EXAMPLE: <code> |
||
| 4784 | * a([1, 2, 3, 4])->randomImmutable(2); // e.g.: Arrayy[1, 4] |
||
| 4785 | * </code> |
||
| 4786 | * |
||
| 4787 | * @param int|null $number <p>How many values you will take?</p> |
||
| 4788 | * |
||
| 4789 | * @return static |
||
| 4790 | * <p>(Immutable)</p> |
||
| 4791 | * |
||
| 4792 | * @psalm-return static<int|array-key,T> |
||
| 4793 | */ |
||
| 4794 | 19 | public function randomImmutable(int $number = null): self |
|
| 4827 | |||
| 4828 | /** |
||
| 4829 | * Pick a random key/index from the keys of this array. |
||
| 4830 | * |
||
| 4831 | * EXAMPLE: <code> |
||
| 4832 | * $arrayy = A::create([1 => 'one', 2 => 'two']); |
||
| 4833 | * $arrayy->randomKey(); // e.g. 2 |
||
| 4834 | * </code> |
||
| 4835 | * |
||
| 4836 | * @throws \RangeException If array is empty |
||
| 4837 | * |
||
| 4838 | * @return mixed |
||
| 4839 | * <p>Get a key/index or null if there wasn't a key/index.</p> |
||
| 4840 | */ |
||
| 4841 | 4 | public function randomKey() |
|
| 4851 | |||
| 4852 | /** |
||
| 4853 | * Pick a given number of random keys/indexes out of this array. |
||
| 4854 | * |
||
| 4855 | * EXAMPLE: <code> |
||
| 4856 | * a([1 => 'one', 2 => 'two'])->randomKeys(); // e.g. Arrayy[1, 2] |
||
| 4857 | * </code> |
||
| 4858 | * |
||
| 4859 | * @param int $number <p>The number of keys/indexes (should be <= \count($this->array))</p> |
||
| 4860 | * |
||
| 4861 | * @throws \RangeException If array is empty |
||
| 4862 | * |
||
| 4863 | * @return static |
||
| 4864 | * <p>(Immutable)</p> |
||
| 4865 | * |
||
| 4866 | * @psalm-return static<TKey,T> |
||
| 4867 | */ |
||
| 4868 | 13 | public function randomKeys(int $number): self |
|
| 4896 | |||
| 4897 | /** |
||
| 4898 | * Get a random value from the current array. |
||
| 4899 | * |
||
| 4900 | * EXAMPLE: <code> |
||
| 4901 | * a([1, 2, 3, 4])->randomMutable(2); // e.g.: Arrayy[1, 4] |
||
| 4902 | * </code> |
||
| 4903 | * |
||
| 4904 | * @param int|null $number <p>How many values you will take?</p> |
||
| 4905 | * |
||
| 4906 | * @return $this |
||
| 4907 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 4908 | * |
||
| 4909 | * @psalm-return static<TKey,T> |
||
| 4910 | */ |
||
| 4911 | 17 | public function randomMutable(int $number = null): self |
|
| 4936 | |||
| 4937 | /** |
||
| 4938 | * Pick a random value from the values of this array. |
||
| 4939 | * |
||
| 4940 | * EXAMPLE: <code> |
||
| 4941 | * a([1 => 'one', 2 => 'two'])->randomValue(); // e.g. 'one' |
||
| 4942 | * </code> |
||
| 4943 | * |
||
| 4944 | * @return mixed |
||
| 4945 | * <p>Get a random value or null if there wasn't a value.</p> |
||
| 4946 | */ |
||
| 4947 | 4 | public function randomValue() |
|
| 4957 | |||
| 4958 | /** |
||
| 4959 | * Pick a given number of random values out of this array. |
||
| 4960 | * |
||
| 4961 | * EXAMPLE: <code> |
||
| 4962 | * a([1 => 'one', 2 => 'two'])->randomValues(); // e.g. Arrayy['one', 'two'] |
||
| 4963 | * </code> |
||
| 4964 | * |
||
| 4965 | * @param int $number |
||
| 4966 | * |
||
| 4967 | * @return static |
||
| 4968 | * <p>(Mutable)</p> |
||
| 4969 | * |
||
| 4970 | * @psalm-return static<TKey,T> |
||
| 4971 | */ |
||
| 4972 | 7 | public function randomValues(int $number): self |
|
| 4976 | |||
| 4977 | /** |
||
| 4978 | * Get a random value from an array, with the ability to skew the results. |
||
| 4979 | * |
||
| 4980 | * EXAMPLE: <code> |
||
| 4981 | * a([0 => 3, 1 => 4])->randomWeighted([1 => 4]); // e.g.: Arrayy[4] (has a 66% chance of returning 4) |
||
| 4982 | * </code> |
||
| 4983 | * |
||
| 4984 | * @param array $array |
||
| 4985 | * @param int|null $number <p>How many values you will take?</p> |
||
| 4986 | * |
||
| 4987 | * @return static<int,mixed> |
||
| 4988 | * <p>(Immutable)</p> |
||
| 4989 | * |
||
| 4990 | * @psalm-param array<mixed,mixed> $array |
||
| 4991 | * @psalm-return static<int|array-key,T> |
||
| 4992 | */ |
||
| 4993 | 9 | public function randomWeighted(array $array, int $number = null): self |
|
| 5008 | |||
| 5009 | /** |
||
| 5010 | * Reduce the current array via callable e.g. anonymous-function. |
||
| 5011 | * |
||
| 5012 | * EXAMPLE: <code> |
||
| 5013 | * function myReducer($resultArray, $value) { |
||
| 5014 | * if ($value == 'foo') { |
||
| 5015 | * $resultArray[] = $value; |
||
| 5016 | * } |
||
| 5017 | * return $resultArray; |
||
| 5018 | * }; |
||
| 5019 | * a(['foo', 'bar'])->reduce('myReducer'); // Arrayy['foo'] |
||
| 5020 | * </cdde> |
||
| 5021 | * |
||
| 5022 | * @param callable $callable |
||
| 5023 | * @param mixed $init |
||
| 5024 | * |
||
| 5025 | * @return static |
||
| 5026 | * <p>(Immutable)</p> |
||
| 5027 | * |
||
| 5028 | * @psalm-return static<TKey,T> |
||
| 5029 | * @psalm-mutation-free |
||
| 5030 | */ |
||
| 5031 | 18 | public function reduce($callable, $init = []): self |
|
| 5061 | |||
| 5062 | /** |
||
| 5063 | * @param bool $unique |
||
| 5064 | * |
||
| 5065 | * @return static |
||
| 5066 | * <p>(Immutable)</p> |
||
| 5067 | * |
||
| 5068 | * @psalm-return static<TKey,T> |
||
| 5069 | * @psalm-mutation-free |
||
| 5070 | */ |
||
| 5071 | 14 | public function reduce_dimension(bool $unique = true): self |
|
| 5094 | |||
| 5095 | /** |
||
| 5096 | * Create a numerically re-indexed Arrayy object. |
||
| 5097 | * |
||
| 5098 | * EXAMPLE: <code> |
||
| 5099 | * a([2 => 1, 3 => 2])->reindex(); // Arrayy[0 => 1, 1 => 2] |
||
| 5100 | * </code> |
||
| 5101 | * |
||
| 5102 | * @return $this |
||
| 5103 | * <p>(Mutable) Return this Arrayy object, with re-indexed array-elements.</p> |
||
| 5104 | * |
||
| 5105 | * @psalm-return static<TKey,T> |
||
| 5106 | */ |
||
| 5107 | 9 | public function reindex(): self |
|
| 5115 | |||
| 5116 | /** |
||
| 5117 | * Return all items that fail the truth test. |
||
| 5118 | * |
||
| 5119 | * EXAMPLE: <code> |
||
| 5120 | * $closure = function ($value) { |
||
| 5121 | * return $value % 2 !== 0; |
||
| 5122 | * } |
||
| 5123 | * a([1, 2, 3, 4])->reject($closure); // Arrayy[1 => 2, 3 => 4] |
||
| 5124 | * </code> |
||
| 5125 | * |
||
| 5126 | * @param \Closure $closure |
||
| 5127 | * |
||
| 5128 | * @return static |
||
| 5129 | * <p>(Immutable)</p> |
||
| 5130 | * |
||
| 5131 | * @psalm-return static<TKey,T> |
||
| 5132 | * @psalm-mutation-free |
||
| 5133 | */ |
||
| 5134 | 1 | View Code Duplication | public function reject(\Closure $closure): self |
| 5151 | |||
| 5152 | /** |
||
| 5153 | * Remove a value from the current array (optional using dot-notation). |
||
| 5154 | * |
||
| 5155 | * EXAMPLE: <code> |
||
| 5156 | * a([1 => 'bar', 'foo' => 'foo'])->remove(1); // Arrayy['foo' => 'foo'] |
||
| 5157 | * </code> |
||
| 5158 | * |
||
| 5159 | * @param mixed $key |
||
| 5160 | * |
||
| 5161 | * @return static |
||
| 5162 | * <p>(Mutable)</p> |
||
| 5163 | * |
||
| 5164 | * @psalm-param TKey $key |
||
| 5165 | * @psalm-return static<TKey,T> |
||
| 5166 | */ |
||
| 5167 | 22 | public function remove($key) |
|
| 5190 | |||
| 5191 | /** |
||
| 5192 | * alias: for "Arrayy->removeValue()" |
||
| 5193 | * |
||
| 5194 | * @param mixed $element |
||
| 5195 | * |
||
| 5196 | * @return static |
||
| 5197 | * <p>(Immutable)</p> |
||
| 5198 | * |
||
| 5199 | * @psalm-param T $element |
||
| 5200 | * @psalm-return static<TKey,T> |
||
| 5201 | * @psalm-mutation-free |
||
| 5202 | */ |
||
| 5203 | 8 | public function removeElement($element) |
|
| 5207 | |||
| 5208 | /** |
||
| 5209 | * Remove the first value from the current array. |
||
| 5210 | * |
||
| 5211 | * EXAMPLE: <code> |
||
| 5212 | * a([1 => 'bar', 'foo' => 'foo'])->removeFirst(); // Arrayy['foo' => 'foo'] |
||
| 5213 | * </code> |
||
| 5214 | * |
||
| 5215 | * @return static |
||
| 5216 | * <p>(Immutable)</p> |
||
| 5217 | * |
||
| 5218 | * @psalm-return static<TKey,T> |
||
| 5219 | * @psalm-mutation-free |
||
| 5220 | */ |
||
| 5221 | 7 | View Code Duplication | public function removeFirst(): self |
| 5233 | |||
| 5234 | /** |
||
| 5235 | * Remove the last value from the current array. |
||
| 5236 | * |
||
| 5237 | * EXAMPLE: <code> |
||
| 5238 | * a([1 => 'bar', 'foo' => 'foo'])->removeLast(); // Arrayy[1 => 'bar'] |
||
| 5239 | * </code> |
||
| 5240 | * |
||
| 5241 | * @return static |
||
| 5242 | * <p>(Immutable)</p> |
||
| 5243 | * |
||
| 5244 | * @psalm-return static<TKey,T> |
||
| 5245 | * @psalm-mutation-free |
||
| 5246 | */ |
||
| 5247 | 7 | View Code Duplication | public function removeLast(): self |
| 5259 | |||
| 5260 | /** |
||
| 5261 | * Removes a particular value from an array (numeric or associative). |
||
| 5262 | * |
||
| 5263 | * EXAMPLE: <code> |
||
| 5264 | * a([1 => 'bar', 'foo' => 'foo'])->removeValue('foo'); // Arrayy[1 => 'bar'] |
||
| 5265 | * </code> |
||
| 5266 | * |
||
| 5267 | * @param mixed $value |
||
| 5268 | * |
||
| 5269 | * @return static |
||
| 5270 | * <p>(Immutable)</p> |
||
| 5271 | * |
||
| 5272 | * @psalm-param T $value |
||
| 5273 | * @psalm-return static<TKey,T> |
||
| 5274 | * @psalm-mutation-free |
||
| 5275 | */ |
||
| 5276 | 8 | public function removeValue($value): self |
|
| 5299 | |||
| 5300 | /** |
||
| 5301 | * Generate array of repeated arrays. |
||
| 5302 | * |
||
| 5303 | * @param int $times <p>How many times has to be repeated.</p> |
||
| 5304 | * |
||
| 5305 | * @return static |
||
| 5306 | * <p>(Immutable)</p> |
||
| 5307 | * |
||
| 5308 | * @psalm-return static<TKey,T> |
||
| 5309 | * @psalm-mutation-free |
||
| 5310 | */ |
||
| 5311 | 1 | public function repeat($times): self |
|
| 5323 | |||
| 5324 | /** |
||
| 5325 | * Replace a key with a new key/value pair. |
||
| 5326 | * |
||
| 5327 | * EXAMPLE: <code> |
||
| 5328 | * $arrayy = a([1 => 'foo', 2 => 'foo2', 3 => 'bar']); |
||
| 5329 | * $arrayy->replace(2, 'notfoo', 'notbar'); // Arrayy[1 => 'foo', 'notfoo' => 'notbar', 3 => 'bar'] |
||
| 5330 | * </code> |
||
| 5331 | * |
||
| 5332 | * @param mixed $oldKey |
||
| 5333 | * @param mixed $newKey |
||
| 5334 | * @param mixed $newValue |
||
| 5335 | * |
||
| 5336 | * @return static |
||
| 5337 | * <p>(Immutable)</p> |
||
| 5338 | * |
||
| 5339 | * @psalm-return static<TKey,T> |
||
| 5340 | * @psalm-mutation-free |
||
| 5341 | */ |
||
| 5342 | 5 | public function replace($oldKey, $newKey, $newValue): self |
|
| 5352 | |||
| 5353 | /** |
||
| 5354 | * Create an array using the current array as values and the other array as keys. |
||
| 5355 | * |
||
| 5356 | * EXAMPLE: <code> |
||
| 5357 | * $firstArray = [ |
||
| 5358 | * 1 => 'one', |
||
| 5359 | * 2 => 'two', |
||
| 5360 | * 3 => 'three', |
||
| 5361 | * ]; |
||
| 5362 | * $secondArray = [ |
||
| 5363 | * 'one' => 1, |
||
| 5364 | * 1 => 'one', |
||
| 5365 | * 2 => 2, |
||
| 5366 | * ]; |
||
| 5367 | * $arrayy = a($firstArray); |
||
| 5368 | * $arrayy->replaceAllKeys($secondArray); // Arrayy[1 => "one", 'one' => "two", 2 => "three"] |
||
| 5369 | * </code> |
||
| 5370 | * |
||
| 5371 | * @param array $keys <p>An array of keys.</p> |
||
| 5372 | * |
||
| 5373 | * @return static |
||
| 5374 | * <p>(Immutable) Arrayy object with keys from the other array.</p> |
||
| 5375 | * |
||
| 5376 | * @psalm-param array<mixed,mixed>|array<mixed,TKey> $keys |
||
| 5377 | * @psalm-return static<TKey,T> |
||
| 5378 | * @psalm-mutation-free |
||
| 5379 | */ |
||
| 5380 | 2 | public function replaceAllKeys(array $keys): self |
|
| 5388 | |||
| 5389 | /** |
||
| 5390 | * Create an array using the current array as keys and the other array as values. |
||
| 5391 | * |
||
| 5392 | * EXAMPLE: <code> |
||
| 5393 | * $firstArray = [ |
||
| 5394 | * 1 => 'one', |
||
| 5395 | * 2 => 'two', |
||
| 5396 | * 3 => 'three', |
||
| 5397 | * ]; |
||
| 5398 | * $secondArray = [ |
||
| 5399 | * 'one' => 1, |
||
| 5400 | * 1 => 'one', |
||
| 5401 | * 2 => 2, |
||
| 5402 | * ]; |
||
| 5403 | * $arrayy = a($firstArray); |
||
| 5404 | * $arrayy->replaceAllValues($secondArray); // Arrayy['one' => 1, 'two' => 'one', 'three' => 2] |
||
| 5405 | * </code> |
||
| 5406 | * |
||
| 5407 | * @param array $array <p>An array of values.</p> |
||
| 5408 | * |
||
| 5409 | * @return static |
||
| 5410 | * <p>(Immutable) Arrayy object with values from the other array.</p> |
||
| 5411 | * |
||
| 5412 | * @psalm-param array<mixed,T> $array |
||
| 5413 | * @psalm-return static<TKey,T> |
||
| 5414 | * @psalm-mutation-free |
||
| 5415 | */ |
||
| 5416 | 2 | public function replaceAllValues(array $array): self |
|
| 5424 | |||
| 5425 | /** |
||
| 5426 | * Replace the keys in an array with another set. |
||
| 5427 | * |
||
| 5428 | * EXAMPLE: <code> |
||
| 5429 | * a([1 => 'bar', 'foo' => 'foo'])->replaceKeys([1 => 2, 'foo' => 'replaced']); // Arrayy[2 => 'bar', 'replaced' => 'foo'] |
||
| 5430 | * </code> |
||
| 5431 | * |
||
| 5432 | * @param array $keys <p>An array of keys matching the array's size</p> |
||
| 5433 | * |
||
| 5434 | * @return static |
||
| 5435 | * <p>(Immutable)</p> |
||
| 5436 | * |
||
| 5437 | * @psalm-param array<mixed,mixed>|array<mixed,TKey> $keys |
||
| 5438 | * @psalm-return static<TKey,T> |
||
| 5439 | * @psalm-mutation-free |
||
| 5440 | */ |
||
| 5441 | 1 | public function replaceKeys(array $keys): self |
|
| 5452 | |||
| 5453 | /** |
||
| 5454 | * Replace the first matched value in an array. |
||
| 5455 | * |
||
| 5456 | * EXAMPLE: <code> |
||
| 5457 | * $testArray = ['bar', 'foo' => 'foo', 'foobar' => 'foobar']; |
||
| 5458 | * a($testArray)->replaceOneValue('foo', 'replaced'); // Arrayy['bar', 'foo' => 'replaced', 'foobar' => 'foobar'] |
||
| 5459 | * </code> |
||
| 5460 | * |
||
| 5461 | * @param mixed $search <p>The value to replace.</p> |
||
| 5462 | * @param mixed $replacement <p>The value to replace.</p> |
||
| 5463 | * |
||
| 5464 | * @return static |
||
| 5465 | * <p>(Immutable)</p> |
||
| 5466 | * |
||
| 5467 | * @psalm-return static<TKey,T> |
||
| 5468 | * @psalm-mutation-free |
||
| 5469 | */ |
||
| 5470 | 3 | View Code Duplication | public function replaceOneValue($search, $replacement = ''): self |
| 5485 | |||
| 5486 | /** |
||
| 5487 | * Replace values in the current array. |
||
| 5488 | * |
||
| 5489 | * EXAMPLE: <code> |
||
| 5490 | * $testArray = ['bar', 'foo' => 'foo', 'foobar' => 'foobar']; |
||
| 5491 | * a($testArray)->replaceValues('foo', 'replaced'); // Arrayy['bar', 'foo' => 'replaced', 'foobar' => 'replacedbar'] |
||
| 5492 | * </code> |
||
| 5493 | * |
||
| 5494 | * @param mixed $search <p>The value to replace.</p> |
||
| 5495 | * @param mixed $replacement <p>What to replace it with.</p> |
||
| 5496 | * |
||
| 5497 | * @return static |
||
| 5498 | * <p>(Immutable)</p> |
||
| 5499 | * |
||
| 5500 | * @psalm-return static<TKey,T> |
||
| 5501 | * @psalm-mutation-free |
||
| 5502 | */ |
||
| 5503 | 1 | public function replaceValues($search, $replacement = ''): self |
|
| 5515 | |||
| 5516 | /** |
||
| 5517 | * Get the last elements from index $from until the end of this array. |
||
| 5518 | * |
||
| 5519 | * EXAMPLE: <code> |
||
| 5520 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->rest(2); // Arrayy[0 => 'lall'] |
||
| 5521 | * </code> |
||
| 5522 | * |
||
| 5523 | * @param int $from |
||
| 5524 | * |
||
| 5525 | * @return static |
||
| 5526 | * <p>(Immutable)</p> |
||
| 5527 | * |
||
| 5528 | * @psalm-return static<TKey,T> |
||
| 5529 | * @psalm-mutation-free |
||
| 5530 | */ |
||
| 5531 | 15 | View Code Duplication | public function rest(int $from = 1): self |
| 5541 | |||
| 5542 | /** |
||
| 5543 | * Return the array in the reverse order. |
||
| 5544 | * |
||
| 5545 | * EXAMPLE: <code> |
||
| 5546 | * a([1, 2, 3])->reverse(); // self[3, 2, 1] |
||
| 5547 | * </code> |
||
| 5548 | * |
||
| 5549 | * @return $this |
||
| 5550 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 5551 | * |
||
| 5552 | * @psalm-return static<TKey,T> |
||
| 5553 | */ |
||
| 5554 | 9 | public function reverse(): self |
|
| 5562 | |||
| 5563 | /** |
||
| 5564 | * Sort an array in reverse order. |
||
| 5565 | * |
||
| 5566 | * @param int $sort_flags [optional] <p> |
||
| 5567 | * You may modify the behavior of the sort using the optional |
||
| 5568 | * parameter sort_flags, for details |
||
| 5569 | * see sort. |
||
| 5570 | * </p> |
||
| 5571 | * |
||
| 5572 | * @return $this |
||
| 5573 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 5574 | * |
||
| 5575 | * @psalm-return static<TKey,T> |
||
| 5576 | */ |
||
| 5577 | 4 | public function rsort(int $sort_flags = 0): self |
|
| 5585 | |||
| 5586 | /** |
||
| 5587 | * Sort an array in reverse order. |
||
| 5588 | * |
||
| 5589 | * @param int $sort_flags [optional] <p> |
||
| 5590 | * You may modify the behavior of the sort using the optional |
||
| 5591 | * parameter sort_flags, for details |
||
| 5592 | * see sort. |
||
| 5593 | * </p> |
||
| 5594 | * |
||
| 5595 | * @return $this |
||
| 5596 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 5597 | * |
||
| 5598 | * @psalm-return static<TKey,T> |
||
| 5599 | * @psalm-mutation-free |
||
| 5600 | */ |
||
| 5601 | 4 | public function rsortImmutable(int $sort_flags = 0): self |
|
| 5612 | |||
| 5613 | /** |
||
| 5614 | * Search for the first index of the current array via $value. |
||
| 5615 | * |
||
| 5616 | * EXAMPLE: <code> |
||
| 5617 | * a(['fòô' => 'bàř', 'lall' => 'bàř'])->searchIndex('bàř'); // Arrayy[0 => 'fòô'] |
||
| 5618 | * </code> |
||
| 5619 | * |
||
| 5620 | * @param mixed $value |
||
| 5621 | * |
||
| 5622 | * @return false|float|int|string |
||
| 5623 | * <p>Will return <b>FALSE</b> if the value can't be found.</p> |
||
| 5624 | * @psalm-mutation-free |
||
| 5625 | */ |
||
| 5626 | 21 | public function searchIndex($value) |
|
| 5636 | |||
| 5637 | /** |
||
| 5638 | * Search for the value of the current array via $index. |
||
| 5639 | * |
||
| 5640 | * EXAMPLE: <code> |
||
| 5641 | * a(['fòô' => 'bàř'])->searchValue('fòô'); // Arrayy[0 => 'bàř'] |
||
| 5642 | * </code> |
||
| 5643 | * |
||
| 5644 | * @param mixed $index |
||
| 5645 | * |
||
| 5646 | * @return static |
||
| 5647 | * <p>(Immutable) Will return a empty Arrayy if the value wasn't found.</p> |
||
| 5648 | * |
||
| 5649 | * @psalm-return static<TKey,T> |
||
| 5650 | * @psalm-mutation-free |
||
| 5651 | */ |
||
| 5652 | 9 | public function searchValue($index): self |
|
| 5682 | |||
| 5683 | /** |
||
| 5684 | * Set a value for the current array (optional using dot-notation). |
||
| 5685 | * |
||
| 5686 | * EXAMPLE: <code> |
||
| 5687 | * $arrayy = a(['Lars' => ['lastname' => 'Moelleken']]); |
||
| 5688 | * $arrayy->set('Lars.lastname', 'Müller'); // Arrayy['Lars', ['lastname' => 'Müller']]] |
||
| 5689 | * </code> |
||
| 5690 | * |
||
| 5691 | * @param string $key <p>The key to set.</p> |
||
| 5692 | * @param mixed $value <p>Its value.</p> |
||
| 5693 | * |
||
| 5694 | * @return $this |
||
| 5695 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 5696 | * |
||
| 5697 | * @psalm-param TKey $key |
||
| 5698 | * @psalm-param T $value |
||
| 5699 | * @psalm-return static<TKey,T> |
||
| 5700 | */ |
||
| 5701 | 28 | public function set($key, $value): self |
|
| 5707 | |||
| 5708 | /** |
||
| 5709 | * Get a value from a array and set it if it was not. |
||
| 5710 | * |
||
| 5711 | * WARNING: this method only set the value, if the $key is not already set |
||
| 5712 | * |
||
| 5713 | * EXAMPLE: <code> |
||
| 5714 | * $arrayy = a([1 => 1, 2 => 2, 3 => 3]); |
||
| 5715 | * $arrayy->setAndGet(1, 4); // 1 |
||
| 5716 | * $arrayy->setAndGet(0, 4); // 4 |
||
| 5717 | * </code> |
||
| 5718 | * |
||
| 5719 | * @param mixed $key <p>The key</p> |
||
| 5720 | * @param mixed $fallback <p>The default value to set if it isn't.</p> |
||
| 5721 | * |
||
| 5722 | * @return mixed |
||
| 5723 | * <p>(Mutable)</p> |
||
| 5724 | */ |
||
| 5725 | 11 | public function setAndGet($key, $fallback = null) |
|
| 5736 | |||
| 5737 | /** |
||
| 5738 | * Shifts a specified value off the beginning of array. |
||
| 5739 | * |
||
| 5740 | * @return mixed |
||
| 5741 | * <p>(Mutable) A shifted element from the current array.</p> |
||
| 5742 | */ |
||
| 5743 | 5 | public function shift() |
|
| 5749 | |||
| 5750 | /** |
||
| 5751 | * Shuffle the current array. |
||
| 5752 | * |
||
| 5753 | * EXAMPLE: <code> |
||
| 5754 | * a([1 => 'bar', 'foo' => 'foo'])->shuffle(); // e.g.: Arrayy[['foo' => 'foo', 1 => 'bar']] |
||
| 5755 | * </code> |
||
| 5756 | * |
||
| 5757 | * @param bool $secure <p>using a CSPRNG | @link https://paragonie.com/b/JvICXzh_jhLyt4y3</p> |
||
| 5758 | * @param array $array [optional] |
||
| 5759 | * |
||
| 5760 | * @return static |
||
| 5761 | * <p>(Immutable)</p> |
||
| 5762 | * |
||
| 5763 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 5764 | * @psalm-return static<TKey,T> |
||
| 5765 | * |
||
| 5766 | * @noinspection BadExceptionsProcessingInspection |
||
| 5767 | * @noinspection RandomApiMigrationInspection |
||
| 5768 | * @noinspection NonSecureShuffleUsageInspection |
||
| 5769 | */ |
||
| 5770 | 2 | public function shuffle(bool $secure = false, array $array = null): self |
|
| 5808 | |||
| 5809 | /** |
||
| 5810 | * Count the values from the current array. |
||
| 5811 | * |
||
| 5812 | * alias: for "Arrayy->count()" |
||
| 5813 | * |
||
| 5814 | * @param int $mode |
||
| 5815 | * |
||
| 5816 | * @return int |
||
| 5817 | */ |
||
| 5818 | 20 | public function size(int $mode = \COUNT_NORMAL): int |
|
| 5822 | |||
| 5823 | /** |
||
| 5824 | * Checks whether array has exactly $size items. |
||
| 5825 | * |
||
| 5826 | * @param int $size |
||
| 5827 | * |
||
| 5828 | * @return bool |
||
| 5829 | */ |
||
| 5830 | 1 | public function sizeIs(int $size): bool |
|
| 5846 | |||
| 5847 | /** |
||
| 5848 | * Checks whether array has between $fromSize to $toSize items. $toSize can be |
||
| 5849 | * smaller than $fromSize. |
||
| 5850 | * |
||
| 5851 | * @param int $fromSize |
||
| 5852 | * @param int $toSize |
||
| 5853 | * |
||
| 5854 | * @return bool |
||
| 5855 | */ |
||
| 5856 | 1 | public function sizeIsBetween(int $fromSize, int $toSize): bool |
|
| 5876 | |||
| 5877 | /** |
||
| 5878 | * Checks whether array has more than $size items. |
||
| 5879 | * |
||
| 5880 | * @param int $size |
||
| 5881 | * |
||
| 5882 | * @return bool |
||
| 5883 | */ |
||
| 5884 | 1 | View Code Duplication | public function sizeIsGreaterThan(int $size): bool |
| 5898 | |||
| 5899 | /** |
||
| 5900 | * Checks whether array has less than $size items. |
||
| 5901 | * |
||
| 5902 | * @param int $size |
||
| 5903 | * |
||
| 5904 | * @return bool |
||
| 5905 | */ |
||
| 5906 | 1 | View Code Duplication | public function sizeIsLessThan(int $size): bool |
| 5920 | |||
| 5921 | /** |
||
| 5922 | * Counts all elements in an array, or something in an object. |
||
| 5923 | * |
||
| 5924 | * <p> |
||
| 5925 | * For objects, if you have SPL installed, you can hook into count() by implementing interface {@see Countable}. |
||
| 5926 | * The interface has exactly one method, {@see Countable::count()}, which returns the return value for the count() |
||
| 5927 | * function. Please see the {@see Array} section of the manual for a detailed explanation of how arrays are |
||
| 5928 | * implemented and used in PHP. |
||
| 5929 | * </p> |
||
| 5930 | * |
||
| 5931 | * @return int |
||
| 5932 | * <p> |
||
| 5933 | * The number of elements in var, which is |
||
| 5934 | * typically an array, since anything else will have one |
||
| 5935 | * element. |
||
| 5936 | * </p> |
||
| 5937 | * <p> |
||
| 5938 | * If var is not an array or an object with |
||
| 5939 | * implemented Countable interface, |
||
| 5940 | * 1 will be returned. |
||
| 5941 | * There is one exception, if var is &null;, |
||
| 5942 | * 0 will be returned. |
||
| 5943 | * </p> |
||
| 5944 | * <p> |
||
| 5945 | * Caution: count may return 0 for a variable that isn't set, |
||
| 5946 | * but it may also return 0 for a variable that has been initialized with an |
||
| 5947 | * empty array. Use isset to test if a variable is set. |
||
| 5948 | * </p> |
||
| 5949 | */ |
||
| 5950 | 10 | public function sizeRecursive(): int |
|
| 5954 | |||
| 5955 | /** |
||
| 5956 | * Extract a slice of the array. |
||
| 5957 | * |
||
| 5958 | * @param int $offset <p>Slice begin index.</p> |
||
| 5959 | * @param int|null $length <p>Length of the slice.</p> |
||
| 5960 | * @param bool $preserveKeys <p>Whether array keys are preserved or no.</p> |
||
| 5961 | * |
||
| 5962 | * @return static |
||
| 5963 | * <p>(Immutable) A slice of the original array with length $length.</p> |
||
| 5964 | * |
||
| 5965 | * @psalm-return static<TKey,T> |
||
| 5966 | * @psalm-mutation-free |
||
| 5967 | */ |
||
| 5968 | 5 | public function slice(int $offset, int $length = null, bool $preserveKeys = false) |
|
| 5981 | |||
| 5982 | /** |
||
| 5983 | * Sort the current array and optional you can keep the keys. |
||
| 5984 | * |
||
| 5985 | * EXAMPLE: <code> |
||
| 5986 | * a(3 => 'd', 2 => 'f', 0 => 'a')->sort(SORT_ASC, SORT_NATURAL, false); // Arrayy[0 => 'a', 1 => 'd', 2 => 'f'] |
||
| 5987 | * </code> |
||
| 5988 | * |
||
| 5989 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 5990 | * @param int $strategy <p>sort_flags => use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 5991 | * <strong>SORT_NATURAL</strong></p> |
||
| 5992 | * @param bool $keepKeys |
||
| 5993 | * |
||
| 5994 | * @return static |
||
| 5995 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 5996 | * |
||
| 5997 | * @psalm-return static<TKey,T> |
||
| 5998 | */ |
||
| 5999 | 20 | public function sort( |
|
| 6013 | |||
| 6014 | /** |
||
| 6015 | * Sort the current array and optional you can keep the keys. |
||
| 6016 | * |
||
| 6017 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 6018 | * @param int $strategy <p>sort_flags => use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 6019 | * <strong>SORT_NATURAL</strong></p> |
||
| 6020 | * @param bool $keepKeys |
||
| 6021 | * |
||
| 6022 | * @return static |
||
| 6023 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 6024 | * |
||
| 6025 | * @psalm-return static<TKey,T> |
||
| 6026 | */ |
||
| 6027 | 12 | public function sortImmutable( |
|
| 6043 | |||
| 6044 | /** |
||
| 6045 | * Sort the current array by key. |
||
| 6046 | * |
||
| 6047 | * EXAMPLE: <code> |
||
| 6048 | * a([1 => 2, 0 => 1])->sortKeys(\SORT_ASC); // Arrayy[0 => 1, 1 => 2] |
||
| 6049 | * </code> |
||
| 6050 | * |
||
| 6051 | * @see http://php.net/manual/en/function.ksort.php |
||
| 6052 | * @see http://php.net/manual/en/function.krsort.php |
||
| 6053 | * |
||
| 6054 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 6055 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 6056 | * <strong>SORT_NATURAL</strong></p> |
||
| 6057 | * |
||
| 6058 | * @return $this |
||
| 6059 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 6060 | * |
||
| 6061 | * @psalm-return static<TKey,T> |
||
| 6062 | */ |
||
| 6063 | 18 | public function sortKeys( |
|
| 6073 | |||
| 6074 | /** |
||
| 6075 | * Sort the current array by key. |
||
| 6076 | * |
||
| 6077 | * @see http://php.net/manual/en/function.ksort.php |
||
| 6078 | * @see http://php.net/manual/en/function.krsort.php |
||
| 6079 | * |
||
| 6080 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 6081 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 6082 | * <strong>SORT_NATURAL</strong></p> |
||
| 6083 | * |
||
| 6084 | * @return $this |
||
| 6085 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 6086 | * |
||
| 6087 | * @psalm-return static<TKey,T> |
||
| 6088 | * @psalm-mutation-free |
||
| 6089 | */ |
||
| 6090 | 8 | public function sortKeysImmutable( |
|
| 6103 | |||
| 6104 | /** |
||
| 6105 | * Sort the current array by value. |
||
| 6106 | * |
||
| 6107 | * EXAMPLE: <code> |
||
| 6108 | * a(3 => 'd', 2 => 'f', 0 => 'a')->sortValueKeepIndex(SORT_ASC, SORT_REGULAR); // Arrayy[0 => 'a', 3 => 'd', 2 => 'f'] |
||
| 6109 | * </code> |
||
| 6110 | * |
||
| 6111 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 6112 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 6113 | * <strong>SORT_NATURAL</strong></p> |
||
| 6114 | * |
||
| 6115 | * @return static |
||
| 6116 | * <p>(Mutable)</p> |
||
| 6117 | * |
||
| 6118 | * @psalm-return static<TKey,T> |
||
| 6119 | */ |
||
| 6120 | 1 | public function sortValueKeepIndex( |
|
| 6126 | |||
| 6127 | /** |
||
| 6128 | * Sort the current array by value. |
||
| 6129 | * |
||
| 6130 | * EXAMPLE: <code> |
||
| 6131 | * a(3 => 'd', 2 => 'f', 0 => 'a')->sortValueNewIndex(SORT_ASC, SORT_NATURAL); // Arrayy[0 => 'a', 1 => 'd', 2 => 'f'] |
||
| 6132 | * </code> |
||
| 6133 | * |
||
| 6134 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 6135 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 6136 | * <strong>SORT_NATURAL</strong></p> |
||
| 6137 | * |
||
| 6138 | * @return static |
||
| 6139 | * <p>(Mutable)</p> |
||
| 6140 | * |
||
| 6141 | * @psalm-return static<TKey,T> |
||
| 6142 | */ |
||
| 6143 | 1 | public function sortValueNewIndex($direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
| 6147 | |||
| 6148 | /** |
||
| 6149 | * Sort a array by value or by a closure. |
||
| 6150 | * |
||
| 6151 | * - If the sorter is null, the array is sorted naturally. |
||
| 6152 | * - Associative (string) keys will be maintained, but numeric keys will be re-indexed. |
||
| 6153 | * |
||
| 6154 | * EXAMPLE: <code> |
||
| 6155 | * $testArray = range(1, 5); |
||
| 6156 | * $under = a($testArray)->sorter( |
||
| 6157 | * function ($value) { |
||
| 6158 | * return $value % 2 === 0; |
||
| 6159 | * } |
||
| 6160 | * ); |
||
| 6161 | * var_dump($under); // Arrayy[1, 3, 5, 2, 4] |
||
| 6162 | * </code> |
||
| 6163 | * |
||
| 6164 | * @param callable|string|null $sorter |
||
| 6165 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or |
||
| 6166 | * <strong>SORT_DESC</strong></p> |
||
| 6167 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 6168 | * <strong>SORT_NATURAL</strong></p> |
||
| 6169 | * |
||
| 6170 | * @return static |
||
| 6171 | * <p>(Immutable)</p> |
||
| 6172 | * |
||
| 6173 | * @psalm-return static<TKey,T> |
||
| 6174 | * @psalm-mutation-free |
||
| 6175 | */ |
||
| 6176 | 1 | public function sorter($sorter = null, $direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
| 6217 | |||
| 6218 | /** |
||
| 6219 | * @param int $offset |
||
| 6220 | * @param int|null $length |
||
| 6221 | * @param array $replacement |
||
| 6222 | * |
||
| 6223 | * @return static |
||
| 6224 | * <p>(Immutable)</p> |
||
| 6225 | * |
||
| 6226 | * @psalm-param array<mixed,mixed>|array<mixed,T> $replacement |
||
| 6227 | * @psalm-return static<TKey,T> |
||
| 6228 | * @psalm-mutation-free |
||
| 6229 | */ |
||
| 6230 | 1 | public function splice(int $offset, int $length = null, $replacement = []): self |
|
| 6247 | |||
| 6248 | /** |
||
| 6249 | * Split an array in the given amount of pieces. |
||
| 6250 | * |
||
| 6251 | * EXAMPLE: <code> |
||
| 6252 | * a(['a' => 1, 'b' => 2])->split(2, true); // Arrayy[['a' => 1], ['b' => 2]] |
||
| 6253 | * </code> |
||
| 6254 | * |
||
| 6255 | * @param int $numberOfPieces |
||
| 6256 | * @param bool $keepKeys |
||
| 6257 | * |
||
| 6258 | * @return static |
||
| 6259 | * <p>(Immutable)</p> |
||
| 6260 | * |
||
| 6261 | * @psalm-return static<TKey,T> |
||
| 6262 | * @psalm-mutation-free |
||
| 6263 | */ |
||
| 6264 | 1 | public function split(int $numberOfPieces = 2, bool $keepKeys = false): self |
|
| 6320 | |||
| 6321 | /** |
||
| 6322 | * Strip all empty items from the current array. |
||
| 6323 | * |
||
| 6324 | * EXAMPLE: <code> |
||
| 6325 | * a(['a' => 1, 'b' => ''])->stripEmpty(); // Arrayy[['a' => 1]] |
||
| 6326 | * </code> |
||
| 6327 | * |
||
| 6328 | * @return static |
||
| 6329 | * <p>(Immutable)</p> |
||
| 6330 | * |
||
| 6331 | * @psalm-return static<TKey,T> |
||
| 6332 | * @psalm-mutation-free |
||
| 6333 | */ |
||
| 6334 | 1 | public function stripEmpty(): self |
|
| 6346 | |||
| 6347 | /** |
||
| 6348 | * Swap two values between positions by key. |
||
| 6349 | * |
||
| 6350 | * EXAMPLE: <code> |
||
| 6351 | * a(['a' => 1, 'b' => ''])->swap('a', 'b'); // Arrayy[['a' => '', 'b' => 1]] |
||
| 6352 | * </code> |
||
| 6353 | * |
||
| 6354 | * @param int|string $swapA <p>a key in the array</p> |
||
| 6355 | * @param int|string $swapB <p>a key in the array</p> |
||
| 6356 | * |
||
| 6357 | * @return static |
||
| 6358 | * <p>(Immutable)</p> |
||
| 6359 | * |
||
| 6360 | * @psalm-return static<TKey,T> |
||
| 6361 | * @psalm-mutation-free |
||
| 6362 | */ |
||
| 6363 | 1 | public function swap($swapA, $swapB): self |
|
| 6375 | |||
| 6376 | /** |
||
| 6377 | * Get the current array from the "Arrayy"-object. |
||
| 6378 | * alias for "getArray()" |
||
| 6379 | * |
||
| 6380 | * @param bool $convertAllArrayyElements <p> |
||
| 6381 | * Convert all Child-"Arrayy" objects also to arrays. |
||
| 6382 | * </p> |
||
| 6383 | * @param bool $preserveKeys <p> |
||
| 6384 | * e.g.: A generator maybe return the same key more then once, |
||
| 6385 | * so maybe you will ignore the keys. |
||
| 6386 | * </p> |
||
| 6387 | * |
||
| 6388 | * @return array |
||
| 6389 | * |
||
| 6390 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 6391 | * @psalm-mutation-free |
||
| 6392 | */ |
||
| 6393 | 930 | public function toArray( |
|
| 6421 | |||
| 6422 | /** |
||
| 6423 | * Get the current array from the "Arrayy"-object as list. |
||
| 6424 | * |
||
| 6425 | * @param bool $convertAllArrayyElements <p> |
||
| 6426 | * Convert all Child-"Arrayy" objects also to arrays. |
||
| 6427 | * </p> |
||
| 6428 | * |
||
| 6429 | * @return array |
||
| 6430 | * |
||
| 6431 | * @psalm-return list<array<TKey,T>> |
||
| 6432 | * @psalm-mutation-free |
||
| 6433 | */ |
||
| 6434 | 1 | public function toList(bool $convertAllArrayyElements = false): array |
|
| 6441 | |||
| 6442 | /** |
||
| 6443 | * Convert the current array to JSON. |
||
| 6444 | * |
||
| 6445 | * EXAMPLE: <code> |
||
| 6446 | * a(['bar', ['foo']])->toJson(); // '["bar",{"1":"foo"}]' |
||
| 6447 | * </code> |
||
| 6448 | * |
||
| 6449 | * @param int $options [optional] <p>e.g. JSON_PRETTY_PRINT</p> |
||
| 6450 | * @param int $depth [optional] <p>Set the maximum depth. Must be greater than zero.</p> |
||
| 6451 | * |
||
| 6452 | * @return string |
||
| 6453 | */ |
||
| 6454 | 12 | public function toJson(int $options = 0, int $depth = 512): string |
|
| 6463 | |||
| 6464 | /** |
||
| 6465 | * @param string[]|null $items [optional] |
||
| 6466 | * @param string[] $helper [optional] |
||
| 6467 | * |
||
| 6468 | * @return static|static[] |
||
| 6469 | * |
||
| 6470 | * @psalm-return static<int, static<TKey,T>> |
||
| 6471 | */ |
||
| 6472 | 1 | public function toPermutation(array $items = null, array $helper = []): self |
|
| 6506 | |||
| 6507 | /** |
||
| 6508 | * Implodes array to a string with specified separator. |
||
| 6509 | * |
||
| 6510 | * @param string $separator [optional] <p>The element's separator.</p> |
||
| 6511 | * |
||
| 6512 | * @return string |
||
| 6513 | * <p>The string representation of array, separated by ",".</p> |
||
| 6514 | */ |
||
| 6515 | 19 | public function toString(string $separator = ','): string |
|
| 6519 | |||
| 6520 | /** |
||
| 6521 | * Return a duplicate free copy of the current array. |
||
| 6522 | * |
||
| 6523 | * EXAMPLE: <code> |
||
| 6524 | * a([2 => 1, 3 => 2, 4 => 2])->uniqueNewIndex(); // Arrayy[1, 2] |
||
| 6525 | * </code> |
||
| 6526 | * |
||
| 6527 | * @return $this |
||
| 6528 | * <p>(Mutable)</p> |
||
| 6529 | * |
||
| 6530 | * @psalm-return static<TKey,T> |
||
| 6531 | */ |
||
| 6532 | 13 | public function uniqueNewIndex(): self |
|
| 6554 | |||
| 6555 | /** |
||
| 6556 | * Return a duplicate free copy of the current array. (with the old keys) |
||
| 6557 | * |
||
| 6558 | * EXAMPLE: <code> |
||
| 6559 | * a([2 => 1, 3 => 2, 4 => 2])->uniqueNewIndex(); // Arrayy[2 => 1, 3 => 2] |
||
| 6560 | * </code> |
||
| 6561 | * |
||
| 6562 | * @return $this |
||
| 6563 | * <p>(Mutable)</p> |
||
| 6564 | * |
||
| 6565 | * @psalm-return static<TKey,T> |
||
| 6566 | */ |
||
| 6567 | 11 | public function uniqueKeepIndex(): self |
|
| 6593 | |||
| 6594 | /** |
||
| 6595 | * alias: for "Arrayy->uniqueNewIndex()" |
||
| 6596 | * |
||
| 6597 | * @return static |
||
| 6598 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
| 6599 | * |
||
| 6600 | * @see Arrayy::unique() |
||
| 6601 | * |
||
| 6602 | * @psalm-return static<TKey,T> |
||
| 6603 | */ |
||
| 6604 | 13 | public function unique(): self |
|
| 6608 | |||
| 6609 | /** |
||
| 6610 | * Prepends one or more values to the beginning of array at once. |
||
| 6611 | * |
||
| 6612 | * @param array ...$args |
||
| 6613 | * |
||
| 6614 | * @return $this |
||
| 6615 | * <p>(Mutable) Return this Arrayy object, with prepended elements to the beginning of array.</p> |
||
| 6616 | * |
||
| 6617 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$args |
||
| 6618 | * @psalm-return static<TKey,T> |
||
| 6619 | */ |
||
| 6620 | 4 | public function unshift(...$args): self |
|
| 6628 | |||
| 6629 | /** |
||
| 6630 | * Tests whether the given closure return something valid for all elements of this array. |
||
| 6631 | * |
||
| 6632 | * @param \Closure $closure the predicate |
||
| 6633 | * |
||
| 6634 | * @return bool |
||
| 6635 | * <p>TRUE, if the predicate yields TRUE for all elements, FALSE otherwise.</p> |
||
| 6636 | */ |
||
| 6637 | 1 | View Code Duplication | public function validate(\Closure $closure): bool |
| 6647 | |||
| 6648 | /** |
||
| 6649 | * Get all values from a array. |
||
| 6650 | * |
||
| 6651 | * EXAMPLE: <code> |
||
| 6652 | * $arrayy = a([1 => 'foo', 2 => 'foo2', 3 => 'bar']); |
||
| 6653 | * $arrayyTmp->values(); // Arrayy[0 => 'foo', 1 => 'foo2', 2 => 'bar'] |
||
| 6654 | * </code> |
||
| 6655 | * |
||
| 6656 | * @return static |
||
| 6657 | * <p>(Immutable)</p> |
||
| 6658 | * |
||
| 6659 | * @psalm-return static<TKey,T> |
||
| 6660 | * @psalm-mutation-free |
||
| 6661 | */ |
||
| 6662 | 2 | public function values(): self |
|
| 6675 | |||
| 6676 | /** |
||
| 6677 | * Apply the given function to every element in the array, discarding the results. |
||
| 6678 | * |
||
| 6679 | * EXAMPLE: <code> |
||
| 6680 | * $callable = function (&$value, $key) { |
||
| 6681 | * $value = $key; |
||
| 6682 | * }; |
||
| 6683 | * $arrayy = a([1, 2, 3]); |
||
| 6684 | * $arrayy->walk($callable); // Arrayy[0, 1, 2] |
||
| 6685 | * </code> |
||
| 6686 | * |
||
| 6687 | * @param callable $callable |
||
| 6688 | * @param bool $recursive [optional] <p>Whether array will be walked recursively or no</p> |
||
| 6689 | * @param mixed $userData [optional] <p> |
||
| 6690 | * If the optional $userData parameter is supplied, |
||
| 6691 | * it will be passed as the third parameter to the $callable. |
||
| 6692 | * </p> |
||
| 6693 | * |
||
| 6694 | * @return $this |
||
| 6695 | * <p>(Mutable) Return this Arrayy object, with modified elements.</p> |
||
| 6696 | * |
||
| 6697 | * @psalm-return static<TKey,T> |
||
| 6698 | */ |
||
| 6699 | 12 | public function walk( |
|
| 6725 | |||
| 6726 | /** |
||
| 6727 | * Returns a collection of matching items. |
||
| 6728 | * |
||
| 6729 | * @param string $keyOrPropertyOrMethod the property or method to evaluate |
||
| 6730 | * @param mixed $value the value to match |
||
| 6731 | * |
||
| 6732 | * @throws \InvalidArgumentException if property or method is not defined |
||
| 6733 | * |
||
| 6734 | * @return static |
||
| 6735 | * |
||
| 6736 | * @psalm-param T $value |
||
| 6737 | * @psalm-return static<TKey,T> |
||
| 6738 | */ |
||
| 6739 | 1 | public function where(string $keyOrPropertyOrMethod, $value): self |
|
| 6752 | |||
| 6753 | /** |
||
| 6754 | * Convert an array into a object. |
||
| 6755 | * |
||
| 6756 | * @param array $array |
||
| 6757 | * |
||
| 6758 | * @return \stdClass |
||
| 6759 | * |
||
| 6760 | * @psalm-param array<mixed,mixed> $array |
||
| 6761 | */ |
||
| 6762 | 4 | final protected static function arrayToObject(array $array = []): \stdClass |
|
| 6781 | |||
| 6782 | /** |
||
| 6783 | * @param array|\Generator|null $input <p> |
||
| 6784 | * An array containing keys to return. |
||
| 6785 | * </p> |
||
| 6786 | * @param mixed|null $search_values [optional] <p> |
||
| 6787 | * If specified, then only keys containing these values are returned. |
||
| 6788 | * </p> |
||
| 6789 | * @param bool $strict [optional] <p> |
||
| 6790 | * Determines if strict comparison (===) should be used during the |
||
| 6791 | * search. |
||
| 6792 | * </p> |
||
| 6793 | * |
||
| 6794 | * @return array |
||
| 6795 | * <p>an array of all the keys in input</p> |
||
| 6796 | * |
||
| 6797 | * @psalm-param array<mixed,mixed>|\Generator<TKey,T>|null $input |
||
| 6798 | * @psalm-return array<TKey|mixed> |
||
| 6799 | * @psalm-mutation-free |
||
| 6800 | */ |
||
| 6801 | 11 | protected function array_keys_recursive( |
|
| 6862 | |||
| 6863 | /** |
||
| 6864 | * @param mixed $path |
||
| 6865 | * @param callable $callable |
||
| 6866 | * @param array|null $currentOffset |
||
| 6867 | * |
||
| 6868 | * @return void |
||
| 6869 | * |
||
| 6870 | * @psalm-param array<mixed,mixed>|array<TKey,T>|null $currentOffset |
||
| 6871 | * @psalm-mutation-free |
||
| 6872 | */ |
||
| 6873 | 10 | protected function callAtPath($path, $callable, &$currentOffset = null) |
|
| 6902 | |||
| 6903 | /** |
||
| 6904 | * Extracts the value of the given property or method from the object. |
||
| 6905 | * |
||
| 6906 | * @param static $object <p>The object to extract the value from.</p> |
||
| 6907 | * @param string $keyOrPropertyOrMethod <p>The property or method for which the |
||
| 6908 | * value should be extracted.</p> |
||
| 6909 | * |
||
| 6910 | * @throws \InvalidArgumentException if the method or property is not defined |
||
| 6911 | * |
||
| 6912 | * @return mixed |
||
| 6913 | * <p>The value extracted from the specified property or method.</p> |
||
| 6914 | * |
||
| 6915 | * @psalm-param self<TKey,T> $object |
||
| 6916 | */ |
||
| 6917 | 1 | final protected function extractValue(self $object, string $keyOrPropertyOrMethod) |
|
| 6939 | |||
| 6940 | /** |
||
| 6941 | * create a fallback for array |
||
| 6942 | * |
||
| 6943 | * 1. use the current array, if it's a array |
||
| 6944 | * 2. fallback to empty array, if there is nothing |
||
| 6945 | * 3. call "getArray()" on object, if there is a "Arrayy"-object |
||
| 6946 | * 4. call "createFromObject()" on object, if there is a "\Traversable"-object |
||
| 6947 | * 5. call "__toArray()" on object, if the method exists |
||
| 6948 | * 6. cast a string or object with "__toString()" into an array |
||
| 6949 | * 7. throw a "InvalidArgumentException"-Exception |
||
| 6950 | * |
||
| 6951 | * @param mixed $data |
||
| 6952 | * |
||
| 6953 | * @throws \InvalidArgumentException |
||
| 6954 | * |
||
| 6955 | * @return array |
||
| 6956 | * |
||
| 6957 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 6958 | */ |
||
| 6959 | 1205 | protected function fallbackForArray(&$data): array |
|
| 6969 | |||
| 6970 | /** |
||
| 6971 | * @param bool $preserveKeys <p> |
||
| 6972 | * e.g.: A generator maybe return the same key more then once, |
||
| 6973 | * so maybe you will ignore the keys. |
||
| 6974 | * </p> |
||
| 6975 | * |
||
| 6976 | * @return bool |
||
| 6977 | * |
||
| 6978 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
| 6979 | * @psalm-mutation-free :/ |
||
| 6980 | */ |
||
| 6981 | 1117 | protected function generatorToArray(bool $preserveKeys = true) |
|
| 6992 | |||
| 6993 | /** |
||
| 6994 | * Get correct PHP constant for direction. |
||
| 6995 | * |
||
| 6996 | * @param int|string $direction |
||
| 6997 | * |
||
| 6998 | * @return int |
||
| 6999 | * @psalm-mutation-free |
||
| 7000 | */ |
||
| 7001 | 43 | protected function getDirection($direction): int |
|
| 7023 | |||
| 7024 | /** |
||
| 7025 | * @return TypeCheckInterface[] |
||
| 7026 | * |
||
| 7027 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
| 7028 | */ |
||
| 7029 | 24 | protected function getPropertiesFromPhpDoc() |
|
| 7084 | |||
| 7085 | /** |
||
| 7086 | * @param mixed $glue |
||
| 7087 | * @param mixed $pieces |
||
| 7088 | * @param bool $useKeys |
||
| 7089 | * |
||
| 7090 | * @return string |
||
| 7091 | * @psalm-mutation-free |
||
| 7092 | */ |
||
| 7093 | 36 | protected function implode_recursive( |
|
| 7126 | |||
| 7127 | /** |
||
| 7128 | * @param mixed $needle <p> |
||
| 7129 | * The searched value. |
||
| 7130 | * </p> |
||
| 7131 | * <p> |
||
| 7132 | * If needle is a string, the comparison is done |
||
| 7133 | * in a case-sensitive manner. |
||
| 7134 | * </p> |
||
| 7135 | * @param array|\Generator|null $haystack <p> |
||
| 7136 | * The array. |
||
| 7137 | * </p> |
||
| 7138 | * @param bool $strict [optional] <p> |
||
| 7139 | * If the third parameter strict is set to true |
||
| 7140 | * then the in_array function will also check the |
||
| 7141 | * types of the |
||
| 7142 | * needle in the haystack. |
||
| 7143 | * </p> |
||
| 7144 | * |
||
| 7145 | * @return bool |
||
| 7146 | * <p>true if needle is found in the array, false otherwise</p> |
||
| 7147 | * |
||
| 7148 | * @psalm-param array<mixed,mixed>|\Generator<TKey,T>|null $haystack |
||
| 7149 | * @psalm-mutation-free |
||
| 7150 | */ |
||
| 7151 | 19 | protected function in_array_recursive($needle, $haystack = null, $strict = true): bool |
|
| 7176 | |||
| 7177 | /** |
||
| 7178 | * @param mixed $data |
||
| 7179 | * |
||
| 7180 | * @return array|null |
||
| 7181 | * |
||
| 7182 | * @psalm-return array<mixed,mixed>|array<TKey,T>|null |
||
| 7183 | */ |
||
| 7184 | 1205 | protected function internalGetArray(&$data) |
|
| 7235 | |||
| 7236 | /** |
||
| 7237 | * Internal mechanics of remove method. |
||
| 7238 | * |
||
| 7239 | * @param mixed $key |
||
| 7240 | * |
||
| 7241 | * @return bool |
||
| 7242 | */ |
||
| 7243 | 22 | protected function internalRemove($key): bool |
|
| 7276 | |||
| 7277 | /** |
||
| 7278 | * Internal mechanic of set method. |
||
| 7279 | * |
||
| 7280 | * @param int|string|null $key |
||
| 7281 | * @param mixed $value |
||
| 7282 | * @param bool $checkProperties |
||
| 7283 | * |
||
| 7284 | * @return bool |
||
| 7285 | */ |
||
| 7286 | 1055 | protected function internalSet( |
|
| 7345 | |||
| 7346 | /** |
||
| 7347 | * Convert a object into an array. |
||
| 7348 | * |
||
| 7349 | * @param mixed|object $object |
||
| 7350 | * |
||
| 7351 | * @return array|mixed |
||
| 7352 | * |
||
| 7353 | * @psalm-mutation-free |
||
| 7354 | */ |
||
| 7355 | 5 | protected static function objectToArray($object) |
|
| 7368 | |||
| 7369 | /** |
||
| 7370 | * @param array $data |
||
| 7371 | * @param bool $checkPropertiesInConstructor |
||
| 7372 | * |
||
| 7373 | * @return void |
||
| 7374 | * |
||
| 7375 | * @psalm-param array<mixed,T> $data |
||
| 7376 | */ |
||
| 7377 | 1203 | protected function setInitialValuesAndProperties(array &$data, bool $checkPropertiesInConstructor) |
|
| 7422 | |||
| 7423 | /** |
||
| 7424 | * sorting keys |
||
| 7425 | * |
||
| 7426 | * @param array $elements |
||
| 7427 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 7428 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 7429 | * <strong>SORT_NATURAL</strong></p> |
||
| 7430 | * |
||
| 7431 | * @return $this |
||
| 7432 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 7433 | * |
||
| 7434 | * @psalm-param array<mixed,mixed>|array<mixed|TKey,T> $elements |
||
| 7435 | * @psalm-return static<TKey,T> |
||
| 7436 | */ |
||
| 7437 | 18 | protected function sorterKeys( |
|
| 7458 | |||
| 7459 | /** |
||
| 7460 | * @param array $elements <p>Warning: used as reference</p> |
||
| 7461 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 7462 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 7463 | * <strong>SORT_NATURAL</strong></p> |
||
| 7464 | * @param bool $keepKeys |
||
| 7465 | * |
||
| 7466 | * @return $this |
||
| 7467 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 7468 | * |
||
| 7469 | * @psalm-param array<mixed,mixed>|array<mixed|TKey,T> $elements |
||
| 7470 | * @psalm-return static<TKey,T> |
||
| 7471 | */ |
||
| 7472 | 24 | protected function sorting( |
|
| 7506 | |||
| 7507 | /** |
||
| 7508 | * @param array $array |
||
| 7509 | * |
||
| 7510 | * @return array |
||
| 7511 | * |
||
| 7512 | * @psalm-mutation-free |
||
| 7513 | */ |
||
| 7514 | 25 | private function getArrayRecursiveHelperArrayy(array $array) |
|
| 7536 | |||
| 7537 | /** |
||
| 7538 | * @param int|string|null $key |
||
| 7539 | * @param mixed $value |
||
| 7540 | * |
||
| 7541 | * @return void |
||
| 7542 | */ |
||
| 7543 | 112 | private function checkType($key, $value) |
|
| 7561 | } |
||
| 7562 |
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..