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 |
||
| 26 | class Arrayy extends \ArrayObject implements \IteratorAggregate, \ArrayAccess, \Serializable, \JsonSerializable, \Countable |
||
| 27 | { |
||
| 28 | const ARRAYY_HELPER_TYPES_FOR_ALL_PROPERTIES = '!!!!Arrayy_Helper_Types_For_All_Properties!!!!'; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var array |
||
| 32 | * |
||
| 33 | * @psalm-var array<TKey,T> |
||
| 34 | */ |
||
| 35 | protected $array = []; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @var \Arrayy\ArrayyRewindableGenerator|null |
||
| 39 | * |
||
| 40 | * @psalm-var \Arrayy\ArrayyRewindableGenerator<TKey,T>|null |
||
| 41 | */ |
||
| 42 | protected $generator; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var string |
||
| 46 | * |
||
| 47 | * @psalm-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>|\Arrayy\Type\TypeInterface|TypeCheckArray<int|string,TypeCheckInterface> |
||
| 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 | * @psalm-param class-string<\Arrayy\ArrayyIterator> $iteratorClass |
||
| 100 | */ |
||
| 101 | 1066 | public function __construct( |
|
| 102 | $data = [], |
||
| 103 | string $iteratorClass = ArrayyIterator::class, |
||
| 104 | bool $checkPropertiesInConstructor = true |
||
| 105 | ) { |
||
| 106 | 1066 | $data = $this->fallbackForArray($data); |
|
| 107 | |||
| 108 | // used only for serialize + unserialize, all other methods are overwritten |
||
| 109 | 1064 | parent::__construct([], 0, $iteratorClass); |
|
| 110 | |||
| 111 | 1064 | $this->setInitialValuesAndProperties($data, $checkPropertiesInConstructor); |
|
| 112 | |||
| 113 | 1057 | $this->setIteratorClass($iteratorClass); |
|
| 114 | 1057 | } |
|
| 115 | |||
| 116 | /** |
||
| 117 | * Call object as function. |
||
| 118 | * |
||
| 119 | * @param mixed $key |
||
| 120 | * |
||
| 121 | * @return mixed |
||
| 122 | */ |
||
| 123 | 1 | public function __invoke($key = null) |
|
| 124 | { |
||
| 125 | 1 | if ($key !== null) { |
|
| 126 | 1 | $this->generatorToArray(); |
|
| 127 | |||
| 128 | 1 | return $this->array[$key] ?? false; |
|
| 129 | } |
||
| 130 | |||
| 131 | return $this->getArray(); |
||
| 132 | } |
||
| 133 | |||
| 134 | /** |
||
| 135 | * Whether or not an element exists by key. |
||
| 136 | * |
||
| 137 | * @param mixed $key |
||
| 138 | * |
||
| 139 | * @return bool |
||
| 140 | * <p>True is the key/index exists, otherwise false.</p> |
||
| 141 | */ |
||
| 142 | public function __isset($key): bool |
||
| 146 | |||
| 147 | /** |
||
| 148 | * Assigns a value to the specified element. |
||
| 149 | * |
||
| 150 | * @param mixed $key |
||
| 151 | * @param mixed $value |
||
| 152 | * |
||
| 153 | * @return void |
||
| 154 | */ |
||
| 155 | 2 | public function __set($key, $value) |
|
| 156 | { |
||
| 157 | 2 | $this->internalSet($key, $value); |
|
| 158 | 2 | } |
|
| 159 | |||
| 160 | /** |
||
| 161 | * magic to string |
||
| 162 | * |
||
| 163 | * @return string |
||
| 164 | */ |
||
| 165 | 15 | public function __toString(): string |
|
| 166 | { |
||
| 167 | 15 | return $this->toString(); |
|
| 168 | } |
||
| 169 | |||
| 170 | /** |
||
| 171 | * Unset element by key. |
||
| 172 | * |
||
| 173 | * @param mixed $key |
||
| 174 | */ |
||
| 175 | public function __unset($key) |
||
| 176 | { |
||
| 177 | $this->internalRemove($key); |
||
| 178 | } |
||
| 179 | |||
| 180 | /** |
||
| 181 | * Get a value by key. |
||
| 182 | * |
||
| 183 | * @param mixed $key |
||
| 184 | * |
||
| 185 | * @return mixed |
||
| 186 | * <p>Get a Value from the current array.</p> |
||
| 187 | */ |
||
| 188 | 4 | public function &__get($key) |
|
| 189 | { |
||
| 190 | 4 | $return = $this->get($key); |
|
| 191 | |||
| 192 | 4 | if (\is_array($return) === true) { |
|
| 193 | return static::create($return, $this->iteratorClass, false); |
||
| 194 | } |
||
| 195 | |||
| 196 | 4 | return $return; |
|
| 197 | } |
||
| 198 | |||
| 199 | /** |
||
| 200 | * alias: for "Arrayy->append()" |
||
| 201 | * |
||
| 202 | * @param mixed $value |
||
| 203 | * |
||
| 204 | * @return static |
||
| 205 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
| 206 | * |
||
| 207 | * @see Arrayy::append() |
||
| 208 | * |
||
| 209 | * @psalm-param T $value |
||
| 210 | * @psalm-return static<TKey,T> |
||
| 211 | */ |
||
| 212 | 3 | public function add($value) |
|
| 216 | |||
| 217 | /** |
||
| 218 | * Append a (key) + value to the current array. |
||
| 219 | * |
||
| 220 | * @param mixed $value |
||
| 221 | * @param mixed $key |
||
| 222 | * |
||
| 223 | * @return $this |
||
| 224 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
| 225 | * |
||
| 226 | * @psalm-param T $value |
||
| 227 | * @psalm-return $this<TKey,T> |
||
| 228 | */ |
||
| 229 | 13 | public function append($value, $key = null): self |
|
| 253 | |||
| 254 | /** |
||
| 255 | * Sort the entries by value. |
||
| 256 | * |
||
| 257 | * @param int $sort_flags [optional] <p> |
||
| 258 | * You may modify the behavior of the sort using the optional |
||
| 259 | * parameter sort_flags, for details |
||
| 260 | * see sort. |
||
| 261 | * </p> |
||
| 262 | * |
||
| 263 | * @return $this |
||
| 264 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 265 | * |
||
| 266 | * @psalm-return $this<TKey,T> |
||
| 267 | */ |
||
| 268 | 4 | public function asort(int $sort_flags = 0): self |
|
| 276 | |||
| 277 | /** |
||
| 278 | * Counts all elements in an array, or something in an object. |
||
| 279 | * |
||
| 280 | * <p> |
||
| 281 | * For objects, if you have SPL installed, you can hook into count() by implementing interface {@see Countable}. |
||
| 282 | * The interface has exactly one method, {@see Countable::count()}, which returns the return value for the count() |
||
| 283 | * function. Please see the {@see Array} section of the manual for a detailed explanation of how arrays are |
||
| 284 | * implemented and used in PHP. |
||
| 285 | * </p> |
||
| 286 | * |
||
| 287 | * @see http://php.net/manual/en/function.count.php |
||
| 288 | * |
||
| 289 | * @param int $mode [optional] If the optional mode parameter is set to |
||
| 290 | * COUNT_RECURSIVE (or 1), count |
||
| 291 | * will recursively count the array. This is particularly useful for |
||
| 292 | * counting all the elements of a multidimensional array. count does not detect infinite recursion. |
||
| 293 | * |
||
| 294 | * @return int |
||
| 295 | * <p> |
||
| 296 | * The number of elements in var, which is |
||
| 297 | * typically an array, since anything else will have one |
||
| 298 | * element. |
||
| 299 | * </p> |
||
| 300 | * <p> |
||
| 301 | * If var is not an array or an object with |
||
| 302 | * implemented Countable interface, |
||
| 303 | * 1 will be returned. |
||
| 304 | * There is one exception, if var is &null;, |
||
| 305 | * 0 will be returned. |
||
| 306 | * </p> |
||
| 307 | * <p> |
||
| 308 | * Caution: count may return 0 for a variable that isn't set, |
||
| 309 | * but it may also return 0 for a variable that has been initialized with an |
||
| 310 | * empty array. Use isset to test if a variable is set. |
||
| 311 | * </p> |
||
| 312 | */ |
||
| 313 | 145 | public function count(int $mode = \COUNT_NORMAL): int |
|
| 325 | |||
| 326 | /** |
||
| 327 | * Exchange the array for another one. |
||
| 328 | * |
||
| 329 | * @param array|static $data |
||
| 330 | * |
||
| 331 | * @return array |
||
| 332 | * |
||
| 333 | * @psalm-param array<TKey,T>|self<TKey,T> $data |
||
| 334 | * @psalm-return array<TKey,T> |
||
| 335 | */ |
||
| 336 | 1 | public function exchangeArray($data): array |
|
| 342 | |||
| 343 | /** |
||
| 344 | * Creates a copy of the ArrayyObject. |
||
| 345 | * |
||
| 346 | * @return array |
||
| 347 | * |
||
| 348 | * @psalm-return array<TKey,T> |
||
| 349 | */ |
||
| 350 | 5 | public function getArrayCopy(): array |
|
| 356 | |||
| 357 | /** |
||
| 358 | * Returns a new iterator, thus implementing the \Iterator interface. |
||
| 359 | * |
||
| 360 | * @return \Iterator<mixed, mixed> |
||
|
|
|||
| 361 | * <p>An iterator for the values in the array.</p> |
||
| 362 | */ |
||
| 363 | 24 | public function getIterator(): \Iterator |
|
| 377 | |||
| 378 | /** |
||
| 379 | * Gets the iterator classname for the ArrayObject. |
||
| 380 | * |
||
| 381 | * @return string |
||
| 382 | * |
||
| 383 | * @psalm-return class-string |
||
| 384 | */ |
||
| 385 | 23 | public function getIteratorClass(): string |
|
| 389 | |||
| 390 | /** |
||
| 391 | * Sort the entries by key |
||
| 392 | * |
||
| 393 | * @param int $sort_flags [optional] <p> |
||
| 394 | * You may modify the behavior of the sort using the optional |
||
| 395 | * parameter sort_flags, for details |
||
| 396 | * see sort. |
||
| 397 | * </p> |
||
| 398 | * |
||
| 399 | * @return $this |
||
| 400 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 401 | * |
||
| 402 | * @psalm-return $this<TKey,T> |
||
| 403 | */ |
||
| 404 | 4 | public function ksort(int $sort_flags = 0): self |
|
| 412 | |||
| 413 | /** |
||
| 414 | * Sort an array using a case insensitive "natural order" algorithm |
||
| 415 | * |
||
| 416 | * @return $this |
||
| 417 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 418 | * |
||
| 419 | * @psalm-return $this<TKey,T> |
||
| 420 | */ |
||
| 421 | public function natcasesort(): self |
||
| 429 | |||
| 430 | /** |
||
| 431 | * Sort entries using a "natural order" algorithm |
||
| 432 | * |
||
| 433 | * @return $this |
||
| 434 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 435 | * |
||
| 436 | * @psalm-return $this<TKey,T> |
||
| 437 | */ |
||
| 438 | 1 | public function natsort(): self |
|
| 446 | |||
| 447 | /** |
||
| 448 | * Whether or not an offset exists. |
||
| 449 | * |
||
| 450 | * @param bool|int|string $offset |
||
| 451 | * |
||
| 452 | * @return bool |
||
| 453 | * |
||
| 454 | * @noinspection PhpSillyAssignmentInspection |
||
| 455 | */ |
||
| 456 | 130 | public function offsetExists($offset): bool |
|
| 457 | { |
||
| 458 | 130 | $this->generatorToArray(); |
|
| 459 | |||
| 460 | 130 | if ($this->array === []) { |
|
| 461 | 5 | return false; |
|
| 462 | } |
||
| 463 | |||
| 464 | // php cast "bool"-index into "int"-index |
||
| 465 | 125 | if ((bool) $offset === $offset) { |
|
| 466 | 1 | $offset = (int) $offset; |
|
| 467 | } |
||
| 468 | |||
| 469 | /** @var int|string $offset - hint for phpstan */ |
||
| 470 | 125 | $offset = $offset; |
|
| 471 | |||
| 472 | 125 | $tmpReturn = $this->keyExists($offset); |
|
| 473 | |||
| 474 | if ( |
||
| 475 | 125 | $tmpReturn === true |
|
| 476 | || |
||
| 477 | ( |
||
| 478 | 92 | $tmpReturn === false |
|
| 479 | && |
||
| 480 | 125 | \strpos((string) $offset, $this->pathSeparator) === false |
|
| 481 | ) |
||
| 482 | ) { |
||
| 483 | 123 | return $tmpReturn; |
|
| 484 | } |
||
| 485 | |||
| 486 | 3 | $offsetExists = false; |
|
| 487 | |||
| 488 | if ( |
||
| 489 | 3 | $this->pathSeparator |
|
| 490 | && |
||
| 491 | 3 | (string) $offset === $offset |
|
| 492 | && |
||
| 493 | 3 | \strpos($offset, $this->pathSeparator) !== false |
|
| 494 | ) { |
||
| 495 | 3 | $explodedPath = \explode($this->pathSeparator, (string) $offset); |
|
| 496 | 3 | if ($explodedPath !== false) { |
|
| 497 | 3 | $lastOffset = \array_pop($explodedPath); |
|
| 498 | 3 | if ($lastOffset !== null) { |
|
| 499 | 3 | $containerPath = \implode($this->pathSeparator, $explodedPath); |
|
| 500 | |||
| 501 | 3 | $this->callAtPath( |
|
| 502 | 3 | $containerPath, |
|
| 503 | 3 | static function ($container) use ($lastOffset, &$offsetExists) { |
|
| 504 | 3 | $offsetExists = \array_key_exists($lastOffset, $container); |
|
| 505 | 3 | } |
|
| 506 | ); |
||
| 507 | } |
||
| 508 | } |
||
| 509 | } |
||
| 510 | |||
| 511 | 3 | return $offsetExists; |
|
| 512 | } |
||
| 513 | |||
| 514 | /** |
||
| 515 | * Returns the value at specified offset. |
||
| 516 | * |
||
| 517 | * @param int|string $offset |
||
| 518 | * |
||
| 519 | * @return mixed |
||
| 520 | * <p>Will return null if the offset did not exists.</p> |
||
| 521 | */ |
||
| 522 | 101 | public function offsetGet($offset) |
|
| 526 | |||
| 527 | /** |
||
| 528 | * Assigns a value to the specified offset + check the type. |
||
| 529 | * |
||
| 530 | * @param int|string|null $offset |
||
| 531 | * @param mixed $value |
||
| 532 | * |
||
| 533 | * @return void |
||
| 534 | */ |
||
| 535 | 21 | public function offsetSet($offset, $value) |
|
| 553 | |||
| 554 | /** |
||
| 555 | * Unset an offset. |
||
| 556 | * |
||
| 557 | * @param int|string $offset |
||
| 558 | * |
||
| 559 | * @return void |
||
| 560 | */ |
||
| 561 | 12 | public function offsetUnset($offset) |
|
| 562 | { |
||
| 563 | 12 | $this->generatorToArray(); |
|
| 564 | |||
| 565 | 12 | if ($this->array === []) { |
|
| 566 | 3 | return; |
|
| 567 | } |
||
| 568 | |||
| 569 | 10 | if ($this->keyExists($offset)) { |
|
| 570 | 7 | unset($this->array[$offset]); |
|
| 571 | |||
| 572 | 7 | return; |
|
| 573 | } |
||
| 574 | |||
| 575 | if ( |
||
| 576 | 5 | $this->pathSeparator |
|
| 577 | && |
||
| 578 | 5 | (string) $offset === $offset |
|
| 579 | && |
||
| 580 | 5 | \strpos($offset, $this->pathSeparator) !== false |
|
| 581 | ) { |
||
| 582 | 2 | $path = \explode($this->pathSeparator, (string) $offset); |
|
| 583 | |||
| 584 | 2 | if ($path !== false) { |
|
| 585 | 2 | $pathToUnset = \array_pop($path); |
|
| 586 | |||
| 587 | 2 | $this->callAtPath( |
|
| 588 | 2 | \implode($this->pathSeparator, $path), |
|
| 589 | 2 | static function (&$offset) use ($pathToUnset) { |
|
| 590 | 2 | unset($offset[$pathToUnset]); |
|
| 591 | 2 | } |
|
| 592 | ); |
||
| 593 | } |
||
| 594 | } |
||
| 595 | |||
| 596 | 5 | unset($this->array[$offset]); |
|
| 597 | 5 | } |
|
| 598 | |||
| 599 | /** |
||
| 600 | * Serialize the current "Arrayy"-object. |
||
| 601 | * |
||
| 602 | * @return string |
||
| 603 | */ |
||
| 604 | 2 | public function serialize(): string |
|
| 614 | |||
| 615 | /** |
||
| 616 | * Sets the iterator classname for the current "Arrayy"-object. |
||
| 617 | * |
||
| 618 | * @param string $iteratorClass |
||
| 619 | * |
||
| 620 | * @throws \InvalidArgumentException |
||
| 621 | * |
||
| 622 | * @return void |
||
| 623 | * |
||
| 624 | * @psalm-param class-string<\Arrayy\ArrayyIterator> $iteratorClass |
||
| 625 | */ |
||
| 626 | 1057 | public function setIteratorClass($iteratorClass) |
|
| 645 | |||
| 646 | /** |
||
| 647 | * Sort the entries with a user-defined comparison function and maintain key association. |
||
| 648 | * |
||
| 649 | * @param callable $function |
||
| 650 | * |
||
| 651 | * @throws \InvalidArgumentException |
||
| 652 | * |
||
| 653 | * @return $this |
||
| 654 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 655 | * |
||
| 656 | * @psalm-return $this<TKey,T> |
||
| 657 | */ |
||
| 658 | View Code Duplication | public function uasort($function): self |
|
| 670 | |||
| 671 | /** |
||
| 672 | * Sort the entries by keys using a user-defined comparison function. |
||
| 673 | * |
||
| 674 | * @param callable $function |
||
| 675 | * |
||
| 676 | * @throws \InvalidArgumentException |
||
| 677 | * |
||
| 678 | * @return static |
||
| 679 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 680 | * |
||
| 681 | * @psalm-return static<TKey,T> |
||
| 682 | */ |
||
| 683 | 5 | public function uksort($function): self |
|
| 687 | |||
| 688 | /** |
||
| 689 | * Unserialize an string and return the instance of the "Arrayy"-class. |
||
| 690 | * |
||
| 691 | * @param string $string |
||
| 692 | * |
||
| 693 | * @return $this |
||
| 694 | * |
||
| 695 | * @psalm-return $this<TKey,T> |
||
| 696 | */ |
||
| 697 | 2 | public function unserialize($string): self |
|
| 707 | |||
| 708 | /** |
||
| 709 | * Append a (key) + values to the current array. |
||
| 710 | * |
||
| 711 | * @param array $values |
||
| 712 | * @param mixed $key |
||
| 713 | * |
||
| 714 | * @return $this |
||
| 715 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
| 716 | * |
||
| 717 | * @psalm-param array<mixed,T> $values |
||
| 718 | * @psalm-param TKey|null $key |
||
| 719 | * @psalm-return $this<TKey,T> |
||
| 720 | */ |
||
| 721 | 1 | public function appendArrayValues(array $values, $key = null) |
|
| 747 | |||
| 748 | /** |
||
| 749 | * Add a suffix to each key. |
||
| 750 | * |
||
| 751 | * @param mixed $prefix |
||
| 752 | * |
||
| 753 | * @return static |
||
| 754 | * <p>(Immutable) Return an Arrayy object, with the prefixed keys.</p> |
||
| 755 | * |
||
| 756 | * @psalm-return static<TKey,T> |
||
| 757 | * @psalm-mutation-free |
||
| 758 | */ |
||
| 759 | 10 | View Code Duplication | public function appendToEachKey($prefix): self |
| 778 | |||
| 779 | /** |
||
| 780 | * Add a prefix to each value. |
||
| 781 | * |
||
| 782 | * @param mixed $prefix |
||
| 783 | * |
||
| 784 | * @return static |
||
| 785 | * <p>(Immutable) Return an Arrayy object, with the prefixed values.</p> |
||
| 786 | * |
||
| 787 | * @psalm-return static<TKey,T> |
||
| 788 | * @psalm-mutation-free |
||
| 789 | */ |
||
| 790 | 10 | View Code Duplication | public function appendToEachValue($prefix): self |
| 809 | |||
| 810 | /** |
||
| 811 | * Sort an array in reverse order and maintain index association. |
||
| 812 | * |
||
| 813 | * @return $this |
||
| 814 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 815 | * |
||
| 816 | * @psalm-return $this<TKey,T> |
||
| 817 | */ |
||
| 818 | 10 | public function arsort(): self |
|
| 826 | |||
| 827 | /** |
||
| 828 | * Iterate over the current array and execute a callback for each loop. |
||
| 829 | * |
||
| 830 | * @param \Closure $closure |
||
| 831 | * |
||
| 832 | * @return static |
||
| 833 | * <p>(Immutable)</p> |
||
| 834 | * |
||
| 835 | * @psalm-return static<TKey,T> |
||
| 836 | * @psalm-mutation-free |
||
| 837 | */ |
||
| 838 | 2 | public function at(\Closure $closure): self |
|
| 852 | |||
| 853 | /** |
||
| 854 | * Returns the average value of the current array. |
||
| 855 | * |
||
| 856 | * @param int $decimals <p>The number of decimal-numbers to return.</p> |
||
| 857 | * |
||
| 858 | * @return float|int |
||
| 859 | * <p>The average value.</p> |
||
| 860 | */ |
||
| 861 | 10 | public function average($decimals = 0) |
|
| 875 | |||
| 876 | /** |
||
| 877 | * Changes all keys in an array. |
||
| 878 | * |
||
| 879 | * @param int $case [optional] <p> Either <strong>CASE_UPPER</strong><br /> |
||
| 880 | * or <strong>CASE_LOWER</strong> (default)</p> |
||
| 881 | * |
||
| 882 | * @return static |
||
| 883 | * <p>(Immutable)</p> |
||
| 884 | * |
||
| 885 | * @psalm-return static<TKey,T> |
||
| 886 | * @psalm-mutation-free |
||
| 887 | */ |
||
| 888 | 1 | public function changeKeyCase(int $case = \CASE_LOWER): self |
|
| 915 | |||
| 916 | /** |
||
| 917 | * Change the path separator of the array wrapper. |
||
| 918 | * |
||
| 919 | * By default, the separator is: "." |
||
| 920 | * |
||
| 921 | * @param string $separator <p>Separator to set.</p> |
||
| 922 | * |
||
| 923 | * @return $this |
||
| 924 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 925 | * |
||
| 926 | * @psalm-return $this<TKey,T> |
||
| 927 | */ |
||
| 928 | 11 | public function changeSeparator($separator): self |
|
| 934 | |||
| 935 | /** |
||
| 936 | * Create a chunked version of the current array. |
||
| 937 | * |
||
| 938 | * @param int $size <p>Size of each chunk.</p> |
||
| 939 | * @param bool $preserveKeys <p>Whether array keys are preserved or no.</p> |
||
| 940 | * |
||
| 941 | * @return static |
||
| 942 | * <p>(Immutable) A new array of chunks from the original array.</p> |
||
| 943 | * |
||
| 944 | * @psalm-return static<TKey,T> |
||
| 945 | * @psalm-mutation-free |
||
| 946 | */ |
||
| 947 | 5 | public function chunk($size, $preserveKeys = false): self |
|
| 955 | |||
| 956 | /** |
||
| 957 | * Clean all falsy values from the current array. |
||
| 958 | * |
||
| 959 | * @return static |
||
| 960 | * <p>(Immutable)</p> |
||
| 961 | * |
||
| 962 | * @psalm-return static<TKey,T> |
||
| 963 | * @psalm-mutation-free |
||
| 964 | */ |
||
| 965 | 8 | public function clean(): self |
|
| 966 | { |
||
| 967 | 8 | return $this->filter( |
|
| 968 | 8 | static function ($value) { |
|
| 969 | 7 | return (bool) $value; |
|
| 970 | 8 | } |
|
| 971 | ); |
||
| 972 | } |
||
| 973 | |||
| 974 | /** |
||
| 975 | * WARNING!!! -> Clear the current array. |
||
| 976 | * |
||
| 977 | * @return $this |
||
| 978 | * <p>(Mutable) Return this Arrayy object, with an empty array.</p> |
||
| 979 | * |
||
| 980 | * @psalm-return $this<TKey,T> |
||
| 981 | */ |
||
| 982 | 5 | public function clear(): self |
|
| 989 | |||
| 990 | /** |
||
| 991 | * Check if an item is in the current array. |
||
| 992 | * |
||
| 993 | * @param float|int|string $value |
||
| 994 | * @param bool $recursive |
||
| 995 | * @param bool $strict |
||
| 996 | * |
||
| 997 | * @return bool |
||
| 998 | */ |
||
| 999 | 24 | public function contains($value, bool $recursive = false, bool $strict = true): bool |
|
| 1020 | |||
| 1021 | /** |
||
| 1022 | * Check if an (case-insensitive) string is in the current array. |
||
| 1023 | * |
||
| 1024 | * @param string $value |
||
| 1025 | * @param bool $recursive |
||
| 1026 | * |
||
| 1027 | * @return bool |
||
| 1028 | */ |
||
| 1029 | 26 | public function containsCaseInsensitive($value, $recursive = false): bool |
|
| 1054 | |||
| 1055 | /** |
||
| 1056 | * Check if the given key/index exists in the array. |
||
| 1057 | * |
||
| 1058 | * @param int|string $key <p>key/index to search for</p> |
||
| 1059 | * |
||
| 1060 | * @return bool |
||
| 1061 | * <p>Returns true if the given key/index exists in the array, false otherwise.</p> |
||
| 1062 | */ |
||
| 1063 | 4 | public function containsKey($key): bool |
|
| 1067 | |||
| 1068 | /** |
||
| 1069 | * Check if all given needles are present in the array as key/index. |
||
| 1070 | * |
||
| 1071 | * @param array $needles <p>The keys you are searching for.</p> |
||
| 1072 | * @param bool $recursive |
||
| 1073 | * |
||
| 1074 | * @return bool |
||
| 1075 | * <p>Returns true if all the given keys/indexes exists in the array, false otherwise.</p> |
||
| 1076 | * |
||
| 1077 | * @psalm-param array<mixed,mixed>|array<TKey> $needles |
||
| 1078 | */ |
||
| 1079 | 2 | public function containsKeys(array $needles, $recursive = false): bool |
|
| 1107 | |||
| 1108 | /** |
||
| 1109 | * Check if all given needles are present in the array as key/index. |
||
| 1110 | * |
||
| 1111 | * @param array $needles <p>The keys you are searching for.</p> |
||
| 1112 | * |
||
| 1113 | * @return bool |
||
| 1114 | * <p>Returns true if all the given keys/indexes exists in the array, false otherwise.</p> |
||
| 1115 | * |
||
| 1116 | * @psalm-param array<mixed,mixed>|array<TKey> $needles |
||
| 1117 | */ |
||
| 1118 | 1 | public function containsKeysRecursive(array $needles): bool |
|
| 1122 | |||
| 1123 | /** |
||
| 1124 | * alias: for "Arrayy->contains()" |
||
| 1125 | * |
||
| 1126 | * @param float|int|string $value |
||
| 1127 | * |
||
| 1128 | * @return bool |
||
| 1129 | * |
||
| 1130 | * @see Arrayy::contains() |
||
| 1131 | */ |
||
| 1132 | 9 | public function containsValue($value): bool |
|
| 1136 | |||
| 1137 | /** |
||
| 1138 | * alias: for "Arrayy->contains($value, true)" |
||
| 1139 | * |
||
| 1140 | * @param float|int|string $value |
||
| 1141 | * |
||
| 1142 | * @return bool |
||
| 1143 | * |
||
| 1144 | * @see Arrayy::contains() |
||
| 1145 | */ |
||
| 1146 | 18 | public function containsValueRecursive($value): bool |
|
| 1150 | |||
| 1151 | /** |
||
| 1152 | * Check if all given needles are present in the array. |
||
| 1153 | * |
||
| 1154 | * @param array $needles |
||
| 1155 | * |
||
| 1156 | * @return bool |
||
| 1157 | * <p>Returns true if all the given values exists in the array, false otherwise.</p> |
||
| 1158 | * |
||
| 1159 | * @psalm-param array<mixed>|array<T> $needles |
||
| 1160 | */ |
||
| 1161 | 1 | public function containsValues(array $needles): bool |
|
| 1167 | |||
| 1168 | /** |
||
| 1169 | * Counts all the values of an array |
||
| 1170 | * |
||
| 1171 | * @see http://php.net/manual/en/function.array-count-values.php |
||
| 1172 | * |
||
| 1173 | * @return static |
||
| 1174 | * <p> |
||
| 1175 | * (Immutable) |
||
| 1176 | * An associative Arrayy-object of values from input as |
||
| 1177 | * keys and their count as value. |
||
| 1178 | * </p> |
||
| 1179 | * |
||
| 1180 | * @psalm-return static<TKey,T> |
||
| 1181 | * @psalm-mutation-free |
||
| 1182 | */ |
||
| 1183 | 7 | public function countValues(): self |
|
| 1187 | |||
| 1188 | /** |
||
| 1189 | * Creates an Arrayy object. |
||
| 1190 | * |
||
| 1191 | * @param mixed $data |
||
| 1192 | * @param string $iteratorClass |
||
| 1193 | * @param bool $checkPropertiesInConstructor |
||
| 1194 | * |
||
| 1195 | * @return static |
||
| 1196 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1197 | * |
||
| 1198 | * @psalm-param class-string<\Arrayy\ArrayyIterator> $iteratorClass |
||
| 1199 | * @psalm-return static<TKey,T> |
||
| 1200 | * @psalm-mutation-free |
||
| 1201 | */ |
||
| 1202 | 669 | public static function create( |
|
| 1213 | |||
| 1214 | /** |
||
| 1215 | * WARNING: Creates an Arrayy object by reference. |
||
| 1216 | * |
||
| 1217 | * @param array $array |
||
| 1218 | * |
||
| 1219 | * @return $this |
||
| 1220 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1221 | * |
||
| 1222 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 1223 | * @psalm-return $this<TKey,T> |
||
| 1224 | */ |
||
| 1225 | 1 | public function createByReference(array &$array = []): self |
|
| 1233 | |||
| 1234 | /** |
||
| 1235 | * Create an new instance from a callable function which will return an Generator. |
||
| 1236 | * |
||
| 1237 | * @param callable $generatorFunction |
||
| 1238 | * |
||
| 1239 | * @return static |
||
| 1240 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1241 | * |
||
| 1242 | * @psalm-param callable():\Generator<TKey,T> $generatorFunction |
||
| 1243 | * @psalm-return static<TKey,T> |
||
| 1244 | * @psalm-mutation-free |
||
| 1245 | */ |
||
| 1246 | 5 | public static function createFromGeneratorFunction(callable $generatorFunction): self |
|
| 1250 | |||
| 1251 | /** |
||
| 1252 | * Create an new instance filled with a copy of values from a "Generator"-object. |
||
| 1253 | * |
||
| 1254 | * @param \Generator $generator |
||
| 1255 | * |
||
| 1256 | * @return static |
||
| 1257 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1258 | * |
||
| 1259 | * @psalm-param \Generator<TKey,T> $generator |
||
| 1260 | * @psalm-return static<TKey,T> |
||
| 1261 | * @psalm-mutation-free |
||
| 1262 | */ |
||
| 1263 | 4 | public static function createFromGeneratorImmutable(\Generator $generator): self |
|
| 1267 | |||
| 1268 | /** |
||
| 1269 | * Create an new Arrayy object via JSON. |
||
| 1270 | * |
||
| 1271 | * @param string $json |
||
| 1272 | * |
||
| 1273 | * @return static |
||
| 1274 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1275 | * |
||
| 1276 | * @psalm-return static<TKey,T> |
||
| 1277 | * @psalm-mutation-free |
||
| 1278 | */ |
||
| 1279 | 5 | public static function createFromJson(string $json): self |
|
| 1283 | |||
| 1284 | /** |
||
| 1285 | * Create an new instance filled with values from an object that is iterable. |
||
| 1286 | * |
||
| 1287 | * @param \Traversable $object <p>iterable object</p> |
||
| 1288 | * |
||
| 1289 | * @return static |
||
| 1290 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1291 | * |
||
| 1292 | * @psalm-param \Traversable<TKey,T> $object |
||
| 1293 | * @psalm-return static<TKey,T> |
||
| 1294 | * @psalm-mutation-free |
||
| 1295 | */ |
||
| 1296 | 4 | public static function createFromObject(\Traversable $object): self |
|
| 1313 | |||
| 1314 | /** |
||
| 1315 | * Create an new instance filled with values from an object. |
||
| 1316 | * |
||
| 1317 | * @param object $object |
||
| 1318 | * |
||
| 1319 | * @return static |
||
| 1320 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1321 | * |
||
| 1322 | * @psalm-return static<TKey,T> |
||
| 1323 | * @psalm-mutation-free |
||
| 1324 | */ |
||
| 1325 | 5 | public static function createFromObjectVars($object): self |
|
| 1329 | |||
| 1330 | /** |
||
| 1331 | * Create an new Arrayy object via string. |
||
| 1332 | * |
||
| 1333 | * @param string $str <p>The input string.</p> |
||
| 1334 | * @param string|null $delimiter <p>The boundary string.</p> |
||
| 1335 | * @param string|null $regEx <p>Use the $delimiter or the $regEx, so if $pattern is null, $delimiter will be |
||
| 1336 | * used.</p> |
||
| 1337 | * |
||
| 1338 | * @return static |
||
| 1339 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1340 | * |
||
| 1341 | * @psalm-return static<TKey,T> |
||
| 1342 | * @psalm-mutation-free |
||
| 1343 | */ |
||
| 1344 | 10 | public static function createFromString(string $str, string $delimiter = null, string $regEx = null): self |
|
| 1345 | { |
||
| 1346 | 10 | if ($regEx) { |
|
| 1347 | 1 | \preg_match_all($regEx, $str, $array); |
|
| 1348 | |||
| 1349 | 1 | if (!empty($array)) { |
|
| 1350 | 1 | $array = $array[0]; |
|
| 1351 | } |
||
| 1352 | } else { |
||
| 1353 | /** @noinspection NestedPositiveIfStatementsInspection */ |
||
| 1354 | 9 | if ($delimiter !== null) { |
|
| 1355 | 7 | $array = \explode($delimiter, $str); |
|
| 1356 | } else { |
||
| 1357 | 2 | $array = [$str]; |
|
| 1358 | } |
||
| 1359 | } |
||
| 1360 | |||
| 1361 | // trim all string in the array |
||
| 1362 | 10 | \array_walk( |
|
| 1363 | 10 | $array, |
|
| 1364 | 10 | static function (&$val) { |
|
| 1365 | 10 | if ((string) $val === $val) { |
|
| 1366 | 10 | $val = \trim($val); |
|
| 1367 | } |
||
| 1368 | 10 | } |
|
| 1369 | ); |
||
| 1370 | |||
| 1371 | 10 | return static::create($array); |
|
| 1372 | } |
||
| 1373 | |||
| 1374 | /** |
||
| 1375 | * Create an new instance filled with a copy of values from a "Traversable"-object. |
||
| 1376 | * |
||
| 1377 | * @param \Traversable $traversable |
||
| 1378 | * |
||
| 1379 | * @return static |
||
| 1380 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1381 | * |
||
| 1382 | * @psalm-param \Traversable<TKey,T> $traversable |
||
| 1383 | * @psalm-return static<TKey,T> |
||
| 1384 | * @psalm-mutation-free |
||
| 1385 | */ |
||
| 1386 | 1 | public static function createFromTraversableImmutable(\Traversable $traversable): self |
|
| 1390 | |||
| 1391 | /** |
||
| 1392 | * Create an new instance containing a range of elements. |
||
| 1393 | * |
||
| 1394 | * @param mixed $low <p>First value of the sequence.</p> |
||
| 1395 | * @param mixed $high <p>The sequence is ended upon reaching the end value.</p> |
||
| 1396 | * @param int $step <p>Used as the increment between elements in the sequence.</p> |
||
| 1397 | * |
||
| 1398 | * @return static |
||
| 1399 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1400 | * |
||
| 1401 | * @psalm-return static<TKey,T> |
||
| 1402 | * @psalm-mutation-free |
||
| 1403 | */ |
||
| 1404 | 2 | public static function createWithRange($low, $high, int $step = 1): self |
|
| 1408 | |||
| 1409 | /** |
||
| 1410 | * Gets the element of the array at the current internal iterator position. |
||
| 1411 | * |
||
| 1412 | * @return false|mixed |
||
| 1413 | */ |
||
| 1414 | public function current() |
||
| 1418 | |||
| 1419 | /** |
||
| 1420 | * Custom sort by index via "uksort". |
||
| 1421 | * |
||
| 1422 | * @see http://php.net/manual/en/function.uksort.php |
||
| 1423 | * |
||
| 1424 | * @param callable $function |
||
| 1425 | * |
||
| 1426 | * @throws \InvalidArgumentException |
||
| 1427 | * |
||
| 1428 | * @return $this |
||
| 1429 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1430 | * |
||
| 1431 | * @psalm-return $this<TKey,T> |
||
| 1432 | */ |
||
| 1433 | 5 | public function customSortKeys(callable $function): self |
|
| 1441 | |||
| 1442 | /** |
||
| 1443 | * Custom sort by value via "usort". |
||
| 1444 | * |
||
| 1445 | * @see http://php.net/manual/en/function.usort.php |
||
| 1446 | * |
||
| 1447 | * @param callable $function |
||
| 1448 | * |
||
| 1449 | * @throws \InvalidArgumentException |
||
| 1450 | * |
||
| 1451 | * @return $this |
||
| 1452 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1453 | * |
||
| 1454 | * @psalm-return $this<TKey,T> |
||
| 1455 | */ |
||
| 1456 | 6 | View Code Duplication | public function customSortValues($function): self |
| 1468 | |||
| 1469 | /** |
||
| 1470 | * Delete the given key or keys. |
||
| 1471 | * |
||
| 1472 | * @param int|int[]|string|string[] $keyOrKeys |
||
| 1473 | * |
||
| 1474 | * @return void |
||
| 1475 | */ |
||
| 1476 | 4 | public function delete($keyOrKeys) |
|
| 1484 | |||
| 1485 | /** |
||
| 1486 | * Return values that are only in the current array. |
||
| 1487 | * |
||
| 1488 | * @param array ...$array |
||
| 1489 | * |
||
| 1490 | * @return static |
||
| 1491 | * <p>(Immutable)</p> |
||
| 1492 | * |
||
| 1493 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$array |
||
| 1494 | * @psalm-return static<TKey,T> |
||
| 1495 | * @psalm-mutation-free |
||
| 1496 | */ |
||
| 1497 | 13 | public function diff(...$array): self |
|
| 1505 | |||
| 1506 | /** |
||
| 1507 | * Return values that are only in the current array. |
||
| 1508 | * |
||
| 1509 | * @param array ...$array |
||
| 1510 | * |
||
| 1511 | * @return static |
||
| 1512 | * <p>(Immutable)</p> |
||
| 1513 | * |
||
| 1514 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$array |
||
| 1515 | * @psalm-return static<TKey,T> |
||
| 1516 | * @psalm-mutation-free |
||
| 1517 | */ |
||
| 1518 | 8 | public function diffKey(...$array): self |
|
| 1526 | |||
| 1527 | /** |
||
| 1528 | * Return values and Keys that are only in the current array. |
||
| 1529 | * |
||
| 1530 | * @param array $array |
||
| 1531 | * |
||
| 1532 | * @return static |
||
| 1533 | * <p>(Immutable)</p> |
||
| 1534 | * |
||
| 1535 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 1536 | * @psalm-return static<TKey,T> |
||
| 1537 | * @psalm-mutation-free |
||
| 1538 | */ |
||
| 1539 | 8 | public function diffKeyAndValue(array $array = []): self |
|
| 1547 | |||
| 1548 | /** |
||
| 1549 | * Return values that are only in the current multi-dimensional array. |
||
| 1550 | * |
||
| 1551 | * @param array $array |
||
| 1552 | * @param array|null $helperVariableForRecursion <p>(only for internal usage)</p> |
||
| 1553 | * |
||
| 1554 | * @return static |
||
| 1555 | * <p>(Immutable)</p> |
||
| 1556 | * |
||
| 1557 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 1558 | * @psalm-param null|array<TKey,T> $helperVariableForRecursion |
||
| 1559 | * @psalm-return static<TKey,T> |
||
| 1560 | * @psalm-mutation-free |
||
| 1561 | */ |
||
| 1562 | 1 | public function diffRecursive(array $array = [], $helperVariableForRecursion = null): self |
|
| 1597 | |||
| 1598 | /** |
||
| 1599 | * Return values that are only in the new $array. |
||
| 1600 | * |
||
| 1601 | * @param array $array |
||
| 1602 | * |
||
| 1603 | * @return static |
||
| 1604 | * <p>(Immutable)</p> |
||
| 1605 | * |
||
| 1606 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 1607 | * @psalm-return static<TKey,T> |
||
| 1608 | * @psalm-mutation-free |
||
| 1609 | */ |
||
| 1610 | 8 | public function diffReverse(array $array = []): self |
|
| 1618 | |||
| 1619 | /** |
||
| 1620 | * Divide an array into two arrays. One with keys and the other with values. |
||
| 1621 | * |
||
| 1622 | * @return static |
||
| 1623 | * <p>(Immutable)</p> |
||
| 1624 | * |
||
| 1625 | * @psalm-return static<TKey,T> |
||
| 1626 | * @psalm-mutation-free |
||
| 1627 | */ |
||
| 1628 | 1 | public function divide(): self |
|
| 1639 | |||
| 1640 | /** |
||
| 1641 | * Iterate over the current array and modify the array's value. |
||
| 1642 | * |
||
| 1643 | * @param \Closure $closure |
||
| 1644 | * |
||
| 1645 | * @return static |
||
| 1646 | * <p>(Immutable)</p> |
||
| 1647 | * |
||
| 1648 | * @psalm-return static<TKey,T> |
||
| 1649 | * @psalm-mutation-free |
||
| 1650 | */ |
||
| 1651 | 5 | View Code Duplication | public function each(\Closure $closure): self |
| 1666 | |||
| 1667 | /** |
||
| 1668 | * Sets the internal iterator to the last element in the array and returns this element. |
||
| 1669 | * |
||
| 1670 | * @return mixed |
||
| 1671 | */ |
||
| 1672 | public function end() |
||
| 1676 | |||
| 1677 | /** |
||
| 1678 | * Check if a value is in the current array using a closure. |
||
| 1679 | * |
||
| 1680 | * @param \Closure $closure |
||
| 1681 | * |
||
| 1682 | * @return bool |
||
| 1683 | * <p>Returns true if the given value is found, false otherwise.</p> |
||
| 1684 | */ |
||
| 1685 | 4 | public function exists(\Closure $closure): bool |
|
| 1700 | |||
| 1701 | /** |
||
| 1702 | * Fill the array until "$num" with "$default" values. |
||
| 1703 | * |
||
| 1704 | * @param int $num |
||
| 1705 | * @param mixed $default |
||
| 1706 | * |
||
| 1707 | * @return static |
||
| 1708 | * <p>(Immutable)</p> |
||
| 1709 | * |
||
| 1710 | * @psalm-return static<TKey,T> |
||
| 1711 | * @psalm-mutation-free |
||
| 1712 | */ |
||
| 1713 | 8 | public function fillWithDefaults(int $num, $default = null): self |
|
| 1736 | |||
| 1737 | /** |
||
| 1738 | * Find all items in an array that pass the truth test. |
||
| 1739 | * |
||
| 1740 | * @param \Closure|null $closure [optional] <p> |
||
| 1741 | * The callback function to use |
||
| 1742 | * </p> |
||
| 1743 | * <p> |
||
| 1744 | * If no callback is supplied, all entries of |
||
| 1745 | * input equal to false (see |
||
| 1746 | * converting to |
||
| 1747 | * boolean) will be removed. |
||
| 1748 | * </p> |
||
| 1749 | * @param int $flag [optional] <p> |
||
| 1750 | * Flag determining what arguments are sent to <i>callback</i>: |
||
| 1751 | * </p><ul> |
||
| 1752 | * <li> |
||
| 1753 | * <b>ARRAY_FILTER_USE_KEY</b> [1] - pass key as the only argument |
||
| 1754 | * to <i>callback</i> instead of the value</span> |
||
| 1755 | * </li> |
||
| 1756 | * <li> |
||
| 1757 | * <b>ARRAY_FILTER_USE_BOTH</b> [2] - pass both value and key as |
||
| 1758 | * arguments to <i>callback</i> instead of the value</span> |
||
| 1759 | * </li> |
||
| 1760 | * </ul> |
||
| 1761 | * |
||
| 1762 | * @return static |
||
| 1763 | * <p>(Immutable)</p> |
||
| 1764 | * |
||
| 1765 | * @psalm-param \Closure(T=,TKey=):bool|\Closure(T=):bool $closure |
||
| 1766 | * @psalm-return static<TKey,T> |
||
| 1767 | * @psalm-mutation-free |
||
| 1768 | */ |
||
| 1769 | 12 | public function filter($closure = null, int $flag = \ARRAY_FILTER_USE_BOTH) |
|
| 1781 | |||
| 1782 | /** |
||
| 1783 | * Filters an array of objects (or a numeric array of associative arrays) based on the value of a particular |
||
| 1784 | * property within that. |
||
| 1785 | * |
||
| 1786 | * @param string $property |
||
| 1787 | * @param string|string[] $value |
||
| 1788 | * @param string $comparisonOp |
||
| 1789 | * <p> |
||
| 1790 | * 'eq' (equals),<br /> |
||
| 1791 | * 'gt' (greater),<br /> |
||
| 1792 | * 'gte' || 'ge' (greater or equals),<br /> |
||
| 1793 | * 'lt' (less),<br /> |
||
| 1794 | * 'lte' || 'le' (less or equals),<br /> |
||
| 1795 | * 'ne' (not equals),<br /> |
||
| 1796 | * 'contains',<br /> |
||
| 1797 | * 'notContains',<br /> |
||
| 1798 | * 'newer' (via strtotime),<br /> |
||
| 1799 | * 'older' (via strtotime),<br /> |
||
| 1800 | * </p> |
||
| 1801 | * |
||
| 1802 | * @return static |
||
| 1803 | * <p>(Immutable)</p> |
||
| 1804 | * |
||
| 1805 | * @psalm-return static<TKey,T> |
||
| 1806 | * @psalm-mutation-free |
||
| 1807 | */ |
||
| 1808 | 1 | public function filterBy(string $property, $value, string $comparisonOp = null): self |
|
| 1809 | { |
||
| 1810 | 1 | if (!$comparisonOp) { |
|
| 1811 | 1 | $comparisonOp = \is_array($value) === true ? 'contains' : 'eq'; |
|
| 1812 | } |
||
| 1813 | |||
| 1814 | $ops = [ |
||
| 1815 | 1 | 'eq' => static function ($item, $prop, $value): bool { |
|
| 1816 | 1 | return $item[$prop] === $value; |
|
| 1817 | 1 | }, |
|
| 1818 | 1 | 'gt' => static function ($item, $prop, $value): bool { |
|
| 1819 | return $item[$prop] > $value; |
||
| 1820 | 1 | }, |
|
| 1821 | 1 | 'ge' => static function ($item, $prop, $value): bool { |
|
| 1822 | return $item[$prop] >= $value; |
||
| 1823 | 1 | }, |
|
| 1824 | 1 | 'gte' => static function ($item, $prop, $value): bool { |
|
| 1825 | return $item[$prop] >= $value; |
||
| 1826 | 1 | }, |
|
| 1827 | 1 | 'lt' => static function ($item, $prop, $value): bool { |
|
| 1828 | 1 | return $item[$prop] < $value; |
|
| 1829 | 1 | }, |
|
| 1830 | 1 | 'le' => static function ($item, $prop, $value): bool { |
|
| 1831 | return $item[$prop] <= $value; |
||
| 1832 | 1 | }, |
|
| 1833 | 1 | 'lte' => static function ($item, $prop, $value): bool { |
|
| 1834 | return $item[$prop] <= $value; |
||
| 1835 | 1 | }, |
|
| 1836 | 1 | 'ne' => static function ($item, $prop, $value): bool { |
|
| 1837 | return $item[$prop] !== $value; |
||
| 1838 | 1 | }, |
|
| 1839 | 1 | 'contains' => static function ($item, $prop, $value): bool { |
|
| 1840 | 1 | return \in_array($item[$prop], (array) $value, true); |
|
| 1841 | 1 | }, |
|
| 1842 | 1 | 'notContains' => static function ($item, $prop, $value): bool { |
|
| 1843 | return !\in_array($item[$prop], (array) $value, true); |
||
| 1844 | 1 | }, |
|
| 1845 | 1 | 'newer' => static function ($item, $prop, $value): bool { |
|
| 1846 | return \strtotime($item[$prop]) > \strtotime($value); |
||
| 1847 | 1 | }, |
|
| 1848 | 1 | 'older' => static function ($item, $prop, $value): bool { |
|
| 1849 | return \strtotime($item[$prop]) < \strtotime($value); |
||
| 1850 | 1 | }, |
|
| 1851 | ]; |
||
| 1852 | |||
| 1853 | 1 | $result = \array_values( |
|
| 1854 | 1 | \array_filter( |
|
| 1855 | 1 | $this->getArray(), |
|
| 1856 | 1 | static function ($item) use ( |
|
| 1857 | 1 | $property, |
|
| 1858 | 1 | $value, |
|
| 1859 | 1 | $ops, |
|
| 1860 | 1 | $comparisonOp |
|
| 1861 | ) { |
||
| 1862 | 1 | $item = (array) $item; |
|
| 1863 | 1 | $itemArrayy = static::create($item); |
|
| 1864 | 1 | $item[$property] = $itemArrayy->get($property, []); |
|
| 1865 | |||
| 1866 | 1 | return $ops[$comparisonOp]($item, $property, $value); |
|
| 1867 | 1 | } |
|
| 1868 | ) |
||
| 1869 | ); |
||
| 1870 | |||
| 1871 | 1 | return static::create( |
|
| 1872 | 1 | $result, |
|
| 1873 | 1 | $this->iteratorClass, |
|
| 1874 | 1 | false |
|
| 1875 | ); |
||
| 1876 | } |
||
| 1877 | |||
| 1878 | /** |
||
| 1879 | * Find the first item in an array that passes the truth test, |
||
| 1880 | * otherwise return false |
||
| 1881 | * |
||
| 1882 | * @param \Closure $closure |
||
| 1883 | * |
||
| 1884 | * @return false|mixed |
||
| 1885 | * <p>Return false if we did not find the value.</p> |
||
| 1886 | */ |
||
| 1887 | 8 | View Code Duplication | public function find(\Closure $closure) |
| 1897 | |||
| 1898 | /** |
||
| 1899 | * find by ... |
||
| 1900 | * |
||
| 1901 | * @param string $property |
||
| 1902 | * @param string|string[] $value |
||
| 1903 | * @param string $comparisonOp |
||
| 1904 | * |
||
| 1905 | * @return static |
||
| 1906 | * <p>(Immutable)</p> |
||
| 1907 | * |
||
| 1908 | * @psalm-return static<TKey,T> |
||
| 1909 | * @psalm-mutation-free |
||
| 1910 | */ |
||
| 1911 | 1 | public function findBy(string $property, $value, string $comparisonOp = 'eq'): self |
|
| 1915 | |||
| 1916 | /** |
||
| 1917 | * Get the first value from the current array. |
||
| 1918 | * |
||
| 1919 | * @return mixed |
||
| 1920 | * <p>Return null if there wasn't a element.</p> |
||
| 1921 | */ |
||
| 1922 | 22 | public function first() |
|
| 1931 | |||
| 1932 | /** |
||
| 1933 | * Get the first key from the current array. |
||
| 1934 | * |
||
| 1935 | * @return mixed |
||
| 1936 | * <p>Return null if there wasn't a element.</p> |
||
| 1937 | */ |
||
| 1938 | 29 | public function firstKey() |
|
| 1944 | |||
| 1945 | /** |
||
| 1946 | * Get the first value(s) from the current array. |
||
| 1947 | * And will return an empty array if there was no first entry. |
||
| 1948 | * |
||
| 1949 | * @param int|null $number <p>How many values you will take?</p> |
||
| 1950 | * |
||
| 1951 | * @return static |
||
| 1952 | * <p>(Immutable)</p> |
||
| 1953 | * |
||
| 1954 | * @psalm-return static<TKey,T> |
||
| 1955 | * @psalm-mutation-free |
||
| 1956 | */ |
||
| 1957 | 37 | View Code Duplication | public function firstsImmutable(int $number = null): self |
| 1974 | |||
| 1975 | /** |
||
| 1976 | * Get the first value(s) from the current array. |
||
| 1977 | * And will return an empty array if there was no first entry. |
||
| 1978 | * |
||
| 1979 | * @param int|null $number <p>How many values you will take?</p> |
||
| 1980 | * |
||
| 1981 | * @return static |
||
| 1982 | * <p>(Immutable)</p> |
||
| 1983 | * |
||
| 1984 | * @psalm-return static<TKey,T> |
||
| 1985 | * @psalm-mutation-free |
||
| 1986 | */ |
||
| 1987 | 3 | View Code Duplication | public function firstsKeys(int $number = null): self |
| 2004 | |||
| 2005 | /** |
||
| 2006 | * Get and rmove the first value(s) from the current array. |
||
| 2007 | * And will return an empty array if there was no first entry. |
||
| 2008 | * |
||
| 2009 | * @param int|null $number <p>How many values you will take?</p> |
||
| 2010 | * |
||
| 2011 | * @return $this |
||
| 2012 | * <p>(Mutable)</p> |
||
| 2013 | * |
||
| 2014 | * @psalm-return $this<TKey,T> |
||
| 2015 | */ |
||
| 2016 | 34 | public function firstsMutable(int $number = null): self |
|
| 2029 | |||
| 2030 | /** |
||
| 2031 | * Exchanges all keys with their associated values in an array. |
||
| 2032 | * |
||
| 2033 | * @return static |
||
| 2034 | * <p>(Immutable)</p> |
||
| 2035 | * |
||
| 2036 | * @psalm-return static<TKey,T> |
||
| 2037 | * @psalm-mutation-free |
||
| 2038 | */ |
||
| 2039 | 1 | public function flip(): self |
|
| 2047 | |||
| 2048 | /** |
||
| 2049 | * Get a value from an array (optional using dot-notation). |
||
| 2050 | * |
||
| 2051 | * @param mixed $key <p>The key to look for.</p> |
||
| 2052 | * @param mixed $fallback <p>Value to fallback to.</p> |
||
| 2053 | * @param array $array <p>The array to get from, if it's set to "null" we use the current array from the |
||
| 2054 | * class.</p> |
||
| 2055 | * |
||
| 2056 | * @return mixed|static |
||
| 2057 | * |
||
| 2058 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 2059 | */ |
||
| 2060 | 172 | public function get($key, $fallback = null, array $array = null) |
|
| 2152 | |||
| 2153 | /** |
||
| 2154 | * alias: for "Arrayy->getArray()" |
||
| 2155 | * |
||
| 2156 | * @return array |
||
| 2157 | * |
||
| 2158 | * @see Arrayy::getArray() |
||
| 2159 | * |
||
| 2160 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 2161 | */ |
||
| 2162 | 1 | public function getAll(): array |
|
| 2166 | |||
| 2167 | /** |
||
| 2168 | * Get the current array from the "Arrayy"-object. |
||
| 2169 | * |
||
| 2170 | * @param bool $convertAllArrayyElements |
||
| 2171 | * |
||
| 2172 | * @return array |
||
| 2173 | * |
||
| 2174 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 2175 | */ |
||
| 2176 | 859 | public function getArray($convertAllArrayyElements = false): array |
|
| 2197 | |||
| 2198 | /** |
||
| 2199 | * Returns the values from a single column of the input array, identified by |
||
| 2200 | * the $columnKey, can be used to extract data-columns from multi-arrays. |
||
| 2201 | * |
||
| 2202 | * Info: Optionally, you may provide an $indexKey to index the values in the returned |
||
| 2203 | * array by the values from the $indexKey column in the input array. |
||
| 2204 | * |
||
| 2205 | * @param mixed $columnKey |
||
| 2206 | * @param mixed $indexKey |
||
| 2207 | * |
||
| 2208 | * @return static |
||
| 2209 | * <p>(Immutable)</p> |
||
| 2210 | * |
||
| 2211 | * @psalm-return static<TKey,T> |
||
| 2212 | * @psalm-mutation-free |
||
| 2213 | */ |
||
| 2214 | 1 | public function getColumn($columnKey = null, $indexKey = null): self |
|
| 2222 | |||
| 2223 | /** |
||
| 2224 | * Get the current array from the "Arrayy"-object as generator. |
||
| 2225 | * |
||
| 2226 | * @return \Generator |
||
| 2227 | * |
||
| 2228 | * @psalm-return \Generator<mixed,T>|\Generator<TKey,T> |
||
| 2229 | */ |
||
| 2230 | 942 | public function getGenerator(): \Generator |
|
| 2238 | |||
| 2239 | /** |
||
| 2240 | * alias: for "Arrayy->keys()" |
||
| 2241 | * |
||
| 2242 | * @return static |
||
| 2243 | * <p>(Immutable)</p> |
||
| 2244 | * |
||
| 2245 | * @see Arrayy::keys() |
||
| 2246 | * |
||
| 2247 | * @psalm-return static<TKey,T> |
||
| 2248 | * @psalm-mutation-free |
||
| 2249 | */ |
||
| 2250 | 2 | public function getKeys() |
|
| 2254 | |||
| 2255 | /** |
||
| 2256 | * Get the current array from the "Arrayy"-object as object. |
||
| 2257 | * |
||
| 2258 | * @return \stdClass |
||
| 2259 | */ |
||
| 2260 | 4 | public function getObject(): \stdClass |
|
| 2264 | |||
| 2265 | /** |
||
| 2266 | * alias: for "Arrayy->randomImmutable()" |
||
| 2267 | * |
||
| 2268 | * @return static |
||
| 2269 | * <p>(Immutable)</p> |
||
| 2270 | * |
||
| 2271 | * @see Arrayy::randomImmutable() |
||
| 2272 | * |
||
| 2273 | * @psalm-return static<TKey,T> |
||
| 2274 | * @psalm-mutation-free |
||
| 2275 | */ |
||
| 2276 | 4 | public function getRandom(): self |
|
| 2280 | |||
| 2281 | /** |
||
| 2282 | * alias: for "Arrayy->randomKey()" |
||
| 2283 | * |
||
| 2284 | * @return mixed |
||
| 2285 | * <p>Get a key/index or null if there wasn't a key/index.</p> |
||
| 2286 | * |
||
| 2287 | * @see Arrayy::randomKey() |
||
| 2288 | */ |
||
| 2289 | 3 | public function getRandomKey() |
|
| 2293 | |||
| 2294 | /** |
||
| 2295 | * alias: for "Arrayy->randomKeys()" |
||
| 2296 | * |
||
| 2297 | * @param int $number |
||
| 2298 | * |
||
| 2299 | * @return static |
||
| 2300 | * <p>(Immutable)</p> |
||
| 2301 | * |
||
| 2302 | * @see Arrayy::randomKeys() |
||
| 2303 | * |
||
| 2304 | * @psalm-return static<TKey,T> |
||
| 2305 | * @psalm-mutation-free |
||
| 2306 | */ |
||
| 2307 | 8 | public function getRandomKeys(int $number): self |
|
| 2311 | |||
| 2312 | /** |
||
| 2313 | * alias: for "Arrayy->randomValue()" |
||
| 2314 | * |
||
| 2315 | * @return mixed |
||
| 2316 | * <p>Get a random value or null if there wasn't a value.</p> |
||
| 2317 | * |
||
| 2318 | * @see Arrayy::randomValue() |
||
| 2319 | */ |
||
| 2320 | 3 | public function getRandomValue() |
|
| 2324 | |||
| 2325 | /** |
||
| 2326 | * alias: for "Arrayy->randomValues()" |
||
| 2327 | * |
||
| 2328 | * @param int $number |
||
| 2329 | * |
||
| 2330 | * @return static |
||
| 2331 | * <p>(Immutable)</p> |
||
| 2332 | * |
||
| 2333 | * @see Arrayy::randomValues() |
||
| 2334 | * |
||
| 2335 | * @psalm-return static<TKey,T> |
||
| 2336 | * @psalm-mutation-free |
||
| 2337 | */ |
||
| 2338 | 6 | public function getRandomValues(int $number): self |
|
| 2342 | |||
| 2343 | /** |
||
| 2344 | * Gets all values. |
||
| 2345 | * |
||
| 2346 | * @return static |
||
| 2347 | * <p>The values of all elements in this array, in the order they |
||
| 2348 | * appear in the array.</p> |
||
| 2349 | * |
||
| 2350 | * @psalm-return static<TKey,T> |
||
| 2351 | */ |
||
| 2352 | 4 | public function getValues() |
|
| 2362 | |||
| 2363 | /** |
||
| 2364 | * Gets all values via Generator. |
||
| 2365 | * |
||
| 2366 | * @return \Generator |
||
| 2367 | * <p>The values of all elements in this array, in the order they |
||
| 2368 | * appear in the array as Generator.</p> |
||
| 2369 | * |
||
| 2370 | * @psalm-return \Generator<TKey,T> |
||
| 2371 | */ |
||
| 2372 | 4 | public function getValuesYield(): \Generator |
|
| 2376 | |||
| 2377 | /** |
||
| 2378 | * Group values from a array according to the results of a closure. |
||
| 2379 | * |
||
| 2380 | * @param callable|string $grouper <p>A callable function name.</p> |
||
| 2381 | * @param bool $saveKeys |
||
| 2382 | * |
||
| 2383 | * @return static |
||
| 2384 | * <p>(Immutable)</p> |
||
| 2385 | * |
||
| 2386 | * @psalm-return static<TKey,T> |
||
| 2387 | * @psalm-mutation-free |
||
| 2388 | */ |
||
| 2389 | 4 | public function group($grouper, bool $saveKeys = false): self |
|
| 2430 | |||
| 2431 | /** |
||
| 2432 | * Check if an array has a given key. |
||
| 2433 | * |
||
| 2434 | * @param mixed $key |
||
| 2435 | * |
||
| 2436 | * @return bool |
||
| 2437 | */ |
||
| 2438 | 23 | public function has($key): bool |
|
| 2449 | |||
| 2450 | /** |
||
| 2451 | * Check if an array has a given value. |
||
| 2452 | * |
||
| 2453 | * INFO: if you need to search recursive please use ```contains()``` |
||
| 2454 | * |
||
| 2455 | * @param mixed $value |
||
| 2456 | * |
||
| 2457 | * @return bool |
||
| 2458 | */ |
||
| 2459 | 1 | public function hasValue($value): bool |
|
| 2463 | |||
| 2464 | /** |
||
| 2465 | * Implodes the values of this array. |
||
| 2466 | * |
||
| 2467 | * @param string $glue |
||
| 2468 | * |
||
| 2469 | * @return string |
||
| 2470 | */ |
||
| 2471 | 28 | public function implode(string $glue = ''): string |
|
| 2475 | |||
| 2476 | /** |
||
| 2477 | * Implodes the keys of this array. |
||
| 2478 | * |
||
| 2479 | * @param string $glue |
||
| 2480 | * |
||
| 2481 | * @return string |
||
| 2482 | */ |
||
| 2483 | 8 | public function implodeKeys(string $glue = ''): string |
|
| 2487 | |||
| 2488 | /** |
||
| 2489 | * Given a list and an iterate-function that returns |
||
| 2490 | * a key for each element in the list (or a property name), |
||
| 2491 | * returns an object with an index of each item. |
||
| 2492 | * |
||
| 2493 | * @param mixed $key |
||
| 2494 | * |
||
| 2495 | * @return static |
||
| 2496 | * <p>(Immutable)</p> |
||
| 2497 | * |
||
| 2498 | * @psalm-return static<TKey,T> |
||
| 2499 | * @psalm-mutation-free |
||
| 2500 | */ |
||
| 2501 | 4 | public function indexBy($key): self |
|
| 2518 | |||
| 2519 | /** |
||
| 2520 | * alias: for "Arrayy->searchIndex()" |
||
| 2521 | * |
||
| 2522 | * @param mixed $value <p>The value to search for.</p> |
||
| 2523 | * |
||
| 2524 | * @return false|mixed |
||
| 2525 | * |
||
| 2526 | * @see Arrayy::searchIndex() |
||
| 2527 | */ |
||
| 2528 | 4 | public function indexOf($value) |
|
| 2532 | |||
| 2533 | /** |
||
| 2534 | * Get everything but the last..$to items. |
||
| 2535 | * |
||
| 2536 | * @param int $to |
||
| 2537 | * |
||
| 2538 | * @return static |
||
| 2539 | * <p>(Immutable)</p> |
||
| 2540 | * |
||
| 2541 | * @psalm-return static<TKey,T> |
||
| 2542 | * @psalm-mutation-free |
||
| 2543 | */ |
||
| 2544 | 12 | public function initial(int $to = 1): self |
|
| 2548 | |||
| 2549 | /** |
||
| 2550 | * Return an array with all elements found in input array. |
||
| 2551 | * |
||
| 2552 | * @param array $search |
||
| 2553 | * @param bool $keepKeys |
||
| 2554 | * |
||
| 2555 | * @return static |
||
| 2556 | * <p>(Immutable)</p> |
||
| 2557 | * |
||
| 2558 | * @psalm-param array<mixed,mixed>|array<TKey,T> $search |
||
| 2559 | * @psalm-return static<TKey,T> |
||
| 2560 | * @psalm-mutation-free |
||
| 2561 | */ |
||
| 2562 | 4 | public function intersection(array $search, bool $keepKeys = false): self |
|
| 2563 | { |
||
| 2564 | 4 | if ($keepKeys) { |
|
| 2565 | 1 | return static::create( |
|
| 2566 | 1 | \array_uintersect( |
|
| 2567 | 1 | $this->getArray(), |
|
| 2568 | 1 | $search, |
|
| 2569 | 1 | static function ($a, $b) { |
|
| 2570 | 1 | return $a === $b ? 0 : -1; |
|
| 2571 | 1 | } |
|
| 2572 | ), |
||
| 2573 | 1 | $this->iteratorClass, |
|
| 2574 | 1 | false |
|
| 2575 | ); |
||
| 2576 | } |
||
| 2577 | |||
| 2578 | 3 | return static::create( |
|
| 2579 | 3 | \array_values(\array_intersect($this->getArray(), $search)), |
|
| 2580 | 3 | $this->iteratorClass, |
|
| 2581 | 3 | false |
|
| 2582 | ); |
||
| 2583 | } |
||
| 2584 | |||
| 2585 | /** |
||
| 2586 | * Return an array with all elements found in input array. |
||
| 2587 | * |
||
| 2588 | * @param array ...$array |
||
| 2589 | * |
||
| 2590 | * @return static |
||
| 2591 | * <p>(Immutable)</p> |
||
| 2592 | * |
||
| 2593 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$array |
||
| 2594 | * @psalm-return static<TKey,T> |
||
| 2595 | * @psalm-mutation-free |
||
| 2596 | */ |
||
| 2597 | 1 | public function intersectionMulti(...$array): self |
|
| 2605 | |||
| 2606 | /** |
||
| 2607 | * Return a boolean flag which indicates whether the two input arrays have any common elements. |
||
| 2608 | * |
||
| 2609 | * @param array $search |
||
| 2610 | * |
||
| 2611 | * @return bool |
||
| 2612 | * |
||
| 2613 | * @psalm-param array<mixed,mixed>|array<TKey,T> $search |
||
| 2614 | */ |
||
| 2615 | 1 | public function intersects(array $search): bool |
|
| 2619 | |||
| 2620 | /** |
||
| 2621 | * Invoke a function on all of an array's values. |
||
| 2622 | * |
||
| 2623 | * @param callable $callable |
||
| 2624 | * @param mixed $arguments |
||
| 2625 | * |
||
| 2626 | * @return static |
||
| 2627 | * <p>(Immutable)</p> |
||
| 2628 | * |
||
| 2629 | * @psalm-param callable(T=,mixed):mixed $callable |
||
| 2630 | * @psalm-return static<TKey,T> |
||
| 2631 | * @psalm-mutation-free |
||
| 2632 | */ |
||
| 2633 | 1 | public function invoke($callable, $arguments = []): self |
|
| 2657 | |||
| 2658 | /** |
||
| 2659 | * Check whether array is associative or not. |
||
| 2660 | * |
||
| 2661 | * @param bool $recursive |
||
| 2662 | * |
||
| 2663 | * @return bool |
||
| 2664 | * <p>Returns true if associative, false otherwise.</p> |
||
| 2665 | */ |
||
| 2666 | 15 | View Code Duplication | public function isAssoc(bool $recursive = false): bool |
| 2680 | |||
| 2681 | /** |
||
| 2682 | * Check if a given key or keys are empty. |
||
| 2683 | * |
||
| 2684 | * @param int|int[]|string|string[]|null $keys |
||
| 2685 | * |
||
| 2686 | * @return bool |
||
| 2687 | * <p>Returns true if empty, false otherwise.</p> |
||
| 2688 | */ |
||
| 2689 | 38 | public function isEmpty($keys = null): bool |
|
| 2707 | |||
| 2708 | /** |
||
| 2709 | * Check if the current array is equal to the given "$array" or not. |
||
| 2710 | * |
||
| 2711 | * @param array $array |
||
| 2712 | * |
||
| 2713 | * @return bool |
||
| 2714 | * |
||
| 2715 | * @psalm-param array<mixed,mixed> $array |
||
| 2716 | */ |
||
| 2717 | 1 | public function isEqual(array $array): bool |
|
| 2721 | |||
| 2722 | /** |
||
| 2723 | * Check if the current array is a multi-array. |
||
| 2724 | * |
||
| 2725 | * @return bool |
||
| 2726 | */ |
||
| 2727 | 22 | public function isMultiArray(): bool |
|
| 2735 | |||
| 2736 | /** |
||
| 2737 | * Check whether array is numeric or not. |
||
| 2738 | * |
||
| 2739 | * @return bool |
||
| 2740 | * <p>Returns true if numeric, false otherwise.</p> |
||
| 2741 | */ |
||
| 2742 | 5 | View Code Duplication | public function isNumeric(): bool |
| 2756 | |||
| 2757 | /** |
||
| 2758 | * Check if the current array is sequential [0, 1, 2, 3, 4, 5 ...] or not. |
||
| 2759 | * |
||
| 2760 | * @param bool $recursive |
||
| 2761 | * |
||
| 2762 | * @return bool |
||
| 2763 | */ |
||
| 2764 | 9 | public function isSequential(bool $recursive = false): bool |
|
| 2781 | |||
| 2782 | /** |
||
| 2783 | * @return array |
||
| 2784 | * |
||
| 2785 | * @psalm-return array<TKey,T> |
||
| 2786 | */ |
||
| 2787 | public function jsonSerialize(): array |
||
| 2791 | |||
| 2792 | /** |
||
| 2793 | * Gets the key/index of the element at the current internal iterator position. |
||
| 2794 | * |
||
| 2795 | * @return int|string|null |
||
| 2796 | */ |
||
| 2797 | public function key() |
||
| 2801 | |||
| 2802 | /** |
||
| 2803 | * Checks if the given key exists in the provided array. |
||
| 2804 | * |
||
| 2805 | * INFO: This method only use "array_key_exists()" if you want to use "dot"-notation, |
||
| 2806 | * then you need to use "Arrayy->offsetExists()". |
||
| 2807 | * |
||
| 2808 | * @param int|string $key the key to look for |
||
| 2809 | * |
||
| 2810 | * @return bool |
||
| 2811 | */ |
||
| 2812 | 127 | public function keyExists($key): bool |
|
| 2816 | |||
| 2817 | /** |
||
| 2818 | * Get all keys from the current array. |
||
| 2819 | * |
||
| 2820 | * @param bool $recursive [optional] <p> |
||
| 2821 | * Get all keys, also from all sub-arrays from an multi-dimensional array. |
||
| 2822 | * </p> |
||
| 2823 | * @param mixed|null $search_values [optional] <p> |
||
| 2824 | * If specified, then only keys containing these values are returned. |
||
| 2825 | * </p> |
||
| 2826 | * @param bool $strict [optional] <p> |
||
| 2827 | * Determines if strict comparison (===) should be used during the search. |
||
| 2828 | * </p> |
||
| 2829 | * |
||
| 2830 | * @return static |
||
| 2831 | * <p>(Immutable) An array of all the keys in input.</p> |
||
| 2832 | * |
||
| 2833 | * @psalm-return static<TKey,T> |
||
| 2834 | * @psalm-mutation-free |
||
| 2835 | */ |
||
| 2836 | 29 | public function keys( |
|
| 2837 | bool $recursive = false, |
||
| 2838 | $search_values = null, |
||
| 2839 | bool $strict = true |
||
| 2840 | ): self { |
||
| 2841 | |||
| 2842 | // recursive |
||
| 2843 | |||
| 2844 | 29 | if ($recursive === true) { |
|
| 2845 | 4 | $array = $this->array_keys_recursive( |
|
| 2846 | 4 | null, |
|
| 2847 | 4 | $search_values, |
|
| 2848 | 4 | $strict |
|
| 2849 | ); |
||
| 2850 | |||
| 2851 | 4 | return static::create( |
|
| 2852 | 4 | $array, |
|
| 2853 | 4 | $this->iteratorClass, |
|
| 2854 | 4 | false |
|
| 2855 | ); |
||
| 2856 | } |
||
| 2857 | |||
| 2858 | // non recursive |
||
| 2859 | |||
| 2860 | 28 | if ($search_values === null) { |
|
| 2861 | 28 | $arrayFunction = function (): \Generator { |
|
| 2862 | 28 | foreach ($this->getGenerator() as $key => $value) { |
|
| 2863 | 26 | yield $key; |
|
| 2864 | } |
||
| 2865 | 28 | }; |
|
| 2866 | } else { |
||
| 2867 | 1 | $arrayFunction = function () use ($search_values, $strict): \Generator { |
|
| 2868 | 1 | $is_array_tmp = \is_array($search_values); |
|
| 2869 | |||
| 2870 | 1 | foreach ($this->getGenerator() as $key => $value) { |
|
| 2871 | View Code Duplication | if ( |
|
| 2872 | ( |
||
| 2873 | 1 | $is_array_tmp === false |
|
| 2874 | && |
||
| 2875 | 1 | $strict === true |
|
| 2876 | && |
||
| 2877 | 1 | $search_values === $value |
|
| 2878 | ) |
||
| 2879 | || |
||
| 2880 | ( |
||
| 2881 | 1 | $is_array_tmp === false |
|
| 2882 | && |
||
| 2883 | 1 | $strict === false |
|
| 2884 | && |
||
| 2885 | 1 | $search_values == $value |
|
| 2886 | ) |
||
| 2887 | || |
||
| 2888 | ( |
||
| 2889 | 1 | $is_array_tmp === true |
|
| 2890 | && |
||
| 2891 | 1 | \in_array($value, $search_values, $strict) |
|
| 2892 | ) |
||
| 2893 | ) { |
||
| 2894 | 1 | yield $key; |
|
| 2895 | } |
||
| 2896 | } |
||
| 2897 | 1 | }; |
|
| 2898 | } |
||
| 2899 | |||
| 2900 | 28 | return static::create( |
|
| 2901 | 28 | $arrayFunction, |
|
| 2902 | 28 | $this->iteratorClass, |
|
| 2903 | 28 | false |
|
| 2904 | ); |
||
| 2905 | } |
||
| 2906 | |||
| 2907 | /** |
||
| 2908 | * Sort an array by key in reverse order. |
||
| 2909 | * |
||
| 2910 | * @param int $sort_flags [optional] <p> |
||
| 2911 | * You may modify the behavior of the sort using the optional |
||
| 2912 | * parameter sort_flags, for details |
||
| 2913 | * see sort. |
||
| 2914 | * </p> |
||
| 2915 | * |
||
| 2916 | * @return $this |
||
| 2917 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 2918 | * |
||
| 2919 | * @psalm-return $this<TKey,T> |
||
| 2920 | */ |
||
| 2921 | 4 | public function krsort(int $sort_flags = 0): self |
|
| 2929 | |||
| 2930 | /** |
||
| 2931 | * Get the last value from the current array. |
||
| 2932 | * |
||
| 2933 | * @return mixed |
||
| 2934 | * <p>Return null if there wasn't a element.</p> |
||
| 2935 | */ |
||
| 2936 | 17 | public function last() |
|
| 2945 | |||
| 2946 | /** |
||
| 2947 | * Get the last key from the current array. |
||
| 2948 | * |
||
| 2949 | * @return mixed |
||
| 2950 | * <p>Return null if there wasn't a element.</p> |
||
| 2951 | */ |
||
| 2952 | 21 | public function lastKey() |
|
| 2958 | |||
| 2959 | /** |
||
| 2960 | * Get the last value(s) from the current array. |
||
| 2961 | * |
||
| 2962 | * @param int|null $number |
||
| 2963 | * |
||
| 2964 | * @return static |
||
| 2965 | * <p>(Immutable)</p> |
||
| 2966 | * |
||
| 2967 | * @psalm-return static<TKey,T> |
||
| 2968 | * @psalm-mutation-free |
||
| 2969 | */ |
||
| 2970 | 13 | public function lastsImmutable(int $number = null): self |
|
| 3001 | |||
| 3002 | /** |
||
| 3003 | * Get the last value(s) from the current array. |
||
| 3004 | * |
||
| 3005 | * @param int|null $number |
||
| 3006 | * |
||
| 3007 | * @return $this |
||
| 3008 | * <p>(Mutable)</p> |
||
| 3009 | * |
||
| 3010 | * @psalm-return $this<TKey,T> |
||
| 3011 | */ |
||
| 3012 | 13 | public function lastsMutable(int $number = null): self |
|
| 3041 | |||
| 3042 | /** |
||
| 3043 | * Count the values from the current array. |
||
| 3044 | * |
||
| 3045 | * alias: for "Arrayy->count()" |
||
| 3046 | * |
||
| 3047 | * @param int $mode |
||
| 3048 | * |
||
| 3049 | * @return int |
||
| 3050 | * |
||
| 3051 | * @see Arrayy::count() |
||
| 3052 | */ |
||
| 3053 | 20 | public function length(int $mode = \COUNT_NORMAL): int |
|
| 3057 | |||
| 3058 | /** |
||
| 3059 | * Apply the given function to the every element of the array, |
||
| 3060 | * collecting the results. |
||
| 3061 | * |
||
| 3062 | * @param callable $callable |
||
| 3063 | * @param bool $useKeyAsSecondParameter |
||
| 3064 | * @param mixed ...$arguments |
||
| 3065 | * |
||
| 3066 | * @return static |
||
| 3067 | * <p>(Immutable) Arrayy object with modified elements.</p> |
||
| 3068 | * |
||
| 3069 | * @psalm-param callable(T=,TKey=,mixed):mixed|callable(T=,mixed):mixed $callable |
||
| 3070 | * @psalm-return static<TKey,T> |
||
| 3071 | * @psalm-mutation-free |
||
| 3072 | */ |
||
| 3073 | 5 | public function map(callable $callable, bool $useKeyAsSecondParameter = false, ...$arguments) |
|
| 3074 | { |
||
| 3075 | 5 | $useArguments = \func_num_args() > 2; |
|
| 3076 | |||
| 3077 | 5 | return static::create( |
|
| 3078 | 5 | function () use ($useArguments, $callable, $useKeyAsSecondParameter, $arguments) { |
|
| 3079 | 5 | foreach ($this->getGenerator() as $key => $value) { |
|
| 3080 | 4 | if ($useArguments) { |
|
| 3081 | 3 | if ($useKeyAsSecondParameter) { |
|
| 3082 | yield $key => $callable($value, $key, ...$arguments); |
||
| 3083 | } else { |
||
| 3084 | 3 | yield $key => $callable($value, ...$arguments); |
|
| 3085 | } |
||
| 3086 | } else { |
||
| 3087 | /** @noinspection NestedPositiveIfStatementsInspection */ |
||
| 3088 | 4 | if ($useKeyAsSecondParameter) { |
|
| 3089 | yield $key => $callable($value, $key); |
||
| 3090 | } else { |
||
| 3091 | 4 | yield $key => $callable($value); |
|
| 3092 | } |
||
| 3093 | } |
||
| 3094 | } |
||
| 3095 | 5 | }, |
|
| 3096 | 5 | $this->iteratorClass, |
|
| 3097 | 5 | false |
|
| 3098 | ); |
||
| 3099 | } |
||
| 3100 | |||
| 3101 | /** |
||
| 3102 | * Check if all items in current array match a truth test. |
||
| 3103 | * |
||
| 3104 | * @param \Closure $closure |
||
| 3105 | * |
||
| 3106 | * @return bool |
||
| 3107 | */ |
||
| 3108 | 15 | View Code Duplication | public function matches(\Closure $closure): bool |
| 3124 | |||
| 3125 | /** |
||
| 3126 | * Check if any item in the current array matches a truth test. |
||
| 3127 | * |
||
| 3128 | * @param \Closure $closure |
||
| 3129 | * |
||
| 3130 | * @return bool |
||
| 3131 | */ |
||
| 3132 | 14 | View Code Duplication | public function matchesAny(\Closure $closure): bool |
| 3148 | |||
| 3149 | /** |
||
| 3150 | * Get the max value from an array. |
||
| 3151 | * |
||
| 3152 | * @return mixed |
||
| 3153 | */ |
||
| 3154 | 10 | View Code Duplication | public function max() |
| 3173 | |||
| 3174 | /** |
||
| 3175 | * Merge the new $array into the current array. |
||
| 3176 | * |
||
| 3177 | * - keep key,value from the current array, also if the index is in the new $array |
||
| 3178 | * |
||
| 3179 | * @param array $array |
||
| 3180 | * @param bool $recursive |
||
| 3181 | * |
||
| 3182 | * @return static |
||
| 3183 | * <p>(Immutable)</p> |
||
| 3184 | * |
||
| 3185 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 3186 | * @psalm-return static<TKey,T> |
||
| 3187 | * @psalm-mutation-free |
||
| 3188 | */ |
||
| 3189 | 25 | View Code Duplication | public function mergeAppendKeepIndex(array $array = [], bool $recursive = false): self |
| 3203 | |||
| 3204 | /** |
||
| 3205 | * Merge the new $array into the current array. |
||
| 3206 | * |
||
| 3207 | * - replace duplicate assoc-keys from the current array with the key,values from the new $array |
||
| 3208 | * - create new indexes |
||
| 3209 | * |
||
| 3210 | * @param array $array |
||
| 3211 | * @param bool $recursive |
||
| 3212 | * |
||
| 3213 | * @return static |
||
| 3214 | * <p>(Immutable)</p> |
||
| 3215 | * |
||
| 3216 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 3217 | * @psalm-return static<TKey,T> |
||
| 3218 | * @psalm-mutation-free |
||
| 3219 | */ |
||
| 3220 | 16 | View Code Duplication | public function mergeAppendNewIndex(array $array = [], bool $recursive = false): self |
| 3234 | |||
| 3235 | /** |
||
| 3236 | * Merge the the current array into the $array. |
||
| 3237 | * |
||
| 3238 | * - use key,value from the new $array, also if the index is in the current array |
||
| 3239 | * |
||
| 3240 | * @param array $array |
||
| 3241 | * @param bool $recursive |
||
| 3242 | * |
||
| 3243 | * @return static |
||
| 3244 | * <p>(Immutable)</p> |
||
| 3245 | * |
||
| 3246 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 3247 | * @psalm-return static<TKey,T> |
||
| 3248 | * @psalm-mutation-free |
||
| 3249 | */ |
||
| 3250 | 16 | View Code Duplication | public function mergePrependKeepIndex(array $array = [], bool $recursive = false): self |
| 3264 | |||
| 3265 | /** |
||
| 3266 | * Merge the current array into the new $array. |
||
| 3267 | * |
||
| 3268 | * - replace duplicate assoc-keys from new $array with the key,values from the current array |
||
| 3269 | * - create new indexes |
||
| 3270 | * |
||
| 3271 | * @param array $array |
||
| 3272 | * @param bool $recursive |
||
| 3273 | * |
||
| 3274 | * @return static |
||
| 3275 | * <p>(Immutable)</p> |
||
| 3276 | * |
||
| 3277 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 3278 | * @psalm-return static<TKey,T> |
||
| 3279 | * @psalm-mutation-free |
||
| 3280 | */ |
||
| 3281 | 17 | View Code Duplication | public function mergePrependNewIndex(array $array = [], bool $recursive = false): self |
| 3295 | |||
| 3296 | /** |
||
| 3297 | * @return ArrayyMeta|static |
||
| 3298 | */ |
||
| 3299 | 15 | public static function meta() |
|
| 3303 | |||
| 3304 | /** |
||
| 3305 | * Get the min value from an array. |
||
| 3306 | * |
||
| 3307 | * @return mixed |
||
| 3308 | */ |
||
| 3309 | 10 | View Code Duplication | public function min() |
| 3328 | |||
| 3329 | /** |
||
| 3330 | * Get the most used value from the array. |
||
| 3331 | * |
||
| 3332 | * @return mixed |
||
| 3333 | * <p>Return null if there wasn't a element.</p> |
||
| 3334 | */ |
||
| 3335 | 3 | public function mostUsedValue() |
|
| 3339 | |||
| 3340 | /** |
||
| 3341 | * Get the most used value from the array. |
||
| 3342 | * |
||
| 3343 | * @param int|null $number <p>How many values you will take?</p> |
||
| 3344 | * |
||
| 3345 | * @return static |
||
| 3346 | * <p>(Immutable)</p> |
||
| 3347 | * |
||
| 3348 | * @psalm-return static<TKey,T> |
||
| 3349 | * @psalm-mutation-free |
||
| 3350 | */ |
||
| 3351 | 3 | public function mostUsedValues(int $number = null): self |
|
| 3355 | |||
| 3356 | /** |
||
| 3357 | * Move an array element to a new index. |
||
| 3358 | * |
||
| 3359 | * cherry-picked from: http://stackoverflow.com/questions/12624153/move-an-array-element-to-a-new-index-in-php |
||
| 3360 | * |
||
| 3361 | * @param int|string $from |
||
| 3362 | * @param int $to |
||
| 3363 | * |
||
| 3364 | * @return static |
||
| 3365 | * <p>(Immutable)</p> |
||
| 3366 | * |
||
| 3367 | * @psalm-return static<TKey,T> |
||
| 3368 | * @psalm-mutation-free |
||
| 3369 | */ |
||
| 3370 | 1 | public function moveElement($from, $to): self |
|
| 3403 | |||
| 3404 | /** |
||
| 3405 | * Move an array element to the first place. |
||
| 3406 | * |
||
| 3407 | * INFO: Instead of "Arrayy->moveElement()" this method will NOT |
||
| 3408 | * loss the keys of an indexed array. |
||
| 3409 | * |
||
| 3410 | * @param int|string $key |
||
| 3411 | * |
||
| 3412 | * @return static |
||
| 3413 | * <p>(Immutable)</p> |
||
| 3414 | * |
||
| 3415 | * @psalm-return static<TKey,T> |
||
| 3416 | * @psalm-mutation-free |
||
| 3417 | */ |
||
| 3418 | 1 | View Code Duplication | public function moveElementToFirstPlace($key): self |
| 3434 | |||
| 3435 | /** |
||
| 3436 | * Move an array element to the last place. |
||
| 3437 | * |
||
| 3438 | * INFO: Instead of "Arrayy->moveElement()" this method will NOT |
||
| 3439 | * loss the keys of an indexed array. |
||
| 3440 | * |
||
| 3441 | * @param int|string $key |
||
| 3442 | * |
||
| 3443 | * @return static |
||
| 3444 | * <p>(Immutable)</p> |
||
| 3445 | * |
||
| 3446 | * @psalm-return static<TKey,T> |
||
| 3447 | * @psalm-mutation-free |
||
| 3448 | */ |
||
| 3449 | 1 | View Code Duplication | public function moveElementToLastPlace($key): self |
| 3465 | |||
| 3466 | /** |
||
| 3467 | * Moves the internal iterator position to the next element and returns this element. |
||
| 3468 | * |
||
| 3469 | * @return mixed |
||
| 3470 | */ |
||
| 3471 | public function next() |
||
| 3475 | |||
| 3476 | /** |
||
| 3477 | * Get the next nth keys and values from the array. |
||
| 3478 | * |
||
| 3479 | * @param int $step |
||
| 3480 | * @param int $offset |
||
| 3481 | * |
||
| 3482 | * @return static |
||
| 3483 | * <p>(Immutable)</p> |
||
| 3484 | * |
||
| 3485 | * @psalm-return static<TKey,T> |
||
| 3486 | * @psalm-mutation-free |
||
| 3487 | */ |
||
| 3488 | public function nth(int $step, int $offset = 0): self |
||
| 3507 | |||
| 3508 | /** |
||
| 3509 | * Get a subset of the items from the given array. |
||
| 3510 | * |
||
| 3511 | * @param mixed[] $keys |
||
| 3512 | * |
||
| 3513 | * @return static |
||
| 3514 | * <p>(Immutable)</p> |
||
| 3515 | * |
||
| 3516 | * @psalm-return static<TKey,T> |
||
| 3517 | * @psalm-mutation-free |
||
| 3518 | */ |
||
| 3519 | 1 | public function only(array $keys): self |
|
| 3529 | |||
| 3530 | /** |
||
| 3531 | * Pad array to the specified size with a given value. |
||
| 3532 | * |
||
| 3533 | * @param int $size <p>Size of the result array.</p> |
||
| 3534 | * @param mixed $value <p>Empty value by default.</p> |
||
| 3535 | * |
||
| 3536 | * @return static |
||
| 3537 | * <p>(Immutable) Arrayy object padded to $size with $value.</p> |
||
| 3538 | * |
||
| 3539 | * @psalm-return static<TKey,T> |
||
| 3540 | * @psalm-mutation-free |
||
| 3541 | */ |
||
| 3542 | 5 | public function pad(int $size, $value): self |
|
| 3550 | |||
| 3551 | /** |
||
| 3552 | * Partitions this array in two array according to a predicate. |
||
| 3553 | * Keys are preserved in the resulting array. |
||
| 3554 | * |
||
| 3555 | * @param \Closure $closure |
||
| 3556 | * <p>The predicate on which to partition.</p> |
||
| 3557 | * |
||
| 3558 | * @return array<int, static> |
||
| 3559 | * <p>An array with two elements. The first element contains the array |
||
| 3560 | * of elements where the predicate returned TRUE, the second element |
||
| 3561 | * contains the array of elements where the predicate returned FALSE.</p> |
||
| 3562 | * |
||
| 3563 | * @psalm-return array<int, static<mixed,T>> |
||
| 3564 | */ |
||
| 3565 | 1 | public function partition(\Closure $closure): array |
|
| 3581 | |||
| 3582 | /** |
||
| 3583 | * Pop a specified value off the end of the current array. |
||
| 3584 | * |
||
| 3585 | * @return mixed |
||
| 3586 | * <p>(Mutable) The popped element from the current array.</p> |
||
| 3587 | */ |
||
| 3588 | 5 | public function pop() |
|
| 3594 | |||
| 3595 | /** |
||
| 3596 | * Prepend a (key) + value to the current array. |
||
| 3597 | * |
||
| 3598 | * @param mixed $value |
||
| 3599 | * @param mixed $key |
||
| 3600 | * |
||
| 3601 | * @return $this |
||
| 3602 | * <p>(Mutable) Return this Arrayy object, with the prepended value.</p> |
||
| 3603 | * |
||
| 3604 | * @psalm-return $this<TKey,T> |
||
| 3605 | */ |
||
| 3606 | 11 | public function prepend($value, $key = null) |
|
| 3622 | |||
| 3623 | /** |
||
| 3624 | * Add a suffix to each key. |
||
| 3625 | * |
||
| 3626 | * @param mixed $suffix |
||
| 3627 | * |
||
| 3628 | * @return static |
||
| 3629 | * <p>(Immutable) Return an Arrayy object, with the prepended keys.</p> |
||
| 3630 | * |
||
| 3631 | * @psalm-return static<TKey,T> |
||
| 3632 | * @psalm-mutation-free |
||
| 3633 | */ |
||
| 3634 | 10 | View Code Duplication | public function prependToEachKey($suffix): self |
| 3660 | |||
| 3661 | /** |
||
| 3662 | * Add a suffix to each value. |
||
| 3663 | * |
||
| 3664 | * @param mixed $suffix |
||
| 3665 | * |
||
| 3666 | * @return static |
||
| 3667 | * <p>(Immutable) Return an Arrayy object, with the prepended values.</p> |
||
| 3668 | * |
||
| 3669 | * @psalm-return static<TKey,T> |
||
| 3670 | * @psalm-mutation-free |
||
| 3671 | */ |
||
| 3672 | 10 | View Code Duplication | public function prependToEachValue($suffix): self |
| 3700 | |||
| 3701 | /** |
||
| 3702 | * Return the value of a given key and |
||
| 3703 | * delete the key. |
||
| 3704 | * |
||
| 3705 | * @param int|int[]|string|string[]|null $keyOrKeys |
||
| 3706 | * @param mixed $fallback |
||
| 3707 | * |
||
| 3708 | * @return mixed |
||
| 3709 | */ |
||
| 3710 | 1 | public function pull($keyOrKeys = null, $fallback = null) |
|
| 3732 | |||
| 3733 | /** |
||
| 3734 | * Push one or more values onto the end of array at once. |
||
| 3735 | * |
||
| 3736 | * @param array ...$args |
||
| 3737 | * |
||
| 3738 | * @return $this |
||
| 3739 | * <p>(Mutable) Return this Arrayy object, with pushed elements to the end of array.</p> |
||
| 3740 | * |
||
| 3741 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
| 3742 | * |
||
| 3743 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$args |
||
| 3744 | * @psalm-return $this<TKey,T> |
||
| 3745 | */ |
||
| 3746 | 5 | public function push(...$args) |
|
| 3764 | |||
| 3765 | /** |
||
| 3766 | * Get a random value from the current array. |
||
| 3767 | * |
||
| 3768 | * @param int|null $number <p>How many values you will take?</p> |
||
| 3769 | * |
||
| 3770 | * @return static |
||
| 3771 | * <p>(Immutable)</p> |
||
| 3772 | * |
||
| 3773 | * @psalm-return static<TKey,T> |
||
| 3774 | * @psalm-mutation-free |
||
| 3775 | */ |
||
| 3776 | 19 | public function randomImmutable(int $number = null): self |
|
| 3809 | |||
| 3810 | /** |
||
| 3811 | * Pick a random key/index from the keys of this array. |
||
| 3812 | * |
||
| 3813 | * @throws \RangeException If array is empty |
||
| 3814 | * |
||
| 3815 | * @return mixed |
||
| 3816 | * <p>Get a key/index or null if there wasn't a key/index.</p> |
||
| 3817 | */ |
||
| 3818 | 4 | public function randomKey() |
|
| 3828 | |||
| 3829 | /** |
||
| 3830 | * Pick a given number of random keys/indexes out of this array. |
||
| 3831 | * |
||
| 3832 | * @param int $number <p>The number of keys/indexes (should be <= \count($this->array))</p> |
||
| 3833 | * |
||
| 3834 | * @throws \RangeException If array is empty |
||
| 3835 | * |
||
| 3836 | * @return static |
||
| 3837 | * <p>(Immutable)</p> |
||
| 3838 | * |
||
| 3839 | * @psalm-return static<TKey,T> |
||
| 3840 | * @psalm-mutation-free |
||
| 3841 | */ |
||
| 3842 | 13 | public function randomKeys(int $number): self |
|
| 3870 | |||
| 3871 | /** |
||
| 3872 | * Get a random value from the current array. |
||
| 3873 | * |
||
| 3874 | * @param int|null $number <p>How many values you will take?</p> |
||
| 3875 | * |
||
| 3876 | * @return $this |
||
| 3877 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 3878 | * |
||
| 3879 | * @psalm-return $this<TKey,T> |
||
| 3880 | */ |
||
| 3881 | 17 | public function randomMutable(int $number = null): self |
|
| 3906 | |||
| 3907 | /** |
||
| 3908 | * Pick a random value from the values of this array. |
||
| 3909 | * |
||
| 3910 | * @return mixed |
||
| 3911 | * <p>Get a random value or null if there wasn't a value.</p> |
||
| 3912 | */ |
||
| 3913 | 4 | public function randomValue() |
|
| 3923 | |||
| 3924 | /** |
||
| 3925 | * Pick a given number of random values out of this array. |
||
| 3926 | * |
||
| 3927 | * @param int $number |
||
| 3928 | * |
||
| 3929 | * @return static |
||
| 3930 | * <p>(Mutable)</p> |
||
| 3931 | * |
||
| 3932 | * @psalm-return static<TKey,T> |
||
| 3933 | */ |
||
| 3934 | 7 | public function randomValues(int $number): self |
|
| 3938 | |||
| 3939 | /** |
||
| 3940 | * Get a random value from an array, with the ability to skew the results. |
||
| 3941 | * |
||
| 3942 | * Example: randomWeighted(['foo' => 1, 'bar' => 2]) has a 66% chance of returning bar. |
||
| 3943 | * |
||
| 3944 | * @param array $array |
||
| 3945 | * @param int|null $number <p>How many values you will take?</p> |
||
| 3946 | * |
||
| 3947 | * @return static |
||
| 3948 | * <p>(Immutable)</p> |
||
| 3949 | * |
||
| 3950 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 3951 | * @psalm-return static<TKey,T> |
||
| 3952 | * @psalm-mutation-free |
||
| 3953 | */ |
||
| 3954 | 9 | public function randomWeighted(array $array, int $number = null): self |
|
| 3969 | |||
| 3970 | /** |
||
| 3971 | * Reduce the current array via callable e.g. anonymous-function. |
||
| 3972 | * |
||
| 3973 | * @param callable $callable |
||
| 3974 | * @param mixed $init |
||
| 3975 | * |
||
| 3976 | * @return static |
||
| 3977 | * <p>(Immutable)</p> |
||
| 3978 | * |
||
| 3979 | * @psalm-return static<TKey,T> |
||
| 3980 | * @psalm-mutation-free |
||
| 3981 | */ |
||
| 3982 | 18 | public function reduce($callable, $init = []): self |
|
| 4012 | |||
| 4013 | /** |
||
| 4014 | * @param bool $unique |
||
| 4015 | * |
||
| 4016 | * @return static |
||
| 4017 | * <p>(Immutable)</p> |
||
| 4018 | * |
||
| 4019 | * @psalm-return static<TKey,T> |
||
| 4020 | * @psalm-mutation-free |
||
| 4021 | */ |
||
| 4022 | 14 | public function reduce_dimension(bool $unique = true): self |
|
| 4041 | |||
| 4042 | /** |
||
| 4043 | * Create a numerically re-indexed Arrayy object. |
||
| 4044 | * |
||
| 4045 | * @return $this |
||
| 4046 | * <p>(Mutable) Return this Arrayy object, with re-indexed array-elements.</p> |
||
| 4047 | * |
||
| 4048 | * @psalm-return $this<TKey,T> |
||
| 4049 | */ |
||
| 4050 | 9 | public function reindex(): self |
|
| 4058 | |||
| 4059 | /** |
||
| 4060 | * Return all items that fail the truth test. |
||
| 4061 | * |
||
| 4062 | * @param \Closure $closure |
||
| 4063 | * |
||
| 4064 | * @return static |
||
| 4065 | * <p>(Immutable)</p> |
||
| 4066 | * |
||
| 4067 | * @psalm-return static<TKey,T> |
||
| 4068 | * @psalm-mutation-free |
||
| 4069 | */ |
||
| 4070 | 1 | View Code Duplication | public function reject(\Closure $closure): self |
| 4087 | |||
| 4088 | /** |
||
| 4089 | * Remove a value from the current array (optional using dot-notation). |
||
| 4090 | * |
||
| 4091 | * @param mixed $key |
||
| 4092 | * |
||
| 4093 | * @return static |
||
| 4094 | * <p>(Mutable)</p> |
||
| 4095 | * |
||
| 4096 | * @psalm-param TKey $key |
||
| 4097 | * @psalm-return static<TKey,T> |
||
| 4098 | */ |
||
| 4099 | 18 | public function remove($key) |
|
| 4122 | |||
| 4123 | /** |
||
| 4124 | * alias: for "Arrayy->removeValue()" |
||
| 4125 | * |
||
| 4126 | * @param mixed $element |
||
| 4127 | * |
||
| 4128 | * @return static |
||
| 4129 | * <p>(Immutable)</p> |
||
| 4130 | * |
||
| 4131 | * @psalm-param T $element |
||
| 4132 | * @psalm-return static<TKey,T> |
||
| 4133 | * @psalm-mutation-free |
||
| 4134 | */ |
||
| 4135 | 8 | public function removeElement($element) |
|
| 4139 | |||
| 4140 | /** |
||
| 4141 | * Remove the first value from the current array. |
||
| 4142 | * |
||
| 4143 | * @return static |
||
| 4144 | * <p>(Immutable)</p> |
||
| 4145 | * |
||
| 4146 | * @psalm-return static<TKey,T> |
||
| 4147 | * @psalm-mutation-free |
||
| 4148 | */ |
||
| 4149 | 7 | View Code Duplication | public function removeFirst(): self |
| 4161 | |||
| 4162 | /** |
||
| 4163 | * Remove the last value from the current array. |
||
| 4164 | * |
||
| 4165 | * @return static |
||
| 4166 | * <p>(Immutable)</p> |
||
| 4167 | * |
||
| 4168 | * @psalm-return static<TKey,T> |
||
| 4169 | * @psalm-mutation-free |
||
| 4170 | */ |
||
| 4171 | 7 | View Code Duplication | public function removeLast(): self |
| 4183 | |||
| 4184 | /** |
||
| 4185 | * Removes a particular value from an array (numeric or associative). |
||
| 4186 | * |
||
| 4187 | * @param mixed $value |
||
| 4188 | * |
||
| 4189 | * @return static |
||
| 4190 | * <p>(Immutable)</p> |
||
| 4191 | * |
||
| 4192 | * @psalm-param T $value |
||
| 4193 | * @psalm-return static<TKey,T> |
||
| 4194 | * @psalm-mutation-free |
||
| 4195 | */ |
||
| 4196 | 8 | public function removeValue($value): self |
|
| 4219 | |||
| 4220 | /** |
||
| 4221 | * Generate array of repeated arrays. |
||
| 4222 | * |
||
| 4223 | * @param int $times <p>How many times has to be repeated.</p> |
||
| 4224 | * |
||
| 4225 | * @return static |
||
| 4226 | * <p>(Immutable)</p> |
||
| 4227 | * |
||
| 4228 | * @psalm-return static<TKey,T> |
||
| 4229 | * @psalm-mutation-free |
||
| 4230 | */ |
||
| 4231 | 1 | public function repeat($times): self |
|
| 4243 | |||
| 4244 | /** |
||
| 4245 | * Replace a key with a new key/value pair. |
||
| 4246 | * |
||
| 4247 | * @param mixed $replace |
||
| 4248 | * @param mixed $key |
||
| 4249 | * @param mixed $value |
||
| 4250 | * |
||
| 4251 | * @return static |
||
| 4252 | * <p>(Immutable)</p> |
||
| 4253 | * |
||
| 4254 | * @psalm-return static<TKey,T> |
||
| 4255 | * @psalm-mutation-free |
||
| 4256 | */ |
||
| 4257 | 2 | public function replace($replace, $key, $value): self |
|
| 4264 | |||
| 4265 | /** |
||
| 4266 | * Create an array using the current array as values and the other array as keys. |
||
| 4267 | * |
||
| 4268 | * @param array $keys <p>An array of keys.</p> |
||
| 4269 | * |
||
| 4270 | * @return static |
||
| 4271 | * <p>(Immutable) Arrayy object with keys from the other array.</p> |
||
| 4272 | * |
||
| 4273 | * @psalm-param array<mixed,mixed>|array<mixed,TKey> $keys |
||
| 4274 | * @psalm-return static<TKey,T> |
||
| 4275 | * @psalm-mutation-free |
||
| 4276 | */ |
||
| 4277 | 2 | public function replaceAllKeys(array $keys): self |
|
| 4285 | |||
| 4286 | /** |
||
| 4287 | * Create an array using the current array as keys and the other array as values. |
||
| 4288 | * |
||
| 4289 | * @param array $array <p>An array o values.</p> |
||
| 4290 | * |
||
| 4291 | * @return static |
||
| 4292 | * <p>(Immutable) Arrayy object with values from the other array.</p> |
||
| 4293 | * |
||
| 4294 | * @psalm-param array<mixed,T> $array |
||
| 4295 | * @psalm-return static<TKey,T> |
||
| 4296 | * @psalm-mutation-free |
||
| 4297 | */ |
||
| 4298 | 2 | public function replaceAllValues(array $array): self |
|
| 4306 | |||
| 4307 | /** |
||
| 4308 | * Replace the keys in an array with another set. |
||
| 4309 | * |
||
| 4310 | * @param array $keys <p>An array of keys matching the array's size</p> |
||
| 4311 | * |
||
| 4312 | * @return static |
||
| 4313 | * <p>(Immutable)</p> |
||
| 4314 | * |
||
| 4315 | * @psalm-param array<mixed,mixed>|array<mixed,TKey> $keys |
||
| 4316 | * @psalm-return static<TKey,T> |
||
| 4317 | * @psalm-mutation-free |
||
| 4318 | */ |
||
| 4319 | 1 | public function replaceKeys(array $keys): self |
|
| 4330 | |||
| 4331 | /** |
||
| 4332 | * Replace the first matched value in an array. |
||
| 4333 | * |
||
| 4334 | * @param mixed $search <p>The value to replace.</p> |
||
| 4335 | * @param mixed $replacement <p>The value to replace.</p> |
||
| 4336 | * |
||
| 4337 | * @return static |
||
| 4338 | * <p>(Immutable)</p> |
||
| 4339 | * |
||
| 4340 | * @psalm-return static<TKey,T> |
||
| 4341 | * @psalm-mutation-free |
||
| 4342 | */ |
||
| 4343 | 3 | public function replaceOneValue($search, $replacement = ''): self |
|
| 4358 | |||
| 4359 | /** |
||
| 4360 | * Replace values in the current array. |
||
| 4361 | * |
||
| 4362 | * @param mixed $search <p>The value to replace.</p> |
||
| 4363 | * @param mixed $replacement <p>What to replace it with.</p> |
||
| 4364 | * |
||
| 4365 | * @return static |
||
| 4366 | * <p>(Immutable)</p> |
||
| 4367 | * |
||
| 4368 | * @psalm-return static<TKey,T> |
||
| 4369 | * @psalm-mutation-free |
||
| 4370 | */ |
||
| 4371 | 1 | public function replaceValues($search, $replacement = ''): self |
|
| 4372 | { |
||
| 4373 | 1 | return $this->each( |
|
| 4374 | 1 | static function ($value) use ($search, $replacement) { |
|
| 4375 | 1 | return \str_replace($search, $replacement, $value); |
|
| 4376 | 1 | } |
|
| 4377 | ); |
||
| 4378 | } |
||
| 4379 | |||
| 4380 | /** |
||
| 4381 | * Get the last elements from index $from until the end of this array. |
||
| 4382 | * |
||
| 4383 | * @param int $from |
||
| 4384 | * |
||
| 4385 | * @return static |
||
| 4386 | * <p>(Immutable)</p> |
||
| 4387 | * |
||
| 4388 | * @psalm-return static<TKey,T> |
||
| 4389 | * @psalm-mutation-free |
||
| 4390 | */ |
||
| 4391 | 15 | View Code Duplication | public function rest(int $from = 1): self |
| 4401 | |||
| 4402 | /** |
||
| 4403 | * Return the array in the reverse order. |
||
| 4404 | * |
||
| 4405 | * @return $this |
||
| 4406 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 4407 | * |
||
| 4408 | * @psalm-return $this<TKey,T> |
||
| 4409 | */ |
||
| 4410 | 9 | public function reverse(): self |
|
| 4418 | |||
| 4419 | /** |
||
| 4420 | * Sort an array in reverse order. |
||
| 4421 | * |
||
| 4422 | * @param int $sort_flags [optional] <p> |
||
| 4423 | * You may modify the behavior of the sort using the optional |
||
| 4424 | * parameter sort_flags, for details |
||
| 4425 | * see sort. |
||
| 4426 | * </p> |
||
| 4427 | * |
||
| 4428 | * @return $this |
||
| 4429 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 4430 | * |
||
| 4431 | * @psalm-return $this<TKey,T> |
||
| 4432 | */ |
||
| 4433 | 4 | public function rsort(int $sort_flags = 0): self |
|
| 4441 | |||
| 4442 | /** |
||
| 4443 | * Search for the first index of the current array via $value. |
||
| 4444 | * |
||
| 4445 | * @param mixed $value |
||
| 4446 | * |
||
| 4447 | * @return false|float|int|string |
||
| 4448 | * <p>Will return <b>FALSE</b> if the value can't be found.</p> |
||
| 4449 | */ |
||
| 4450 | 21 | public function searchIndex($value) |
|
| 4460 | |||
| 4461 | /** |
||
| 4462 | * Search for the value of the current array via $index. |
||
| 4463 | * |
||
| 4464 | * @param mixed $index |
||
| 4465 | * |
||
| 4466 | * @return static |
||
| 4467 | * <p>(Immutable) Will return a empty Arrayy if the value wasn't found.</p> |
||
| 4468 | * |
||
| 4469 | * @psalm-return static<TKey,T> |
||
| 4470 | * @psalm-mutation-free |
||
| 4471 | */ |
||
| 4472 | 9 | public function searchValue($index): self |
|
| 4502 | |||
| 4503 | /** |
||
| 4504 | * Set a value for the current array (optional using dot-notation). |
||
| 4505 | * |
||
| 4506 | * @param string $key <p>The key to set.</p> |
||
| 4507 | * @param mixed $value <p>Its value.</p> |
||
| 4508 | * |
||
| 4509 | * @return $this |
||
| 4510 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 4511 | * |
||
| 4512 | * @psalm-param TKey $key |
||
| 4513 | * @psalm-param T $value |
||
| 4514 | * @psalm-return $this<TKey,T> |
||
| 4515 | */ |
||
| 4516 | 18 | public function set($key, $value): self |
|
| 4524 | |||
| 4525 | /** |
||
| 4526 | * Get a value from a array and set it if it was not. |
||
| 4527 | * |
||
| 4528 | * WARNING: this method only set the value, if the $key is not already set |
||
| 4529 | * |
||
| 4530 | * @param mixed $key <p>The key</p> |
||
| 4531 | * @param mixed $fallback <p>The default value to set if it isn't.</p> |
||
| 4532 | * |
||
| 4533 | * @return mixed |
||
| 4534 | * <p>(Mutable)</p> |
||
| 4535 | */ |
||
| 4536 | 11 | public function setAndGet($key, $fallback = null) |
|
| 4547 | |||
| 4548 | /** |
||
| 4549 | * Shifts a specified value off the beginning of array. |
||
| 4550 | * |
||
| 4551 | * @return mixed |
||
| 4552 | * <p>(Mutable) A shifted element from the current array.</p> |
||
| 4553 | */ |
||
| 4554 | 5 | public function shift() |
|
| 4560 | |||
| 4561 | /** |
||
| 4562 | * Shuffle the current array. |
||
| 4563 | * |
||
| 4564 | * @param bool $secure <p>using a CSPRNG | @link https://paragonie.com/b/JvICXzh_jhLyt4y3</p> |
||
| 4565 | * @param array $array [optional] |
||
| 4566 | * |
||
| 4567 | * @return static |
||
| 4568 | * <p>(Immutable)</p> |
||
| 4569 | * |
||
| 4570 | * @psalm-param array<mixed,mixed>|array<TKey,T> $array |
||
| 4571 | * @psalm-return static<TKey,T> |
||
| 4572 | * @psalm-mutation-free |
||
| 4573 | */ |
||
| 4574 | 2 | public function shuffle(bool $secure = false, array $array = null): self |
|
| 4575 | { |
||
| 4576 | 2 | if ($array === null) { |
|
| 4577 | 2 | $array = $this->getArray(); |
|
| 4578 | } |
||
| 4579 | |||
| 4580 | 2 | if ($secure !== true) { |
|
| 4581 | /** @noinspection NonSecureShuffleUsageInspection */ |
||
| 4582 | 2 | \shuffle($array); |
|
| 4583 | } else { |
||
| 4584 | 1 | $size = \count($array, \COUNT_NORMAL); |
|
| 4585 | 1 | $keys = \array_keys($array); |
|
| 4586 | 1 | for ($i = $size - 1; $i > 0; --$i) { |
|
| 4587 | try { |
||
| 4588 | 1 | $r = \random_int(0, $i); |
|
| 4589 | } catch (\Exception $e) { |
||
| 4590 | /** @noinspection RandomApiMigrationInspection */ |
||
| 4591 | $r = \mt_rand(0, $i); |
||
| 4592 | } |
||
| 4593 | 1 | if ($r !== $i) { |
|
| 4594 | 1 | $temp = $array[$keys[$r]]; |
|
| 4595 | 1 | $array[$keys[$r]] = $array[$keys[$i]]; |
|
| 4596 | 1 | $array[$keys[$i]] = $temp; |
|
| 4597 | } |
||
| 4598 | } |
||
| 4599 | |||
| 4600 | // reset indices |
||
| 4601 | 1 | $array = \array_values($array); |
|
| 4602 | } |
||
| 4603 | |||
| 4604 | 2 | foreach ($array as $key => $value) { |
|
| 4605 | // check if recursive is needed |
||
| 4606 | 2 | if (\is_array($value) === true) { |
|
| 4607 | 2 | $array[$key] = $this->shuffle($secure, $value); |
|
| 4608 | } |
||
| 4609 | } |
||
| 4610 | |||
| 4611 | 2 | return static::create( |
|
| 4612 | 2 | $array, |
|
| 4613 | 2 | $this->iteratorClass, |
|
| 4614 | 2 | false |
|
| 4615 | ); |
||
| 4616 | } |
||
| 4617 | |||
| 4618 | /** |
||
| 4619 | * Count the values from the current array. |
||
| 4620 | * |
||
| 4621 | * alias: for "Arrayy->count()" |
||
| 4622 | * |
||
| 4623 | * @param int $mode |
||
| 4624 | * |
||
| 4625 | * @return int |
||
| 4626 | */ |
||
| 4627 | 20 | public function size(int $mode = \COUNT_NORMAL): int |
|
| 4631 | |||
| 4632 | /** |
||
| 4633 | * Checks whether array has exactly $size items. |
||
| 4634 | * |
||
| 4635 | * @param int $size |
||
| 4636 | * |
||
| 4637 | * @return bool |
||
| 4638 | */ |
||
| 4639 | 1 | View Code Duplication | public function sizeIs(int $size): bool |
| 4653 | |||
| 4654 | /** |
||
| 4655 | * Checks whether array has between $fromSize to $toSize items. $toSize can be |
||
| 4656 | * smaller than $fromSize. |
||
| 4657 | * |
||
| 4658 | * @param int $fromSize |
||
| 4659 | * @param int $toSize |
||
| 4660 | * |
||
| 4661 | * @return bool |
||
| 4662 | */ |
||
| 4663 | 1 | public function sizeIsBetween(int $fromSize, int $toSize): bool |
|
| 4683 | |||
| 4684 | /** |
||
| 4685 | * Checks whether array has more than $size items. |
||
| 4686 | * |
||
| 4687 | * @param int $size |
||
| 4688 | * |
||
| 4689 | * @return bool |
||
| 4690 | */ |
||
| 4691 | 1 | View Code Duplication | public function sizeIsGreaterThan(int $size): bool |
| 4705 | |||
| 4706 | /** |
||
| 4707 | * Checks whether array has less than $size items. |
||
| 4708 | * |
||
| 4709 | * @param int $size |
||
| 4710 | * |
||
| 4711 | * @return bool |
||
| 4712 | */ |
||
| 4713 | 1 | View Code Duplication | public function sizeIsLessThan(int $size): bool |
| 4727 | |||
| 4728 | /** |
||
| 4729 | * Counts all elements in an array, or something in an object. |
||
| 4730 | * |
||
| 4731 | * <p> |
||
| 4732 | * For objects, if you have SPL installed, you can hook into count() by implementing interface {@see Countable}. |
||
| 4733 | * The interface has exactly one method, {@see Countable::count()}, which returns the return value for the count() |
||
| 4734 | * function. Please see the {@see Array} section of the manual for a detailed explanation of how arrays are |
||
| 4735 | * implemented and used in PHP. |
||
| 4736 | * </p> |
||
| 4737 | * |
||
| 4738 | * @return int |
||
| 4739 | * <p> |
||
| 4740 | * The number of elements in var, which is |
||
| 4741 | * typically an array, since anything else will have one |
||
| 4742 | * element. |
||
| 4743 | * </p> |
||
| 4744 | * <p> |
||
| 4745 | * If var is not an array or an object with |
||
| 4746 | * implemented Countable interface, |
||
| 4747 | * 1 will be returned. |
||
| 4748 | * There is one exception, if var is &null;, |
||
| 4749 | * 0 will be returned. |
||
| 4750 | * </p> |
||
| 4751 | * <p> |
||
| 4752 | * Caution: count may return 0 for a variable that isn't set, |
||
| 4753 | * but it may also return 0 for a variable that has been initialized with an |
||
| 4754 | * empty array. Use isset to test if a variable is set. |
||
| 4755 | * </p> |
||
| 4756 | */ |
||
| 4757 | 10 | public function sizeRecursive(): int |
|
| 4761 | |||
| 4762 | /** |
||
| 4763 | * Extract a slice of the array. |
||
| 4764 | * |
||
| 4765 | * @param int $offset <p>Slice begin index.</p> |
||
| 4766 | * @param int|null $length <p>Length of the slice.</p> |
||
| 4767 | * @param bool $preserveKeys <p>Whether array keys are preserved or no.</p> |
||
| 4768 | * |
||
| 4769 | * @return static |
||
| 4770 | * <p>(Immutable) A slice of the original array with length $length.</p> |
||
| 4771 | * |
||
| 4772 | * @psalm-return static<TKey,T> |
||
| 4773 | * @psalm-mutation-free |
||
| 4774 | */ |
||
| 4775 | 5 | public function slice(int $offset, int $length = null, bool $preserveKeys = false) |
|
| 4788 | |||
| 4789 | /** |
||
| 4790 | * Sort the current array and optional you can keep the keys. |
||
| 4791 | * |
||
| 4792 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 4793 | * @param int $strategy <p>sort_flags => use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 4794 | * <strong>SORT_NATURAL</strong></p> |
||
| 4795 | * @param bool $keepKeys |
||
| 4796 | * |
||
| 4797 | * @return static |
||
| 4798 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 4799 | * |
||
| 4800 | * @psalm-return static<TKey,T> |
||
| 4801 | */ |
||
| 4802 | 20 | public function sort($direction = \SORT_ASC, int $strategy = \SORT_REGULAR, bool $keepKeys = false): self |
|
| 4813 | |||
| 4814 | /** |
||
| 4815 | * Sort the current array by key. |
||
| 4816 | * |
||
| 4817 | * @see http://php.net/manual/en/function.ksort.php |
||
| 4818 | * @see http://php.net/manual/en/function.krsort.php |
||
| 4819 | * |
||
| 4820 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 4821 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 4822 | * <strong>SORT_NATURAL</strong></p> |
||
| 4823 | * |
||
| 4824 | * @return $this |
||
| 4825 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 4826 | * |
||
| 4827 | * @psalm-return $this<TKey,T> |
||
| 4828 | */ |
||
| 4829 | 18 | public function sortKeys($direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
| 4837 | |||
| 4838 | /** |
||
| 4839 | * Sort the current array by value. |
||
| 4840 | * |
||
| 4841 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 4842 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 4843 | * <strong>SORT_NATURAL</strong></p> |
||
| 4844 | * |
||
| 4845 | * @return static |
||
| 4846 | * <p>(Mutable)</p> |
||
| 4847 | * |
||
| 4848 | * @psalm-return static<TKey,T> |
||
| 4849 | */ |
||
| 4850 | 1 | public function sortValueKeepIndex($direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
| 4854 | |||
| 4855 | /** |
||
| 4856 | * Sort the current array by value. |
||
| 4857 | * |
||
| 4858 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 4859 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 4860 | * <strong>SORT_NATURAL</strong></p> |
||
| 4861 | * |
||
| 4862 | * @return static |
||
| 4863 | * <p>(Mutable)</p> |
||
| 4864 | * |
||
| 4865 | * @psalm-return static<TKey,T> |
||
| 4866 | */ |
||
| 4867 | 1 | public function sortValueNewIndex($direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
| 4871 | |||
| 4872 | /** |
||
| 4873 | * Sort a array by value, by a closure or by a property. |
||
| 4874 | * |
||
| 4875 | * - If the sorter is null, the array is sorted naturally. |
||
| 4876 | * - Associative (string) keys will be maintained, but numeric keys will be re-indexed. |
||
| 4877 | * |
||
| 4878 | * @param callable|string|null $sorter |
||
| 4879 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or |
||
| 4880 | * <strong>SORT_DESC</strong></p> |
||
| 4881 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 4882 | * <strong>SORT_NATURAL</strong></p> |
||
| 4883 | * |
||
| 4884 | * @return static |
||
| 4885 | * <p>(Immutable)</p> |
||
| 4886 | * |
||
| 4887 | * @psalm-return static<TKey,T> |
||
| 4888 | * @psalm-mutation-free |
||
| 4889 | */ |
||
| 4890 | 1 | public function sorter($sorter = null, $direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
| 4891 | { |
||
| 4892 | 1 | $array = $this->getArray(); |
|
| 4893 | 1 | $direction = $this->getDirection($direction); |
|
| 4894 | |||
| 4895 | // Transform all values into their results. |
||
| 4896 | 1 | if ($sorter) { |
|
| 4897 | 1 | $arrayy = static::create( |
|
| 4898 | 1 | $array, |
|
| 4899 | 1 | $this->iteratorClass, |
|
| 4900 | 1 | false |
|
| 4901 | ); |
||
| 4902 | |||
| 4903 | 1 | $results = $arrayy->each( |
|
| 4904 | 1 | function ($value) use ($sorter) { |
|
| 4905 | 1 | if (\is_callable($sorter) === true) { |
|
| 4906 | 1 | return $sorter($value); |
|
| 4907 | } |
||
| 4908 | |||
| 4909 | 1 | return $this->get($sorter); |
|
| 4910 | 1 | } |
|
| 4911 | ); |
||
| 4912 | |||
| 4913 | 1 | $results = $results->getArray(); |
|
| 4914 | } else { |
||
| 4915 | 1 | $results = $array; |
|
| 4916 | } |
||
| 4917 | |||
| 4918 | // Sort by the results and replace by original values |
||
| 4919 | 1 | \array_multisort($results, $direction, $strategy, $array); |
|
| 4920 | |||
| 4921 | 1 | return static::create( |
|
| 4922 | 1 | $array, |
|
| 4923 | 1 | $this->iteratorClass, |
|
| 4924 | 1 | false |
|
| 4925 | ); |
||
| 4926 | } |
||
| 4927 | |||
| 4928 | /** |
||
| 4929 | * @param int $offset |
||
| 4930 | * @param int|null $length |
||
| 4931 | * @param array $replacement |
||
| 4932 | * |
||
| 4933 | * @return static |
||
| 4934 | * <p>(Immutable)</p> |
||
| 4935 | * |
||
| 4936 | * @psalm-param array<mixed,mixed>|array<mixed,T> $replacement |
||
| 4937 | * @psalm-return static<TKey,T> |
||
| 4938 | * @psalm-mutation-free |
||
| 4939 | */ |
||
| 4940 | 1 | public function splice(int $offset, int $length = null, $replacement = []): self |
|
| 4957 | |||
| 4958 | /** |
||
| 4959 | * Split an array in the given amount of pieces. |
||
| 4960 | * |
||
| 4961 | * @param int $numberOfPieces |
||
| 4962 | * @param bool $keepKeys |
||
| 4963 | * |
||
| 4964 | * @return static |
||
| 4965 | * <p>(Immutable)</p> |
||
| 4966 | * |
||
| 4967 | * @psalm-return static<TKey,T> |
||
| 4968 | * @psalm-mutation-free |
||
| 4969 | */ |
||
| 4970 | 1 | public function split(int $numberOfPieces = 2, bool $keepKeys = false): self |
|
| 4989 | |||
| 4990 | /** |
||
| 4991 | * Stripe all empty items. |
||
| 4992 | * |
||
| 4993 | * @return static |
||
| 4994 | * <p>(Immutable)</p> |
||
| 4995 | * |
||
| 4996 | * @psalm-return static<TKey,T> |
||
| 4997 | * @psalm-mutation-free |
||
| 4998 | */ |
||
| 4999 | 1 | public function stripEmpty(): self |
|
| 5000 | { |
||
| 5001 | 1 | return $this->filter( |
|
| 5002 | 1 | static function ($item) { |
|
| 5003 | 1 | if ($item === null) { |
|
| 5004 | 1 | return false; |
|
| 5005 | } |
||
| 5006 | |||
| 5007 | 1 | return (bool) \trim((string) $item); |
|
| 5008 | 1 | } |
|
| 5009 | ); |
||
| 5010 | } |
||
| 5011 | |||
| 5012 | /** |
||
| 5013 | * Swap two values between positions by key. |
||
| 5014 | * |
||
| 5015 | * @param int|string $swapA <p>a key in the array</p> |
||
| 5016 | * @param int|string $swapB <p>a key in the array</p> |
||
| 5017 | * |
||
| 5018 | * @return static |
||
| 5019 | * <p>(Immutable)</p> |
||
| 5020 | * |
||
| 5021 | * @psalm-return static<TKey,T> |
||
| 5022 | * @psalm-mutation-free |
||
| 5023 | */ |
||
| 5024 | 1 | public function swap($swapA, $swapB): self |
|
| 5036 | |||
| 5037 | /** |
||
| 5038 | * alias: for "Arrayy->getArray()" |
||
| 5039 | * |
||
| 5040 | * @param bool $convertAllArrayyElements |
||
| 5041 | * |
||
| 5042 | * @return array |
||
| 5043 | * |
||
| 5044 | * @see Arrayy::getArray() |
||
| 5045 | * |
||
| 5046 | * @psalm-return array<array-key,mixed> |
||
| 5047 | */ |
||
| 5048 | 241 | public function toArray(bool $convertAllArrayyElements = false): array |
|
| 5052 | |||
| 5053 | /** |
||
| 5054 | * Convert the current array to JSON. |
||
| 5055 | * |
||
| 5056 | * @param int $options [optional] <p>e.g. JSON_PRETTY_PRINT</p> |
||
| 5057 | * @param int $depth [optional] <p>Set the maximum depth. Must be greater than zero.</p> |
||
| 5058 | * |
||
| 5059 | * @return string |
||
| 5060 | */ |
||
| 5061 | 7 | public function toJson(int $options = 0, int $depth = 512): string |
|
| 5070 | |||
| 5071 | /** |
||
| 5072 | * @param string[]|null $items |
||
| 5073 | * @param string[] $helper |
||
| 5074 | * |
||
| 5075 | * @return static |
||
| 5076 | * |
||
| 5077 | * @psalm-return static<mixed,T> |
||
| 5078 | */ |
||
| 5079 | 1 | public function toPermutation(array $items = null, array $helper = []): self |
|
| 5113 | |||
| 5114 | /** |
||
| 5115 | * Implodes array to a string with specified separator. |
||
| 5116 | * |
||
| 5117 | * @param string $separator [optional] <p>The element's separator.</p> |
||
| 5118 | * |
||
| 5119 | * @return string |
||
| 5120 | * <p>The string representation of array, separated by ",".</p> |
||
| 5121 | */ |
||
| 5122 | 19 | public function toString(string $separator = ','): string |
|
| 5126 | |||
| 5127 | /** |
||
| 5128 | * Return a duplicate free copy of the current array. |
||
| 5129 | * |
||
| 5130 | * @return $this |
||
| 5131 | * <p>(Mutable)</p> |
||
| 5132 | * |
||
| 5133 | * @psalm-return $this<TKey,T> |
||
| 5134 | */ |
||
| 5135 | 13 | public function unique(): self |
|
| 5136 | { |
||
| 5137 | // INFO: \array_unique() can't handle e.g. "stdClass"-values in an array |
||
| 5138 | |||
| 5139 | 13 | $this->array = $this->reduce( |
|
| 5140 | 13 | static function ($resultArray, $value) { |
|
| 5141 | 12 | if (!\in_array($value, $resultArray, true)) { |
|
| 5142 | 12 | $resultArray[] = $value; |
|
| 5143 | } |
||
| 5144 | |||
| 5145 | 12 | return $resultArray; |
|
| 5146 | 13 | }, |
|
| 5147 | 13 | [] |
|
| 5148 | 13 | )->getArray(); |
|
| 5149 | 13 | $this->generator = null; |
|
| 5150 | |||
| 5151 | 13 | return $this; |
|
| 5152 | } |
||
| 5153 | |||
| 5154 | /** |
||
| 5155 | * Return a duplicate free copy of the current array. (with the old keys) |
||
| 5156 | * |
||
| 5157 | * @return $this |
||
| 5158 | * <p>(Mutable)</p> |
||
| 5159 | * |
||
| 5160 | * @psalm-return $this<TKey,T> |
||
| 5161 | */ |
||
| 5162 | 11 | public function uniqueKeepIndex(): self |
|
| 5163 | { |
||
| 5164 | // INFO: \array_unique() can't handle e.g. "stdClass"-values in an array |
||
| 5165 | |||
| 5166 | // init |
||
| 5167 | 11 | $array = $this->getArray(); |
|
| 5168 | |||
| 5169 | 11 | $this->array = \array_reduce( |
|
| 5170 | 11 | \array_keys($array), |
|
| 5171 | 11 | static function ($resultArray, $key) use ($array) { |
|
| 5172 | 10 | if (!\in_array($array[$key], $resultArray, true)) { |
|
| 5173 | 10 | $resultArray[$key] = $array[$key]; |
|
| 5174 | } |
||
| 5175 | |||
| 5176 | 10 | return $resultArray; |
|
| 5177 | 11 | }, |
|
| 5178 | 11 | [] |
|
| 5179 | ); |
||
| 5180 | 11 | $this->generator = null; |
|
| 5181 | |||
| 5182 | 11 | if ($this->array === null) { |
|
| 5183 | $this->array = []; |
||
| 5184 | } else { |
||
| 5185 | 11 | $this->array = (array) $this->array; |
|
| 5186 | } |
||
| 5187 | |||
| 5188 | 11 | return $this; |
|
| 5189 | } |
||
| 5190 | |||
| 5191 | /** |
||
| 5192 | * alias: for "Arrayy->unique()" |
||
| 5193 | * |
||
| 5194 | * @return static |
||
| 5195 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
| 5196 | * |
||
| 5197 | * @see Arrayy::unique() |
||
| 5198 | * |
||
| 5199 | * @psalm-return static<TKey,T> |
||
| 5200 | */ |
||
| 5201 | 10 | public function uniqueNewIndex(): self |
|
| 5205 | |||
| 5206 | /** |
||
| 5207 | * Prepends one or more values to the beginning of array at once. |
||
| 5208 | * |
||
| 5209 | * @param array ...$args |
||
| 5210 | * |
||
| 5211 | * @return $this |
||
| 5212 | * <p>(Mutable) Return this Arrayy object, with prepended elements to the beginning of array.</p> |
||
| 5213 | * |
||
| 5214 | * @psalm-param array<mixed,mixed>|array<TKey,T> ...$args |
||
| 5215 | * @psalm-return $this<TKey,T> |
||
| 5216 | */ |
||
| 5217 | 4 | public function unshift(...$args): self |
|
| 5225 | |||
| 5226 | /** |
||
| 5227 | * Tests whether the given closure retrun something valid for all elements of this array. |
||
| 5228 | * |
||
| 5229 | * @param \Closure $closure the predicate |
||
| 5230 | * |
||
| 5231 | * @return bool |
||
| 5232 | * <p>TRUE, if the predicate yields TRUE for all elements, FALSE otherwise.</p> |
||
| 5233 | */ |
||
| 5234 | 1 | View Code Duplication | public function validate(\Closure $closure): bool |
| 5244 | |||
| 5245 | /** |
||
| 5246 | * Get all values from a array. |
||
| 5247 | * |
||
| 5248 | * @return static |
||
| 5249 | * <p>(Immutable)</p> |
||
| 5250 | * |
||
| 5251 | * @psalm-return static<mixed,T> |
||
| 5252 | * @psalm-mutation-free |
||
| 5253 | */ |
||
| 5254 | 2 | public function values(): self |
|
| 5255 | { |
||
| 5256 | 2 | return static::create( |
|
| 5257 | 2 | function () { |
|
| 5258 | /** @noinspection YieldFromCanBeUsedInspection */ |
||
| 5259 | 2 | foreach ($this->getGenerator() as $value) { |
|
| 5260 | 2 | yield $value; |
|
| 5261 | } |
||
| 5262 | 2 | }, |
|
| 5263 | 2 | $this->iteratorClass, |
|
| 5264 | 2 | false |
|
| 5265 | ); |
||
| 5266 | } |
||
| 5267 | |||
| 5268 | /** |
||
| 5269 | * Apply the given function to every element in the array, discarding the results. |
||
| 5270 | * |
||
| 5271 | * @param callable $callable |
||
| 5272 | * @param bool $recursive <p>Whether array will be walked recursively or no</p> |
||
| 5273 | * |
||
| 5274 | * @return $this |
||
| 5275 | * <p>(Mutable) Return this Arrayy object, with modified elements.</p> |
||
| 5276 | * |
||
| 5277 | * @psalm-return $this<TKey,T> |
||
| 5278 | */ |
||
| 5279 | 12 | public function walk($callable, bool $recursive = false): self |
|
| 5291 | |||
| 5292 | /** |
||
| 5293 | * Returns a collection of matching items. |
||
| 5294 | * |
||
| 5295 | * @param string $keyOrPropertyOrMethod the property or method to evaluate |
||
| 5296 | * @param mixed $value the value to match |
||
| 5297 | * |
||
| 5298 | * @throws \InvalidArgumentException if property or method is not defined |
||
| 5299 | * |
||
| 5300 | * @return static |
||
| 5301 | * |
||
| 5302 | * @psalm-param T $value |
||
| 5303 | * @psalm-return static<TKey,T> |
||
| 5304 | */ |
||
| 5305 | 1 | public function where(string $keyOrPropertyOrMethod, $value): self |
|
| 5306 | { |
||
| 5307 | 1 | return $this->filter( |
|
| 5308 | 1 | function ($item) use ($keyOrPropertyOrMethod, $value) { |
|
| 5309 | 1 | $accessorValue = $this->extractValue( |
|
| 5310 | 1 | $item, |
|
| 5311 | 1 | $keyOrPropertyOrMethod |
|
| 5312 | ); |
||
| 5313 | |||
| 5314 | 1 | return $accessorValue === $value; |
|
| 5315 | 1 | } |
|
| 5316 | ); |
||
| 5317 | } |
||
| 5318 | |||
| 5319 | /** |
||
| 5320 | * Convert an array into a object. |
||
| 5321 | * |
||
| 5322 | * @param array $array |
||
| 5323 | * |
||
| 5324 | * @return \stdClass |
||
| 5325 | * |
||
| 5326 | * @psalm-param array<mixed,mixed> $array |
||
| 5327 | */ |
||
| 5328 | 4 | final protected static function arrayToObject(array $array = []): \stdClass |
|
| 5347 | |||
| 5348 | /** |
||
| 5349 | * @param array|\Generator|null $input <p> |
||
| 5350 | * An array containing keys to return. |
||
| 5351 | * </p> |
||
| 5352 | * @param mixed|null $search_values [optional] <p> |
||
| 5353 | * If specified, then only keys containing these values are returned. |
||
| 5354 | * </p> |
||
| 5355 | * @param bool $strict [optional] <p> |
||
| 5356 | * Determines if strict comparison (===) should be used during the |
||
| 5357 | * search. |
||
| 5358 | * </p> |
||
| 5359 | * |
||
| 5360 | * @return array |
||
| 5361 | * <p>an array of all the keys in input</p> |
||
| 5362 | * |
||
| 5363 | * @psalm-param array<mixed,mixed>|\Generator<TKey,T>|null $input |
||
| 5364 | * @psalm-return array<TKey|mixed> |
||
| 5365 | */ |
||
| 5366 | 11 | protected function array_keys_recursive( |
|
| 5427 | |||
| 5428 | /** |
||
| 5429 | * @param mixed $path |
||
| 5430 | * @param callable $callable |
||
| 5431 | * @param array|null $currentOffset |
||
| 5432 | * |
||
| 5433 | * @return void |
||
| 5434 | * |
||
| 5435 | * @psalm-param array<mixed,mixed>|array<TKey,T>|null $currentOffset |
||
| 5436 | */ |
||
| 5437 | 4 | protected function callAtPath($path, $callable, &$currentOffset = null) |
|
| 5466 | |||
| 5467 | /** |
||
| 5468 | * Extracts the value of the given property or method from the object. |
||
| 5469 | * |
||
| 5470 | * @param static $object <p>The object to extract the value from.</p> |
||
| 5471 | * @param string $keyOrPropertyOrMethod <p>The property or method for which the |
||
| 5472 | * value should be extracted.</p> |
||
| 5473 | * |
||
| 5474 | * @throws \InvalidArgumentException if the method or property is not defined |
||
| 5475 | * |
||
| 5476 | * @return mixed |
||
| 5477 | * <p>The value extracted from the specified property or method.</p> |
||
| 5478 | * |
||
| 5479 | * @psalm-param self<TKey,T> $object |
||
| 5480 | */ |
||
| 5481 | 2 | final protected function extractValue(self $object, string $keyOrPropertyOrMethod) |
|
| 5503 | |||
| 5504 | /** |
||
| 5505 | * create a fallback for array |
||
| 5506 | * |
||
| 5507 | * 1. use the current array, if it's a array |
||
| 5508 | * 2. fallback to empty array, if there is nothing |
||
| 5509 | * 3. call "getArray()" on object, if there is a "Arrayy"-object |
||
| 5510 | * 4. call "createFromObject()" on object, if there is a "\Traversable"-object |
||
| 5511 | * 5. call "__toArray()" on object, if the method exists |
||
| 5512 | * 6. cast a string or object with "__toString()" into an array |
||
| 5513 | * 7. throw a "InvalidArgumentException"-Exception |
||
| 5514 | * |
||
| 5515 | * @param mixed $data |
||
| 5516 | * |
||
| 5517 | * @throws \InvalidArgumentException |
||
| 5518 | * |
||
| 5519 | * @return array |
||
| 5520 | * |
||
| 5521 | * @psalm-return array<mixed,mixed>|array<TKey,T> |
||
| 5522 | */ |
||
| 5523 | 1066 | protected function fallbackForArray(&$data): array |
|
| 5533 | |||
| 5534 | /** |
||
| 5535 | * @return bool |
||
| 5536 | * |
||
| 5537 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
| 5538 | */ |
||
| 5539 | 982 | protected function generatorToArray() |
|
| 5550 | |||
| 5551 | /** |
||
| 5552 | * Get correct PHP constant for direction. |
||
| 5553 | * |
||
| 5554 | * @param int|string $direction |
||
| 5555 | * |
||
| 5556 | * @return int |
||
| 5557 | */ |
||
| 5558 | 39 | protected function getDirection($direction): int |
|
| 5580 | |||
| 5581 | /** |
||
| 5582 | * @return TypeCheckPhpDoc[] |
||
| 5583 | * |
||
| 5584 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
| 5585 | */ |
||
| 5586 | 16 | protected function getPropertiesFromPhpDoc() |
|
| 5611 | |||
| 5612 | /** |
||
| 5613 | * @param mixed $glue |
||
| 5614 | * @param mixed $pieces |
||
| 5615 | * @param bool $useKeys |
||
| 5616 | * |
||
| 5617 | * @return string |
||
| 5618 | */ |
||
| 5619 | 36 | protected function implode_recursive($glue = '', $pieces = [], bool $useKeys = false): string |
|
| 5649 | |||
| 5650 | /** |
||
| 5651 | * @param mixed $needle <p> |
||
| 5652 | * The searched value. |
||
| 5653 | * </p> |
||
| 5654 | * <p> |
||
| 5655 | * If needle is a string, the comparison is done |
||
| 5656 | * in a case-sensitive manner. |
||
| 5657 | * </p> |
||
| 5658 | * @param array|\Generator|null $haystack <p> |
||
| 5659 | * The array. |
||
| 5660 | * </p> |
||
| 5661 | * @param bool $strict [optional] <p> |
||
| 5662 | * If the third parameter strict is set to true |
||
| 5663 | * then the in_array function will also check the |
||
| 5664 | * types of the |
||
| 5665 | * needle in the haystack. |
||
| 5666 | * </p> |
||
| 5667 | * |
||
| 5668 | * @return bool |
||
| 5669 | * <p>true if needle is found in the array, false otherwise</p> |
||
| 5670 | * |
||
| 5671 | * @psalm-param array<mixed,mixed>|\Generator<TKey,T>|null $haystack |
||
| 5672 | */ |
||
| 5673 | 19 | protected function in_array_recursive($needle, $haystack = null, $strict = true): bool |
|
| 5698 | |||
| 5699 | /** |
||
| 5700 | * @param mixed $data |
||
| 5701 | * |
||
| 5702 | * @return array|null |
||
| 5703 | * |
||
| 5704 | * @psalm-return array<mixed,mixed>|array<TKey,T>|null |
||
| 5705 | */ |
||
| 5706 | 1066 | protected function internalGetArray(&$data) |
|
| 5754 | |||
| 5755 | /** |
||
| 5756 | * Internal mechanics of remove method. |
||
| 5757 | * |
||
| 5758 | * @param mixed $key |
||
| 5759 | * |
||
| 5760 | * @return bool |
||
| 5761 | */ |
||
| 5762 | 18 | protected function internalRemove($key): bool |
|
| 5795 | |||
| 5796 | /** |
||
| 5797 | * Internal mechanic of set method. |
||
| 5798 | * |
||
| 5799 | * @param int|string|null $key |
||
| 5800 | * @param mixed $value |
||
| 5801 | * @param bool $checkProperties |
||
| 5802 | * |
||
| 5803 | * @return bool |
||
| 5804 | */ |
||
| 5805 | 938 | protected function internalSet( |
|
| 5851 | |||
| 5852 | /** |
||
| 5853 | * Convert a object into an array. |
||
| 5854 | * |
||
| 5855 | * @param object $object |
||
| 5856 | * |
||
| 5857 | * @return mixed |
||
| 5858 | */ |
||
| 5859 | 5 | protected static function objectToArray($object) |
|
| 5871 | |||
| 5872 | /** |
||
| 5873 | * @param array $data |
||
| 5874 | * @param bool $checkPropertiesInConstructor |
||
| 5875 | * |
||
| 5876 | * @return void |
||
| 5877 | * |
||
| 5878 | * @psalm-param array<mixed,T> $data |
||
| 5879 | */ |
||
| 5880 | 1064 | protected function setInitialValuesAndProperties(array &$data, bool $checkPropertiesInConstructor) |
|
| 5922 | |||
| 5923 | /** |
||
| 5924 | * sorting keys |
||
| 5925 | * |
||
| 5926 | * @param array $elements |
||
| 5927 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 5928 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 5929 | * <strong>SORT_NATURAL</strong></p> |
||
| 5930 | * |
||
| 5931 | * @return $this |
||
| 5932 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 5933 | * |
||
| 5934 | * @psalm-param array<mixed,mixed>|array<mixed|TKey,T> $elements |
||
| 5935 | * @psalm-return $this<mixed|TKey,T> |
||
| 5936 | */ |
||
| 5937 | 18 | protected function sorterKeys(array &$elements, $direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
| 5955 | |||
| 5956 | /** |
||
| 5957 | * @param array $elements <p>Warning: used as reference</p> |
||
| 5958 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 5959 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 5960 | * <strong>SORT_NATURAL</strong></p> |
||
| 5961 | * @param bool $keepKeys |
||
| 5962 | * |
||
| 5963 | * @return $this |
||
| 5964 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 5965 | * |
||
| 5966 | * @psalm-param array<mixed> $elements |
||
| 5967 | * @psalm-return $this<mixed|TKey,T> |
||
| 5968 | */ |
||
| 5969 | 20 | protected function sorting(array &$elements, $direction = \SORT_ASC, int $strategy = \SORT_REGULAR, bool $keepKeys = false): self |
|
| 5999 | |||
| 6000 | /** |
||
| 6001 | * @param int|string|null $key |
||
| 6002 | * @param mixed $value |
||
| 6003 | * |
||
| 6004 | * @return void |
||
| 6005 | */ |
||
| 6006 | 87 | private function checkType($key, $value) |
|
| 6024 | } |
||
| 6025 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.