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 |
||
| 22 | class Arrayy extends \ArrayObject implements \IteratorAggregate, \ArrayAccess, \Serializable, \JsonSerializable, \Countable |
||
| 23 | { |
||
| 24 | const ARRAYY_HELPER_TYPES_FOR_ALL_PROPERTIES = '!!!!Arrayy_Helper_Types_For_All_Properties!!!!'; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @var array |
||
| 28 | */ |
||
| 29 | protected $array = []; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var \Arrayy\ArrayyRewindableGenerator|null |
||
| 33 | */ |
||
| 34 | protected $generator; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var string |
||
| 38 | * |
||
| 39 | * @psalm-var class-string<\Arrayy\ArrayyIterator> |
||
| 40 | */ |
||
| 41 | protected $iteratorClass = ArrayyIterator::class; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @var string |
||
| 45 | */ |
||
| 46 | protected $pathSeparator = '.'; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @var bool |
||
| 50 | */ |
||
| 51 | protected $checkPropertyTypes = false; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @var bool |
||
| 55 | */ |
||
| 56 | protected $checkForMissingPropertiesInConstructor = false; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @var bool |
||
| 60 | */ |
||
| 61 | protected $checkPropertiesMismatchInConstructor = false; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @var bool |
||
| 65 | */ |
||
| 66 | protected $checkPropertiesMismatch = true; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @var array<TypeCheckInterface>|\Arrayy\Type\TypeInterface|TypeCheckArray<TypeCheckInterface> |
||
| 70 | */ |
||
| 71 | protected $properties = []; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Initializes |
||
| 75 | * |
||
| 76 | * @param mixed $data <p> |
||
| 77 | * Should be an array or a generator, otherwise it will try |
||
| 78 | * to convert it into an array. |
||
| 79 | * </p> |
||
| 80 | * @param string $iteratorClass optional <p> |
||
| 81 | * You can overwrite the ArrayyIterator, but mostly you don't |
||
| 82 | * need this option. |
||
| 83 | * </p> |
||
| 84 | * @param bool $checkPropertiesInConstructor optional <p> |
||
| 85 | * You need to extend the "Arrayy"-class and you need to set |
||
| 86 | * the $checkPropertiesMismatchInConstructor class property |
||
| 87 | * to |
||
| 88 | * true, otherwise this option didn't not work anyway. |
||
| 89 | * </p> |
||
| 90 | * |
||
| 91 | * @psalm-param class-string<\Arrayy\ArrayyIterator> $iteratorClass |
||
| 92 | */ |
||
| 93 | 1053 | public function __construct( |
|
| 94 | $data = [], |
||
| 95 | string $iteratorClass = ArrayyIterator::class, |
||
| 96 | bool $checkPropertiesInConstructor = true |
||
| 97 | ) { |
||
| 98 | 1053 | $data = $this->fallbackForArray($data); |
|
| 99 | |||
| 100 | // used only for serialize + unserialize, all other methods are overwritten |
||
| 101 | 1051 | parent::__construct([], 0, $iteratorClass); |
|
| 102 | |||
| 103 | 1051 | $this->setInitialValuesAndProperties($data, $checkPropertiesInConstructor); |
|
| 104 | |||
| 105 | 1044 | $this->setIteratorClass($iteratorClass); |
|
| 106 | 1044 | } |
|
| 107 | |||
| 108 | /** |
||
| 109 | * Call object as function. |
||
| 110 | * |
||
| 111 | * @param mixed $key |
||
| 112 | * |
||
| 113 | * @return mixed |
||
| 114 | */ |
||
| 115 | 1 | public function __invoke($key = null) |
|
| 116 | { |
||
| 117 | 1 | if ($key !== null) { |
|
| 118 | 1 | $this->generatorToArray(); |
|
| 119 | |||
| 120 | 1 | return $this->array[$key] ?? false; |
|
| 121 | } |
||
| 122 | |||
| 123 | return $this->getArray(); |
||
| 124 | } |
||
| 125 | |||
| 126 | /** |
||
| 127 | * Whether or not an element exists by key. |
||
| 128 | * |
||
| 129 | * @param mixed $key |
||
| 130 | * |
||
| 131 | * @return bool |
||
| 132 | * <p>True is the key/index exists, otherwise false.</p> |
||
| 133 | */ |
||
| 134 | public function __isset($key): bool |
||
| 135 | { |
||
| 136 | return $this->offsetExists($key); |
||
| 137 | } |
||
| 138 | |||
| 139 | /** |
||
| 140 | * Assigns a value to the specified element. |
||
| 141 | * |
||
| 142 | * @param mixed $key |
||
| 143 | * @param mixed $value |
||
| 144 | * |
||
| 145 | * @return void |
||
| 146 | */ |
||
| 147 | 2 | public function __set($key, $value) |
|
| 148 | { |
||
| 149 | 2 | $this->internalSet($key, $value); |
|
| 150 | 2 | } |
|
| 151 | |||
| 152 | /** |
||
| 153 | * magic to string |
||
| 154 | * |
||
| 155 | * @return string |
||
| 156 | */ |
||
| 157 | 15 | public function __toString(): string |
|
| 158 | { |
||
| 159 | 15 | return $this->toString(); |
|
| 160 | } |
||
| 161 | |||
| 162 | /** |
||
| 163 | * Unset element by key. |
||
| 164 | * |
||
| 165 | * @param mixed $key |
||
| 166 | */ |
||
| 167 | public function __unset($key) |
||
| 168 | { |
||
| 169 | $this->internalRemove($key); |
||
| 170 | } |
||
| 171 | |||
| 172 | /** |
||
| 173 | * Get a value by key. |
||
| 174 | * |
||
| 175 | * @param mixed $key |
||
| 176 | * |
||
| 177 | * @return mixed |
||
| 178 | * <p>Get a Value from the current array.</p> |
||
| 179 | */ |
||
| 180 | 4 | public function &__get($key) |
|
| 181 | { |
||
| 182 | 4 | $return = $this->get($key); |
|
| 183 | |||
| 184 | 4 | if (\is_array($return) === true) { |
|
| 185 | return static::create($return, $this->iteratorClass, false); |
||
| 186 | } |
||
| 187 | |||
| 188 | 4 | return $return; |
|
| 189 | } |
||
| 190 | |||
| 191 | /** |
||
| 192 | * alias: for "Arrayy->append()" |
||
| 193 | * |
||
| 194 | * @param mixed $value |
||
| 195 | * |
||
| 196 | * @return static |
||
| 197 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
| 198 | * |
||
| 199 | * @see Arrayy::append() |
||
| 200 | */ |
||
| 201 | 3 | public function add($value) |
|
| 205 | |||
| 206 | /** |
||
| 207 | * Append a (key) + value to the current array. |
||
| 208 | * |
||
| 209 | * @param mixed $value |
||
| 210 | * @param mixed $key |
||
| 211 | * |
||
| 212 | * @return static |
||
| 213 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
| 214 | */ |
||
| 215 | 13 | public function append($value, $key = null): self |
|
| 216 | { |
||
| 217 | 13 | $this->generatorToArray(); |
|
| 218 | |||
| 219 | 13 | if ($this->properties !== []) { |
|
| 220 | 4 | $this->checkType($key, $value); |
|
| 221 | } |
||
| 222 | |||
| 223 | 12 | if ($key !== null) { |
|
| 224 | if ( |
||
| 225 | isset($this->array[$key]) |
||
| 226 | && |
||
| 227 | \is_array($this->array[$key]) === true |
||
| 228 | ) { |
||
| 229 | $this->array[$key][] = $value; |
||
| 230 | } else { |
||
| 231 | $this->array[$key] = $value; |
||
| 232 | } |
||
| 233 | } else { |
||
| 234 | 12 | $this->array[] = $value; |
|
| 235 | } |
||
| 236 | |||
| 237 | 12 | return $this; |
|
| 238 | } |
||
| 239 | |||
| 240 | /** |
||
| 241 | * Sort the entries by value. |
||
| 242 | * |
||
| 243 | * @param int $sort_flags [optional] <p> |
||
| 244 | * You may modify the behavior of the sort using the optional |
||
| 245 | * parameter sort_flags, for details |
||
| 246 | * see sort. |
||
| 247 | * </p> |
||
| 248 | * |
||
| 249 | * @return static |
||
| 250 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 251 | */ |
||
| 252 | 4 | public function asort(int $sort_flags = 0): self |
|
| 253 | { |
||
| 254 | 4 | $this->generatorToArray(); |
|
| 255 | |||
| 256 | 4 | \asort($this->array, $sort_flags); |
|
| 257 | |||
| 258 | 4 | return $this; |
|
| 259 | } |
||
| 260 | |||
| 261 | /** |
||
| 262 | * Counts all elements in an array, or something in an object. |
||
| 263 | * |
||
| 264 | * <p> |
||
| 265 | * For objects, if you have SPL installed, you can hook into count() by implementing interface {@see Countable}. |
||
| 266 | * The interface has exactly one method, {@see Countable::count()}, which returns the return value for the count() |
||
| 267 | * function. Please see the {@see Array} section of the manual for a detailed explanation of how arrays are |
||
| 268 | * implemented and used in PHP. |
||
| 269 | * </p> |
||
| 270 | * |
||
| 271 | * @see http://php.net/manual/en/function.count.php |
||
| 272 | * |
||
| 273 | * @param int $mode [optional] If the optional mode parameter is set to |
||
| 274 | * COUNT_RECURSIVE (or 1), count |
||
| 275 | * will recursively count the array. This is particularly useful for |
||
| 276 | * counting all the elements of a multidimensional array. count does not detect infinite recursion. |
||
| 277 | * |
||
| 278 | * @return int |
||
| 279 | * <p> |
||
| 280 | * The number of elements in var, which is |
||
| 281 | * typically an array, since anything else will have one |
||
| 282 | * element. |
||
| 283 | * </p> |
||
| 284 | * <p> |
||
| 285 | * If var is not an array or an object with |
||
| 286 | * implemented Countable interface, |
||
| 287 | * 1 will be returned. |
||
| 288 | * There is one exception, if var is &null;, |
||
| 289 | * 0 will be returned. |
||
| 290 | * </p> |
||
| 291 | * <p> |
||
| 292 | * Caution: count may return 0 for a variable that isn't set, |
||
| 293 | * but it may also return 0 for a variable that has been initialized with an |
||
| 294 | * empty array. Use isset to test if a variable is set. |
||
| 295 | * </p> |
||
| 296 | */ |
||
| 297 | 51 | public function count(int $mode = \COUNT_NORMAL): int |
|
| 298 | { |
||
| 299 | 51 | return \count($this->getArray(), $mode); |
|
| 300 | } |
||
| 301 | |||
| 302 | /** |
||
| 303 | * Exchange the array for another one. |
||
| 304 | * |
||
| 305 | * @param array|static $data |
||
| 306 | * |
||
| 307 | * @return array |
||
| 308 | */ |
||
| 309 | 1 | public function exchangeArray($data): array |
|
| 310 | { |
||
| 311 | 1 | $this->array = $this->fallbackForArray($data); |
|
| 312 | |||
| 313 | 1 | return $this->array; |
|
| 314 | } |
||
| 315 | |||
| 316 | /** |
||
| 317 | * Creates a copy of the ArrayyObject. |
||
| 318 | * |
||
| 319 | * @return array |
||
| 320 | */ |
||
| 321 | 5 | public function getArrayCopy(): array |
|
| 322 | { |
||
| 323 | 5 | $this->generatorToArray(); |
|
| 324 | |||
| 325 | 5 | return $this->array; |
|
| 326 | } |
||
| 327 | |||
| 328 | /** |
||
| 329 | * Returns a new iterator, thus implementing the \Iterator interface. |
||
| 330 | * |
||
| 331 | * @return \Iterator<mixed, mixed> |
||
|
|
|||
| 332 | * <p>An iterator for the values in the array.</p> |
||
| 333 | */ |
||
| 334 | 24 | public function getIterator(): \Iterator |
|
| 335 | { |
||
| 336 | 24 | if ($this->generator instanceof ArrayyRewindableGenerator) { |
|
| 337 | 1 | return $this->generator; |
|
| 338 | } |
||
| 339 | |||
| 340 | 23 | $iterator = $this->getIteratorClass(); |
|
| 341 | |||
| 342 | 23 | if ($iterator === ArrayyIterator::class) { |
|
| 343 | 23 | return new $iterator($this->getArray(), 0, static::class); |
|
| 344 | } |
||
| 345 | |||
| 346 | return new $iterator($this->getArray()); |
||
| 347 | } |
||
| 348 | |||
| 349 | /** |
||
| 350 | * Gets the iterator classname for the ArrayObject. |
||
| 351 | * |
||
| 352 | * @return string |
||
| 353 | */ |
||
| 354 | 23 | public function getIteratorClass(): string |
|
| 358 | |||
| 359 | /** |
||
| 360 | * Sort the entries by key |
||
| 361 | * |
||
| 362 | * @param int $sort_flags [optional] <p> |
||
| 363 | * You may modify the behavior of the sort using the optional |
||
| 364 | * parameter sort_flags, for details |
||
| 365 | * see sort. |
||
| 366 | * </p> |
||
| 367 | * |
||
| 368 | * @return static |
||
| 369 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 370 | */ |
||
| 371 | 4 | public function ksort(int $sort_flags = 0): self |
|
| 379 | |||
| 380 | /** |
||
| 381 | * Sort an array using a case insensitive "natural order" algorithm |
||
| 382 | * |
||
| 383 | * @return static |
||
| 384 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 385 | */ |
||
| 386 | public function natcasesort(): self |
||
| 394 | |||
| 395 | /** |
||
| 396 | * Sort entries using a "natural order" algorithm |
||
| 397 | * |
||
| 398 | * @return static |
||
| 399 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 400 | */ |
||
| 401 | 1 | public function natsort(): self |
|
| 409 | |||
| 410 | /** |
||
| 411 | * Whether or not an offset exists. |
||
| 412 | * |
||
| 413 | * @param bool|int|string $offset |
||
| 414 | * |
||
| 415 | * @return bool |
||
| 416 | * |
||
| 417 | * @noinspection PhpSillyAssignmentInspection |
||
| 418 | */ |
||
| 419 | 127 | public function offsetExists($offset): bool |
|
| 420 | { |
||
| 421 | 127 | $this->generatorToArray(); |
|
| 422 | |||
| 423 | 127 | if ($this->array === []) { |
|
| 424 | 5 | return false; |
|
| 425 | } |
||
| 426 | |||
| 427 | // php cast "bool"-index into "int"-index |
||
| 428 | 122 | if ((bool) $offset === $offset) { |
|
| 429 | 1 | $offset = (int) $offset; |
|
| 430 | } |
||
| 431 | |||
| 432 | /** @var int|string $offset - hint for phpstan */ |
||
| 433 | 122 | $offset = $offset; |
|
| 434 | |||
| 435 | 122 | $tmpReturn = $this->keyExists($offset); |
|
| 436 | |||
| 437 | if ( |
||
| 438 | 122 | $tmpReturn === true |
|
| 439 | || |
||
| 440 | ( |
||
| 441 | 89 | $tmpReturn === false |
|
| 442 | && |
||
| 443 | 122 | \strpos((string) $offset, $this->pathSeparator) === false |
|
| 444 | ) |
||
| 445 | ) { |
||
| 446 | 120 | return $tmpReturn; |
|
| 447 | } |
||
| 448 | |||
| 449 | 3 | $offsetExists = false; |
|
| 450 | |||
| 451 | if ( |
||
| 452 | 3 | $this->pathSeparator |
|
| 453 | && |
||
| 454 | 3 | (string) $offset === $offset |
|
| 455 | && |
||
| 456 | 3 | \strpos($offset, $this->pathSeparator) !== false |
|
| 457 | ) { |
||
| 458 | 3 | $explodedPath = \explode($this->pathSeparator, (string) $offset); |
|
| 459 | 3 | if ($explodedPath !== false) { |
|
| 460 | 3 | $lastOffset = \array_pop($explodedPath); |
|
| 461 | 3 | if ($lastOffset !== null) { |
|
| 462 | 3 | $containerPath = \implode($this->pathSeparator, $explodedPath); |
|
| 463 | |||
| 464 | 3 | $this->callAtPath( |
|
| 465 | 3 | $containerPath, |
|
| 466 | static function ($container) use ($lastOffset, &$offsetExists) { |
||
| 467 | 3 | $offsetExists = \array_key_exists($lastOffset, $container); |
|
| 468 | 3 | } |
|
| 469 | ); |
||
| 470 | } |
||
| 471 | } |
||
| 472 | } |
||
| 473 | |||
| 474 | 3 | return $offsetExists; |
|
| 475 | } |
||
| 476 | |||
| 477 | /** |
||
| 478 | * Returns the value at specified offset. |
||
| 479 | * |
||
| 480 | * @param int|string $offset |
||
| 481 | * |
||
| 482 | * @return mixed |
||
| 483 | * <p>Will return null if the offset did not exists.</p> |
||
| 484 | */ |
||
| 485 | 98 | public function offsetGet($offset) |
|
| 489 | |||
| 490 | /** |
||
| 491 | * Assigns a value to the specified offset + check the type. |
||
| 492 | * |
||
| 493 | * @param int|string|null $offset |
||
| 494 | * @param mixed $value |
||
| 495 | * |
||
| 496 | * @return void |
||
| 497 | */ |
||
| 498 | 21 | public function offsetSet($offset, $value) |
|
| 499 | { |
||
| 516 | |||
| 517 | /** |
||
| 518 | * Unset an offset. |
||
| 519 | * |
||
| 520 | * @param int|string $offset |
||
| 521 | * |
||
| 522 | * @return void |
||
| 523 | */ |
||
| 524 | 12 | public function offsetUnset($offset) |
|
| 561 | |||
| 562 | /** |
||
| 563 | * Serialize the current "Arrayy"-object. |
||
| 564 | * |
||
| 565 | * @return string |
||
| 566 | */ |
||
| 567 | 2 | public function serialize(): string |
|
| 577 | |||
| 578 | /** |
||
| 579 | * Sets the iterator classname for the current "Arrayy"-object. |
||
| 580 | * |
||
| 581 | * @param string $iteratorClass |
||
| 582 | * |
||
| 583 | * @throws \InvalidArgumentException |
||
| 584 | * |
||
| 585 | * @return void |
||
| 586 | * |
||
| 587 | * @psalm-param class-string<\Arrayy\ArrayyIterator> $iteratorClass |
||
| 588 | */ |
||
| 589 | 1044 | public function setIteratorClass($iteratorClass) |
|
| 608 | |||
| 609 | /** |
||
| 610 | * Sort the entries with a user-defined comparison function and maintain key association. |
||
| 611 | * |
||
| 612 | * @param callable $function |
||
| 613 | * |
||
| 614 | * @throws \InvalidArgumentException |
||
| 615 | * |
||
| 616 | * @return static |
||
| 617 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 618 | */ |
||
| 619 | View Code Duplication | public function uasort($function): self |
|
| 631 | |||
| 632 | /** |
||
| 633 | * Sort the entries by keys using a user-defined comparison function. |
||
| 634 | * |
||
| 635 | * @param callable $function |
||
| 636 | * |
||
| 637 | * @throws \InvalidArgumentException |
||
| 638 | * |
||
| 639 | * @return static |
||
| 640 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 641 | */ |
||
| 642 | 5 | public function uksort($function): self |
|
| 646 | |||
| 647 | /** |
||
| 648 | * Unserialize an string and return the instance of the "Arrayy"-class. |
||
| 649 | * |
||
| 650 | * @param string $string |
||
| 651 | * |
||
| 652 | * @return static |
||
| 653 | */ |
||
| 654 | 2 | public function unserialize($string): self |
|
| 664 | |||
| 665 | /** |
||
| 666 | * Append a (key) + values to the current array. |
||
| 667 | * |
||
| 668 | * @param array $values |
||
| 669 | * @param mixed $key |
||
| 670 | * |
||
| 671 | * @return static |
||
| 672 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
| 673 | */ |
||
| 674 | 1 | public function appendArrayValues(array $values, $key = null) |
|
| 700 | |||
| 701 | /** |
||
| 702 | * Add a suffix to each key. |
||
| 703 | * |
||
| 704 | * @param mixed $prefix |
||
| 705 | * |
||
| 706 | * @return static |
||
| 707 | * <p>(Immutable) Return an Arrayy object, with the prefixed keys.</p> |
||
| 708 | */ |
||
| 709 | 10 | View Code Duplication | public function appendToEachKey($prefix): self |
| 728 | |||
| 729 | /** |
||
| 730 | * Add a prefix to each value. |
||
| 731 | * |
||
| 732 | * @param mixed $prefix |
||
| 733 | * |
||
| 734 | * @return static |
||
| 735 | * <p>(Immutable) Return an Arrayy object, with the prefixed values.</p> |
||
| 736 | */ |
||
| 737 | 10 | View Code Duplication | public function appendToEachValue($prefix): self |
| 756 | |||
| 757 | /** |
||
| 758 | * Sort an array in reverse order and maintain index association. |
||
| 759 | * |
||
| 760 | * @return static |
||
| 761 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 762 | */ |
||
| 763 | 10 | public function arsort(): self |
|
| 771 | |||
| 772 | /** |
||
| 773 | * Iterate over the current array and execute a callback for each loop. |
||
| 774 | * |
||
| 775 | * @param \Closure $closure |
||
| 776 | * |
||
| 777 | * @return static |
||
| 778 | * <p>(Immutable)</p> |
||
| 779 | */ |
||
| 780 | 2 | public function at(\Closure $closure): self |
|
| 794 | |||
| 795 | /** |
||
| 796 | * Returns the average value of the current array. |
||
| 797 | * |
||
| 798 | * @param int $decimals <p>The number of decimal-numbers to return.</p> |
||
| 799 | * |
||
| 800 | * @return float|int |
||
| 801 | * <p>The average value.</p> |
||
| 802 | */ |
||
| 803 | 10 | public function average($decimals = 0) |
|
| 817 | |||
| 818 | /** |
||
| 819 | * Changes all keys in an array. |
||
| 820 | * |
||
| 821 | * @param int $case [optional] <p> Either <strong>CASE_UPPER</strong><br /> |
||
| 822 | * or <strong>CASE_LOWER</strong> (default)</p> |
||
| 823 | * |
||
| 824 | * @return static |
||
| 825 | * <p>(Immutable)</p> |
||
| 826 | */ |
||
| 827 | 1 | public function changeKeyCase(int $case = \CASE_LOWER): self |
|
| 854 | |||
| 855 | /** |
||
| 856 | * Change the path separator of the array wrapper. |
||
| 857 | * |
||
| 858 | * By default, the separator is: "." |
||
| 859 | * |
||
| 860 | * @param string $separator <p>Separator to set.</p> |
||
| 861 | * |
||
| 862 | * @return static |
||
| 863 | * <p>Mutable</p> |
||
| 864 | */ |
||
| 865 | 11 | public function changeSeparator($separator): self |
|
| 871 | |||
| 872 | /** |
||
| 873 | * Create a chunked version of the current array. |
||
| 874 | * |
||
| 875 | * @param int $size <p>Size of each chunk.</p> |
||
| 876 | * @param bool $preserveKeys <p>Whether array keys are preserved or no.</p> |
||
| 877 | * |
||
| 878 | * @return static |
||
| 879 | * <p>(Immutable) A new array of chunks from the original array.</p> |
||
| 880 | */ |
||
| 881 | 5 | public function chunk($size, $preserveKeys = false): self |
|
| 889 | |||
| 890 | /** |
||
| 891 | * Clean all falsy values from the current array. |
||
| 892 | * |
||
| 893 | * @return static |
||
| 894 | * <p>(Immutable)</p> |
||
| 895 | */ |
||
| 896 | 8 | public function clean(): self |
|
| 904 | |||
| 905 | /** |
||
| 906 | * WARNING!!! -> Clear the current array. |
||
| 907 | * |
||
| 908 | * @return static |
||
| 909 | * <p>(Mutable) Return this Arrayy object, with an empty array.</p> |
||
| 910 | */ |
||
| 911 | 5 | public function clear(): self |
|
| 918 | |||
| 919 | /** |
||
| 920 | * Check if an item is in the current array. |
||
| 921 | * |
||
| 922 | * @param float|int|string $value |
||
| 923 | * @param bool $recursive |
||
| 924 | * @param bool $strict |
||
| 925 | * |
||
| 926 | * @return bool |
||
| 927 | */ |
||
| 928 | 23 | public function contains($value, bool $recursive = false, bool $strict = true): bool |
|
| 949 | |||
| 950 | /** |
||
| 951 | * Check if an (case-insensitive) string is in the current array. |
||
| 952 | * |
||
| 953 | * @param string $value |
||
| 954 | * @param bool $recursive |
||
| 955 | * |
||
| 956 | * @return bool |
||
| 957 | */ |
||
| 958 | 26 | public function containsCaseInsensitive($value, $recursive = false): bool |
|
| 983 | |||
| 984 | /** |
||
| 985 | * Check if the given key/index exists in the array. |
||
| 986 | * |
||
| 987 | * @param int|string $key <p>key/index to search for</p> |
||
| 988 | * |
||
| 989 | * @return bool |
||
| 990 | * <p>Returns true if the given key/index exists in the array, false otherwise.</p> |
||
| 991 | */ |
||
| 992 | 4 | public function containsKey($key): bool |
|
| 996 | |||
| 997 | /** |
||
| 998 | * Check if all given needles are present in the array as key/index. |
||
| 999 | * |
||
| 1000 | * @param array $needles <p>The keys you are searching for.</p> |
||
| 1001 | * @param bool $recursive |
||
| 1002 | * |
||
| 1003 | * @return bool |
||
| 1004 | * <p>Returns true if all the given keys/indexes exists in the array, false otherwise.</p> |
||
| 1005 | */ |
||
| 1006 | 2 | public function containsKeys(array $needles, $recursive = false): bool |
|
| 1034 | |||
| 1035 | /** |
||
| 1036 | * Check if all given needles are present in the array as key/index. |
||
| 1037 | * |
||
| 1038 | * @param array $needles <p>The keys you are searching for.</p> |
||
| 1039 | * |
||
| 1040 | * @return bool |
||
| 1041 | * <p>Returns true if all the given keys/indexes exists in the array, false otherwise.</p> |
||
| 1042 | */ |
||
| 1043 | 1 | public function containsKeysRecursive(array $needles): bool |
|
| 1047 | |||
| 1048 | /** |
||
| 1049 | * alias: for "Arrayy->contains()" |
||
| 1050 | * |
||
| 1051 | * @param float|int|string $value |
||
| 1052 | * |
||
| 1053 | * @return bool |
||
| 1054 | * |
||
| 1055 | * @see Arrayy::contains() |
||
| 1056 | */ |
||
| 1057 | 9 | public function containsValue($value): bool |
|
| 1061 | |||
| 1062 | /** |
||
| 1063 | * alias: for "Arrayy->contains($value, true)" |
||
| 1064 | * |
||
| 1065 | * @param float|int|string $value |
||
| 1066 | * |
||
| 1067 | * @return bool |
||
| 1068 | * |
||
| 1069 | * @see Arrayy::contains() |
||
| 1070 | */ |
||
| 1071 | 18 | public function containsValueRecursive($value): bool |
|
| 1075 | |||
| 1076 | /** |
||
| 1077 | * Check if all given needles are present in the array. |
||
| 1078 | * |
||
| 1079 | * @param array $needles |
||
| 1080 | * |
||
| 1081 | * @return bool |
||
| 1082 | * <p>Returns true if all the given values exists in the array, false otherwise.</p> |
||
| 1083 | */ |
||
| 1084 | 1 | public function containsValues(array $needles): bool |
|
| 1090 | |||
| 1091 | /** |
||
| 1092 | * Counts all the values of an array |
||
| 1093 | * |
||
| 1094 | * @see http://php.net/manual/en/function.array-count-values.php |
||
| 1095 | * |
||
| 1096 | * @return static |
||
| 1097 | * <p> |
||
| 1098 | * (Immutable) |
||
| 1099 | * An associative Arrayy-object of values from input as |
||
| 1100 | * keys and their count as value. |
||
| 1101 | * </p> |
||
| 1102 | */ |
||
| 1103 | 7 | public function countValues(): self |
|
| 1107 | |||
| 1108 | /** |
||
| 1109 | * Creates an Arrayy object. |
||
| 1110 | * |
||
| 1111 | * @param mixed $data |
||
| 1112 | * @param string $iteratorClass |
||
| 1113 | * @param bool $checkPropertiesInConstructor |
||
| 1114 | * |
||
| 1115 | * @return static |
||
| 1116 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1117 | * |
||
| 1118 | * @psalm-param class-string<\Arrayy\ArrayyIterator> $iteratorClass |
||
| 1119 | */ |
||
| 1120 | 660 | public static function create( |
|
| 1131 | |||
| 1132 | /** |
||
| 1133 | * WARNING: Creates an Arrayy object by reference. |
||
| 1134 | * |
||
| 1135 | * @param array $array |
||
| 1136 | * |
||
| 1137 | * @return static |
||
| 1138 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1139 | */ |
||
| 1140 | 1 | public function createByReference(array &$array = []): self |
|
| 1148 | |||
| 1149 | /** |
||
| 1150 | * Create an new instance from a callable function which will return an Generator. |
||
| 1151 | * |
||
| 1152 | * @param callable():Generator $generatorFunction |
||
| 1153 | * |
||
| 1154 | * @return static |
||
| 1155 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1156 | */ |
||
| 1157 | 5 | public static function createFromGeneratorFunction(callable $generatorFunction): self |
|
| 1161 | |||
| 1162 | /** |
||
| 1163 | * Create an new instance filled with a copy of values from a "Generator"-object. |
||
| 1164 | * |
||
| 1165 | * @param \Generator $generator |
||
| 1166 | * |
||
| 1167 | * @return static |
||
| 1168 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1169 | */ |
||
| 1170 | 4 | public static function createFromGeneratorImmutable(\Generator $generator): self |
|
| 1174 | |||
| 1175 | /** |
||
| 1176 | * Create an new Arrayy object via JSON. |
||
| 1177 | * |
||
| 1178 | * @param string $json |
||
| 1179 | * |
||
| 1180 | * @return static |
||
| 1181 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1182 | */ |
||
| 1183 | 5 | public static function createFromJson(string $json): self |
|
| 1187 | |||
| 1188 | /** |
||
| 1189 | * Create an new instance filled with values from an object that is iterable. |
||
| 1190 | * |
||
| 1191 | * @param \Traversable $object <p>iterable object</p> |
||
| 1192 | * |
||
| 1193 | * @return static |
||
| 1194 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1195 | */ |
||
| 1196 | 4 | public static function createFromObject(\Traversable $object): self |
|
| 1213 | |||
| 1214 | /** |
||
| 1215 | * Create an new instance filled with values from an object. |
||
| 1216 | * |
||
| 1217 | * @param object $object |
||
| 1218 | * |
||
| 1219 | * @return static |
||
| 1220 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1221 | */ |
||
| 1222 | 5 | public static function createFromObjectVars($object): self |
|
| 1226 | |||
| 1227 | /** |
||
| 1228 | * Create an new Arrayy object via string. |
||
| 1229 | * |
||
| 1230 | * @param string $str <p>The input string.</p> |
||
| 1231 | * @param string|null $delimiter <p>The boundary string.</p> |
||
| 1232 | * @param string|null $regEx <p>Use the $delimiter or the $regEx, so if $pattern is null, $delimiter will be |
||
| 1233 | * used.</p> |
||
| 1234 | * |
||
| 1235 | * @return static |
||
| 1236 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1237 | */ |
||
| 1238 | 10 | public static function createFromString(string $str, string $delimiter = null, string $regEx = null): self |
|
| 1267 | |||
| 1268 | /** |
||
| 1269 | * Create an new instance filled with a copy of values from a "Traversable"-object. |
||
| 1270 | * |
||
| 1271 | * @param \Traversable $traversable |
||
| 1272 | * |
||
| 1273 | * @return static |
||
| 1274 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1275 | */ |
||
| 1276 | 1 | public static function createFromTraversableImmutable(\Traversable $traversable): self |
|
| 1280 | |||
| 1281 | /** |
||
| 1282 | * Create an new instance containing a range of elements. |
||
| 1283 | * |
||
| 1284 | * @param mixed $low <p>First value of the sequence.</p> |
||
| 1285 | * @param mixed $high <p>The sequence is ended upon reaching the end value.</p> |
||
| 1286 | * @param int $step <p>Used as the increment between elements in the sequence.</p> |
||
| 1287 | * |
||
| 1288 | * @return static |
||
| 1289 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1290 | */ |
||
| 1291 | 2 | public static function createWithRange($low, $high, int $step = 1): self |
|
| 1295 | |||
| 1296 | /** |
||
| 1297 | * Gets the element of the array at the current internal iterator position. |
||
| 1298 | * |
||
| 1299 | * @return false|mixed |
||
| 1300 | */ |
||
| 1301 | public function current() |
||
| 1305 | |||
| 1306 | /** |
||
| 1307 | * Custom sort by index via "uksort". |
||
| 1308 | * |
||
| 1309 | * @see http://php.net/manual/en/function.uksort.php |
||
| 1310 | * |
||
| 1311 | * @param callable $function |
||
| 1312 | * |
||
| 1313 | * @throws \InvalidArgumentException |
||
| 1314 | * |
||
| 1315 | * @return static |
||
| 1316 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1317 | */ |
||
| 1318 | 5 | View Code Duplication | public function customSortKeys($function): self |
| 1330 | |||
| 1331 | /** |
||
| 1332 | * Custom sort by value via "usort". |
||
| 1333 | * |
||
| 1334 | * @see http://php.net/manual/en/function.usort.php |
||
| 1335 | * |
||
| 1336 | * @param callable $function |
||
| 1337 | * |
||
| 1338 | * @throws \InvalidArgumentException |
||
| 1339 | * |
||
| 1340 | * @return static |
||
| 1341 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1342 | */ |
||
| 1343 | 6 | View Code Duplication | public function customSortValues($function): self |
| 1355 | |||
| 1356 | /** |
||
| 1357 | * Delete the given key or keys. |
||
| 1358 | * |
||
| 1359 | * @param int|int[]|string|string[] $keyOrKeys |
||
| 1360 | * |
||
| 1361 | * @return void |
||
| 1362 | */ |
||
| 1363 | 4 | public function delete($keyOrKeys) |
|
| 1371 | |||
| 1372 | /** |
||
| 1373 | * Return values that are only in the current array. |
||
| 1374 | * |
||
| 1375 | * @param array ...$array |
||
| 1376 | * |
||
| 1377 | * @return static |
||
| 1378 | * <p>(Immutable)</p> |
||
| 1379 | */ |
||
| 1380 | 13 | public function diff(...$array): self |
|
| 1388 | |||
| 1389 | /** |
||
| 1390 | * Return values that are only in the current array. |
||
| 1391 | * |
||
| 1392 | * @param array ...$array |
||
| 1393 | * |
||
| 1394 | * @return static |
||
| 1395 | * <p>(Immutable)</p> |
||
| 1396 | */ |
||
| 1397 | 8 | public function diffKey(...$array): self |
|
| 1405 | |||
| 1406 | /** |
||
| 1407 | * Return values and Keys that are only in the current array. |
||
| 1408 | * |
||
| 1409 | * @param array $array |
||
| 1410 | * |
||
| 1411 | * @return static |
||
| 1412 | * <p>(Immutable)</p> |
||
| 1413 | */ |
||
| 1414 | 8 | public function diffKeyAndValue(array $array = []): self |
|
| 1422 | |||
| 1423 | /** |
||
| 1424 | * Return values that are only in the current multi-dimensional array. |
||
| 1425 | * |
||
| 1426 | * @param array $array |
||
| 1427 | * @param array|null $helperVariableForRecursion <p>(only for internal usage)</p> |
||
| 1428 | * |
||
| 1429 | * @return static |
||
| 1430 | * <p>(Immutable)</p> |
||
| 1431 | */ |
||
| 1432 | 1 | public function diffRecursive(array $array = [], $helperVariableForRecursion = null): self |
|
| 1467 | |||
| 1468 | /** |
||
| 1469 | * Return values that are only in the new $array. |
||
| 1470 | * |
||
| 1471 | * @param array $array |
||
| 1472 | * |
||
| 1473 | * @return static |
||
| 1474 | * <p>(Immutable)</p> |
||
| 1475 | */ |
||
| 1476 | 8 | public function diffReverse(array $array = []): self |
|
| 1484 | |||
| 1485 | /** |
||
| 1486 | * Divide an array into two arrays. One with keys and the other with values. |
||
| 1487 | * |
||
| 1488 | * @return static |
||
| 1489 | * <p>(Immutable)</p> |
||
| 1490 | */ |
||
| 1491 | 1 | public function divide(): self |
|
| 1502 | |||
| 1503 | /** |
||
| 1504 | * Iterate over the current array and modify the array's value. |
||
| 1505 | * |
||
| 1506 | * @param \Closure $closure |
||
| 1507 | * |
||
| 1508 | * @return static |
||
| 1509 | * <p>(Immutable)</p> |
||
| 1510 | */ |
||
| 1511 | 5 | View Code Duplication | public function each(\Closure $closure): self |
| 1526 | |||
| 1527 | /** |
||
| 1528 | * Sets the internal iterator to the last element in the array and returns this element. |
||
| 1529 | * |
||
| 1530 | * @return mixed |
||
| 1531 | */ |
||
| 1532 | public function end() |
||
| 1536 | |||
| 1537 | /** |
||
| 1538 | * Check if a value is in the current array using a closure. |
||
| 1539 | * |
||
| 1540 | * @param \Closure $closure |
||
| 1541 | * |
||
| 1542 | * @return bool |
||
| 1543 | * <p>Returns true if the given value is found, false otherwise.</p> |
||
| 1544 | */ |
||
| 1545 | 4 | public function exists(\Closure $closure): bool |
|
| 1560 | |||
| 1561 | /** |
||
| 1562 | * Fill the array until "$num" with "$default" values. |
||
| 1563 | * |
||
| 1564 | * @param int $num |
||
| 1565 | * @param mixed $default |
||
| 1566 | * |
||
| 1567 | * @return static |
||
| 1568 | * <p>(Immutable)</p> |
||
| 1569 | */ |
||
| 1570 | 8 | public function fillWithDefaults(int $num, $default = null): self |
|
| 1593 | |||
| 1594 | /** |
||
| 1595 | * Find all items in an array that pass the truth test. |
||
| 1596 | * |
||
| 1597 | * @param \Closure|null $closure [optional] <p> |
||
| 1598 | * The callback function to use |
||
| 1599 | * </p> |
||
| 1600 | * <p> |
||
| 1601 | * If no callback is supplied, all entries of |
||
| 1602 | * input equal to false (see |
||
| 1603 | * converting to |
||
| 1604 | * boolean) will be removed. |
||
| 1605 | * </p> |
||
| 1606 | * @param int $flag [optional] <p> |
||
| 1607 | * Flag determining what arguments are sent to <i>callback</i>: |
||
| 1608 | * </p><ul> |
||
| 1609 | * <li> |
||
| 1610 | * <b>ARRAY_FILTER_USE_KEY</b> [1] - pass key as the only argument |
||
| 1611 | * to <i>callback</i> instead of the value</span> |
||
| 1612 | * </li> |
||
| 1613 | * <li> |
||
| 1614 | * <b>ARRAY_FILTER_USE_BOTH</b> [2] - pass both value and key as |
||
| 1615 | * arguments to <i>callback</i> instead of the value</span> |
||
| 1616 | * </li> |
||
| 1617 | * </ul> |
||
| 1618 | * |
||
| 1619 | * @return static |
||
| 1620 | * <p>(Immutable)</p> |
||
| 1621 | */ |
||
| 1622 | 12 | public function filter($closure = null, int $flag = \ARRAY_FILTER_USE_BOTH) |
|
| 1634 | |||
| 1635 | /** |
||
| 1636 | * Filters an array of objects (or a numeric array of associative arrays) based on the value of a particular |
||
| 1637 | * property within that. |
||
| 1638 | * |
||
| 1639 | * @param string $property |
||
| 1640 | * @param string|string[] $value |
||
| 1641 | * @param string $comparisonOp |
||
| 1642 | * <p> |
||
| 1643 | * 'eq' (equals),<br /> |
||
| 1644 | * 'gt' (greater),<br /> |
||
| 1645 | * 'gte' || 'ge' (greater or equals),<br /> |
||
| 1646 | * 'lt' (less),<br /> |
||
| 1647 | * 'lte' || 'le' (less or equals),<br /> |
||
| 1648 | * 'ne' (not equals),<br /> |
||
| 1649 | * 'contains',<br /> |
||
| 1650 | * 'notContains',<br /> |
||
| 1651 | * 'newer' (via strtotime),<br /> |
||
| 1652 | * 'older' (via strtotime),<br /> |
||
| 1653 | * </p> |
||
| 1654 | * |
||
| 1655 | * @return static |
||
| 1656 | * <p>(Immutable)</p> |
||
| 1657 | */ |
||
| 1658 | 1 | public function filterBy(string $property, $value, string $comparisonOp = null): self |
|
| 1727 | |||
| 1728 | /** |
||
| 1729 | * Find the first item in an array that passes the truth test, |
||
| 1730 | * otherwise return false |
||
| 1731 | * |
||
| 1732 | * @param \Closure $closure |
||
| 1733 | * |
||
| 1734 | * @return false|mixed |
||
| 1735 | * <p>Return false if we did not find the value.</p> |
||
| 1736 | */ |
||
| 1737 | 8 | public function find(\Closure $closure) |
|
| 1747 | |||
| 1748 | /** |
||
| 1749 | * find by ... |
||
| 1750 | * |
||
| 1751 | * @param string $property |
||
| 1752 | * @param string|string[] $value |
||
| 1753 | * @param string $comparisonOp |
||
| 1754 | * |
||
| 1755 | * @return static |
||
| 1756 | * <p>(Immutable)</p> |
||
| 1757 | */ |
||
| 1758 | 1 | public function findBy(string $property, $value, string $comparisonOp = 'eq'): self |
|
| 1762 | |||
| 1763 | /** |
||
| 1764 | * Get the first value from the current array. |
||
| 1765 | * |
||
| 1766 | * @return mixed |
||
| 1767 | * <p>Return null if there wasn't a element.</p> |
||
| 1768 | */ |
||
| 1769 | 21 | public function first() |
|
| 1778 | |||
| 1779 | /** |
||
| 1780 | * Get the first key from the current array. |
||
| 1781 | * |
||
| 1782 | * @return mixed |
||
| 1783 | * <p>Return null if there wasn't a element.</p> |
||
| 1784 | */ |
||
| 1785 | 28 | public function firstKey() |
|
| 1791 | |||
| 1792 | /** |
||
| 1793 | * Get the first value(s) from the current array. |
||
| 1794 | * And will return an empty array if there was no first entry. |
||
| 1795 | * |
||
| 1796 | * @param int|null $number <p>How many values you will take?</p> |
||
| 1797 | * |
||
| 1798 | * @return static |
||
| 1799 | * <p>(Immutable)</p> |
||
| 1800 | */ |
||
| 1801 | 37 | View Code Duplication | public function firstsImmutable(int $number = null): self |
| 1818 | |||
| 1819 | /** |
||
| 1820 | * Get the first value(s) from the current array. |
||
| 1821 | * And will return an empty array if there was no first entry. |
||
| 1822 | * |
||
| 1823 | * @param int|null $number <p>How many values you will take?</p> |
||
| 1824 | * |
||
| 1825 | * @return static |
||
| 1826 | * <p>(Immutable)</p> |
||
| 1827 | */ |
||
| 1828 | 3 | View Code Duplication | public function firstsKeys(int $number = null): self |
| 1845 | |||
| 1846 | /** |
||
| 1847 | * Get and rmove the first value(s) from the current array. |
||
| 1848 | * And will return an empty array if there was no first entry. |
||
| 1849 | * |
||
| 1850 | * @param int|null $number <p>How many values you will take?</p> |
||
| 1851 | * |
||
| 1852 | * @return static |
||
| 1853 | * <p>(Mutable)</p> |
||
| 1854 | */ |
||
| 1855 | 34 | public function firstsMutable(int $number = null): self |
|
| 1868 | |||
| 1869 | /** |
||
| 1870 | * Exchanges all keys with their associated values in an array. |
||
| 1871 | * |
||
| 1872 | * @return static |
||
| 1873 | * <p>(Immutable)</p> |
||
| 1874 | */ |
||
| 1875 | 1 | public function flip(): self |
|
| 1883 | |||
| 1884 | /** |
||
| 1885 | * Tests whether the given predicate p holds for all elements of this array. |
||
| 1886 | * |
||
| 1887 | * @param \Closure $closure the predicate |
||
| 1888 | * |
||
| 1889 | * @return bool |
||
| 1890 | * <p>TRUE, if the predicate yields TRUE for all elements, FALSE otherwise.</p> |
||
| 1891 | */ |
||
| 1892 | public function forAll(\Closure $closure): bool |
||
| 1902 | |||
| 1903 | /** |
||
| 1904 | * Get a value from an array (optional using dot-notation). |
||
| 1905 | * |
||
| 1906 | * @param mixed $key <p>The key to look for.</p> |
||
| 1907 | * @param mixed $fallback <p>Value to fallback to.</p> |
||
| 1908 | * @param array $array <p>The array to get from, if it's set to "null" we use the current array from the |
||
| 1909 | * class.</p> |
||
| 1910 | * |
||
| 1911 | * @return mixed|static |
||
| 1912 | */ |
||
| 1913 | 169 | public function get($key, $fallback = null, array $array = null) |
|
| 2005 | |||
| 2006 | /** |
||
| 2007 | * alias: for "Arrayy->getArray()" |
||
| 2008 | * |
||
| 2009 | * @return array |
||
| 2010 | * |
||
| 2011 | * @see Arrayy::getArray() |
||
| 2012 | */ |
||
| 2013 | 1 | public function getAll(): array |
|
| 2017 | |||
| 2018 | /** |
||
| 2019 | * Get the current array from the "Arrayy"-object. |
||
| 2020 | * |
||
| 2021 | * @param bool $convertAllArrayyElements |
||
| 2022 | * |
||
| 2023 | * @return array |
||
| 2024 | */ |
||
| 2025 | 842 | public function getArray($convertAllArrayyElements = false): array |
|
| 2046 | |||
| 2047 | /** |
||
| 2048 | * Returns the values from a single column of the input array, identified by |
||
| 2049 | * the $columnKey, can be used to extract data-columns from multi-arrays. |
||
| 2050 | * |
||
| 2051 | * Info: Optionally, you may provide an $indexKey to index the values in the returned |
||
| 2052 | * array by the values from the $indexKey column in the input array. |
||
| 2053 | * |
||
| 2054 | * @param mixed $columnKey |
||
| 2055 | * @param mixed $indexKey |
||
| 2056 | * |
||
| 2057 | * @return static |
||
| 2058 | * <p>(Immutable)</p> |
||
| 2059 | */ |
||
| 2060 | 1 | public function getColumn($columnKey = null, $indexKey = null): self |
|
| 2068 | |||
| 2069 | /** |
||
| 2070 | * Get the current array from the "Arrayy"-object as generator. |
||
| 2071 | * |
||
| 2072 | * @return \Generator |
||
| 2073 | */ |
||
| 2074 | 920 | public function getGenerator(): \Generator |
|
| 2082 | |||
| 2083 | /** |
||
| 2084 | * alias: for "Arrayy->keys()" |
||
| 2085 | * |
||
| 2086 | * @return static |
||
| 2087 | * <p>(Immutable)</p> |
||
| 2088 | * |
||
| 2089 | * @see Arrayy::keys() |
||
| 2090 | */ |
||
| 2091 | 2 | public function getKeys() |
|
| 2095 | |||
| 2096 | /** |
||
| 2097 | * Get the current array from the "Arrayy"-object as object. |
||
| 2098 | * |
||
| 2099 | * @return \stdClass |
||
| 2100 | */ |
||
| 2101 | 4 | public function getObject(): \stdClass |
|
| 2105 | |||
| 2106 | /** |
||
| 2107 | * alias: for "Arrayy->randomImmutable()" |
||
| 2108 | * |
||
| 2109 | * @return static |
||
| 2110 | * <p>(Immutable)</p> |
||
| 2111 | * |
||
| 2112 | * @see Arrayy::randomImmutable() |
||
| 2113 | */ |
||
| 2114 | 4 | public function getRandom(): self |
|
| 2118 | |||
| 2119 | /** |
||
| 2120 | * alias: for "Arrayy->randomKey()" |
||
| 2121 | * |
||
| 2122 | * @return mixed |
||
| 2123 | * <p>Get a key/index or null if there wasn't a key/index.</p> |
||
| 2124 | * |
||
| 2125 | * @see Arrayy::randomKey() |
||
| 2126 | */ |
||
| 2127 | 3 | public function getRandomKey() |
|
| 2131 | |||
| 2132 | /** |
||
| 2133 | * alias: for "Arrayy->randomKeys()" |
||
| 2134 | * |
||
| 2135 | * @param int $number |
||
| 2136 | * |
||
| 2137 | * @return static |
||
| 2138 | * <p>(Immutable)</p> |
||
| 2139 | * |
||
| 2140 | * @see Arrayy::randomKeys() |
||
| 2141 | */ |
||
| 2142 | 8 | public function getRandomKeys(int $number): self |
|
| 2146 | |||
| 2147 | /** |
||
| 2148 | * alias: for "Arrayy->randomValue()" |
||
| 2149 | * |
||
| 2150 | * @return mixed |
||
| 2151 | * <p>Get a random value or null if there wasn't a value.</p> |
||
| 2152 | * |
||
| 2153 | * @see Arrayy::randomValue() |
||
| 2154 | */ |
||
| 2155 | 3 | public function getRandomValue() |
|
| 2159 | |||
| 2160 | /** |
||
| 2161 | * alias: for "Arrayy->randomValues()" |
||
| 2162 | * |
||
| 2163 | * @param int $number |
||
| 2164 | * |
||
| 2165 | * @return static |
||
| 2166 | * <p>(Immutable)</p> |
||
| 2167 | * |
||
| 2168 | * @see Arrayy::randomValues() |
||
| 2169 | */ |
||
| 2170 | 6 | public function getRandomValues(int $number): self |
|
| 2174 | |||
| 2175 | /** |
||
| 2176 | * Gets all values. |
||
| 2177 | * |
||
| 2178 | * @return static |
||
| 2179 | * <p>The values of all elements in this array, in the order they |
||
| 2180 | * appear in the array.</p> |
||
| 2181 | */ |
||
| 2182 | public function getValues() |
||
| 2192 | |||
| 2193 | /** |
||
| 2194 | * Gets all values via Generator. |
||
| 2195 | * |
||
| 2196 | * @return \Generator |
||
| 2197 | * <p>The values of all elements in this array, in the order they |
||
| 2198 | * appear in the array as Generator.</p> |
||
| 2199 | */ |
||
| 2200 | public function getValuesYield(): \Generator |
||
| 2204 | |||
| 2205 | /** |
||
| 2206 | * Group values from a array according to the results of a closure. |
||
| 2207 | * |
||
| 2208 | * @param callable|string $grouper <p>A callable function name.</p> |
||
| 2209 | * @param bool $saveKeys |
||
| 2210 | * |
||
| 2211 | * @return static |
||
| 2212 | * <p>(Immutable)</p> |
||
| 2213 | */ |
||
| 2214 | 4 | public function group($grouper, bool $saveKeys = false): self |
|
| 2255 | |||
| 2256 | /** |
||
| 2257 | * Check if an array has a given key. |
||
| 2258 | * |
||
| 2259 | * @param mixed $key |
||
| 2260 | * |
||
| 2261 | * @return bool |
||
| 2262 | */ |
||
| 2263 | 23 | public function has($key): bool |
|
| 2274 | |||
| 2275 | /** |
||
| 2276 | * Check if an array has a given value. |
||
| 2277 | * |
||
| 2278 | * INFO: if you need to search recursive please use ```contains()``` |
||
| 2279 | * |
||
| 2280 | * @param mixed $value |
||
| 2281 | * |
||
| 2282 | * @return bool |
||
| 2283 | */ |
||
| 2284 | 1 | public function hasValue($value): bool |
|
| 2288 | |||
| 2289 | /** |
||
| 2290 | * Implodes the values of this array. |
||
| 2291 | * |
||
| 2292 | * @param string $glue |
||
| 2293 | * |
||
| 2294 | * @return string |
||
| 2295 | */ |
||
| 2296 | 28 | public function implode(string $glue = ''): string |
|
| 2300 | |||
| 2301 | /** |
||
| 2302 | * Implodes the keys of this array. |
||
| 2303 | * |
||
| 2304 | * @param string $glue |
||
| 2305 | * |
||
| 2306 | * @return string |
||
| 2307 | */ |
||
| 2308 | 8 | public function implodeKeys(string $glue = ''): string |
|
| 2312 | |||
| 2313 | /** |
||
| 2314 | * Given a list and an iterate-function that returns |
||
| 2315 | * a key for each element in the list (or a property name), |
||
| 2316 | * returns an object with an index of each item. |
||
| 2317 | * |
||
| 2318 | * @param mixed $key |
||
| 2319 | * |
||
| 2320 | * @return static |
||
| 2321 | * <p>(Immutable)</p> |
||
| 2322 | */ |
||
| 2323 | 4 | public function indexBy($key): self |
|
| 2340 | |||
| 2341 | /** |
||
| 2342 | * alias: for "Arrayy->searchIndex()" |
||
| 2343 | * |
||
| 2344 | * @param mixed $value <p>The value to search for.</p> |
||
| 2345 | * |
||
| 2346 | * @return false|mixed |
||
| 2347 | * |
||
| 2348 | * @see Arrayy::searchIndex() |
||
| 2349 | */ |
||
| 2350 | 4 | public function indexOf($value) |
|
| 2354 | |||
| 2355 | /** |
||
| 2356 | * Get everything but the last..$to items. |
||
| 2357 | * |
||
| 2358 | * @param int $to |
||
| 2359 | * |
||
| 2360 | * @return static |
||
| 2361 | * <p>(Immutable)</p> |
||
| 2362 | */ |
||
| 2363 | 12 | public function initial(int $to = 1): self |
|
| 2367 | |||
| 2368 | /** |
||
| 2369 | * Return an array with all elements found in input array. |
||
| 2370 | * |
||
| 2371 | * @param array $search |
||
| 2372 | * @param bool $keepKeys |
||
| 2373 | * |
||
| 2374 | * @return static |
||
| 2375 | * <p>(Immutable)</p> |
||
| 2376 | */ |
||
| 2377 | 4 | public function intersection(array $search, bool $keepKeys = false): self |
|
| 2399 | |||
| 2400 | /** |
||
| 2401 | * Return an array with all elements found in input array. |
||
| 2402 | * |
||
| 2403 | * @param array ...$array |
||
| 2404 | * |
||
| 2405 | * @return static |
||
| 2406 | * <p>(Immutable)</p> |
||
| 2407 | */ |
||
| 2408 | 1 | public function intersectionMulti(...$array): self |
|
| 2416 | |||
| 2417 | /** |
||
| 2418 | * Return a boolean flag which indicates whether the two input arrays have any common elements. |
||
| 2419 | * |
||
| 2420 | * @param array $search |
||
| 2421 | * |
||
| 2422 | * @return bool |
||
| 2423 | */ |
||
| 2424 | 1 | public function intersects(array $search): bool |
|
| 2428 | |||
| 2429 | /** |
||
| 2430 | * Invoke a function on all of an array's values. |
||
| 2431 | * |
||
| 2432 | * @param callable $callable |
||
| 2433 | * @param mixed $arguments |
||
| 2434 | * |
||
| 2435 | * @return static |
||
| 2436 | * <p>(Immutable)</p> |
||
| 2437 | */ |
||
| 2438 | 1 | public function invoke($callable, $arguments = []): self |
|
| 2462 | |||
| 2463 | /** |
||
| 2464 | * Check whether array is associative or not. |
||
| 2465 | * |
||
| 2466 | * @param bool $recursive |
||
| 2467 | * |
||
| 2468 | * @return bool |
||
| 2469 | * <p>Returns true if associative, false otherwise.</p> |
||
| 2470 | */ |
||
| 2471 | 15 | View Code Duplication | public function isAssoc(bool $recursive = false): bool |
| 2485 | |||
| 2486 | /** |
||
| 2487 | * Check if a given key or keys are empty. |
||
| 2488 | * |
||
| 2489 | * @param int|int[]|string|string[]|null $keys |
||
| 2490 | * |
||
| 2491 | * @return bool |
||
| 2492 | * <p>Returns true if empty, false otherwise.</p> |
||
| 2493 | */ |
||
| 2494 | 38 | public function isEmpty($keys = null): bool |
|
| 2512 | |||
| 2513 | /** |
||
| 2514 | * Check if the current array is equal to the given "$array" or not. |
||
| 2515 | * |
||
| 2516 | * @param array $array |
||
| 2517 | * |
||
| 2518 | * @return bool |
||
| 2519 | */ |
||
| 2520 | 1 | public function isEqual(array $array): bool |
|
| 2524 | |||
| 2525 | /** |
||
| 2526 | * Check if the current array is a multi-array. |
||
| 2527 | * |
||
| 2528 | * @return bool |
||
| 2529 | */ |
||
| 2530 | 22 | public function isMultiArray(): bool |
|
| 2538 | |||
| 2539 | /** |
||
| 2540 | * Check whether array is numeric or not. |
||
| 2541 | * |
||
| 2542 | * @return bool |
||
| 2543 | * <p>Returns true if numeric, false otherwise.</p> |
||
| 2544 | */ |
||
| 2545 | 5 | View Code Duplication | public function isNumeric(): bool |
| 2559 | |||
| 2560 | /** |
||
| 2561 | * Check if the current array is sequential [0, 1, 2, 3, 4, 5 ...] or not. |
||
| 2562 | * |
||
| 2563 | * @param bool $recursive |
||
| 2564 | * |
||
| 2565 | * @return bool |
||
| 2566 | */ |
||
| 2567 | 9 | public function isSequential(bool $recursive = false): bool |
|
| 2584 | |||
| 2585 | /** |
||
| 2586 | * @return array |
||
| 2587 | */ |
||
| 2588 | public function jsonSerialize(): array |
||
| 2592 | |||
| 2593 | /** |
||
| 2594 | * Gets the key/index of the element at the current internal iterator position. |
||
| 2595 | * |
||
| 2596 | * @return int|string|null |
||
| 2597 | */ |
||
| 2598 | public function key() |
||
| 2602 | |||
| 2603 | /** |
||
| 2604 | * Checks if the given key exists in the provided array. |
||
| 2605 | * |
||
| 2606 | * INFO: This method only use "array_key_exists()" if you want to use "dot"-notation, |
||
| 2607 | * then you need to use "Arrayy->offsetExists()". |
||
| 2608 | * |
||
| 2609 | * @param int|string $key the key to look for |
||
| 2610 | * |
||
| 2611 | * @return bool |
||
| 2612 | */ |
||
| 2613 | 124 | public function keyExists($key): bool |
|
| 2617 | |||
| 2618 | /** |
||
| 2619 | * Get all keys from the current array. |
||
| 2620 | * |
||
| 2621 | * @param bool $recursive [optional] <p> |
||
| 2622 | * Get all keys, also from all sub-arrays from an multi-dimensional array. |
||
| 2623 | * </p> |
||
| 2624 | * @param mixed|null $search_values [optional] <p> |
||
| 2625 | * If specified, then only keys containing these values are returned. |
||
| 2626 | * </p> |
||
| 2627 | * @param bool $strict [optional] <p> |
||
| 2628 | * Determines if strict comparison (===) should be used during the search. |
||
| 2629 | * </p> |
||
| 2630 | * |
||
| 2631 | * @return static |
||
| 2632 | * <p>(Immutable) An array of all the keys in input.</p> |
||
| 2633 | */ |
||
| 2634 | 29 | public function keys( |
|
| 2704 | |||
| 2705 | /** |
||
| 2706 | * Sort an array by key in reverse order. |
||
| 2707 | * |
||
| 2708 | * @param int $sort_flags [optional] <p> |
||
| 2709 | * You may modify the behavior of the sort using the optional |
||
| 2710 | * parameter sort_flags, for details |
||
| 2711 | * see sort. |
||
| 2712 | * </p> |
||
| 2713 | * |
||
| 2714 | * @return static |
||
| 2715 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 2716 | */ |
||
| 2717 | 4 | public function krsort(int $sort_flags = 0): self |
|
| 2725 | |||
| 2726 | /** |
||
| 2727 | * Get the last value from the current array. |
||
| 2728 | * |
||
| 2729 | * @return mixed |
||
| 2730 | * <p>Return null if there wasn't a element.</p> |
||
| 2731 | */ |
||
| 2732 | 17 | public function last() |
|
| 2741 | |||
| 2742 | /** |
||
| 2743 | * Get the last key from the current array. |
||
| 2744 | * |
||
| 2745 | * @return mixed |
||
| 2746 | * <p>Return null if there wasn't a element.</p> |
||
| 2747 | */ |
||
| 2748 | 21 | public function lastKey() |
|
| 2754 | |||
| 2755 | /** |
||
| 2756 | * Get the last value(s) from the current array. |
||
| 2757 | * |
||
| 2758 | * @param int|null $number |
||
| 2759 | * |
||
| 2760 | * @return static |
||
| 2761 | * <p>(Immutable)</p> |
||
| 2762 | */ |
||
| 2763 | 13 | public function lastsImmutable(int $number = null): self |
|
| 2794 | |||
| 2795 | /** |
||
| 2796 | * Get the last value(s) from the current array. |
||
| 2797 | * |
||
| 2798 | * @param int|null $number |
||
| 2799 | * |
||
| 2800 | * @return static |
||
| 2801 | * <p>(Mutable)</p> |
||
| 2802 | */ |
||
| 2803 | 13 | public function lastsMutable(int $number = null): self |
|
| 2832 | |||
| 2833 | /** |
||
| 2834 | * Count the values from the current array. |
||
| 2835 | * |
||
| 2836 | * alias: for "Arrayy->count()" |
||
| 2837 | * |
||
| 2838 | * @param int $mode |
||
| 2839 | * |
||
| 2840 | * @return int |
||
| 2841 | * |
||
| 2842 | * @see Arrayy::count() |
||
| 2843 | */ |
||
| 2844 | 20 | public function length(int $mode = \COUNT_NORMAL): int |
|
| 2848 | |||
| 2849 | /** |
||
| 2850 | * Apply the given function to the every element of the array, |
||
| 2851 | * collecting the results. |
||
| 2852 | * |
||
| 2853 | * @param callable $callable |
||
| 2854 | * @param bool $useKeyAsSecondParameter |
||
| 2855 | * @param mixed ...$arguments |
||
| 2856 | * |
||
| 2857 | * @return static |
||
| 2858 | * <p>(Immutable) Arrayy object with modified elements.</p> |
||
| 2859 | */ |
||
| 2860 | 5 | public function map(callable $callable, bool $useKeyAsSecondParameter = false, ...$arguments) |
|
| 2887 | |||
| 2888 | /** |
||
| 2889 | * Check if all items in current array match a truth test. |
||
| 2890 | * |
||
| 2891 | * @param \Closure $closure |
||
| 2892 | * |
||
| 2893 | * @return bool |
||
| 2894 | */ |
||
| 2895 | 15 | View Code Duplication | public function matches(\Closure $closure): bool |
| 2911 | |||
| 2912 | /** |
||
| 2913 | * Check if any item in the current array matches a truth test. |
||
| 2914 | * |
||
| 2915 | * @param \Closure $closure |
||
| 2916 | * |
||
| 2917 | * @return bool |
||
| 2918 | */ |
||
| 2919 | 14 | View Code Duplication | public function matchesAny(\Closure $closure): bool |
| 2935 | |||
| 2936 | /** |
||
| 2937 | * Get the max value from an array. |
||
| 2938 | * |
||
| 2939 | * @return mixed |
||
| 2940 | */ |
||
| 2941 | 10 | View Code Duplication | public function max() |
| 2949 | |||
| 2950 | /** |
||
| 2951 | * Merge the new $array into the current array. |
||
| 2952 | * |
||
| 2953 | * - keep key,value from the current array, also if the index is in the new $array |
||
| 2954 | * |
||
| 2955 | * @param array $array |
||
| 2956 | * @param bool $recursive |
||
| 2957 | * |
||
| 2958 | * @return static |
||
| 2959 | * <p>(Immutable)</p> |
||
| 2960 | */ |
||
| 2961 | 25 | View Code Duplication | public function mergeAppendKeepIndex(array $array = [], bool $recursive = false): self |
| 2975 | |||
| 2976 | /** |
||
| 2977 | * Merge the new $array into the current array. |
||
| 2978 | * |
||
| 2979 | * - replace duplicate assoc-keys from the current array with the key,values from the new $array |
||
| 2980 | * - create new indexes |
||
| 2981 | * |
||
| 2982 | * @param array $array |
||
| 2983 | * @param bool $recursive |
||
| 2984 | * |
||
| 2985 | * @return static |
||
| 2986 | * <p>(Immutable)</p> |
||
| 2987 | */ |
||
| 2988 | 16 | View Code Duplication | public function mergeAppendNewIndex(array $array = [], bool $recursive = false): self |
| 3002 | |||
| 3003 | /** |
||
| 3004 | * Merge the the current array into the $array. |
||
| 3005 | * |
||
| 3006 | * - use key,value from the new $array, also if the index is in the current array |
||
| 3007 | * |
||
| 3008 | * @param array $array |
||
| 3009 | * @param bool $recursive |
||
| 3010 | * |
||
| 3011 | * @return static |
||
| 3012 | * <p>(Immutable)</p> |
||
| 3013 | */ |
||
| 3014 | 16 | View Code Duplication | public function mergePrependKeepIndex(array $array = [], bool $recursive = false): self |
| 3028 | |||
| 3029 | /** |
||
| 3030 | * Merge the current array into the new $array. |
||
| 3031 | * |
||
| 3032 | * - replace duplicate assoc-keys from new $array with the key,values from the current array |
||
| 3033 | * - create new indexes |
||
| 3034 | * |
||
| 3035 | * @param array $array |
||
| 3036 | * @param bool $recursive |
||
| 3037 | * |
||
| 3038 | * @return static |
||
| 3039 | * <p>(Immutable)</p> |
||
| 3040 | */ |
||
| 3041 | 17 | View Code Duplication | public function mergePrependNewIndex(array $array = [], bool $recursive = false): self |
| 3055 | |||
| 3056 | /** |
||
| 3057 | * @return ArrayyMeta|static |
||
| 3058 | */ |
||
| 3059 | 15 | public static function meta() |
|
| 3063 | |||
| 3064 | /** |
||
| 3065 | * Get the min value from an array. |
||
| 3066 | * |
||
| 3067 | * @return mixed |
||
| 3068 | */ |
||
| 3069 | 10 | View Code Duplication | public function min() |
| 3077 | |||
| 3078 | /** |
||
| 3079 | * Get the most used value from the array. |
||
| 3080 | * |
||
| 3081 | * @return mixed |
||
| 3082 | * <p>Return null if there wasn't a element.</p> |
||
| 3083 | */ |
||
| 3084 | 3 | public function mostUsedValue() |
|
| 3088 | |||
| 3089 | /** |
||
| 3090 | * Get the most used value from the array. |
||
| 3091 | * |
||
| 3092 | * @param int|null $number <p>How many values you will take?</p> |
||
| 3093 | * |
||
| 3094 | * @return static |
||
| 3095 | * <p>(Immutable)</p> |
||
| 3096 | */ |
||
| 3097 | 3 | public function mostUsedValues(int $number = null): self |
|
| 3101 | |||
| 3102 | /** |
||
| 3103 | * Move an array element to a new index. |
||
| 3104 | * |
||
| 3105 | * cherry-picked from: http://stackoverflow.com/questions/12624153/move-an-array-element-to-a-new-index-in-php |
||
| 3106 | * |
||
| 3107 | * @param int|string $from |
||
| 3108 | * @param int $to |
||
| 3109 | * |
||
| 3110 | * @return static |
||
| 3111 | * <p>(Immutable)</p> |
||
| 3112 | */ |
||
| 3113 | 1 | public function moveElement($from, $to): self |
|
| 3146 | |||
| 3147 | /** |
||
| 3148 | * Move an array element to the first place. |
||
| 3149 | * |
||
| 3150 | * INFO: Instead of "Arrayy->moveElement()" this method will NOT |
||
| 3151 | * loss the keys of an indexed array. |
||
| 3152 | * |
||
| 3153 | * @param int|string $key |
||
| 3154 | * |
||
| 3155 | * @return static |
||
| 3156 | * <p>(Immutable)</p> |
||
| 3157 | */ |
||
| 3158 | 1 | View Code Duplication | public function moveElementToFirstPlace($key): self |
| 3174 | |||
| 3175 | /** |
||
| 3176 | * Move an array element to the last place. |
||
| 3177 | * |
||
| 3178 | * INFO: Instead of "Arrayy->moveElement()" this method will NOT |
||
| 3179 | * loss the keys of an indexed array. |
||
| 3180 | * |
||
| 3181 | * @param int|string $key |
||
| 3182 | * |
||
| 3183 | * @return static |
||
| 3184 | * <p>(Immutable)</p> |
||
| 3185 | */ |
||
| 3186 | 1 | View Code Duplication | public function moveElementToLastPlace($key): self |
| 3202 | |||
| 3203 | /** |
||
| 3204 | * Moves the internal iterator position to the next element and returns this element. |
||
| 3205 | * |
||
| 3206 | * @return mixed |
||
| 3207 | */ |
||
| 3208 | public function next() |
||
| 3212 | |||
| 3213 | /** |
||
| 3214 | * Get a subset of the items from the given array. |
||
| 3215 | * |
||
| 3216 | * @param mixed[] $keys |
||
| 3217 | * |
||
| 3218 | * @return static |
||
| 3219 | * <p>(Immutable)</p> |
||
| 3220 | */ |
||
| 3221 | public function only(array $keys): self |
||
| 3231 | |||
| 3232 | /** |
||
| 3233 | * Pad array to the specified size with a given value. |
||
| 3234 | * |
||
| 3235 | * @param int $size <p>Size of the result array.</p> |
||
| 3236 | * @param mixed $value <p>Empty value by default.</p> |
||
| 3237 | * |
||
| 3238 | * @return static |
||
| 3239 | * <p>(Immutable) Arrayy object padded to $size with $value.</p> |
||
| 3240 | */ |
||
| 3241 | 5 | public function pad(int $size, $value): self |
|
| 3249 | |||
| 3250 | /** |
||
| 3251 | * Partitions this array in two array according to a predicate. |
||
| 3252 | * Keys are preserved in the resulting array. |
||
| 3253 | * |
||
| 3254 | * @param \Closure $closure |
||
| 3255 | * <p>The predicate on which to partition.</p> |
||
| 3256 | * |
||
| 3257 | * @return array<int, static> |
||
| 3258 | * <p>An array with two elements. The first element contains the array |
||
| 3259 | * of elements where the predicate returned TRUE, the second element |
||
| 3260 | * contains the array of elements where the predicate returned FALSE.</p> |
||
| 3261 | */ |
||
| 3262 | public function partition(\Closure $closure): array |
||
| 3278 | |||
| 3279 | /** |
||
| 3280 | * Pop a specified value off the end of the current array. |
||
| 3281 | * |
||
| 3282 | * @return mixed |
||
| 3283 | * <p>(Mutable) The popped element from the current array.</p> |
||
| 3284 | */ |
||
| 3285 | 5 | public function pop() |
|
| 3291 | |||
| 3292 | /** |
||
| 3293 | * Prepend a (key) + value to the current array. |
||
| 3294 | * |
||
| 3295 | * @param mixed $value |
||
| 3296 | * @param mixed $key |
||
| 3297 | * |
||
| 3298 | * @return static |
||
| 3299 | * <p>(Mutable) Return this Arrayy object, with the prepended value.</p> |
||
| 3300 | */ |
||
| 3301 | 11 | public function prepend($value, $key = null) |
|
| 3317 | |||
| 3318 | /** |
||
| 3319 | * Add a suffix to each key. |
||
| 3320 | * |
||
| 3321 | * @param mixed $suffix |
||
| 3322 | * |
||
| 3323 | * @return static |
||
| 3324 | * <p>(Immutable) Return an Arrayy object, with the prepended keys.</p> |
||
| 3325 | */ |
||
| 3326 | 10 | View Code Duplication | public function prependToEachKey($suffix): self |
| 3352 | |||
| 3353 | /** |
||
| 3354 | * Add a suffix to each value. |
||
| 3355 | * |
||
| 3356 | * @param mixed $suffix |
||
| 3357 | * |
||
| 3358 | * @return static |
||
| 3359 | * <p>(Immutable) Return an Arrayy object, with the prepended values.</p> |
||
| 3360 | */ |
||
| 3361 | 10 | View Code Duplication | public function prependToEachValue($suffix): self |
| 3389 | |||
| 3390 | /** |
||
| 3391 | * Return the value of a given key and |
||
| 3392 | * delete the key. |
||
| 3393 | * |
||
| 3394 | * @param int|int[]|string|string[]|null $keyOrKeys |
||
| 3395 | * @param mixed $fallback |
||
| 3396 | * |
||
| 3397 | * @return mixed |
||
| 3398 | */ |
||
| 3399 | 1 | public function pull($keyOrKeys = null, $fallback = null) |
|
| 3421 | |||
| 3422 | /** |
||
| 3423 | * Push one or more values onto the end of array at once. |
||
| 3424 | * |
||
| 3425 | * @param array ...$args |
||
| 3426 | * |
||
| 3427 | * @return static |
||
| 3428 | * <p>(Mutable) Return this Arrayy object, with pushed elements to the end of array.</p> |
||
| 3429 | * |
||
| 3430 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
| 3431 | */ |
||
| 3432 | 5 | public function push(...$args) |
|
| 3450 | |||
| 3451 | /** |
||
| 3452 | * Get a random value from the current array. |
||
| 3453 | * |
||
| 3454 | * @param int|null $number <p>How many values you will take?</p> |
||
| 3455 | * |
||
| 3456 | * @return static |
||
| 3457 | * <p>(Immutable)</p> |
||
| 3458 | */ |
||
| 3459 | 19 | public function randomImmutable(int $number = null): self |
|
| 3492 | |||
| 3493 | /** |
||
| 3494 | * Pick a random key/index from the keys of this array. |
||
| 3495 | * |
||
| 3496 | * @throws \RangeException If array is empty |
||
| 3497 | * |
||
| 3498 | * @return mixed |
||
| 3499 | * <p>Get a key/index or null if there wasn't a key/index.</p> |
||
| 3500 | */ |
||
| 3501 | 4 | public function randomKey() |
|
| 3511 | |||
| 3512 | /** |
||
| 3513 | * Pick a given number of random keys/indexes out of this array. |
||
| 3514 | * |
||
| 3515 | * @param int $number <p>The number of keys/indexes (should be <= \count($this->array))</p> |
||
| 3516 | * |
||
| 3517 | * @throws \RangeException If array is empty |
||
| 3518 | * |
||
| 3519 | * @return static |
||
| 3520 | * <p>(Immutable)</p> |
||
| 3521 | */ |
||
| 3522 | 13 | public function randomKeys(int $number): self |
|
| 3546 | |||
| 3547 | /** |
||
| 3548 | * Get a random value from the current array. |
||
| 3549 | * |
||
| 3550 | * @param int|null $number <p>How many values you will take?</p> |
||
| 3551 | * |
||
| 3552 | * @return static |
||
| 3553 | * <p>(Mutable)</p> |
||
| 3554 | */ |
||
| 3555 | 17 | public function randomMutable(int $number = null): self |
|
| 3580 | |||
| 3581 | /** |
||
| 3582 | * Pick a random value from the values of this array. |
||
| 3583 | * |
||
| 3584 | * @return mixed |
||
| 3585 | * <p>Get a random value or null if there wasn't a value.</p> |
||
| 3586 | */ |
||
| 3587 | 4 | public function randomValue() |
|
| 3597 | |||
| 3598 | /** |
||
| 3599 | * Pick a given number of random values out of this array. |
||
| 3600 | * |
||
| 3601 | * @param int $number |
||
| 3602 | * |
||
| 3603 | * @return static |
||
| 3604 | * <p>(Mutable)</p> |
||
| 3605 | */ |
||
| 3606 | 7 | public function randomValues(int $number): self |
|
| 3610 | |||
| 3611 | /** |
||
| 3612 | * Get a random value from an array, with the ability to skew the results. |
||
| 3613 | * |
||
| 3614 | * Example: randomWeighted(['foo' => 1, 'bar' => 2]) has a 66% chance of returning bar. |
||
| 3615 | * |
||
| 3616 | * @param array $array |
||
| 3617 | * @param int|null $number <p>How many values you will take?</p> |
||
| 3618 | * |
||
| 3619 | * @return static |
||
| 3620 | * <p>(Immutable)</p> |
||
| 3621 | */ |
||
| 3622 | 9 | public function randomWeighted(array $array, int $number = null): self |
|
| 3637 | |||
| 3638 | /** |
||
| 3639 | * Reduce the current array via callable e.g. anonymous-function. |
||
| 3640 | * |
||
| 3641 | * @param callable $callable |
||
| 3642 | * @param mixed $init |
||
| 3643 | * |
||
| 3644 | * @return static |
||
| 3645 | * <p>(Immutable)</p> |
||
| 3646 | */ |
||
| 3647 | 18 | public function reduce($callable, $init = []): self |
|
| 3677 | |||
| 3678 | /** |
||
| 3679 | * @param bool $unique |
||
| 3680 | * |
||
| 3681 | * @return static |
||
| 3682 | * <p>(Immutable)</p> |
||
| 3683 | */ |
||
| 3684 | 14 | public function reduce_dimension(bool $unique = true): self |
|
| 3703 | |||
| 3704 | /** |
||
| 3705 | * Create a numerically re-indexed Arrayy object. |
||
| 3706 | * |
||
| 3707 | * @return static |
||
| 3708 | * <p>(Mutable) Return this Arrayy object, with re-indexed array-elements.</p> |
||
| 3709 | */ |
||
| 3710 | 9 | public function reindex(): self |
|
| 3718 | |||
| 3719 | /** |
||
| 3720 | * Return all items that fail the truth test. |
||
| 3721 | * |
||
| 3722 | * @param \Closure $closure |
||
| 3723 | * |
||
| 3724 | * @return static |
||
| 3725 | * <p>(Immutable)</p> |
||
| 3726 | */ |
||
| 3727 | 1 | View Code Duplication | public function reject(\Closure $closure): self |
| 3744 | |||
| 3745 | /** |
||
| 3746 | * Remove a value from the current array (optional using dot-notation). |
||
| 3747 | * |
||
| 3748 | * @param mixed $key |
||
| 3749 | * |
||
| 3750 | * @return static |
||
| 3751 | * <p>(Mutable)</p> |
||
| 3752 | */ |
||
| 3753 | 18 | public function remove($key) |
|
| 3776 | |||
| 3777 | /** |
||
| 3778 | * alias: for "Arrayy->removeValue()" |
||
| 3779 | * |
||
| 3780 | * @param mixed $element |
||
| 3781 | * |
||
| 3782 | * @return static |
||
| 3783 | */ |
||
| 3784 | 8 | public function removeElement($element) |
|
| 3788 | |||
| 3789 | /** |
||
| 3790 | * Remove the first value from the current array. |
||
| 3791 | * |
||
| 3792 | * @return static |
||
| 3793 | * <p>(Immutable)</p> |
||
| 3794 | */ |
||
| 3795 | 7 | View Code Duplication | public function removeFirst(): self |
| 3807 | |||
| 3808 | /** |
||
| 3809 | * Remove the last value from the current array. |
||
| 3810 | * |
||
| 3811 | * @return static |
||
| 3812 | * <p>(Immutable)</p> |
||
| 3813 | */ |
||
| 3814 | 7 | View Code Duplication | public function removeLast(): self |
| 3826 | |||
| 3827 | /** |
||
| 3828 | * Removes a particular value from an array (numeric or associative). |
||
| 3829 | * |
||
| 3830 | * @param mixed $value |
||
| 3831 | * |
||
| 3832 | * @return static |
||
| 3833 | * <p>(Immutable)</p> |
||
| 3834 | */ |
||
| 3835 | 8 | public function removeValue($value): self |
|
| 3858 | |||
| 3859 | /** |
||
| 3860 | * Generate array of repeated arrays. |
||
| 3861 | * |
||
| 3862 | * @param int $times <p>How many times has to be repeated.</p> |
||
| 3863 | * |
||
| 3864 | * @return static |
||
| 3865 | * <p>(Immutable)</p> |
||
| 3866 | */ |
||
| 3867 | 1 | public function repeat($times): self |
|
| 3879 | |||
| 3880 | /** |
||
| 3881 | * Replace a key with a new key/value pair. |
||
| 3882 | * |
||
| 3883 | * @param mixed $replace |
||
| 3884 | * @param mixed $key |
||
| 3885 | * @param mixed $value |
||
| 3886 | * |
||
| 3887 | * @return static |
||
| 3888 | * <p>(Immutable)</p> |
||
| 3889 | */ |
||
| 3890 | 2 | public function replace($replace, $key, $value): self |
|
| 3897 | |||
| 3898 | /** |
||
| 3899 | * Create an array using the current array as values and the other array as keys. |
||
| 3900 | * |
||
| 3901 | * @param array $keys <p>An array of keys.</p> |
||
| 3902 | * |
||
| 3903 | * @return static |
||
| 3904 | * <p>(Immutable) Arrayy object with keys from the other array.</p> |
||
| 3905 | */ |
||
| 3906 | 2 | public function replaceAllKeys(array $keys): self |
|
| 3914 | |||
| 3915 | /** |
||
| 3916 | * Create an array using the current array as keys and the other array as values. |
||
| 3917 | * |
||
| 3918 | * @param array $array <p>An array o values.</p> |
||
| 3919 | * |
||
| 3920 | * @return static |
||
| 3921 | * <p>(Immutable) Arrayy object with values from the other array.</p> |
||
| 3922 | */ |
||
| 3923 | 2 | public function replaceAllValues(array $array): self |
|
| 3931 | |||
| 3932 | /** |
||
| 3933 | * Replace the keys in an array with another set. |
||
| 3934 | * |
||
| 3935 | * @param array $keys <p>An array of keys matching the array's size</p> |
||
| 3936 | * |
||
| 3937 | * @return static |
||
| 3938 | * <p>(Immutable)</p> |
||
| 3939 | */ |
||
| 3940 | 1 | public function replaceKeys(array $keys): self |
|
| 3951 | |||
| 3952 | /** |
||
| 3953 | * Replace the first matched value in an array. |
||
| 3954 | * |
||
| 3955 | * @param mixed $search <p>The value to replace.</p> |
||
| 3956 | * @param mixed $replacement <p>The value to replace.</p> |
||
| 3957 | * |
||
| 3958 | * @return static |
||
| 3959 | * <p>(Immutable)</p> |
||
| 3960 | */ |
||
| 3961 | 3 | public function replaceOneValue($search, $replacement = ''): self |
|
| 3976 | |||
| 3977 | /** |
||
| 3978 | * Replace values in the current array. |
||
| 3979 | * |
||
| 3980 | * @param mixed $search <p>The value to replace.</p> |
||
| 3981 | * @param mixed $replacement <p>What to replace it with.</p> |
||
| 3982 | * |
||
| 3983 | * @return static |
||
| 3984 | * <p>(Immutable)</p> |
||
| 3985 | */ |
||
| 3986 | 1 | public function replaceValues($search, $replacement = ''): self |
|
| 3994 | |||
| 3995 | /** |
||
| 3996 | * Get the last elements from index $from until the end of this array. |
||
| 3997 | * |
||
| 3998 | * @param int $from |
||
| 3999 | * |
||
| 4000 | * @return static |
||
| 4001 | * <p>(Immutable)</p> |
||
| 4002 | */ |
||
| 4003 | 15 | View Code Duplication | public function rest(int $from = 1): self |
| 4013 | |||
| 4014 | /** |
||
| 4015 | * Return the array in the reverse order. |
||
| 4016 | * |
||
| 4017 | * @return static |
||
| 4018 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 4019 | */ |
||
| 4020 | 9 | public function reverse(): self |
|
| 4028 | |||
| 4029 | /** |
||
| 4030 | * Sort an array in reverse order. |
||
| 4031 | * |
||
| 4032 | * @param int $sort_flags [optional] <p> |
||
| 4033 | * You may modify the behavior of the sort using the optional |
||
| 4034 | * parameter sort_flags, for details |
||
| 4035 | * see sort. |
||
| 4036 | * </p> |
||
| 4037 | * |
||
| 4038 | * @return static |
||
| 4039 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 4040 | */ |
||
| 4041 | 4 | public function rsort(int $sort_flags = 0): self |
|
| 4049 | |||
| 4050 | /** |
||
| 4051 | * Search for the first index of the current array via $value. |
||
| 4052 | * |
||
| 4053 | * @param mixed $value |
||
| 4054 | * |
||
| 4055 | * @return false|float|int|string |
||
| 4056 | * <p>Will return <b>FALSE</b> if the value can't be found.</p> |
||
| 4057 | */ |
||
| 4058 | 21 | public function searchIndex($value) |
|
| 4068 | |||
| 4069 | /** |
||
| 4070 | * Search for the value of the current array via $index. |
||
| 4071 | * |
||
| 4072 | * @param mixed $index |
||
| 4073 | * |
||
| 4074 | * @return static |
||
| 4075 | * <p>(Immutable) Will return a empty Arrayy if the value wasn't found.</p> |
||
| 4076 | */ |
||
| 4077 | 9 | public function searchValue($index): self |
|
| 4107 | |||
| 4108 | /** |
||
| 4109 | * Set a value for the current array (optional using dot-notation). |
||
| 4110 | * |
||
| 4111 | * @param string $key <p>The key to set.</p> |
||
| 4112 | * @param mixed $value <p>Its value.</p> |
||
| 4113 | * |
||
| 4114 | * @return static |
||
| 4115 | * <p>(Mutable)</p> |
||
| 4116 | */ |
||
| 4117 | 18 | public function set($key, $value): self |
|
| 4125 | |||
| 4126 | /** |
||
| 4127 | * Get a value from a array and set it if it was not. |
||
| 4128 | * |
||
| 4129 | * WARNING: this method only set the value, if the $key is not already set |
||
| 4130 | * |
||
| 4131 | * @param mixed $key <p>The key</p> |
||
| 4132 | * @param mixed $fallback <p>The default value to set if it isn't.</p> |
||
| 4133 | * |
||
| 4134 | * @return mixed |
||
| 4135 | * <p>(Mutable)</p> |
||
| 4136 | */ |
||
| 4137 | 11 | public function setAndGet($key, $fallback = null) |
|
| 4148 | |||
| 4149 | /** |
||
| 4150 | * Shifts a specified value off the beginning of array. |
||
| 4151 | * |
||
| 4152 | * @return mixed |
||
| 4153 | * <p>(Mutable) A shifted element from the current array.</p> |
||
| 4154 | */ |
||
| 4155 | 5 | public function shift() |
|
| 4161 | |||
| 4162 | /** |
||
| 4163 | * Shuffle the current array. |
||
| 4164 | * |
||
| 4165 | * @param bool $secure <p>using a CSPRNG | @link https://paragonie.com/b/JvICXzh_jhLyt4y3</p> |
||
| 4166 | * @param array $array [optional] |
||
| 4167 | * |
||
| 4168 | * @return static |
||
| 4169 | * <p>(Immutable)</p> |
||
| 4170 | */ |
||
| 4171 | 2 | public function shuffle(bool $secure = false, array $array = null): self |
|
| 4214 | |||
| 4215 | /** |
||
| 4216 | * Count the values from the current array. |
||
| 4217 | * |
||
| 4218 | * alias: for "Arrayy->count()" |
||
| 4219 | * |
||
| 4220 | * @param int $mode |
||
| 4221 | * |
||
| 4222 | * @return int |
||
| 4223 | */ |
||
| 4224 | 20 | public function size(int $mode = \COUNT_NORMAL): int |
|
| 4228 | |||
| 4229 | /** |
||
| 4230 | * Checks whether array has exactly $size items. |
||
| 4231 | * |
||
| 4232 | * @param int $size |
||
| 4233 | * |
||
| 4234 | * @return bool |
||
| 4235 | */ |
||
| 4236 | 1 | View Code Duplication | public function sizeIs(int $size): bool |
| 4250 | |||
| 4251 | /** |
||
| 4252 | * Checks whether array has between $fromSize to $toSize items. $toSize can be |
||
| 4253 | * smaller than $fromSize. |
||
| 4254 | * |
||
| 4255 | * @param int $fromSize |
||
| 4256 | * @param int $toSize |
||
| 4257 | * |
||
| 4258 | * @return bool |
||
| 4259 | */ |
||
| 4260 | 1 | public function sizeIsBetween(int $fromSize, int $toSize): bool |
|
| 4280 | |||
| 4281 | /** |
||
| 4282 | * Checks whether array has more than $size items. |
||
| 4283 | * |
||
| 4284 | * @param int $size |
||
| 4285 | * |
||
| 4286 | * @return bool |
||
| 4287 | */ |
||
| 4288 | 1 | View Code Duplication | public function sizeIsGreaterThan(int $size): bool |
| 4302 | |||
| 4303 | /** |
||
| 4304 | * Checks whether array has less than $size items. |
||
| 4305 | * |
||
| 4306 | * @param int $size |
||
| 4307 | * |
||
| 4308 | * @return bool |
||
| 4309 | */ |
||
| 4310 | 1 | View Code Duplication | public function sizeIsLessThan(int $size): bool |
| 4324 | |||
| 4325 | /** |
||
| 4326 | * Counts all elements in an array, or something in an object. |
||
| 4327 | * |
||
| 4328 | * <p> |
||
| 4329 | * For objects, if you have SPL installed, you can hook into count() by implementing interface {@see Countable}. |
||
| 4330 | * The interface has exactly one method, {@see Countable::count()}, which returns the return value for the count() |
||
| 4331 | * function. Please see the {@see Array} section of the manual for a detailed explanation of how arrays are |
||
| 4332 | * implemented and used in PHP. |
||
| 4333 | * </p> |
||
| 4334 | * |
||
| 4335 | * @return int |
||
| 4336 | * <p> |
||
| 4337 | * The number of elements in var, which is |
||
| 4338 | * typically an array, since anything else will have one |
||
| 4339 | * element. |
||
| 4340 | * </p> |
||
| 4341 | * <p> |
||
| 4342 | * If var is not an array or an object with |
||
| 4343 | * implemented Countable interface, |
||
| 4344 | * 1 will be returned. |
||
| 4345 | * There is one exception, if var is &null;, |
||
| 4346 | * 0 will be returned. |
||
| 4347 | * </p> |
||
| 4348 | * <p> |
||
| 4349 | * Caution: count may return 0 for a variable that isn't set, |
||
| 4350 | * but it may also return 0 for a variable that has been initialized with an |
||
| 4351 | * empty array. Use isset to test if a variable is set. |
||
| 4352 | * </p> |
||
| 4353 | */ |
||
| 4354 | 10 | public function sizeRecursive(): int |
|
| 4358 | |||
| 4359 | /** |
||
| 4360 | * Extract a slice of the array. |
||
| 4361 | * |
||
| 4362 | * @param int $offset <p>Slice begin index.</p> |
||
| 4363 | * @param int|null $length <p>Length of the slice.</p> |
||
| 4364 | * @param bool $preserveKeys <p>Whether array keys are preserved or no.</p> |
||
| 4365 | * |
||
| 4366 | * @return static |
||
| 4367 | * <p>A slice of the original array with length $length.</p> |
||
| 4368 | */ |
||
| 4369 | 5 | public function slice(int $offset, int $length = null, bool $preserveKeys = false) |
|
| 4382 | |||
| 4383 | /** |
||
| 4384 | * Sort the current array and optional you can keep the keys. |
||
| 4385 | * |
||
| 4386 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 4387 | * @param int $strategy <p>sort_flags => use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 4388 | * <strong>SORT_NATURAL</strong></p> |
||
| 4389 | * @param bool $keepKeys |
||
| 4390 | * |
||
| 4391 | * @return static |
||
| 4392 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 4393 | */ |
||
| 4394 | 20 | public function sort($direction = \SORT_ASC, int $strategy = \SORT_REGULAR, bool $keepKeys = false): self |
|
| 4405 | |||
| 4406 | /** |
||
| 4407 | * Sort the current array by key. |
||
| 4408 | * |
||
| 4409 | * @see http://php.net/manual/en/function.ksort.php |
||
| 4410 | * @see http://php.net/manual/en/function.krsort.php |
||
| 4411 | * |
||
| 4412 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 4413 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 4414 | * <strong>SORT_NATURAL</strong></p> |
||
| 4415 | * |
||
| 4416 | * @return static |
||
| 4417 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 4418 | */ |
||
| 4419 | 18 | public function sortKeys($direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
| 4427 | |||
| 4428 | /** |
||
| 4429 | * Sort the current array by value. |
||
| 4430 | * |
||
| 4431 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 4432 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 4433 | * <strong>SORT_NATURAL</strong></p> |
||
| 4434 | * |
||
| 4435 | * @return static |
||
| 4436 | * <p>(Mutable)</p> |
||
| 4437 | */ |
||
| 4438 | 1 | public function sortValueKeepIndex($direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
| 4442 | |||
| 4443 | /** |
||
| 4444 | * Sort the current array by value. |
||
| 4445 | * |
||
| 4446 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 4447 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 4448 | * <strong>SORT_NATURAL</strong></p> |
||
| 4449 | * |
||
| 4450 | * @return static |
||
| 4451 | * <p>(Mutable)</p> |
||
| 4452 | */ |
||
| 4453 | 1 | public function sortValueNewIndex($direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
| 4457 | |||
| 4458 | /** |
||
| 4459 | * Sort a array by value, by a closure or by a property. |
||
| 4460 | * |
||
| 4461 | * - If the sorter is null, the array is sorted naturally. |
||
| 4462 | * - Associative (string) keys will be maintained, but numeric keys will be re-indexed. |
||
| 4463 | * |
||
| 4464 | * @param callable|string|null $sorter |
||
| 4465 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or |
||
| 4466 | * <strong>SORT_DESC</strong></p> |
||
| 4467 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 4468 | * <strong>SORT_NATURAL</strong></p> |
||
| 4469 | * |
||
| 4470 | * @return static |
||
| 4471 | * <p>(Immutable)</p> |
||
| 4472 | */ |
||
| 4473 | 1 | public function sorter($sorter = null, $direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
| 4510 | |||
| 4511 | /** |
||
| 4512 | * @param int $offset |
||
| 4513 | * @param int|null $length |
||
| 4514 | * @param array $replacement |
||
| 4515 | * |
||
| 4516 | * @return static |
||
| 4517 | * <p>(Immutable)</p> |
||
| 4518 | */ |
||
| 4519 | 1 | public function splice(int $offset, int $length = null, $replacement = []): self |
|
| 4531 | |||
| 4532 | /** |
||
| 4533 | * Split an array in the given amount of pieces. |
||
| 4534 | * |
||
| 4535 | * @param int $numberOfPieces |
||
| 4536 | * @param bool $keepKeys |
||
| 4537 | * |
||
| 4538 | * @return static |
||
| 4539 | * <p>(Immutable)</p> |
||
| 4540 | */ |
||
| 4541 | 1 | public function split(int $numberOfPieces = 2, bool $keepKeys = false): self |
|
| 4560 | |||
| 4561 | /** |
||
| 4562 | * Stripe all empty items. |
||
| 4563 | * |
||
| 4564 | * @return static |
||
| 4565 | * <p>(Immutable)</p> |
||
| 4566 | */ |
||
| 4567 | 1 | public function stripEmpty(): self |
|
| 4579 | |||
| 4580 | /** |
||
| 4581 | * Swap two values between positions by key. |
||
| 4582 | * |
||
| 4583 | * @param int|string $swapA <p>a key in the array</p> |
||
| 4584 | * @param int|string $swapB <p>a key in the array</p> |
||
| 4585 | * |
||
| 4586 | * @return static |
||
| 4587 | * <p>(Immutable)</p> |
||
| 4588 | */ |
||
| 4589 | 1 | public function swap($swapA, $swapB): self |
|
| 4601 | |||
| 4602 | /** |
||
| 4603 | * alias: for "Arrayy->getArray()" |
||
| 4604 | * |
||
| 4605 | * @param bool $convertAllArrayyElements |
||
| 4606 | * |
||
| 4607 | * @return array |
||
| 4608 | * |
||
| 4609 | * @see Arrayy::getArray() |
||
| 4610 | */ |
||
| 4611 | 237 | public function toArray(bool $convertAllArrayyElements = false): array |
|
| 4615 | |||
| 4616 | /** |
||
| 4617 | * Convert the current array to JSON. |
||
| 4618 | * |
||
| 4619 | * @param int $options [optional] <p>e.g. JSON_PRETTY_PRINT</p> |
||
| 4620 | * @param int $depth [optional] <p>Set the maximum depth. Must be greater than zero.</p> |
||
| 4621 | * |
||
| 4622 | * @return string |
||
| 4623 | */ |
||
| 4624 | 7 | public function toJson(int $options = 0, int $depth = 512): string |
|
| 4633 | |||
| 4634 | /** |
||
| 4635 | * Implodes array to a string with specified separator. |
||
| 4636 | * |
||
| 4637 | * @param string $separator [optional] <p>The element's separator.</p> |
||
| 4638 | * |
||
| 4639 | * @return string |
||
| 4640 | * <p>The string representation of array, separated by ",".</p> |
||
| 4641 | */ |
||
| 4642 | 19 | public function toString(string $separator = ','): string |
|
| 4646 | |||
| 4647 | /** |
||
| 4648 | * Return a duplicate free copy of the current array. |
||
| 4649 | * |
||
| 4650 | * @return static |
||
| 4651 | * <p>(Mutable)</p> |
||
| 4652 | */ |
||
| 4653 | 13 | public function unique(): self |
|
| 4671 | |||
| 4672 | /** |
||
| 4673 | * Return a duplicate free copy of the current array. (with the old keys) |
||
| 4674 | * |
||
| 4675 | * @return static |
||
| 4676 | * <p>(Mutable)</p> |
||
| 4677 | */ |
||
| 4678 | 11 | public function uniqueKeepIndex(): self |
|
| 4706 | |||
| 4707 | /** |
||
| 4708 | * alias: for "Arrayy->unique()" |
||
| 4709 | * |
||
| 4710 | * @return static |
||
| 4711 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
| 4712 | * |
||
| 4713 | * @see Arrayy::unique() |
||
| 4714 | */ |
||
| 4715 | 10 | public function uniqueNewIndex(): self |
|
| 4719 | |||
| 4720 | /** |
||
| 4721 | * Prepends one or more values to the beginning of array at once. |
||
| 4722 | * |
||
| 4723 | * @param array ...$args |
||
| 4724 | * |
||
| 4725 | * @return static |
||
| 4726 | * <p>(Mutable) Return this Arrayy object, with prepended elements to the beginning of array.</p> |
||
| 4727 | */ |
||
| 4728 | 4 | public function unshift(...$args): self |
|
| 4736 | |||
| 4737 | /** |
||
| 4738 | * Get all values from a array. |
||
| 4739 | * |
||
| 4740 | * @return static |
||
| 4741 | * <p>(Immutable)</p> |
||
| 4742 | */ |
||
| 4743 | 2 | public function values(): self |
|
| 4756 | |||
| 4757 | /** |
||
| 4758 | * Apply the given function to every element in the array, discarding the results. |
||
| 4759 | * |
||
| 4760 | * @param callable $callable |
||
| 4761 | * @param bool $recursive <p>Whether array will be walked recursively or no</p> |
||
| 4762 | * |
||
| 4763 | * @return static |
||
| 4764 | * <p>(Mutable) Return this Arrayy object, with modified elements.</p> |
||
| 4765 | */ |
||
| 4766 | 12 | public function walk($callable, bool $recursive = false): self |
|
| 4778 | |||
| 4779 | /** |
||
| 4780 | * Returns a collection of matching items. |
||
| 4781 | * |
||
| 4782 | * @param string $keyOrPropertyOrMethod the property or method to evaluate |
||
| 4783 | * @param mixed $value the value to match |
||
| 4784 | * |
||
| 4785 | * @throws \InvalidArgumentException if property or method is not defined |
||
| 4786 | * |
||
| 4787 | * @return static |
||
| 4788 | * |
||
| 4789 | * @psalm-return static<T> |
||
| 4790 | */ |
||
| 4791 | 1 | public function where(string $keyOrPropertyOrMethod, $value): self |
|
| 4804 | |||
| 4805 | /** |
||
| 4806 | * Convert an array into a object. |
||
| 4807 | * |
||
| 4808 | * @param array $array PHP array |
||
| 4809 | * |
||
| 4810 | * @return \stdClass |
||
| 4811 | */ |
||
| 4812 | 4 | final protected static function arrayToObject(array $array = []): \stdClass |
|
| 4831 | |||
| 4832 | /** |
||
| 4833 | * @param array|\Generator|null $input <p> |
||
| 4834 | * An array containing keys to return. |
||
| 4835 | * </p> |
||
| 4836 | * @param mixed|null $search_values [optional] <p> |
||
| 4837 | * If specified, then only keys containing these values are returned. |
||
| 4838 | * </p> |
||
| 4839 | * @param bool $strict [optional] <p> |
||
| 4840 | * Determines if strict comparison (===) should be used during the |
||
| 4841 | * search. |
||
| 4842 | * </p> |
||
| 4843 | * |
||
| 4844 | * @return array |
||
| 4845 | * <p>an array of all the keys in input</p> |
||
| 4846 | */ |
||
| 4847 | 11 | protected function array_keys_recursive( |
|
| 4908 | |||
| 4909 | /** |
||
| 4910 | * @param mixed $path |
||
| 4911 | * @param callable $callable |
||
| 4912 | * @param array|null $currentOffset |
||
| 4913 | * |
||
| 4914 | * @return void |
||
| 4915 | */ |
||
| 4916 | 4 | protected function callAtPath($path, $callable, &$currentOffset = null) |
|
| 4945 | |||
| 4946 | /** |
||
| 4947 | * create a fallback for array |
||
| 4948 | * |
||
| 4949 | * 1. use the current array, if it's a array |
||
| 4950 | * 2. fallback to empty array, if there is nothing |
||
| 4951 | * 3. call "getArray()" on object, if there is a "Arrayy"-object |
||
| 4952 | * 4. call "createFromObject()" on object, if there is a "\Traversable"-object |
||
| 4953 | * 5. call "__toArray()" on object, if the method exists |
||
| 4954 | * 6. cast a string or object with "__toString()" into an array |
||
| 4955 | * 7. throw a "InvalidArgumentException"-Exception |
||
| 4956 | * |
||
| 4957 | * @param mixed $data |
||
| 4958 | * |
||
| 4959 | * @throws \InvalidArgumentException |
||
| 4960 | * |
||
| 4961 | * @return array |
||
| 4962 | */ |
||
| 4963 | 1053 | protected function fallbackForArray(&$data): array |
|
| 4973 | |||
| 4974 | /** |
||
| 4975 | * @return bool |
||
| 4976 | * |
||
| 4977 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
| 4978 | */ |
||
| 4979 | 970 | protected function generatorToArray() |
|
| 4990 | |||
| 4991 | /** |
||
| 4992 | * Get correct PHP constant for direction. |
||
| 4993 | * |
||
| 4994 | * @param int|string $direction |
||
| 4995 | * |
||
| 4996 | * @return int |
||
| 4997 | */ |
||
| 4998 | 39 | protected function getDirection($direction): int |
|
| 5020 | |||
| 5021 | /** |
||
| 5022 | * @return TypeCheckPhpDoc[] |
||
| 5023 | * |
||
| 5024 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
| 5025 | */ |
||
| 5026 | 16 | protected function getPropertiesFromPhpDoc() |
|
| 5051 | |||
| 5052 | /** |
||
| 5053 | * @param mixed $glue |
||
| 5054 | * @param mixed $pieces |
||
| 5055 | * @param bool $useKeys |
||
| 5056 | * |
||
| 5057 | * @return string |
||
| 5058 | */ |
||
| 5059 | 36 | protected function implode_recursive($glue = '', $pieces = [], bool $useKeys = false): string |
|
| 5089 | |||
| 5090 | /** |
||
| 5091 | * @param mixed $needle <p> |
||
| 5092 | * The searched value. |
||
| 5093 | * </p> |
||
| 5094 | * <p> |
||
| 5095 | * If needle is a string, the comparison is done |
||
| 5096 | * in a case-sensitive manner. |
||
| 5097 | * </p> |
||
| 5098 | * @param array|\Generator|null $haystack <p> |
||
| 5099 | * The array. |
||
| 5100 | * </p> |
||
| 5101 | * @param bool $strict [optional] <p> |
||
| 5102 | * If the third parameter strict is set to true |
||
| 5103 | * then the in_array function will also check the |
||
| 5104 | * types of the |
||
| 5105 | * needle in the haystack. |
||
| 5106 | * </p> |
||
| 5107 | * |
||
| 5108 | * @return bool |
||
| 5109 | * <p>true if needle is found in the array, false otherwise</p> |
||
| 5110 | */ |
||
| 5111 | 18 | protected function in_array_recursive($needle, $haystack = null, $strict = true): bool |
|
| 5136 | |||
| 5137 | /** |
||
| 5138 | * @param mixed $data |
||
| 5139 | * |
||
| 5140 | * @return array|null |
||
| 5141 | */ |
||
| 5142 | 1053 | protected function internalGetArray(&$data) |
|
| 5190 | |||
| 5191 | /** |
||
| 5192 | * Internal mechanics of remove method. |
||
| 5193 | * |
||
| 5194 | * @param mixed $key |
||
| 5195 | * |
||
| 5196 | * @return bool |
||
| 5197 | */ |
||
| 5198 | 18 | protected function internalRemove($key): bool |
|
| 5231 | |||
| 5232 | /** |
||
| 5233 | * Internal mechanic of set method. |
||
| 5234 | * |
||
| 5235 | * @param int|string|null $key |
||
| 5236 | * @param mixed $value |
||
| 5237 | * @param bool $checkProperties |
||
| 5238 | * |
||
| 5239 | * @return bool |
||
| 5240 | */ |
||
| 5241 | 927 | protected function internalSet( |
|
| 5287 | |||
| 5288 | /** |
||
| 5289 | * Convert a object into an array. |
||
| 5290 | * |
||
| 5291 | * @param object $object |
||
| 5292 | * |
||
| 5293 | * @return mixed |
||
| 5294 | */ |
||
| 5295 | 5 | protected static function objectToArray($object) |
|
| 5307 | |||
| 5308 | /** |
||
| 5309 | * @param array $data |
||
| 5310 | * @param bool $checkPropertiesInConstructor |
||
| 5311 | * |
||
| 5312 | * @return void |
||
| 5313 | */ |
||
| 5314 | 1051 | protected function setInitialValuesAndProperties(array &$data, bool $checkPropertiesInConstructor) |
|
| 5356 | |||
| 5357 | /** |
||
| 5358 | * sorting keys |
||
| 5359 | * |
||
| 5360 | * @param array $elements |
||
| 5361 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 5362 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 5363 | * <strong>SORT_NATURAL</strong></p> |
||
| 5364 | * |
||
| 5365 | * @return static |
||
| 5366 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 5367 | */ |
||
| 5368 | 18 | protected function sorterKeys(array &$elements, $direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
| 5386 | |||
| 5387 | /** |
||
| 5388 | * @param array $elements <p>Warning: used as reference</p> |
||
| 5389 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 5390 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 5391 | * <strong>SORT_NATURAL</strong></p> |
||
| 5392 | * @param bool $keepKeys |
||
| 5393 | * |
||
| 5394 | * @return static |
||
| 5395 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 5396 | */ |
||
| 5397 | 20 | protected function sorting(array &$elements, $direction = \SORT_ASC, int $strategy = \SORT_REGULAR, bool $keepKeys = false): self |
|
| 5427 | |||
| 5428 | /** |
||
| 5429 | * Extracts the value of the given property or method from the object. |
||
| 5430 | * |
||
| 5431 | * @param \Arrayy\Arrayy $object <p>The object to extract the value from.</p> |
||
| 5432 | * @param string $keyOrPropertyOrMethod <p>The property or method for which the |
||
| 5433 | * value should be extracted.</p> |
||
| 5434 | * |
||
| 5435 | * @throws \InvalidArgumentException if the method or property is not defined |
||
| 5436 | * |
||
| 5437 | * @return mixed |
||
| 5438 | * <p>The value extracted from the specified property or method.</p> |
||
| 5439 | */ |
||
| 5440 | 2 | final protected function extractValue(Arrayy $object, string $keyOrPropertyOrMethod) |
|
| 5462 | |||
| 5463 | /** |
||
| 5464 | * @param int|string|null $key |
||
| 5465 | * @param mixed $value |
||
| 5466 | * |
||
| 5467 | * @return void |
||
| 5468 | */ |
||
| 5469 | 84 | private function checkType($key, $value) |
|
| 5487 | } |
||
| 5488 |
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.