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 |
||
24 | class Arrayy extends \ArrayObject implements \IteratorAggregate, \ArrayAccess, \Serializable, \JsonSerializable, \Countable |
||
25 | { |
||
26 | const ARRAYY_HELPER_TYPES_FOR_ALL_PROPERTIES = '!!!!Arrayy_Helper_Types_For_All_Properties!!!!'; |
||
27 | |||
28 | const ARRAYY_HELPER_WALK = '!!!!Arrayy_Helper_Walk!!!!'; |
||
29 | |||
30 | /** |
||
31 | * @var array |
||
32 | * |
||
33 | * @phpstan-var array<int|string|TKey,T> |
||
34 | */ |
||
35 | protected $array = []; |
||
36 | |||
37 | /** |
||
38 | * @var \Arrayy\ArrayyRewindableGenerator|null |
||
39 | * |
||
40 | * @phpstan-var \Arrayy\ArrayyRewindableGenerator<TKey,T>|null |
||
41 | */ |
||
42 | protected $generator; |
||
43 | |||
44 | /** |
||
45 | * @var string |
||
46 | * |
||
47 | * @phpstan-var class-string<\Arrayy\ArrayyIterator> |
||
48 | */ |
||
49 | protected $iteratorClass = ArrayyIterator::class; |
||
50 | |||
51 | /** |
||
52 | * @var string |
||
53 | */ |
||
54 | protected $pathSeparator = '.'; |
||
55 | |||
56 | /** |
||
57 | * @var bool |
||
58 | */ |
||
59 | protected $checkPropertyTypes = false; |
||
60 | |||
61 | /** |
||
62 | * @var bool |
||
63 | */ |
||
64 | protected $checkForMissingPropertiesInConstructor = false; |
||
65 | |||
66 | /** |
||
67 | * @var bool |
||
68 | */ |
||
69 | protected $checkPropertiesMismatchInConstructor = false; |
||
70 | |||
71 | /** |
||
72 | * @var bool |
||
73 | */ |
||
74 | protected $checkPropertiesMismatch = true; |
||
75 | |||
76 | /** |
||
77 | * @var array<int|string,TypeCheckInterface>|mixed|TypeCheckArray<int|string,TypeCheckInterface>|TypeInterface |
||
78 | */ |
||
79 | protected $properties = []; |
||
80 | |||
81 | /** |
||
82 | * Initializes |
||
83 | * |
||
84 | * @param mixed $data <p> |
||
85 | * Should be an array or a generator, otherwise it will try |
||
86 | * to convert it into an array. |
||
87 | * </p> |
||
88 | * @param string $iteratorClass optional <p> |
||
89 | * You can overwrite the ArrayyIterator, but mostly you don't |
||
90 | * need this option. |
||
91 | * </p> |
||
92 | * @param bool $checkPropertiesInConstructor optional <p> |
||
93 | * You need to extend the "Arrayy"-class and you need to set |
||
94 | * the $checkPropertiesMismatchInConstructor class property |
||
95 | * to |
||
96 | * true, otherwise this option didn't not work anyway. |
||
97 | * </p> |
||
98 | * |
||
99 | * @phpstan-param class-string<\Arrayy\ArrayyIterator> $iteratorClass |
||
100 | */ |
||
101 | 1213 | public function __construct( |
|
102 | $data = [], |
||
103 | string $iteratorClass = ArrayyIterator::class, |
||
104 | bool $checkPropertiesInConstructor = true |
||
105 | ) { |
||
106 | 1213 | $data = $this->fallbackForArray($data); |
|
107 | |||
108 | // used only for serialize + unserialize, all other methods are overwritten |
||
109 | /** |
||
110 | * @psalm-suppress InvalidArgument - why? |
||
111 | */ |
||
112 | 1211 | parent::__construct([], 0, $iteratorClass); |
|
113 | |||
114 | 1211 | $this->setInitialValuesAndProperties($data, $checkPropertiesInConstructor); |
|
115 | |||
116 | 1203 | $this->setIteratorClass($iteratorClass); |
|
117 | 1203 | } |
|
118 | |||
119 | /** |
||
120 | * @return void |
||
121 | */ |
||
122 | 52 | public function __clone() |
|
123 | { |
||
124 | 52 | if (!\is_array($this->properties)) { |
|
125 | $this->properties = clone $this->properties; |
||
|
|||
126 | } |
||
127 | |||
128 | 52 | if ($this->generator !== null) { |
|
129 | $this->generator = clone $this->generator; |
||
130 | } |
||
131 | 52 | } |
|
132 | |||
133 | /** |
||
134 | * Call object as function. |
||
135 | * |
||
136 | * @param mixed $key |
||
137 | * |
||
138 | * @return mixed |
||
139 | */ |
||
140 | 1 | public function __invoke($key = null) |
|
141 | { |
||
142 | 1 | if ($key !== null) { |
|
143 | 1 | $this->generatorToArray(); |
|
144 | |||
145 | 1 | return $this->array[$key] ?? false; |
|
146 | } |
||
147 | |||
148 | return $this->toArray(); |
||
149 | } |
||
150 | |||
151 | /** |
||
152 | * Whether or not an element exists by key. |
||
153 | * |
||
154 | * @param mixed $key |
||
155 | * |
||
156 | * @return bool |
||
157 | * <p>True is the key/index exists, otherwise false.</p> |
||
158 | */ |
||
159 | public function __isset($key): bool |
||
160 | { |
||
161 | return $this->offsetExists($key); |
||
162 | } |
||
163 | |||
164 | /** |
||
165 | * Assigns a value to the specified element. |
||
166 | * |
||
167 | * @param mixed $key |
||
168 | * @param mixed $value |
||
169 | * |
||
170 | * @return void |
||
171 | */ |
||
172 | 3 | public function __set($key, $value) |
|
173 | { |
||
174 | 3 | $this->internalSet($key, $value); |
|
175 | 3 | } |
|
176 | |||
177 | /** |
||
178 | * magic to string |
||
179 | * |
||
180 | * @return string |
||
181 | */ |
||
182 | 15 | public function __toString(): string |
|
183 | { |
||
184 | 15 | return $this->toString(); |
|
185 | } |
||
186 | |||
187 | /** |
||
188 | * Unset element by key. |
||
189 | * |
||
190 | * @param mixed $key |
||
191 | */ |
||
192 | public function __unset($key) |
||
193 | { |
||
194 | $this->internalRemove($key); |
||
195 | } |
||
196 | |||
197 | /** |
||
198 | * Get a value by key. |
||
199 | * |
||
200 | * @param mixed $key |
||
201 | * |
||
202 | * @return mixed |
||
203 | * <p>Get a Value from the current array.</p> |
||
204 | */ |
||
205 | 133 | public function &__get($key) |
|
206 | { |
||
207 | 133 | $return = $this->get($key, null, null, true); |
|
208 | |||
209 | 133 | if (\is_array($return) === true) { |
|
210 | $return = static::create( |
||
211 | [], |
||
212 | $this->iteratorClass, |
||
213 | false |
||
214 | )->createByReference($return); |
||
215 | } |
||
216 | |||
217 | 133 | return $return; |
|
218 | } |
||
219 | |||
220 | /** |
||
221 | * Add new values (optional using dot-notation). |
||
222 | * |
||
223 | * @param mixed $value |
||
224 | * @param int|string|null $key |
||
225 | * |
||
226 | * @return static |
||
227 | * <p>(Immutable) Return this Arrayy object, with the appended values.</p> |
||
228 | * |
||
229 | * @phpstan-param T $value |
||
230 | * @phpstan-return static<TKey,T> |
||
231 | * |
||
232 | * @phpstan-param T $value |
||
233 | * @phpstan-param TKey $key |
||
234 | * @psalm-mutation-free |
||
235 | */ |
||
236 | 13 | public function add($value, $key = null) |
|
237 | { |
||
238 | 13 | if ($key !== null) { |
|
239 | 5 | $get = $this->get($key); |
|
240 | 5 | if ($get !== null) { |
|
241 | 1 | $value = \array_merge_recursive( |
|
242 | 1 | !$get instanceof self ? [$get] : $get->getArray(), |
|
243 | 1 | !\is_array($value) ? [$value] : $value |
|
244 | ); |
||
245 | } |
||
246 | |||
247 | 5 | $this->internalSet($key, $value); |
|
248 | |||
249 | 4 | return $this; |
|
250 | } |
||
251 | |||
252 | 8 | return $this->append($value); |
|
253 | } |
||
254 | |||
255 | /** |
||
256 | * Append a (key) + value to the current array. |
||
257 | * |
||
258 | * EXAMPLE: <code> |
||
259 | * a(['fòô' => 'bàř'])->append('foo'); // Arrayy['fòô' => 'bàř', 0 => 'foo'] |
||
260 | * </code> |
||
261 | * |
||
262 | * @param mixed $value |
||
263 | * @param mixed $key |
||
264 | * |
||
265 | * @return $this |
||
266 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
267 | * |
||
268 | * @phpstan-param T $value |
||
269 | * @phpstan-param TKey|null $key |
||
270 | * @phpstan-return static<TKey,T> |
||
271 | */ |
||
272 | 20 | public function append($value, $key = null): self |
|
273 | { |
||
274 | 20 | $this->generatorToArray(); |
|
275 | |||
276 | 20 | if ($this->properties !== []) { |
|
277 | 6 | $this->checkType($key, $value); |
|
278 | } |
||
279 | |||
280 | 19 | if ($key !== null) { |
|
281 | if ( |
||
282 | 2 | isset($this->array[$key]) |
|
283 | && |
||
284 | 2 | \is_array($this->array[$key]) |
|
285 | ) { |
||
286 | $this->array[$key][] = $value; |
||
287 | } else { |
||
288 | 2 | $this->array[$key] = $value; |
|
289 | } |
||
290 | } else { |
||
291 | 17 | $this->array[] = $value; |
|
292 | } |
||
293 | |||
294 | 19 | return $this; |
|
295 | } |
||
296 | |||
297 | /** |
||
298 | * Append a (key) + value to the current array. |
||
299 | * |
||
300 | * EXAMPLE: <code> |
||
301 | * a(['fòô' => 'bàř'])->appendImmutable('foo')->getArray(); // ['fòô' => 'bàř', 0 => 'foo'] |
||
302 | * </code> |
||
303 | * |
||
304 | * @param mixed $value |
||
305 | * @param mixed $key |
||
306 | * |
||
307 | * @return $this |
||
308 | * <p>(Immutable) Return this Arrayy object, with the appended values.</p> |
||
309 | * |
||
310 | * @phpstan-param T $value |
||
311 | * @phpstan-param TKey $key |
||
312 | * @phpstan-return static<TKey,T> |
||
313 | * @psalm-mutation-free |
||
314 | */ |
||
315 | 1 | View Code Duplication | public function appendImmutable($value, $key = null): self |
316 | { |
||
317 | $generator = function () use ($key, $value): \Generator { |
||
318 | 1 | if ($this->properties !== []) { |
|
319 | $this->checkType($key, $value); |
||
320 | } |
||
321 | |||
322 | /** @noinspection YieldFromCanBeUsedInspection - FP */ |
||
323 | 1 | foreach ($this->getGenerator() as $keyOld => $itemOld) { |
|
324 | 1 | yield $keyOld => $itemOld; |
|
325 | } |
||
326 | |||
327 | 1 | if ($key !== null) { |
|
328 | yield $key => $value; |
||
329 | } else { |
||
330 | 1 | yield $value; |
|
331 | } |
||
332 | 1 | }; |
|
333 | |||
334 | 1 | return static::create( |
|
335 | 1 | $generator, |
|
336 | 1 | $this->iteratorClass, |
|
337 | 1 | false |
|
338 | ); |
||
339 | } |
||
340 | |||
341 | /** |
||
342 | * Sort the entries by value. |
||
343 | * |
||
344 | * @param int $sort_flags [optional] <p> |
||
345 | * You may modify the behavior of the sort using the optional |
||
346 | * parameter sort_flags, for details |
||
347 | * see sort. |
||
348 | * </p> |
||
349 | * |
||
350 | * @return $this |
||
351 | * <p>(Mutable) Return this Arrayy object.</p> |
||
352 | * |
||
353 | * @phpstan-return static<TKey,T> |
||
354 | */ |
||
355 | 4 | public function asort(int $sort_flags = 0): self |
|
356 | { |
||
357 | 4 | $this->generatorToArray(); |
|
358 | |||
359 | 4 | \asort($this->array, $sort_flags); |
|
360 | |||
361 | 4 | return $this; |
|
362 | } |
||
363 | |||
364 | /** |
||
365 | * Sort the entries by value. |
||
366 | * |
||
367 | * @param int $sort_flags [optional] <p> |
||
368 | * You may modify the behavior of the sort using the optional |
||
369 | * parameter sort_flags, for details |
||
370 | * see sort. |
||
371 | * </p> |
||
372 | * |
||
373 | * @return $this |
||
374 | * <p>(Immutable) Return this Arrayy object.</p> |
||
375 | * |
||
376 | * @phpstan-return static<TKey,T> |
||
377 | * @psalm-mutation-free |
||
378 | */ |
||
379 | 4 | public function asortImmutable(int $sort_flags = 0): self |
|
380 | { |
||
381 | 4 | $that = clone $this; |
|
382 | |||
383 | /** |
||
384 | * @psalm-suppress ImpureMethodCall - object is already cloned |
||
385 | */ |
||
386 | 4 | $that->asort($sort_flags); |
|
387 | |||
388 | 4 | return $that; |
|
389 | } |
||
390 | |||
391 | /** |
||
392 | * Counts all elements in an array, or something in an object. |
||
393 | * |
||
394 | * EXAMPLE: <code> |
||
395 | * a([-9, -8, -7, 1.32])->count(); // 4 |
||
396 | * </code> |
||
397 | * |
||
398 | * <p> |
||
399 | * For objects, if you have SPL installed, you can hook into count() by implementing interface {@see Countable}. |
||
400 | * The interface has exactly one method, {@see Countable::count()}, which returns the return value for the count() |
||
401 | * function. Please see the {@see Array} section of the manual for a detailed explanation of how arrays are |
||
402 | * implemented and used in PHP. |
||
403 | * </p> |
||
404 | * |
||
405 | * @see http://php.net/manual/en/function.count.php |
||
406 | * |
||
407 | * @param int $mode [optional] If the optional mode parameter is set to |
||
408 | * COUNT_RECURSIVE (or 1), count |
||
409 | * will recursively count the array. This is particularly useful for |
||
410 | * counting all the elements of a multidimensional array. count does not detect infinite recursion. |
||
411 | * |
||
412 | * @return int |
||
413 | * <p> |
||
414 | * The number of elements in var, which is |
||
415 | * typically an array, since anything else will have one |
||
416 | * element. |
||
417 | * </p> |
||
418 | * <p> |
||
419 | * If var is not an array or an object with |
||
420 | * implemented Countable interface, |
||
421 | * 1 will be returned. |
||
422 | * There is one exception, if var is &null;, |
||
423 | * 0 will be returned. |
||
424 | * </p> |
||
425 | * <p> |
||
426 | * Caution: count may return 0 for a variable that isn't set, |
||
427 | * but it may also return 0 for a variable that has been initialized with an |
||
428 | * empty array. Use isset to test if a variable is set. |
||
429 | * </p> |
||
430 | * @psalm-mutation-free |
||
431 | */ |
||
432 | 147 | public function count(int $mode = \COUNT_NORMAL): int |
|
433 | { |
||
434 | if ( |
||
435 | 147 | $this->generator |
|
436 | && |
||
437 | 147 | $mode === \COUNT_NORMAL |
|
438 | ) { |
||
439 | 4 | return \iterator_count($this->generator); |
|
440 | } |
||
441 | |||
442 | 143 | return \count($this->toArray(), $mode); |
|
443 | } |
||
444 | |||
445 | /** |
||
446 | * Exchange the array for another one. |
||
447 | * |
||
448 | * @param array|mixed|static $data |
||
449 | * |
||
450 | * 1. use the current array, if it's a array |
||
451 | * 2. fallback to empty array, if there is nothing |
||
452 | * 3. call "getArray()" on object, if there is a "Arrayy"-object |
||
453 | * 4. call "createFromObject()" on object, if there is a "\Traversable"-object |
||
454 | * 5. call "__toArray()" on object, if the method exists |
||
455 | * 6. cast a string or object with "__toString()" into an array |
||
456 | * 7. throw a "InvalidArgumentException"-Exception |
||
457 | * |
||
458 | * @return array |
||
459 | * |
||
460 | * @phpstan-param T|array<TKey,T>|self<TKey,T> $data |
||
461 | * @phpstan-return array<TKey,T> |
||
462 | */ |
||
463 | 1 | public function exchangeArray($data): array |
|
464 | { |
||
465 | /** @phpstan-var array<TKey,T> array */ |
||
466 | 1 | $array = $this->fallbackForArray($data); |
|
467 | |||
468 | 1 | $this->array = $array; |
|
469 | 1 | $this->generator = null; |
|
470 | |||
471 | 1 | return $this->array; |
|
472 | } |
||
473 | |||
474 | /** |
||
475 | * Creates a copy of the ArrayyObject. |
||
476 | * |
||
477 | * @return array |
||
478 | * |
||
479 | * @phpstan-return array<int|string|TKey,T> |
||
480 | */ |
||
481 | 6 | public function getArrayCopy(): array |
|
487 | |||
488 | /** |
||
489 | * Returns a new iterator, thus implementing the \Iterator interface. |
||
490 | * |
||
491 | * EXAMPLE: <code> |
||
492 | * a(['foo', 'bar'])->getIterator(); // ArrayyIterator['foo', 'bar'] |
||
493 | * </code> |
||
494 | * |
||
495 | * @return \Iterator<mixed, mixed> |
||
496 | * <p>An iterator for the values in the array.</p> |
||
497 | * @phpstan-return \Iterator<array-key|TKey, mixed|T> |
||
498 | */ |
||
499 | 28 | public function getIterator(): \Iterator |
|
525 | |||
526 | /** |
||
527 | * Gets the iterator classname for the ArrayObject. |
||
528 | * |
||
529 | * @return string |
||
530 | * |
||
531 | * @phpstan-return class-string |
||
532 | */ |
||
533 | 27 | public function getIteratorClass(): string |
|
537 | |||
538 | /** |
||
539 | * Sort the entries by key. |
||
540 | * |
||
541 | * @param int $sort_flags [optional] <p> |
||
542 | * You may modify the behavior of the sort using the optional |
||
543 | * parameter sort_flags, for details |
||
544 | * see sort. |
||
545 | * </p> |
||
546 | * |
||
547 | * @return $this |
||
548 | * <p>(Mutable) Return this Arrayy object.</p> |
||
549 | * |
||
550 | * @phpstan-return static<TKey,T> |
||
551 | */ |
||
552 | 4 | public function ksort(int $sort_flags = 0): self |
|
560 | |||
561 | /** |
||
562 | * Sort the entries by key. |
||
563 | * |
||
564 | * @param int $sort_flags [optional] <p> |
||
565 | * You may modify the behavior of the sort using the optional |
||
566 | * parameter sort_flags, for details |
||
567 | * see sort. |
||
568 | * </p> |
||
569 | * |
||
570 | * @return $this |
||
571 | * <p>(Immutable) Return this Arrayy object.</p> |
||
572 | * |
||
573 | * @phpstan-return static<TKey,T> |
||
574 | */ |
||
575 | 4 | public function ksortImmutable(int $sort_flags = 0): self |
|
586 | |||
587 | /** |
||
588 | * Sort an array using a case insensitive "natural order" algorithm. |
||
589 | * |
||
590 | * @return $this |
||
591 | * <p>(Mutable) Return this Arrayy object.</p> |
||
592 | * |
||
593 | * @phpstan-return static<TKey,T> |
||
594 | */ |
||
595 | 8 | public function natcasesort(): self |
|
603 | |||
604 | /** |
||
605 | * Sort an array using a case insensitive "natural order" algorithm. |
||
606 | * |
||
607 | * @return $this |
||
608 | * <p>(Immutable) Return this Arrayy object.</p> |
||
609 | * |
||
610 | * @phpstan-return static<TKey,T> |
||
611 | * @psalm-mutation-free |
||
612 | */ |
||
613 | 4 | public function natcasesortImmutable(): self |
|
624 | |||
625 | /** |
||
626 | * Sort entries using a "natural order" algorithm. |
||
627 | * |
||
628 | * @return $this |
||
629 | * <p>(Mutable) Return this Arrayy object.</p> |
||
630 | * |
||
631 | * @phpstan-return static<TKey,T> |
||
632 | */ |
||
633 | 10 | public function natsort(): self |
|
641 | |||
642 | /** |
||
643 | * Sort entries using a "natural order" algorithm. |
||
644 | * |
||
645 | * @return $this |
||
646 | * <p>(Immutable) Return this Arrayy object.</p> |
||
647 | * |
||
648 | * @phpstan-return static<TKey,T> |
||
649 | * @psalm-mutation-free |
||
650 | */ |
||
651 | 4 | public function natsortImmutable(): self |
|
662 | |||
663 | /** |
||
664 | * Whether or not an offset exists. |
||
665 | * |
||
666 | * @param bool|int|string $offset |
||
667 | * |
||
668 | * @return bool |
||
669 | * |
||
670 | * @psalm-mutation-free |
||
671 | */ |
||
672 | 164 | public function offsetExists($offset): bool |
|
673 | { |
||
674 | // php cast "bool"-index into "int"-index |
||
675 | 164 | if ((bool) $offset === $offset) { |
|
676 | 1 | $offset = (int) $offset; |
|
677 | } |
||
678 | 164 | \assert(\is_int($offset) || \is_string($offset)); |
|
679 | |||
680 | 164 | $offsetExists = $this->keyExists($offset); |
|
681 | 164 | if ($offsetExists === true) { |
|
682 | 143 | return true; |
|
683 | } |
||
684 | |||
685 | /** |
||
686 | * https://github.com/vimeo/psalm/issues/2536 |
||
687 | * |
||
688 | * @psalm-suppress PossiblyInvalidArgument |
||
689 | * @psalm-suppress InvalidScalarArgument |
||
690 | */ |
||
691 | View Code Duplication | if ( |
|
692 | 124 | $this->pathSeparator |
|
693 | && |
||
694 | 124 | (string) $offset === $offset |
|
695 | && |
||
696 | 124 | \strpos($offset, $this->pathSeparator) !== false |
|
697 | ) { |
||
698 | 4 | $explodedPath = \explode($this->pathSeparator, (string) $offset); |
|
699 | 4 | if ($explodedPath !== false) { |
|
700 | /** @var string $lastOffset - helper for phpstan */ |
||
701 | 4 | $lastOffset = \array_pop($explodedPath); |
|
702 | 4 | $containerPath = \implode($this->pathSeparator, $explodedPath); |
|
703 | |||
704 | /** |
||
705 | * @psalm-suppress MissingClosureReturnType |
||
706 | * @psalm-suppress MissingClosureParamType |
||
707 | */ |
||
708 | 4 | $this->callAtPath( |
|
709 | 4 | $containerPath, |
|
710 | static function ($container) use ($lastOffset, &$offsetExists) { |
||
711 | 4 | $offsetExists = \array_key_exists($lastOffset, $container); |
|
712 | 4 | } |
|
713 | ); |
||
714 | } |
||
715 | } |
||
716 | |||
717 | 124 | return $offsetExists; |
|
718 | } |
||
719 | |||
720 | /** |
||
721 | * Returns the value at specified offset. |
||
722 | * |
||
723 | * @param int|string $offset |
||
724 | * |
||
725 | * @return mixed |
||
726 | * <p>Will return null if the offset did not exists.</p> |
||
727 | */ |
||
728 | 133 | public function &offsetGet($offset) |
|
729 | { |
||
730 | // init |
||
731 | 133 | $value = null; |
|
732 | |||
733 | 133 | if ($this->offsetExists($offset)) { |
|
734 | 131 | $value = &$this->__get($offset); |
|
735 | } |
||
736 | |||
737 | 133 | return $value; |
|
738 | } |
||
739 | |||
740 | /** |
||
741 | * Assigns a value to the specified offset + check the type. |
||
742 | * |
||
743 | * @param int|string|null $offset |
||
744 | * @param mixed $value |
||
745 | * |
||
746 | * @return void |
||
747 | */ |
||
748 | 28 | public function offsetSet($offset, $value) |
|
749 | { |
||
750 | 28 | $this->generatorToArray(); |
|
751 | |||
752 | 28 | if ($offset === null) { |
|
753 | 7 | if ($this->properties !== []) { |
|
754 | 2 | $this->checkType(null, $value); |
|
755 | } |
||
756 | |||
757 | 6 | $this->array[] = $value; |
|
758 | } else { |
||
759 | 21 | $this->internalSet( |
|
760 | 21 | $offset, |
|
761 | 21 | $value, |
|
762 | 21 | true |
|
763 | ); |
||
764 | } |
||
765 | 27 | } |
|
766 | |||
767 | /** |
||
768 | * Unset an offset. |
||
769 | * |
||
770 | * @param int|string $offset |
||
771 | * |
||
772 | * @return void |
||
773 | * <p>(Mutable) Return nothing.</p> |
||
774 | */ |
||
775 | 26 | public function offsetUnset($offset) |
|
776 | { |
||
777 | 26 | $this->generatorToArray(); |
|
778 | |||
779 | 26 | if ($this->array === []) { |
|
780 | 6 | return; |
|
781 | } |
||
782 | |||
783 | 21 | if ($this->keyExists($offset)) { |
|
784 | 14 | unset($this->array[$offset]); |
|
785 | |||
786 | 14 | return; |
|
787 | } |
||
788 | |||
789 | /** |
||
790 | * https://github.com/vimeo/psalm/issues/2536 |
||
791 | * |
||
792 | * @psalm-suppress PossiblyInvalidArgument |
||
793 | * @psalm-suppress InvalidScalarArgument |
||
794 | */ |
||
795 | View Code Duplication | if ( |
|
796 | 10 | $this->pathSeparator |
|
797 | && |
||
798 | 10 | (string) $offset === $offset |
|
799 | && |
||
800 | 10 | \strpos($offset, $this->pathSeparator) !== false |
|
801 | ) { |
||
802 | 7 | $path = \explode($this->pathSeparator, (string) $offset); |
|
803 | |||
804 | 7 | if ($path !== false) { |
|
805 | 7 | $pathToUnset = \array_pop($path); |
|
806 | |||
807 | /** |
||
808 | * @psalm-suppress MissingClosureReturnType |
||
809 | * @psalm-suppress MissingClosureParamType |
||
810 | */ |
||
811 | 7 | $this->callAtPath( |
|
812 | 7 | \implode($this->pathSeparator, $path), |
|
813 | static function (&$offset) use ($pathToUnset) { |
||
814 | 6 | if (\is_array($offset)) { |
|
815 | 5 | unset($offset[$pathToUnset]); |
|
816 | } else { |
||
817 | 1 | $offset = null; |
|
818 | } |
||
819 | 7 | } |
|
820 | ); |
||
821 | } |
||
822 | } |
||
823 | |||
824 | 10 | unset($this->array[$offset]); |
|
825 | 10 | } |
|
826 | |||
827 | /** |
||
828 | * Serialize the current "Arrayy"-object. |
||
829 | * |
||
830 | * EXAMPLE: <code> |
||
831 | * a([1, 4, 7])->serialize(); |
||
832 | * </code> |
||
833 | * |
||
834 | * @return string |
||
835 | */ |
||
836 | 2 | public function serialize(): string |
|
837 | { |
||
838 | 2 | $this->generatorToArray(); |
|
839 | |||
840 | 2 | if (\PHP_VERSION_ID < 70400) { |
|
841 | 2 | return parent::serialize(); |
|
842 | } |
||
843 | |||
844 | return \serialize($this); |
||
845 | } |
||
846 | |||
847 | /** |
||
848 | * Sets the iterator classname for the current "Arrayy"-object. |
||
849 | * |
||
850 | * @param string $iteratorClass |
||
851 | * |
||
852 | * @throws \InvalidArgumentException |
||
853 | * |
||
854 | * @return void |
||
855 | * |
||
856 | * @phpstan-param class-string<\Arrayy\ArrayyIterator> $iteratorClass |
||
857 | */ |
||
858 | 1203 | public function setIteratorClass($iteratorClass) |
|
859 | { |
||
860 | 1203 | if (\class_exists($iteratorClass)) { |
|
861 | 1203 | $this->iteratorClass = $iteratorClass; |
|
862 | |||
863 | 1203 | return; |
|
864 | } |
||
865 | |||
866 | if (\strpos($iteratorClass, '\\') === 0) { |
||
867 | /** @var class-string<\Arrayy\ArrayyIterator<TKey,T>> $iteratorClass */ |
||
868 | $iteratorClass = '\\' . $iteratorClass; |
||
869 | if (\class_exists($iteratorClass)) { |
||
870 | /** |
||
871 | * @psalm-suppress PropertyTypeCoercion |
||
872 | */ |
||
873 | $this->iteratorClass = $iteratorClass; |
||
874 | |||
875 | return; |
||
876 | } |
||
877 | } |
||
878 | |||
879 | throw new \InvalidArgumentException('The iterator class does not exist: ' . $iteratorClass); |
||
880 | } |
||
881 | |||
882 | /** |
||
883 | * Sort the entries with a user-defined comparison function and maintain key association. |
||
884 | * |
||
885 | * @param callable $function |
||
886 | * |
||
887 | * @throws \InvalidArgumentException |
||
888 | * |
||
889 | * @return $this |
||
890 | * <p>(Mutable) Return this Arrayy object.</p> |
||
891 | * |
||
892 | * @phpstan-return static<TKey,T> |
||
893 | */ |
||
894 | 8 | public function uasort($function): self |
|
895 | { |
||
896 | 8 | if (!\is_callable($function)) { |
|
897 | throw new \InvalidArgumentException('Passed function must be callable'); |
||
898 | } |
||
899 | |||
900 | 8 | $this->generatorToArray(); |
|
901 | |||
902 | 8 | \uasort($this->array, $function); |
|
903 | |||
904 | 8 | return $this; |
|
905 | } |
||
906 | |||
907 | /** |
||
908 | * Sort the entries with a user-defined comparison function and maintain key association. |
||
909 | * |
||
910 | * @param callable $function |
||
911 | * |
||
912 | * @throws \InvalidArgumentException |
||
913 | * |
||
914 | * @return $this |
||
915 | * <p>(Immutable) Return this Arrayy object.</p> |
||
916 | * |
||
917 | * @phpstan-return static<TKey,T> |
||
918 | * @psalm-mutation-free |
||
919 | */ |
||
920 | 4 | public function uasortImmutable($function): self |
|
921 | { |
||
922 | 4 | $that = clone $this; |
|
923 | |||
924 | /** |
||
925 | * @psalm-suppress ImpureMethodCall - object is already cloned |
||
926 | */ |
||
927 | 4 | $that->uasort($function); |
|
928 | |||
929 | 4 | return $that; |
|
930 | } |
||
931 | |||
932 | /** |
||
933 | * Sort the entries by keys using a user-defined comparison function. |
||
934 | * |
||
935 | * @param callable $function |
||
936 | * |
||
937 | * @throws \InvalidArgumentException |
||
938 | * |
||
939 | * @return static |
||
940 | * <p>(Mutable) Return this Arrayy object.</p> |
||
941 | * |
||
942 | * @phpstan-return static<TKey,T> |
||
943 | */ |
||
944 | 5 | public function uksort($function): self |
|
945 | { |
||
946 | 5 | return $this->customSortKeys($function); |
|
947 | } |
||
948 | |||
949 | /** |
||
950 | * Sort the entries by keys using a user-defined comparison function. |
||
951 | * |
||
952 | * @param callable $function |
||
953 | * |
||
954 | * @throws \InvalidArgumentException |
||
955 | * |
||
956 | * @return static |
||
957 | * <p>(Immutable) Return this Arrayy object.</p> |
||
958 | * |
||
959 | * @phpstan-return static<TKey,T> |
||
960 | * @psalm-mutation-free |
||
961 | */ |
||
962 | 1 | public function uksortImmutable($function): self |
|
963 | { |
||
964 | 1 | return $this->customSortKeysImmutable($function); |
|
965 | } |
||
966 | |||
967 | /** |
||
968 | * Unserialize an string and return the instance of the "Arrayy"-class. |
||
969 | * |
||
970 | * EXAMPLE: <code> |
||
971 | * $serialized = a([1, 4, 7])->serialize(); |
||
972 | * a()->unserialize($serialized); |
||
973 | * </code> |
||
974 | * |
||
975 | * @param string $string |
||
976 | * |
||
977 | * @return $this |
||
978 | * |
||
979 | * @phpstan-return static<TKey,T> |
||
980 | */ |
||
981 | 2 | public function unserialize($string): self |
|
982 | { |
||
983 | 2 | if (\PHP_VERSION_ID < 70400) { |
|
984 | 2 | parent::unserialize($string); |
|
985 | |||
986 | 2 | return $this; |
|
987 | } |
||
988 | |||
989 | return \unserialize($string, ['allowed_classes' => [__CLASS__, TypeCheckPhpDoc::class]]); |
||
990 | } |
||
991 | |||
992 | /** |
||
993 | * Append a (key) + values to the current array. |
||
994 | * |
||
995 | * EXAMPLE: <code> |
||
996 | * a(['fòô' => ['bàř']])->appendArrayValues(['foo1', 'foo2'], 'fòô'); // Arrayy['fòô' => ['bàř', 'foo1', 'foo2']] |
||
997 | * </code> |
||
998 | * |
||
999 | * @param array $values |
||
1000 | * @param mixed $key |
||
1001 | * |
||
1002 | * @return $this |
||
1003 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
1004 | * |
||
1005 | * @phpstan-param array<array-key,T> $values |
||
1006 | * @phpstan-param TKey|null $key |
||
1007 | * @phpstan-return static<TKey,T> |
||
1008 | */ |
||
1009 | 1 | public function appendArrayValues(array $values, $key = null) |
|
1010 | { |
||
1011 | 1 | $this->generatorToArray(); |
|
1012 | |||
1013 | 1 | if ($key !== null) { |
|
1014 | if ( |
||
1015 | 1 | isset($this->array[$key]) |
|
1016 | && |
||
1017 | 1 | \is_array($this->array[$key]) |
|
1018 | ) { |
||
1019 | 1 | foreach ($values as $value) { |
|
1020 | 1 | $this->array[$key][] = $value; |
|
1021 | } |
||
1022 | } else { |
||
1023 | foreach ($values as $value) { |
||
1024 | 1 | $this->array[$key] = $value; |
|
1025 | } |
||
1026 | } |
||
1027 | } else { |
||
1028 | foreach ($values as $value) { |
||
1029 | $this->array[] = $value; |
||
1030 | } |
||
1031 | } |
||
1032 | |||
1033 | 1 | return $this; |
|
1034 | } |
||
1035 | |||
1036 | /** |
||
1037 | * Add a suffix to each key. |
||
1038 | * |
||
1039 | * @param int|string $prefix |
||
1040 | * |
||
1041 | * @return static |
||
1042 | * <p>(Immutable) Return an Arrayy object, with the prefixed keys.</p> |
||
1043 | * |
||
1044 | * @phpstan-return static<TKey,T> |
||
1045 | * @psalm-mutation-free |
||
1046 | */ |
||
1047 | 10 | View Code Duplication | public function appendToEachKey($prefix): self |
1048 | { |
||
1049 | // init |
||
1050 | 10 | $result = []; |
|
1051 | |||
1052 | 10 | foreach ($this->getGenerator() as $key => $item) { |
|
1053 | 9 | if ($item instanceof self) { |
|
1054 | $result[$prefix . $key] = $item->appendToEachKey($prefix); |
||
1055 | 9 | } elseif (\is_array($item)) { |
|
1056 | $result[$prefix . $key] = self::create($item, $this->iteratorClass, false) |
||
1057 | ->appendToEachKey($prefix) |
||
1058 | ->toArray(); |
||
1059 | } else { |
||
1060 | 9 | $result[$prefix . $key] = $item; |
|
1061 | } |
||
1062 | } |
||
1063 | |||
1064 | 10 | return self::create( |
|
1065 | 10 | $result, |
|
1066 | 10 | $this->iteratorClass, |
|
1067 | 10 | false |
|
1068 | ); |
||
1069 | } |
||
1070 | |||
1071 | /** |
||
1072 | * Add a prefix to each value. |
||
1073 | * |
||
1074 | * @param float|int|string $prefix |
||
1075 | * |
||
1076 | * @return static |
||
1077 | * <p>(Immutable) Return an Arrayy object, with the prefixed values.</p> |
||
1078 | * |
||
1079 | * @phpstan-return static<TKey,T> |
||
1080 | * @psalm-mutation-free |
||
1081 | */ |
||
1082 | 10 | View Code Duplication | public function appendToEachValue($prefix): self |
1083 | { |
||
1084 | // init |
||
1085 | 10 | $result = []; |
|
1086 | |||
1087 | 10 | foreach ($this->getGenerator() as $key => $item) { |
|
1088 | 9 | if ($item instanceof self) { |
|
1089 | $result[$key] = $item->appendToEachValue($prefix); |
||
1090 | 9 | } elseif (\is_array($item)) { |
|
1091 | $result[$key] = self::create($item, $this->iteratorClass, false)->appendToEachValue($prefix)->toArray(); |
||
1092 | 9 | } elseif (\is_object($item) === true) { |
|
1093 | 1 | $result[$key] = $item; |
|
1094 | } else { |
||
1095 | 9 | $result[$key] = $prefix . $item; |
|
1096 | } |
||
1097 | } |
||
1098 | |||
1099 | 10 | return self::create($result, $this->iteratorClass, false); |
|
1100 | } |
||
1101 | |||
1102 | /** |
||
1103 | * Sort an array in reverse order and maintain index association. |
||
1104 | * |
||
1105 | * @return $this |
||
1106 | * <p>(Mutable) Return this Arrayy object.</p> |
||
1107 | * |
||
1108 | * @phpstan-return static<TKey,T> |
||
1109 | */ |
||
1110 | 4 | public function arsort(): self |
|
1111 | { |
||
1112 | 4 | $this->generatorToArray(); |
|
1113 | |||
1114 | 4 | \arsort($this->array); |
|
1115 | |||
1116 | 4 | return $this; |
|
1117 | } |
||
1118 | |||
1119 | /** |
||
1120 | * Sort an array in reverse order and maintain index association. |
||
1121 | * |
||
1122 | * @return $this |
||
1123 | * <p>(Immutable) Return this Arrayy object.</p> |
||
1124 | * |
||
1125 | * @phpstan-return static<TKey,T> |
||
1126 | * @psalm-mutation-free |
||
1127 | */ |
||
1128 | 10 | public function arsortImmutable(): self |
|
1129 | { |
||
1130 | 10 | $that = clone $this; |
|
1131 | |||
1132 | 10 | $that->generatorToArray(); |
|
1133 | |||
1134 | 10 | \arsort($that->array); |
|
1135 | |||
1136 | 10 | return $that; |
|
1137 | } |
||
1138 | |||
1139 | /** |
||
1140 | * Iterate over the current array and execute a callback for each loop. |
||
1141 | * |
||
1142 | * EXAMPLE: <code> |
||
1143 | * $result = A::create(); |
||
1144 | * $closure = function ($value, $key) use ($result) { |
||
1145 | * $result[$key] = ':' . $value . ':'; |
||
1146 | * }; |
||
1147 | * a(['foo', 'bar' => 'bis'])->at($closure); // Arrayy[':foo:', 'bar' => ':bis:'] |
||
1148 | * </code> |
||
1149 | * |
||
1150 | * @param \Closure $closure |
||
1151 | * |
||
1152 | * @return static |
||
1153 | * <p>(Immutable)</p> |
||
1154 | * |
||
1155 | * @phpstan-param \Closure(T=,TKey=):mixed $closure <p>INFO: \Closure result is not used, but void is not supported in PHP 7.0</p> |
||
1156 | * @phpstan-return static<TKey,T> |
||
1157 | * @psalm-mutation-free |
||
1158 | */ |
||
1159 | 3 | public function at(\Closure $closure): self |
|
1173 | |||
1174 | /** |
||
1175 | * Returns the average value of the current array. |
||
1176 | * |
||
1177 | * EXAMPLE: <code> |
||
1178 | * a([-9, -8, -7, 1.32])->average(2); // -5.67 |
||
1179 | * </code> |
||
1180 | * |
||
1181 | * @param int $decimals <p>The number of decimal-numbers to return.</p> |
||
1182 | * |
||
1183 | * @return float|int |
||
1184 | * <p>The average value.</p> |
||
1185 | * @psalm-mutation-free |
||
1186 | */ |
||
1187 | 10 | public function average($decimals = 0) |
|
1201 | |||
1202 | /** |
||
1203 | * Changes all keys in an array. |
||
1204 | * |
||
1205 | * @param int $case [optional] <p> Either <strong>CASE_UPPER</strong><br /> |
||
1206 | * or <strong>CASE_LOWER</strong> (default)</p> |
||
1207 | * |
||
1208 | * @return static |
||
1209 | * <p>(Immutable)</p> |
||
1210 | * |
||
1211 | * @phpstan-return static<TKey,T> |
||
1212 | * @psalm-mutation-free |
||
1213 | */ |
||
1214 | 1 | public function changeKeyCase(int $case = \CASE_LOWER): self |
|
1243 | |||
1244 | /** |
||
1245 | * Change the path separator of the array wrapper. |
||
1246 | * |
||
1247 | * By default, the separator is: "." |
||
1248 | * |
||
1249 | * @param string $separator <p>Separator to set.</p> |
||
1250 | * |
||
1251 | * @return $this |
||
1252 | * <p>(Mutable) Return this Arrayy object.</p> |
||
1253 | * |
||
1254 | * @phpstan-return static<TKey,T> |
||
1255 | */ |
||
1256 | 11 | public function changeSeparator($separator): self |
|
1262 | |||
1263 | /** |
||
1264 | * Create a chunked version of the current array. |
||
1265 | * |
||
1266 | * EXAMPLE: <code> |
||
1267 | * a([-9, -8, -7, 1.32])->chunk(2); // Arrayy[[-9, -8], [-7, 1.32]] |
||
1268 | * </code> |
||
1269 | * |
||
1270 | * @param int $size <p>Size of each chunk.</p> |
||
1271 | * @param bool $preserveKeys <p>Whether array keys are preserved or no.</p> |
||
1272 | * |
||
1273 | * @return static |
||
1274 | * <p>(Immutable) A new array of chunks from the original array.</p> |
||
1275 | * |
||
1276 | * @phpstan-return static<TKey,T> |
||
1277 | * @psalm-mutation-free |
||
1278 | */ |
||
1279 | 5 | public function chunk($size, $preserveKeys = false): self |
|
1329 | |||
1330 | /** |
||
1331 | * Clean all falsy values from the current array. |
||
1332 | * |
||
1333 | * EXAMPLE: <code> |
||
1334 | * a([-8 => -9, 1, 2 => false])->clean(); // Arrayy[-8 => -9, 1] |
||
1335 | * </code> |
||
1336 | * |
||
1337 | * @return static |
||
1338 | * <p>(Immutable)</p> |
||
1339 | * |
||
1340 | * @phpstan-return static<TKey,T> |
||
1341 | * @psalm-mutation-free |
||
1342 | */ |
||
1343 | 8 | public function clean(): self |
|
1351 | |||
1352 | /** |
||
1353 | * WARNING!!! -> Clear the current full array or a $key of it. |
||
1354 | * |
||
1355 | * EXAMPLE: <code> |
||
1356 | * a([-8 => -9, 1, 2 => false])->clear(); // Arrayy[] |
||
1357 | * </code> |
||
1358 | * |
||
1359 | * @param int|int[]|string|string[]|null $key |
||
1360 | * |
||
1361 | * @return $this |
||
1362 | * <p>(Mutable) Return this Arrayy object, with an empty array.</p> |
||
1363 | * |
||
1364 | * @phpstan-return static<TKey,T> |
||
1365 | */ |
||
1366 | 10 | public function clear($key = null): self |
|
1385 | |||
1386 | /** |
||
1387 | * Check if an item is in the current array. |
||
1388 | * |
||
1389 | * EXAMPLE: <code> |
||
1390 | * a([1, true])->contains(true); // true |
||
1391 | * </code> |
||
1392 | * |
||
1393 | * @param float|int|string $value |
||
1394 | * @param bool $recursive |
||
1395 | * @param bool $strict |
||
1396 | * |
||
1397 | * @return bool |
||
1398 | * @psalm-mutation-free |
||
1399 | */ |
||
1400 | 23 | public function contains($value, bool $recursive = false, bool $strict = true): bool |
|
1422 | |||
1423 | /** |
||
1424 | * Check if an (case-insensitive) string is in the current array. |
||
1425 | * |
||
1426 | * EXAMPLE: <code> |
||
1427 | * a(['E', 'é'])->containsCaseInsensitive('É'); // true |
||
1428 | * </code> |
||
1429 | * |
||
1430 | * @param mixed $value |
||
1431 | * @param bool $recursive |
||
1432 | * |
||
1433 | * @return bool |
||
1434 | * @psalm-mutation-free |
||
1435 | * |
||
1436 | * @psalm-suppress InvalidCast - hack for int|float|bool support |
||
1437 | */ |
||
1438 | 26 | public function containsCaseInsensitive($value, $recursive = false): bool |
|
1469 | |||
1470 | /** |
||
1471 | * Check if the given key/index exists in the array. |
||
1472 | * |
||
1473 | * EXAMPLE: <code> |
||
1474 | * a([1 => true])->containsKey(1); // true |
||
1475 | * </code> |
||
1476 | * |
||
1477 | * @param int|string $key <p>key/index to search for</p> |
||
1478 | * |
||
1479 | * @return bool |
||
1480 | * <p>Returns true if the given key/index exists in the array, false otherwise.</p> |
||
1481 | * |
||
1482 | * @psalm-mutation-free |
||
1483 | */ |
||
1484 | 4 | public function containsKey($key): bool |
|
1488 | |||
1489 | /** |
||
1490 | * Check if all given needles are present in the array as key/index. |
||
1491 | * |
||
1492 | * EXAMPLE: <code> |
||
1493 | * a([1 => true])->containsKeys(array(1 => 0)); // true |
||
1494 | * </code> |
||
1495 | * |
||
1496 | * @param array $needles <p>The keys you are searching for.</p> |
||
1497 | * @param bool $recursive |
||
1498 | * |
||
1499 | * @return bool |
||
1500 | * <p>Returns true if all the given keys/indexes exists in the array, false otherwise.</p> |
||
1501 | * |
||
1502 | * @phpstan-param array<array-key>|array<TKey> $needles |
||
1503 | * @psalm-mutation-free |
||
1504 | */ |
||
1505 | 2 | public function containsKeys(array $needles, $recursive = false): bool |
|
1533 | |||
1534 | /** |
||
1535 | * Check if all given needles are present in the array as key/index. |
||
1536 | * |
||
1537 | * @param array $needles <p>The keys you are searching for.</p> |
||
1538 | * |
||
1539 | * @return bool |
||
1540 | * <p>Returns true if all the given keys/indexes exists in the array, false otherwise.</p> |
||
1541 | * |
||
1542 | * @phpstan-param array<array-key>|array<TKey> $needles |
||
1543 | * @psalm-mutation-free |
||
1544 | */ |
||
1545 | 1 | public function containsKeysRecursive(array $needles): bool |
|
1549 | |||
1550 | /** |
||
1551 | * alias: for "Arrayy->contains()" |
||
1552 | * |
||
1553 | * @param float|int|string $value |
||
1554 | * |
||
1555 | * @return bool |
||
1556 | * |
||
1557 | * @see Arrayy::contains() |
||
1558 | * @psalm-mutation-free |
||
1559 | */ |
||
1560 | 9 | public function containsValue($value): bool |
|
1564 | |||
1565 | /** |
||
1566 | * alias: for "Arrayy->contains($value, true)" |
||
1567 | * |
||
1568 | * @param float|int|string $value |
||
1569 | * |
||
1570 | * @return bool |
||
1571 | * |
||
1572 | * @see Arrayy::contains() |
||
1573 | * @psalm-mutation-free |
||
1574 | */ |
||
1575 | 18 | public function containsValueRecursive($value): bool |
|
1579 | |||
1580 | /** |
||
1581 | * Check if all given needles are present in the array. |
||
1582 | * |
||
1583 | * EXAMPLE: <code> |
||
1584 | * a([1, true])->containsValues(array(1, true)); // true |
||
1585 | * </code> |
||
1586 | * |
||
1587 | * @param array $needles |
||
1588 | * |
||
1589 | * @return bool |
||
1590 | * <p>Returns true if all the given values exists in the array, false otherwise.</p> |
||
1591 | * |
||
1592 | * @phpstan-param array<mixed>|array<T> $needles |
||
1593 | * @psalm-mutation-free |
||
1594 | */ |
||
1595 | 1 | public function containsValues(array $needles): bool |
|
1610 | |||
1611 | /** |
||
1612 | * Counts all the values of an array |
||
1613 | * |
||
1614 | * @see http://php.net/manual/en/function.array-count-values.php |
||
1615 | * |
||
1616 | * @return static |
||
1617 | * <p> |
||
1618 | * (Immutable) |
||
1619 | * An associative Arrayy-object of values from input as |
||
1620 | * keys and their count as value. |
||
1621 | * </p> |
||
1622 | * |
||
1623 | * @phpstan-return static<TKey,T> |
||
1624 | * @psalm-mutation-free |
||
1625 | */ |
||
1626 | 7 | public function countValues(): self |
|
1630 | |||
1631 | /** |
||
1632 | * Creates an Arrayy object. |
||
1633 | * |
||
1634 | * @param mixed $data |
||
1635 | * @param string $iteratorClass |
||
1636 | * @param bool $checkPropertiesInConstructor |
||
1637 | * |
||
1638 | * @return static |
||
1639 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1640 | * |
||
1641 | * @phpstan-param array<array-key,T>|\Traversable<array-key,T>|callable():\Generator<TKey,T>|(T&\Traversable) $data |
||
1642 | * @phpstan-param class-string<\Arrayy\ArrayyIterator> $iteratorClass |
||
1643 | * @phpstan-return static<TKey,T> |
||
1644 | * @psalm-mutation-free |
||
1645 | */ |
||
1646 | 731 | public static function create( |
|
1657 | |||
1658 | /** |
||
1659 | * Flatten an array with the given character as a key delimiter. |
||
1660 | * |
||
1661 | * EXAMPLE: <code> |
||
1662 | * $dot = a(['foo' => ['abc' => 'xyz', 'bar' => ['baz']]]); |
||
1663 | * $flatten = $dot->flatten(); |
||
1664 | * $flatten['foo.abc']; // 'xyz' |
||
1665 | * $flatten['foo.bar.0']; // 'baz' |
||
1666 | * </code> |
||
1667 | * |
||
1668 | * @param string $delimiter |
||
1669 | * @param string $prepend |
||
1670 | * @param array|null $items |
||
1671 | * |
||
1672 | * @return array |
||
1673 | */ |
||
1674 | 2 | public function flatten($delimiter = '.', $prepend = '', $items = null) |
|
1697 | |||
1698 | /** |
||
1699 | * WARNING: Creates an Arrayy object by reference. |
||
1700 | * |
||
1701 | * @param array $array |
||
1702 | * |
||
1703 | * @return $this |
||
1704 | * <p>(Mutable) Return this Arrayy object.</p> |
||
1705 | * |
||
1706 | * @phpstan-param array<TKey,T> $array |
||
1707 | * @phpstan-return $this<TKey,T> |
||
1708 | * |
||
1709 | * @internal this will not check any types because it's set directly as reference |
||
1710 | */ |
||
1711 | 26 | public function createByReference(array &$array = []): self |
|
1718 | |||
1719 | /** |
||
1720 | * Create an new instance from a callable function which will return an Generator. |
||
1721 | * |
||
1722 | * @param callable $generatorFunction |
||
1723 | * |
||
1724 | * @return static |
||
1725 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1726 | * |
||
1727 | * @phpstan-param callable():\Generator<TKey,T> $generatorFunction |
||
1728 | * @phpstan-return static<TKey,T> |
||
1729 | * @psalm-mutation-free |
||
1730 | */ |
||
1731 | 7 | public static function createFromGeneratorFunction(callable $generatorFunction): self |
|
1735 | |||
1736 | /** |
||
1737 | * Create an new instance filled with a copy of values from a "Generator"-object. |
||
1738 | * |
||
1739 | * @param \Generator $generator |
||
1740 | * |
||
1741 | * @return static |
||
1742 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1743 | * |
||
1744 | * @phpstan-param \Generator<TKey,T> $generator |
||
1745 | * @phpstan-return static<TKey,T> |
||
1746 | * @psalm-mutation-free |
||
1747 | */ |
||
1748 | 4 | public static function createFromGeneratorImmutable(\Generator $generator): self |
|
1752 | |||
1753 | /** |
||
1754 | * Create an new Arrayy object via JSON. |
||
1755 | * |
||
1756 | * @param string $json |
||
1757 | * |
||
1758 | * @return static |
||
1759 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1760 | * |
||
1761 | * @phpstan-return static<int|string,mixed> |
||
1762 | * @psalm-mutation-free |
||
1763 | */ |
||
1764 | 5 | public static function createFromJson(string $json): self |
|
1768 | |||
1769 | /** |
||
1770 | * Create an new Arrayy object via JSON. |
||
1771 | * |
||
1772 | * @param array $array |
||
1773 | * |
||
1774 | * @return static |
||
1775 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1776 | * |
||
1777 | * @phpstan-param array<TKey,T> $array |
||
1778 | * @phpstan-return static<TKey,T> |
||
1779 | * @psalm-mutation-free |
||
1780 | */ |
||
1781 | 1 | public static function createFromArray(array $array): self |
|
1785 | |||
1786 | /** |
||
1787 | * Create an new instance filled with values from an object that is iterable. |
||
1788 | * |
||
1789 | * @param \Traversable $object <p>iterable object</p> |
||
1790 | * |
||
1791 | * @return static |
||
1792 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1793 | * |
||
1794 | * @phpstan-param \Traversable<array-key,T> $object |
||
1795 | * @phpstan-return static<array-key,T> |
||
1796 | * @psalm-mutation-free |
||
1797 | */ |
||
1798 | 4 | public static function createFromObject(\Traversable $object): self |
|
1818 | |||
1819 | /** |
||
1820 | * Create an new instance filled with values from an object. |
||
1821 | * |
||
1822 | * @param object $object |
||
1823 | * |
||
1824 | * @return static |
||
1825 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1826 | * |
||
1827 | * @phpstan-return static<array-key,mixed> |
||
1828 | * @psalm-mutation-free |
||
1829 | */ |
||
1830 | 5 | public static function createFromObjectVars($object): self |
|
1834 | |||
1835 | /** |
||
1836 | * Create an new Arrayy object via string. |
||
1837 | * |
||
1838 | * @param string $str <p>The input string.</p> |
||
1839 | * @param string|null $delimiter <p>The boundary string.</p> |
||
1840 | * @param string|null $regEx <p>Use the $delimiter or the $regEx, so if $pattern is null, $delimiter will be |
||
1841 | * used.</p> |
||
1842 | * |
||
1843 | * @return static |
||
1844 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1845 | * |
||
1846 | * @phpstan-return static<int,string> |
||
1847 | * @psalm-mutation-free |
||
1848 | */ |
||
1849 | 10 | public static function createFromString(string $str, string $delimiter = null, string $regEx = null): self |
|
1881 | |||
1882 | /** |
||
1883 | * Create an new instance filled with a copy of values from a "Traversable"-object. |
||
1884 | * |
||
1885 | * @param \Traversable $traversable |
||
1886 | * @param bool $use_keys [optional] <p> |
||
1887 | * Whether to use the iterator element keys as index. |
||
1888 | * </p> |
||
1889 | * |
||
1890 | * @return static |
||
1891 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1892 | * |
||
1893 | * @phpstan-param \Traversable<array-key|TKey,T> $traversable |
||
1894 | * @phpstan-return static<int|TKey,T> |
||
1895 | * @psalm-mutation-free |
||
1896 | */ |
||
1897 | 1 | public static function createFromTraversableImmutable(\Traversable $traversable, bool $use_keys = true): self |
|
1901 | |||
1902 | /** |
||
1903 | * Create an new instance containing a range of elements. |
||
1904 | * |
||
1905 | * @param float|int|string $low <p>First value of the sequence.</p> |
||
1906 | * @param float|int|string $high <p>The sequence is ended upon reaching the end value.</p> |
||
1907 | * @param float|int $step <p>Used as the increment between elements in the sequence.</p> |
||
1908 | * |
||
1909 | * @return static |
||
1910 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
1911 | * |
||
1912 | * @phpstan-return static<int,int|string> |
||
1913 | * @psalm-mutation-free |
||
1914 | */ |
||
1915 | 2 | public static function createWithRange($low, $high, $step = 1): self |
|
1919 | |||
1920 | /** |
||
1921 | * Gets the element of the array at the current internal iterator position. |
||
1922 | * |
||
1923 | * @return false|mixed |
||
1924 | * |
||
1925 | * @phpstan-return false|T |
||
1926 | */ |
||
1927 | public function current() |
||
1935 | |||
1936 | /** |
||
1937 | * Custom sort by index via "uksort". |
||
1938 | * |
||
1939 | * EXAMPLE: <code> |
||
1940 | * $callable = function ($a, $b) { |
||
1941 | * if ($a == $b) { |
||
1942 | * return 0; |
||
1943 | * } |
||
1944 | * return ($a > $b) ? 1 : -1; |
||
1945 | * }; |
||
1946 | * $arrayy = a(['three' => 3, 'one' => 1, 'two' => 2]); |
||
1947 | * $resultArrayy = $arrayy->customSortKeys($callable); // Arrayy['one' => 1, 'three' => 3, 'two' => 2] |
||
1948 | * </code> |
||
1949 | * |
||
1950 | * @see http://php.net/manual/en/function.uksort.php |
||
1951 | * |
||
1952 | * @param callable $function |
||
1953 | * |
||
1954 | * @throws \InvalidArgumentException |
||
1955 | * |
||
1956 | * @return $this |
||
1957 | * <p>(Mutable) Return this Arrayy object.</p> |
||
1958 | * |
||
1959 | * @phpstan-return static<TKey,T> |
||
1960 | */ |
||
1961 | 5 | public function customSortKeys(callable $function): self |
|
1969 | |||
1970 | /** |
||
1971 | * Custom sort by index via "uksort". |
||
1972 | * |
||
1973 | * @see http://php.net/manual/en/function.uksort.php |
||
1974 | * |
||
1975 | * @param callable $function |
||
1976 | * |
||
1977 | * @throws \InvalidArgumentException |
||
1978 | * |
||
1979 | * @return $this |
||
1980 | * <p>(Immutable) Return this Arrayy object.</p> |
||
1981 | * |
||
1982 | * @phpstan-return static<TKey,T> |
||
1983 | * @psalm-mutation-free |
||
1984 | */ |
||
1985 | 1 | public function customSortKeysImmutable(callable $function): self |
|
1998 | |||
1999 | /** |
||
2000 | * Custom sort by value via "usort". |
||
2001 | * |
||
2002 | * EXAMPLE: <code> |
||
2003 | * $callable = function ($a, $b) { |
||
2004 | * if ($a == $b) { |
||
2005 | * return 0; |
||
2006 | * } |
||
2007 | * return ($a > $b) ? 1 : -1; |
||
2008 | * }; |
||
2009 | * $arrayy = a(['three' => 3, 'one' => 1, 'two' => 2]); |
||
2010 | * $resultArrayy = $arrayy->customSortValues($callable); // Arrayy['one' => 1, 'two' => 2, 'three' => 3] |
||
2011 | * </code> |
||
2012 | * |
||
2013 | * @see http://php.net/manual/en/function.usort.php |
||
2014 | * |
||
2015 | * @param callable $function |
||
2016 | * |
||
2017 | * @return $this |
||
2018 | * <p>(Mutable) Return this Arrayy object.</p> |
||
2019 | * |
||
2020 | * @phpstan-return static<TKey,T> |
||
2021 | */ |
||
2022 | 10 | public function customSortValues(callable $function): self |
|
2023 | { |
||
2024 | 10 | $this->generatorToArray(); |
|
2025 | |||
2026 | 10 | \usort($this->array, $function); |
|
2027 | |||
2028 | 10 | return $this; |
|
2029 | } |
||
2030 | |||
2031 | /** |
||
2032 | * Custom sort by value via "usort". |
||
2033 | * |
||
2034 | * @see http://php.net/manual/en/function.usort.php |
||
2035 | * |
||
2036 | * @param callable $function |
||
2037 | * |
||
2038 | * @throws \InvalidArgumentException |
||
2039 | * |
||
2040 | * @return $this |
||
2041 | * <p>(Immutable) Return this Arrayy object.</p> |
||
2042 | * |
||
2043 | * @phpstan-return static<TKey,T> |
||
2044 | * @psalm-mutation-free |
||
2045 | */ |
||
2046 | 4 | public function customSortValuesImmutable($function): self |
|
2057 | |||
2058 | /** |
||
2059 | * Delete the given key or keys. |
||
2060 | * |
||
2061 | * @param int|int[]|string|string[] $keyOrKeys |
||
2062 | * |
||
2063 | * @return void |
||
2064 | */ |
||
2065 | 9 | public function delete($keyOrKeys) |
|
2073 | |||
2074 | /** |
||
2075 | * Return elements where the values that are only in the current array. |
||
2076 | * |
||
2077 | * EXAMPLE: <code> |
||
2078 | * a([1 => 1, 2 => 2])->diff([1 => 1]); // Arrayy[2 => 2] |
||
2079 | * </code> |
||
2080 | * |
||
2081 | * @param array ...$array |
||
2082 | * |
||
2083 | * @return static |
||
2084 | * <p>(Immutable)</p> |
||
2085 | * |
||
2086 | * @phpstan-param array<TKey,T> ...$array |
||
2087 | * @phpstan-return static<TKey,T> |
||
2088 | * @psalm-mutation-free |
||
2089 | */ |
||
2090 | 13 | View Code Duplication | public function diff(array ...$array): self |
2112 | |||
2113 | /** |
||
2114 | * Return elements where the keys are only in the current array. |
||
2115 | * |
||
2116 | * @param array ...$array |
||
2117 | * |
||
2118 | * @return static |
||
2119 | * <p>(Immutable)</p> |
||
2120 | * |
||
2121 | * @phpstan-param array<TKey,T> ...$array |
||
2122 | * @phpstan-return static<TKey,T> |
||
2123 | * @psalm-mutation-free |
||
2124 | */ |
||
2125 | 9 | View Code Duplication | public function diffKey(array ...$array): self |
2147 | |||
2148 | /** |
||
2149 | * Return elements where the values and keys are only in the current array. |
||
2150 | * |
||
2151 | * @param array ...$array |
||
2152 | * |
||
2153 | * @return static |
||
2154 | * <p>(Immutable)</p> |
||
2155 | * |
||
2156 | * @phpstan-param array<TKey,T> $array |
||
2157 | * @phpstan-return static<TKey,T> |
||
2158 | * @psalm-mutation-free |
||
2159 | */ |
||
2160 | 9 | public function diffKeyAndValue(array ...$array): self |
|
2188 | |||
2189 | /** |
||
2190 | * Return elements where the values are only in the current multi-dimensional array. |
||
2191 | * |
||
2192 | * EXAMPLE: <code> |
||
2193 | * a([1 => [1 => 1], 2 => [2 => 2]])->diffRecursive([1 => [1 => 1]]); // Arrayy[2 => [2 => 2]] |
||
2194 | * </code> |
||
2195 | * |
||
2196 | * @param array $array |
||
2197 | * @param array|\Generator|null $helperVariableForRecursion <p>(only for internal usage)</p> |
||
2198 | * |
||
2199 | * @return static |
||
2200 | * <p>(Immutable)</p> |
||
2201 | * |
||
2202 | * @phpstan-param array<TKey,T> $array |
||
2203 | * @phpstan-param null|array<TKey,T>|\Generator<TKey,T> $helperVariableForRecursion |
||
2204 | * @phpstan-return static<TKey,T> |
||
2205 | * @psalm-mutation-free |
||
2206 | */ |
||
2207 | 1 | public function diffRecursive(array $array = [], $helperVariableForRecursion = null): self |
|
2242 | |||
2243 | /** |
||
2244 | * Return elements where the values that are only in the new $array. |
||
2245 | * |
||
2246 | * EXAMPLE: <code> |
||
2247 | * a([1 => 1])->diffReverse([1 => 1, 2 => 2]); // Arrayy[2 => 2] |
||
2248 | * </code> |
||
2249 | * |
||
2250 | * @param array $array |
||
2251 | * |
||
2252 | * @return static |
||
2253 | * <p>(Immutable)</p> |
||
2254 | * |
||
2255 | * @phpstan-param array<TKey,T> $array |
||
2256 | * @phpstan-return static<TKey,T> |
||
2257 | * @psalm-mutation-free |
||
2258 | */ |
||
2259 | 8 | public function diffReverse(array $array = []): self |
|
2267 | |||
2268 | /** |
||
2269 | * Divide an array into two arrays. One with keys and the other with values. |
||
2270 | * |
||
2271 | * EXAMPLE: <code> |
||
2272 | * a(['a' => 1, 'b' => ''])->divide(); // Arrayy[Arrayy['a', 'b'], Arrayy[1, '']] |
||
2273 | * </code> |
||
2274 | * |
||
2275 | * @return static |
||
2276 | * <p>(Immutable)</p> |
||
2277 | * |
||
2278 | * @phpstan-return static<TKey,T> |
||
2279 | * @psalm-mutation-free |
||
2280 | */ |
||
2281 | 1 | public function divide(): self |
|
2292 | |||
2293 | /** |
||
2294 | * Iterate over the current array and modify the array's value. |
||
2295 | * |
||
2296 | * EXAMPLE: <code> |
||
2297 | * $result = A::create(); |
||
2298 | * $closure = function ($value) { |
||
2299 | * return ':' . $value . ':'; |
||
2300 | * }; |
||
2301 | * a(['foo', 'bar' => 'bis'])->each($closure); // Arrayy[':foo:', 'bar' => ':bis:'] |
||
2302 | * </code> |
||
2303 | * |
||
2304 | * @param \Closure $closure |
||
2305 | * |
||
2306 | * @return static |
||
2307 | * <p>(Immutable)</p> |
||
2308 | * |
||
2309 | * @phpstan-param \Closure(T=):T|\Closure(T=,TKey=):T $closure |
||
2310 | * @phpstan-return static<TKey,T> |
||
2311 | * @psalm-mutation-free |
||
2312 | */ |
||
2313 | 5 | View Code Duplication | public function each(\Closure $closure): self |
2328 | |||
2329 | /** |
||
2330 | * Sets the internal iterator to the last element in the array and returns this element. |
||
2331 | * |
||
2332 | * @return false|mixed |
||
2333 | * |
||
2334 | * @phpstan-return T|false |
||
2335 | */ |
||
2336 | public function end() |
||
2354 | |||
2355 | /** |
||
2356 | * Check if a value is in the current array using a closure. |
||
2357 | * |
||
2358 | * EXAMPLE: <code> |
||
2359 | * $callable = function ($value, $key) { |
||
2360 | * return 2 === $key and 'two' === $value; |
||
2361 | * }; |
||
2362 | * a(['foo', 2 => 'two'])->exists($callable); // true |
||
2363 | * </code> |
||
2364 | * |
||
2365 | * @param \Closure $closure |
||
2366 | * |
||
2367 | * @return bool |
||
2368 | * <p>Returns true if the given value is found, false otherwise.</p> |
||
2369 | * |
||
2370 | * @phpstan-param \Closure(T=,TKey=):bool $closure |
||
2371 | */ |
||
2372 | 4 | public function exists(\Closure $closure): bool |
|
2387 | |||
2388 | /** |
||
2389 | * Fill the array until "$num" with "$default" values. |
||
2390 | * |
||
2391 | * EXAMPLE: <code> |
||
2392 | * a(['bar'])->fillWithDefaults(3, 'foo'); // Arrayy['bar', 'foo', 'foo'] |
||
2393 | * </code> |
||
2394 | * |
||
2395 | * @param int $num |
||
2396 | * @param mixed $default |
||
2397 | * |
||
2398 | * @return static |
||
2399 | * <p>(Immutable)</p> |
||
2400 | * |
||
2401 | * @phpstan-param T $default |
||
2402 | * @phpstan-return static<TKey,T> |
||
2403 | * @psalm-mutation-free |
||
2404 | */ |
||
2405 | 8 | public function fillWithDefaults(int $num, $default = null): self |
|
2428 | |||
2429 | /** |
||
2430 | * Find all items in an array that pass the truth test. |
||
2431 | * |
||
2432 | * EXAMPLE: <code> |
||
2433 | * $closure = function ($value) { |
||
2434 | * return $value % 2 !== 0; |
||
2435 | * } |
||
2436 | * a([1, 2, 3, 4])->filter($closure); // Arrayy[0 => 1, 2 => 3] |
||
2437 | * </code> |
||
2438 | * |
||
2439 | * @param \Closure|null $closure [optional] <p> |
||
2440 | * The callback function to use |
||
2441 | * </p> |
||
2442 | * <p> |
||
2443 | * If no callback is supplied, all entries of |
||
2444 | * input equal to false (see |
||
2445 | * converting to |
||
2446 | * boolean) will be removed. |
||
2447 | * </p> |
||
2448 | * @param int $flag [optional] <p> |
||
2449 | * Flag determining what arguments are sent to <i>callback</i>: |
||
2450 | * </p> |
||
2451 | * <ul> |
||
2452 | * <li> |
||
2453 | * <b>ARRAY_FILTER_USE_KEY</b> (1) - pass key as the only argument |
||
2454 | * to <i>callback</i> instead of the value |
||
2455 | * </li> |
||
2456 | * <li> |
||
2457 | * <b>ARRAY_FILTER_USE_BOTH</b> (2) - pass both value and key as |
||
2458 | * arguments to <i>callback</i> instead of the value |
||
2459 | * </li> |
||
2460 | * </ul> |
||
2461 | * |
||
2462 | * @return static |
||
2463 | * <p>(Immutable)</p> |
||
2464 | * |
||
2465 | * @phpstan-param null|(\Closure(T=,TKey=):bool)|(\Closure(T=):bool)|(\Closure(TKey=):bool) $closure |
||
2466 | * @phpstan-return static<TKey,T> |
||
2467 | * @psalm-mutation-free |
||
2468 | */ |
||
2469 | 12 | public function filter($closure = null, int $flag = \ARRAY_FILTER_USE_BOTH) |
|
2511 | |||
2512 | /** |
||
2513 | * Filters an array of objects (or a numeric array of associative arrays) based on the value of a particular |
||
2514 | * property within that. |
||
2515 | * |
||
2516 | * @param string $property |
||
2517 | * @param mixed $value |
||
2518 | * @param string|null $comparisonOp |
||
2519 | * <p> |
||
2520 | * 'eq' (equals),<br /> |
||
2521 | * 'gt' (greater),<br /> |
||
2522 | * 'gte' || 'ge' (greater or equals),<br /> |
||
2523 | * 'lt' (less),<br /> |
||
2524 | * 'lte' || 'le' (less or equals),<br /> |
||
2525 | * 'ne' (not equals),<br /> |
||
2526 | * 'contains',<br /> |
||
2527 | * 'notContains',<br /> |
||
2528 | * 'newer' (via strtotime),<br /> |
||
2529 | * 'older' (via strtotime),<br /> |
||
2530 | * </p> |
||
2531 | * |
||
2532 | * @return static |
||
2533 | * <p>(Immutable)</p> |
||
2534 | * |
||
2535 | * @phpstan-param mixed|T $value |
||
2536 | * @phpstan-return static<TKey,T> |
||
2537 | * @psalm-mutation-free |
||
2538 | * |
||
2539 | * @psalm-suppress MissingClosureReturnType |
||
2540 | * @psalm-suppress MissingClosureParamType |
||
2541 | */ |
||
2542 | 1 | public function filterBy( |
|
2614 | |||
2615 | /** |
||
2616 | * Find the first item in an array that passes the truth test, otherwise return false. |
||
2617 | * |
||
2618 | * EXAMPLE: <code> |
||
2619 | * $search = 'foo'; |
||
2620 | * $closure = function ($value, $key) use ($search) { |
||
2621 | * return $value === $search; |
||
2622 | * }; |
||
2623 | * a(['foo', 'bar', 'lall'])->find($closure); // 'foo' |
||
2624 | * </code> |
||
2625 | * |
||
2626 | * @param \Closure $closure |
||
2627 | * |
||
2628 | * @return false|mixed |
||
2629 | * <p>Return false if we did not find the value.</p> |
||
2630 | * |
||
2631 | * @phpstan-param \Closure(T=,TKey=):bool $closure |
||
2632 | * @phpstan-return T|false |
||
2633 | */ |
||
2634 | 8 | View Code Duplication | public function find(\Closure $closure) |
2644 | |||
2645 | /** |
||
2646 | * find by ... |
||
2647 | * |
||
2648 | * EXAMPLE: <code> |
||
2649 | * $array = [ |
||
2650 | * 0 => ['id' => 123, 'name' => 'foo', 'group' => 'primary', 'value' => 123456, 'when' => '2014-01-01'], |
||
2651 | * 1 => ['id' => 456, 'name' => 'bar', 'group' => 'primary', 'value' => 1468, 'when' => '2014-07-15'], |
||
2652 | * ]; |
||
2653 | * a($array)->filterBy('name', 'foo'); // Arrayy[0 => ['id' => 123, 'name' => 'foo', 'group' => 'primary', 'value' => 123456, 'when' => '2014-01-01']] |
||
2654 | * </code> |
||
2655 | * |
||
2656 | * @param string $property |
||
2657 | * @param mixed $value |
||
2658 | * @param string $comparisonOp |
||
2659 | * |
||
2660 | * @return static |
||
2661 | * <p>(Immutable)</p> |
||
2662 | * |
||
2663 | * @phpstan-param mixed|T $value |
||
2664 | * @phpstan-return static<TKey,T> |
||
2665 | * @psalm-mutation-free |
||
2666 | */ |
||
2667 | 1 | public function findBy(string $property, $value, string $comparisonOp = 'eq'): self |
|
2671 | |||
2672 | /** |
||
2673 | * Get the first value from the current array. |
||
2674 | * |
||
2675 | * EXAMPLE: <code> |
||
2676 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->first(); // 'foo' |
||
2677 | * </code> |
||
2678 | * |
||
2679 | * @return mixed|null |
||
2680 | * <p>Return null if there wasn't a element.</p> |
||
2681 | * |
||
2682 | * @phpstan-return T|null |
||
2683 | * @psalm-mutation-free |
||
2684 | */ |
||
2685 | 22 | public function first() |
|
2694 | |||
2695 | /** |
||
2696 | * Get the first key from the current array. |
||
2697 | * |
||
2698 | * @return mixed|null |
||
2699 | * <p>Return null if there wasn't a element.</p> |
||
2700 | * |
||
2701 | * @psalm-mutation-free |
||
2702 | */ |
||
2703 | 29 | public function firstKey() |
|
2709 | |||
2710 | /** |
||
2711 | * Get the first value(s) from the current array. |
||
2712 | * And will return an empty array if there was no first entry. |
||
2713 | * |
||
2714 | * EXAMPLE: <code> |
||
2715 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->firstsImmutable(2); // Arrayy[0 => 'foo', 1 => 'bar'] |
||
2716 | * </code> |
||
2717 | * |
||
2718 | * @param int|null $number <p>How many values you will take?</p> |
||
2719 | * |
||
2720 | * @return static |
||
2721 | * <p>(Immutable)</p> |
||
2722 | * |
||
2723 | * @phpstan-return static<TKey,T> |
||
2724 | * @psalm-mutation-free |
||
2725 | */ |
||
2726 | 37 | public function firstsImmutable(int $number = null): self |
|
2742 | |||
2743 | /** |
||
2744 | * Get the first value(s) from the current array. |
||
2745 | * And will return an empty array if there was no first entry. |
||
2746 | * |
||
2747 | * @param int|null $number <p>How many values you will take?</p> |
||
2748 | * |
||
2749 | * @return static |
||
2750 | * <p>(Immutable)</p> |
||
2751 | * |
||
2752 | * @phpstan-return static<TKey,T> |
||
2753 | * @psalm-mutation-free |
||
2754 | */ |
||
2755 | 3 | View Code Duplication | public function firstsKeys(int $number = null): self |
2771 | |||
2772 | /** |
||
2773 | * Get and remove the first value(s) from the current array. |
||
2774 | * And will return an empty array if there was no first entry. |
||
2775 | * |
||
2776 | * EXAMPLE: <code> |
||
2777 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->firstsMutable(); // 'foo' |
||
2778 | * </code> |
||
2779 | * |
||
2780 | * @param int|null $number <p>How many values you will take?</p> |
||
2781 | * |
||
2782 | * @return $this |
||
2783 | * <p>(Mutable)</p> |
||
2784 | * |
||
2785 | * @phpstan-return static<TKey,T> |
||
2786 | */ |
||
2787 | 34 | public function firstsMutable(int $number = null): self |
|
2799 | |||
2800 | /** |
||
2801 | * Exchanges all keys with their associated values in an array. |
||
2802 | * |
||
2803 | * EXAMPLE: <code> |
||
2804 | * a([0 => 'foo', 1 => 'bar'])->flip(); // Arrayy['foo' => 0, 'bar' => 1] |
||
2805 | * </code> |
||
2806 | * |
||
2807 | * @return static |
||
2808 | * <p>(Immutable)</p> |
||
2809 | * |
||
2810 | * @phpstan-return static<array-key,TKey> |
||
2811 | * @psalm-mutation-free |
||
2812 | */ |
||
2813 | 1 | public function flip(): self |
|
2827 | |||
2828 | /** |
||
2829 | * Get a value from an array (optional using dot-notation). |
||
2830 | * |
||
2831 | * EXAMPLE: <code> |
||
2832 | * $arrayy = a(['user' => ['lastname' => 'Moelleken']]); |
||
2833 | * $arrayy->get('user.lastname'); // 'Moelleken' |
||
2834 | * // --- |
||
2835 | * $arrayy = new A(); |
||
2836 | * $arrayy['user'] = ['lastname' => 'Moelleken']; |
||
2837 | * $arrayy['user.firstname'] = 'Lars'; |
||
2838 | * $arrayy['user']['lastname']; // Moelleken |
||
2839 | * $arrayy['user.lastname']; // Moelleken |
||
2840 | * $arrayy['user.firstname']; // Lars |
||
2841 | * </code> |
||
2842 | * |
||
2843 | * @param int|string $key <p>The key to look for.</p> |
||
2844 | * @param mixed $fallback <p>Value to fallback to.</p> |
||
2845 | * @param array|null $array <p>The array to get from, if it's set to "null" we use the current array from the |
||
2846 | * class.</p> |
||
2847 | * @param bool $useByReference |
||
2848 | * |
||
2849 | * @return mixed|static |
||
2850 | * |
||
2851 | * @phpstan-param array-key $key |
||
2852 | * @phpstan-param array<array-key,mixed>|array<TKey,T> $array |
||
2853 | * @psalm-mutation-free |
||
2854 | */ |
||
2855 | 248 | public function get( |
|
3028 | |||
3029 | /** |
||
3030 | * alias: for "Arrayy->toArray()" |
||
3031 | * |
||
3032 | * @return array |
||
3033 | * |
||
3034 | * @see Arrayy::getArray() |
||
3035 | * |
||
3036 | * @phpstan-return array<TKey,T> |
||
3037 | */ |
||
3038 | 15 | public function getAll(): array |
|
3042 | |||
3043 | /** |
||
3044 | * Get the current array from the "Arrayy"-object. |
||
3045 | * |
||
3046 | * alias for "toArray()" |
||
3047 | * |
||
3048 | * @param bool $convertAllArrayyElements <p> |
||
3049 | * Convert all Child-"Arrayy" objects also to arrays. |
||
3050 | * </p> |
||
3051 | * @param bool $preserveKeys <p> |
||
3052 | * e.g.: A generator maybe return the same key more then once, |
||
3053 | * so maybe you will ignore the keys. |
||
3054 | * </p> |
||
3055 | * |
||
3056 | * @return array |
||
3057 | * |
||
3058 | * @phpstan-return array<TKey,T> |
||
3059 | * @psalm-mutation-free |
||
3060 | * |
||
3061 | * @see Arrayy::toArray() |
||
3062 | */ |
||
3063 | 513 | public function getArray( |
|
3072 | |||
3073 | /** |
||
3074 | * @param string $json |
||
3075 | * |
||
3076 | * @return $this |
||
3077 | */ |
||
3078 | 3 | public static function createFromJsonMapper(string $json) |
|
3094 | |||
3095 | /** |
||
3096 | * @return array<int|string,TypeCheckInterface>|mixed|TypeCheckArray<int|string,TypeCheckInterface>|TypeInterface |
||
3097 | * |
||
3098 | * @internal |
||
3099 | */ |
||
3100 | 6 | public function getPhpDocPropertiesFromClass() |
|
3108 | |||
3109 | /** |
||
3110 | * Get the current array from the "Arrayy"-object as list. |
||
3111 | * |
||
3112 | * alias for "toList()" |
||
3113 | * |
||
3114 | * @param bool $convertAllArrayyElements <p> |
||
3115 | * Convert all Child-"Arrayy" objects also to arrays. |
||
3116 | * </p> |
||
3117 | * |
||
3118 | * @return array |
||
3119 | * |
||
3120 | * @phpstan-return list<mixed>|list<T> |
||
3121 | * @psalm-mutation-free |
||
3122 | * |
||
3123 | * @see Arrayy::toList() |
||
3124 | */ |
||
3125 | 1 | public function getList(bool $convertAllArrayyElements = false): array |
|
3129 | |||
3130 | /** |
||
3131 | * Returns the values from a single column of the input array, identified by |
||
3132 | * the $columnKey, can be used to extract data-columns from multi-arrays. |
||
3133 | * |
||
3134 | * EXAMPLE: <code> |
||
3135 | * a([['foo' => 'bar', 'id' => 1], ['foo => 'lall', 'id' => 2]])->getColumn('foo', 'id'); // Arrayy[1 => 'bar', 2 => 'lall'] |
||
3136 | * </code> |
||
3137 | * |
||
3138 | * INFO: Optionally, you may provide an $indexKey to index the values in the returned |
||
3139 | * array by the values from the $indexKey column in the input array. |
||
3140 | * |
||
3141 | * @param int|string|null $columnKey |
||
3142 | * @param int|string|null $indexKey |
||
3143 | * |
||
3144 | * @return static |
||
3145 | * <p>(Immutable)</p> |
||
3146 | * |
||
3147 | * @phpstan-return static<TKey,T> |
||
3148 | * @psalm-mutation-free |
||
3149 | */ |
||
3150 | 1 | public function getColumn($columnKey = null, $indexKey = null): self |
|
3210 | |||
3211 | /** |
||
3212 | * Get the current array from the "Arrayy"-object as generator by reference. |
||
3213 | * |
||
3214 | * @return \Generator |
||
3215 | * |
||
3216 | * @phpstan-return \Generator<mixed,T>|\Generator<TKey,T> |
||
3217 | */ |
||
3218 | 75 | public function &getGeneratorByReference(): \Generator |
|
3237 | |||
3238 | /** |
||
3239 | * Get the current array from the "Arrayy"-object as generator. |
||
3240 | * |
||
3241 | * @return \Generator |
||
3242 | * |
||
3243 | * @phpstan-return \Generator<mixed,T>|\Generator<TKey,T> |
||
3244 | * @psalm-mutation-free |
||
3245 | */ |
||
3246 | 1073 | public function getGenerator(): \Generator |
|
3256 | |||
3257 | /** |
||
3258 | * alias: for "Arrayy->keys()" |
||
3259 | * |
||
3260 | * @return static |
||
3261 | * <p>(Immutable)</p> |
||
3262 | * |
||
3263 | * @see Arrayy::keys() |
||
3264 | * |
||
3265 | * @phpstan-return static<int,TKey> |
||
3266 | * @psalm-mutation-free |
||
3267 | */ |
||
3268 | 2 | public function getKeys() |
|
3272 | |||
3273 | /** |
||
3274 | * Get the current array from the "Arrayy"-object as object. |
||
3275 | * |
||
3276 | * @return \stdClass |
||
3277 | */ |
||
3278 | 4 | public function getObject(): \stdClass |
|
3282 | |||
3283 | /** |
||
3284 | * alias: for "Arrayy->randomImmutable()" |
||
3285 | * |
||
3286 | * @return static |
||
3287 | * <p>(Immutable)</p> |
||
3288 | * |
||
3289 | * @see Arrayy::randomImmutable() |
||
3290 | * |
||
3291 | * @phpstan-return static<int|array-key,T> |
||
3292 | */ |
||
3293 | 4 | public function getRandom(): self |
|
3297 | |||
3298 | /** |
||
3299 | * alias: for "Arrayy->randomKey()" |
||
3300 | * |
||
3301 | * @return mixed |
||
3302 | * <p>Get a key/index or null if there wasn't a key/index.</p> |
||
3303 | * |
||
3304 | * @see Arrayy::randomKey() |
||
3305 | */ |
||
3306 | 3 | public function getRandomKey() |
|
3310 | |||
3311 | /** |
||
3312 | * alias: for "Arrayy->randomKeys()" |
||
3313 | * |
||
3314 | * @param int $number |
||
3315 | * |
||
3316 | * @return static |
||
3317 | * <p>(Immutable)</p> |
||
3318 | * |
||
3319 | * @see Arrayy::randomKeys() |
||
3320 | * |
||
3321 | * @phpstan-return static<TKey,T> |
||
3322 | */ |
||
3323 | 8 | public function getRandomKeys(int $number): self |
|
3327 | |||
3328 | /** |
||
3329 | * alias: for "Arrayy->randomValue()" |
||
3330 | * |
||
3331 | * @return mixed |
||
3332 | * <p>Get a random value or null if there wasn't a value.</p> |
||
3333 | * |
||
3334 | * @see Arrayy::randomValue() |
||
3335 | */ |
||
3336 | 3 | public function getRandomValue() |
|
3340 | |||
3341 | /** |
||
3342 | * alias: for "Arrayy->randomValues()" |
||
3343 | * |
||
3344 | * @param int $number |
||
3345 | * |
||
3346 | * @return static |
||
3347 | * <p>(Immutable)</p> |
||
3348 | * |
||
3349 | * @see Arrayy::randomValues() |
||
3350 | * |
||
3351 | * @phpstan-return static<TKey,T> |
||
3352 | */ |
||
3353 | 6 | public function getRandomValues(int $number): self |
|
3357 | |||
3358 | /** |
||
3359 | * Gets all values. |
||
3360 | * |
||
3361 | * @return static |
||
3362 | * <p>The values of all elements in this array, in the order they |
||
3363 | * appear in the array.</p> |
||
3364 | * |
||
3365 | * @phpstan-return static<TKey,T> |
||
3366 | */ |
||
3367 | 4 | public function getValues() |
|
3377 | |||
3378 | /** |
||
3379 | * Gets all values via Generator. |
||
3380 | * |
||
3381 | * @return \Generator |
||
3382 | * <p>The values of all elements in this array, in the order they |
||
3383 | * appear in the array as Generator.</p> |
||
3384 | * |
||
3385 | * @phpstan-return \Generator<TKey,T> |
||
3386 | */ |
||
3387 | 4 | public function getValuesYield(): \Generator |
|
3391 | |||
3392 | /** |
||
3393 | * Group values from a array according to the results of a closure. |
||
3394 | * |
||
3395 | * @param callable|string $grouper <p>A callable function name.</p> |
||
3396 | * @param bool $saveKeys |
||
3397 | * |
||
3398 | * @return static |
||
3399 | * <p>(Immutable)</p> |
||
3400 | * |
||
3401 | * @phpstan-return static<TKey,T> |
||
3402 | * @psalm-mutation-free |
||
3403 | */ |
||
3404 | 4 | public function group($grouper, bool $saveKeys = false): self |
|
3445 | |||
3446 | /** |
||
3447 | * Check if an array has a given key. |
||
3448 | * |
||
3449 | * @param mixed $key |
||
3450 | * |
||
3451 | * @return bool |
||
3452 | */ |
||
3453 | 30 | public function has($key): bool |
|
3479 | |||
3480 | /** |
||
3481 | * Check if an array has a given value. |
||
3482 | * |
||
3483 | * INFO: If you need to search recursive please use ```contains($value, true)```. |
||
3484 | * |
||
3485 | * @param mixed $value |
||
3486 | * |
||
3487 | * @return bool |
||
3488 | */ |
||
3489 | 1 | public function hasValue($value): bool |
|
3493 | |||
3494 | /** |
||
3495 | * Implodes the values of this array. |
||
3496 | * |
||
3497 | * EXAMPLE: <code> |
||
3498 | * a([0 => -9, 1, 2])->implode('|'); // '-9|1|2' |
||
3499 | * </code> |
||
3500 | * |
||
3501 | * @param string $glue |
||
3502 | * @param string $prefix |
||
3503 | * |
||
3504 | * @return string |
||
3505 | * @psalm-mutation-free |
||
3506 | */ |
||
3507 | 28 | public function implode(string $glue = '', string $prefix = ''): string |
|
3511 | |||
3512 | /** |
||
3513 | * Implodes the keys of this array. |
||
3514 | * |
||
3515 | * @param string $glue |
||
3516 | * |
||
3517 | * @return string |
||
3518 | * @psalm-mutation-free |
||
3519 | */ |
||
3520 | 8 | public function implodeKeys(string $glue = ''): string |
|
3524 | |||
3525 | /** |
||
3526 | * Given a list and an iterate-function that returns |
||
3527 | * a key for each element in the list (or a property name), |
||
3528 | * returns an object with an index of each item. |
||
3529 | * |
||
3530 | * @param mixed $key |
||
3531 | * |
||
3532 | * @return static |
||
3533 | * <p>(Immutable)</p> |
||
3534 | * |
||
3535 | * @phpstan-return static<TKey,T> |
||
3536 | * @psalm-mutation-free |
||
3537 | */ |
||
3538 | 4 | View Code Duplication | public function indexBy($key): self |
3555 | |||
3556 | /** |
||
3557 | * alias: for "Arrayy->searchIndex()" |
||
3558 | * |
||
3559 | * @param mixed $value <p>The value to search for.</p> |
||
3560 | * |
||
3561 | * @return false|mixed |
||
3562 | * |
||
3563 | * @see Arrayy::searchIndex() |
||
3564 | */ |
||
3565 | 4 | public function indexOf($value) |
|
3569 | |||
3570 | /** |
||
3571 | * Get everything but the last..$to items. |
||
3572 | * |
||
3573 | * EXAMPLE: <code> |
||
3574 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->initial(2); // Arrayy[0 => 'foo'] |
||
3575 | * </code> |
||
3576 | * |
||
3577 | * @param int $to |
||
3578 | * |
||
3579 | * @return static |
||
3580 | * <p>(Immutable)</p> |
||
3581 | * |
||
3582 | * @phpstan-return static<TKey,T> |
||
3583 | * @psalm-mutation-free |
||
3584 | */ |
||
3585 | 12 | public function initial(int $to = 1): self |
|
3589 | |||
3590 | /** |
||
3591 | * Return an array with all elements found in input array. |
||
3592 | * |
||
3593 | * EXAMPLE: <code> |
||
3594 | * a(['foo', 'bar'])->intersection(['bar', 'baz']); // Arrayy['bar'] |
||
3595 | * </code> |
||
3596 | * |
||
3597 | * @param array $search |
||
3598 | * @param bool $keepKeys |
||
3599 | * |
||
3600 | * @return static |
||
3601 | * <p>(Immutable)</p> |
||
3602 | * |
||
3603 | * @phpstan-param array<TKey,T> $search |
||
3604 | * @phpstan-return static<TKey,T> |
||
3605 | * @psalm-mutation-free |
||
3606 | */ |
||
3607 | 4 | public function intersection(array $search, bool $keepKeys = false): self |
|
3633 | |||
3634 | /** |
||
3635 | * Return an array with all elements found in input array. |
||
3636 | * |
||
3637 | * @param array ...$array |
||
3638 | * |
||
3639 | * @return static |
||
3640 | * <p>(Immutable)</p> |
||
3641 | * |
||
3642 | * @phpstan-param array<array<TKey,T>> ...$array |
||
3643 | * @phpstan-return static<TKey,T> |
||
3644 | * @psalm-mutation-free |
||
3645 | */ |
||
3646 | 1 | public function intersectionMulti(...$array): self |
|
3654 | |||
3655 | /** |
||
3656 | * Return a boolean flag which indicates whether the two input arrays have any common elements. |
||
3657 | * |
||
3658 | * EXAMPLE: <code> |
||
3659 | * a(['foo', 'bar'])->intersects(['föö', 'bär']); // false |
||
3660 | * </code> |
||
3661 | * |
||
3662 | * @param array $search |
||
3663 | * |
||
3664 | * @return bool |
||
3665 | * |
||
3666 | * @phpstan-param array<TKey,T> $search |
||
3667 | */ |
||
3668 | 1 | public function intersects(array $search): bool |
|
3672 | |||
3673 | /** |
||
3674 | * Invoke a function on all of an array's values. |
||
3675 | * |
||
3676 | * @param callable $callable |
||
3677 | * @param mixed $arguments |
||
3678 | * |
||
3679 | * @return static |
||
3680 | * <p>(Immutable)</p> |
||
3681 | * |
||
3682 | * @phpstan-param callable(T=,mixed):mixed $callable |
||
3683 | * @phpstan-return static<TKey,T> |
||
3684 | * @psalm-mutation-free |
||
3685 | */ |
||
3686 | 1 | public function invoke($callable, $arguments = []): self |
|
3710 | |||
3711 | /** |
||
3712 | * Check whether array is associative or not. |
||
3713 | * |
||
3714 | * EXAMPLE: <code> |
||
3715 | * a(['foo' => 'bar', 2, 3])->isAssoc(); // true |
||
3716 | * </code> |
||
3717 | * |
||
3718 | * @param bool $recursive |
||
3719 | * |
||
3720 | * @return bool |
||
3721 | * <p>Returns true if associative, false otherwise.</p> |
||
3722 | */ |
||
3723 | 15 | View Code Duplication | public function isAssoc(bool $recursive = false): bool |
3738 | |||
3739 | /** |
||
3740 | * Check if a given key or keys are empty. |
||
3741 | * |
||
3742 | * @param int|int[]|string|string[]|null $keys |
||
3743 | * |
||
3744 | * @return bool |
||
3745 | * <p>Returns true if empty, false otherwise.</p> |
||
3746 | * @psalm-mutation-free |
||
3747 | */ |
||
3748 | 45 | public function isEmpty($keys = null): bool |
|
3766 | |||
3767 | /** |
||
3768 | * Check if the current array is equal to the given "$array" or not. |
||
3769 | * |
||
3770 | * EXAMPLE: <code> |
||
3771 | * a(['💩'])->isEqual(['💩']); // true |
||
3772 | * </code> |
||
3773 | * |
||
3774 | * @param array $array |
||
3775 | * |
||
3776 | * @return bool |
||
3777 | * |
||
3778 | * @phpstan-param array<int|string,mixed> $array |
||
3779 | */ |
||
3780 | 1 | public function isEqual(array $array): bool |
|
3784 | |||
3785 | /** |
||
3786 | * Check if the current array is a multi-array. |
||
3787 | * |
||
3788 | * EXAMPLE: <code> |
||
3789 | * a(['foo' => [1, 2 , 3]])->isMultiArray(); // true |
||
3790 | * </code> |
||
3791 | * |
||
3792 | * @return bool |
||
3793 | */ |
||
3794 | 22 | public function isMultiArray(): bool |
|
3804 | |||
3805 | /** |
||
3806 | * Check whether array is numeric or not. |
||
3807 | * |
||
3808 | * @return bool |
||
3809 | * <p>Returns true if numeric, false otherwise.</p> |
||
3810 | */ |
||
3811 | 5 | View Code Duplication | public function isNumeric(): bool |
3826 | |||
3827 | /** |
||
3828 | * Check if the current array is sequential [0, 1, 2, 3, 4, 5 ...] or not. |
||
3829 | * |
||
3830 | * EXAMPLE: <code> |
||
3831 | * a([0 => 'foo', 1 => 'lall', 2 => 'foobar'])->isSequential(); // true |
||
3832 | * </code> |
||
3833 | * |
||
3834 | * INFO: If the array is empty we count it as non-sequential. |
||
3835 | * |
||
3836 | * @param bool $recursive |
||
3837 | * |
||
3838 | * @return bool |
||
3839 | * @psalm-mutation-free |
||
3840 | */ |
||
3841 | 10 | public function isSequential(bool $recursive = false): bool |
|
3870 | |||
3871 | /** |
||
3872 | * @return array |
||
3873 | * |
||
3874 | * @phpstan-return array<TKey,T> |
||
3875 | */ |
||
3876 | 2 | public function jsonSerialize(): array |
|
3880 | |||
3881 | /** |
||
3882 | * Gets the key/index of the element at the current internal iterator position. |
||
3883 | * |
||
3884 | * @return int|string|null |
||
3885 | * @phpstan-return array-key|null |
||
3886 | */ |
||
3887 | public function key() |
||
3895 | |||
3896 | /** |
||
3897 | * Checks if the given key exists in the provided array. |
||
3898 | * |
||
3899 | * INFO: This method only use "array_key_exists()" if you want to use "dot"-notation, |
||
3900 | * then you need to use "Arrayy->offsetExists()". |
||
3901 | * |
||
3902 | * @param int|string $key the key to look for |
||
3903 | * |
||
3904 | * @return bool |
||
3905 | * @psalm-mutation-free |
||
3906 | */ |
||
3907 | 174 | public function keyExists($key): bool |
|
3917 | |||
3918 | /** |
||
3919 | * Get all keys from the current array. |
||
3920 | * |
||
3921 | * EXAMPLE: <code> |
||
3922 | * a([1 => 'foo', 2 => 'foo2', 3 => 'bar'])->keys(); // Arrayy[1, 2, 3] |
||
3923 | * </code> |
||
3924 | * |
||
3925 | * @param bool $recursive [optional] <p> |
||
3926 | * Get all keys, also from all sub-arrays from an multi-dimensional array. |
||
3927 | * </p> |
||
3928 | * @param mixed|null $search_values [optional] <p> |
||
3929 | * If specified, then only keys containing these values are returned. |
||
3930 | * </p> |
||
3931 | * @param bool $strict [optional] <p> |
||
3932 | * Determines if strict comparison (===) should be used during the search. |
||
3933 | * </p> |
||
3934 | * |
||
3935 | * @return static |
||
3936 | * <p>(Immutable) An array of all the keys in input.</p> |
||
3937 | * |
||
3938 | * @phpstan-return static<int,TKey> |
||
3939 | * @psalm-mutation-free |
||
3940 | */ |
||
3941 | 29 | public function keys( |
|
4012 | |||
4013 | /** |
||
4014 | * Sort an array by key in reverse order. |
||
4015 | * |
||
4016 | * @param int $sort_flags [optional] <p> |
||
4017 | * You may modify the behavior of the sort using the optional |
||
4018 | * parameter sort_flags, for details |
||
4019 | * see sort. |
||
4020 | * </p> |
||
4021 | * |
||
4022 | * @return $this |
||
4023 | * <p>(Mutable) Return this Arrayy object.</p> |
||
4024 | * |
||
4025 | * @phpstan-return static<TKey,T> |
||
4026 | */ |
||
4027 | 4 | public function krsort(int $sort_flags = 0): self |
|
4035 | |||
4036 | /** |
||
4037 | * Sort an array by key in reverse order. |
||
4038 | * |
||
4039 | * @param int $sort_flags [optional] <p> |
||
4040 | * You may modify the behavior of the sort using the optional |
||
4041 | * parameter sort_flags, for details |
||
4042 | * see sort. |
||
4043 | * </p> |
||
4044 | * |
||
4045 | * @return $this |
||
4046 | * <p>(Immutable) Return this Arrayy object.</p> |
||
4047 | * |
||
4048 | * @phpstan-return static<TKey,T> |
||
4049 | * @psalm-mutation-free |
||
4050 | */ |
||
4051 | 4 | public function krsortImmutable(int $sort_flags = 0): self |
|
4062 | |||
4063 | /** |
||
4064 | * Get the last value from the current array. |
||
4065 | * |
||
4066 | * EXAMPLE: <code> |
||
4067 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->last(); // 'lall' |
||
4068 | * </code> |
||
4069 | * |
||
4070 | * @return mixed|null |
||
4071 | * <p>Return null if there wasn't a element.</p> |
||
4072 | * |
||
4073 | * @phpstan-return T|null |
||
4074 | * @psalm-mutation-free |
||
4075 | */ |
||
4076 | 17 | public function last() |
|
4085 | |||
4086 | /** |
||
4087 | * Get the last key from the current array. |
||
4088 | * |
||
4089 | * @return mixed|null |
||
4090 | * <p>Return null if there wasn't a element.</p> |
||
4091 | * @psalm-mutation-free |
||
4092 | */ |
||
4093 | 21 | public function lastKey() |
|
4099 | |||
4100 | /** |
||
4101 | * Get the last value(s) from the current array. |
||
4102 | * |
||
4103 | * EXAMPLE: <code> |
||
4104 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->lasts(2); // Arrayy[0 => 'bar', 1 => 'lall'] |
||
4105 | * </code> |
||
4106 | * |
||
4107 | * @param int|null $number |
||
4108 | * |
||
4109 | * @return static |
||
4110 | * <p>(Immutable)</p> |
||
4111 | * |
||
4112 | * @phpstan-return static<TKey,T> |
||
4113 | * @psalm-mutation-free |
||
4114 | */ |
||
4115 | 13 | public function lastsImmutable(int $number = null): self |
|
4145 | |||
4146 | /** |
||
4147 | * Get the last value(s) from the current array. |
||
4148 | * |
||
4149 | * EXAMPLE: <code> |
||
4150 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->lasts(2); // Arrayy[0 => 'bar', 1 => 'lall'] |
||
4151 | * </code> |
||
4152 | * |
||
4153 | * @param int|null $number |
||
4154 | * |
||
4155 | * @return $this |
||
4156 | * <p>(Mutable)</p> |
||
4157 | * |
||
4158 | * @phpstan-return static<TKey,T> |
||
4159 | */ |
||
4160 | 13 | public function lastsMutable(int $number = null): self |
|
4171 | |||
4172 | /** |
||
4173 | * Count the values from the current array. |
||
4174 | * |
||
4175 | * alias: for "Arrayy->count()" |
||
4176 | * |
||
4177 | * @param int $mode |
||
4178 | * |
||
4179 | * @return int |
||
4180 | * |
||
4181 | * @see Arrayy::count() |
||
4182 | */ |
||
4183 | 20 | public function length(int $mode = \COUNT_NORMAL): int |
|
4187 | |||
4188 | /** |
||
4189 | * Apply the given function to the every element of the array, |
||
4190 | * collecting the results. |
||
4191 | * |
||
4192 | * EXAMPLE: <code> |
||
4193 | * a(['foo', 'Foo'])->map('mb_strtoupper'); // Arrayy['FOO', 'FOO'] |
||
4194 | * </code> |
||
4195 | * |
||
4196 | * @param callable $callable |
||
4197 | * @param bool $useKeyAsSecondParameter |
||
4198 | * @param mixed ...$arguments |
||
4199 | * |
||
4200 | * @return static |
||
4201 | * <p>(Immutable) Arrayy object with modified elements.</p> |
||
4202 | * |
||
4203 | * @template T2 |
||
4204 | * <p>The output value type.</p> |
||
4205 | * |
||
4206 | * @phpstan-param callable(T,TKey=,mixed=):T2 $callable |
||
4207 | * @phpstan-return static<TKey,T2> |
||
4208 | * @psalm-mutation-free |
||
4209 | */ |
||
4210 | 6 | public function map( |
|
4243 | |||
4244 | /** |
||
4245 | * Check if all items in current array match a truth test. |
||
4246 | * |
||
4247 | * EXAMPLE: <code> |
||
4248 | * $closure = function ($value, $key) { |
||
4249 | * return ($value % 2 === 0); |
||
4250 | * }; |
||
4251 | * a([2, 4, 8])->matches($closure); // true |
||
4252 | * </code> |
||
4253 | * |
||
4254 | * @param \Closure $closure |
||
4255 | * |
||
4256 | * @return bool |
||
4257 | * |
||
4258 | * @phpstan-param \Closure(T=,TKey=):bool $closure |
||
4259 | */ |
||
4260 | 15 | View Code Duplication | public function matches(\Closure $closure): bool |
4276 | |||
4277 | /** |
||
4278 | * Check if any item in the current array matches a truth test. |
||
4279 | * |
||
4280 | * EXAMPLE: <code> |
||
4281 | * $closure = function ($value, $key) { |
||
4282 | * return ($value % 2 === 0); |
||
4283 | * }; |
||
4284 | * a([1, 4, 7])->matches($closure); // true |
||
4285 | * </code> |
||
4286 | * |
||
4287 | * @param \Closure $closure |
||
4288 | * |
||
4289 | * @return bool |
||
4290 | * |
||
4291 | * @phpstan-param \Closure(T=,TKey=):bool $closure |
||
4292 | */ |
||
4293 | 14 | View Code Duplication | public function matchesAny(\Closure $closure): bool |
4309 | |||
4310 | /** |
||
4311 | * Get the max value from an array. |
||
4312 | * |
||
4313 | * EXAMPLE: <code> |
||
4314 | * a([-9, -8, -7, 1.32])->max(); // 1.32 |
||
4315 | * </code> |
||
4316 | * |
||
4317 | * @return false|float|int|string |
||
4318 | * <p>Will return false if there are no values.</p> |
||
4319 | */ |
||
4320 | 10 | View Code Duplication | public function max() |
4340 | |||
4341 | /** |
||
4342 | * Merge the new $array into the current array. |
||
4343 | * |
||
4344 | * - keep key,value from the current array, also if the index is in the new $array |
||
4345 | * |
||
4346 | * EXAMPLE: <code> |
||
4347 | * $array1 = [1 => 'one', 'foo' => 'bar1']; |
||
4348 | * $array2 = ['foo' => 'bar2', 3 => 'three']; |
||
4349 | * a($array1)->mergeAppendKeepIndex($array2); // Arrayy[1 => 'one', 'foo' => 'bar2', 3 => 'three'] |
||
4350 | * // --- |
||
4351 | * $array1 = [0 => 'one', 1 => 'foo']; |
||
4352 | * $array2 = [0 => 'foo', 1 => 'bar2']; |
||
4353 | * a($array1)->mergeAppendKeepIndex($array2); // Arrayy[0 => 'foo', 1 => 'bar2'] |
||
4354 | * </code> |
||
4355 | * |
||
4356 | * @param array $array |
||
4357 | * @param bool $recursive |
||
4358 | * |
||
4359 | * @return static |
||
4360 | * <p>(Immutable)</p> |
||
4361 | * |
||
4362 | * @phpstan-param array<int|TKey,T> $array |
||
4363 | * @phpstan-return static<int|TKey,T> |
||
4364 | * @psalm-mutation-free |
||
4365 | */ |
||
4366 | 33 | View Code Duplication | public function mergeAppendKeepIndex(array $array = [], bool $recursive = false): self |
4381 | |||
4382 | /** |
||
4383 | * Merge the new $array into the current array. |
||
4384 | * |
||
4385 | * - replace duplicate assoc-keys from the current array with the key,values from the new $array |
||
4386 | * - create new indexes |
||
4387 | * |
||
4388 | * EXAMPLE: <code> |
||
4389 | * $array1 = [1 => 'one', 'foo' => 'bar1']; |
||
4390 | * $array2 = ['foo' => 'bar2', 3 => 'three']; |
||
4391 | * a($array1)->mergeAppendNewIndex($array2); // Arrayy[0 => 'one', 'foo' => 'bar2', 1 => 'three'] |
||
4392 | * // --- |
||
4393 | * $array1 = [0 => 'one', 1 => 'foo']; |
||
4394 | * $array2 = [0 => 'foo', 1 => 'bar2']; |
||
4395 | * a($array1)->mergeAppendNewIndex($array2); // Arrayy[0 => 'one', 1 => 'foo', 2 => 'foo', 3 => 'bar2'] |
||
4396 | * </code> |
||
4397 | * |
||
4398 | * @param array $array |
||
4399 | * @param bool $recursive |
||
4400 | * |
||
4401 | * @return static |
||
4402 | * <p>(Immutable)</p> |
||
4403 | * |
||
4404 | * @phpstan-param array<TKey,T> $array |
||
4405 | * @phpstan-return static<int,T> |
||
4406 | * @psalm-mutation-free |
||
4407 | */ |
||
4408 | 20 | View Code Duplication | public function mergeAppendNewIndex(array $array = [], bool $recursive = false): self |
4423 | |||
4424 | /** |
||
4425 | * Merge the the current array into the $array. |
||
4426 | * |
||
4427 | * - use key,value from the new $array, also if the index is in the current array |
||
4428 | * |
||
4429 | * EXAMPLE: <code> |
||
4430 | * $array1 = [1 => 'one', 'foo' => 'bar1']; |
||
4431 | * $array2 = ['foo' => 'bar2', 3 => 'three']; |
||
4432 | * a($array1)->mergePrependKeepIndex($array2); // Arrayy['foo' => 'bar1', 3 => 'three', 1 => 'one'] |
||
4433 | * // --- |
||
4434 | * $array1 = [0 => 'one', 1 => 'foo']; |
||
4435 | * $array2 = [0 => 'foo', 1 => 'bar2']; |
||
4436 | * a($array1)->mergePrependKeepIndex($array2); // Arrayy[0 => 'one', 1 => 'foo'] |
||
4437 | * </code> |
||
4438 | * |
||
4439 | * @param array $array |
||
4440 | * @param bool $recursive |
||
4441 | * |
||
4442 | * @return static |
||
4443 | * <p>(Immutable)</p> |
||
4444 | * |
||
4445 | * @phpstan-param array<TKey,T> $array |
||
4446 | * @phpstan-return static<TKey,T> |
||
4447 | * @psalm-mutation-free |
||
4448 | */ |
||
4449 | 17 | View Code Duplication | public function mergePrependKeepIndex(array $array = [], bool $recursive = false): self |
4464 | |||
4465 | /** |
||
4466 | * Merge the current array into the new $array. |
||
4467 | * |
||
4468 | * - replace duplicate assoc-keys from new $array with the key,values from the current array |
||
4469 | * - create new indexes |
||
4470 | * |
||
4471 | * EXAMPLE: <code> |
||
4472 | * $array1 = [1 => 'one', 'foo' => 'bar1']; |
||
4473 | * $array2 = ['foo' => 'bar2', 3 => 'three']; |
||
4474 | * a($array1)->mergePrependNewIndex($array2); // Arrayy['foo' => 'bar1', 0 => 'three', 1 => 'one'] |
||
4475 | * // --- |
||
4476 | * $array1 = [0 => 'one', 1 => 'foo']; |
||
4477 | * $array2 = [0 => 'foo', 1 => 'bar2']; |
||
4478 | * a($array1)->mergePrependNewIndex($array2); // Arrayy[0 => 'foo', 1 => 'bar2', 2 => 'one', 3 => 'foo'] |
||
4479 | * </code> |
||
4480 | * |
||
4481 | * @param array $array |
||
4482 | * @param bool $recursive |
||
4483 | * |
||
4484 | * @return static |
||
4485 | * <p>(Immutable)</p> |
||
4486 | * |
||
4487 | * @phpstan-param array<TKey,T> $array |
||
4488 | * @phpstan-return static<int,T> |
||
4489 | * @psalm-mutation-free |
||
4490 | */ |
||
4491 | 21 | View Code Duplication | public function mergePrependNewIndex(array $array = [], bool $recursive = false): self |
4506 | |||
4507 | /** |
||
4508 | * @return ArrayyMeta|mixed|static |
||
4509 | */ |
||
4510 | 18 | public static function meta() |
|
4514 | |||
4515 | /** |
||
4516 | * Get the min value from an array. |
||
4517 | * |
||
4518 | * EXAMPLE: <code> |
||
4519 | * a([-9, -8, -7, 1.32])->min(); // -9 |
||
4520 | * </code> |
||
4521 | * |
||
4522 | * @return false|mixed |
||
4523 | * <p>Will return false if there are no values.</p> |
||
4524 | */ |
||
4525 | 10 | View Code Duplication | public function min() |
4545 | |||
4546 | /** |
||
4547 | * Get the most used value from the array. |
||
4548 | * |
||
4549 | * @return mixed|null |
||
4550 | * <p>(Immutable) Return null if there wasn't a element.</p> |
||
4551 | * |
||
4552 | * @phpstan-return T|null |
||
4553 | * @psalm-mutation-free |
||
4554 | */ |
||
4555 | 3 | public function mostUsedValue() |
|
4559 | |||
4560 | /** |
||
4561 | * Get the most used value from the array. |
||
4562 | * |
||
4563 | * @param int|null $number <p>How many values you will take?</p> |
||
4564 | * |
||
4565 | * @return static |
||
4566 | * <p>(Immutable)</p> |
||
4567 | * |
||
4568 | * @phpstan-return static<TKey,T> |
||
4569 | * @psalm-mutation-free |
||
4570 | */ |
||
4571 | 3 | public function mostUsedValues(int $number = null): self |
|
4575 | |||
4576 | /** |
||
4577 | * Move an array element to a new index. |
||
4578 | * |
||
4579 | * EXAMPLE: <code> |
||
4580 | * $arr2 = new A(['A' => 'a', 'B' => 'b', 'C' => 'c', 'D' => 'd', 'E' => 'e']); |
||
4581 | * $newArr2 = $arr2->moveElement('D', 1); // Arrayy['A' => 'a', 'D' => 'd', 'B' => 'b', 'C' => 'c', 'E' => 'e'] |
||
4582 | * </code> |
||
4583 | * |
||
4584 | * @param int|string $from |
||
4585 | * @param int $to |
||
4586 | * |
||
4587 | * @return static |
||
4588 | * <p>(Immutable)</p> |
||
4589 | * |
||
4590 | * @phpstan-return static<TKey,T> |
||
4591 | * @psalm-mutation-free |
||
4592 | */ |
||
4593 | 1 | public function moveElement($from, $to): self |
|
4626 | |||
4627 | /** |
||
4628 | * Move an array element to the first place. |
||
4629 | * |
||
4630 | * INFO: Instead of "Arrayy->moveElement()" this method will NOT |
||
4631 | * loss the keys of an indexed array. |
||
4632 | * |
||
4633 | * @param int|string $key |
||
4634 | * |
||
4635 | * @return static |
||
4636 | * <p>(Immutable)</p> |
||
4637 | * |
||
4638 | * @phpstan-return static<TKey,T> |
||
4639 | * @psalm-mutation-free |
||
4640 | */ |
||
4641 | 1 | View Code Duplication | public function moveElementToFirstPlace($key): self |
4657 | |||
4658 | /** |
||
4659 | * Move an array element to the last place. |
||
4660 | * |
||
4661 | * INFO: Instead of "Arrayy->moveElement()" this method will NOT |
||
4662 | * loss the keys of an indexed array. |
||
4663 | * |
||
4664 | * @param int|string $key |
||
4665 | * |
||
4666 | * @return static |
||
4667 | * <p>(Immutable)</p> |
||
4668 | * |
||
4669 | * @phpstan-return static<TKey,T> |
||
4670 | * @psalm-mutation-free |
||
4671 | */ |
||
4672 | 1 | View Code Duplication | public function moveElementToLastPlace($key): self |
4688 | |||
4689 | /** |
||
4690 | * Moves the internal iterator position to the next element and returns this element. |
||
4691 | * |
||
4692 | * @return false|mixed |
||
4693 | * <p>(Mutable) Will return false if there are no values.</p> |
||
4694 | * |
||
4695 | * @phpstan-return false|T |
||
4696 | */ |
||
4697 | public function next() |
||
4707 | |||
4708 | /** |
||
4709 | * Get the next nth keys and values from the array. |
||
4710 | * |
||
4711 | * @param int $step |
||
4712 | * @param int $offset |
||
4713 | * |
||
4714 | * @return static |
||
4715 | * <p>(Immutable)</p> |
||
4716 | * |
||
4717 | * @phpstan-return static<TKey,T> |
||
4718 | * @psalm-mutation-free |
||
4719 | */ |
||
4720 | 1 | public function nth(int $step, int $offset = 0): self |
|
4739 | |||
4740 | /** |
||
4741 | * Get a subset of the items from the given array. |
||
4742 | * |
||
4743 | * @param int[]|string[] $keys |
||
4744 | * |
||
4745 | * @return static |
||
4746 | * <p>(Immutable)</p> |
||
4747 | * |
||
4748 | * @phpstan-param array-key[] $keys |
||
4749 | * @phpstan-return static<TKey,T> |
||
4750 | * @psalm-mutation-free |
||
4751 | */ |
||
4752 | 1 | View Code Duplication | public function only(array $keys): self |
4770 | |||
4771 | /** |
||
4772 | * Pad array to the specified size with a given value. |
||
4773 | * |
||
4774 | * @param int $size <p>Size of the result array.</p> |
||
4775 | * @param mixed $value <p>Empty value by default.</p> |
||
4776 | * |
||
4777 | * @return static |
||
4778 | * <p>(Immutable) Arrayy object padded to $size with $value.</p> |
||
4779 | * |
||
4780 | * @phpstan-return static<TKey,T> |
||
4781 | * @psalm-mutation-free |
||
4782 | */ |
||
4783 | 5 | public function pad(int $size, $value): self |
|
4791 | |||
4792 | /** |
||
4793 | * Partitions this array in two array according to a predicate. |
||
4794 | * Keys are preserved in the resulting array. |
||
4795 | * |
||
4796 | * @param \Closure $closure |
||
4797 | * <p>The predicate on which to partition.</p> |
||
4798 | * |
||
4799 | * @return array<int, static> |
||
4800 | * <p>An array with two elements. The first element contains the array |
||
4801 | * of elements where the predicate returned TRUE, the second element |
||
4802 | * contains the array of elements where the predicate returned FALSE.</p> |
||
4803 | * |
||
4804 | * @phpstan-param \Closure(T=,TKey=):bool $closure |
||
4805 | * @phpstan-return array<int, static<TKey,T>> |
||
4806 | */ |
||
4807 | 1 | public function partition(\Closure $closure): array |
|
4823 | |||
4824 | /** |
||
4825 | * Pop a specified value off the end of the current array. |
||
4826 | * |
||
4827 | * @return mixed|null |
||
4828 | * <p>(Mutable) The popped element from the current array or null if the array is e.g. empty.</p> |
||
4829 | * |
||
4830 | * @phpstan-return T|null |
||
4831 | */ |
||
4832 | 5 | public function pop() |
|
4838 | |||
4839 | /** |
||
4840 | * Prepend a (key) + value to the current array. |
||
4841 | * |
||
4842 | * EXAMPLE: <code> |
||
4843 | * a(['fòô' => 'bàř'])->prepend('foo'); // Arrayy[0 => 'foo', 'fòô' => 'bàř'] |
||
4844 | * </code> |
||
4845 | * |
||
4846 | * @param mixed $value |
||
4847 | * @param mixed $key |
||
4848 | * |
||
4849 | * @return $this |
||
4850 | * <p>(Mutable) Return this Arrayy object, with the prepended value.</p> |
||
4851 | * |
||
4852 | * @phpstan-param T $value |
||
4853 | * @phpstan-param TKey|null $key |
||
4854 | * @phpstan-return static<TKey,T> |
||
4855 | */ |
||
4856 | 11 | public function prepend($value, $key = null) |
|
4872 | |||
4873 | /** |
||
4874 | * Prepend a (key) + value to the current array. |
||
4875 | * |
||
4876 | * EXAMPLE: <code> |
||
4877 | * a(['fòô' => 'bàř'])->prependImmutable('foo')->getArray(); // [0 => 'foo', 'fòô' => 'bàř'] |
||
4878 | * </code> |
||
4879 | * |
||
4880 | * @param mixed $value |
||
4881 | * @param mixed $key |
||
4882 | * |
||
4883 | * @return $this |
||
4884 | * <p>(Immutable) Return this Arrayy object, with the prepended value.</p> |
||
4885 | * |
||
4886 | * @phpstan-param T $value |
||
4887 | * @phpstan-param TKey $key |
||
4888 | * @phpstan-return static<TKey,T> |
||
4889 | * @psalm-mutation-free |
||
4890 | */ |
||
4891 | 1 | View Code Duplication | public function prependImmutable($value, $key = null) |
4916 | |||
4917 | /** |
||
4918 | * Add a suffix to each key. |
||
4919 | * |
||
4920 | * @param float|int|string $suffix |
||
4921 | * |
||
4922 | * @return static |
||
4923 | * <p>(Immutable) Return an Arrayy object, with the prepended keys.</p> |
||
4924 | * |
||
4925 | * @phpstan-return static<TKey,T> |
||
4926 | * @psalm-mutation-free |
||
4927 | */ |
||
4928 | 10 | View Code Duplication | public function prependToEachKey($suffix): self |
4954 | |||
4955 | /** |
||
4956 | * Add a suffix to each value. |
||
4957 | * |
||
4958 | * @param float|int|string $suffix |
||
4959 | * |
||
4960 | * @return static |
||
4961 | * <p>(Immutable) Return an Arrayy object, with the prepended values.</p> |
||
4962 | * |
||
4963 | * @phpstan-return static<TKey,T> |
||
4964 | * @psalm-mutation-free |
||
4965 | */ |
||
4966 | 10 | View Code Duplication | public function prependToEachValue($suffix): self |
4994 | |||
4995 | /** |
||
4996 | * Return the value of a given key and |
||
4997 | * delete the key. |
||
4998 | * |
||
4999 | * @param int|int[]|string|string[]|null $keyOrKeys |
||
5000 | * @param mixed $fallback |
||
5001 | * |
||
5002 | * @return mixed |
||
5003 | */ |
||
5004 | 6 | public function pull($keyOrKeys = null, $fallback = null) |
|
5026 | |||
5027 | /** |
||
5028 | * Push one or more values onto the end of array at once. |
||
5029 | * |
||
5030 | * @param mixed ...$args |
||
5031 | * |
||
5032 | * @return $this |
||
5033 | * <p>(Mutable) Return this Arrayy object, with pushed elements to the end of array.</p> |
||
5034 | * |
||
5035 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
5036 | * |
||
5037 | * @phpstan-param array<TKey,T> ...$args |
||
5038 | * @phpstan-return static<TKey,T> |
||
5039 | */ |
||
5040 | 9 | View Code Duplication | public function push(...$args) |
5058 | |||
5059 | /** |
||
5060 | * Get a random value from the current array. |
||
5061 | * |
||
5062 | * EXAMPLE: <code> |
||
5063 | * a([1, 2, 3, 4])->randomImmutable(2); // e.g.: Arrayy[1, 4] |
||
5064 | * </code> |
||
5065 | * |
||
5066 | * @param int|null $number <p>How many values you will take?</p> |
||
5067 | * |
||
5068 | * @return static |
||
5069 | * <p>(Immutable)</p> |
||
5070 | * |
||
5071 | * @phpstan-return static<int|array-key,T> |
||
5072 | */ |
||
5073 | 19 | public function randomImmutable(int $number = null): self |
|
5106 | |||
5107 | /** |
||
5108 | * Pick a random key/index from the keys of this array. |
||
5109 | * |
||
5110 | * EXAMPLE: <code> |
||
5111 | * $arrayy = A::create([1 => 'one', 2 => 'two']); |
||
5112 | * $arrayy->randomKey(); // e.g. 2 |
||
5113 | * </code> |
||
5114 | * |
||
5115 | * @throws \RangeException If array is empty |
||
5116 | * |
||
5117 | * @return mixed |
||
5118 | * <p>Get a key/index or null if there wasn't a key/index.</p> |
||
5119 | */ |
||
5120 | 4 | public function randomKey() |
|
5130 | |||
5131 | /** |
||
5132 | * Pick a given number of random keys/indexes out of this array. |
||
5133 | * |
||
5134 | * EXAMPLE: <code> |
||
5135 | * a([1 => 'one', 2 => 'two'])->randomKeys(); // e.g. Arrayy[1, 2] |
||
5136 | * </code> |
||
5137 | * |
||
5138 | * @param int $number <p>The number of keys/indexes (should be <= \count($this->array))</p> |
||
5139 | * |
||
5140 | * @throws \RangeException If array is empty |
||
5141 | * |
||
5142 | * @return static |
||
5143 | * <p>(Immutable)</p> |
||
5144 | * |
||
5145 | * @phpstan-return static<TKey,T> |
||
5146 | */ |
||
5147 | 13 | public function randomKeys(int $number): self |
|
5175 | |||
5176 | /** |
||
5177 | * Get a random value from the current array. |
||
5178 | * |
||
5179 | * EXAMPLE: <code> |
||
5180 | * a([1, 2, 3, 4])->randomMutable(2); // e.g.: Arrayy[1, 4] |
||
5181 | * </code> |
||
5182 | * |
||
5183 | * @param int|null $number <p>How many values you will take?</p> |
||
5184 | * |
||
5185 | * @return $this |
||
5186 | * <p>(Mutable) Return this Arrayy object.</p> |
||
5187 | * |
||
5188 | * @phpstan-return static<TKey,T> |
||
5189 | */ |
||
5190 | 17 | public function randomMutable(int $number = null): self |
|
5215 | |||
5216 | /** |
||
5217 | * Pick a random value from the values of this array. |
||
5218 | * |
||
5219 | * EXAMPLE: <code> |
||
5220 | * a([1 => 'one', 2 => 'two'])->randomValue(); // e.g. 'one' |
||
5221 | * </code> |
||
5222 | * |
||
5223 | * @return mixed |
||
5224 | * <p>Get a random value or null if there wasn't a value.</p> |
||
5225 | */ |
||
5226 | 4 | public function randomValue() |
|
5236 | |||
5237 | /** |
||
5238 | * Pick a given number of random values out of this array. |
||
5239 | * |
||
5240 | * EXAMPLE: <code> |
||
5241 | * a([1 => 'one', 2 => 'two'])->randomValues(); // e.g. Arrayy['one', 'two'] |
||
5242 | * </code> |
||
5243 | * |
||
5244 | * @param int $number |
||
5245 | * |
||
5246 | * @return static |
||
5247 | * <p>(Mutable)</p> |
||
5248 | * |
||
5249 | * @phpstan-return static<TKey,T> |
||
5250 | */ |
||
5251 | 7 | public function randomValues(int $number): self |
|
5255 | |||
5256 | /** |
||
5257 | * Get a random value from an array, with the ability to skew the results. |
||
5258 | * |
||
5259 | * EXAMPLE: <code> |
||
5260 | * a([0 => 3, 1 => 4])->randomWeighted([1 => 4]); // e.g.: Arrayy[4] (has a 66% chance of returning 4) |
||
5261 | * </code> |
||
5262 | * |
||
5263 | * @param array $array |
||
5264 | * @param int|null $number <p>How many values you will take?</p> |
||
5265 | * |
||
5266 | * @return static<int,mixed> |
||
5267 | * <p>(Immutable)</p> |
||
5268 | * |
||
5269 | * @phpstan-param array<T,int> $array |
||
5270 | * @phpstan-return static<(int|string),T> |
||
5271 | */ |
||
5272 | 9 | public function randomWeighted(array $array, int $number = null): self |
|
5287 | |||
5288 | /** |
||
5289 | * Reduce the current array via callable e.g. anonymous-function and return the end result. |
||
5290 | * |
||
5291 | * EXAMPLE: <code> |
||
5292 | * a([1, 2, 3, 4])->reduce( |
||
5293 | * function ($carry, $item) { |
||
5294 | * return $carry * $item; |
||
5295 | * }, |
||
5296 | * 1 |
||
5297 | * ); // Arrayy[24] |
||
5298 | * </code> |
||
5299 | * |
||
5300 | * @param callable $callable |
||
5301 | * @param mixed $initial |
||
5302 | * |
||
5303 | * @return static |
||
5304 | * <p>(Immutable)</p> |
||
5305 | * |
||
5306 | * @template T2 |
||
5307 | * <p>The output value type.</p> |
||
5308 | * |
||
5309 | * @phpstan-param callable(T2, T, TKey): T2 $callable |
||
5310 | * @phpstan-param T2 $initial |
||
5311 | * |
||
5312 | * @phpstan-return static<TKey,T2> |
||
5313 | * @psalm-mutation-free |
||
5314 | */ |
||
5315 | 18 | View Code Duplication | public function reduce($callable, $initial = []): self |
5327 | |||
5328 | /** |
||
5329 | * @param bool $unique |
||
5330 | * |
||
5331 | * @return static |
||
5332 | * <p>(Immutable)</p> |
||
5333 | * |
||
5334 | * @phpstan-return static<int,mixed> |
||
5335 | * @psalm-mutation-free |
||
5336 | */ |
||
5337 | 14 | public function reduce_dimension(bool $unique = true): self |
|
5360 | |||
5361 | /** |
||
5362 | * Create a numerically re-indexed Arrayy object. |
||
5363 | * |
||
5364 | * EXAMPLE: <code> |
||
5365 | * a([2 => 1, 3 => 2])->reindex(); // Arrayy[0 => 1, 1 => 2] |
||
5366 | * </code> |
||
5367 | * |
||
5368 | * @return $this |
||
5369 | * <p>(Mutable) Return this Arrayy object, with re-indexed array-elements.</p> |
||
5370 | * |
||
5371 | * @phpstan-return static<TKey,T> |
||
5372 | */ |
||
5373 | 9 | public function reindex(): self |
|
5381 | |||
5382 | /** |
||
5383 | * Return all items that fail the truth test. |
||
5384 | * |
||
5385 | * EXAMPLE: <code> |
||
5386 | * $closure = function ($value) { |
||
5387 | * return $value % 2 !== 0; |
||
5388 | * } |
||
5389 | * a([1, 2, 3, 4])->reject($closure); // Arrayy[1 => 2, 3 => 4] |
||
5390 | * </code> |
||
5391 | * |
||
5392 | * @param \Closure $closure |
||
5393 | * |
||
5394 | * @return static |
||
5395 | * <p>(Immutable)</p> |
||
5396 | * |
||
5397 | * @phpstan-param \Closure(T=,TKey=):bool $closure |
||
5398 | * @phpstan-return static<TKey,T> |
||
5399 | * @psalm-mutation-free |
||
5400 | */ |
||
5401 | 1 | View Code Duplication | public function reject(\Closure $closure): self |
5418 | |||
5419 | /** |
||
5420 | * Remove a value from the current array (optional using dot-notation). |
||
5421 | * |
||
5422 | * EXAMPLE: <code> |
||
5423 | * a([1 => 'bar', 'foo' => 'foo'])->remove(1); // Arrayy['foo' => 'foo'] |
||
5424 | * </code> |
||
5425 | * |
||
5426 | * @param mixed $key |
||
5427 | * |
||
5428 | * @return static |
||
5429 | * <p>(Mutable)</p> |
||
5430 | * |
||
5431 | * @phpstan-param TKey $key |
||
5432 | * @phpstan-return static<TKey,T> |
||
5433 | */ |
||
5434 | 22 | public function remove($key) |
|
5457 | |||
5458 | /** |
||
5459 | * alias: for "Arrayy->removeValue()" |
||
5460 | * |
||
5461 | * @param mixed $element |
||
5462 | * |
||
5463 | * @return static |
||
5464 | * <p>(Immutable)</p> |
||
5465 | * |
||
5466 | * @phpstan-param T $element |
||
5467 | * @phpstan-return static<TKey,T> |
||
5468 | * @psalm-mutation-free |
||
5469 | */ |
||
5470 | 8 | public function removeElement($element) |
|
5474 | |||
5475 | /** |
||
5476 | * Remove the first value from the current array. |
||
5477 | * |
||
5478 | * EXAMPLE: <code> |
||
5479 | * a([1 => 'bar', 'foo' => 'foo'])->removeFirst(); // Arrayy['foo' => 'foo'] |
||
5480 | * </code> |
||
5481 | * |
||
5482 | * @return static |
||
5483 | * <p>(Immutable)</p> |
||
5484 | * |
||
5485 | * @phpstan-return static<TKey,T> |
||
5486 | * @psalm-mutation-free |
||
5487 | */ |
||
5488 | 7 | View Code Duplication | public function removeFirst(): self |
5500 | |||
5501 | /** |
||
5502 | * Remove the last value from the current array. |
||
5503 | * |
||
5504 | * EXAMPLE: <code> |
||
5505 | * a([1 => 'bar', 'foo' => 'foo'])->removeLast(); // Arrayy[1 => 'bar'] |
||
5506 | * </code> |
||
5507 | * |
||
5508 | * @return static |
||
5509 | * <p>(Immutable)</p> |
||
5510 | * |
||
5511 | * @phpstan-return static<TKey,T> |
||
5512 | * @psalm-mutation-free |
||
5513 | */ |
||
5514 | 7 | View Code Duplication | public function removeLast(): self |
5526 | |||
5527 | /** |
||
5528 | * Removes a particular value from an array (numeric or associative). |
||
5529 | * |
||
5530 | * EXAMPLE: <code> |
||
5531 | * a([1 => 'bar', 'foo' => 'foo'])->removeValue('foo'); // Arrayy[1 => 'bar'] |
||
5532 | * </code> |
||
5533 | * |
||
5534 | * @param mixed $value |
||
5535 | * |
||
5536 | * @return static |
||
5537 | * <p>(Immutable)</p> |
||
5538 | * |
||
5539 | * @phpstan-param T $value |
||
5540 | * @phpstan-return static<TKey,T> |
||
5541 | * @psalm-mutation-free |
||
5542 | */ |
||
5543 | 8 | public function removeValue($value): self |
|
5567 | |||
5568 | /** |
||
5569 | * Generate array of repeated arrays. |
||
5570 | * |
||
5571 | * @param int $times <p>How many times has to be repeated.</p> |
||
5572 | * |
||
5573 | * @return static |
||
5574 | * <p>(Immutable)</p> |
||
5575 | * |
||
5576 | * @phpstan-return static<TKey,T> |
||
5577 | * @psalm-mutation-free |
||
5578 | */ |
||
5579 | 1 | public function repeat($times): self |
|
5591 | |||
5592 | /** |
||
5593 | * Replace a key with a new key/value pair. |
||
5594 | * |
||
5595 | * EXAMPLE: <code> |
||
5596 | * $arrayy = a([1 => 'foo', 2 => 'foo2', 3 => 'bar']); |
||
5597 | * $arrayy->replace(2, 'notfoo', 'notbar'); // Arrayy[1 => 'foo', 'notfoo' => 'notbar', 3 => 'bar'] |
||
5598 | * </code> |
||
5599 | * |
||
5600 | * @param mixed $oldKey |
||
5601 | * @param mixed $newKey |
||
5602 | * @param mixed $newValue |
||
5603 | * |
||
5604 | * @return static |
||
5605 | * <p>(Immutable)</p> |
||
5606 | * |
||
5607 | * @phpstan-return static<TKey,T> |
||
5608 | * @psalm-mutation-free |
||
5609 | */ |
||
5610 | 5 | public function replace($oldKey, $newKey, $newValue): self |
|
5620 | |||
5621 | /** |
||
5622 | * Create an array using the current array as values and the other array as keys. |
||
5623 | * |
||
5624 | * EXAMPLE: <code> |
||
5625 | * $firstArray = [ |
||
5626 | * 1 => 'one', |
||
5627 | * 2 => 'two', |
||
5628 | * 3 => 'three', |
||
5629 | * ]; |
||
5630 | * $secondArray = [ |
||
5631 | * 'one' => 1, |
||
5632 | * 1 => 'one', |
||
5633 | * 2 => 2, |
||
5634 | * ]; |
||
5635 | * $arrayy = a($firstArray); |
||
5636 | * $arrayy->replaceAllKeys($secondArray); // Arrayy[1 => "one", 'one' => "two", 2 => "three"] |
||
5637 | * </code> |
||
5638 | * |
||
5639 | * @param int[]|string[] $keys <p>An array of keys.</p> |
||
5640 | * |
||
5641 | * @return static |
||
5642 | * <p>(Immutable) Arrayy object with keys from the other array, empty Arrayy object if the number of elements |
||
5643 | * for each array isn't equal or if the arrays are empty. |
||
5644 | * </p> |
||
5645 | * |
||
5646 | * @phpstan-param array<array-key,TKey> $keys |
||
5647 | * @phpstan-return static<TKey,T> |
||
5648 | * @psalm-mutation-free |
||
5649 | */ |
||
5650 | 2 | View Code Duplication | public function replaceAllKeys(array $keys): self |
5663 | |||
5664 | /** |
||
5665 | * Create an array using the current array as keys and the other array as values. |
||
5666 | * |
||
5667 | * EXAMPLE: <code> |
||
5668 | * $firstArray = [ |
||
5669 | * 1 => 'one', |
||
5670 | * 2 => 'two', |
||
5671 | * 3 => 'three', |
||
5672 | * ]; |
||
5673 | * $secondArray = [ |
||
5674 | * 'one' => 1, |
||
5675 | * 1 => 'one', |
||
5676 | * 2 => 2, |
||
5677 | * ]; |
||
5678 | * $arrayy = a($firstArray); |
||
5679 | * $arrayy->replaceAllValues($secondArray); // Arrayy['one' => 1, 'two' => 'one', 'three' => 2] |
||
5680 | * </code> |
||
5681 | * |
||
5682 | * @param array $array <p>An array of values.</p> |
||
5683 | * |
||
5684 | * @return static |
||
5685 | * <p>(Immutable) Arrayy object with values from the other array, empty Arrayy object if the number of elements |
||
5686 | * for each array isn't equal or if the arrays are empty. |
||
5687 | * </p> |
||
5688 | * |
||
5689 | * @phpstan-param array<array-key,T> $array |
||
5690 | * @phpstan-return static<TKey,T> |
||
5691 | * @psalm-mutation-free |
||
5692 | */ |
||
5693 | 2 | View Code Duplication | public function replaceAllValues(array $array): self |
5706 | |||
5707 | /** |
||
5708 | * Replace the keys in an array with another set. |
||
5709 | * |
||
5710 | * EXAMPLE: <code> |
||
5711 | * a([1 => 'bar', 'foo' => 'foo'])->replaceKeys([1 => 2, 'foo' => 'replaced']); // Arrayy[2 => 'bar', 'replaced' => 'foo'] |
||
5712 | * </code> |
||
5713 | * |
||
5714 | * @param array $keys <p>An array of keys matching the array's size.</p> |
||
5715 | * |
||
5716 | * @return static |
||
5717 | * <p>(Immutable)</p> |
||
5718 | * |
||
5719 | * @phpstan-param array<array-key,TKey> $keys |
||
5720 | * @phpstan-return static<TKey,T> |
||
5721 | * @psalm-mutation-free |
||
5722 | */ |
||
5723 | 1 | View Code Duplication | public function replaceKeys(array $keys): self |
5737 | |||
5738 | /** |
||
5739 | * Replace the first matched value in an array. |
||
5740 | * |
||
5741 | * EXAMPLE: <code> |
||
5742 | * $testArray = ['bar', 'foo' => 'foo', 'foobar' => 'foobar']; |
||
5743 | * a($testArray)->replaceOneValue('foo', 'replaced'); // Arrayy['bar', 'foo' => 'replaced', 'foobar' => 'foobar'] |
||
5744 | * </code> |
||
5745 | * |
||
5746 | * @param mixed $search <p>The value to replace.</p> |
||
5747 | * @param mixed $replacement <p>The value to replace.</p> |
||
5748 | * |
||
5749 | * @return static |
||
5750 | * <p>(Immutable)</p> |
||
5751 | * |
||
5752 | * @phpstan-return static<TKey,T> |
||
5753 | * @psalm-mutation-free |
||
5754 | */ |
||
5755 | 3 | public function replaceOneValue($search, $replacement = ''): self |
|
5770 | |||
5771 | /** |
||
5772 | * Replace values in the current array. |
||
5773 | * |
||
5774 | * EXAMPLE: <code> |
||
5775 | * $testArray = ['bar', 'foo' => 'foo', 'foobar' => 'foobar']; |
||
5776 | * a($testArray)->replaceValues('foo', 'replaced'); // Arrayy['bar', 'foo' => 'replaced', 'foobar' => 'replacedbar'] |
||
5777 | * </code> |
||
5778 | * |
||
5779 | * @param string $search <p>The value to replace.</p> |
||
5780 | * @param string $replacement <p>What to replace it with.</p> |
||
5781 | * |
||
5782 | * @return static |
||
5783 | * <p>(Immutable)</p> |
||
5784 | * |
||
5785 | * @phpstan-return static<TKey,T> |
||
5786 | * @psalm-mutation-free |
||
5787 | */ |
||
5788 | 1 | public function replaceValues($search, $replacement = ''): self |
|
5797 | |||
5798 | /** |
||
5799 | * Get the last elements from index $from until the end of this array. |
||
5800 | * |
||
5801 | * EXAMPLE: <code> |
||
5802 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->rest(2); // Arrayy[0 => 'lall'] |
||
5803 | * </code> |
||
5804 | * |
||
5805 | * @param int $from |
||
5806 | * |
||
5807 | * @return static |
||
5808 | * <p>(Immutable)</p> |
||
5809 | * |
||
5810 | * @phpstan-return static<TKey,T> |
||
5811 | * @psalm-mutation-free |
||
5812 | */ |
||
5813 | 15 | View Code Duplication | public function rest(int $from = 1): self |
5823 | |||
5824 | /** |
||
5825 | * Return the array in the reverse order. |
||
5826 | * |
||
5827 | * EXAMPLE: <code> |
||
5828 | * a([1, 2, 3])->reverse(); // self[3, 2, 1] |
||
5829 | * </code> |
||
5830 | * |
||
5831 | * @return $this |
||
5832 | * <p>(Mutable) Return this Arrayy object.</p> |
||
5833 | * |
||
5834 | * @phpstan-return static<TKey,T> |
||
5835 | */ |
||
5836 | 9 | public function reverse(): self |
|
5844 | |||
5845 | /** |
||
5846 | * Sort an array in reverse order. |
||
5847 | * |
||
5848 | * @param int $sort_flags [optional] <p> |
||
5849 | * You may modify the behavior of the sort using the optional |
||
5850 | * parameter sort_flags, for details |
||
5851 | * see sort. |
||
5852 | * </p> |
||
5853 | * |
||
5854 | * @return $this |
||
5855 | * <p>(Mutable) Return this Arrayy object.</p> |
||
5856 | * |
||
5857 | * @phpstan-return static<TKey,T> |
||
5858 | */ |
||
5859 | 4 | public function rsort(int $sort_flags = 0): self |
|
5867 | |||
5868 | /** |
||
5869 | * Sort an array in reverse order. |
||
5870 | * |
||
5871 | * @param int $sort_flags [optional] <p> |
||
5872 | * You may modify the behavior of the sort using the optional |
||
5873 | * parameter sort_flags, for details |
||
5874 | * see sort. |
||
5875 | * </p> |
||
5876 | * |
||
5877 | * @return $this |
||
5878 | * <p>(Immutable) Return this Arrayy object.</p> |
||
5879 | * |
||
5880 | * @phpstan-return static<TKey,T> |
||
5881 | * @psalm-mutation-free |
||
5882 | */ |
||
5883 | 4 | public function rsortImmutable(int $sort_flags = 0): self |
|
5894 | |||
5895 | /** |
||
5896 | * Search for the first index of the current array via $value. |
||
5897 | * |
||
5898 | * EXAMPLE: <code> |
||
5899 | * a(['fòô' => 'bàř', 'lall' => 'bàř'])->searchIndex('bàř'); // Arrayy[0 => 'fòô'] |
||
5900 | * </code> |
||
5901 | * |
||
5902 | * @param mixed $value |
||
5903 | * |
||
5904 | * @return false|float|int|string |
||
5905 | * <p>Will return <b>FALSE</b> if the value can't be found.</p> |
||
5906 | * @psalm-mutation-free |
||
5907 | */ |
||
5908 | 21 | public function searchIndex($value) |
|
5918 | |||
5919 | /** |
||
5920 | * Search for the value of the current array via $index. |
||
5921 | * |
||
5922 | * EXAMPLE: <code> |
||
5923 | * a(['fòô' => 'bàř'])->searchValue('fòô'); // Arrayy[0 => 'bàř'] |
||
5924 | * </code> |
||
5925 | * |
||
5926 | * @param mixed $index |
||
5927 | * |
||
5928 | * @return static |
||
5929 | * <p>(Immutable) Will return a empty Arrayy if the value wasn't found.</p> |
||
5930 | * |
||
5931 | * @phpstan-return static<TKey,T> |
||
5932 | * @psalm-mutation-free |
||
5933 | */ |
||
5934 | 9 | public function searchValue($index): self |
|
5964 | |||
5965 | /** |
||
5966 | * Set a value for the current array (optional using dot-notation). |
||
5967 | * |
||
5968 | * EXAMPLE: <code> |
||
5969 | * $arrayy = a(['Lars' => ['lastname' => 'Moelleken']]); |
||
5970 | * $arrayy->set('Lars.lastname', 'Müller'); // Arrayy['Lars', ['lastname' => 'Müller']]] |
||
5971 | * </code> |
||
5972 | * |
||
5973 | * @param string $key <p>The key to set.</p> |
||
5974 | * @param mixed $value <p>Its value.</p> |
||
5975 | * |
||
5976 | * @return $this |
||
5977 | * <p>(Mutable) Return this Arrayy object.</p> |
||
5978 | * |
||
5979 | * @phpstan-param TKey $key |
||
5980 | * @phpstan-param T $value |
||
5981 | * @phpstan-return static<TKey,T> |
||
5982 | */ |
||
5983 | 28 | public function set($key, $value): self |
|
5989 | |||
5990 | /** |
||
5991 | * Get a value from a array and set it if it was not. |
||
5992 | * |
||
5993 | * WARNING: this method only set the value, if the $key is not already set |
||
5994 | * |
||
5995 | * EXAMPLE: <code> |
||
5996 | * $arrayy = a([1 => 1, 2 => 2, 3 => 3]); |
||
5997 | * $arrayy->setAndGet(1, 4); // 1 |
||
5998 | * $arrayy->setAndGet(0, 4); // 4 |
||
5999 | * </code> |
||
6000 | * |
||
6001 | * @param mixed $key <p>The key</p> |
||
6002 | * @param mixed $fallback <p>The default value to set if it isn't.</p> |
||
6003 | * |
||
6004 | * @return mixed |
||
6005 | * <p>(Mutable)</p> |
||
6006 | */ |
||
6007 | 11 | public function setAndGet($key, $fallback = null) |
|
6018 | |||
6019 | /** |
||
6020 | * Shifts a specified value off the beginning of array. |
||
6021 | * |
||
6022 | * @return mixed |
||
6023 | * <p>(Mutable) A shifted element from the current array.</p> |
||
6024 | */ |
||
6025 | 5 | public function shift() |
|
6031 | |||
6032 | /** |
||
6033 | * Shuffle the current array. |
||
6034 | * |
||
6035 | * EXAMPLE: <code> |
||
6036 | * a([1 => 'bar', 'foo' => 'foo'])->shuffle(); // e.g.: Arrayy[['foo' => 'foo', 1 => 'bar']] |
||
6037 | * </code> |
||
6038 | * |
||
6039 | * @param bool $secure <p>using a CSPRNG | @see https://paragonie.com/b/JvICXzh_jhLyt4y3</p> |
||
6040 | * @param array|null $array [optional] |
||
6041 | * |
||
6042 | * @return static |
||
6043 | * <p>(Immutable)</p> |
||
6044 | * |
||
6045 | * @phpstan-param array<TKey,T> $array |
||
6046 | * @phpstan-return static<TKey,T> |
||
6047 | * |
||
6048 | * @noinspection BadExceptionsProcessingInspection |
||
6049 | * @noinspection NonSecureShuffleUsageInspection |
||
6050 | */ |
||
6051 | 2 | public function shuffle(bool $secure = false, array $array = null): self |
|
6093 | |||
6094 | /** |
||
6095 | * Count the values from the current array. |
||
6096 | * |
||
6097 | * alias: for "Arrayy->count()" |
||
6098 | * |
||
6099 | * @param int $mode |
||
6100 | * |
||
6101 | * @return int |
||
6102 | */ |
||
6103 | 20 | public function size(int $mode = \COUNT_NORMAL): int |
|
6107 | |||
6108 | /** |
||
6109 | * Checks whether array has exactly $size items. |
||
6110 | * |
||
6111 | * @param int $size |
||
6112 | * |
||
6113 | * @return bool |
||
6114 | */ |
||
6115 | 1 | public function sizeIs(int $size): bool |
|
6131 | |||
6132 | /** |
||
6133 | * Checks whether array has between $fromSize to $toSize items. $toSize can be |
||
6134 | * smaller than $fromSize. |
||
6135 | * |
||
6136 | * @param int $fromSize |
||
6137 | * @param int $toSize |
||
6138 | * |
||
6139 | * @return bool |
||
6140 | */ |
||
6141 | 1 | public function sizeIsBetween(int $fromSize, int $toSize): bool |
|
6161 | |||
6162 | /** |
||
6163 | * Checks whether array has more than $size items. |
||
6164 | * |
||
6165 | * @param int $size |
||
6166 | * |
||
6167 | * @return bool |
||
6168 | */ |
||
6169 | 1 | View Code Duplication | public function sizeIsGreaterThan(int $size): bool |
6183 | |||
6184 | /** |
||
6185 | * Checks whether array has less than $size items. |
||
6186 | * |
||
6187 | * @param int $size |
||
6188 | * |
||
6189 | * @return bool |
||
6190 | */ |
||
6191 | 1 | View Code Duplication | public function sizeIsLessThan(int $size): bool |
6205 | |||
6206 | /** |
||
6207 | * Counts all elements in an array, or something in an object. |
||
6208 | * |
||
6209 | * <p> |
||
6210 | * For objects, if you have SPL installed, you can hook into count() by implementing interface {@see Countable}. |
||
6211 | * The interface has exactly one method, {@see Countable::count()}, which returns the return value for the count() |
||
6212 | * function. Please see the {@see Array} section of the manual for a detailed explanation of how arrays are |
||
6213 | * implemented and used in PHP. |
||
6214 | * </p> |
||
6215 | * |
||
6216 | * @return int |
||
6217 | * <p> |
||
6218 | * The number of elements in var, which is |
||
6219 | * typically an array, since anything else will have one |
||
6220 | * element. |
||
6221 | * </p> |
||
6222 | * <p> |
||
6223 | * If var is not an array or an object with |
||
6224 | * implemented Countable interface, |
||
6225 | * 1 will be returned. |
||
6226 | * There is one exception, if var is &null;, |
||
6227 | * 0 will be returned. |
||
6228 | * </p> |
||
6229 | * <p> |
||
6230 | * Caution: count may return 0 for a variable that isn't set, |
||
6231 | * but it may also return 0 for a variable that has been initialized with an |
||
6232 | * empty array. Use isset to test if a variable is set. |
||
6233 | * </p> |
||
6234 | */ |
||
6235 | 10 | public function sizeRecursive(): int |
|
6239 | |||
6240 | /** |
||
6241 | * Extract a slice of the array. |
||
6242 | * |
||
6243 | * @param int $offset <p>Slice begin index.</p> |
||
6244 | * @param int|null $length <p>Length of the slice.</p> |
||
6245 | * @param bool $preserveKeys <p>Whether array keys are preserved or no.</p> |
||
6246 | * |
||
6247 | * @return static |
||
6248 | * <p>(Immutable) A slice of the original array with length $length.</p> |
||
6249 | * |
||
6250 | * @phpstan-return static<TKey,T> |
||
6251 | * @psalm-mutation-free |
||
6252 | */ |
||
6253 | 5 | public function slice(int $offset, int $length = null, bool $preserveKeys = false) |
|
6266 | |||
6267 | /** |
||
6268 | * Sort the current array and optional you can keep the keys. |
||
6269 | * |
||
6270 | * EXAMPLE: <code> |
||
6271 | * a(3 => 'd', 2 => 'f', 0 => 'a')->sort(SORT_ASC, SORT_NATURAL, false); // Arrayy[0 => 'a', 1 => 'd', 2 => 'f'] |
||
6272 | * </code> |
||
6273 | * |
||
6274 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
6275 | * @param int $strategy <p>sort_flags => use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
6276 | * <strong>SORT_NATURAL</strong></p> |
||
6277 | * @param bool $keepKeys |
||
6278 | * |
||
6279 | * @return static |
||
6280 | * <p>(Mutable) Return this Arrayy object.</p> |
||
6281 | * |
||
6282 | * @phpstan-return static<int|TKey,T> |
||
6283 | */ |
||
6284 | 20 | public function sort( |
|
6298 | |||
6299 | /** |
||
6300 | * Sort the current array and optional you can keep the keys. |
||
6301 | * |
||
6302 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
6303 | * @param int $strategy <p>sort_flags => use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
6304 | * <strong>SORT_NATURAL</strong></p> |
||
6305 | * @param bool $keepKeys |
||
6306 | * |
||
6307 | * @return static |
||
6308 | * <p>(Immutable) Return this Arrayy object.</p> |
||
6309 | * |
||
6310 | * @phpstan-return static<int|TKey,T> |
||
6311 | */ |
||
6312 | 12 | public function sortImmutable( |
|
6328 | |||
6329 | /** |
||
6330 | * Sort the current array by key. |
||
6331 | * |
||
6332 | * EXAMPLE: <code> |
||
6333 | * a([1 => 2, 0 => 1])->sortKeys(\SORT_ASC); // Arrayy[0 => 1, 1 => 2] |
||
6334 | * </code> |
||
6335 | * |
||
6336 | * @see http://php.net/manual/en/function.ksort.php |
||
6337 | * @see http://php.net/manual/en/function.krsort.php |
||
6338 | * |
||
6339 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
6340 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
6341 | * <strong>SORT_NATURAL</strong></p> |
||
6342 | * |
||
6343 | * @return $this |
||
6344 | * <p>(Mutable) Return this Arrayy object.</p> |
||
6345 | * |
||
6346 | * @phpstan-return static<TKey,T> |
||
6347 | */ |
||
6348 | 18 | public function sortKeys( |
|
6358 | |||
6359 | /** |
||
6360 | * Sort the current array by key. |
||
6361 | * |
||
6362 | * @see http://php.net/manual/en/function.ksort.php |
||
6363 | * @see http://php.net/manual/en/function.krsort.php |
||
6364 | * |
||
6365 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
6366 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
6367 | * <strong>SORT_NATURAL</strong></p> |
||
6368 | * |
||
6369 | * @return $this |
||
6370 | * <p>(Immutable) Return this Arrayy object.</p> |
||
6371 | * |
||
6372 | * @phpstan-return static<TKey,T> |
||
6373 | * @psalm-mutation-free |
||
6374 | */ |
||
6375 | 8 | public function sortKeysImmutable( |
|
6388 | |||
6389 | /** |
||
6390 | * Sort the current array by value. |
||
6391 | * |
||
6392 | * EXAMPLE: <code> |
||
6393 | * a(3 => 'd', 2 => 'f', 0 => 'a')->sortValueKeepIndex(SORT_ASC, SORT_REGULAR); // Arrayy[0 => 'a', 3 => 'd', 2 => 'f'] |
||
6394 | * </code> |
||
6395 | * |
||
6396 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
6397 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
6398 | * <strong>SORT_NATURAL</strong></p> |
||
6399 | * |
||
6400 | * @return static |
||
6401 | * <p>(Mutable)</p> |
||
6402 | * |
||
6403 | * @phpstan-return static<int|TKey,T> |
||
6404 | */ |
||
6405 | 1 | public function sortValueKeepIndex( |
|
6411 | |||
6412 | /** |
||
6413 | * Sort the current array by value. |
||
6414 | * |
||
6415 | * EXAMPLE: <code> |
||
6416 | * a(3 => 'd', 2 => 'f', 0 => 'a')->sortValueNewIndex(SORT_ASC, SORT_NATURAL); // Arrayy[0 => 'a', 1 => 'd', 2 => 'f'] |
||
6417 | * </code> |
||
6418 | * |
||
6419 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
6420 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
6421 | * <strong>SORT_NATURAL</strong></p> |
||
6422 | * |
||
6423 | * @return static |
||
6424 | * <p>(Mutable)</p> |
||
6425 | * |
||
6426 | * @phpstan-return static<int|TKey,T> |
||
6427 | */ |
||
6428 | 1 | public function sortValueNewIndex($direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
6432 | |||
6433 | /** |
||
6434 | * Sort a array by value or by a closure. |
||
6435 | * |
||
6436 | * - If the sorter is null, the array is sorted naturally. |
||
6437 | * - Associative (string) keys will be maintained, but numeric keys will be re-indexed. |
||
6438 | * |
||
6439 | * EXAMPLE: <code> |
||
6440 | * $testArray = range(1, 5); |
||
6441 | * $under = a($testArray)->sorter( |
||
6442 | * function ($value) { |
||
6443 | * return $value % 2 === 0; |
||
6444 | * } |
||
6445 | * ); |
||
6446 | * var_dump($under); // Arrayy[1, 3, 5, 2, 4] |
||
6447 | * </code> |
||
6448 | * |
||
6449 | * @param callable|mixed|null $sorter |
||
6450 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or |
||
6451 | * <strong>SORT_DESC</strong></p> |
||
6452 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
6453 | * <strong>SORT_NATURAL</strong></p> |
||
6454 | * |
||
6455 | * @return static |
||
6456 | * <p>(Immutable)</p> |
||
6457 | * |
||
6458 | * @pslam-param callable|T|null $sorter |
||
6459 | * @phpstan-return static<TKey,T> |
||
6460 | * @psalm-mutation-free |
||
6461 | */ |
||
6462 | 1 | public function sorter($sorter = null, $direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
6503 | |||
6504 | /** |
||
6505 | * @param int $offset |
||
6506 | * @param int|null $length |
||
6507 | * @param array $replacement |
||
6508 | * |
||
6509 | * @return static |
||
6510 | * <p>(Immutable)</p> |
||
6511 | * |
||
6512 | * @phpstan-param array<mixed,T> $replacement |
||
6513 | * @phpstan-return static<TKey,T> |
||
6514 | * @psalm-mutation-free |
||
6515 | */ |
||
6516 | 1 | public function splice(int $offset, int $length = null, $replacement = []): self |
|
6533 | |||
6534 | /** |
||
6535 | * Split an array in the given amount of pieces. |
||
6536 | * |
||
6537 | * EXAMPLE: <code> |
||
6538 | * a(['a' => 1, 'b' => 2])->split(2, true); // Arrayy[['a' => 1], ['b' => 2]] |
||
6539 | * </code> |
||
6540 | * |
||
6541 | * @param int $numberOfPieces |
||
6542 | * @param bool $keepKeys |
||
6543 | * |
||
6544 | * @return static |
||
6545 | * <p>(Immutable)</p> |
||
6546 | * |
||
6547 | * @phpstan-return static<TKey,T> |
||
6548 | * @psalm-mutation-free |
||
6549 | */ |
||
6550 | 1 | public function split(int $numberOfPieces = 2, bool $keepKeys = false): self |
|
6606 | |||
6607 | /** |
||
6608 | * Strip all empty items from the current array. |
||
6609 | * |
||
6610 | * EXAMPLE: <code> |
||
6611 | * a(['a' => 1, 'b' => ''])->stripEmpty(); // Arrayy[['a' => 1]] |
||
6612 | * </code> |
||
6613 | * |
||
6614 | * @return static |
||
6615 | * <p>(Immutable)</p> |
||
6616 | * |
||
6617 | * @phpstan-return static<TKey,T> |
||
6618 | * @psalm-mutation-free |
||
6619 | */ |
||
6620 | 1 | public function stripEmpty(): self |
|
6632 | |||
6633 | /** |
||
6634 | * Swap two values between positions by key. |
||
6635 | * |
||
6636 | * EXAMPLE: <code> |
||
6637 | * a(['a' => 1, 'b' => ''])->swap('a', 'b'); // Arrayy[['a' => '', 'b' => 1]] |
||
6638 | * </code> |
||
6639 | * |
||
6640 | * @param int|string $swapA <p>a key in the array</p> |
||
6641 | * @param int|string $swapB <p>a key in the array</p> |
||
6642 | * |
||
6643 | * @return static |
||
6644 | * <p>(Immutable)</p> |
||
6645 | * |
||
6646 | * @phpstan-return static<TKey,T> |
||
6647 | * @psalm-mutation-free |
||
6648 | */ |
||
6649 | 1 | public function swap($swapA, $swapB): self |
|
6661 | |||
6662 | /** |
||
6663 | * Get the current array from the "Arrayy"-object. |
||
6664 | * alias for "getArray()" |
||
6665 | * |
||
6666 | * @param bool $convertAllArrayyElements <p> |
||
6667 | * Convert all Child-"Arrayy" objects also to arrays. |
||
6668 | * </p> |
||
6669 | * @param bool $preserveKeys <p> |
||
6670 | * e.g.: A generator maybe return the same key more then once, |
||
6671 | * so maybe you will ignore the keys. |
||
6672 | * </p> |
||
6673 | * |
||
6674 | * @return array |
||
6675 | * |
||
6676 | * @phpstan-return array<TKey,T> |
||
6677 | * @psalm-mutation-free |
||
6678 | */ |
||
6679 | 942 | public function toArray( |
|
6708 | |||
6709 | /** |
||
6710 | * Get the current array from the "Arrayy"-object as list. |
||
6711 | * |
||
6712 | * @param bool $convertAllArrayyElements <p> |
||
6713 | * Convert all Child-"Arrayy" objects also to arrays. |
||
6714 | * </p> |
||
6715 | * |
||
6716 | * @return array |
||
6717 | * |
||
6718 | * @phpstan-return list<mixed>|list<T> |
||
6719 | * @psalm-mutation-free |
||
6720 | */ |
||
6721 | 1 | public function toList(bool $convertAllArrayyElements = false): array |
|
6728 | |||
6729 | /** |
||
6730 | * Convert the current array to JSON. |
||
6731 | * |
||
6732 | * EXAMPLE: <code> |
||
6733 | * a(['bar', ['foo']])->toJson(); // '["bar",{"1":"foo"}]' |
||
6734 | * </code> |
||
6735 | * |
||
6736 | * @param int $options [optional] <p>e.g. JSON_PRETTY_PRINT</p> |
||
6737 | * @param int $depth [optional] <p>Set the maximum depth. Must be greater than zero.</p> |
||
6738 | * |
||
6739 | * @return string |
||
6740 | */ |
||
6741 | 12 | public function toJson(int $options = 0, int $depth = 512): string |
|
6750 | |||
6751 | /** |
||
6752 | * @param string[]|null $items [optional] |
||
6753 | * @param string[] $helper [optional] |
||
6754 | * |
||
6755 | * @return static|static[] |
||
6756 | * |
||
6757 | * @phpstan-return static<int, static<TKey,T>> |
||
6758 | */ |
||
6759 | 1 | public function toPermutation(array $items = null, array $helper = []): self |
|
6792 | |||
6793 | /** |
||
6794 | * Implodes array to a string with specified separator. |
||
6795 | * |
||
6796 | * @param string $separator [optional] <p>The element's separator.</p> |
||
6797 | * |
||
6798 | * @return string |
||
6799 | * <p>The string representation of array, separated by ",".</p> |
||
6800 | */ |
||
6801 | 19 | public function toString(string $separator = ','): string |
|
6805 | |||
6806 | /** |
||
6807 | * Return a duplicate free copy of the current array. |
||
6808 | * |
||
6809 | * EXAMPLE: <code> |
||
6810 | * a([2 => 1, 3 => 2, 4 => 2])->uniqueNewIndex(); // Arrayy[1, 2] |
||
6811 | * </code> |
||
6812 | * |
||
6813 | * @return $this |
||
6814 | * <p>(Mutable)</p> |
||
6815 | * |
||
6816 | * @phpstan-return static<int,T> |
||
6817 | */ |
||
6818 | 13 | public function uniqueNewIndex(): self |
|
6836 | |||
6837 | /** |
||
6838 | * Return a duplicate free copy of the current array. (with the old keys) |
||
6839 | * |
||
6840 | * EXAMPLE: <code> |
||
6841 | * a([2 => 1, 3 => 2, 4 => 2])->uniqueNewIndex(); // Arrayy[2 => 1, 3 => 2] |
||
6842 | * </code> |
||
6843 | * |
||
6844 | * @return $this |
||
6845 | * <p>(Mutable)</p> |
||
6846 | * |
||
6847 | * @phpstan-return static<TKey,T> |
||
6848 | */ |
||
6849 | 11 | public function uniqueKeepIndex(): self |
|
6875 | |||
6876 | /** |
||
6877 | * alias: for "Arrayy->uniqueNewIndex()" |
||
6878 | * |
||
6879 | * @return static |
||
6880 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
6881 | * |
||
6882 | * @see Arrayy::unique() |
||
6883 | * |
||
6884 | * @phpstan-return static<int,T> |
||
6885 | */ |
||
6886 | 13 | public function unique(): self |
|
6890 | |||
6891 | /** |
||
6892 | * Prepends one or more values to the beginning of array at once. |
||
6893 | * |
||
6894 | * @param mixed ...$args |
||
6895 | * |
||
6896 | * @return $this |
||
6897 | * <p>(Mutable) Return this Arrayy object, with prepended elements to the beginning of array.</p> |
||
6898 | * |
||
6899 | * @phpstan-param array<TKey,T> ...$args |
||
6900 | * @phpstan-return static<TKey,T> |
||
6901 | */ |
||
6902 | 6 | View Code Duplication | public function unshift(...$args): self |
6920 | |||
6921 | /** |
||
6922 | * Tests whether the given closure return something valid for all elements of this array. |
||
6923 | * |
||
6924 | * @param \Closure $closure the predicate |
||
6925 | * |
||
6926 | * @return bool |
||
6927 | * <p>TRUE, if the predicate yields TRUE for all elements, FALSE otherwise.</p> |
||
6928 | * |
||
6929 | * @phpstan-param \Closure(T=,TKey=):bool $closure |
||
6930 | */ |
||
6931 | 1 | View Code Duplication | public function validate(\Closure $closure): bool |
6941 | |||
6942 | /** |
||
6943 | * Get all values from a array. |
||
6944 | * |
||
6945 | * EXAMPLE: <code> |
||
6946 | * $arrayy = a([1 => 'foo', 2 => 'foo2', 3 => 'bar']); |
||
6947 | * $arrayyTmp->values(); // Arrayy[0 => 'foo', 1 => 'foo2', 2 => 'bar'] |
||
6948 | * </code> |
||
6949 | * |
||
6950 | * @return static |
||
6951 | * <p>(Immutable)</p> |
||
6952 | * |
||
6953 | * @phpstan-return static<TKey,T> |
||
6954 | * @psalm-mutation-free |
||
6955 | */ |
||
6956 | 2 | public function values(): self |
|
6969 | |||
6970 | /** |
||
6971 | * Apply the given function to every element in the array, discarding the results. |
||
6972 | * |
||
6973 | * EXAMPLE: <code> |
||
6974 | * $callable = function (&$value, $key) { |
||
6975 | * $value = $key; |
||
6976 | * }; |
||
6977 | * $arrayy = a([1, 2, 3]); |
||
6978 | * $arrayy->walk($callable); // Arrayy[0, 1, 2] |
||
6979 | * </code> |
||
6980 | * |
||
6981 | * @param callable $callable |
||
6982 | * @param bool $recursive [optional] <p>Whether array will be walked recursively or no</p> |
||
6983 | * @param mixed $userData [optional] <p> |
||
6984 | * If the optional $userData parameter is supplied, |
||
6985 | * it will be passed as the third parameter to the $callable. |
||
6986 | * </p> |
||
6987 | * |
||
6988 | * @return $this |
||
6989 | * <p>(Mutable) Return this Arrayy object, with modified elements.</p> |
||
6990 | * |
||
6991 | * @phpstan-return static<TKey,T> |
||
6992 | */ |
||
6993 | 12 | public function walk( |
|
7019 | |||
7020 | /** |
||
7021 | * Returns a collection of matching items. |
||
7022 | * |
||
7023 | * @param string $keyOrPropertyOrMethod the property or method to evaluate |
||
7024 | * @param mixed $value the value to match |
||
7025 | * |
||
7026 | * @throws \InvalidArgumentException if property or method is not defined |
||
7027 | * |
||
7028 | * @return static |
||
7029 | * |
||
7030 | * @phpstan-return static<TKey,T> |
||
7031 | */ |
||
7032 | 1 | public function where(string $keyOrPropertyOrMethod, $value): self |
|
7045 | |||
7046 | /** |
||
7047 | * Convert an array into a object. |
||
7048 | * |
||
7049 | * @param array $array |
||
7050 | * |
||
7051 | * @return \stdClass |
||
7052 | * |
||
7053 | * @phpstan-param array<int|string,mixed> $array |
||
7054 | */ |
||
7055 | 4 | final protected static function arrayToObject(array $array = []): \stdClass |
|
7074 | |||
7075 | /** |
||
7076 | * @param array|\Generator|null $input <p> |
||
7077 | * An array containing keys to return. |
||
7078 | * </p> |
||
7079 | * @param mixed|null $search_values [optional] <p> |
||
7080 | * If specified, then only keys containing these values are returned. |
||
7081 | * </p> |
||
7082 | * @param bool $strict [optional] <p> |
||
7083 | * Determines if strict comparison (===) should be used during the |
||
7084 | * search. |
||
7085 | * </p> |
||
7086 | * |
||
7087 | * @return array |
||
7088 | * <p>An array of all the keys in input.</p> |
||
7089 | * |
||
7090 | * @phpstan-param array<mixed>|null $input |
||
7091 | * @phpstan-return array<mixed> |
||
7092 | * @psalm-mutation-free |
||
7093 | */ |
||
7094 | 11 | protected function array_keys_recursive( |
|
7155 | |||
7156 | /** |
||
7157 | * @param mixed $path |
||
7158 | * @param callable $callable |
||
7159 | * @param array|null $currentOffset |
||
7160 | * |
||
7161 | * @return void |
||
7162 | * |
||
7163 | * @phpstan-param array<TKey,T>|null $currentOffset |
||
7164 | * @psalm-mutation-free |
||
7165 | */ |
||
7166 | 10 | protected function callAtPath($path, $callable, &$currentOffset = null) |
|
7195 | |||
7196 | /** |
||
7197 | * Extracts the value of the given property or method from the object. |
||
7198 | * |
||
7199 | * @param static $object <p>The object to extract the value from.</p> |
||
7200 | * @param string $keyOrPropertyOrMethod <p>The property or method for which the |
||
7201 | * value should be extracted.</p> |
||
7202 | * |
||
7203 | * @throws \InvalidArgumentException if the method or property is not defined |
||
7204 | * |
||
7205 | * @return mixed |
||
7206 | * <p>The value extracted from the specified property or method.</p> |
||
7207 | * |
||
7208 | * @phpstan-param self<TKey,T> $object |
||
7209 | */ |
||
7210 | 1 | final protected function extractValue(self $object, string $keyOrPropertyOrMethod) |
|
7232 | |||
7233 | /** |
||
7234 | * create a fallback for array |
||
7235 | * |
||
7236 | * 1. use the current array, if it's a array |
||
7237 | * 2. fallback to empty array, if there is nothing |
||
7238 | * 3. call "getArray()" on object, if there is a "Arrayy"-object |
||
7239 | * 4. call "createFromObject()" on object, if there is a "\Traversable"-object |
||
7240 | * 5. call "__toArray()" on object, if the method exists |
||
7241 | * 6. cast a string or object with "__toString()" into an array |
||
7242 | * 7. throw a "InvalidArgumentException"-Exception |
||
7243 | * |
||
7244 | * @param mixed $data |
||
7245 | * |
||
7246 | * @throws \InvalidArgumentException |
||
7247 | * |
||
7248 | * @return array |
||
7249 | * |
||
7250 | * @phpstan-return array<mixed>|array<TKey,T> |
||
7251 | */ |
||
7252 | 1213 | protected function fallbackForArray(&$data): array |
|
7262 | |||
7263 | /** |
||
7264 | * @param bool $preserveKeys <p> |
||
7265 | * e.g.: A generator maybe return the same key more then once, |
||
7266 | * so maybe you will ignore the keys. |
||
7267 | * </p> |
||
7268 | * |
||
7269 | * @return bool |
||
7270 | * |
||
7271 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
7272 | * @psalm-mutation-free :/ |
||
7273 | */ |
||
7274 | 1122 | protected function generatorToArray(bool $preserveKeys = true) |
|
7285 | |||
7286 | /** |
||
7287 | * Get correct PHP constant for direction. |
||
7288 | * |
||
7289 | * @param int|string $direction |
||
7290 | * |
||
7291 | * @return int |
||
7292 | * @psalm-mutation-free |
||
7293 | */ |
||
7294 | 43 | protected function getDirection($direction): int |
|
7316 | |||
7317 | /** |
||
7318 | * @return TypeCheckInterface[] |
||
7319 | * |
||
7320 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
7321 | */ |
||
7322 | 24 | protected function getPropertiesFromPhpDoc() |
|
7377 | |||
7378 | /** |
||
7379 | * @param mixed $glue |
||
7380 | * @param mixed $pieces |
||
7381 | * @param bool $useKeys |
||
7382 | * |
||
7383 | * @return string |
||
7384 | * |
||
7385 | * @phpstan-param scalar|object|self<TKey|T>|array<TKey,T> $pieces |
||
7386 | * @psalm-mutation-free |
||
7387 | */ |
||
7388 | 36 | protected function implode_recursive( |
|
7425 | |||
7426 | /** |
||
7427 | * @param mixed $needle <p> |
||
7428 | * The searched value. |
||
7429 | * </p> |
||
7430 | * <p> |
||
7431 | * If needle is a string, the comparison is done |
||
7432 | * in a case-sensitive manner. |
||
7433 | * </p> |
||
7434 | * @param array|\Generator|null $haystack <p> |
||
7435 | * The array. |
||
7436 | * </p> |
||
7437 | * @param bool $strict [optional] <p> |
||
7438 | * If the third parameter strict is set to true |
||
7439 | * then the in_array function will also check the |
||
7440 | * types of the |
||
7441 | * needle in the haystack. |
||
7442 | * </p> |
||
7443 | * |
||
7444 | * @return bool |
||
7445 | * <p>true if needle is found in the array, false otherwise</p> |
||
7446 | * |
||
7447 | * @phpstan-param (array&T)|array<TKey,T>|\Generator<TKey,T>|null $haystack |
||
7448 | * @psalm-mutation-free |
||
7449 | */ |
||
7450 | 18 | protected function in_array_recursive($needle, $haystack = null, $strict = true): bool |
|
7475 | |||
7476 | /** |
||
7477 | * @param mixed $data |
||
7478 | * |
||
7479 | * @return array<mixed>|null |
||
7480 | */ |
||
7481 | 1213 | protected function internalGetArray(&$data) |
|
7532 | |||
7533 | /** |
||
7534 | * Internal mechanics of remove method. |
||
7535 | * |
||
7536 | * @param mixed $key |
||
7537 | * |
||
7538 | * @return bool |
||
7539 | */ |
||
7540 | 22 | protected function internalRemove($key): bool |
|
7573 | |||
7574 | /** |
||
7575 | * Internal mechanic of set method. |
||
7576 | * |
||
7577 | * @param int|string|null $key |
||
7578 | * @param mixed $value |
||
7579 | * @param bool $checkProperties |
||
7580 | * |
||
7581 | * @return bool |
||
7582 | */ |
||
7583 | 1063 | protected function internalSet( |
|
7642 | |||
7643 | /** |
||
7644 | * Convert a object into an array. |
||
7645 | * |
||
7646 | * @param mixed|object $object |
||
7647 | * |
||
7648 | * @return array|mixed |
||
7649 | * |
||
7650 | * @psalm-mutation-free |
||
7651 | */ |
||
7652 | 5 | protected static function objectToArray($object) |
|
7665 | |||
7666 | /** |
||
7667 | * @param array $data |
||
7668 | * @param bool $checkPropertiesInConstructor |
||
7669 | * |
||
7670 | * @return void |
||
7671 | * |
||
7672 | * @phpstan-param array<mixed,T> $data |
||
7673 | */ |
||
7674 | 1211 | protected function setInitialValuesAndProperties(array &$data, bool $checkPropertiesInConstructor) |
|
7719 | |||
7720 | /** |
||
7721 | * sorting keys |
||
7722 | * |
||
7723 | * @param array $elements |
||
7724 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
7725 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
7726 | * <strong>SORT_NATURAL</strong></p> |
||
7727 | * |
||
7728 | * @return $this |
||
7729 | * <p>(Mutable) Return this Arrayy object.</p> |
||
7730 | * |
||
7731 | * @phpstan-param array<mixed|TKey,T> $elements |
||
7732 | * @phpstan-return static<TKey,T> |
||
7733 | */ |
||
7734 | 18 | protected function sorterKeys( |
|
7755 | |||
7756 | /** |
||
7757 | * @param array $elements <p>Warning: used as reference</p> |
||
7758 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
7759 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
7760 | * <strong>SORT_NATURAL</strong></p> |
||
7761 | * @param bool $keepKeys |
||
7762 | * |
||
7763 | * @return $this |
||
7764 | * <p>(Mutable) Return this Arrayy object.</p> |
||
7765 | * |
||
7766 | * @phpstan-param array<mixed|TKey,T> $elements |
||
7767 | * @phpstan-return static<int|TKey,T> |
||
7768 | */ |
||
7769 | 24 | protected function sorting( |
|
7803 | |||
7804 | /** |
||
7805 | * @param array $array |
||
7806 | * |
||
7807 | * @return array |
||
7808 | * |
||
7809 | * @psalm-mutation-free |
||
7810 | */ |
||
7811 | 25 | private function getArrayRecursiveHelperArrayy(array $array) |
|
7833 | |||
7834 | /** |
||
7835 | * @param int|string|null $key |
||
7836 | * @param mixed $value |
||
7837 | * |
||
7838 | * @return void |
||
7839 | */ |
||
7840 | 117 | private function checkType($key, $value) |
|
7858 | } |
||
7859 |
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..