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 |
|
595 | { |
||
596 | 157 | $this->generatorToArray(); |
|
597 | |||
598 | 157 | if ($this->array === []) { |
|
599 | 8 | return false; |
|
600 | } |
||
601 | |||
602 | // php cast "bool"-index into "int"-index |
||
603 | 151 | if ((bool) $offset === $offset) { |
|
604 | 1 | $offset = (int) $offset; |
|
605 | } |
||
606 | |||
607 | /** @var int|string $offset - hint for phpstan */ |
||
608 | 151 | $offset = $offset; |
|
609 | |||
610 | 151 | $tmpReturn = $this->keyExists($offset); |
|
611 | |||
612 | if ( |
||
613 | 151 | $tmpReturn === true |
|
614 | || |
||
615 | 151 | \strpos((string) $offset, $this->pathSeparator) === false |
|
616 | ) { |
||
617 | 148 | return $tmpReturn; |
|
618 | } |
||
619 | |||
620 | 4 | $offsetExists = false; |
|
621 | |||
622 | /** |
||
623 | * https://github.com/vimeo/psalm/issues/2536 |
||
624 | * |
||
625 | * @psalm-suppress PossiblyInvalidArgument |
||
626 | * @psalm-suppress InvalidScalarArgument |
||
627 | */ |
||
628 | View Code Duplication | if ( |
|
629 | 4 | $this->pathSeparator |
|
630 | && |
||
631 | 4 | (string) $offset === $offset |
|
632 | && |
||
633 | 4 | \strpos($offset, $this->pathSeparator) !== false |
|
634 | ) { |
||
635 | 4 | $explodedPath = \explode($this->pathSeparator, (string) $offset); |
|
636 | 4 | if ($explodedPath !== false) { |
|
637 | /** @var string $lastOffset - helper for phpstan */ |
||
638 | 4 | $lastOffset = \array_pop($explodedPath); |
|
639 | 4 | $containerPath = \implode($this->pathSeparator, $explodedPath); |
|
640 | |||
641 | /** |
||
642 | * @psalm-suppress MissingClosureReturnType |
||
643 | * @psalm-suppress MissingClosureParamType |
||
644 | */ |
||
645 | 4 | $this->callAtPath( |
|
646 | 4 | $containerPath, |
|
647 | 4 | static function ($container) use ($lastOffset, &$offsetExists) { |
|
648 | 4 | $offsetExists = \array_key_exists($lastOffset, $container); |
|
649 | 4 | } |
|
650 | ); |
||
651 | } |
||
652 | } |
||
653 | |||
654 | 4 | return $offsetExists; |
|
655 | } |
||
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) |
|
713 | { |
||
714 | 25 | $this->generatorToArray(); |
|
715 | |||
716 | 25 | if ($this->array === []) { |
|
717 | 6 | return; |
|
718 | } |
||
719 | |||
720 | 20 | if ($this->keyExists($offset)) { |
|
721 | 13 | unset($this->array[$offset]); |
|
722 | |||
723 | 13 | return; |
|
724 | } |
||
725 | |||
726 | /** |
||
727 | * https://github.com/vimeo/psalm/issues/2536 |
||
728 | * |
||
729 | * @psalm-suppress PossiblyInvalidArgument |
||
730 | * @psalm-suppress InvalidScalarArgument |
||
731 | */ |
||
732 | View Code Duplication | if ( |
|
733 | 10 | $this->pathSeparator |
|
734 | && |
||
735 | 10 | (string) $offset === $offset |
|
736 | && |
||
737 | 10 | \strpos($offset, $this->pathSeparator) !== false |
|
738 | ) { |
||
739 | 7 | $path = \explode($this->pathSeparator, (string) $offset); |
|
740 | |||
741 | 7 | if ($path !== false) { |
|
742 | 7 | $pathToUnset = \array_pop($path); |
|
743 | |||
744 | /** |
||
745 | * @psalm-suppress MissingClosureReturnType |
||
746 | * @psalm-suppress MissingClosureParamType |
||
747 | */ |
||
748 | 7 | $this->callAtPath( |
|
749 | 7 | \implode($this->pathSeparator, $path), |
|
750 | 7 | static function (&$offset) use ($pathToUnset) { |
|
751 | 6 | if (\is_array($offset)) { |
|
752 | 5 | unset($offset[$pathToUnset]); |
|
753 | } else { |
||
754 | 1 | $offset = null; |
|
755 | } |
||
756 | 7 | } |
|
757 | ); |
||
758 | } |
||
759 | } |
||
760 | |||
761 | 10 | unset($this->array[$offset]); |
|
762 | 10 | } |
|
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 |
|
1224 | { |
||
1225 | 8 | return $this->filter( |
|
1226 | 8 | static function ($value) { |
|
1227 | 7 | return (bool) $value; |
|
1228 | 8 | } |
|
1229 | ); |
||
1230 | } |
||
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 |
|
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 | 717 | 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 |
|
1706 | { |
||
1707 | 10 | if ($regEx) { |
|
1708 | 1 | \preg_match_all($regEx, $str, $array); |
|
1709 | |||
1710 | 1 | if (!empty($array)) { |
|
1711 | 1 | $array = $array[0]; |
|
1712 | } |
||
1713 | } else { |
||
1714 | /** @noinspection NestedPositiveIfStatementsInspection */ |
||
1715 | 9 | if ($delimiter !== null) { |
|
1716 | 7 | $array = \explode($delimiter, $str); |
|
1717 | } else { |
||
1718 | 2 | $array = [$str]; |
|
1719 | } |
||
1720 | } |
||
1721 | |||
1722 | // trim all string in the array |
||
1723 | /** |
||
1724 | * @psalm-suppress MissingClosureParamType |
||
1725 | */ |
||
1726 | 10 | \array_walk( |
|
1727 | 10 | $array, |
|
1728 | 10 | static function (&$val) { |
|
1729 | 10 | if ((string) $val === $val) { |
|
1730 | 10 | $val = \trim($val); |
|
1731 | } |
||
1732 | 10 | } |
|
1733 | ); |
||
1734 | |||
1735 | 10 | return static::create($array); |
|
1736 | } |
||
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( |
|
2257 | string $property, |
||
2258 | $value, |
||
2259 | string $comparisonOp = null |
||
2260 | ): self { |
||
2261 | 1 | if (!$comparisonOp) { |
|
2262 | 1 | $comparisonOp = \is_array($value) === true ? 'contains' : 'eq'; |
|
2263 | } |
||
2264 | |||
2265 | $ops = [ |
||
2266 | 1 | 'eq' => static function ($item, $prop, $value): bool { |
|
2267 | 1 | return $item[$prop] === $value; |
|
2268 | 1 | }, |
|
2269 | 1 | 'gt' => static function ($item, $prop, $value): bool { |
|
2270 | return $item[$prop] > $value; |
||
2271 | 1 | }, |
|
2272 | 1 | 'ge' => static function ($item, $prop, $value): bool { |
|
2273 | return $item[$prop] >= $value; |
||
2274 | 1 | }, |
|
2275 | 1 | 'gte' => static function ($item, $prop, $value): bool { |
|
2276 | return $item[$prop] >= $value; |
||
2277 | 1 | }, |
|
2278 | 1 | 'lt' => static function ($item, $prop, $value): bool { |
|
2279 | 1 | return $item[$prop] < $value; |
|
2280 | 1 | }, |
|
2281 | 1 | 'le' => static function ($item, $prop, $value): bool { |
|
2282 | return $item[$prop] <= $value; |
||
2283 | 1 | }, |
|
2284 | 1 | 'lte' => static function ($item, $prop, $value): bool { |
|
2285 | return $item[$prop] <= $value; |
||
2286 | 1 | }, |
|
2287 | 1 | 'ne' => static function ($item, $prop, $value): bool { |
|
2288 | return $item[$prop] !== $value; |
||
2289 | 1 | }, |
|
2290 | 1 | 'contains' => static function ($item, $prop, $value): bool { |
|
2291 | 1 | return \in_array($item[$prop], (array) $value, true); |
|
2292 | 1 | }, |
|
2293 | 1 | 'notContains' => static function ($item, $prop, $value): bool { |
|
2294 | return !\in_array($item[$prop], (array) $value, true); |
||
2295 | 1 | }, |
|
2296 | 1 | 'newer' => static function ($item, $prop, $value): bool { |
|
2297 | return \strtotime($item[$prop]) > \strtotime($value); |
||
2298 | 1 | }, |
|
2299 | 1 | 'older' => static function ($item, $prop, $value): bool { |
|
2300 | return \strtotime($item[$prop]) < \strtotime($value); |
||
2301 | 1 | }, |
|
2302 | ]; |
||
2303 | |||
2304 | 1 | $result = \array_values( |
|
2305 | 1 | \array_filter( |
|
2306 | 1 | $this->toArray(false, true), |
|
2307 | 1 | static function ($item) use ( |
|
2308 | 1 | $property, |
|
2309 | 1 | $value, |
|
2310 | 1 | $ops, |
|
2311 | 1 | $comparisonOp |
|
2312 | ) { |
||
2313 | 1 | $item = (array) $item; |
|
2314 | 1 | $itemArrayy = static::create($item); |
|
2315 | 1 | $item[$property] = $itemArrayy->get($property, []); |
|
2316 | |||
2317 | 1 | return $ops[$comparisonOp]($item, $property, $value); |
|
2318 | 1 | } |
|
2319 | ) |
||
2320 | ); |
||
2321 | |||
2322 | 1 | return static::create( |
|
2323 | 1 | $result, |
|
2324 | 1 | $this->iteratorClass, |
|
2325 | 1 | false |
|
2326 | ); |
||
2327 | } |
||
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( |
|
2680 | |||
2681 | /** |
||
2682 | * alias: for "Arrayy->toArray()" |
||
2683 | * |
||
2684 | * @return array |
||
2685 | * |
||
2686 | * @see Arrayy::getArray() |
||
2687 | * |
||
2688 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
2689 | */ |
||
2690 | 15 | public function getAll(): array |
|
2694 | |||
2695 | /** |
||
2696 | * Get the current array from the "Arrayy"-object. |
||
2697 | * |
||
2698 | * alias for "toArray()" |
||
2699 | * |
||
2700 | * @param bool $convertAllArrayyElements <p> |
||
2701 | * Convert all Child-"Arrayy" objects also to arrays. |
||
2702 | * </p> |
||
2703 | * @param bool $preserveKeys <p> |
||
2704 | * e.g.: A generator maybe return the same key more then once, |
||
2705 | * so maybe you will ignore the keys. |
||
2706 | * </p> |
||
2707 | * |
||
2708 | * @return array |
||
2709 | * |
||
2710 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
2711 | * @psalm-mutation-free |
||
2712 | * |
||
2713 | * @see Arrayy::toArray() |
||
2714 | */ |
||
2715 | 500 | public function getArray( |
|
2724 | |||
2725 | /** |
||
2726 | * @param string $json |
||
2727 | * |
||
2728 | * @return $this |
||
2729 | */ |
||
2730 | 3 | public static function createFromJsonMapper(string $json) |
|
2746 | |||
2747 | /** |
||
2748 | * @return array<int|string,TypeCheckInterface>|mixed|TypeCheckArray<int|string,TypeCheckInterface>|TypeInterface |
||
2749 | * |
||
2750 | * @internal |
||
2751 | */ |
||
2752 | 6 | public function getPhpDocPropertiesFromClass() |
|
2760 | |||
2761 | /** |
||
2762 | * Get the current array from the "Arrayy"-object as list. |
||
2763 | * |
||
2764 | * alias for "toList()" |
||
2765 | * |
||
2766 | * @param bool $convertAllArrayyElements <p> |
||
2767 | * Convert all Child-"Arrayy" objects also to arrays. |
||
2768 | * </p> |
||
2769 | * |
||
2770 | * @return array |
||
2771 | * |
||
2772 | * @psalm-return array<int,mixed>|array<int,T> |
||
2773 | * @psalm-mutation-free |
||
2774 | * |
||
2775 | * @see Arrayy::toList() |
||
2776 | */ |
||
2777 | 1 | public function getList(bool $convertAllArrayyElements = false): array |
|
2781 | |||
2782 | /** |
||
2783 | * Returns the values from a single column of the input array, identified by |
||
2784 | * the $columnKey, can be used to extract data-columns from multi-arrays. |
||
2785 | * |
||
2786 | * Info: Optionally, you may provide an $indexKey to index the values in the returned |
||
2787 | * array by the values from the $indexKey column in the input array. |
||
2788 | * |
||
2789 | * @param mixed $columnKey |
||
2790 | * @param mixed $indexKey |
||
2791 | * |
||
2792 | * @return static |
||
2793 | * <p>(Immutable)</p> |
||
2794 | * |
||
2795 | * @psalm-return static<TKey,T> |
||
2796 | * @psalm-mutation-free |
||
2797 | */ |
||
2798 | 1 | public function getColumn($columnKey = null, $indexKey = null): self |
|
2806 | |||
2807 | /** |
||
2808 | * Get the current array from the "Arrayy"-object as generator by reference. |
||
2809 | * |
||
2810 | * @return \Generator |
||
2811 | * |
||
2812 | * @psalm-return \Generator<mixed,T>|\Generator<TKey,T> |
||
2813 | */ |
||
2814 | 75 | public function &getGeneratorByReference(): \Generator |
|
2833 | |||
2834 | /** |
||
2835 | * Get the current array from the "Arrayy"-object as generator. |
||
2836 | * |
||
2837 | * @return \Generator |
||
2838 | * |
||
2839 | * @psalm-return \Generator<mixed,T>|\Generator<TKey,T> |
||
2840 | * @psalm-mutation-free |
||
2841 | */ |
||
2842 | 996 | public function getGenerator(): \Generator |
|
2852 | |||
2853 | /** |
||
2854 | * alias: for "Arrayy->keys()" |
||
2855 | * |
||
2856 | * @return static |
||
2857 | * <p>(Immutable)</p> |
||
2858 | * |
||
2859 | * @see Arrayy::keys() |
||
2860 | * |
||
2861 | * @psalm-return static<array-key,TKey> |
||
2862 | * @psalm-mutation-free |
||
2863 | */ |
||
2864 | 2 | public function getKeys() |
|
2868 | |||
2869 | /** |
||
2870 | * Get the current array from the "Arrayy"-object as object. |
||
2871 | * |
||
2872 | * @return \stdClass |
||
2873 | */ |
||
2874 | 4 | public function getObject(): \stdClass |
|
2878 | |||
2879 | /** |
||
2880 | * alias: for "Arrayy->randomImmutable()" |
||
2881 | * |
||
2882 | * @return static |
||
2883 | * <p>(Immutable)</p> |
||
2884 | * |
||
2885 | * @see Arrayy::randomImmutable() |
||
2886 | * |
||
2887 | * @psalm-return static<int|array-key,T> |
||
2888 | */ |
||
2889 | 4 | public function getRandom(): self |
|
2893 | |||
2894 | /** |
||
2895 | * alias: for "Arrayy->randomKey()" |
||
2896 | * |
||
2897 | * @return mixed |
||
2898 | * <p>Get a key/index or null if there wasn't a key/index.</p> |
||
2899 | * |
||
2900 | * @see Arrayy::randomKey() |
||
2901 | */ |
||
2902 | 3 | public function getRandomKey() |
|
2906 | |||
2907 | /** |
||
2908 | * alias: for "Arrayy->randomKeys()" |
||
2909 | * |
||
2910 | * @param int $number |
||
2911 | * |
||
2912 | * @return static |
||
2913 | * <p>(Immutable)</p> |
||
2914 | * |
||
2915 | * @see Arrayy::randomKeys() |
||
2916 | * |
||
2917 | * @psalm-return static<TKey,T> |
||
2918 | */ |
||
2919 | 8 | public function getRandomKeys(int $number): self |
|
2923 | |||
2924 | /** |
||
2925 | * alias: for "Arrayy->randomValue()" |
||
2926 | * |
||
2927 | * @return mixed |
||
2928 | * <p>Get a random value or null if there wasn't a value.</p> |
||
2929 | * |
||
2930 | * @see Arrayy::randomValue() |
||
2931 | */ |
||
2932 | 3 | public function getRandomValue() |
|
2936 | |||
2937 | /** |
||
2938 | * alias: for "Arrayy->randomValues()" |
||
2939 | * |
||
2940 | * @param int $number |
||
2941 | * |
||
2942 | * @return static |
||
2943 | * <p>(Immutable)</p> |
||
2944 | * |
||
2945 | * @see Arrayy::randomValues() |
||
2946 | * |
||
2947 | * @psalm-return static<TKey,T> |
||
2948 | */ |
||
2949 | 6 | public function getRandomValues(int $number): self |
|
2953 | |||
2954 | /** |
||
2955 | * Gets all values. |
||
2956 | * |
||
2957 | * @return static |
||
2958 | * <p>The values of all elements in this array, in the order they |
||
2959 | * appear in the array.</p> |
||
2960 | * |
||
2961 | * @psalm-return static<TKey,T> |
||
2962 | */ |
||
2963 | 4 | public function getValues() |
|
2973 | |||
2974 | /** |
||
2975 | * Gets all values via Generator. |
||
2976 | * |
||
2977 | * @return \Generator |
||
2978 | * <p>The values of all elements in this array, in the order they |
||
2979 | * appear in the array as Generator.</p> |
||
2980 | * |
||
2981 | * @psalm-return \Generator<TKey,T> |
||
2982 | */ |
||
2983 | 4 | public function getValuesYield(): \Generator |
|
2987 | |||
2988 | /** |
||
2989 | * Group values from a array according to the results of a closure. |
||
2990 | * |
||
2991 | * @param callable|string $grouper <p>A callable function name.</p> |
||
2992 | * @param bool $saveKeys |
||
2993 | * |
||
2994 | * @return static |
||
2995 | * <p>(Immutable)</p> |
||
2996 | * |
||
2997 | * @psalm-return static<TKey,T> |
||
2998 | * @psalm-mutation-free |
||
2999 | */ |
||
3000 | 4 | public function group($grouper, bool $saveKeys = false): self |
|
3041 | |||
3042 | /** |
||
3043 | * Check if an array has a given key. |
||
3044 | * |
||
3045 | * @param mixed $key |
||
3046 | * |
||
3047 | * @return bool |
||
3048 | */ |
||
3049 | 30 | public function has($key): bool |
|
3075 | |||
3076 | /** |
||
3077 | * Check if an array has a given value. |
||
3078 | * |
||
3079 | * INFO: if you need to search recursive please use ```contains()``` |
||
3080 | * |
||
3081 | * @param mixed $value |
||
3082 | * |
||
3083 | * @return bool |
||
3084 | */ |
||
3085 | 1 | public function hasValue($value): bool |
|
3089 | |||
3090 | /** |
||
3091 | * Implodes the values of this array. |
||
3092 | * |
||
3093 | * @param string $glue |
||
3094 | * |
||
3095 | * @return string |
||
3096 | * @psalm-mutation-free |
||
3097 | */ |
||
3098 | 28 | public function implode(string $glue = ''): string |
|
3102 | |||
3103 | /** |
||
3104 | * Implodes the keys of this array. |
||
3105 | * |
||
3106 | * @param string $glue |
||
3107 | * |
||
3108 | * @return string |
||
3109 | * @psalm-mutation-free |
||
3110 | */ |
||
3111 | 8 | public function implodeKeys(string $glue = ''): string |
|
3115 | |||
3116 | /** |
||
3117 | * Given a list and an iterate-function that returns |
||
3118 | * a key for each element in the list (or a property name), |
||
3119 | * returns an object with an index of each item. |
||
3120 | * |
||
3121 | * @param mixed $key |
||
3122 | * |
||
3123 | * @return static |
||
3124 | * <p>(Immutable)</p> |
||
3125 | * |
||
3126 | * @psalm-return static<TKey,T> |
||
3127 | * @psalm-mutation-free |
||
3128 | */ |
||
3129 | 4 | public function indexBy($key): self |
|
3146 | |||
3147 | /** |
||
3148 | * alias: for "Arrayy->searchIndex()" |
||
3149 | * |
||
3150 | * @param mixed $value <p>The value to search for.</p> |
||
3151 | * |
||
3152 | * @return false|mixed |
||
3153 | * |
||
3154 | * @see Arrayy::searchIndex() |
||
3155 | */ |
||
3156 | 4 | public function indexOf($value) |
|
3160 | |||
3161 | /** |
||
3162 | * Get everything but the last..$to items. |
||
3163 | * |
||
3164 | * @param int $to |
||
3165 | * |
||
3166 | * @return static |
||
3167 | * <p>(Immutable)</p> |
||
3168 | * |
||
3169 | * @psalm-return static<TKey,T> |
||
3170 | * @psalm-mutation-free |
||
3171 | */ |
||
3172 | 12 | public function initial(int $to = 1): self |
|
3176 | |||
3177 | /** |
||
3178 | * Return an array with all elements found in input array. |
||
3179 | * |
||
3180 | * @param array $search |
||
3181 | * @param bool $keepKeys |
||
3182 | * |
||
3183 | * @return static |
||
3184 | * <p>(Immutable)</p> |
||
3185 | * |
||
3186 | * @psalm-param array<mixed,mixed>|array<TKey,T> $search |
||
3187 | * @psalm-return static<TKey,T> |
||
3188 | * @psalm-mutation-free |
||
3189 | */ |
||
3190 | 4 | public function intersection(array $search, bool $keepKeys = false): self |
|
3216 | |||
3217 | /** |
||
3218 | * Return an array with all elements found in input array. |
||
3219 | * |
||
3220 | * @param array ...$array |
||
3221 | * |
||
3222 | * @return static |
||
3223 | * <p>(Immutable)</p> |
||
3224 | * |
||
3225 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$array |
||
3226 | * @psalm-return static<TKey,T> |
||
3227 | * @psalm-mutation-free |
||
3228 | */ |
||
3229 | 1 | public function intersectionMulti(...$array): self |
|
3237 | |||
3238 | /** |
||
3239 | * Return a boolean flag which indicates whether the two input arrays have any common elements. |
||
3240 | * |
||
3241 | * @param array $search |
||
3242 | * |
||
3243 | * @return bool |
||
3244 | * |
||
3245 | * @psalm-param array<mixed,mixed>|array<TKey,T> $search |
||
3246 | */ |
||
3247 | 1 | public function intersects(array $search): bool |
|
3251 | |||
3252 | /** |
||
3253 | * Invoke a function on all of an array's values. |
||
3254 | * |
||
3255 | * @param callable $callable |
||
3256 | * @param mixed $arguments |
||
3257 | * |
||
3258 | * @return static |
||
3259 | * <p>(Immutable)</p> |
||
3260 | * |
||
3261 | * @psalm-param callable(T=,mixed):mixed $callable |
||
3262 | * @psalm-return static<TKey,T> |
||
3263 | * @psalm-mutation-free |
||
3264 | */ |
||
3265 | 1 | View Code Duplication | public function invoke($callable, $arguments = []): self |
3289 | |||
3290 | /** |
||
3291 | * Check whether array is associative or not. |
||
3292 | * |
||
3293 | * @param bool $recursive |
||
3294 | * |
||
3295 | * @return bool |
||
3296 | * <p>Returns true if associative, false otherwise.</p> |
||
3297 | */ |
||
3298 | 15 | View Code Duplication | public function isAssoc(bool $recursive = false): bool |
3313 | |||
3314 | /** |
||
3315 | * Check if a given key or keys are empty. |
||
3316 | * |
||
3317 | * @param int|int[]|string|string[]|null $keys |
||
3318 | * |
||
3319 | * @return bool |
||
3320 | * <p>Returns true if empty, false otherwise.</p> |
||
3321 | * @psalm-mutation-free |
||
3322 | */ |
||
3323 | 45 | public function isEmpty($keys = null): bool |
|
3341 | |||
3342 | /** |
||
3343 | * Check if the current array is equal to the given "$array" or not. |
||
3344 | * |
||
3345 | * @param array $array |
||
3346 | * |
||
3347 | * @return bool |
||
3348 | * |
||
3349 | * @psalm-param array<mixed,mixed> $array |
||
3350 | */ |
||
3351 | 1 | public function isEqual(array $array): bool |
|
3355 | |||
3356 | /** |
||
3357 | * Check if the current array is a multi-array. |
||
3358 | * |
||
3359 | * @return bool |
||
3360 | */ |
||
3361 | 22 | public function isMultiArray(): bool |
|
3369 | |||
3370 | /** |
||
3371 | * Check whether array is numeric or not. |
||
3372 | * |
||
3373 | * @return bool |
||
3374 | * <p>Returns true if numeric, false otherwise.</p> |
||
3375 | */ |
||
3376 | 5 | View Code Duplication | public function isNumeric(): bool |
3391 | |||
3392 | /** |
||
3393 | * Check if the current array is sequential [0, 1, 2, 3, 4, 5 ...] or not. |
||
3394 | * |
||
3395 | * @param bool $recursive |
||
3396 | * |
||
3397 | * @return bool |
||
3398 | * @psalm-mutation-free |
||
3399 | */ |
||
3400 | 9 | public function isSequential(bool $recursive = false): bool |
|
3417 | |||
3418 | /** |
||
3419 | * @return array |
||
3420 | * |
||
3421 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
3422 | */ |
||
3423 | 2 | public function jsonSerialize(): array |
|
3427 | |||
3428 | /** |
||
3429 | * Gets the key/index of the element at the current internal iterator position. |
||
3430 | * |
||
3431 | * @return int|string|null |
||
3432 | */ |
||
3433 | public function key() |
||
3437 | |||
3438 | /** |
||
3439 | * Checks if the given key exists in the provided array. |
||
3440 | * |
||
3441 | * INFO: This method only use "array_key_exists()" if you want to use "dot"-notation, |
||
3442 | * then you need to use "Arrayy->offsetExists()". |
||
3443 | * |
||
3444 | * @param int|string $key the key to look for |
||
3445 | * |
||
3446 | * @return bool |
||
3447 | * @psalm-mutation-free |
||
3448 | */ |
||
3449 | 162 | public function keyExists($key): bool |
|
3453 | |||
3454 | /** |
||
3455 | * Get all keys from the current array. |
||
3456 | * |
||
3457 | * @param bool $recursive [optional] <p> |
||
3458 | * Get all keys, also from all sub-arrays from an multi-dimensional array. |
||
3459 | * </p> |
||
3460 | * @param mixed|null $search_values [optional] <p> |
||
3461 | * If specified, then only keys containing these values are returned. |
||
3462 | * </p> |
||
3463 | * @param bool $strict [optional] <p> |
||
3464 | * Determines if strict comparison (===) should be used during the search. |
||
3465 | * </p> |
||
3466 | * |
||
3467 | * @return static |
||
3468 | * <p>(Immutable) An array of all the keys in input.</p> |
||
3469 | * |
||
3470 | * @psalm-return static<array-key,TKey> |
||
3471 | * @psalm-mutation-free |
||
3472 | */ |
||
3473 | 29 | public function keys( |
|
3544 | |||
3545 | /** |
||
3546 | * Sort an array by key in reverse order. |
||
3547 | * |
||
3548 | * @param int $sort_flags [optional] <p> |
||
3549 | * You may modify the behavior of the sort using the optional |
||
3550 | * parameter sort_flags, for details |
||
3551 | * see sort. |
||
3552 | * </p> |
||
3553 | * |
||
3554 | * @return $this |
||
3555 | * <p>(Mutable) Return this Arrayy object.</p> |
||
3556 | * |
||
3557 | * @psalm-return static<TKey,T> |
||
3558 | */ |
||
3559 | 4 | public function krsort(int $sort_flags = 0): self |
|
3567 | |||
3568 | /** |
||
3569 | * Sort an array by key in reverse order. |
||
3570 | * |
||
3571 | * @param int $sort_flags [optional] <p> |
||
3572 | * You may modify the behavior of the sort using the optional |
||
3573 | * parameter sort_flags, for details |
||
3574 | * see sort. |
||
3575 | * </p> |
||
3576 | * |
||
3577 | * @return $this |
||
3578 | * <p>(Immutable) Return this Arrayy object.</p> |
||
3579 | * |
||
3580 | * @psalm-return static<TKey,T> |
||
3581 | * @psalm-mutation-free |
||
3582 | */ |
||
3583 | 4 | public function krsortImmutable(int $sort_flags = 0): self |
|
3594 | |||
3595 | /** |
||
3596 | * Get the last value from the current array. |
||
3597 | * |
||
3598 | * @return mixed|null |
||
3599 | * <p>Return null if there wasn't a element.</p> |
||
3600 | * @psalm-mutation-free |
||
3601 | */ |
||
3602 | 17 | public function last() |
|
3611 | |||
3612 | /** |
||
3613 | * Get the last key from the current array. |
||
3614 | * |
||
3615 | * @return mixed|null |
||
3616 | * <p>Return null if there wasn't a element.</p> |
||
3617 | * @psalm-mutation-free |
||
3618 | */ |
||
3619 | 21 | public function lastKey() |
|
3625 | |||
3626 | /** |
||
3627 | * Get the last value(s) from the current array. |
||
3628 | * |
||
3629 | * @param int|null $number |
||
3630 | * |
||
3631 | * @return static |
||
3632 | * <p>(Immutable)</p> |
||
3633 | * |
||
3634 | * @psalm-return static<TKey,T> |
||
3635 | * @psalm-mutation-free |
||
3636 | */ |
||
3637 | 13 | public function lastsImmutable(int $number = null): self |
|
3667 | |||
3668 | /** |
||
3669 | * Get the last value(s) from the current array. |
||
3670 | * |
||
3671 | * @param int|null $number |
||
3672 | * |
||
3673 | * @return $this |
||
3674 | * <p>(Mutable)</p> |
||
3675 | * |
||
3676 | * @psalm-return static<TKey,T> |
||
3677 | */ |
||
3678 | 13 | public function lastsMutable(int $number = null): self |
|
3706 | |||
3707 | /** |
||
3708 | * Count the values from the current array. |
||
3709 | * |
||
3710 | * alias: for "Arrayy->count()" |
||
3711 | * |
||
3712 | * @param int $mode |
||
3713 | * |
||
3714 | * @return int |
||
3715 | * |
||
3716 | * @see Arrayy::count() |
||
3717 | */ |
||
3718 | 20 | public function length(int $mode = \COUNT_NORMAL): int |
|
3722 | |||
3723 | /** |
||
3724 | * Apply the given function to the every element of the array, |
||
3725 | * collecting the results. |
||
3726 | * |
||
3727 | * @param callable $callable |
||
3728 | * @param bool $useKeyAsSecondParameter |
||
3729 | * @param mixed ...$arguments |
||
3730 | * |
||
3731 | * @return static |
||
3732 | * <p>(Immutable) Arrayy object with modified elements.</p> |
||
3733 | * |
||
3734 | * @psalm-param callable(T,TKey=,mixed=):mixed $callable |
||
3735 | * @psalm-return static<TKey,T> |
||
3736 | * @psalm-mutation-free |
||
3737 | */ |
||
3738 | 5 | public function map( |
|
3771 | |||
3772 | /** |
||
3773 | * Check if all items in current array match a truth test. |
||
3774 | * |
||
3775 | * @param \Closure $closure |
||
3776 | * |
||
3777 | * @return bool |
||
3778 | */ |
||
3779 | 15 | View Code Duplication | public function matches(\Closure $closure): bool |
3795 | |||
3796 | /** |
||
3797 | * Check if any item in the current array matches a truth test. |
||
3798 | * |
||
3799 | * @param \Closure $closure |
||
3800 | * |
||
3801 | * @return bool |
||
3802 | */ |
||
3803 | 14 | View Code Duplication | public function matchesAny(\Closure $closure): bool |
3819 | |||
3820 | /** |
||
3821 | * Get the max value from an array. |
||
3822 | * |
||
3823 | * @return false|mixed |
||
3824 | * <p>Will return false if there are no values.</p> |
||
3825 | */ |
||
3826 | 10 | View Code Duplication | public function max() |
3846 | |||
3847 | /** |
||
3848 | * Merge the new $array into the current array. |
||
3849 | * |
||
3850 | * - keep key,value from the current array, also if the index is in the new $array |
||
3851 | * |
||
3852 | * @param array $array |
||
3853 | * @param bool $recursive |
||
3854 | * |
||
3855 | * @return static |
||
3856 | * <p>(Immutable)</p> |
||
3857 | * |
||
3858 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
3859 | * @psalm-return static<int|TKey,T> |
||
3860 | * @psalm-mutation-free |
||
3861 | */ |
||
3862 | 32 | View Code Duplication | public function mergeAppendKeepIndex(array $array = [], bool $recursive = false): self |
3877 | |||
3878 | /** |
||
3879 | * Merge the new $array into the current array. |
||
3880 | * |
||
3881 | * - replace duplicate assoc-keys from the current array with the key,values from the new $array |
||
3882 | * - create new indexes |
||
3883 | * |
||
3884 | * @param array $array |
||
3885 | * @param bool $recursive |
||
3886 | * |
||
3887 | * @return static |
||
3888 | * <p>(Immutable)</p> |
||
3889 | * |
||
3890 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
3891 | * @psalm-return static<TKey,T> |
||
3892 | * @psalm-mutation-free |
||
3893 | */ |
||
3894 | 19 | View Code Duplication | public function mergeAppendNewIndex(array $array = [], bool $recursive = false): self |
3909 | |||
3910 | /** |
||
3911 | * Merge the the current array into the $array. |
||
3912 | * |
||
3913 | * - use key,value from the new $array, also if the index is in the current array |
||
3914 | * |
||
3915 | * @param array $array |
||
3916 | * @param bool $recursive |
||
3917 | * |
||
3918 | * @return static |
||
3919 | * <p>(Immutable)</p> |
||
3920 | * |
||
3921 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
3922 | * @psalm-return static<TKey,T> |
||
3923 | * @psalm-mutation-free |
||
3924 | */ |
||
3925 | 16 | View Code Duplication | public function mergePrependKeepIndex(array $array = [], bool $recursive = false): self |
3940 | |||
3941 | /** |
||
3942 | * Merge the current array into the new $array. |
||
3943 | * |
||
3944 | * - replace duplicate assoc-keys from new $array with the key,values from the current array |
||
3945 | * - create new indexes |
||
3946 | * |
||
3947 | * @param array $array |
||
3948 | * @param bool $recursive |
||
3949 | * |
||
3950 | * @return static |
||
3951 | * <p>(Immutable)</p> |
||
3952 | * |
||
3953 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
3954 | * @psalm-return static<TKey,T> |
||
3955 | * @psalm-mutation-free |
||
3956 | */ |
||
3957 | 20 | View Code Duplication | public function mergePrependNewIndex(array $array = [], bool $recursive = false): self |
3972 | |||
3973 | /** |
||
3974 | * @return ArrayyMeta|static |
||
3975 | */ |
||
3976 | 16 | public static function meta() |
|
3980 | |||
3981 | /** |
||
3982 | * Get the min value from an array. |
||
3983 | * |
||
3984 | * @return false|mixed |
||
3985 | * <p>Will return false if there are no values.</p> |
||
3986 | */ |
||
3987 | 10 | View Code Duplication | public function min() |
4007 | |||
4008 | /** |
||
4009 | * Get the most used value from the array. |
||
4010 | * |
||
4011 | * @return mixed|null |
||
4012 | * <p>(Immutable) Return null if there wasn't a element.</p> |
||
4013 | * @psalm-mutation-free |
||
4014 | */ |
||
4015 | 3 | public function mostUsedValue() |
|
4019 | |||
4020 | /** |
||
4021 | * Get the most used value from the array. |
||
4022 | * |
||
4023 | * @param int|null $number <p>How many values you will take?</p> |
||
4024 | * |
||
4025 | * @return static |
||
4026 | * <p>(Immutable)</p> |
||
4027 | * |
||
4028 | * @psalm-return static<TKey,T> |
||
4029 | * @psalm-mutation-free |
||
4030 | */ |
||
4031 | 3 | public function mostUsedValues(int $number = null): self |
|
4035 | |||
4036 | /** |
||
4037 | * Move an array element to a new index. |
||
4038 | * |
||
4039 | * cherry-picked from: http://stackoverflow.com/questions/12624153/move-an-array-element-to-a-new-index-in-php |
||
4040 | * |
||
4041 | * @param int|string $from |
||
4042 | * @param int $to |
||
4043 | * |
||
4044 | * @return static |
||
4045 | * <p>(Immutable)</p> |
||
4046 | * |
||
4047 | * @psalm-return static<TKey,T> |
||
4048 | * @psalm-mutation-free |
||
4049 | */ |
||
4050 | 1 | public function moveElement($from, $to): self |
|
4083 | |||
4084 | /** |
||
4085 | * Move an array element to the first place. |
||
4086 | * |
||
4087 | * INFO: Instead of "Arrayy->moveElement()" this method will NOT |
||
4088 | * loss the keys of an indexed array. |
||
4089 | * |
||
4090 | * @param int|string $key |
||
4091 | * |
||
4092 | * @return static |
||
4093 | * <p>(Immutable)</p> |
||
4094 | * |
||
4095 | * @psalm-return static<TKey,T> |
||
4096 | * @psalm-mutation-free |
||
4097 | */ |
||
4098 | 1 | View Code Duplication | public function moveElementToFirstPlace($key): self |
4114 | |||
4115 | /** |
||
4116 | * Move an array element to the last place. |
||
4117 | * |
||
4118 | * INFO: Instead of "Arrayy->moveElement()" this method will NOT |
||
4119 | * loss the keys of an indexed array. |
||
4120 | * |
||
4121 | * @param int|string $key |
||
4122 | * |
||
4123 | * @return static |
||
4124 | * <p>(Immutable)</p> |
||
4125 | * |
||
4126 | * @psalm-return static<TKey,T> |
||
4127 | * @psalm-mutation-free |
||
4128 | */ |
||
4129 | 1 | View Code Duplication | public function moveElementToLastPlace($key): self |
4145 | |||
4146 | /** |
||
4147 | * Moves the internal iterator position to the next element and returns this element. |
||
4148 | * |
||
4149 | * @return false|mixed |
||
4150 | * <p>(Mutable) Will return false if there are no values.</p> |
||
4151 | */ |
||
4152 | public function next() |
||
4156 | |||
4157 | /** |
||
4158 | * Get the next nth keys and values from the array. |
||
4159 | * |
||
4160 | * @param int $step |
||
4161 | * @param int $offset |
||
4162 | * |
||
4163 | * @return static |
||
4164 | * <p>(Immutable)</p> |
||
4165 | * |
||
4166 | * @psalm-return static<TKey,T> |
||
4167 | * @psalm-mutation-free |
||
4168 | */ |
||
4169 | public function nth(int $step, int $offset = 0): self |
||
4188 | |||
4189 | /** |
||
4190 | * Get a subset of the items from the given array. |
||
4191 | * |
||
4192 | * @param mixed[] $keys |
||
4193 | * |
||
4194 | * @return static |
||
4195 | * <p>(Immutable)</p> |
||
4196 | * |
||
4197 | * @psalm-return static<TKey,T> |
||
4198 | * @psalm-mutation-free |
||
4199 | */ |
||
4200 | 1 | public function only(array $keys): self |
|
4210 | |||
4211 | /** |
||
4212 | * Pad array to the specified size with a given value. |
||
4213 | * |
||
4214 | * @param int $size <p>Size of the result array.</p> |
||
4215 | * @param mixed $value <p>Empty value by default.</p> |
||
4216 | * |
||
4217 | * @return static |
||
4218 | * <p>(Immutable) Arrayy object padded to $size with $value.</p> |
||
4219 | * |
||
4220 | * @psalm-return static<TKey,T> |
||
4221 | * @psalm-mutation-free |
||
4222 | */ |
||
4223 | 5 | public function pad(int $size, $value): self |
|
4231 | |||
4232 | /** |
||
4233 | * Partitions this array in two array according to a predicate. |
||
4234 | * Keys are preserved in the resulting array. |
||
4235 | * |
||
4236 | * @param \Closure $closure |
||
4237 | * <p>The predicate on which to partition.</p> |
||
4238 | * |
||
4239 | * @return array<int, static> |
||
4240 | * <p>An array with two elements. The first element contains the array |
||
4241 | * of elements where the predicate returned TRUE, the second element |
||
4242 | * contains the array of elements where the predicate returned FALSE.</p> |
||
4243 | * |
||
4244 | * @psalm-return array<int, static<TKey,T>> |
||
4245 | */ |
||
4246 | 1 | public function partition(\Closure $closure): array |
|
4262 | |||
4263 | /** |
||
4264 | * Pop a specified value off the end of the current array. |
||
4265 | * |
||
4266 | * @return mixed|null |
||
4267 | * <p>(Mutable) The popped element from the current array or null if the array is e.g. empty.</p> |
||
4268 | */ |
||
4269 | 5 | public function pop() |
|
4275 | |||
4276 | /** |
||
4277 | * Prepend a (key) + value to the current array. |
||
4278 | * |
||
4279 | * EXAMPLE: <code> |
||
4280 | * a(['fòô' => 'bàř'])->prepend('foo'); // Arrayy[0 => 'foo', 'fòô' => 'bàř'] |
||
4281 | * </code> |
||
4282 | * |
||
4283 | * @param mixed $value |
||
4284 | * @param mixed $key |
||
4285 | * |
||
4286 | * @return $this |
||
4287 | * <p>(Mutable) Return this Arrayy object, with the prepended value.</p> |
||
4288 | * |
||
4289 | * @psalm-return static<TKey,T> |
||
4290 | */ |
||
4291 | 11 | public function prepend($value, $key = null) |
|
4307 | |||
4308 | /** |
||
4309 | * Add a suffix to each key. |
||
4310 | * |
||
4311 | * @param mixed $suffix |
||
4312 | * |
||
4313 | * @return static |
||
4314 | * <p>(Immutable) Return an Arrayy object, with the prepended keys.</p> |
||
4315 | * |
||
4316 | * @psalm-return static<TKey,T> |
||
4317 | * @psalm-mutation-free |
||
4318 | */ |
||
4319 | 10 | View Code Duplication | public function prependToEachKey($suffix): self |
4345 | |||
4346 | /** |
||
4347 | * Add a suffix to each value. |
||
4348 | * |
||
4349 | * @param mixed $suffix |
||
4350 | * |
||
4351 | * @return static |
||
4352 | * <p>(Immutable) Return an Arrayy object, with the prepended values.</p> |
||
4353 | * |
||
4354 | * @psalm-return static<TKey,T> |
||
4355 | * @psalm-mutation-free |
||
4356 | */ |
||
4357 | 10 | View Code Duplication | public function prependToEachValue($suffix): self |
4385 | |||
4386 | /** |
||
4387 | * Return the value of a given key and |
||
4388 | * delete the key. |
||
4389 | * |
||
4390 | * @param int|int[]|string|string[]|null $keyOrKeys |
||
4391 | * @param mixed $fallback |
||
4392 | * |
||
4393 | * @return mixed |
||
4394 | */ |
||
4395 | 5 | public function pull($keyOrKeys = null, $fallback = null) |
|
4417 | |||
4418 | /** |
||
4419 | * Push one or more values onto the end of array at once. |
||
4420 | * |
||
4421 | * @param array ...$args |
||
4422 | * |
||
4423 | * @return $this |
||
4424 | * <p>(Mutable) Return this Arrayy object, with pushed elements to the end of array.</p> |
||
4425 | * |
||
4426 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
4427 | * |
||
4428 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$args |
||
4429 | * @psalm-return static<TKey,T> |
||
4430 | */ |
||
4431 | 7 | public function push(...$args) |
|
4449 | |||
4450 | /** |
||
4451 | * Get a random value from the current array. |
||
4452 | * |
||
4453 | * @param int|null $number <p>How many values you will take?</p> |
||
4454 | * |
||
4455 | * @return static |
||
4456 | * <p>(Immutable)</p> |
||
4457 | * |
||
4458 | * @psalm-return static<int|array-key,T> |
||
4459 | */ |
||
4460 | 19 | public function randomImmutable(int $number = null): self |
|
4493 | |||
4494 | /** |
||
4495 | * Pick a random key/index from the keys of this array. |
||
4496 | * |
||
4497 | * @throws \RangeException If array is empty |
||
4498 | * |
||
4499 | * @return mixed |
||
4500 | * <p>Get a key/index or null if there wasn't a key/index.</p> |
||
4501 | */ |
||
4502 | 4 | public function randomKey() |
|
4512 | |||
4513 | /** |
||
4514 | * Pick a given number of random keys/indexes out of this array. |
||
4515 | * |
||
4516 | * @param int $number <p>The number of keys/indexes (should be <= \count($this->array))</p> |
||
4517 | * |
||
4518 | * @throws \RangeException If array is empty |
||
4519 | * |
||
4520 | * @return static |
||
4521 | * <p>(Immutable)</p> |
||
4522 | * |
||
4523 | * @psalm-return static<TKey,T> |
||
4524 | */ |
||
4525 | 13 | public function randomKeys(int $number): self |
|
4553 | |||
4554 | /** |
||
4555 | * Get a random value from the current array. |
||
4556 | * |
||
4557 | * @param int|null $number <p>How many values you will take?</p> |
||
4558 | * |
||
4559 | * @return $this |
||
4560 | * <p>(Mutable) Return this Arrayy object.</p> |
||
4561 | * |
||
4562 | * @psalm-return static<TKey,T> |
||
4563 | */ |
||
4564 | 17 | public function randomMutable(int $number = null): self |
|
4589 | |||
4590 | /** |
||
4591 | * Pick a random value from the values of this array. |
||
4592 | * |
||
4593 | * @return mixed |
||
4594 | * <p>Get a random value or null if there wasn't a value.</p> |
||
4595 | */ |
||
4596 | 4 | public function randomValue() |
|
4606 | |||
4607 | /** |
||
4608 | * Pick a given number of random values out of this array. |
||
4609 | * |
||
4610 | * @param int $number |
||
4611 | * |
||
4612 | * @return static |
||
4613 | * <p>(Mutable)</p> |
||
4614 | * |
||
4615 | * @psalm-return static<TKey,T> |
||
4616 | */ |
||
4617 | 7 | public function randomValues(int $number): self |
|
4621 | |||
4622 | /** |
||
4623 | * Get a random value from an array, with the ability to skew the results. |
||
4624 | * |
||
4625 | * Example: randomWeighted(['foo' => 1, 'bar' => 2]) has a 66% chance of returning bar. |
||
4626 | * |
||
4627 | * @param array $array |
||
4628 | * @param int|null $number <p>How many values you will take?</p> |
||
4629 | * |
||
4630 | * @return static<int,mixed> |
||
4631 | * <p>(Immutable)</p> |
||
4632 | * |
||
4633 | * @psalm-param array<mixed,mixed> $array |
||
4634 | * @psalm-return static<int|array-key,T> |
||
4635 | */ |
||
4636 | 9 | public function randomWeighted(array $array, int $number = null): self |
|
4651 | |||
4652 | /** |
||
4653 | * Reduce the current array via callable e.g. anonymous-function. |
||
4654 | * |
||
4655 | * @param callable $callable |
||
4656 | * @param mixed $init |
||
4657 | * |
||
4658 | * @return static |
||
4659 | * <p>(Immutable)</p> |
||
4660 | * |
||
4661 | * @psalm-return static<TKey,T> |
||
4662 | * @psalm-mutation-free |
||
4663 | */ |
||
4664 | 18 | public function reduce($callable, $init = []): self |
|
4694 | |||
4695 | /** |
||
4696 | * @param bool $unique |
||
4697 | * |
||
4698 | * @return static |
||
4699 | * <p>(Immutable)</p> |
||
4700 | * |
||
4701 | * @psalm-return static<TKey,T> |
||
4702 | * @psalm-mutation-free |
||
4703 | */ |
||
4704 | 14 | public function reduce_dimension(bool $unique = true): self |
|
4727 | |||
4728 | /** |
||
4729 | * Create a numerically re-indexed Arrayy object. |
||
4730 | * |
||
4731 | * @return $this |
||
4732 | * <p>(Mutable) Return this Arrayy object, with re-indexed array-elements.</p> |
||
4733 | * |
||
4734 | * @psalm-return static<TKey,T> |
||
4735 | */ |
||
4736 | 9 | public function reindex(): self |
|
4744 | |||
4745 | /** |
||
4746 | * Return all items that fail the truth test. |
||
4747 | * |
||
4748 | * @param \Closure $closure |
||
4749 | * |
||
4750 | * @return static |
||
4751 | * <p>(Immutable)</p> |
||
4752 | * |
||
4753 | * @psalm-return static<TKey,T> |
||
4754 | * @psalm-mutation-free |
||
4755 | */ |
||
4756 | 1 | View Code Duplication | public function reject(\Closure $closure): self |
4773 | |||
4774 | /** |
||
4775 | * Remove a value from the current array (optional using dot-notation). |
||
4776 | * |
||
4777 | * @param mixed $key |
||
4778 | * |
||
4779 | * @return static |
||
4780 | * <p>(Mutable)</p> |
||
4781 | * |
||
4782 | * @psalm-param TKey $key |
||
4783 | * @psalm-return static<TKey,T> |
||
4784 | */ |
||
4785 | 21 | public function remove($key) |
|
4808 | |||
4809 | /** |
||
4810 | * alias: for "Arrayy->removeValue()" |
||
4811 | * |
||
4812 | * @param mixed $element |
||
4813 | * |
||
4814 | * @return static |
||
4815 | * <p>(Immutable)</p> |
||
4816 | * |
||
4817 | * @psalm-param T $element |
||
4818 | * @psalm-return static<TKey,T> |
||
4819 | * @psalm-mutation-free |
||
4820 | */ |
||
4821 | 8 | public function removeElement($element) |
|
4825 | |||
4826 | /** |
||
4827 | * Remove the first value from the current array. |
||
4828 | * |
||
4829 | * @return static |
||
4830 | * <p>(Immutable)</p> |
||
4831 | * |
||
4832 | * @psalm-return static<TKey,T> |
||
4833 | * @psalm-mutation-free |
||
4834 | */ |
||
4835 | 7 | View Code Duplication | public function removeFirst(): self |
4847 | |||
4848 | /** |
||
4849 | * Remove the last value from the current array. |
||
4850 | * |
||
4851 | * @return static |
||
4852 | * <p>(Immutable)</p> |
||
4853 | * |
||
4854 | * @psalm-return static<TKey,T> |
||
4855 | * @psalm-mutation-free |
||
4856 | */ |
||
4857 | 7 | View Code Duplication | public function removeLast(): self |
4869 | |||
4870 | /** |
||
4871 | * Removes a particular value from an array (numeric or associative). |
||
4872 | * |
||
4873 | * @param mixed $value |
||
4874 | * |
||
4875 | * @return static |
||
4876 | * <p>(Immutable)</p> |
||
4877 | * |
||
4878 | * @psalm-param T $value |
||
4879 | * @psalm-return static<TKey,T> |
||
4880 | * @psalm-mutation-free |
||
4881 | */ |
||
4882 | 8 | public function removeValue($value): self |
|
4905 | |||
4906 | /** |
||
4907 | * Generate array of repeated arrays. |
||
4908 | * |
||
4909 | * @param int $times <p>How many times has to be repeated.</p> |
||
4910 | * |
||
4911 | * @return static |
||
4912 | * <p>(Immutable)</p> |
||
4913 | * |
||
4914 | * @psalm-return static<TKey,T> |
||
4915 | * @psalm-mutation-free |
||
4916 | */ |
||
4917 | 1 | public function repeat($times): self |
|
4929 | |||
4930 | /** |
||
4931 | * Replace a key with a new key/value pair. |
||
4932 | * |
||
4933 | * @param mixed $oldKey |
||
4934 | * @param mixed $newKey |
||
4935 | * @param mixed $newValue |
||
4936 | * |
||
4937 | * @return static |
||
4938 | * <p>(Immutable)</p> |
||
4939 | * |
||
4940 | * @psalm-return static<TKey,T> |
||
4941 | * @psalm-mutation-free |
||
4942 | */ |
||
4943 | 5 | public function replace($oldKey, $newKey, $newValue): self |
|
4953 | |||
4954 | /** |
||
4955 | * Create an array using the current array as values and the other array as keys. |
||
4956 | * |
||
4957 | * @param array $keys <p>An array of keys.</p> |
||
4958 | * |
||
4959 | * @return static |
||
4960 | * <p>(Immutable) Arrayy object with keys from the other array.</p> |
||
4961 | * |
||
4962 | * @psalm-param array<mixed,mixed>|array<mixed,TKey> $keys |
||
4963 | * @psalm-return static<TKey,T> |
||
4964 | * @psalm-mutation-free |
||
4965 | */ |
||
4966 | 2 | public function replaceAllKeys(array $keys): self |
|
4974 | |||
4975 | /** |
||
4976 | * Create an array using the current array as keys and the other array as values. |
||
4977 | * |
||
4978 | * @param array $array <p>An array o values.</p> |
||
4979 | * |
||
4980 | * @return static |
||
4981 | * <p>(Immutable) Arrayy object with values from the other array.</p> |
||
4982 | * |
||
4983 | * @psalm-param array<mixed,T> $array |
||
4984 | * @psalm-return static<TKey,T> |
||
4985 | * @psalm-mutation-free |
||
4986 | */ |
||
4987 | 2 | public function replaceAllValues(array $array): self |
|
4995 | |||
4996 | /** |
||
4997 | * Replace the keys in an array with another set. |
||
4998 | * |
||
4999 | * @param array $keys <p>An array of keys matching the array's size</p> |
||
5000 | * |
||
5001 | * @return static |
||
5002 | * <p>(Immutable)</p> |
||
5003 | * |
||
5004 | * @psalm-param array<mixed,mixed>|array<mixed,TKey> $keys |
||
5005 | * @psalm-return static<TKey,T> |
||
5006 | * @psalm-mutation-free |
||
5007 | */ |
||
5008 | 1 | public function replaceKeys(array $keys): self |
|
5019 | |||
5020 | /** |
||
5021 | * Replace the first matched value in an array. |
||
5022 | * |
||
5023 | * @param mixed $search <p>The value to replace.</p> |
||
5024 | * @param mixed $replacement <p>The value to replace.</p> |
||
5025 | * |
||
5026 | * @return static |
||
5027 | * <p>(Immutable)</p> |
||
5028 | * |
||
5029 | * @psalm-return static<TKey,T> |
||
5030 | * @psalm-mutation-free |
||
5031 | */ |
||
5032 | 3 | View Code Duplication | public function replaceOneValue($search, $replacement = ''): self |
5047 | |||
5048 | /** |
||
5049 | * Replace values in the current array. |
||
5050 | * |
||
5051 | * @param mixed $search <p>The value to replace.</p> |
||
5052 | * @param mixed $replacement <p>What to replace it with.</p> |
||
5053 | * |
||
5054 | * @return static |
||
5055 | * <p>(Immutable)</p> |
||
5056 | * |
||
5057 | * @psalm-return static<TKey,T> |
||
5058 | * @psalm-mutation-free |
||
5059 | */ |
||
5060 | 1 | public function replaceValues($search, $replacement = ''): self |
|
5072 | |||
5073 | /** |
||
5074 | * Get the last elements from index $from until the end of this array. |
||
5075 | * |
||
5076 | * @param int $from |
||
5077 | * |
||
5078 | * @return static |
||
5079 | * <p>(Immutable)</p> |
||
5080 | * |
||
5081 | * @psalm-return static<TKey,T> |
||
5082 | * @psalm-mutation-free |
||
5083 | */ |
||
5084 | 15 | View Code Duplication | public function rest(int $from = 1): self |
5094 | |||
5095 | /** |
||
5096 | * Return the array in the reverse order. |
||
5097 | * |
||
5098 | * @return $this |
||
5099 | * <p>(Mutable) Return this Arrayy object.</p> |
||
5100 | * |
||
5101 | * @psalm-return static<TKey,T> |
||
5102 | */ |
||
5103 | 9 | public function reverse(): self |
|
5111 | |||
5112 | /** |
||
5113 | * Sort an array in reverse order. |
||
5114 | * |
||
5115 | * @param int $sort_flags [optional] <p> |
||
5116 | * You may modify the behavior of the sort using the optional |
||
5117 | * parameter sort_flags, for details |
||
5118 | * see sort. |
||
5119 | * </p> |
||
5120 | * |
||
5121 | * @return $this |
||
5122 | * <p>(Mutable) Return this Arrayy object.</p> |
||
5123 | * |
||
5124 | * @psalm-return static<TKey,T> |
||
5125 | */ |
||
5126 | 4 | public function rsort(int $sort_flags = 0): self |
|
5134 | |||
5135 | /** |
||
5136 | * Sort an array in reverse order. |
||
5137 | * |
||
5138 | * @param int $sort_flags [optional] <p> |
||
5139 | * You may modify the behavior of the sort using the optional |
||
5140 | * parameter sort_flags, for details |
||
5141 | * see sort. |
||
5142 | * </p> |
||
5143 | * |
||
5144 | * @return $this |
||
5145 | * <p>(Immutable) Return this Arrayy object.</p> |
||
5146 | * |
||
5147 | * @psalm-return static<TKey,T> |
||
5148 | * @psalm-mutation-free |
||
5149 | */ |
||
5150 | 4 | public function rsortImmutable(int $sort_flags = 0): self |
|
5161 | |||
5162 | /** |
||
5163 | * Search for the first index of the current array via $value. |
||
5164 | * |
||
5165 | * @param mixed $value |
||
5166 | * |
||
5167 | * @return false|float|int|string |
||
5168 | * <p>Will return <b>FALSE</b> if the value can't be found.</p> |
||
5169 | * @psalm-mutation-free |
||
5170 | */ |
||
5171 | 21 | public function searchIndex($value) |
|
5181 | |||
5182 | /** |
||
5183 | * Search for the value of the current array via $index. |
||
5184 | * |
||
5185 | * @param mixed $index |
||
5186 | * |
||
5187 | * @return static |
||
5188 | * <p>(Immutable) Will return a empty Arrayy if the value wasn't found.</p> |
||
5189 | * |
||
5190 | * @psalm-return static<TKey,T> |
||
5191 | * @psalm-mutation-free |
||
5192 | */ |
||
5193 | 9 | public function searchValue($index): self |
|
5223 | |||
5224 | /** |
||
5225 | * Set a value for the current array (optional using dot-notation). |
||
5226 | * |
||
5227 | * @param string $key <p>The key to set.</p> |
||
5228 | * @param mixed $value <p>Its value.</p> |
||
5229 | * |
||
5230 | * @return $this |
||
5231 | * <p>(Mutable) Return this Arrayy object.</p> |
||
5232 | * |
||
5233 | * @psalm-param TKey $key |
||
5234 | * @psalm-param T $value |
||
5235 | * @psalm-return static<TKey,T> |
||
5236 | */ |
||
5237 | 28 | public function set($key, $value): self |
|
5243 | |||
5244 | /** |
||
5245 | * Get a value from a array and set it if it was not. |
||
5246 | * |
||
5247 | * WARNING: this method only set the value, if the $key is not already set |
||
5248 | * |
||
5249 | * @param mixed $key <p>The key</p> |
||
5250 | * @param mixed $fallback <p>The default value to set if it isn't.</p> |
||
5251 | * |
||
5252 | * @return mixed |
||
5253 | * <p>(Mutable)</p> |
||
5254 | */ |
||
5255 | 11 | public function setAndGet($key, $fallback = null) |
|
5266 | |||
5267 | /** |
||
5268 | * Shifts a specified value off the beginning of array. |
||
5269 | * |
||
5270 | * @return mixed |
||
5271 | * <p>(Mutable) A shifted element from the current array.</p> |
||
5272 | */ |
||
5273 | 5 | public function shift() |
|
5279 | |||
5280 | /** |
||
5281 | * Shuffle the current array. |
||
5282 | * |
||
5283 | * @param bool $secure <p>using a CSPRNG | @link https://paragonie.com/b/JvICXzh_jhLyt4y3</p> |
||
5284 | * @param array $array [optional] |
||
5285 | * |
||
5286 | * @return static |
||
5287 | * <p>(Immutable)</p> |
||
5288 | * |
||
5289 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
5290 | * @psalm-return static<TKey,T> |
||
5291 | * |
||
5292 | * @noinspection BadExceptionsProcessingInspection |
||
5293 | * @noinspection RandomApiMigrationInspection |
||
5294 | * @noinspection NonSecureShuffleUsageInspection |
||
5295 | */ |
||
5296 | 2 | public function shuffle(bool $secure = false, array $array = null): self |
|
5334 | |||
5335 | /** |
||
5336 | * Count the values from the current array. |
||
5337 | * |
||
5338 | * alias: for "Arrayy->count()" |
||
5339 | * |
||
5340 | * @param int $mode |
||
5341 | * |
||
5342 | * @return int |
||
5343 | */ |
||
5344 | 20 | public function size(int $mode = \COUNT_NORMAL): int |
|
5348 | |||
5349 | /** |
||
5350 | * Checks whether array has exactly $size items. |
||
5351 | * |
||
5352 | * @param int $size |
||
5353 | * |
||
5354 | * @return bool |
||
5355 | */ |
||
5356 | 1 | public function sizeIs(int $size): bool |
|
5372 | |||
5373 | /** |
||
5374 | * Checks whether array has between $fromSize to $toSize items. $toSize can be |
||
5375 | * smaller than $fromSize. |
||
5376 | * |
||
5377 | * @param int $fromSize |
||
5378 | * @param int $toSize |
||
5379 | * |
||
5380 | * @return bool |
||
5381 | */ |
||
5382 | 1 | public function sizeIsBetween(int $fromSize, int $toSize): bool |
|
5402 | |||
5403 | /** |
||
5404 | * Checks whether array has more than $size items. |
||
5405 | * |
||
5406 | * @param int $size |
||
5407 | * |
||
5408 | * @return bool |
||
5409 | */ |
||
5410 | 1 | View Code Duplication | public function sizeIsGreaterThan(int $size): bool |
5424 | |||
5425 | /** |
||
5426 | * Checks whether array has less than $size items. |
||
5427 | * |
||
5428 | * @param int $size |
||
5429 | * |
||
5430 | * @return bool |
||
5431 | */ |
||
5432 | 1 | View Code Duplication | public function sizeIsLessThan(int $size): bool |
5446 | |||
5447 | /** |
||
5448 | * Counts all elements in an array, or something in an object. |
||
5449 | * |
||
5450 | * <p> |
||
5451 | * For objects, if you have SPL installed, you can hook into count() by implementing interface {@see Countable}. |
||
5452 | * The interface has exactly one method, {@see Countable::count()}, which returns the return value for the count() |
||
5453 | * function. Please see the {@see Array} section of the manual for a detailed explanation of how arrays are |
||
5454 | * implemented and used in PHP. |
||
5455 | * </p> |
||
5456 | * |
||
5457 | * @return int |
||
5458 | * <p> |
||
5459 | * The number of elements in var, which is |
||
5460 | * typically an array, since anything else will have one |
||
5461 | * element. |
||
5462 | * </p> |
||
5463 | * <p> |
||
5464 | * If var is not an array or an object with |
||
5465 | * implemented Countable interface, |
||
5466 | * 1 will be returned. |
||
5467 | * There is one exception, if var is &null;, |
||
5468 | * 0 will be returned. |
||
5469 | * </p> |
||
5470 | * <p> |
||
5471 | * Caution: count may return 0 for a variable that isn't set, |
||
5472 | * but it may also return 0 for a variable that has been initialized with an |
||
5473 | * empty array. Use isset to test if a variable is set. |
||
5474 | * </p> |
||
5475 | */ |
||
5476 | 10 | public function sizeRecursive(): int |
|
5480 | |||
5481 | /** |
||
5482 | * Extract a slice of the array. |
||
5483 | * |
||
5484 | * @param int $offset <p>Slice begin index.</p> |
||
5485 | * @param int|null $length <p>Length of the slice.</p> |
||
5486 | * @param bool $preserveKeys <p>Whether array keys are preserved or no.</p> |
||
5487 | * |
||
5488 | * @return static |
||
5489 | * <p>(Immutable) A slice of the original array with length $length.</p> |
||
5490 | * |
||
5491 | * @psalm-return static<TKey,T> |
||
5492 | * @psalm-mutation-free |
||
5493 | */ |
||
5494 | 5 | public function slice(int $offset, int $length = null, bool $preserveKeys = false) |
|
5507 | |||
5508 | /** |
||
5509 | * Sort the current array and optional you can keep the keys. |
||
5510 | * |
||
5511 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
5512 | * @param int $strategy <p>sort_flags => use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
5513 | * <strong>SORT_NATURAL</strong></p> |
||
5514 | * @param bool $keepKeys |
||
5515 | * |
||
5516 | * @return static |
||
5517 | * <p>(Mutable) Return this Arrayy object.</p> |
||
5518 | * |
||
5519 | * @psalm-return static<TKey,T> |
||
5520 | */ |
||
5521 | 20 | public function sort( |
|
5535 | |||
5536 | /** |
||
5537 | * Sort the current array and optional you can keep the keys. |
||
5538 | * |
||
5539 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
5540 | * @param int $strategy <p>sort_flags => use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
5541 | * <strong>SORT_NATURAL</strong></p> |
||
5542 | * @param bool $keepKeys |
||
5543 | * |
||
5544 | * @return static |
||
5545 | * <p>(Immutable) Return this Arrayy object.</p> |
||
5546 | * |
||
5547 | * @psalm-return static<TKey,T> |
||
5548 | */ |
||
5549 | 12 | public function sortImmutable( |
|
5565 | |||
5566 | /** |
||
5567 | * Sort the current array by key. |
||
5568 | * |
||
5569 | * @see http://php.net/manual/en/function.ksort.php |
||
5570 | * @see http://php.net/manual/en/function.krsort.php |
||
5571 | * |
||
5572 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
5573 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
5574 | * <strong>SORT_NATURAL</strong></p> |
||
5575 | * |
||
5576 | * @return $this |
||
5577 | * <p>(Mutable) Return this Arrayy object.</p> |
||
5578 | * |
||
5579 | * @psalm-return static<TKey,T> |
||
5580 | */ |
||
5581 | 18 | public function sortKeys( |
|
5591 | |||
5592 | /** |
||
5593 | * Sort the current array by key. |
||
5594 | * |
||
5595 | * @see http://php.net/manual/en/function.ksort.php |
||
5596 | * @see http://php.net/manual/en/function.krsort.php |
||
5597 | * |
||
5598 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
5599 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
5600 | * <strong>SORT_NATURAL</strong></p> |
||
5601 | * |
||
5602 | * @return $this |
||
5603 | * <p>(Immutable) Return this Arrayy object.</p> |
||
5604 | * |
||
5605 | * @psalm-return static<TKey,T> |
||
5606 | * @psalm-mutation-free |
||
5607 | */ |
||
5608 | 8 | public function sortKeysImmutable( |
|
5621 | |||
5622 | /** |
||
5623 | * Sort the current array by value. |
||
5624 | * |
||
5625 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
5626 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
5627 | * <strong>SORT_NATURAL</strong></p> |
||
5628 | * |
||
5629 | * @return static |
||
5630 | * <p>(Mutable)</p> |
||
5631 | * |
||
5632 | * @psalm-return static<TKey,T> |
||
5633 | */ |
||
5634 | 1 | public function sortValueKeepIndex( |
|
5640 | |||
5641 | /** |
||
5642 | * Sort the current array by value. |
||
5643 | * |
||
5644 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
5645 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
5646 | * <strong>SORT_NATURAL</strong></p> |
||
5647 | * |
||
5648 | * @return static |
||
5649 | * <p>(Mutable)</p> |
||
5650 | * |
||
5651 | * @psalm-return static<TKey,T> |
||
5652 | */ |
||
5653 | 1 | public function sortValueNewIndex($direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
5657 | |||
5658 | /** |
||
5659 | * Sort a array by value, by a closure or by a property. |
||
5660 | * |
||
5661 | * - If the sorter is null, the array is sorted naturally. |
||
5662 | * - Associative (string) keys will be maintained, but numeric keys will be re-indexed. |
||
5663 | * |
||
5664 | * @param callable|string|null $sorter |
||
5665 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or |
||
5666 | * <strong>SORT_DESC</strong></p> |
||
5667 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
5668 | * <strong>SORT_NATURAL</strong></p> |
||
5669 | * |
||
5670 | * @return static |
||
5671 | * <p>(Immutable)</p> |
||
5672 | * |
||
5673 | * @psalm-return static<TKey,T> |
||
5674 | * @psalm-mutation-free |
||
5675 | */ |
||
5676 | 1 | public function sorter($sorter = null, $direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
5717 | |||
5718 | /** |
||
5719 | * @param int $offset |
||
5720 | * @param int|null $length |
||
5721 | * @param array $replacement |
||
5722 | * |
||
5723 | * @return static |
||
5724 | * <p>(Immutable)</p> |
||
5725 | * |
||
5726 | * @psalm-param array<mixed,mixed>|array<mixed,T> $replacement |
||
5727 | * @psalm-return static<TKey,T> |
||
5728 | * @psalm-mutation-free |
||
5729 | */ |
||
5730 | 1 | public function splice(int $offset, int $length = null, $replacement = []): self |
|
5747 | |||
5748 | /** |
||
5749 | * Split an array in the given amount of pieces. |
||
5750 | * |
||
5751 | * @param int $numberOfPieces |
||
5752 | * @param bool $keepKeys |
||
5753 | * |
||
5754 | * @return static |
||
5755 | * <p>(Immutable)</p> |
||
5756 | * |
||
5757 | * @psalm-return static<TKey,T> |
||
5758 | * @psalm-mutation-free |
||
5759 | */ |
||
5760 | 1 | public function split(int $numberOfPieces = 2, bool $keepKeys = false): self |
|
5779 | |||
5780 | /** |
||
5781 | * Stripe all empty items. |
||
5782 | * |
||
5783 | * @return static |
||
5784 | * <p>(Immutable)</p> |
||
5785 | * |
||
5786 | * @psalm-return static<TKey,T> |
||
5787 | * @psalm-mutation-free |
||
5788 | */ |
||
5789 | 1 | public function stripEmpty(): self |
|
5801 | |||
5802 | /** |
||
5803 | * Swap two values between positions by key. |
||
5804 | * |
||
5805 | * @param int|string $swapA <p>a key in the array</p> |
||
5806 | * @param int|string $swapB <p>a key in the array</p> |
||
5807 | * |
||
5808 | * @return static |
||
5809 | * <p>(Immutable)</p> |
||
5810 | * |
||
5811 | * @psalm-return static<TKey,T> |
||
5812 | * @psalm-mutation-free |
||
5813 | */ |
||
5814 | 1 | public function swap($swapA, $swapB): self |
|
5826 | |||
5827 | /** |
||
5828 | * Get the current array from the "Arrayy"-object. |
||
5829 | * alias for "getArray()" |
||
5830 | * |
||
5831 | * @param bool $convertAllArrayyElements <p> |
||
5832 | * Convert all Child-"Arrayy" objects also to arrays. |
||
5833 | * </p> |
||
5834 | * @param bool $preserveKeys <p> |
||
5835 | * e.g.: A generator maybe return the same key more then once, |
||
5836 | * so maybe you will ignore the keys. |
||
5837 | * </p> |
||
5838 | * |
||
5839 | * @return array |
||
5840 | * |
||
5841 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
5842 | * @psalm-mutation-free |
||
5843 | */ |
||
5844 | 945 | public function toArray( |
|
5869 | |||
5870 | /** |
||
5871 | * Get the current array from the "Arrayy"-object as list. |
||
5872 | * |
||
5873 | * @param bool $convertAllArrayyElements <p> |
||
5874 | * Convert all Child-"Arrayy" objects also to arrays. |
||
5875 | * </p> |
||
5876 | * |
||
5877 | * @return array |
||
5878 | * |
||
5879 | * @psalm-return list<array<TKey,T>> |
||
5880 | * @psalm-mutation-free |
||
5881 | */ |
||
5882 | 1 | public function toList(bool $convertAllArrayyElements = false): array |
|
5889 | |||
5890 | /** |
||
5891 | * Convert the current array to JSON. |
||
5892 | * |
||
5893 | * @param int $options [optional] <p>e.g. JSON_PRETTY_PRINT</p> |
||
5894 | * @param int $depth [optional] <p>Set the maximum depth. Must be greater than zero.</p> |
||
5895 | * |
||
5896 | * @return string |
||
5897 | */ |
||
5898 | 12 | public function toJson(int $options = 0, int $depth = 512): string |
|
5907 | |||
5908 | /** |
||
5909 | * @param string[]|null $items [optional] |
||
5910 | * @param string[] $helper [optional] |
||
5911 | * |
||
5912 | * @return static|static[] |
||
5913 | * |
||
5914 | * @psalm-return static<int, static<TKey,T>> |
||
5915 | */ |
||
5916 | 1 | public function toPermutation(array $items = null, array $helper = []): self |
|
5950 | |||
5951 | /** |
||
5952 | * Implodes array to a string with specified separator. |
||
5953 | * |
||
5954 | * @param string $separator [optional] <p>The element's separator.</p> |
||
5955 | * |
||
5956 | * @return string |
||
5957 | * <p>The string representation of array, separated by ",".</p> |
||
5958 | */ |
||
5959 | 19 | public function toString(string $separator = ','): string |
|
5963 | |||
5964 | /** |
||
5965 | * Return a duplicate free copy of the current array. |
||
5966 | * |
||
5967 | * @return $this |
||
5968 | * <p>(Mutable)</p> |
||
5969 | * |
||
5970 | * @psalm-return static<TKey,T> |
||
5971 | */ |
||
5972 | 13 | public function unique(): self |
|
5994 | |||
5995 | /** |
||
5996 | * Return a duplicate free copy of the current array. (with the old keys) |
||
5997 | * |
||
5998 | * @return $this |
||
5999 | * <p>(Mutable)</p> |
||
6000 | * |
||
6001 | * @psalm-return static<TKey,T> |
||
6002 | */ |
||
6003 | 11 | public function uniqueKeepIndex(): self |
|
6029 | |||
6030 | /** |
||
6031 | * alias: for "Arrayy->unique()" |
||
6032 | * |
||
6033 | * @return static |
||
6034 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
6035 | * |
||
6036 | * @see Arrayy::unique() |
||
6037 | * |
||
6038 | * @psalm-return static<TKey,T> |
||
6039 | */ |
||
6040 | 10 | public function uniqueNewIndex(): self |
|
6044 | |||
6045 | /** |
||
6046 | * Prepends one or more values to the beginning of array at once. |
||
6047 | * |
||
6048 | * @param array ...$args |
||
6049 | * |
||
6050 | * @return $this |
||
6051 | * <p>(Mutable) Return this Arrayy object, with prepended elements to the beginning of array.</p> |
||
6052 | * |
||
6053 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$args |
||
6054 | * @psalm-return static<TKey,T> |
||
6055 | */ |
||
6056 | 4 | public function unshift(...$args): self |
|
6064 | |||
6065 | /** |
||
6066 | * Tests whether the given closure return something valid for all elements of this array. |
||
6067 | * |
||
6068 | * @param \Closure $closure the predicate |
||
6069 | * |
||
6070 | * @return bool |
||
6071 | * <p>TRUE, if the predicate yields TRUE for all elements, FALSE otherwise.</p> |
||
6072 | */ |
||
6073 | 1 | View Code Duplication | public function validate(\Closure $closure): bool |
6083 | |||
6084 | /** |
||
6085 | * Get all values from a array. |
||
6086 | * |
||
6087 | * @return static |
||
6088 | * <p>(Immutable)</p> |
||
6089 | * |
||
6090 | * @psalm-return static<TKey,T> |
||
6091 | * @psalm-mutation-free |
||
6092 | */ |
||
6093 | 2 | public function values(): self |
|
6106 | |||
6107 | /** |
||
6108 | * Apply the given function to every element in the array, discarding the results. |
||
6109 | * |
||
6110 | * @param callable $callable |
||
6111 | * @param bool $recursive [optional] <p>Whether array will be walked recursively or no</p> |
||
6112 | * @param mixed $userData [optional] <p> |
||
6113 | * If the optional $userData parameter is supplied, |
||
6114 | * it will be passed as the third parameter to the $callable. |
||
6115 | * </p> |
||
6116 | * |
||
6117 | * @return $this |
||
6118 | * <p>(Mutable) Return this Arrayy object, with modified elements.</p> |
||
6119 | * |
||
6120 | * @psalm-return static<TKey,T> |
||
6121 | */ |
||
6122 | 12 | public function walk($callable, bool $recursive = false, $userData = self::ARRAYY_HELPER_WALK): self |
|
6144 | |||
6145 | /** |
||
6146 | * Returns a collection of matching items. |
||
6147 | * |
||
6148 | * @param string $keyOrPropertyOrMethod the property or method to evaluate |
||
6149 | * @param mixed $value the value to match |
||
6150 | * |
||
6151 | * @throws \InvalidArgumentException if property or method is not defined |
||
6152 | * |
||
6153 | * @return static |
||
6154 | * |
||
6155 | * @psalm-param T $value |
||
6156 | * @psalm-return static<TKey,T> |
||
6157 | */ |
||
6158 | 1 | public function where(string $keyOrPropertyOrMethod, $value): self |
|
6171 | |||
6172 | /** |
||
6173 | * Convert an array into a object. |
||
6174 | * |
||
6175 | * @param array $array |
||
6176 | * |
||
6177 | * @return \stdClass |
||
6178 | * |
||
6179 | * @psalm-param array<mixed,mixed> $array |
||
6180 | */ |
||
6181 | 4 | final protected static function arrayToObject(array $array = []): \stdClass |
|
6200 | |||
6201 | /** |
||
6202 | * @param array|\Generator|null $input <p> |
||
6203 | * An array containing keys to return. |
||
6204 | * </p> |
||
6205 | * @param mixed|null $search_values [optional] <p> |
||
6206 | * If specified, then only keys containing these values are returned. |
||
6207 | * </p> |
||
6208 | * @param bool $strict [optional] <p> |
||
6209 | * Determines if strict comparison (===) should be used during the |
||
6210 | * search. |
||
6211 | * </p> |
||
6212 | * |
||
6213 | * @return array |
||
6214 | * <p>an array of all the keys in input</p> |
||
6215 | * |
||
6216 | * @psalm-param array<mixed,mixed>|\Generator<TKey,T>|null $input |
||
6217 | * @psalm-return array<TKey|mixed> |
||
6218 | * @psalm-mutation-free |
||
6219 | */ |
||
6220 | 11 | protected function array_keys_recursive( |
|
6281 | |||
6282 | /** |
||
6283 | * @param mixed $path |
||
6284 | * @param callable $callable |
||
6285 | * @param array|null $currentOffset |
||
6286 | * |
||
6287 | * @return void |
||
6288 | * |
||
6289 | * @psalm-param array<mixed,mixed>|array<TKey,T>|null $currentOffset |
||
6290 | * @psalm-mutation-free |
||
6291 | */ |
||
6292 | 10 | protected function callAtPath($path, $callable, &$currentOffset = null) |
|
6321 | |||
6322 | /** |
||
6323 | * Extracts the value of the given property or method from the object. |
||
6324 | * |
||
6325 | * @param static $object <p>The object to extract the value from.</p> |
||
6326 | * @param string $keyOrPropertyOrMethod <p>The property or method for which the |
||
6327 | * value should be extracted.</p> |
||
6328 | * |
||
6329 | * @throws \InvalidArgumentException if the method or property is not defined |
||
6330 | * |
||
6331 | * @return mixed |
||
6332 | * <p>The value extracted from the specified property or method.</p> |
||
6333 | * |
||
6334 | * @psalm-param self<TKey,T> $object |
||
6335 | */ |
||
6336 | 2 | final protected function extractValue(self $object, string $keyOrPropertyOrMethod) |
|
6358 | |||
6359 | /** |
||
6360 | * create a fallback for array |
||
6361 | * |
||
6362 | * 1. use the current array, if it's a array |
||
6363 | * 2. fallback to empty array, if there is nothing |
||
6364 | * 3. call "getArray()" on object, if there is a "Arrayy"-object |
||
6365 | * 4. call "createFromObject()" on object, if there is a "\Traversable"-object |
||
6366 | * 5. call "__toArray()" on object, if the method exists |
||
6367 | * 6. cast a string or object with "__toString()" into an array |
||
6368 | * 7. throw a "InvalidArgumentException"-Exception |
||
6369 | * |
||
6370 | * @param mixed $data |
||
6371 | * |
||
6372 | * @throws \InvalidArgumentException |
||
6373 | * |
||
6374 | * @return array |
||
6375 | * |
||
6376 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
6377 | */ |
||
6378 | 1198 | protected function fallbackForArray(&$data): array |
|
6388 | |||
6389 | /** |
||
6390 | * @param bool $preserveKeys <p> |
||
6391 | * e.g.: A generator maybe return the same key more then once, |
||
6392 | * so maybe you will ignore the keys. |
||
6393 | * </p> |
||
6394 | * |
||
6395 | * @return bool |
||
6396 | * |
||
6397 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
6398 | * @psalm-mutation-free :/ |
||
6399 | */ |
||
6400 | 1110 | protected function generatorToArray(bool $preserveKeys = true) |
|
6411 | |||
6412 | /** |
||
6413 | * Get correct PHP constant for direction. |
||
6414 | * |
||
6415 | * @param int|string $direction |
||
6416 | * |
||
6417 | * @return int |
||
6418 | * @psalm-mutation-free |
||
6419 | */ |
||
6420 | 43 | protected function getDirection($direction): int |
|
6442 | |||
6443 | /** |
||
6444 | * @return TypeCheckInterface[] |
||
6445 | * |
||
6446 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
6447 | */ |
||
6448 | 22 | protected function getPropertiesFromPhpDoc() |
|
6479 | |||
6480 | /** |
||
6481 | * @param mixed $glue |
||
6482 | * @param mixed $pieces |
||
6483 | * @param bool $useKeys |
||
6484 | * |
||
6485 | * @return string |
||
6486 | * @psalm-mutation-free |
||
6487 | */ |
||
6488 | 36 | protected function implode_recursive( |
|
6521 | |||
6522 | /** |
||
6523 | * @param mixed $needle <p> |
||
6524 | * The searched value. |
||
6525 | * </p> |
||
6526 | * <p> |
||
6527 | * If needle is a string, the comparison is done |
||
6528 | * in a case-sensitive manner. |
||
6529 | * </p> |
||
6530 | * @param array|\Generator|null $haystack <p> |
||
6531 | * The array. |
||
6532 | * </p> |
||
6533 | * @param bool $strict [optional] <p> |
||
6534 | * If the third parameter strict is set to true |
||
6535 | * then the in_array function will also check the |
||
6536 | * types of the |
||
6537 | * needle in the haystack. |
||
6538 | * </p> |
||
6539 | * |
||
6540 | * @return bool |
||
6541 | * <p>true if needle is found in the array, false otherwise</p> |
||
6542 | * |
||
6543 | * @psalm-param array<mixed,mixed>|\Generator<TKey,T>|null $haystack |
||
6544 | * @psalm-mutation-free |
||
6545 | */ |
||
6546 | 18 | protected function in_array_recursive($needle, $haystack = null, $strict = true): bool |
|
6571 | |||
6572 | /** |
||
6573 | * @param mixed $data |
||
6574 | * |
||
6575 | * @return array|null |
||
6576 | * |
||
6577 | * @psalm-return array<mixed,mixed>|array<TKey,T>|null |
||
6578 | */ |
||
6579 | 1198 | protected function internalGetArray(&$data) |
|
6630 | |||
6631 | /** |
||
6632 | * Internal mechanics of remove method. |
||
6633 | * |
||
6634 | * @param mixed $key |
||
6635 | * |
||
6636 | * @return bool |
||
6637 | */ |
||
6638 | 21 | protected function internalRemove($key): bool |
|
6671 | |||
6672 | /** |
||
6673 | * Internal mechanic of set method. |
||
6674 | * |
||
6675 | * @param int|string|null $key |
||
6676 | * @param mixed $value |
||
6677 | * @param bool $checkProperties |
||
6678 | * |
||
6679 | * @return bool |
||
6680 | */ |
||
6681 | 1048 | protected function internalSet( |
|
6740 | |||
6741 | /** |
||
6742 | * Convert a object into an array. |
||
6743 | * |
||
6744 | * @param mixed|object $object |
||
6745 | * |
||
6746 | * @return array|mixed |
||
6747 | * |
||
6748 | * @psalm-mutation-free |
||
6749 | */ |
||
6750 | 5 | protected static function objectToArray($object) |
|
6763 | |||
6764 | /** |
||
6765 | * @param array $data |
||
6766 | * @param bool $checkPropertiesInConstructor |
||
6767 | * |
||
6768 | * @return void |
||
6769 | * |
||
6770 | * @psalm-param array<mixed,T> $data |
||
6771 | */ |
||
6772 | 1196 | protected function setInitialValuesAndProperties(array &$data, bool $checkPropertiesInConstructor) |
|
6817 | |||
6818 | /** |
||
6819 | * sorting keys |
||
6820 | * |
||
6821 | * @param array $elements |
||
6822 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
6823 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
6824 | * <strong>SORT_NATURAL</strong></p> |
||
6825 | * |
||
6826 | * @return $this |
||
6827 | * <p>(Mutable) Return this Arrayy object.</p> |
||
6828 | * |
||
6829 | * @psalm-param array<mixed,mixed>|array<mixed|TKey,T> $elements |
||
6830 | * @psalm-return static<TKey,T> |
||
6831 | */ |
||
6832 | 18 | protected function sorterKeys( |
|
6853 | |||
6854 | /** |
||
6855 | * @param array $elements <p>Warning: used as reference</p> |
||
6856 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
6857 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
6858 | * <strong>SORT_NATURAL</strong></p> |
||
6859 | * @param bool $keepKeys |
||
6860 | * |
||
6861 | * @return $this |
||
6862 | * <p>(Mutable) Return this Arrayy object.</p> |
||
6863 | * |
||
6864 | * @psalm-param array<mixed,mixed>|array<mixed|TKey,T> $elements |
||
6865 | * @psalm-return static<TKey,T> |
||
6866 | */ |
||
6867 | 24 | protected function sorting(array &$elements, $direction = \SORT_ASC, int $strategy = \SORT_REGULAR, bool $keepKeys = false): self |
|
6897 | |||
6898 | /** |
||
6899 | * @param array $array |
||
6900 | * |
||
6901 | * @return array |
||
6902 | * |
||
6903 | * @psalm-mutation-free |
||
6904 | */ |
||
6905 | 25 | private function getArrayRecursiveHelperArrayy(array $array) |
|
6927 | |||
6928 | /** |
||
6929 | * @param int|string|null $key |
||
6930 | * @param mixed $value |
||
6931 | * |
||
6932 | * @return void |
||
6933 | */ |
||
6934 | 109 | private function checkType($key, $value) |
|
6952 | } |
||
6953 |
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..