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 | 1198 | 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 | 126 | 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>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
| 227 | * |
||
| 228 | * @psalm-param T $value |
||
| 229 | * @psalm-return static<TKey,T> |
||
| 230 | */ |
||
| 231 | 13 | public function add($value, $key = null) |
|
| 232 | { |
||
| 233 | 13 | if ($key !== null) { |
|
| 234 | 5 | $get = $this->get($key); |
|
| 235 | 5 | if ($get !== null) { |
|
| 236 | 1 | $value = \array_merge_recursive( |
|
| 237 | 1 | !$get instanceof self ? [$get] : $get->getArray(), |
|
| 238 | 1 | !\is_array($value) ? [$value] : $value |
|
| 239 | ); |
||
| 240 | } |
||
| 241 | |||
| 242 | 5 | $this->internalSet($key, $value); |
|
| 243 | |||
| 244 | 4 | return $this; |
|
| 245 | } |
||
| 246 | |||
| 247 | 8 | return $this->append($value); |
|
| 248 | } |
||
| 249 | |||
| 250 | /** |
||
| 251 | * Append a (key) + value to the current array. |
||
| 252 | * |
||
| 253 | * EXAMPLE: <code> |
||
| 254 | * a(['fòô' => 'bàř'])->append('foo'); // Arrayy['fòô' => 'bàř', 0 => 'foo'] |
||
| 255 | * </code> |
||
| 256 | * |
||
| 257 | * @param mixed $value |
||
| 258 | * @param mixed $key |
||
| 259 | * |
||
| 260 | * @return $this |
||
| 261 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
| 262 | * |
||
| 263 | * @psalm-return static<TKey,T> |
||
| 264 | */ |
||
| 265 | 20 | public function append($value, $key = null): self |
|
| 289 | |||
| 290 | /** |
||
| 291 | * Sort the entries by value. |
||
| 292 | * |
||
| 293 | * @param int $sort_flags [optional] <p> |
||
| 294 | * You may modify the behavior of the sort using the optional |
||
| 295 | * parameter sort_flags, for details |
||
| 296 | * see sort. |
||
| 297 | * </p> |
||
| 298 | * |
||
| 299 | * @return $this |
||
| 300 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 301 | * |
||
| 302 | * @psalm-return static<TKey,T> |
||
| 303 | */ |
||
| 304 | 4 | public function asort(int $sort_flags = 0): self |
|
| 312 | |||
| 313 | /** |
||
| 314 | * Sort the entries by value. |
||
| 315 | * |
||
| 316 | * @param int $sort_flags [optional] <p> |
||
| 317 | * You may modify the behavior of the sort using the optional |
||
| 318 | * parameter sort_flags, for details |
||
| 319 | * see sort. |
||
| 320 | * </p> |
||
| 321 | * |
||
| 322 | * @return $this |
||
| 323 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 324 | * |
||
| 325 | * @psalm-return static<TKey,T> |
||
| 326 | * @psalm-mutation-free |
||
| 327 | */ |
||
| 328 | 4 | public function asortImmutable(int $sort_flags = 0): self |
|
| 339 | |||
| 340 | /** |
||
| 341 | * Counts all elements in an array, or something in an object. |
||
| 342 | * |
||
| 343 | * <p> |
||
| 344 | * For objects, if you have SPL installed, you can hook into count() by implementing interface {@see Countable}. |
||
| 345 | * The interface has exactly one method, {@see Countable::count()}, which returns the return value for the count() |
||
| 346 | * function. Please see the {@see Array} section of the manual for a detailed explanation of how arrays are |
||
| 347 | * implemented and used in PHP. |
||
| 348 | * </p> |
||
| 349 | * |
||
| 350 | * @see http://php.net/manual/en/function.count.php |
||
| 351 | * |
||
| 352 | * @param int $mode [optional] If the optional mode parameter is set to |
||
| 353 | * COUNT_RECURSIVE (or 1), count |
||
| 354 | * will recursively count the array. This is particularly useful for |
||
| 355 | * counting all the elements of a multidimensional array. count does not detect infinite recursion. |
||
| 356 | * |
||
| 357 | * @return int |
||
| 358 | * <p> |
||
| 359 | * The number of elements in var, which is |
||
| 360 | * typically an array, since anything else will have one |
||
| 361 | * element. |
||
| 362 | * </p> |
||
| 363 | * <p> |
||
| 364 | * If var is not an array or an object with |
||
| 365 | * implemented Countable interface, |
||
| 366 | * 1 will be returned. |
||
| 367 | * There is one exception, if var is &null;, |
||
| 368 | * 0 will be returned. |
||
| 369 | * </p> |
||
| 370 | * <p> |
||
| 371 | * Caution: count may return 0 for a variable that isn't set, |
||
| 372 | * but it may also return 0 for a variable that has been initialized with an |
||
| 373 | * empty array. Use isset to test if a variable is set. |
||
| 374 | * </p> |
||
| 375 | * @psalm-mutation-free |
||
| 376 | */ |
||
| 377 | 148 | public function count(int $mode = \COUNT_NORMAL): int |
|
| 389 | |||
| 390 | /** |
||
| 391 | * Exchange the array for another one. |
||
| 392 | * |
||
| 393 | * @param array|static $data |
||
| 394 | * |
||
| 395 | * @return array |
||
| 396 | * |
||
| 397 | * @psalm-param array<TKey,T>|self<TKey,T> $data |
||
| 398 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 399 | */ |
||
| 400 | 1 | public function exchangeArray($data): array |
|
| 406 | |||
| 407 | /** |
||
| 408 | * Creates a copy of the ArrayyObject. |
||
| 409 | * |
||
| 410 | * @return array |
||
| 411 | * |
||
| 412 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 413 | */ |
||
| 414 | 6 | public function getArrayCopy(): array |
|
| 420 | |||
| 421 | /** |
||
| 422 | * Returns a new iterator, thus implementing the \Iterator interface. |
||
| 423 | * |
||
| 424 | * @return \Iterator<mixed, mixed> |
||
| 425 | * <p>An iterator for the values in the array.</p> |
||
| 426 | * @psalm-return \Iterator<array-key|TKey, mixed|T> |
||
| 427 | */ |
||
| 428 | 27 | public function getIterator(): \Iterator |
|
| 445 | |||
| 446 | /** |
||
| 447 | * Gets the iterator classname for the ArrayObject. |
||
| 448 | * |
||
| 449 | * @return string |
||
| 450 | * |
||
| 451 | * @psalm-return class-string |
||
| 452 | */ |
||
| 453 | 26 | public function getIteratorClass(): string |
|
| 457 | |||
| 458 | /** |
||
| 459 | * Sort the entries by key. |
||
| 460 | * |
||
| 461 | * @param int $sort_flags [optional] <p> |
||
| 462 | * You may modify the behavior of the sort using the optional |
||
| 463 | * parameter sort_flags, for details |
||
| 464 | * see sort. |
||
| 465 | * </p> |
||
| 466 | * |
||
| 467 | * @return $this |
||
| 468 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 469 | * |
||
| 470 | * @psalm-return static<TKey,T> |
||
| 471 | */ |
||
| 472 | 4 | public function ksort(int $sort_flags = 0): self |
|
| 480 | |||
| 481 | /** |
||
| 482 | * Sort the entries by key. |
||
| 483 | * |
||
| 484 | * @param int $sort_flags [optional] <p> |
||
| 485 | * You may modify the behavior of the sort using the optional |
||
| 486 | * parameter sort_flags, for details |
||
| 487 | * see sort. |
||
| 488 | * </p> |
||
| 489 | * |
||
| 490 | * @return $this |
||
| 491 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 492 | * |
||
| 493 | * @psalm-return static<TKey,T> |
||
| 494 | */ |
||
| 495 | 4 | public function ksortImmutable(int $sort_flags = 0): self |
|
| 506 | |||
| 507 | /** |
||
| 508 | * Sort an array using a case insensitive "natural order" algorithm. |
||
| 509 | * |
||
| 510 | * @return $this |
||
| 511 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 512 | * |
||
| 513 | * @psalm-return static<TKey,T> |
||
| 514 | */ |
||
| 515 | 8 | public function natcasesort(): self |
|
| 523 | |||
| 524 | /** |
||
| 525 | * Sort an array using a case insensitive "natural order" algorithm. |
||
| 526 | * |
||
| 527 | * @return $this |
||
| 528 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 529 | * |
||
| 530 | * @psalm-return static<TKey,T> |
||
| 531 | * @psalm-mutation-free |
||
| 532 | */ |
||
| 533 | 4 | public function natcasesortImmutable(): self |
|
| 544 | |||
| 545 | /** |
||
| 546 | * Sort entries using a "natural order" algorithm. |
||
| 547 | * |
||
| 548 | * @return $this |
||
| 549 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 550 | * |
||
| 551 | * @psalm-return static<TKey,T> |
||
| 552 | */ |
||
| 553 | 10 | public function natsort(): self |
|
| 561 | |||
| 562 | /** |
||
| 563 | * Sort entries using a "natural order" algorithm. |
||
| 564 | * |
||
| 565 | * @return $this |
||
| 566 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 567 | * |
||
| 568 | * @psalm-return static<TKey,T> |
||
| 569 | * @psalm-mutation-free |
||
| 570 | */ |
||
| 571 | 4 | public function natsortImmutable(): self |
|
| 582 | |||
| 583 | /** |
||
| 584 | * Whether or not an offset exists. |
||
| 585 | * |
||
| 586 | * @param bool|int|string $offset |
||
| 587 | * |
||
| 588 | * @return bool |
||
| 589 | * |
||
| 590 | * @noinspection PhpSillyAssignmentInspection |
||
| 591 | * |
||
| 592 | * @psalm-mutation-free |
||
| 593 | */ |
||
| 594 | 157 | public function offsetExists($offset): bool |
|
| 656 | |||
| 657 | /** |
||
| 658 | * Returns the value at specified offset. |
||
| 659 | * |
||
| 660 | * @param int|string $offset |
||
| 661 | * |
||
| 662 | * @return mixed |
||
| 663 | * <p>Will return null if the offset did not exists.</p> |
||
| 664 | */ |
||
| 665 | 126 | public function &offsetGet($offset) |
|
| 676 | |||
| 677 | /** |
||
| 678 | * Assigns a value to the specified offset + check the type. |
||
| 679 | * |
||
| 680 | * @param int|string|null $offset |
||
| 681 | * @param mixed $value |
||
| 682 | * |
||
| 683 | * @return void |
||
| 684 | */ |
||
| 685 | 27 | public function offsetSet($offset, $value) |
|
| 703 | |||
| 704 | /** |
||
| 705 | * Unset an offset. |
||
| 706 | * |
||
| 707 | * @param int|string $offset |
||
| 708 | * |
||
| 709 | * @return void |
||
| 710 | * <p>(Mutable) Return nothing.</p> |
||
| 711 | */ |
||
| 712 | 25 | public function offsetUnset($offset) |
|
| 763 | |||
| 764 | /** |
||
| 765 | * Serialize the current "Arrayy"-object. |
||
| 766 | * |
||
| 767 | * @return string |
||
| 768 | */ |
||
| 769 | 2 | public function serialize(): string |
|
| 779 | |||
| 780 | /** |
||
| 781 | * Sets the iterator classname for the current "Arrayy"-object. |
||
| 782 | * |
||
| 783 | * @param string $iteratorClass |
||
| 784 | * |
||
| 785 | * @throws \InvalidArgumentException |
||
| 786 | * |
||
| 787 | * @return void |
||
| 788 | * |
||
| 789 | * @psalm-param class-string<\Arrayy\ArrayyIterator> $iteratorClass |
||
| 790 | */ |
||
| 791 | 1189 | public function setIteratorClass($iteratorClass) |
|
| 813 | |||
| 814 | /** |
||
| 815 | * Sort the entries with a user-defined comparison function and maintain key association. |
||
| 816 | * |
||
| 817 | * @param callable $function |
||
| 818 | * |
||
| 819 | * @throws \InvalidArgumentException |
||
| 820 | * |
||
| 821 | * @return $this |
||
| 822 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 823 | * |
||
| 824 | * @psalm-return static<TKey,T> |
||
| 825 | */ |
||
| 826 | 8 | View Code Duplication | public function uasort($function): self |
| 838 | |||
| 839 | /** |
||
| 840 | * Sort the entries with a user-defined comparison function and maintain key association. |
||
| 841 | * |
||
| 842 | * @param callable $function |
||
| 843 | * |
||
| 844 | * @throws \InvalidArgumentException |
||
| 845 | * |
||
| 846 | * @return $this |
||
| 847 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 848 | * |
||
| 849 | * @psalm-return static<TKey,T> |
||
| 850 | * @psalm-mutation-free |
||
| 851 | */ |
||
| 852 | 4 | public function uasortImmutable($function): self |
|
| 863 | |||
| 864 | /** |
||
| 865 | * Sort the entries by keys using a user-defined comparison function. |
||
| 866 | * |
||
| 867 | * @param callable $function |
||
| 868 | * |
||
| 869 | * @throws \InvalidArgumentException |
||
| 870 | * |
||
| 871 | * @return static |
||
| 872 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 873 | * |
||
| 874 | * @psalm-return static<TKey,T> |
||
| 875 | */ |
||
| 876 | 5 | public function uksort($function): self |
|
| 880 | |||
| 881 | /** |
||
| 882 | * Sort the entries by keys using a user-defined comparison function. |
||
| 883 | * |
||
| 884 | * @param callable $function |
||
| 885 | * |
||
| 886 | * @throws \InvalidArgumentException |
||
| 887 | * |
||
| 888 | * @return static |
||
| 889 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 890 | * |
||
| 891 | * @psalm-return static<TKey,T> |
||
| 892 | * @psalm-mutation-free |
||
| 893 | */ |
||
| 894 | 1 | public function uksortImmutable($function): self |
|
| 898 | |||
| 899 | /** |
||
| 900 | * Unserialize an string and return the instance of the "Arrayy"-class. |
||
| 901 | * |
||
| 902 | * @param string $string |
||
| 903 | * |
||
| 904 | * @return $this |
||
| 905 | * |
||
| 906 | * @psalm-return static<TKey,T> |
||
| 907 | */ |
||
| 908 | 2 | public function unserialize($string): self |
|
| 918 | |||
| 919 | /** |
||
| 920 | * Append a (key) + values to the current array. |
||
| 921 | * |
||
| 922 | * EXAMPLE: <code> |
||
| 923 | * a(['fòô' => ['bàř']])->appendArrayValues(['foo1', 'foo2'], 'fòô'); // Arrayy['fòô' => ['bàř', 'foo1', 'foo2']] |
||
| 924 | * </code> |
||
| 925 | * |
||
| 926 | * @param array $values |
||
| 927 | * @param mixed $key |
||
| 928 | * |
||
| 929 | * @return $this |
||
| 930 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
| 931 | * |
||
| 932 | * @psalm-param array<mixed,T> $values |
||
| 933 | * @psalm-param TKey|null $key |
||
| 934 | * @psalm-return static<TKey,T> |
||
| 935 | */ |
||
| 936 | 1 | public function appendArrayValues(array $values, $key = null) |
|
| 962 | |||
| 963 | /** |
||
| 964 | * Add a suffix to each key. |
||
| 965 | * |
||
| 966 | * @param mixed $prefix |
||
| 967 | * |
||
| 968 | * @return static |
||
| 969 | * <p>(Immutable) Return an Arrayy object, with the prefixed keys.</p> |
||
| 970 | * |
||
| 971 | * @psalm-return static<TKey,T> |
||
| 972 | * @psalm-mutation-free |
||
| 973 | */ |
||
| 974 | 10 | View Code Duplication | public function appendToEachKey($prefix): self |
| 993 | |||
| 994 | /** |
||
| 995 | * Add a prefix to each value. |
||
| 996 | * |
||
| 997 | * @param mixed $prefix |
||
| 998 | * |
||
| 999 | * @return static |
||
| 1000 | * <p>(Immutable) Return an Arrayy object, with the prefixed values.</p> |
||
| 1001 | * |
||
| 1002 | * @psalm-return static<TKey,T> |
||
| 1003 | * @psalm-mutation-free |
||
| 1004 | */ |
||
| 1005 | 10 | View Code Duplication | public function appendToEachValue($prefix): self |
| 1024 | |||
| 1025 | /** |
||
| 1026 | * Sort an array in reverse order and maintain index association. |
||
| 1027 | * |
||
| 1028 | * @return $this |
||
| 1029 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1030 | * |
||
| 1031 | * @psalm-return static<TKey,T> |
||
| 1032 | */ |
||
| 1033 | 4 | public function arsort(): self |
|
| 1041 | |||
| 1042 | /** |
||
| 1043 | * Sort an array in reverse order and maintain index association. |
||
| 1044 | * |
||
| 1045 | * @return $this |
||
| 1046 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 1047 | * |
||
| 1048 | * @psalm-return static<TKey,T> |
||
| 1049 | * @psalm-mutation-free |
||
| 1050 | */ |
||
| 1051 | 10 | public function arsortImmutable(): self |
|
| 1061 | |||
| 1062 | /** |
||
| 1063 | * Iterate over the current array and execute a callback for each loop. |
||
| 1064 | * |
||
| 1065 | * EXAMPLE: <code> |
||
| 1066 | * $result = A::create(); |
||
| 1067 | * $closure = function ($value, $key) use ($result) { |
||
| 1068 | * $result[$key] = ':' . $value . ':'; |
||
| 1069 | * }; |
||
| 1070 | * a(['foo', 'bar' => 'bis'])->at($closure); // Arrayy[':foo:', 'bar' => ':bis:'] |
||
| 1071 | * </code> |
||
| 1072 | * |
||
| 1073 | * @param \Closure $closure |
||
| 1074 | * |
||
| 1075 | * @return static |
||
| 1076 | * <p>(Immutable)</p> |
||
| 1077 | * |
||
| 1078 | * @psalm-return static<TKey,T> |
||
| 1079 | * @psalm-mutation-free |
||
| 1080 | */ |
||
| 1081 | 3 | public function at(\Closure $closure): self |
|
| 1095 | |||
| 1096 | /** |
||
| 1097 | * Returns the average value of the current array. |
||
| 1098 | * |
||
| 1099 | * EXAMPLE: <code> |
||
| 1100 | * a([-9, -8, -7, 1.32])->average(2); // -5.67 |
||
| 1101 | * </code> |
||
| 1102 | * |
||
| 1103 | * @param int $decimals <p>The number of decimal-numbers to return.</p> |
||
| 1104 | * |
||
| 1105 | * @return float|int |
||
| 1106 | * <p>The average value.</p> |
||
| 1107 | * @psalm-mutation-free |
||
| 1108 | */ |
||
| 1109 | 10 | public function average($decimals = 0) |
|
| 1123 | |||
| 1124 | /** |
||
| 1125 | * Changes all keys in an array. |
||
| 1126 | * |
||
| 1127 | * @param int $case [optional] <p> Either <strong>CASE_UPPER</strong><br /> |
||
| 1128 | * or <strong>CASE_LOWER</strong> (default)</p> |
||
| 1129 | * |
||
| 1130 | * @return static |
||
| 1131 | * <p>(Immutable)</p> |
||
| 1132 | * |
||
| 1133 | * @psalm-return static<TKey,T> |
||
| 1134 | * @psalm-mutation-free |
||
| 1135 | */ |
||
| 1136 | 1 | public function changeKeyCase(int $case = \CASE_LOWER): self |
|
| 1165 | |||
| 1166 | /** |
||
| 1167 | * Change the path separator of the array wrapper. |
||
| 1168 | * |
||
| 1169 | * By default, the separator is: "." |
||
| 1170 | * |
||
| 1171 | * @param string $separator <p>Separator to set.</p> |
||
| 1172 | * |
||
| 1173 | * @return $this |
||
| 1174 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1175 | * |
||
| 1176 | * @psalm-return static<TKey,T> |
||
| 1177 | */ |
||
| 1178 | 11 | public function changeSeparator($separator): self |
|
| 1184 | |||
| 1185 | /** |
||
| 1186 | * Create a chunked version of the current array. |
||
| 1187 | * |
||
| 1188 | * EXAMPLE: <code> |
||
| 1189 | * a([-9, -8, -7, 1.32])->chunk(2); // Arrayy[[-9, -8], [-7, 1.32]] |
||
| 1190 | * </code> |
||
| 1191 | * |
||
| 1192 | * @param int $size <p>Size of each chunk.</p> |
||
| 1193 | * @param bool $preserveKeys <p>Whether array keys are preserved or no.</p> |
||
| 1194 | * |
||
| 1195 | * @return static |
||
| 1196 | * <p>(Immutable) A new array of chunks from the original array.</p> |
||
| 1197 | * |
||
| 1198 | * @psalm-return static<TKey,T> |
||
| 1199 | * @psalm-mutation-free |
||
| 1200 | */ |
||
| 1201 | 5 | public function chunk($size, $preserveKeys = false): self |
|
| 1209 | |||
| 1210 | /** |
||
| 1211 | * Clean all falsy values from the current array. |
||
| 1212 | * |
||
| 1213 | * EXAMPLE: <code> |
||
| 1214 | * a([-8 => -9, 1, 2 => false])->clean(); // Arrayy[-8 => -9, 1] |
||
| 1215 | * </code> |
||
| 1216 | * |
||
| 1217 | * @return static |
||
| 1218 | * <p>(Immutable)</p> |
||
| 1219 | * |
||
| 1220 | * @psalm-return static<TKey,T> |
||
| 1221 | * @psalm-mutation-free |
||
| 1222 | */ |
||
| 1223 | 8 | public function clean(): self |
|
| 1231 | |||
| 1232 | /** |
||
| 1233 | * WARNING!!! -> Clear the current full array or a $key of it. |
||
| 1234 | * |
||
| 1235 | * EXAMPLE: <code> |
||
| 1236 | * a([-8 => -9, 1, 2 => false])->clear(); // Arrayy[] |
||
| 1237 | * </code> |
||
| 1238 | * |
||
| 1239 | * @param int|int[]|string|string[]|null $key |
||
| 1240 | * |
||
| 1241 | * @return $this |
||
| 1242 | * <p>(Mutable) Return this Arrayy object, with an empty array.</p> |
||
| 1243 | * |
||
| 1244 | * @psalm-return static<TKey,T> |
||
| 1245 | */ |
||
| 1246 | 10 | public function clear($key = null): self |
|
| 1265 | |||
| 1266 | /** |
||
| 1267 | * Check if an item is in the current array. |
||
| 1268 | * |
||
| 1269 | * EXAMPLE: <code> |
||
| 1270 | * a([1, true])->contains(true); // true |
||
| 1271 | * </code> |
||
| 1272 | * |
||
| 1273 | * @param float|int|string $value |
||
| 1274 | * @param bool $recursive |
||
| 1275 | * @param bool $strict |
||
| 1276 | * |
||
| 1277 | * @return bool |
||
| 1278 | * @psalm-mutation-free |
||
| 1279 | */ |
||
| 1280 | 23 | public function contains($value, bool $recursive = false, bool $strict = true): bool |
|
| 1281 | { |
||
| 1282 | 23 | if ($recursive === true) { |
|
| 1283 | 18 | return $this->in_array_recursive($value, $this->toArray(), $strict); |
|
| 1284 | } |
||
| 1285 | |||
| 1286 | /** @noinspection PhpParameterByRefIsNotUsedAsReferenceInspection */ |
||
| 1287 | 14 | foreach ($this->getGeneratorByReference() as &$valueFromArray) { |
|
| 1288 | 11 | if ($strict) { |
|
| 1289 | 11 | if ($value === $valueFromArray) { |
|
| 1290 | 11 | return true; |
|
| 1291 | } |
||
| 1292 | } else { |
||
| 1293 | /** @noinspection NestedPositiveIfStatementsInspection */ |
||
| 1294 | if ($value == $valueFromArray) { |
||
| 1295 | return true; |
||
| 1296 | } |
||
| 1297 | } |
||
| 1298 | } |
||
| 1299 | |||
| 1300 | 7 | return false; |
|
| 1301 | } |
||
| 1302 | |||
| 1303 | /** |
||
| 1304 | * Check if an (case-insensitive) string is in the current array. |
||
| 1305 | * |
||
| 1306 | * EXAMPLE: <code> |
||
| 1307 | * a(['E', 'é'])->containsCaseInsensitive('É'); // true |
||
| 1308 | * </code> |
||
| 1309 | * |
||
| 1310 | * @param mixed $value |
||
| 1311 | * @param bool $recursive |
||
| 1312 | * |
||
| 1313 | * @return bool |
||
| 1314 | * @psalm-mutation-free |
||
| 1315 | * |
||
| 1316 | * @psalm-suppress InvalidCast - hack for int|float|bool support |
||
| 1317 | */ |
||
| 1318 | 26 | public function containsCaseInsensitive($value, $recursive = false): bool |
|
| 1349 | |||
| 1350 | /** |
||
| 1351 | * Check if the given key/index exists in the array. |
||
| 1352 | * |
||
| 1353 | * EXAMPLE: <code> |
||
| 1354 | * a([1 => true])->containsKey(1); // true |
||
| 1355 | * </code> |
||
| 1356 | * |
||
| 1357 | * @param int|string $key <p>key/index to search for</p> |
||
| 1358 | * |
||
| 1359 | * @return bool |
||
| 1360 | * <p>Returns true if the given key/index exists in the array, false otherwise.</p> |
||
| 1361 | * |
||
| 1362 | * @psalm-mutation-free |
||
| 1363 | */ |
||
| 1364 | 4 | public function containsKey($key): bool |
|
| 1368 | |||
| 1369 | /** |
||
| 1370 | * Check if all given needles are present in the array as key/index. |
||
| 1371 | * |
||
| 1372 | * EXAMPLE: <code> |
||
| 1373 | * a([1 => true])->containsKeys(array(1 => 0)); // true |
||
| 1374 | * </code> |
||
| 1375 | * |
||
| 1376 | * @param array $needles <p>The keys you are searching for.</p> |
||
| 1377 | * @param bool $recursive |
||
| 1378 | * |
||
| 1379 | * @return bool |
||
| 1380 | * <p>Returns true if all the given keys/indexes exists in the array, false otherwise.</p> |
||
| 1381 | * |
||
| 1382 | * @psalm-param array<mixed,mixed>|array<TKey> $needles |
||
| 1383 | * @psalm-mutation-free |
||
| 1384 | */ |
||
| 1385 | 2 | public function containsKeys(array $needles, $recursive = false): bool |
|
| 1413 | |||
| 1414 | /** |
||
| 1415 | * Check if all given needles are present in the array as key/index. |
||
| 1416 | * |
||
| 1417 | * @param array $needles <p>The keys you are searching for.</p> |
||
| 1418 | * |
||
| 1419 | * @return bool |
||
| 1420 | * <p>Returns true if all the given keys/indexes exists in the array, false otherwise.</p> |
||
| 1421 | * |
||
| 1422 | * @psalm-param array<mixed,mixed>|array<TKey> $needles |
||
| 1423 | * @psalm-mutation-free |
||
| 1424 | */ |
||
| 1425 | 1 | public function containsKeysRecursive(array $needles): bool |
|
| 1429 | |||
| 1430 | /** |
||
| 1431 | * alias: for "Arrayy->contains()" |
||
| 1432 | * |
||
| 1433 | * @param float|int|string $value |
||
| 1434 | * |
||
| 1435 | * @return bool |
||
| 1436 | * |
||
| 1437 | * @see Arrayy::contains() |
||
| 1438 | * @psalm-mutation-free |
||
| 1439 | */ |
||
| 1440 | 9 | public function containsValue($value): bool |
|
| 1444 | |||
| 1445 | /** |
||
| 1446 | * alias: for "Arrayy->contains($value, true)" |
||
| 1447 | * |
||
| 1448 | * @param float|int|string $value |
||
| 1449 | * |
||
| 1450 | * @return bool |
||
| 1451 | * |
||
| 1452 | * @see Arrayy::contains() |
||
| 1453 | * @psalm-mutation-free |
||
| 1454 | */ |
||
| 1455 | 18 | public function containsValueRecursive($value): bool |
|
| 1459 | |||
| 1460 | /** |
||
| 1461 | * Check if all given needles are present in the array. |
||
| 1462 | * |
||
| 1463 | * EXAMPLE: <code> |
||
| 1464 | * a([1, true])->containsValues(array(1, true)); // true |
||
| 1465 | * </code> |
||
| 1466 | * |
||
| 1467 | * @param array $needles |
||
| 1468 | * |
||
| 1469 | * @return bool |
||
| 1470 | * <p>Returns true if all the given values exists in the array, false otherwise.</p> |
||
| 1471 | * |
||
| 1472 | * @psalm-param array<mixed>|array<T> $needles |
||
| 1473 | * @psalm-mutation-free |
||
| 1474 | */ |
||
| 1475 | 1 | public function containsValues(array $needles): bool |
|
| 1481 | |||
| 1482 | /** |
||
| 1483 | * Counts all the values of an array |
||
| 1484 | * |
||
| 1485 | * @see http://php.net/manual/en/function.array-count-values.php |
||
| 1486 | * |
||
| 1487 | * @return static |
||
| 1488 | * <p> |
||
| 1489 | * (Immutable) |
||
| 1490 | * An associative Arrayy-object of values from input as |
||
| 1491 | * keys and their count as value. |
||
| 1492 | * </p> |
||
| 1493 | * |
||
| 1494 | * @psalm-return static<TKey,T> |
||
| 1495 | * @psalm-mutation-free |
||
| 1496 | */ |
||
| 1497 | 7 | public function countValues(): self |
|
| 1501 | |||
| 1502 | /** |
||
| 1503 | * Creates an Arrayy object. |
||
| 1504 | * |
||
| 1505 | * @param mixed $data |
||
| 1506 | * @param string $iteratorClass |
||
| 1507 | * @param bool $checkPropertiesInConstructor |
||
| 1508 | * |
||
| 1509 | * @return static |
||
| 1510 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1511 | * |
||
| 1512 | * @psalm-param class-string<\Arrayy\ArrayyIterator> $iteratorClass |
||
| 1513 | * |
||
| 1514 | * @psalm-mutation-free |
||
| 1515 | */ |
||
| 1516 | 718 | public static function create( |
|
| 1527 | |||
| 1528 | /** |
||
| 1529 | * Flatten an array with the given character as a key delimiter |
||
| 1530 | * |
||
| 1531 | * @param string $delimiter |
||
| 1532 | * @param string $prepend |
||
| 1533 | * @param array|null $items |
||
| 1534 | * |
||
| 1535 | * @return array |
||
| 1536 | */ |
||
| 1537 | 2 | public function flatten($delimiter = '.', $prepend = '', $items = null) |
|
| 1560 | |||
| 1561 | /** |
||
| 1562 | * WARNING: Creates an Arrayy object by reference. |
||
| 1563 | * |
||
| 1564 | * @param array $array |
||
| 1565 | * |
||
| 1566 | * @return $this |
||
| 1567 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1568 | * |
||
| 1569 | * @psalm-param array<mixed,mixed>|array<array-key,mixed> $array |
||
| 1570 | */ |
||
| 1571 | 27 | public function createByReference(array &$array = []): self |
|
| 1579 | |||
| 1580 | /** |
||
| 1581 | * Create an new instance from a callable function which will return an Generator. |
||
| 1582 | * |
||
| 1583 | * @param callable $generatorFunction |
||
| 1584 | * |
||
| 1585 | * @return static |
||
| 1586 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1587 | * |
||
| 1588 | * @psalm-param callable():\Generator<array-key,mixed> $generatorFunction |
||
| 1589 | * |
||
| 1590 | * @psalm-mutation-free |
||
| 1591 | */ |
||
| 1592 | 7 | public static function createFromGeneratorFunction(callable $generatorFunction): self |
|
| 1596 | |||
| 1597 | /** |
||
| 1598 | * Create an new instance filled with a copy of values from a "Generator"-object. |
||
| 1599 | * |
||
| 1600 | * @param \Generator $generator |
||
| 1601 | * |
||
| 1602 | * @return static |
||
| 1603 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1604 | * |
||
| 1605 | * @psalm-param \Generator<array-key,mixed> $generator |
||
| 1606 | * |
||
| 1607 | * @psalm-mutation-free |
||
| 1608 | */ |
||
| 1609 | 4 | public static function createFromGeneratorImmutable(\Generator $generator): self |
|
| 1613 | |||
| 1614 | /** |
||
| 1615 | * Create an new Arrayy object via JSON. |
||
| 1616 | * |
||
| 1617 | * @param string $json |
||
| 1618 | * |
||
| 1619 | * @return static |
||
| 1620 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1621 | * |
||
| 1622 | * @psalm-mutation-free |
||
| 1623 | */ |
||
| 1624 | 5 | public static function createFromJson(string $json): self |
|
| 1628 | |||
| 1629 | /** |
||
| 1630 | * Create an new Arrayy object via JSON. |
||
| 1631 | * |
||
| 1632 | * @param array $array |
||
| 1633 | * |
||
| 1634 | * @return static |
||
| 1635 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1636 | * |
||
| 1637 | * @psalm-mutation-free |
||
| 1638 | */ |
||
| 1639 | 1 | public static function createFromArray(array $array): self |
|
| 1643 | |||
| 1644 | /** |
||
| 1645 | * Create an new instance filled with values from an object that is iterable. |
||
| 1646 | * |
||
| 1647 | * @param \Traversable $object <p>iterable object</p> |
||
| 1648 | * |
||
| 1649 | * @return static |
||
| 1650 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1651 | * |
||
| 1652 | * @psalm-param \Traversable<array-key,mixed> $object |
||
| 1653 | * |
||
| 1654 | * @psalm-mutation-free |
||
| 1655 | */ |
||
| 1656 | 4 | public static function createFromObject(\Traversable $object): self |
|
| 1676 | |||
| 1677 | /** |
||
| 1678 | * Create an new instance filled with values from an object. |
||
| 1679 | * |
||
| 1680 | * @param object $object |
||
| 1681 | * |
||
| 1682 | * @return static |
||
| 1683 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1684 | * |
||
| 1685 | * @psalm-mutation-free |
||
| 1686 | */ |
||
| 1687 | 5 | public static function createFromObjectVars($object): self |
|
| 1691 | |||
| 1692 | /** |
||
| 1693 | * Create an new Arrayy object via string. |
||
| 1694 | * |
||
| 1695 | * @param string $str <p>The input string.</p> |
||
| 1696 | * @param string|null $delimiter <p>The boundary string.</p> |
||
| 1697 | * @param string|null $regEx <p>Use the $delimiter or the $regEx, so if $pattern is null, $delimiter will be |
||
| 1698 | * used.</p> |
||
| 1699 | * |
||
| 1700 | * @return static |
||
| 1701 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1702 | * |
||
| 1703 | * @psalm-mutation-free |
||
| 1704 | */ |
||
| 1705 | 10 | public static function createFromString(string $str, string $delimiter = null, string $regEx = null): self |
|
| 1737 | |||
| 1738 | /** |
||
| 1739 | * Create an new instance filled with a copy of values from a "Traversable"-object. |
||
| 1740 | * |
||
| 1741 | * @param \Traversable $traversable |
||
| 1742 | * |
||
| 1743 | * @return static |
||
| 1744 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1745 | * |
||
| 1746 | * @psalm-param \Traversable<array-key,mixed> $traversable |
||
| 1747 | * |
||
| 1748 | * @psalm-mutation-free |
||
| 1749 | */ |
||
| 1750 | 1 | public static function createFromTraversableImmutable(\Traversable $traversable): self |
|
| 1754 | |||
| 1755 | /** |
||
| 1756 | * Create an new instance containing a range of elements. |
||
| 1757 | * |
||
| 1758 | * @param float|int|string $low <p>First value of the sequence.</p> |
||
| 1759 | * @param float|int|string $high <p>The sequence is ended upon reaching the end value.</p> |
||
| 1760 | * @param float|int $step <p>Used as the increment between elements in the sequence.</p> |
||
| 1761 | * |
||
| 1762 | * @return static |
||
| 1763 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1764 | * |
||
| 1765 | * @psalm-mutation-free |
||
| 1766 | */ |
||
| 1767 | 2 | public static function createWithRange($low, $high, $step = 1): self |
|
| 1771 | |||
| 1772 | /** |
||
| 1773 | * Gets the element of the array at the current internal iterator position. |
||
| 1774 | * |
||
| 1775 | * @return false|mixed |
||
| 1776 | */ |
||
| 1777 | public function current() |
||
| 1781 | |||
| 1782 | /** |
||
| 1783 | * Custom sort by index via "uksort". |
||
| 1784 | * |
||
| 1785 | * EXAMPLE: <code> |
||
| 1786 | * $callable = function ($a, $b) { |
||
| 1787 | * if ($a == $b) { |
||
| 1788 | * return 0; |
||
| 1789 | * } |
||
| 1790 | * return ($a > $b) ? 1 : -1; |
||
| 1791 | * }; |
||
| 1792 | * $arrayy = a(['three' => 3, 'one' => 1, 'two' => 2]); |
||
| 1793 | * $resultArrayy = $arrayy->customSortKeys($callable); // Arrayy['one' => 1, 'three' => 3, 'two' => 2] |
||
| 1794 | * </code> |
||
| 1795 | * |
||
| 1796 | * @see http://php.net/manual/en/function.uksort.php |
||
| 1797 | * |
||
| 1798 | * @param callable $function |
||
| 1799 | * |
||
| 1800 | * @throws \InvalidArgumentException |
||
| 1801 | * |
||
| 1802 | * @return $this |
||
| 1803 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1804 | * |
||
| 1805 | * @psalm-return static<TKey,T> |
||
| 1806 | */ |
||
| 1807 | 5 | public function customSortKeys(callable $function): self |
|
| 1815 | |||
| 1816 | /** |
||
| 1817 | * Custom sort by index via "uksort". |
||
| 1818 | * |
||
| 1819 | * @see http://php.net/manual/en/function.uksort.php |
||
| 1820 | * |
||
| 1821 | * @param callable $function |
||
| 1822 | * |
||
| 1823 | * @throws \InvalidArgumentException |
||
| 1824 | * |
||
| 1825 | * @return $this |
||
| 1826 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 1827 | * |
||
| 1828 | * @psalm-return static<TKey,T> |
||
| 1829 | * @psalm-mutation-free |
||
| 1830 | */ |
||
| 1831 | 1 | public function customSortKeysImmutable(callable $function): self |
|
| 1844 | |||
| 1845 | /** |
||
| 1846 | * Custom sort by value via "usort". |
||
| 1847 | * |
||
| 1848 | * EXAMPLE: <code> |
||
| 1849 | * $callable = function ($a, $b) { |
||
| 1850 | * if ($a == $b) { |
||
| 1851 | * return 0; |
||
| 1852 | * } |
||
| 1853 | * return ($a > $b) ? 1 : -1; |
||
| 1854 | * }; |
||
| 1855 | * $arrayy = a(['three' => 3, 'one' => 1, 'two' => 2]); |
||
| 1856 | * $resultArrayy = $arrayy->customSortValues($callable); // Arrayy['one' => 1, 'two' => 2, 'three' => 3] |
||
| 1857 | * </code> |
||
| 1858 | * |
||
| 1859 | * @see http://php.net/manual/en/function.usort.php |
||
| 1860 | * |
||
| 1861 | * @param callable $function |
||
| 1862 | * |
||
| 1863 | * @throws \InvalidArgumentException |
||
| 1864 | * |
||
| 1865 | * @return $this |
||
| 1866 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1867 | * |
||
| 1868 | * @psalm-return static<TKey,T> |
||
| 1869 | */ |
||
| 1870 | 10 | View Code Duplication | public function customSortValues($function): self |
| 1882 | |||
| 1883 | /** |
||
| 1884 | * Custom sort by value via "usort". |
||
| 1885 | * |
||
| 1886 | * @see http://php.net/manual/en/function.usort.php |
||
| 1887 | * |
||
| 1888 | * @param callable $function |
||
| 1889 | * |
||
| 1890 | * @throws \InvalidArgumentException |
||
| 1891 | * |
||
| 1892 | * @return $this |
||
| 1893 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 1894 | * |
||
| 1895 | * @psalm-return static<TKey,T> |
||
| 1896 | * @psalm-mutation-free |
||
| 1897 | */ |
||
| 1898 | 4 | public function customSortValuesImmutable($function): self |
|
| 1909 | |||
| 1910 | /** |
||
| 1911 | * Delete the given key or keys. |
||
| 1912 | * |
||
| 1913 | * @param int|int[]|string|string[] $keyOrKeys |
||
| 1914 | * |
||
| 1915 | * @return void |
||
| 1916 | */ |
||
| 1917 | 9 | public function delete($keyOrKeys) |
|
| 1925 | |||
| 1926 | /** |
||
| 1927 | * Return values that are only in the current array. |
||
| 1928 | * |
||
| 1929 | * EXAMPLE: <code> |
||
| 1930 | * a([1 => 1, 2 => 2])->diff([1 => 1]); // Arrayy[2 => 2] |
||
| 1931 | * </code> |
||
| 1932 | * |
||
| 1933 | * @param array ...$array |
||
| 1934 | * |
||
| 1935 | * @return static |
||
| 1936 | * <p>(Immutable)</p> |
||
| 1937 | * |
||
| 1938 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$array |
||
| 1939 | * @psalm-return static<TKey,T> |
||
| 1940 | * @psalm-mutation-free |
||
| 1941 | */ |
||
| 1942 | 13 | public function diff(...$array): self |
|
| 1950 | |||
| 1951 | /** |
||
| 1952 | * Return values that are only in the current array. |
||
| 1953 | * |
||
| 1954 | * @param array ...$array |
||
| 1955 | * |
||
| 1956 | * @return static |
||
| 1957 | * <p>(Immutable)</p> |
||
| 1958 | * |
||
| 1959 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$array |
||
| 1960 | * @psalm-return static<TKey,T> |
||
| 1961 | * @psalm-mutation-free |
||
| 1962 | */ |
||
| 1963 | 8 | public function diffKey(...$array): self |
|
| 1971 | |||
| 1972 | /** |
||
| 1973 | * Return values and Keys that are only in the current array. |
||
| 1974 | * |
||
| 1975 | * @param array $array |
||
| 1976 | * |
||
| 1977 | * @return static |
||
| 1978 | * <p>(Immutable)</p> |
||
| 1979 | * |
||
| 1980 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 1981 | * @psalm-return static<TKey,T> |
||
| 1982 | * @psalm-mutation-free |
||
| 1983 | */ |
||
| 1984 | 8 | public function diffKeyAndValue(array $array = []): self |
|
| 1992 | |||
| 1993 | /** |
||
| 1994 | * Return values that are only in the current multi-dimensional array. |
||
| 1995 | * |
||
| 1996 | * @param array $array |
||
| 1997 | * @param array|\Generator|null $helperVariableForRecursion <p>(only for internal usage)</p> |
||
| 1998 | * |
||
| 1999 | * @return static |
||
| 2000 | * <p>(Immutable)</p> |
||
| 2001 | * |
||
| 2002 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 2003 | * @psalm-param null|array<TKey,T>|\Generator<TKey,T> $helperVariableForRecursion |
||
| 2004 | * @psalm-return static<TKey,T> |
||
| 2005 | * @psalm-mutation-free |
||
| 2006 | */ |
||
| 2007 | 1 | public function diffRecursive(array $array = [], $helperVariableForRecursion = null): self |
|
| 2042 | |||
| 2043 | /** |
||
| 2044 | * Return values that are only in the new $array. |
||
| 2045 | * |
||
| 2046 | * @param array $array |
||
| 2047 | * |
||
| 2048 | * @return static |
||
| 2049 | * <p>(Immutable)</p> |
||
| 2050 | * |
||
| 2051 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 2052 | * @psalm-return static<TKey,T> |
||
| 2053 | * @psalm-mutation-free |
||
| 2054 | */ |
||
| 2055 | 8 | public function diffReverse(array $array = []): self |
|
| 2063 | |||
| 2064 | /** |
||
| 2065 | * Divide an array into two arrays. One with keys and the other with values. |
||
| 2066 | * |
||
| 2067 | * @return static |
||
| 2068 | * <p>(Immutable)</p> |
||
| 2069 | * |
||
| 2070 | * @psalm-return static<TKey,T> |
||
| 2071 | * @psalm-mutation-free |
||
| 2072 | */ |
||
| 2073 | 1 | public function divide(): self |
|
| 2084 | |||
| 2085 | /** |
||
| 2086 | * Iterate over the current array and modify the array's value. |
||
| 2087 | * |
||
| 2088 | * @param \Closure $closure |
||
| 2089 | * |
||
| 2090 | * @return static |
||
| 2091 | * <p>(Immutable)</p> |
||
| 2092 | * |
||
| 2093 | * @psalm-return static<TKey,T> |
||
| 2094 | * @psalm-mutation-free |
||
| 2095 | */ |
||
| 2096 | 5 | View Code Duplication | public function each(\Closure $closure): self |
| 2111 | |||
| 2112 | /** |
||
| 2113 | * Sets the internal iterator to the last element in the array and returns this element. |
||
| 2114 | * |
||
| 2115 | * @return mixed |
||
| 2116 | */ |
||
| 2117 | public function end() |
||
| 2121 | |||
| 2122 | /** |
||
| 2123 | * Check if a value is in the current array using a closure. |
||
| 2124 | * |
||
| 2125 | * @param \Closure $closure |
||
| 2126 | * |
||
| 2127 | * @return bool |
||
| 2128 | * <p>Returns true if the given value is found, false otherwise.</p> |
||
| 2129 | */ |
||
| 2130 | 4 | public function exists(\Closure $closure): bool |
|
| 2145 | |||
| 2146 | /** |
||
| 2147 | * Fill the array until "$num" with "$default" values. |
||
| 2148 | * |
||
| 2149 | * @param int $num |
||
| 2150 | * @param mixed $default |
||
| 2151 | * |
||
| 2152 | * @return static |
||
| 2153 | * <p>(Immutable)</p> |
||
| 2154 | * |
||
| 2155 | * @psalm-return static<TKey,T> |
||
| 2156 | * @psalm-mutation-free |
||
| 2157 | */ |
||
| 2158 | 8 | public function fillWithDefaults(int $num, $default = null): self |
|
| 2181 | |||
| 2182 | /** |
||
| 2183 | * Find all items in an array that pass the truth test. |
||
| 2184 | * |
||
| 2185 | * @param \Closure|null $closure [optional] <p> |
||
| 2186 | * The callback function to use |
||
| 2187 | * </p> |
||
| 2188 | * <p> |
||
| 2189 | * If no callback is supplied, all entries of |
||
| 2190 | * input equal to false (see |
||
| 2191 | * converting to |
||
| 2192 | * boolean) will be removed. |
||
| 2193 | * </p> |
||
| 2194 | * @param int $flag [optional] <p> |
||
| 2195 | * Flag determining what arguments are sent to <i>callback</i>: |
||
| 2196 | * </p><ul> |
||
| 2197 | * <li> |
||
| 2198 | * <b>ARRAY_FILTER_USE_KEY</b> [1] - pass key as the only argument |
||
| 2199 | * to <i>callback</i> instead of the value</span> |
||
| 2200 | * </li> |
||
| 2201 | * <li> |
||
| 2202 | * <b>ARRAY_FILTER_USE_BOTH</b> [2] - pass both value and key as |
||
| 2203 | * arguments to <i>callback</i> instead of the value</span> |
||
| 2204 | * </li> |
||
| 2205 | * </ul> |
||
| 2206 | * |
||
| 2207 | * @return static |
||
| 2208 | * <p>(Immutable)</p> |
||
| 2209 | * |
||
| 2210 | * @psalm-param \Closure(T=,TKey=):bool|\Closure(T=):bool $closure |
||
| 2211 | * @psalm-return static<TKey,T> |
||
| 2212 | * @psalm-mutation-free |
||
| 2213 | */ |
||
| 2214 | 12 | public function filter($closure = null, int $flag = \ARRAY_FILTER_USE_BOTH) |
|
| 2226 | |||
| 2227 | /** |
||
| 2228 | * Filters an array of objects (or a numeric array of associative arrays) based on the value of a particular |
||
| 2229 | * property within that. |
||
| 2230 | * |
||
| 2231 | * @param string $property |
||
| 2232 | * @param string|string[] $value |
||
| 2233 | * @param string $comparisonOp |
||
| 2234 | * <p> |
||
| 2235 | * 'eq' (equals),<br /> |
||
| 2236 | * 'gt' (greater),<br /> |
||
| 2237 | * 'gte' || 'ge' (greater or equals),<br /> |
||
| 2238 | * 'lt' (less),<br /> |
||
| 2239 | * 'lte' || 'le' (less or equals),<br /> |
||
| 2240 | * 'ne' (not equals),<br /> |
||
| 2241 | * 'contains',<br /> |
||
| 2242 | * 'notContains',<br /> |
||
| 2243 | * 'newer' (via strtotime),<br /> |
||
| 2244 | * 'older' (via strtotime),<br /> |
||
| 2245 | * </p> |
||
| 2246 | * |
||
| 2247 | * @return static |
||
| 2248 | * <p>(Immutable)</p> |
||
| 2249 | * |
||
| 2250 | * @psalm-return static<TKey,T> |
||
| 2251 | * @psalm-mutation-free |
||
| 2252 | * |
||
| 2253 | * @psalm-suppress MissingClosureReturnType |
||
| 2254 | * @psalm-suppress MissingClosureParamType |
||
| 2255 | */ |
||
| 2256 | 1 | public function filterBy( |
|
| 2328 | |||
| 2329 | /** |
||
| 2330 | * Find the first item in an array that passes the truth test, |
||
| 2331 | * otherwise return false |
||
| 2332 | * |
||
| 2333 | * @param \Closure $closure |
||
| 2334 | * |
||
| 2335 | * @return false|mixed |
||
| 2336 | * <p>Return false if we did not find the value.</p> |
||
| 2337 | */ |
||
| 2338 | 8 | View Code Duplication | public function find(\Closure $closure) |
| 2348 | |||
| 2349 | /** |
||
| 2350 | * find by ... |
||
| 2351 | * |
||
| 2352 | * @param string $property |
||
| 2353 | * @param string|string[] $value |
||
| 2354 | * @param string $comparisonOp |
||
| 2355 | * |
||
| 2356 | * @return static |
||
| 2357 | * <p>(Immutable)</p> |
||
| 2358 | * |
||
| 2359 | * @psalm-return static<TKey,T> |
||
| 2360 | * @psalm-mutation-free |
||
| 2361 | */ |
||
| 2362 | 1 | public function findBy(string $property, $value, string $comparisonOp = 'eq'): self |
|
| 2366 | |||
| 2367 | /** |
||
| 2368 | * Get the first value from the current array. |
||
| 2369 | * |
||
| 2370 | * @return mixed |
||
| 2371 | * <p>Return null if there wasn't a element.</p> |
||
| 2372 | */ |
||
| 2373 | 22 | public function first() |
|
| 2382 | |||
| 2383 | /** |
||
| 2384 | * Get the first key from the current array. |
||
| 2385 | * |
||
| 2386 | * @return mixed |
||
| 2387 | * <p>Return null if there wasn't a element.</p> |
||
| 2388 | * @psalm-mutation-free |
||
| 2389 | */ |
||
| 2390 | 29 | public function firstKey() |
|
| 2396 | |||
| 2397 | /** |
||
| 2398 | * Get the first value(s) from the current array. |
||
| 2399 | * And will return an empty array if there was no first entry. |
||
| 2400 | * |
||
| 2401 | * @param int|null $number <p>How many values you will take?</p> |
||
| 2402 | * |
||
| 2403 | * @return static |
||
| 2404 | * <p>(Immutable)</p> |
||
| 2405 | * |
||
| 2406 | * @psalm-return static<TKey,T> |
||
| 2407 | * @psalm-mutation-free |
||
| 2408 | */ |
||
| 2409 | 37 | View Code Duplication | public function firstsImmutable(int $number = null): self |
| 2425 | |||
| 2426 | /** |
||
| 2427 | * Get the first value(s) from the current array. |
||
| 2428 | * And will return an empty array if there was no first entry. |
||
| 2429 | * |
||
| 2430 | * @param int|null $number <p>How many values you will take?</p> |
||
| 2431 | * |
||
| 2432 | * @return static |
||
| 2433 | * <p>(Immutable)</p> |
||
| 2434 | * |
||
| 2435 | * @psalm-return static<TKey,T> |
||
| 2436 | * @psalm-mutation-free |
||
| 2437 | */ |
||
| 2438 | 3 | View Code Duplication | public function firstsKeys(int $number = null): self |
| 2454 | |||
| 2455 | /** |
||
| 2456 | * Get and rmove the first value(s) from the current array. |
||
| 2457 | * And will return an empty array if there was no first entry. |
||
| 2458 | * |
||
| 2459 | * @param int|null $number <p>How many values you will take?</p> |
||
| 2460 | * |
||
| 2461 | * @return $this |
||
| 2462 | * <p>(Mutable)</p> |
||
| 2463 | * |
||
| 2464 | * @psalm-return static<TKey,T> |
||
| 2465 | */ |
||
| 2466 | 34 | public function firstsMutable(int $number = null): self |
|
| 2478 | |||
| 2479 | /** |
||
| 2480 | * Exchanges all keys with their associated values in an array. |
||
| 2481 | * |
||
| 2482 | * @return static |
||
| 2483 | * <p>(Immutable)</p> |
||
| 2484 | * |
||
| 2485 | * @psalm-return static<TKey,T> |
||
| 2486 | * @psalm-mutation-free |
||
| 2487 | */ |
||
| 2488 | 1 | public function flip(): self |
|
| 2496 | |||
| 2497 | /** |
||
| 2498 | * Get a value from an array (optional using dot-notation). |
||
| 2499 | * |
||
| 2500 | * @param mixed $key <p>The key to look for.</p> |
||
| 2501 | * @param mixed $fallback <p>Value to fallback to.</p> |
||
| 2502 | * @param array $array <p>The array to get from, if it's set to "null" we use the current array from the |
||
| 2503 | * class.</p> |
||
| 2504 | * @param bool $useByReference |
||
| 2505 | * |
||
| 2506 | * @return mixed|static |
||
| 2507 | * |
||
| 2508 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 2509 | * @psalm-mutation-free |
||
| 2510 | */ |
||
| 2511 | 242 | public function get( |
|
| 2676 | |||
| 2677 | /** |
||
| 2678 | * alias: for "Arrayy->toArray()" |
||
| 2679 | * |
||
| 2680 | * @return array |
||
| 2681 | * |
||
| 2682 | * @see Arrayy::getArray() |
||
| 2683 | * |
||
| 2684 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 2685 | */ |
||
| 2686 | 15 | public function getAll(): array |
|
| 2690 | |||
| 2691 | /** |
||
| 2692 | * Get the current array from the "Arrayy"-object. |
||
| 2693 | * |
||
| 2694 | * alias for "toArray()" |
||
| 2695 | * |
||
| 2696 | * @param bool $convertAllArrayyElements <p> |
||
| 2697 | * Convert all Child-"Arrayy" objects also to arrays. |
||
| 2698 | * </p> |
||
| 2699 | * @param bool $preserveKeys <p> |
||
| 2700 | * e.g.: A generator maybe return the same key more then once, |
||
| 2701 | * so maybe you will ignore the keys. |
||
| 2702 | * </p> |
||
| 2703 | * |
||
| 2704 | * @return array |
||
| 2705 | * |
||
| 2706 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 2707 | * @psalm-mutation-free |
||
| 2708 | * |
||
| 2709 | * @see Arrayy::toArray() |
||
| 2710 | */ |
||
| 2711 | 500 | public function getArray( |
|
| 2720 | |||
| 2721 | /** |
||
| 2722 | * @param string $json |
||
| 2723 | * |
||
| 2724 | * @return $this |
||
| 2725 | */ |
||
| 2726 | 3 | public static function createFromJsonMapper(string $json) |
|
| 2742 | |||
| 2743 | /** |
||
| 2744 | * @return array<int|string,TypeCheckInterface>|mixed|TypeCheckArray<int|string,TypeCheckInterface>|TypeInterface |
||
| 2745 | * |
||
| 2746 | * @internal |
||
| 2747 | */ |
||
| 2748 | 6 | public function getPhpDocPropertiesFromClass() |
|
| 2756 | |||
| 2757 | /** |
||
| 2758 | * Get the current array from the "Arrayy"-object as list. |
||
| 2759 | * |
||
| 2760 | * alias for "toList()" |
||
| 2761 | * |
||
| 2762 | * @param bool $convertAllArrayyElements <p> |
||
| 2763 | * Convert all Child-"Arrayy" objects also to arrays. |
||
| 2764 | * </p> |
||
| 2765 | * |
||
| 2766 | * @return array |
||
| 2767 | * |
||
| 2768 | * @psalm-return array<int,mixed>|array<int,T> |
||
| 2769 | * @psalm-mutation-free |
||
| 2770 | * |
||
| 2771 | * @see Arrayy::toList() |
||
| 2772 | */ |
||
| 2773 | 1 | public function getList(bool $convertAllArrayyElements = false): array |
|
| 2777 | |||
| 2778 | /** |
||
| 2779 | * Returns the values from a single column of the input array, identified by |
||
| 2780 | * the $columnKey, can be used to extract data-columns from multi-arrays. |
||
| 2781 | * |
||
| 2782 | * Info: Optionally, you may provide an $indexKey to index the values in the returned |
||
| 2783 | * array by the values from the $indexKey column in the input array. |
||
| 2784 | * |
||
| 2785 | * @param mixed $columnKey |
||
| 2786 | * @param mixed $indexKey |
||
| 2787 | * |
||
| 2788 | * @return static |
||
| 2789 | * <p>(Immutable)</p> |
||
| 2790 | * |
||
| 2791 | * @psalm-return static<TKey,T> |
||
| 2792 | * @psalm-mutation-free |
||
| 2793 | */ |
||
| 2794 | 1 | public function getColumn($columnKey = null, $indexKey = null): self |
|
| 2802 | |||
| 2803 | /** |
||
| 2804 | * Get the current array from the "Arrayy"-object as generator by reference. |
||
| 2805 | * |
||
| 2806 | * @return \Generator |
||
| 2807 | * |
||
| 2808 | * @psalm-return \Generator<mixed,T>|\Generator<TKey,T> |
||
| 2809 | */ |
||
| 2810 | 75 | public function &getGeneratorByReference(): \Generator |
|
| 2829 | |||
| 2830 | /** |
||
| 2831 | * Get the current array from the "Arrayy"-object as generator. |
||
| 2832 | * |
||
| 2833 | * @return \Generator |
||
| 2834 | * |
||
| 2835 | * @psalm-return \Generator<mixed,T>|\Generator<TKey,T> |
||
| 2836 | * @psalm-mutation-free |
||
| 2837 | */ |
||
| 2838 | 996 | public function getGenerator(): \Generator |
|
| 2848 | |||
| 2849 | /** |
||
| 2850 | * alias: for "Arrayy->keys()" |
||
| 2851 | * |
||
| 2852 | * @return static |
||
| 2853 | * <p>(Immutable)</p> |
||
| 2854 | * |
||
| 2855 | * @see Arrayy::keys() |
||
| 2856 | * |
||
| 2857 | * @psalm-return static<array-key,TKey> |
||
| 2858 | * @psalm-mutation-free |
||
| 2859 | */ |
||
| 2860 | 2 | public function getKeys() |
|
| 2864 | |||
| 2865 | /** |
||
| 2866 | * Get the current array from the "Arrayy"-object as object. |
||
| 2867 | * |
||
| 2868 | * @return \stdClass |
||
| 2869 | */ |
||
| 2870 | 4 | public function getObject(): \stdClass |
|
| 2874 | |||
| 2875 | /** |
||
| 2876 | * alias: for "Arrayy->randomImmutable()" |
||
| 2877 | * |
||
| 2878 | * @return static |
||
| 2879 | * <p>(Immutable)</p> |
||
| 2880 | * |
||
| 2881 | * @see Arrayy::randomImmutable() |
||
| 2882 | * |
||
| 2883 | * @psalm-return static<int|array-key,T> |
||
| 2884 | */ |
||
| 2885 | 4 | public function getRandom(): self |
|
| 2889 | |||
| 2890 | /** |
||
| 2891 | * alias: for "Arrayy->randomKey()" |
||
| 2892 | * |
||
| 2893 | * @return mixed |
||
| 2894 | * <p>Get a key/index or null if there wasn't a key/index.</p> |
||
| 2895 | * |
||
| 2896 | * @see Arrayy::randomKey() |
||
| 2897 | */ |
||
| 2898 | 3 | public function getRandomKey() |
|
| 2902 | |||
| 2903 | /** |
||
| 2904 | * alias: for "Arrayy->randomKeys()" |
||
| 2905 | * |
||
| 2906 | * @param int $number |
||
| 2907 | * |
||
| 2908 | * @return static |
||
| 2909 | * <p>(Immutable)</p> |
||
| 2910 | * |
||
| 2911 | * @see Arrayy::randomKeys() |
||
| 2912 | * |
||
| 2913 | * @psalm-return static<TKey,T> |
||
| 2914 | */ |
||
| 2915 | 8 | public function getRandomKeys(int $number): self |
|
| 2919 | |||
| 2920 | /** |
||
| 2921 | * alias: for "Arrayy->randomValue()" |
||
| 2922 | * |
||
| 2923 | * @return mixed |
||
| 2924 | * <p>Get a random value or null if there wasn't a value.</p> |
||
| 2925 | * |
||
| 2926 | * @see Arrayy::randomValue() |
||
| 2927 | */ |
||
| 2928 | 3 | public function getRandomValue() |
|
| 2932 | |||
| 2933 | /** |
||
| 2934 | * alias: for "Arrayy->randomValues()" |
||
| 2935 | * |
||
| 2936 | * @param int $number |
||
| 2937 | * |
||
| 2938 | * @return static |
||
| 2939 | * <p>(Immutable)</p> |
||
| 2940 | * |
||
| 2941 | * @see Arrayy::randomValues() |
||
| 2942 | * |
||
| 2943 | * @psalm-return static<TKey,T> |
||
| 2944 | */ |
||
| 2945 | 6 | public function getRandomValues(int $number): self |
|
| 2949 | |||
| 2950 | /** |
||
| 2951 | * Gets all values. |
||
| 2952 | * |
||
| 2953 | * @return static |
||
| 2954 | * <p>The values of all elements in this array, in the order they |
||
| 2955 | * appear in the array.</p> |
||
| 2956 | * |
||
| 2957 | * @psalm-return static<TKey,T> |
||
| 2958 | */ |
||
| 2959 | 4 | public function getValues() |
|
| 2969 | |||
| 2970 | /** |
||
| 2971 | * Gets all values via Generator. |
||
| 2972 | * |
||
| 2973 | * @return \Generator |
||
| 2974 | * <p>The values of all elements in this array, in the order they |
||
| 2975 | * appear in the array as Generator.</p> |
||
| 2976 | * |
||
| 2977 | * @psalm-return \Generator<TKey,T> |
||
| 2978 | */ |
||
| 2979 | 4 | public function getValuesYield(): \Generator |
|
| 2983 | |||
| 2984 | /** |
||
| 2985 | * Group values from a array according to the results of a closure. |
||
| 2986 | * |
||
| 2987 | * @param callable|string $grouper <p>A callable function name.</p> |
||
| 2988 | * @param bool $saveKeys |
||
| 2989 | * |
||
| 2990 | * @return static |
||
| 2991 | * <p>(Immutable)</p> |
||
| 2992 | * |
||
| 2993 | * @psalm-return static<TKey,T> |
||
| 2994 | * @psalm-mutation-free |
||
| 2995 | */ |
||
| 2996 | 4 | public function group($grouper, bool $saveKeys = false): self |
|
| 3037 | |||
| 3038 | /** |
||
| 3039 | * Check if an array has a given key. |
||
| 3040 | * |
||
| 3041 | * @param mixed $key |
||
| 3042 | * |
||
| 3043 | * @return bool |
||
| 3044 | */ |
||
| 3045 | 30 | public function has($key): bool |
|
| 3071 | |||
| 3072 | /** |
||
| 3073 | * Check if an array has a given value. |
||
| 3074 | * |
||
| 3075 | * INFO: if you need to search recursive please use ```contains()``` |
||
| 3076 | * |
||
| 3077 | * @param mixed $value |
||
| 3078 | * |
||
| 3079 | * @return bool |
||
| 3080 | */ |
||
| 3081 | 1 | public function hasValue($value): bool |
|
| 3085 | |||
| 3086 | /** |
||
| 3087 | * Implodes the values of this array. |
||
| 3088 | * |
||
| 3089 | * @param string $glue |
||
| 3090 | * |
||
| 3091 | * @return string |
||
| 3092 | * @psalm-mutation-free |
||
| 3093 | */ |
||
| 3094 | 28 | public function implode(string $glue = ''): string |
|
| 3098 | |||
| 3099 | /** |
||
| 3100 | * Implodes the keys of this array. |
||
| 3101 | * |
||
| 3102 | * @param string $glue |
||
| 3103 | * |
||
| 3104 | * @return string |
||
| 3105 | * @psalm-mutation-free |
||
| 3106 | */ |
||
| 3107 | 8 | public function implodeKeys(string $glue = ''): string |
|
| 3111 | |||
| 3112 | /** |
||
| 3113 | * Given a list and an iterate-function that returns |
||
| 3114 | * a key for each element in the list (or a property name), |
||
| 3115 | * returns an object with an index of each item. |
||
| 3116 | * |
||
| 3117 | * @param mixed $key |
||
| 3118 | * |
||
| 3119 | * @return static |
||
| 3120 | * <p>(Immutable)</p> |
||
| 3121 | * |
||
| 3122 | * @psalm-return static<TKey,T> |
||
| 3123 | * @psalm-mutation-free |
||
| 3124 | */ |
||
| 3125 | 4 | public function indexBy($key): self |
|
| 3142 | |||
| 3143 | /** |
||
| 3144 | * alias: for "Arrayy->searchIndex()" |
||
| 3145 | * |
||
| 3146 | * @param mixed $value <p>The value to search for.</p> |
||
| 3147 | * |
||
| 3148 | * @return false|mixed |
||
| 3149 | * |
||
| 3150 | * @see Arrayy::searchIndex() |
||
| 3151 | */ |
||
| 3152 | 4 | public function indexOf($value) |
|
| 3156 | |||
| 3157 | /** |
||
| 3158 | * Get everything but the last..$to items. |
||
| 3159 | * |
||
| 3160 | * @param int $to |
||
| 3161 | * |
||
| 3162 | * @return static |
||
| 3163 | * <p>(Immutable)</p> |
||
| 3164 | * |
||
| 3165 | * @psalm-return static<TKey,T> |
||
| 3166 | * @psalm-mutation-free |
||
| 3167 | */ |
||
| 3168 | 12 | public function initial(int $to = 1): self |
|
| 3172 | |||
| 3173 | /** |
||
| 3174 | * Return an array with all elements found in input array. |
||
| 3175 | * |
||
| 3176 | * @param array $search |
||
| 3177 | * @param bool $keepKeys |
||
| 3178 | * |
||
| 3179 | * @return static |
||
| 3180 | * <p>(Immutable)</p> |
||
| 3181 | * |
||
| 3182 | * @psalm-param array<mixed,mixed>|array<TKey,T> $search |
||
| 3183 | * @psalm-return static<TKey,T> |
||
| 3184 | * @psalm-mutation-free |
||
| 3185 | */ |
||
| 3186 | 4 | public function intersection(array $search, bool $keepKeys = false): self |
|
| 3212 | |||
| 3213 | /** |
||
| 3214 | * Return an array with all elements found in input array. |
||
| 3215 | * |
||
| 3216 | * @param array ...$array |
||
| 3217 | * |
||
| 3218 | * @return static |
||
| 3219 | * <p>(Immutable)</p> |
||
| 3220 | * |
||
| 3221 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$array |
||
| 3222 | * @psalm-return static<TKey,T> |
||
| 3223 | * @psalm-mutation-free |
||
| 3224 | */ |
||
| 3225 | 1 | public function intersectionMulti(...$array): self |
|
| 3233 | |||
| 3234 | /** |
||
| 3235 | * Return a boolean flag which indicates whether the two input arrays have any common elements. |
||
| 3236 | * |
||
| 3237 | * @param array $search |
||
| 3238 | * |
||
| 3239 | * @return bool |
||
| 3240 | * |
||
| 3241 | * @psalm-param array<mixed,mixed>|array<TKey,T> $search |
||
| 3242 | */ |
||
| 3243 | 1 | public function intersects(array $search): bool |
|
| 3247 | |||
| 3248 | /** |
||
| 3249 | * Invoke a function on all of an array's values. |
||
| 3250 | * |
||
| 3251 | * @param callable $callable |
||
| 3252 | * @param mixed $arguments |
||
| 3253 | * |
||
| 3254 | * @return static |
||
| 3255 | * <p>(Immutable)</p> |
||
| 3256 | * |
||
| 3257 | * @psalm-param callable(T=,mixed):mixed $callable |
||
| 3258 | * @psalm-return static<TKey,T> |
||
| 3259 | * @psalm-mutation-free |
||
| 3260 | */ |
||
| 3261 | 1 | View Code Duplication | public function invoke($callable, $arguments = []): self |
| 3285 | |||
| 3286 | /** |
||
| 3287 | * Check whether array is associative or not. |
||
| 3288 | * |
||
| 3289 | * @param bool $recursive |
||
| 3290 | * |
||
| 3291 | * @return bool |
||
| 3292 | * <p>Returns true if associative, false otherwise.</p> |
||
| 3293 | */ |
||
| 3294 | 15 | View Code Duplication | public function isAssoc(bool $recursive = false): bool |
| 3309 | |||
| 3310 | /** |
||
| 3311 | * Check if a given key or keys are empty. |
||
| 3312 | * |
||
| 3313 | * @param int|int[]|string|string[]|null $keys |
||
| 3314 | * |
||
| 3315 | * @return bool |
||
| 3316 | * <p>Returns true if empty, false otherwise.</p> |
||
| 3317 | * @psalm-mutation-free |
||
| 3318 | */ |
||
| 3319 | 45 | public function isEmpty($keys = null): bool |
|
| 3337 | |||
| 3338 | /** |
||
| 3339 | * Check if the current array is equal to the given "$array" or not. |
||
| 3340 | * |
||
| 3341 | * @param array $array |
||
| 3342 | * |
||
| 3343 | * @return bool |
||
| 3344 | * |
||
| 3345 | * @psalm-param array<mixed,mixed> $array |
||
| 3346 | */ |
||
| 3347 | 1 | public function isEqual(array $array): bool |
|
| 3351 | |||
| 3352 | /** |
||
| 3353 | * Check if the current array is a multi-array. |
||
| 3354 | * |
||
| 3355 | * @return bool |
||
| 3356 | */ |
||
| 3357 | 22 | public function isMultiArray(): bool |
|
| 3365 | |||
| 3366 | /** |
||
| 3367 | * Check whether array is numeric or not. |
||
| 3368 | * |
||
| 3369 | * @return bool |
||
| 3370 | * <p>Returns true if numeric, false otherwise.</p> |
||
| 3371 | */ |
||
| 3372 | 5 | View Code Duplication | public function isNumeric(): bool |
| 3387 | |||
| 3388 | /** |
||
| 3389 | * Check if the current array is sequential [0, 1, 2, 3, 4, 5 ...] or not. |
||
| 3390 | * |
||
| 3391 | * @param bool $recursive |
||
| 3392 | * |
||
| 3393 | * @return bool |
||
| 3394 | * @psalm-mutation-free |
||
| 3395 | */ |
||
| 3396 | 9 | public function isSequential(bool $recursive = false): bool |
|
| 3413 | |||
| 3414 | /** |
||
| 3415 | * @return array |
||
| 3416 | * |
||
| 3417 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 3418 | */ |
||
| 3419 | 2 | public function jsonSerialize(): array |
|
| 3423 | |||
| 3424 | /** |
||
| 3425 | * Gets the key/index of the element at the current internal iterator position. |
||
| 3426 | * |
||
| 3427 | * @return int|string|null |
||
| 3428 | */ |
||
| 3429 | public function key() |
||
| 3433 | |||
| 3434 | /** |
||
| 3435 | * Checks if the given key exists in the provided array. |
||
| 3436 | * |
||
| 3437 | * INFO: This method only use "array_key_exists()" if you want to use "dot"-notation, |
||
| 3438 | * then you need to use "Arrayy->offsetExists()". |
||
| 3439 | * |
||
| 3440 | * @param int|string $key the key to look for |
||
| 3441 | * |
||
| 3442 | * @return bool |
||
| 3443 | * @psalm-mutation-free |
||
| 3444 | */ |
||
| 3445 | 162 | public function keyExists($key): bool |
|
| 3449 | |||
| 3450 | /** |
||
| 3451 | * Get all keys from the current array. |
||
| 3452 | * |
||
| 3453 | * @param bool $recursive [optional] <p> |
||
| 3454 | * Get all keys, also from all sub-arrays from an multi-dimensional array. |
||
| 3455 | * </p> |
||
| 3456 | * @param mixed|null $search_values [optional] <p> |
||
| 3457 | * If specified, then only keys containing these values are returned. |
||
| 3458 | * </p> |
||
| 3459 | * @param bool $strict [optional] <p> |
||
| 3460 | * Determines if strict comparison (===) should be used during the search. |
||
| 3461 | * </p> |
||
| 3462 | * |
||
| 3463 | * @return static |
||
| 3464 | * <p>(Immutable) An array of all the keys in input.</p> |
||
| 3465 | * |
||
| 3466 | * @psalm-return static<array-key,TKey> |
||
| 3467 | * @psalm-mutation-free |
||
| 3468 | */ |
||
| 3469 | 29 | public function keys( |
|
| 3540 | |||
| 3541 | /** |
||
| 3542 | * Sort an array by key in reverse order. |
||
| 3543 | * |
||
| 3544 | * @param int $sort_flags [optional] <p> |
||
| 3545 | * You may modify the behavior of the sort using the optional |
||
| 3546 | * parameter sort_flags, for details |
||
| 3547 | * see sort. |
||
| 3548 | * </p> |
||
| 3549 | * |
||
| 3550 | * @return $this |
||
| 3551 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 3552 | * |
||
| 3553 | * @psalm-return static<TKey,T> |
||
| 3554 | */ |
||
| 3555 | 4 | public function krsort(int $sort_flags = 0): self |
|
| 3563 | |||
| 3564 | /** |
||
| 3565 | * Sort an array by key in reverse order. |
||
| 3566 | * |
||
| 3567 | * @param int $sort_flags [optional] <p> |
||
| 3568 | * You may modify the behavior of the sort using the optional |
||
| 3569 | * parameter sort_flags, for details |
||
| 3570 | * see sort. |
||
| 3571 | * </p> |
||
| 3572 | * |
||
| 3573 | * @return $this |
||
| 3574 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 3575 | * |
||
| 3576 | * @psalm-return static<TKey,T> |
||
| 3577 | * @psalm-mutation-free |
||
| 3578 | */ |
||
| 3579 | 4 | public function krsortImmutable(int $sort_flags = 0): self |
|
| 3590 | |||
| 3591 | /** |
||
| 3592 | * Get the last value from the current array. |
||
| 3593 | * |
||
| 3594 | * @return mixed|null |
||
| 3595 | * <p>Return null if there wasn't a element.</p> |
||
| 3596 | * @psalm-mutation-free |
||
| 3597 | */ |
||
| 3598 | 17 | public function last() |
|
| 3607 | |||
| 3608 | /** |
||
| 3609 | * Get the last key from the current array. |
||
| 3610 | * |
||
| 3611 | * @return mixed|null |
||
| 3612 | * <p>Return null if there wasn't a element.</p> |
||
| 3613 | * @psalm-mutation-free |
||
| 3614 | */ |
||
| 3615 | 21 | public function lastKey() |
|
| 3621 | |||
| 3622 | /** |
||
| 3623 | * Get the last value(s) from the current array. |
||
| 3624 | * |
||
| 3625 | * @param int|null $number |
||
| 3626 | * |
||
| 3627 | * @return static |
||
| 3628 | * <p>(Immutable)</p> |
||
| 3629 | * |
||
| 3630 | * @psalm-return static<TKey,T> |
||
| 3631 | * @psalm-mutation-free |
||
| 3632 | */ |
||
| 3633 | 13 | public function lastsImmutable(int $number = null): self |
|
| 3663 | |||
| 3664 | /** |
||
| 3665 | * Get the last value(s) from the current array. |
||
| 3666 | * |
||
| 3667 | * @param int|null $number |
||
| 3668 | * |
||
| 3669 | * @return $this |
||
| 3670 | * <p>(Mutable)</p> |
||
| 3671 | * |
||
| 3672 | * @psalm-return static<TKey,T> |
||
| 3673 | */ |
||
| 3674 | 13 | public function lastsMutable(int $number = null): self |
|
| 3702 | |||
| 3703 | /** |
||
| 3704 | * Count the values from the current array. |
||
| 3705 | * |
||
| 3706 | * alias: for "Arrayy->count()" |
||
| 3707 | * |
||
| 3708 | * @param int $mode |
||
| 3709 | * |
||
| 3710 | * @return int |
||
| 3711 | * |
||
| 3712 | * @see Arrayy::count() |
||
| 3713 | */ |
||
| 3714 | 20 | public function length(int $mode = \COUNT_NORMAL): int |
|
| 3718 | |||
| 3719 | /** |
||
| 3720 | * Apply the given function to the every element of the array, |
||
| 3721 | * collecting the results. |
||
| 3722 | * |
||
| 3723 | * @param callable $callable |
||
| 3724 | * @param bool $useKeyAsSecondParameter |
||
| 3725 | * @param mixed ...$arguments |
||
| 3726 | * |
||
| 3727 | * @return static |
||
| 3728 | * <p>(Immutable) Arrayy object with modified elements.</p> |
||
| 3729 | * |
||
| 3730 | * @psalm-param callable(T,TKey=,mixed=):mixed $callable |
||
| 3731 | * @psalm-return static<TKey,T> |
||
| 3732 | * @psalm-mutation-free |
||
| 3733 | */ |
||
| 3734 | 5 | public function map( |
|
| 3767 | |||
| 3768 | /** |
||
| 3769 | * Check if all items in current array match a truth test. |
||
| 3770 | * |
||
| 3771 | * @param \Closure $closure |
||
| 3772 | * |
||
| 3773 | * @return bool |
||
| 3774 | */ |
||
| 3775 | 15 | View Code Duplication | public function matches(\Closure $closure): bool |
| 3791 | |||
| 3792 | /** |
||
| 3793 | * Check if any item in the current array matches a truth test. |
||
| 3794 | * |
||
| 3795 | * @param \Closure $closure |
||
| 3796 | * |
||
| 3797 | * @return bool |
||
| 3798 | */ |
||
| 3799 | 14 | View Code Duplication | public function matchesAny(\Closure $closure): bool |
| 3815 | |||
| 3816 | /** |
||
| 3817 | * Get the max value from an array. |
||
| 3818 | * |
||
| 3819 | * @return false|mixed |
||
| 3820 | * <p>Will return false if there are no values.</p> |
||
| 3821 | */ |
||
| 3822 | 10 | View Code Duplication | public function max() |
| 3842 | |||
| 3843 | /** |
||
| 3844 | * Merge the new $array into the current array. |
||
| 3845 | * |
||
| 3846 | * - keep key,value from the current array, also if the index is in the new $array |
||
| 3847 | * |
||
| 3848 | * @param array $array |
||
| 3849 | * @param bool $recursive |
||
| 3850 | * |
||
| 3851 | * @return static |
||
| 3852 | * <p>(Immutable)</p> |
||
| 3853 | * |
||
| 3854 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 3855 | * @psalm-return static<int|TKey,T> |
||
| 3856 | * @psalm-mutation-free |
||
| 3857 | */ |
||
| 3858 | 32 | View Code Duplication | public function mergeAppendKeepIndex(array $array = [], bool $recursive = false): self |
| 3873 | |||
| 3874 | /** |
||
| 3875 | * Merge the new $array into the current array. |
||
| 3876 | * |
||
| 3877 | * - replace duplicate assoc-keys from the current array with the key,values from the new $array |
||
| 3878 | * - create new indexes |
||
| 3879 | * |
||
| 3880 | * @param array $array |
||
| 3881 | * @param bool $recursive |
||
| 3882 | * |
||
| 3883 | * @return static |
||
| 3884 | * <p>(Immutable)</p> |
||
| 3885 | * |
||
| 3886 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 3887 | * @psalm-return static<TKey,T> |
||
| 3888 | * @psalm-mutation-free |
||
| 3889 | */ |
||
| 3890 | 19 | View Code Duplication | public function mergeAppendNewIndex(array $array = [], bool $recursive = false): self |
| 3905 | |||
| 3906 | /** |
||
| 3907 | * Merge the the current array into the $array. |
||
| 3908 | * |
||
| 3909 | * - use key,value from the new $array, also if the index is in the current array |
||
| 3910 | * |
||
| 3911 | * @param array $array |
||
| 3912 | * @param bool $recursive |
||
| 3913 | * |
||
| 3914 | * @return static |
||
| 3915 | * <p>(Immutable)</p> |
||
| 3916 | * |
||
| 3917 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 3918 | * @psalm-return static<TKey,T> |
||
| 3919 | * @psalm-mutation-free |
||
| 3920 | */ |
||
| 3921 | 16 | View Code Duplication | public function mergePrependKeepIndex(array $array = [], bool $recursive = false): self |
| 3936 | |||
| 3937 | /** |
||
| 3938 | * Merge the current array into the new $array. |
||
| 3939 | * |
||
| 3940 | * - replace duplicate assoc-keys from new $array with the key,values from the current array |
||
| 3941 | * - create new indexes |
||
| 3942 | * |
||
| 3943 | * @param array $array |
||
| 3944 | * @param bool $recursive |
||
| 3945 | * |
||
| 3946 | * @return static |
||
| 3947 | * <p>(Immutable)</p> |
||
| 3948 | * |
||
| 3949 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 3950 | * @psalm-return static<TKey,T> |
||
| 3951 | * @psalm-mutation-free |
||
| 3952 | */ |
||
| 3953 | 20 | View Code Duplication | public function mergePrependNewIndex(array $array = [], bool $recursive = false): self |
| 3968 | |||
| 3969 | /** |
||
| 3970 | * @return ArrayyMeta|static |
||
| 3971 | */ |
||
| 3972 | 16 | public static function meta() |
|
| 3976 | |||
| 3977 | /** |
||
| 3978 | * Get the min value from an array. |
||
| 3979 | * |
||
| 3980 | * @return false|mixed |
||
| 3981 | * <p>Will return false if there are no values.</p> |
||
| 3982 | */ |
||
| 3983 | 10 | View Code Duplication | public function min() |
| 4003 | |||
| 4004 | /** |
||
| 4005 | * Get the most used value from the array. |
||
| 4006 | * |
||
| 4007 | * @return mixed|null |
||
| 4008 | * <p>(Immutable) Return null if there wasn't a element.</p> |
||
| 4009 | * @psalm-mutation-free |
||
| 4010 | */ |
||
| 4011 | 3 | public function mostUsedValue() |
|
| 4015 | |||
| 4016 | /** |
||
| 4017 | * Get the most used value from the array. |
||
| 4018 | * |
||
| 4019 | * @param int|null $number <p>How many values you will take?</p> |
||
| 4020 | * |
||
| 4021 | * @return static |
||
| 4022 | * <p>(Immutable)</p> |
||
| 4023 | * |
||
| 4024 | * @psalm-return static<TKey,T> |
||
| 4025 | * @psalm-mutation-free |
||
| 4026 | */ |
||
| 4027 | 3 | public function mostUsedValues(int $number = null): self |
|
| 4031 | |||
| 4032 | /** |
||
| 4033 | * Move an array element to a new index. |
||
| 4034 | * |
||
| 4035 | * cherry-picked from: http://stackoverflow.com/questions/12624153/move-an-array-element-to-a-new-index-in-php |
||
| 4036 | * |
||
| 4037 | * @param int|string $from |
||
| 4038 | * @param int $to |
||
| 4039 | * |
||
| 4040 | * @return static |
||
| 4041 | * <p>(Immutable)</p> |
||
| 4042 | * |
||
| 4043 | * @psalm-return static<TKey,T> |
||
| 4044 | * @psalm-mutation-free |
||
| 4045 | */ |
||
| 4046 | 1 | public function moveElement($from, $to): self |
|
| 4079 | |||
| 4080 | /** |
||
| 4081 | * Move an array element to the first place. |
||
| 4082 | * |
||
| 4083 | * INFO: Instead of "Arrayy->moveElement()" this method will NOT |
||
| 4084 | * loss the keys of an indexed array. |
||
| 4085 | * |
||
| 4086 | * @param int|string $key |
||
| 4087 | * |
||
| 4088 | * @return static |
||
| 4089 | * <p>(Immutable)</p> |
||
| 4090 | * |
||
| 4091 | * @psalm-return static<TKey,T> |
||
| 4092 | * @psalm-mutation-free |
||
| 4093 | */ |
||
| 4094 | 1 | View Code Duplication | public function moveElementToFirstPlace($key): self |
| 4110 | |||
| 4111 | /** |
||
| 4112 | * Move an array element to the last place. |
||
| 4113 | * |
||
| 4114 | * INFO: Instead of "Arrayy->moveElement()" this method will NOT |
||
| 4115 | * loss the keys of an indexed array. |
||
| 4116 | * |
||
| 4117 | * @param int|string $key |
||
| 4118 | * |
||
| 4119 | * @return static |
||
| 4120 | * <p>(Immutable)</p> |
||
| 4121 | * |
||
| 4122 | * @psalm-return static<TKey,T> |
||
| 4123 | * @psalm-mutation-free |
||
| 4124 | */ |
||
| 4125 | 1 | View Code Duplication | public function moveElementToLastPlace($key): self |
| 4141 | |||
| 4142 | /** |
||
| 4143 | * Moves the internal iterator position to the next element and returns this element. |
||
| 4144 | * |
||
| 4145 | * @return false|mixed |
||
| 4146 | * <p>(Mutable) Will return false if there are no values.</p> |
||
| 4147 | */ |
||
| 4148 | public function next() |
||
| 4152 | |||
| 4153 | /** |
||
| 4154 | * Get the next nth keys and values from the array. |
||
| 4155 | * |
||
| 4156 | * @param int $step |
||
| 4157 | * @param int $offset |
||
| 4158 | * |
||
| 4159 | * @return static |
||
| 4160 | * <p>(Immutable)</p> |
||
| 4161 | * |
||
| 4162 | * @psalm-return static<TKey,T> |
||
| 4163 | * @psalm-mutation-free |
||
| 4164 | */ |
||
| 4165 | 1 | public function nth(int $step, int $offset = 0): self |
|
| 4184 | |||
| 4185 | /** |
||
| 4186 | * Get a subset of the items from the given array. |
||
| 4187 | * |
||
| 4188 | * @param mixed[] $keys |
||
| 4189 | * |
||
| 4190 | * @return static |
||
| 4191 | * <p>(Immutable)</p> |
||
| 4192 | * |
||
| 4193 | * @psalm-return static<TKey,T> |
||
| 4194 | * @psalm-mutation-free |
||
| 4195 | */ |
||
| 4196 | 1 | public function only(array $keys): self |
|
| 4206 | |||
| 4207 | /** |
||
| 4208 | * Pad array to the specified size with a given value. |
||
| 4209 | * |
||
| 4210 | * @param int $size <p>Size of the result array.</p> |
||
| 4211 | * @param mixed $value <p>Empty value by default.</p> |
||
| 4212 | * |
||
| 4213 | * @return static |
||
| 4214 | * <p>(Immutable) Arrayy object padded to $size with $value.</p> |
||
| 4215 | * |
||
| 4216 | * @psalm-return static<TKey,T> |
||
| 4217 | * @psalm-mutation-free |
||
| 4218 | */ |
||
| 4219 | 5 | public function pad(int $size, $value): self |
|
| 4227 | |||
| 4228 | /** |
||
| 4229 | * Partitions this array in two array according to a predicate. |
||
| 4230 | * Keys are preserved in the resulting array. |
||
| 4231 | * |
||
| 4232 | * @param \Closure $closure |
||
| 4233 | * <p>The predicate on which to partition.</p> |
||
| 4234 | * |
||
| 4235 | * @return array<int, static> |
||
| 4236 | * <p>An array with two elements. The first element contains the array |
||
| 4237 | * of elements where the predicate returned TRUE, the second element |
||
| 4238 | * contains the array of elements where the predicate returned FALSE.</p> |
||
| 4239 | * |
||
| 4240 | * @psalm-return array<int, static<TKey,T>> |
||
| 4241 | */ |
||
| 4242 | 1 | public function partition(\Closure $closure): array |
|
| 4258 | |||
| 4259 | /** |
||
| 4260 | * Pop a specified value off the end of the current array. |
||
| 4261 | * |
||
| 4262 | * @return mixed|null |
||
| 4263 | * <p>(Mutable) The popped element from the current array or null if the array is e.g. empty.</p> |
||
| 4264 | */ |
||
| 4265 | 5 | public function pop() |
|
| 4271 | |||
| 4272 | /** |
||
| 4273 | * Prepend a (key) + value to the current array. |
||
| 4274 | * |
||
| 4275 | * EXAMPLE: <code> |
||
| 4276 | * a(['fòô' => 'bàř'])->prepend('foo'); // Arrayy[0 => 'foo', 'fòô' => 'bàř'] |
||
| 4277 | * </code> |
||
| 4278 | * |
||
| 4279 | * @param mixed $value |
||
| 4280 | * @param mixed $key |
||
| 4281 | * |
||
| 4282 | * @return $this |
||
| 4283 | * <p>(Mutable) Return this Arrayy object, with the prepended value.</p> |
||
| 4284 | * |
||
| 4285 | * @psalm-return static<TKey,T> |
||
| 4286 | */ |
||
| 4287 | 11 | public function prepend($value, $key = null) |
|
| 4303 | |||
| 4304 | /** |
||
| 4305 | * Add a suffix to each key. |
||
| 4306 | * |
||
| 4307 | * @param mixed $suffix |
||
| 4308 | * |
||
| 4309 | * @return static |
||
| 4310 | * <p>(Immutable) Return an Arrayy object, with the prepended keys.</p> |
||
| 4311 | * |
||
| 4312 | * @psalm-return static<TKey,T> |
||
| 4313 | * @psalm-mutation-free |
||
| 4314 | */ |
||
| 4315 | 10 | View Code Duplication | public function prependToEachKey($suffix): self |
| 4341 | |||
| 4342 | /** |
||
| 4343 | * Add a suffix to each value. |
||
| 4344 | * |
||
| 4345 | * @param mixed $suffix |
||
| 4346 | * |
||
| 4347 | * @return static |
||
| 4348 | * <p>(Immutable) Return an Arrayy object, with the prepended values.</p> |
||
| 4349 | * |
||
| 4350 | * @psalm-return static<TKey,T> |
||
| 4351 | * @psalm-mutation-free |
||
| 4352 | */ |
||
| 4353 | 10 | View Code Duplication | public function prependToEachValue($suffix): self |
| 4381 | |||
| 4382 | /** |
||
| 4383 | * Return the value of a given key and |
||
| 4384 | * delete the key. |
||
| 4385 | * |
||
| 4386 | * @param int|int[]|string|string[]|null $keyOrKeys |
||
| 4387 | * @param mixed $fallback |
||
| 4388 | * |
||
| 4389 | * @return mixed |
||
| 4390 | */ |
||
| 4391 | 5 | public function pull($keyOrKeys = null, $fallback = null) |
|
| 4413 | |||
| 4414 | /** |
||
| 4415 | * Push one or more values onto the end of array at once. |
||
| 4416 | * |
||
| 4417 | * @param array ...$args |
||
| 4418 | * |
||
| 4419 | * @return $this |
||
| 4420 | * <p>(Mutable) Return this Arrayy object, with pushed elements to the end of array.</p> |
||
| 4421 | * |
||
| 4422 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
| 4423 | * |
||
| 4424 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$args |
||
| 4425 | * @psalm-return static<TKey,T> |
||
| 4426 | */ |
||
| 4427 | 7 | public function push(...$args) |
|
| 4445 | |||
| 4446 | /** |
||
| 4447 | * Get a random value from the current array. |
||
| 4448 | * |
||
| 4449 | * @param int|null $number <p>How many values you will take?</p> |
||
| 4450 | * |
||
| 4451 | * @return static |
||
| 4452 | * <p>(Immutable)</p> |
||
| 4453 | * |
||
| 4454 | * @psalm-return static<int|array-key,T> |
||
| 4455 | */ |
||
| 4456 | 19 | public function randomImmutable(int $number = null): self |
|
| 4489 | |||
| 4490 | /** |
||
| 4491 | * Pick a random key/index from the keys of this array. |
||
| 4492 | * |
||
| 4493 | * @throws \RangeException If array is empty |
||
| 4494 | * |
||
| 4495 | * @return mixed |
||
| 4496 | * <p>Get a key/index or null if there wasn't a key/index.</p> |
||
| 4497 | */ |
||
| 4498 | 4 | public function randomKey() |
|
| 4508 | |||
| 4509 | /** |
||
| 4510 | * Pick a given number of random keys/indexes out of this array. |
||
| 4511 | * |
||
| 4512 | * @param int $number <p>The number of keys/indexes (should be <= \count($this->array))</p> |
||
| 4513 | * |
||
| 4514 | * @throws \RangeException If array is empty |
||
| 4515 | * |
||
| 4516 | * @return static |
||
| 4517 | * <p>(Immutable)</p> |
||
| 4518 | * |
||
| 4519 | * @psalm-return static<TKey,T> |
||
| 4520 | */ |
||
| 4521 | 13 | public function randomKeys(int $number): self |
|
| 4549 | |||
| 4550 | /** |
||
| 4551 | * Get a random value from the current array. |
||
| 4552 | * |
||
| 4553 | * @param int|null $number <p>How many values you will take?</p> |
||
| 4554 | * |
||
| 4555 | * @return $this |
||
| 4556 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 4557 | * |
||
| 4558 | * @psalm-return static<TKey,T> |
||
| 4559 | */ |
||
| 4560 | 17 | public function randomMutable(int $number = null): self |
|
| 4585 | |||
| 4586 | /** |
||
| 4587 | * Pick a random value from the values of this array. |
||
| 4588 | * |
||
| 4589 | * @return mixed |
||
| 4590 | * <p>Get a random value or null if there wasn't a value.</p> |
||
| 4591 | */ |
||
| 4592 | 4 | public function randomValue() |
|
| 4602 | |||
| 4603 | /** |
||
| 4604 | * Pick a given number of random values out of this array. |
||
| 4605 | * |
||
| 4606 | * @param int $number |
||
| 4607 | * |
||
| 4608 | * @return static |
||
| 4609 | * <p>(Mutable)</p> |
||
| 4610 | * |
||
| 4611 | * @psalm-return static<TKey,T> |
||
| 4612 | */ |
||
| 4613 | 7 | public function randomValues(int $number): self |
|
| 4617 | |||
| 4618 | /** |
||
| 4619 | * Get a random value from an array, with the ability to skew the results. |
||
| 4620 | * |
||
| 4621 | * Example: randomWeighted(['foo' => 1, 'bar' => 2]) has a 66% chance of returning bar. |
||
| 4622 | * |
||
| 4623 | * @param array $array |
||
| 4624 | * @param int|null $number <p>How many values you will take?</p> |
||
| 4625 | * |
||
| 4626 | * @return static<int,mixed> |
||
| 4627 | * <p>(Immutable)</p> |
||
| 4628 | * |
||
| 4629 | * @psalm-param array<mixed,mixed> $array |
||
| 4630 | * @psalm-return static<int|array-key,T> |
||
| 4631 | */ |
||
| 4632 | 9 | public function randomWeighted(array $array, int $number = null): self |
|
| 4647 | |||
| 4648 | /** |
||
| 4649 | * Reduce the current array via callable e.g. anonymous-function. |
||
| 4650 | * |
||
| 4651 | * @param callable $callable |
||
| 4652 | * @param mixed $init |
||
| 4653 | * |
||
| 4654 | * @return static |
||
| 4655 | * <p>(Immutable)</p> |
||
| 4656 | * |
||
| 4657 | * @psalm-return static<TKey,T> |
||
| 4658 | * @psalm-mutation-free |
||
| 4659 | */ |
||
| 4660 | 18 | public function reduce($callable, $init = []): self |
|
| 4690 | |||
| 4691 | /** |
||
| 4692 | * @param bool $unique |
||
| 4693 | * |
||
| 4694 | * @return static |
||
| 4695 | * <p>(Immutable)</p> |
||
| 4696 | * |
||
| 4697 | * @psalm-return static<TKey,T> |
||
| 4698 | * @psalm-mutation-free |
||
| 4699 | */ |
||
| 4700 | 14 | public function reduce_dimension(bool $unique = true): self |
|
| 4723 | |||
| 4724 | /** |
||
| 4725 | * Create a numerically re-indexed Arrayy object. |
||
| 4726 | * |
||
| 4727 | * @return $this |
||
| 4728 | * <p>(Mutable) Return this Arrayy object, with re-indexed array-elements.</p> |
||
| 4729 | * |
||
| 4730 | * @psalm-return static<TKey,T> |
||
| 4731 | */ |
||
| 4732 | 9 | public function reindex(): self |
|
| 4740 | |||
| 4741 | /** |
||
| 4742 | * Return all items that fail the truth test. |
||
| 4743 | * |
||
| 4744 | * @param \Closure $closure |
||
| 4745 | * |
||
| 4746 | * @return static |
||
| 4747 | * <p>(Immutable)</p> |
||
| 4748 | * |
||
| 4749 | * @psalm-return static<TKey,T> |
||
| 4750 | * @psalm-mutation-free |
||
| 4751 | */ |
||
| 4752 | 1 | View Code Duplication | public function reject(\Closure $closure): self |
| 4769 | |||
| 4770 | /** |
||
| 4771 | * Remove a value from the current array (optional using dot-notation). |
||
| 4772 | * |
||
| 4773 | * @param mixed $key |
||
| 4774 | * |
||
| 4775 | * @return static |
||
| 4776 | * <p>(Mutable)</p> |
||
| 4777 | * |
||
| 4778 | * @psalm-param TKey $key |
||
| 4779 | * @psalm-return static<TKey,T> |
||
| 4780 | */ |
||
| 4781 | 21 | public function remove($key) |
|
| 4804 | |||
| 4805 | /** |
||
| 4806 | * alias: for "Arrayy->removeValue()" |
||
| 4807 | * |
||
| 4808 | * @param mixed $element |
||
| 4809 | * |
||
| 4810 | * @return static |
||
| 4811 | * <p>(Immutable)</p> |
||
| 4812 | * |
||
| 4813 | * @psalm-param T $element |
||
| 4814 | * @psalm-return static<TKey,T> |
||
| 4815 | * @psalm-mutation-free |
||
| 4816 | */ |
||
| 4817 | 8 | public function removeElement($element) |
|
| 4821 | |||
| 4822 | /** |
||
| 4823 | * Remove the first value from the current array. |
||
| 4824 | * |
||
| 4825 | * @return static |
||
| 4826 | * <p>(Immutable)</p> |
||
| 4827 | * |
||
| 4828 | * @psalm-return static<TKey,T> |
||
| 4829 | * @psalm-mutation-free |
||
| 4830 | */ |
||
| 4831 | 7 | View Code Duplication | public function removeFirst(): self |
| 4843 | |||
| 4844 | /** |
||
| 4845 | * Remove the last value from the current array. |
||
| 4846 | * |
||
| 4847 | * @return static |
||
| 4848 | * <p>(Immutable)</p> |
||
| 4849 | * |
||
| 4850 | * @psalm-return static<TKey,T> |
||
| 4851 | * @psalm-mutation-free |
||
| 4852 | */ |
||
| 4853 | 7 | View Code Duplication | public function removeLast(): self |
| 4865 | |||
| 4866 | /** |
||
| 4867 | * Removes a particular value from an array (numeric or associative). |
||
| 4868 | * |
||
| 4869 | * @param mixed $value |
||
| 4870 | * |
||
| 4871 | * @return static |
||
| 4872 | * <p>(Immutable)</p> |
||
| 4873 | * |
||
| 4874 | * @psalm-param T $value |
||
| 4875 | * @psalm-return static<TKey,T> |
||
| 4876 | * @psalm-mutation-free |
||
| 4877 | */ |
||
| 4878 | 8 | public function removeValue($value): self |
|
| 4901 | |||
| 4902 | /** |
||
| 4903 | * Generate array of repeated arrays. |
||
| 4904 | * |
||
| 4905 | * @param int $times <p>How many times has to be repeated.</p> |
||
| 4906 | * |
||
| 4907 | * @return static |
||
| 4908 | * <p>(Immutable)</p> |
||
| 4909 | * |
||
| 4910 | * @psalm-return static<TKey,T> |
||
| 4911 | * @psalm-mutation-free |
||
| 4912 | */ |
||
| 4913 | 1 | public function repeat($times): self |
|
| 4925 | |||
| 4926 | /** |
||
| 4927 | * Replace a key with a new key/value pair. |
||
| 4928 | * |
||
| 4929 | * @param mixed $oldKey |
||
| 4930 | * @param mixed $newKey |
||
| 4931 | * @param mixed $newValue |
||
| 4932 | * |
||
| 4933 | * @return static |
||
| 4934 | * <p>(Immutable)</p> |
||
| 4935 | * |
||
| 4936 | * @psalm-return static<TKey,T> |
||
| 4937 | * @psalm-mutation-free |
||
| 4938 | */ |
||
| 4939 | 5 | public function replace($oldKey, $newKey, $newValue): self |
|
| 4949 | |||
| 4950 | /** |
||
| 4951 | * Create an array using the current array as values and the other array as keys. |
||
| 4952 | * |
||
| 4953 | * @param array $keys <p>An array of keys.</p> |
||
| 4954 | * |
||
| 4955 | * @return static |
||
| 4956 | * <p>(Immutable) Arrayy object with keys from the other array.</p> |
||
| 4957 | * |
||
| 4958 | * @psalm-param array<mixed,mixed>|array<mixed,TKey> $keys |
||
| 4959 | * @psalm-return static<TKey,T> |
||
| 4960 | * @psalm-mutation-free |
||
| 4961 | */ |
||
| 4962 | 2 | public function replaceAllKeys(array $keys): self |
|
| 4970 | |||
| 4971 | /** |
||
| 4972 | * Create an array using the current array as keys and the other array as values. |
||
| 4973 | * |
||
| 4974 | * @param array $array <p>An array o values.</p> |
||
| 4975 | * |
||
| 4976 | * @return static |
||
| 4977 | * <p>(Immutable) Arrayy object with values from the other array.</p> |
||
| 4978 | * |
||
| 4979 | * @psalm-param array<mixed,T> $array |
||
| 4980 | * @psalm-return static<TKey,T> |
||
| 4981 | * @psalm-mutation-free |
||
| 4982 | */ |
||
| 4983 | 2 | public function replaceAllValues(array $array): self |
|
| 4991 | |||
| 4992 | /** |
||
| 4993 | * Replace the keys in an array with another set. |
||
| 4994 | * |
||
| 4995 | * @param array $keys <p>An array of keys matching the array's size</p> |
||
| 4996 | * |
||
| 4997 | * @return static |
||
| 4998 | * <p>(Immutable)</p> |
||
| 4999 | * |
||
| 5000 | * @psalm-param array<mixed,mixed>|array<mixed,TKey> $keys |
||
| 5001 | * @psalm-return static<TKey,T> |
||
| 5002 | * @psalm-mutation-free |
||
| 5003 | */ |
||
| 5004 | 1 | public function replaceKeys(array $keys): self |
|
| 5015 | |||
| 5016 | /** |
||
| 5017 | * Replace the first matched value in an array. |
||
| 5018 | * |
||
| 5019 | * @param mixed $search <p>The value to replace.</p> |
||
| 5020 | * @param mixed $replacement <p>The value to replace.</p> |
||
| 5021 | * |
||
| 5022 | * @return static |
||
| 5023 | * <p>(Immutable)</p> |
||
| 5024 | * |
||
| 5025 | * @psalm-return static<TKey,T> |
||
| 5026 | * @psalm-mutation-free |
||
| 5027 | */ |
||
| 5028 | 3 | View Code Duplication | public function replaceOneValue($search, $replacement = ''): self |
| 5043 | |||
| 5044 | /** |
||
| 5045 | * Replace values in the current array. |
||
| 5046 | * |
||
| 5047 | * @param mixed $search <p>The value to replace.</p> |
||
| 5048 | * @param mixed $replacement <p>What to replace it with.</p> |
||
| 5049 | * |
||
| 5050 | * @return static |
||
| 5051 | * <p>(Immutable)</p> |
||
| 5052 | * |
||
| 5053 | * @psalm-return static<TKey,T> |
||
| 5054 | * @psalm-mutation-free |
||
| 5055 | */ |
||
| 5056 | 1 | public function replaceValues($search, $replacement = ''): self |
|
| 5068 | |||
| 5069 | /** |
||
| 5070 | * Get the last elements from index $from until the end of this array. |
||
| 5071 | * |
||
| 5072 | * @param int $from |
||
| 5073 | * |
||
| 5074 | * @return static |
||
| 5075 | * <p>(Immutable)</p> |
||
| 5076 | * |
||
| 5077 | * @psalm-return static<TKey,T> |
||
| 5078 | * @psalm-mutation-free |
||
| 5079 | */ |
||
| 5080 | 15 | View Code Duplication | public function rest(int $from = 1): self |
| 5090 | |||
| 5091 | /** |
||
| 5092 | * Return the array in the reverse order. |
||
| 5093 | * |
||
| 5094 | * @return $this |
||
| 5095 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 5096 | * |
||
| 5097 | * @psalm-return static<TKey,T> |
||
| 5098 | */ |
||
| 5099 | 9 | public function reverse(): self |
|
| 5107 | |||
| 5108 | /** |
||
| 5109 | * Sort an array in reverse order. |
||
| 5110 | * |
||
| 5111 | * @param int $sort_flags [optional] <p> |
||
| 5112 | * You may modify the behavior of the sort using the optional |
||
| 5113 | * parameter sort_flags, for details |
||
| 5114 | * see sort. |
||
| 5115 | * </p> |
||
| 5116 | * |
||
| 5117 | * @return $this |
||
| 5118 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 5119 | * |
||
| 5120 | * @psalm-return static<TKey,T> |
||
| 5121 | */ |
||
| 5122 | 4 | public function rsort(int $sort_flags = 0): self |
|
| 5130 | |||
| 5131 | /** |
||
| 5132 | * Sort an array in reverse order. |
||
| 5133 | * |
||
| 5134 | * @param int $sort_flags [optional] <p> |
||
| 5135 | * You may modify the behavior of the sort using the optional |
||
| 5136 | * parameter sort_flags, for details |
||
| 5137 | * see sort. |
||
| 5138 | * </p> |
||
| 5139 | * |
||
| 5140 | * @return $this |
||
| 5141 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 5142 | * |
||
| 5143 | * @psalm-return static<TKey,T> |
||
| 5144 | * @psalm-mutation-free |
||
| 5145 | */ |
||
| 5146 | 4 | public function rsortImmutable(int $sort_flags = 0): self |
|
| 5157 | |||
| 5158 | /** |
||
| 5159 | * Search for the first index of the current array via $value. |
||
| 5160 | * |
||
| 5161 | * @param mixed $value |
||
| 5162 | * |
||
| 5163 | * @return false|float|int|string |
||
| 5164 | * <p>Will return <b>FALSE</b> if the value can't be found.</p> |
||
| 5165 | * @psalm-mutation-free |
||
| 5166 | */ |
||
| 5167 | 21 | public function searchIndex($value) |
|
| 5177 | |||
| 5178 | /** |
||
| 5179 | * Search for the value of the current array via $index. |
||
| 5180 | * |
||
| 5181 | * @param mixed $index |
||
| 5182 | * |
||
| 5183 | * @return static |
||
| 5184 | * <p>(Immutable) Will return a empty Arrayy if the value wasn't found.</p> |
||
| 5185 | * |
||
| 5186 | * @psalm-return static<TKey,T> |
||
| 5187 | * @psalm-mutation-free |
||
| 5188 | */ |
||
| 5189 | 9 | public function searchValue($index): self |
|
| 5219 | |||
| 5220 | /** |
||
| 5221 | * Set a value for the current array (optional using dot-notation). |
||
| 5222 | * |
||
| 5223 | * @param string $key <p>The key to set.</p> |
||
| 5224 | * @param mixed $value <p>Its value.</p> |
||
| 5225 | * |
||
| 5226 | * @return $this |
||
| 5227 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 5228 | * |
||
| 5229 | * @psalm-param TKey $key |
||
| 5230 | * @psalm-param T $value |
||
| 5231 | * @psalm-return static<TKey,T> |
||
| 5232 | */ |
||
| 5233 | 28 | public function set($key, $value): self |
|
| 5239 | |||
| 5240 | /** |
||
| 5241 | * Get a value from a array and set it if it was not. |
||
| 5242 | * |
||
| 5243 | * WARNING: this method only set the value, if the $key is not already set |
||
| 5244 | * |
||
| 5245 | * @param mixed $key <p>The key</p> |
||
| 5246 | * @param mixed $fallback <p>The default value to set if it isn't.</p> |
||
| 5247 | * |
||
| 5248 | * @return mixed |
||
| 5249 | * <p>(Mutable)</p> |
||
| 5250 | */ |
||
| 5251 | 11 | public function setAndGet($key, $fallback = null) |
|
| 5262 | |||
| 5263 | /** |
||
| 5264 | * Shifts a specified value off the beginning of array. |
||
| 5265 | * |
||
| 5266 | * @return mixed |
||
| 5267 | * <p>(Mutable) A shifted element from the current array.</p> |
||
| 5268 | */ |
||
| 5269 | 5 | public function shift() |
|
| 5275 | |||
| 5276 | /** |
||
| 5277 | * Shuffle the current array. |
||
| 5278 | * |
||
| 5279 | * @param bool $secure <p>using a CSPRNG | @link https://paragonie.com/b/JvICXzh_jhLyt4y3</p> |
||
| 5280 | * @param array $array [optional] |
||
| 5281 | * |
||
| 5282 | * @return static |
||
| 5283 | * <p>(Immutable)</p> |
||
| 5284 | * |
||
| 5285 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 5286 | * @psalm-return static<TKey,T> |
||
| 5287 | * |
||
| 5288 | * @noinspection BadExceptionsProcessingInspection |
||
| 5289 | * @noinspection RandomApiMigrationInspection |
||
| 5290 | * @noinspection NonSecureShuffleUsageInspection |
||
| 5291 | */ |
||
| 5292 | 2 | public function shuffle(bool $secure = false, array $array = null): self |
|
| 5330 | |||
| 5331 | /** |
||
| 5332 | * Count the values from the current array. |
||
| 5333 | * |
||
| 5334 | * alias: for "Arrayy->count()" |
||
| 5335 | * |
||
| 5336 | * @param int $mode |
||
| 5337 | * |
||
| 5338 | * @return int |
||
| 5339 | */ |
||
| 5340 | 20 | public function size(int $mode = \COUNT_NORMAL): int |
|
| 5344 | |||
| 5345 | /** |
||
| 5346 | * Checks whether array has exactly $size items. |
||
| 5347 | * |
||
| 5348 | * @param int $size |
||
| 5349 | * |
||
| 5350 | * @return bool |
||
| 5351 | */ |
||
| 5352 | 1 | public function sizeIs(int $size): bool |
|
| 5368 | |||
| 5369 | /** |
||
| 5370 | * Checks whether array has between $fromSize to $toSize items. $toSize can be |
||
| 5371 | * smaller than $fromSize. |
||
| 5372 | * |
||
| 5373 | * @param int $fromSize |
||
| 5374 | * @param int $toSize |
||
| 5375 | * |
||
| 5376 | * @return bool |
||
| 5377 | */ |
||
| 5378 | 1 | public function sizeIsBetween(int $fromSize, int $toSize): bool |
|
| 5398 | |||
| 5399 | /** |
||
| 5400 | * Checks whether array has more than $size items. |
||
| 5401 | * |
||
| 5402 | * @param int $size |
||
| 5403 | * |
||
| 5404 | * @return bool |
||
| 5405 | */ |
||
| 5406 | 1 | View Code Duplication | public function sizeIsGreaterThan(int $size): bool |
| 5420 | |||
| 5421 | /** |
||
| 5422 | * Checks whether array has less than $size items. |
||
| 5423 | * |
||
| 5424 | * @param int $size |
||
| 5425 | * |
||
| 5426 | * @return bool |
||
| 5427 | */ |
||
| 5428 | 1 | View Code Duplication | public function sizeIsLessThan(int $size): bool |
| 5442 | |||
| 5443 | /** |
||
| 5444 | * Counts all elements in an array, or something in an object. |
||
| 5445 | * |
||
| 5446 | * <p> |
||
| 5447 | * For objects, if you have SPL installed, you can hook into count() by implementing interface {@see Countable}. |
||
| 5448 | * The interface has exactly one method, {@see Countable::count()}, which returns the return value for the count() |
||
| 5449 | * function. Please see the {@see Array} section of the manual for a detailed explanation of how arrays are |
||
| 5450 | * implemented and used in PHP. |
||
| 5451 | * </p> |
||
| 5452 | * |
||
| 5453 | * @return int |
||
| 5454 | * <p> |
||
| 5455 | * The number of elements in var, which is |
||
| 5456 | * typically an array, since anything else will have one |
||
| 5457 | * element. |
||
| 5458 | * </p> |
||
| 5459 | * <p> |
||
| 5460 | * If var is not an array or an object with |
||
| 5461 | * implemented Countable interface, |
||
| 5462 | * 1 will be returned. |
||
| 5463 | * There is one exception, if var is &null;, |
||
| 5464 | * 0 will be returned. |
||
| 5465 | * </p> |
||
| 5466 | * <p> |
||
| 5467 | * Caution: count may return 0 for a variable that isn't set, |
||
| 5468 | * but it may also return 0 for a variable that has been initialized with an |
||
| 5469 | * empty array. Use isset to test if a variable is set. |
||
| 5470 | * </p> |
||
| 5471 | */ |
||
| 5472 | 10 | public function sizeRecursive(): int |
|
| 5476 | |||
| 5477 | /** |
||
| 5478 | * Extract a slice of the array. |
||
| 5479 | * |
||
| 5480 | * @param int $offset <p>Slice begin index.</p> |
||
| 5481 | * @param int|null $length <p>Length of the slice.</p> |
||
| 5482 | * @param bool $preserveKeys <p>Whether array keys are preserved or no.</p> |
||
| 5483 | * |
||
| 5484 | * @return static |
||
| 5485 | * <p>(Immutable) A slice of the original array with length $length.</p> |
||
| 5486 | * |
||
| 5487 | * @psalm-return static<TKey,T> |
||
| 5488 | * @psalm-mutation-free |
||
| 5489 | */ |
||
| 5490 | 5 | public function slice(int $offset, int $length = null, bool $preserveKeys = false) |
|
| 5503 | |||
| 5504 | /** |
||
| 5505 | * Sort the current array and optional you can keep the keys. |
||
| 5506 | * |
||
| 5507 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 5508 | * @param int $strategy <p>sort_flags => use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 5509 | * <strong>SORT_NATURAL</strong></p> |
||
| 5510 | * @param bool $keepKeys |
||
| 5511 | * |
||
| 5512 | * @return static |
||
| 5513 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 5514 | * |
||
| 5515 | * @psalm-return static<TKey,T> |
||
| 5516 | */ |
||
| 5517 | 20 | public function sort( |
|
| 5531 | |||
| 5532 | /** |
||
| 5533 | * Sort the current array and optional you can keep the keys. |
||
| 5534 | * |
||
| 5535 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 5536 | * @param int $strategy <p>sort_flags => use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 5537 | * <strong>SORT_NATURAL</strong></p> |
||
| 5538 | * @param bool $keepKeys |
||
| 5539 | * |
||
| 5540 | * @return static |
||
| 5541 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 5542 | * |
||
| 5543 | * @psalm-return static<TKey,T> |
||
| 5544 | */ |
||
| 5545 | 12 | public function sortImmutable( |
|
| 5561 | |||
| 5562 | /** |
||
| 5563 | * Sort the current array by key. |
||
| 5564 | * |
||
| 5565 | * @see http://php.net/manual/en/function.ksort.php |
||
| 5566 | * @see http://php.net/manual/en/function.krsort.php |
||
| 5567 | * |
||
| 5568 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 5569 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 5570 | * <strong>SORT_NATURAL</strong></p> |
||
| 5571 | * |
||
| 5572 | * @return $this |
||
| 5573 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 5574 | * |
||
| 5575 | * @psalm-return static<TKey,T> |
||
| 5576 | */ |
||
| 5577 | 18 | public function sortKeys( |
|
| 5587 | |||
| 5588 | /** |
||
| 5589 | * Sort the current array by key. |
||
| 5590 | * |
||
| 5591 | * @see http://php.net/manual/en/function.ksort.php |
||
| 5592 | * @see http://php.net/manual/en/function.krsort.php |
||
| 5593 | * |
||
| 5594 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 5595 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 5596 | * <strong>SORT_NATURAL</strong></p> |
||
| 5597 | * |
||
| 5598 | * @return $this |
||
| 5599 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 5600 | * |
||
| 5601 | * @psalm-return static<TKey,T> |
||
| 5602 | * @psalm-mutation-free |
||
| 5603 | */ |
||
| 5604 | 8 | public function sortKeysImmutable( |
|
| 5617 | |||
| 5618 | /** |
||
| 5619 | * Sort the current array by value. |
||
| 5620 | * |
||
| 5621 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 5622 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 5623 | * <strong>SORT_NATURAL</strong></p> |
||
| 5624 | * |
||
| 5625 | * @return static |
||
| 5626 | * <p>(Mutable)</p> |
||
| 5627 | * |
||
| 5628 | * @psalm-return static<TKey,T> |
||
| 5629 | */ |
||
| 5630 | 1 | public function sortValueKeepIndex( |
|
| 5636 | |||
| 5637 | /** |
||
| 5638 | * Sort the current array by value. |
||
| 5639 | * |
||
| 5640 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 5641 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 5642 | * <strong>SORT_NATURAL</strong></p> |
||
| 5643 | * |
||
| 5644 | * @return static |
||
| 5645 | * <p>(Mutable)</p> |
||
| 5646 | * |
||
| 5647 | * @psalm-return static<TKey,T> |
||
| 5648 | */ |
||
| 5649 | 1 | public function sortValueNewIndex($direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
| 5653 | |||
| 5654 | /** |
||
| 5655 | * Sort a array by value, by a closure or by a property. |
||
| 5656 | * |
||
| 5657 | * - If the sorter is null, the array is sorted naturally. |
||
| 5658 | * - Associative (string) keys will be maintained, but numeric keys will be re-indexed. |
||
| 5659 | * |
||
| 5660 | * @param callable|string|null $sorter |
||
| 5661 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or |
||
| 5662 | * <strong>SORT_DESC</strong></p> |
||
| 5663 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 5664 | * <strong>SORT_NATURAL</strong></p> |
||
| 5665 | * |
||
| 5666 | * @return static |
||
| 5667 | * <p>(Immutable)</p> |
||
| 5668 | * |
||
| 5669 | * @psalm-return static<TKey,T> |
||
| 5670 | * @psalm-mutation-free |
||
| 5671 | */ |
||
| 5672 | 1 | public function sorter($sorter = null, $direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
| 5713 | |||
| 5714 | /** |
||
| 5715 | * @param int $offset |
||
| 5716 | * @param int|null $length |
||
| 5717 | * @param array $replacement |
||
| 5718 | * |
||
| 5719 | * @return static |
||
| 5720 | * <p>(Immutable)</p> |
||
| 5721 | * |
||
| 5722 | * @psalm-param array<mixed,mixed>|array<mixed,T> $replacement |
||
| 5723 | * @psalm-return static<TKey,T> |
||
| 5724 | * @psalm-mutation-free |
||
| 5725 | */ |
||
| 5726 | 1 | public function splice(int $offset, int $length = null, $replacement = []): self |
|
| 5743 | |||
| 5744 | /** |
||
| 5745 | * Split an array in the given amount of pieces. |
||
| 5746 | * |
||
| 5747 | * @param int $numberOfPieces |
||
| 5748 | * @param bool $keepKeys |
||
| 5749 | * |
||
| 5750 | * @return static |
||
| 5751 | * <p>(Immutable)</p> |
||
| 5752 | * |
||
| 5753 | * @psalm-return static<TKey,T> |
||
| 5754 | * @psalm-mutation-free |
||
| 5755 | */ |
||
| 5756 | 1 | public function split(int $numberOfPieces = 2, bool $keepKeys = false): self |
|
| 5775 | |||
| 5776 | /** |
||
| 5777 | * Stripe all empty items. |
||
| 5778 | * |
||
| 5779 | * @return static |
||
| 5780 | * <p>(Immutable)</p> |
||
| 5781 | * |
||
| 5782 | * @psalm-return static<TKey,T> |
||
| 5783 | * @psalm-mutation-free |
||
| 5784 | */ |
||
| 5785 | 1 | public function stripEmpty(): self |
|
| 5797 | |||
| 5798 | /** |
||
| 5799 | * Swap two values between positions by key. |
||
| 5800 | * |
||
| 5801 | * @param int|string $swapA <p>a key in the array</p> |
||
| 5802 | * @param int|string $swapB <p>a key in the array</p> |
||
| 5803 | * |
||
| 5804 | * @return static |
||
| 5805 | * <p>(Immutable)</p> |
||
| 5806 | * |
||
| 5807 | * @psalm-return static<TKey,T> |
||
| 5808 | * @psalm-mutation-free |
||
| 5809 | */ |
||
| 5810 | 1 | public function swap($swapA, $swapB): self |
|
| 5822 | |||
| 5823 | /** |
||
| 5824 | * Get the current array from the "Arrayy"-object. |
||
| 5825 | * alias for "getArray()" |
||
| 5826 | * |
||
| 5827 | * @param bool $convertAllArrayyElements <p> |
||
| 5828 | * Convert all Child-"Arrayy" objects also to arrays. |
||
| 5829 | * </p> |
||
| 5830 | * @param bool $preserveKeys <p> |
||
| 5831 | * e.g.: A generator maybe return the same key more then once, |
||
| 5832 | * so maybe you will ignore the keys. |
||
| 5833 | * </p> |
||
| 5834 | * |
||
| 5835 | * @return array |
||
| 5836 | * |
||
| 5837 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 5838 | * @psalm-mutation-free |
||
| 5839 | */ |
||
| 5840 | 945 | public function toArray( |
|
| 5865 | |||
| 5866 | /** |
||
| 5867 | * Get the current array from the "Arrayy"-object as list. |
||
| 5868 | * |
||
| 5869 | * @param bool $convertAllArrayyElements <p> |
||
| 5870 | * Convert all Child-"Arrayy" objects also to arrays. |
||
| 5871 | * </p> |
||
| 5872 | * |
||
| 5873 | * @return array |
||
| 5874 | * |
||
| 5875 | * @psalm-return list<array<TKey,T>> |
||
| 5876 | * @psalm-mutation-free |
||
| 5877 | */ |
||
| 5878 | 1 | public function toList(bool $convertAllArrayyElements = false): array |
|
| 5885 | |||
| 5886 | /** |
||
| 5887 | * Convert the current array to JSON. |
||
| 5888 | * |
||
| 5889 | * @param int $options [optional] <p>e.g. JSON_PRETTY_PRINT</p> |
||
| 5890 | * @param int $depth [optional] <p>Set the maximum depth. Must be greater than zero.</p> |
||
| 5891 | * |
||
| 5892 | * @return string |
||
| 5893 | */ |
||
| 5894 | 12 | public function toJson(int $options = 0, int $depth = 512): string |
|
| 5903 | |||
| 5904 | /** |
||
| 5905 | * @param string[]|null $items [optional] |
||
| 5906 | * @param string[] $helper [optional] |
||
| 5907 | * |
||
| 5908 | * @return static|static[] |
||
| 5909 | * |
||
| 5910 | * @psalm-return static<int, static<TKey,T>> |
||
| 5911 | */ |
||
| 5912 | 1 | public function toPermutation(array $items = null, array $helper = []): self |
|
| 5946 | |||
| 5947 | /** |
||
| 5948 | * Implodes array to a string with specified separator. |
||
| 5949 | * |
||
| 5950 | * @param string $separator [optional] <p>The element's separator.</p> |
||
| 5951 | * |
||
| 5952 | * @return string |
||
| 5953 | * <p>The string representation of array, separated by ",".</p> |
||
| 5954 | */ |
||
| 5955 | 19 | public function toString(string $separator = ','): string |
|
| 5959 | |||
| 5960 | /** |
||
| 5961 | * Return a duplicate free copy of the current array. |
||
| 5962 | * |
||
| 5963 | * @return $this |
||
| 5964 | * <p>(Mutable)</p> |
||
| 5965 | * |
||
| 5966 | * @psalm-return static<TKey,T> |
||
| 5967 | */ |
||
| 5968 | 13 | public function unique(): self |
|
| 5990 | |||
| 5991 | /** |
||
| 5992 | * Return a duplicate free copy of the current array. (with the old keys) |
||
| 5993 | * |
||
| 5994 | * @return $this |
||
| 5995 | * <p>(Mutable)</p> |
||
| 5996 | * |
||
| 5997 | * @psalm-return static<TKey,T> |
||
| 5998 | */ |
||
| 5999 | 11 | public function uniqueKeepIndex(): self |
|
| 6025 | |||
| 6026 | /** |
||
| 6027 | * alias: for "Arrayy->unique()" |
||
| 6028 | * |
||
| 6029 | * @return static |
||
| 6030 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
| 6031 | * |
||
| 6032 | * @see Arrayy::unique() |
||
| 6033 | * |
||
| 6034 | * @psalm-return static<TKey,T> |
||
| 6035 | */ |
||
| 6036 | 10 | public function uniqueNewIndex(): self |
|
| 6040 | |||
| 6041 | /** |
||
| 6042 | * Prepends one or more values to the beginning of array at once. |
||
| 6043 | * |
||
| 6044 | * @param array ...$args |
||
| 6045 | * |
||
| 6046 | * @return $this |
||
| 6047 | * <p>(Mutable) Return this Arrayy object, with prepended elements to the beginning of array.</p> |
||
| 6048 | * |
||
| 6049 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$args |
||
| 6050 | * @psalm-return static<TKey,T> |
||
| 6051 | */ |
||
| 6052 | 4 | public function unshift(...$args): self |
|
| 6060 | |||
| 6061 | /** |
||
| 6062 | * Tests whether the given closure return something valid for all elements of this array. |
||
| 6063 | * |
||
| 6064 | * @param \Closure $closure the predicate |
||
| 6065 | * |
||
| 6066 | * @return bool |
||
| 6067 | * <p>TRUE, if the predicate yields TRUE for all elements, FALSE otherwise.</p> |
||
| 6068 | */ |
||
| 6069 | 1 | View Code Duplication | public function validate(\Closure $closure): bool |
| 6079 | |||
| 6080 | /** |
||
| 6081 | * Get all values from a array. |
||
| 6082 | * |
||
| 6083 | * @return static |
||
| 6084 | * <p>(Immutable)</p> |
||
| 6085 | * |
||
| 6086 | * @psalm-return static<TKey,T> |
||
| 6087 | * @psalm-mutation-free |
||
| 6088 | */ |
||
| 6089 | 2 | public function values(): self |
|
| 6102 | |||
| 6103 | /** |
||
| 6104 | * Apply the given function to every element in the array, discarding the results. |
||
| 6105 | * |
||
| 6106 | * @param callable $callable |
||
| 6107 | * @param bool $recursive [optional] <p>Whether array will be walked recursively or no</p> |
||
| 6108 | * @param mixed $userData [optional] <p> |
||
| 6109 | * If the optional $userData parameter is supplied, |
||
| 6110 | * it will be passed as the third parameter to the $callable. |
||
| 6111 | * </p> |
||
| 6112 | * |
||
| 6113 | * @return $this |
||
| 6114 | * <p>(Mutable) Return this Arrayy object, with modified elements.</p> |
||
| 6115 | * |
||
| 6116 | * @psalm-return static<TKey,T> |
||
| 6117 | */ |
||
| 6118 | 12 | public function walk($callable, bool $recursive = false, $userData = self::ARRAYY_HELPER_WALK): self |
|
| 6140 | |||
| 6141 | /** |
||
| 6142 | * Returns a collection of matching items. |
||
| 6143 | * |
||
| 6144 | * @param string $keyOrPropertyOrMethod the property or method to evaluate |
||
| 6145 | * @param mixed $value the value to match |
||
| 6146 | * |
||
| 6147 | * @throws \InvalidArgumentException if property or method is not defined |
||
| 6148 | * |
||
| 6149 | * @return static |
||
| 6150 | * |
||
| 6151 | * @psalm-param T $value |
||
| 6152 | * @psalm-return static<TKey,T> |
||
| 6153 | */ |
||
| 6154 | 1 | public function where(string $keyOrPropertyOrMethod, $value): self |
|
| 6167 | |||
| 6168 | /** |
||
| 6169 | * Convert an array into a object. |
||
| 6170 | * |
||
| 6171 | * @param array $array |
||
| 6172 | * |
||
| 6173 | * @return \stdClass |
||
| 6174 | * |
||
| 6175 | * @psalm-param array<mixed,mixed> $array |
||
| 6176 | */ |
||
| 6177 | 4 | final protected static function arrayToObject(array $array = []): \stdClass |
|
| 6196 | |||
| 6197 | /** |
||
| 6198 | * @param array|\Generator|null $input <p> |
||
| 6199 | * An array containing keys to return. |
||
| 6200 | * </p> |
||
| 6201 | * @param mixed|null $search_values [optional] <p> |
||
| 6202 | * If specified, then only keys containing these values are returned. |
||
| 6203 | * </p> |
||
| 6204 | * @param bool $strict [optional] <p> |
||
| 6205 | * Determines if strict comparison (===) should be used during the |
||
| 6206 | * search. |
||
| 6207 | * </p> |
||
| 6208 | * |
||
| 6209 | * @return array |
||
| 6210 | * <p>an array of all the keys in input</p> |
||
| 6211 | * |
||
| 6212 | * @psalm-param array<mixed,mixed>|\Generator<TKey,T>|null $input |
||
| 6213 | * @psalm-return array<TKey|mixed> |
||
| 6214 | * @psalm-mutation-free |
||
| 6215 | */ |
||
| 6216 | 11 | protected function array_keys_recursive( |
|
| 6277 | |||
| 6278 | /** |
||
| 6279 | * @param mixed $path |
||
| 6280 | * @param callable $callable |
||
| 6281 | * @param array|null $currentOffset |
||
| 6282 | * |
||
| 6283 | * @return void |
||
| 6284 | * |
||
| 6285 | * @psalm-param array<mixed,mixed>|array<TKey,T>|null $currentOffset |
||
| 6286 | * @psalm-mutation-free |
||
| 6287 | */ |
||
| 6288 | 10 | protected function callAtPath($path, $callable, &$currentOffset = null) |
|
| 6317 | |||
| 6318 | /** |
||
| 6319 | * Extracts the value of the given property or method from the object. |
||
| 6320 | * |
||
| 6321 | * @param static $object <p>The object to extract the value from.</p> |
||
| 6322 | * @param string $keyOrPropertyOrMethod <p>The property or method for which the |
||
| 6323 | * value should be extracted.</p> |
||
| 6324 | * |
||
| 6325 | * @throws \InvalidArgumentException if the method or property is not defined |
||
| 6326 | * |
||
| 6327 | * @return mixed |
||
| 6328 | * <p>The value extracted from the specified property or method.</p> |
||
| 6329 | * |
||
| 6330 | * @psalm-param self<TKey,T> $object |
||
| 6331 | */ |
||
| 6332 | 2 | final protected function extractValue(self $object, string $keyOrPropertyOrMethod) |
|
| 6354 | |||
| 6355 | /** |
||
| 6356 | * create a fallback for array |
||
| 6357 | * |
||
| 6358 | * 1. use the current array, if it's a array |
||
| 6359 | * 2. fallback to empty array, if there is nothing |
||
| 6360 | * 3. call "getArray()" on object, if there is a "Arrayy"-object |
||
| 6361 | * 4. call "createFromObject()" on object, if there is a "\Traversable"-object |
||
| 6362 | * 5. call "__toArray()" on object, if the method exists |
||
| 6363 | * 6. cast a string or object with "__toString()" into an array |
||
| 6364 | * 7. throw a "InvalidArgumentException"-Exception |
||
| 6365 | * |
||
| 6366 | * @param mixed $data |
||
| 6367 | * |
||
| 6368 | * @throws \InvalidArgumentException |
||
| 6369 | * |
||
| 6370 | * @return array |
||
| 6371 | * |
||
| 6372 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 6373 | */ |
||
| 6374 | 1198 | protected function fallbackForArray(&$data): array |
|
| 6384 | |||
| 6385 | /** |
||
| 6386 | * @param bool $preserveKeys <p> |
||
| 6387 | * e.g.: A generator maybe return the same key more then once, |
||
| 6388 | * so maybe you will ignore the keys. |
||
| 6389 | * </p> |
||
| 6390 | * |
||
| 6391 | * @return bool |
||
| 6392 | * |
||
| 6393 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
| 6394 | * @psalm-mutation-free :/ |
||
| 6395 | */ |
||
| 6396 | 1110 | protected function generatorToArray(bool $preserveKeys = true) |
|
| 6407 | |||
| 6408 | /** |
||
| 6409 | * Get correct PHP constant for direction. |
||
| 6410 | * |
||
| 6411 | * @param int|string $direction |
||
| 6412 | * |
||
| 6413 | * @return int |
||
| 6414 | * @psalm-mutation-free |
||
| 6415 | */ |
||
| 6416 | 43 | protected function getDirection($direction): int |
|
| 6438 | |||
| 6439 | /** |
||
| 6440 | * @return TypeCheckInterface[] |
||
| 6441 | * |
||
| 6442 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
| 6443 | */ |
||
| 6444 | 22 | protected function getPropertiesFromPhpDoc() |
|
| 6475 | |||
| 6476 | /** |
||
| 6477 | * @param mixed $glue |
||
| 6478 | * @param mixed $pieces |
||
| 6479 | * @param bool $useKeys |
||
| 6480 | * |
||
| 6481 | * @return string |
||
| 6482 | * @psalm-mutation-free |
||
| 6483 | */ |
||
| 6484 | 36 | protected function implode_recursive( |
|
| 6517 | |||
| 6518 | /** |
||
| 6519 | * @param mixed $needle <p> |
||
| 6520 | * The searched value. |
||
| 6521 | * </p> |
||
| 6522 | * <p> |
||
| 6523 | * If needle is a string, the comparison is done |
||
| 6524 | * in a case-sensitive manner. |
||
| 6525 | * </p> |
||
| 6526 | * @param array|\Generator|null $haystack <p> |
||
| 6527 | * The array. |
||
| 6528 | * </p> |
||
| 6529 | * @param bool $strict [optional] <p> |
||
| 6530 | * If the third parameter strict is set to true |
||
| 6531 | * then the in_array function will also check the |
||
| 6532 | * types of the |
||
| 6533 | * needle in the haystack. |
||
| 6534 | * </p> |
||
| 6535 | * |
||
| 6536 | * @return bool |
||
| 6537 | * <p>true if needle is found in the array, false otherwise</p> |
||
| 6538 | * |
||
| 6539 | * @psalm-param array<mixed,mixed>|\Generator<TKey,T>|null $haystack |
||
| 6540 | * @psalm-mutation-free |
||
| 6541 | */ |
||
| 6542 | 18 | protected function in_array_recursive($needle, $haystack = null, $strict = true): bool |
|
| 6567 | |||
| 6568 | /** |
||
| 6569 | * @param mixed $data |
||
| 6570 | * |
||
| 6571 | * @return array|null |
||
| 6572 | * |
||
| 6573 | * @psalm-return array<mixed,mixed>|array<TKey,T>|null |
||
| 6574 | */ |
||
| 6575 | 1198 | protected function internalGetArray(&$data) |
|
| 6626 | |||
| 6627 | /** |
||
| 6628 | * Internal mechanics of remove method. |
||
| 6629 | * |
||
| 6630 | * @param mixed $key |
||
| 6631 | * |
||
| 6632 | * @return bool |
||
| 6633 | */ |
||
| 6634 | 21 | protected function internalRemove($key): bool |
|
| 6667 | |||
| 6668 | /** |
||
| 6669 | * Internal mechanic of set method. |
||
| 6670 | * |
||
| 6671 | * @param int|string|null $key |
||
| 6672 | * @param mixed $value |
||
| 6673 | * @param bool $checkProperties |
||
| 6674 | * |
||
| 6675 | * @return bool |
||
| 6676 | */ |
||
| 6677 | 1048 | protected function internalSet( |
|
| 6736 | |||
| 6737 | /** |
||
| 6738 | * Convert a object into an array. |
||
| 6739 | * |
||
| 6740 | * @param mixed|object $object |
||
| 6741 | * |
||
| 6742 | * @return array|mixed |
||
| 6743 | * |
||
| 6744 | * @psalm-mutation-free |
||
| 6745 | */ |
||
| 6746 | 5 | protected static function objectToArray($object) |
|
| 6759 | |||
| 6760 | /** |
||
| 6761 | * @param array $data |
||
| 6762 | * @param bool $checkPropertiesInConstructor |
||
| 6763 | * |
||
| 6764 | * @return void |
||
| 6765 | * |
||
| 6766 | * @psalm-param array<mixed,T> $data |
||
| 6767 | */ |
||
| 6768 | 1196 | protected function setInitialValuesAndProperties(array &$data, bool $checkPropertiesInConstructor) |
|
| 6813 | |||
| 6814 | /** |
||
| 6815 | * sorting keys |
||
| 6816 | * |
||
| 6817 | * @param array $elements |
||
| 6818 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 6819 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 6820 | * <strong>SORT_NATURAL</strong></p> |
||
| 6821 | * |
||
| 6822 | * @return $this |
||
| 6823 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 6824 | * |
||
| 6825 | * @psalm-param array<mixed,mixed>|array<mixed|TKey,T> $elements |
||
| 6826 | * @psalm-return static<TKey,T> |
||
| 6827 | */ |
||
| 6828 | 18 | protected function sorterKeys( |
|
| 6849 | |||
| 6850 | /** |
||
| 6851 | * @param array $elements <p>Warning: used as reference</p> |
||
| 6852 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 6853 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 6854 | * <strong>SORT_NATURAL</strong></p> |
||
| 6855 | * @param bool $keepKeys |
||
| 6856 | * |
||
| 6857 | * @return $this |
||
| 6858 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 6859 | * |
||
| 6860 | * @psalm-param array<mixed,mixed>|array<mixed|TKey,T> $elements |
||
| 6861 | * @psalm-return static<TKey,T> |
||
| 6862 | */ |
||
| 6863 | 24 | protected function sorting(array &$elements, $direction = \SORT_ASC, int $strategy = \SORT_REGULAR, bool $keepKeys = false): self |
|
| 6893 | |||
| 6894 | /** |
||
| 6895 | * @param array $array |
||
| 6896 | * |
||
| 6897 | * @return array |
||
| 6898 | * |
||
| 6899 | * @psalm-mutation-free |
||
| 6900 | */ |
||
| 6901 | 25 | private function getArrayRecursiveHelperArrayy(array $array) |
|
| 6923 | |||
| 6924 | /** |
||
| 6925 | * @param int|string|null $key |
||
| 6926 | * @param mixed $value |
||
| 6927 | * |
||
| 6928 | * @return void |
||
| 6929 | */ |
||
| 6930 | 109 | private function checkType($key, $value) |
|
| 6948 | } |
||
| 6949 |
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..