Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Arrayy often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Arrayy, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 24 | class Arrayy extends \ArrayObject implements \IteratorAggregate, \ArrayAccess, \Serializable, \JsonSerializable, \Countable |
||
| 25 | { |
||
| 26 | const ARRAYY_HELPER_TYPES_FOR_ALL_PROPERTIES = '!!!!Arrayy_Helper_Types_For_All_Properties!!!!'; |
||
| 27 | |||
| 28 | const ARRAYY_HELPER_WALK = '!!!!Arrayy_Helper_Walk!!!!'; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var array |
||
| 32 | * |
||
| 33 | * @phpstan-var array<int|string|TKey,T> |
||
| 34 | */ |
||
| 35 | protected $array = []; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @var \Arrayy\ArrayyRewindableGenerator|null |
||
| 39 | * |
||
| 40 | * @phpstan-var \Arrayy\ArrayyRewindableGenerator<TKey,T>|null |
||
| 41 | */ |
||
| 42 | protected $generator; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var string |
||
| 46 | * |
||
| 47 | * @phpstan-var class-string<\Arrayy\ArrayyIterator> |
||
| 48 | */ |
||
| 49 | protected $iteratorClass = ArrayyIterator::class; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @var string |
||
| 53 | */ |
||
| 54 | protected $pathSeparator = '.'; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @var bool |
||
| 58 | */ |
||
| 59 | protected $checkPropertyTypes = false; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @var bool |
||
| 63 | */ |
||
| 64 | protected $checkForMissingPropertiesInConstructor = false; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @var bool |
||
| 68 | */ |
||
| 69 | protected $checkPropertiesMismatchInConstructor = false; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @var bool |
||
| 73 | */ |
||
| 74 | protected $checkPropertiesMismatch = true; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @var array<int|string,TypeCheckInterface>|mixed|TypeCheckArray<int|string,TypeCheckInterface>|TypeInterface |
||
| 78 | */ |
||
| 79 | protected $properties = []; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Initializes |
||
| 83 | * |
||
| 84 | * @param mixed $data <p> |
||
| 85 | * Should be an array or a generator, otherwise it will try |
||
| 86 | * to convert it into an array. |
||
| 87 | * </p> |
||
| 88 | * @param string $iteratorClass optional <p> |
||
| 89 | * You can overwrite the ArrayyIterator, but mostly you don't |
||
| 90 | * need this option. |
||
| 91 | * </p> |
||
| 92 | * @param bool $checkPropertiesInConstructor optional <p> |
||
| 93 | * You need to extend the "Arrayy"-class and you need to set |
||
| 94 | * the $checkPropertiesMismatchInConstructor class property |
||
| 95 | * to |
||
| 96 | * true, otherwise this option didn't not work anyway. |
||
| 97 | * </p> |
||
| 98 | * |
||
| 99 | * @phpstan-param class-string<\Arrayy\ArrayyIterator> $iteratorClass |
||
| 100 | */ |
||
| 101 | 1212 | public function __construct( |
|
| 102 | $data = [], |
||
| 103 | string $iteratorClass = ArrayyIterator::class, |
||
| 104 | bool $checkPropertiesInConstructor = true |
||
| 105 | ) { |
||
| 106 | 1212 | $data = $this->fallbackForArray($data); |
|
| 107 | |||
| 108 | // used only for serialize + unserialize, all other methods are overwritten |
||
| 109 | /** |
||
| 110 | * @psalm-suppress InvalidArgument - why? |
||
| 111 | */ |
||
| 112 | 1210 | parent::__construct([], 0, $iteratorClass); |
|
| 113 | |||
| 114 | 1210 | $this->setInitialValuesAndProperties($data, $checkPropertiesInConstructor); |
|
| 115 | |||
| 116 | 1202 | $this->setIteratorClass($iteratorClass); |
|
| 117 | 1202 | } |
|
| 118 | |||
| 119 | /** |
||
| 120 | * @return void |
||
| 121 | */ |
||
| 122 | 52 | public function __clone() |
|
| 123 | { |
||
| 124 | 52 | if (!\is_array($this->properties)) { |
|
| 125 | $this->properties = clone $this->properties; |
||
|
|
|||
| 126 | } |
||
| 127 | |||
| 128 | 52 | if ($this->generator !== null) { |
|
| 129 | $this->generator = clone $this->generator; |
||
| 130 | } |
||
| 131 | 52 | } |
|
| 132 | |||
| 133 | /** |
||
| 134 | * Call object as function. |
||
| 135 | * |
||
| 136 | * @param mixed $key |
||
| 137 | * |
||
| 138 | * @return mixed |
||
| 139 | */ |
||
| 140 | 1 | public function __invoke($key = null) |
|
| 141 | { |
||
| 142 | 1 | if ($key !== null) { |
|
| 143 | 1 | $this->generatorToArray(); |
|
| 144 | |||
| 145 | 1 | return $this->array[$key] ?? false; |
|
| 146 | } |
||
| 147 | |||
| 148 | return $this->toArray(); |
||
| 149 | } |
||
| 150 | |||
| 151 | /** |
||
| 152 | * Whether or not an element exists by key. |
||
| 153 | * |
||
| 154 | * @param mixed $key |
||
| 155 | * |
||
| 156 | * @return bool |
||
| 157 | * <p>True is the key/index exists, otherwise false.</p> |
||
| 158 | */ |
||
| 159 | public function __isset($key): bool |
||
| 160 | { |
||
| 161 | return $this->offsetExists($key); |
||
| 162 | } |
||
| 163 | |||
| 164 | /** |
||
| 165 | * Assigns a value to the specified element. |
||
| 166 | * |
||
| 167 | * @param mixed $key |
||
| 168 | * @param mixed $value |
||
| 169 | * |
||
| 170 | * @return void |
||
| 171 | */ |
||
| 172 | 3 | public function __set($key, $value) |
|
| 173 | { |
||
| 174 | 3 | $this->internalSet($key, $value); |
|
| 175 | 3 | } |
|
| 176 | |||
| 177 | /** |
||
| 178 | * magic to string |
||
| 179 | * |
||
| 180 | * @return string |
||
| 181 | */ |
||
| 182 | 15 | public function __toString(): string |
|
| 183 | { |
||
| 184 | 15 | return $this->toString(); |
|
| 185 | } |
||
| 186 | |||
| 187 | /** |
||
| 188 | * Unset element by key. |
||
| 189 | * |
||
| 190 | * @param mixed $key |
||
| 191 | */ |
||
| 192 | public function __unset($key) |
||
| 193 | { |
||
| 194 | $this->internalRemove($key); |
||
| 195 | } |
||
| 196 | |||
| 197 | /** |
||
| 198 | * Get a value by key. |
||
| 199 | * |
||
| 200 | * @param mixed $key |
||
| 201 | * |
||
| 202 | * @return mixed |
||
| 203 | * <p>Get a Value from the current array.</p> |
||
| 204 | */ |
||
| 205 | 133 | public function &__get($key) |
|
| 206 | { |
||
| 207 | 133 | $return = $this->get($key, null, null, true); |
|
| 208 | |||
| 209 | 133 | if (\is_array($return) === true) { |
|
| 210 | $return = static::create( |
||
| 211 | [], |
||
| 212 | $this->iteratorClass, |
||
| 213 | false |
||
| 214 | )->createByReference($return); |
||
| 215 | } |
||
| 216 | |||
| 217 | 133 | return $return; |
|
| 218 | } |
||
| 219 | |||
| 220 | /** |
||
| 221 | * Add new values (optional using dot-notation). |
||
| 222 | * |
||
| 223 | * @param mixed $value |
||
| 224 | * @param int|string|null $key |
||
| 225 | * |
||
| 226 | * @return static |
||
| 227 | * <p>(Immutable) Return this Arrayy object, with the appended values.</p> |
||
| 228 | * |
||
| 229 | * @phpstan-param T $value |
||
| 230 | * @phpstan-return static<TKey,T> |
||
| 231 | * |
||
| 232 | * @phpstan-param T $value |
||
| 233 | * @phpstan-param TKey $key |
||
| 234 | * @psalm-mutation-free |
||
| 235 | */ |
||
| 236 | 13 | public function add($value, $key = null) |
|
| 237 | { |
||
| 238 | 13 | if ($key !== null) { |
|
| 239 | 5 | $get = $this->get($key); |
|
| 240 | 5 | if ($get !== null) { |
|
| 241 | 1 | $value = \array_merge_recursive( |
|
| 242 | 1 | !$get instanceof self ? [$get] : $get->getArray(), |
|
| 243 | 1 | !\is_array($value) ? [$value] : $value |
|
| 244 | ); |
||
| 245 | } |
||
| 246 | |||
| 247 | 5 | $this->internalSet($key, $value); |
|
| 248 | |||
| 249 | 4 | return $this; |
|
| 250 | } |
||
| 251 | |||
| 252 | 8 | return $this->append($value); |
|
| 253 | } |
||
| 254 | |||
| 255 | /** |
||
| 256 | * Append a (key) + value to the current array. |
||
| 257 | * |
||
| 258 | * EXAMPLE: <code> |
||
| 259 | * a(['fòô' => 'bàř'])->append('foo'); // Arrayy['fòô' => 'bàř', 0 => 'foo'] |
||
| 260 | * </code> |
||
| 261 | * |
||
| 262 | * @param mixed $value |
||
| 263 | * @param mixed $key |
||
| 264 | * |
||
| 265 | * @return $this |
||
| 266 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
| 267 | * |
||
| 268 | * @phpstan-param T $value |
||
| 269 | * @phpstan-param TKey|null $key |
||
| 270 | * @phpstan-return static<TKey,T> |
||
| 271 | */ |
||
| 272 | 20 | public function append($value, $key = null): self |
|
| 273 | { |
||
| 274 | 20 | $this->generatorToArray(); |
|
| 275 | |||
| 276 | 20 | if ($this->properties !== []) { |
|
| 277 | 6 | $this->checkType($key, $value); |
|
| 278 | } |
||
| 279 | |||
| 280 | 19 | if ($key !== null) { |
|
| 281 | if ( |
||
| 282 | 2 | isset($this->array[$key]) |
|
| 283 | && |
||
| 284 | 2 | \is_array($this->array[$key]) |
|
| 285 | ) { |
||
| 286 | $this->array[$key][] = $value; |
||
| 287 | } else { |
||
| 288 | 2 | $this->array[$key] = $value; |
|
| 289 | } |
||
| 290 | } else { |
||
| 291 | 17 | $this->array[] = $value; |
|
| 292 | } |
||
| 293 | |||
| 294 | 19 | return $this; |
|
| 295 | } |
||
| 296 | |||
| 297 | /** |
||
| 298 | * Append a (key) + value to the current array. |
||
| 299 | * |
||
| 300 | * EXAMPLE: <code> |
||
| 301 | * a(['fòô' => 'bàř'])->appendImmutable('foo')->getArray(); // ['fòô' => 'bàř', 0 => 'foo'] |
||
| 302 | * </code> |
||
| 303 | * |
||
| 304 | * @param mixed $value |
||
| 305 | * @param mixed $key |
||
| 306 | * |
||
| 307 | * @return $this |
||
| 308 | * <p>(Immutable) Return this Arrayy object, with the appended values.</p> |
||
| 309 | * |
||
| 310 | * @phpstan-param T $value |
||
| 311 | * @phpstan-param TKey $key |
||
| 312 | * @phpstan-return static<TKey,T> |
||
| 313 | * @psalm-mutation-free |
||
| 314 | */ |
||
| 315 | 1 | View Code Duplication | public function appendImmutable($value, $key = null): self |
| 316 | { |
||
| 317 | $generator = function () use ($key, $value): \Generator { |
||
| 318 | 1 | if ($this->properties !== []) { |
|
| 319 | $this->checkType($key, $value); |
||
| 320 | } |
||
| 321 | |||
| 322 | /** @noinspection YieldFromCanBeUsedInspection - FP */ |
||
| 323 | 1 | foreach ($this->getGenerator() as $keyOld => $itemOld) { |
|
| 324 | 1 | yield $keyOld => $itemOld; |
|
| 325 | } |
||
| 326 | |||
| 327 | 1 | if ($key !== null) { |
|
| 328 | yield $key => $value; |
||
| 329 | } else { |
||
| 330 | 1 | yield $value; |
|
| 331 | } |
||
| 332 | 1 | }; |
|
| 333 | |||
| 334 | 1 | return static::create( |
|
| 335 | 1 | $generator, |
|
| 336 | 1 | $this->iteratorClass, |
|
| 337 | 1 | false |
|
| 338 | ); |
||
| 339 | } |
||
| 340 | |||
| 341 | /** |
||
| 342 | * Sort the entries by value. |
||
| 343 | * |
||
| 344 | * @param int $sort_flags [optional] <p> |
||
| 345 | * You may modify the behavior of the sort using the optional |
||
| 346 | * parameter sort_flags, for details |
||
| 347 | * see sort. |
||
| 348 | * </p> |
||
| 349 | * |
||
| 350 | * @return $this |
||
| 351 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 352 | * |
||
| 353 | * @phpstan-return static<TKey,T> |
||
| 354 | */ |
||
| 355 | 4 | public function asort(int $sort_flags = 0): self |
|
| 356 | { |
||
| 357 | 4 | $this->generatorToArray(); |
|
| 358 | |||
| 359 | 4 | \asort($this->array, $sort_flags); |
|
| 360 | |||
| 361 | 4 | return $this; |
|
| 362 | } |
||
| 363 | |||
| 364 | /** |
||
| 365 | * Sort the entries by value. |
||
| 366 | * |
||
| 367 | * @param int $sort_flags [optional] <p> |
||
| 368 | * You may modify the behavior of the sort using the optional |
||
| 369 | * parameter sort_flags, for details |
||
| 370 | * see sort. |
||
| 371 | * </p> |
||
| 372 | * |
||
| 373 | * @return $this |
||
| 374 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 375 | * |
||
| 376 | * @phpstan-return static<TKey,T> |
||
| 377 | * @psalm-mutation-free |
||
| 378 | */ |
||
| 379 | 4 | public function asortImmutable(int $sort_flags = 0): self |
|
| 380 | { |
||
| 381 | 4 | $that = clone $this; |
|
| 382 | |||
| 383 | /** |
||
| 384 | * @psalm-suppress ImpureMethodCall - object is already cloned |
||
| 385 | */ |
||
| 386 | 4 | $that->asort($sort_flags); |
|
| 387 | |||
| 388 | 4 | return $that; |
|
| 389 | } |
||
| 390 | |||
| 391 | /** |
||
| 392 | * Counts all elements in an array, or something in an object. |
||
| 393 | * |
||
| 394 | * EXAMPLE: <code> |
||
| 395 | * a([-9, -8, -7, 1.32])->count(); // 4 |
||
| 396 | * </code> |
||
| 397 | * |
||
| 398 | * <p> |
||
| 399 | * For objects, if you have SPL installed, you can hook into count() by implementing interface {@see Countable}. |
||
| 400 | * The interface has exactly one method, {@see Countable::count()}, which returns the return value for the count() |
||
| 401 | * function. Please see the {@see Array} section of the manual for a detailed explanation of how arrays are |
||
| 402 | * implemented and used in PHP. |
||
| 403 | * </p> |
||
| 404 | * |
||
| 405 | * @see http://php.net/manual/en/function.count.php |
||
| 406 | * |
||
| 407 | * @param int $mode [optional] If the optional mode parameter is set to |
||
| 408 | * COUNT_RECURSIVE (or 1), count |
||
| 409 | * will recursively count the array. This is particularly useful for |
||
| 410 | * counting all the elements of a multidimensional array. count does not detect infinite recursion. |
||
| 411 | * |
||
| 412 | * @return int |
||
| 413 | * <p> |
||
| 414 | * The number of elements in var, which is |
||
| 415 | * typically an array, since anything else will have one |
||
| 416 | * element. |
||
| 417 | * </p> |
||
| 418 | * <p> |
||
| 419 | * If var is not an array or an object with |
||
| 420 | * implemented Countable interface, |
||
| 421 | * 1 will be returned. |
||
| 422 | * There is one exception, if var is &null;, |
||
| 423 | * 0 will be returned. |
||
| 424 | * </p> |
||
| 425 | * <p> |
||
| 426 | * Caution: count may return 0 for a variable that isn't set, |
||
| 427 | * but it may also return 0 for a variable that has been initialized with an |
||
| 428 | * empty array. Use isset to test if a variable is set. |
||
| 429 | * </p> |
||
| 430 | * @psalm-mutation-free |
||
| 431 | */ |
||
| 432 | 147 | public function count(int $mode = \COUNT_NORMAL): int |
|
| 433 | { |
||
| 434 | if ( |
||
| 435 | 147 | $this->generator |
|
| 436 | && |
||
| 437 | 147 | $mode === \COUNT_NORMAL |
|
| 438 | ) { |
||
| 439 | 4 | return \iterator_count($this->generator); |
|
| 440 | } |
||
| 441 | |||
| 442 | 143 | return \count($this->toArray(), $mode); |
|
| 443 | } |
||
| 444 | |||
| 445 | /** |
||
| 446 | * Exchange the array for another one. |
||
| 447 | * |
||
| 448 | * @param array|mixed|static $data |
||
| 449 | * |
||
| 450 | * 1. use the current array, if it's a array |
||
| 451 | * 2. fallback to empty array, if there is nothing |
||
| 452 | * 3. call "getArray()" on object, if there is a "Arrayy"-object |
||
| 453 | * 4. call "createFromObject()" on object, if there is a "\Traversable"-object |
||
| 454 | * 5. call "__toArray()" on object, if the method exists |
||
| 455 | * 6. cast a string or object with "__toString()" into an array |
||
| 456 | * 7. throw a "InvalidArgumentException"-Exception |
||
| 457 | * |
||
| 458 | * @return array |
||
| 459 | * |
||
| 460 | * @phpstan-param T|array<TKey,T>|self<TKey,T> $data |
||
| 461 | * @phpstan-return array<TKey,T> |
||
| 462 | */ |
||
| 463 | 1 | public function exchangeArray($data): array |
|
| 464 | { |
||
| 465 | /** @phpstan-var array<TKey,T> array */ |
||
| 466 | 1 | $array = $this->fallbackForArray($data); |
|
| 467 | |||
| 468 | 1 | $this->array = $array; |
|
| 469 | 1 | $this->generator = null; |
|
| 470 | |||
| 471 | 1 | return $this->array; |
|
| 472 | } |
||
| 473 | |||
| 474 | /** |
||
| 475 | * Creates a copy of the ArrayyObject. |
||
| 476 | * |
||
| 477 | * @return array |
||
| 478 | * |
||
| 479 | * @phpstan-return array<int|string|TKey,T> |
||
| 480 | */ |
||
| 481 | 6 | public function getArrayCopy(): array |
|
| 487 | |||
| 488 | /** |
||
| 489 | * Returns a new iterator, thus implementing the \Iterator interface. |
||
| 490 | * |
||
| 491 | * EXAMPLE: <code> |
||
| 492 | * a(['foo', 'bar'])->getIterator(); // ArrayyIterator['foo', 'bar'] |
||
| 493 | * </code> |
||
| 494 | * |
||
| 495 | * @return \Iterator<mixed, mixed> |
||
| 496 | * <p>An iterator for the values in the array.</p> |
||
| 497 | * @phpstan-return \Iterator<array-key|TKey, mixed|T> |
||
| 498 | */ |
||
| 499 | 28 | public function getIterator(): \Iterator |
|
| 525 | |||
| 526 | /** |
||
| 527 | * Gets the iterator classname for the ArrayObject. |
||
| 528 | * |
||
| 529 | * @return string |
||
| 530 | * |
||
| 531 | * @phpstan-return class-string |
||
| 532 | */ |
||
| 533 | 27 | public function getIteratorClass(): string |
|
| 537 | |||
| 538 | /** |
||
| 539 | * Sort the entries by key. |
||
| 540 | * |
||
| 541 | * @param int $sort_flags [optional] <p> |
||
| 542 | * You may modify the behavior of the sort using the optional |
||
| 543 | * parameter sort_flags, for details |
||
| 544 | * see sort. |
||
| 545 | * </p> |
||
| 546 | * |
||
| 547 | * @return $this |
||
| 548 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 549 | * |
||
| 550 | * @phpstan-return static<TKey,T> |
||
| 551 | */ |
||
| 552 | 4 | public function ksort(int $sort_flags = 0): self |
|
| 560 | |||
| 561 | /** |
||
| 562 | * Sort the entries by key. |
||
| 563 | * |
||
| 564 | * @param int $sort_flags [optional] <p> |
||
| 565 | * You may modify the behavior of the sort using the optional |
||
| 566 | * parameter sort_flags, for details |
||
| 567 | * see sort. |
||
| 568 | * </p> |
||
| 569 | * |
||
| 570 | * @return $this |
||
| 571 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 572 | * |
||
| 573 | * @phpstan-return static<TKey,T> |
||
| 574 | */ |
||
| 575 | 4 | public function ksortImmutable(int $sort_flags = 0): self |
|
| 586 | |||
| 587 | /** |
||
| 588 | * Sort an array using a case insensitive "natural order" algorithm. |
||
| 589 | * |
||
| 590 | * @return $this |
||
| 591 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 592 | * |
||
| 593 | * @phpstan-return static<TKey,T> |
||
| 594 | */ |
||
| 595 | 8 | public function natcasesort(): self |
|
| 603 | |||
| 604 | /** |
||
| 605 | * Sort an array using a case insensitive "natural order" algorithm. |
||
| 606 | * |
||
| 607 | * @return $this |
||
| 608 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 609 | * |
||
| 610 | * @phpstan-return static<TKey,T> |
||
| 611 | * @psalm-mutation-free |
||
| 612 | */ |
||
| 613 | 4 | public function natcasesortImmutable(): self |
|
| 624 | |||
| 625 | /** |
||
| 626 | * Sort entries using a "natural order" algorithm. |
||
| 627 | * |
||
| 628 | * @return $this |
||
| 629 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 630 | * |
||
| 631 | * @phpstan-return static<TKey,T> |
||
| 632 | */ |
||
| 633 | 10 | public function natsort(): self |
|
| 641 | |||
| 642 | /** |
||
| 643 | * Sort entries using a "natural order" algorithm. |
||
| 644 | * |
||
| 645 | * @return $this |
||
| 646 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 647 | * |
||
| 648 | * @phpstan-return static<TKey,T> |
||
| 649 | * @psalm-mutation-free |
||
| 650 | */ |
||
| 651 | 4 | public function natsortImmutable(): self |
|
| 662 | |||
| 663 | /** |
||
| 664 | * Whether or not an offset exists. |
||
| 665 | * |
||
| 666 | * @param bool|int|string $offset |
||
| 667 | * |
||
| 668 | * @return bool |
||
| 669 | * |
||
| 670 | * @psalm-mutation-free |
||
| 671 | */ |
||
| 672 | 164 | public function offsetExists($offset): bool |
|
| 673 | { |
||
| 674 | // php cast "bool"-index into "int"-index |
||
| 675 | 164 | if ((bool) $offset === $offset) { |
|
| 676 | 1 | $offset = (int) $offset; |
|
| 677 | } |
||
| 678 | 164 | \assert(\is_int($offset) || \is_string($offset)); |
|
| 679 | |||
| 680 | 164 | $offsetExists = $this->keyExists($offset); |
|
| 681 | 164 | if ($offsetExists === true) { |
|
| 682 | 143 | return true; |
|
| 683 | } |
||
| 684 | |||
| 685 | /** |
||
| 686 | * https://github.com/vimeo/psalm/issues/2536 |
||
| 687 | * |
||
| 688 | * @psalm-suppress PossiblyInvalidArgument |
||
| 689 | * @psalm-suppress InvalidScalarArgument |
||
| 690 | */ |
||
| 691 | View Code Duplication | if ( |
|
| 692 | 124 | $this->pathSeparator |
|
| 693 | && |
||
| 694 | 124 | (string) $offset === $offset |
|
| 695 | && |
||
| 696 | 124 | \strpos($offset, $this->pathSeparator) !== false |
|
| 697 | ) { |
||
| 698 | 4 | $explodedPath = \explode($this->pathSeparator, (string) $offset); |
|
| 699 | 4 | if ($explodedPath !== false) { |
|
| 700 | /** @var string $lastOffset - helper for phpstan */ |
||
| 701 | 4 | $lastOffset = \array_pop($explodedPath); |
|
| 702 | 4 | $containerPath = \implode($this->pathSeparator, $explodedPath); |
|
| 703 | |||
| 704 | /** |
||
| 705 | * @psalm-suppress MissingClosureReturnType |
||
| 706 | * @psalm-suppress MissingClosureParamType |
||
| 707 | */ |
||
| 708 | 4 | $this->callAtPath( |
|
| 709 | 4 | $containerPath, |
|
| 710 | static function ($container) use ($lastOffset, &$offsetExists) { |
||
| 711 | 4 | $offsetExists = \array_key_exists($lastOffset, $container); |
|
| 712 | 4 | } |
|
| 713 | ); |
||
| 714 | } |
||
| 715 | } |
||
| 716 | |||
| 717 | 124 | return $offsetExists; |
|
| 718 | } |
||
| 719 | |||
| 720 | /** |
||
| 721 | * Returns the value at specified offset. |
||
| 722 | * |
||
| 723 | * @param int|string $offset |
||
| 724 | * |
||
| 725 | * @return mixed |
||
| 726 | * <p>Will return null if the offset did not exists.</p> |
||
| 727 | */ |
||
| 728 | 133 | public function &offsetGet($offset) |
|
| 729 | { |
||
| 730 | // init |
||
| 731 | 133 | $value = null; |
|
| 732 | |||
| 733 | 133 | if ($this->offsetExists($offset)) { |
|
| 734 | 131 | $value = &$this->__get($offset); |
|
| 735 | } |
||
| 736 | |||
| 737 | 133 | return $value; |
|
| 738 | } |
||
| 739 | |||
| 740 | /** |
||
| 741 | * Assigns a value to the specified offset + check the type. |
||
| 742 | * |
||
| 743 | * @param int|string|null $offset |
||
| 744 | * @param mixed $value |
||
| 745 | * |
||
| 746 | * @return void |
||
| 747 | */ |
||
| 748 | 28 | public function offsetSet($offset, $value) |
|
| 749 | { |
||
| 750 | 28 | $this->generatorToArray(); |
|
| 751 | |||
| 752 | 28 | if ($offset === null) { |
|
| 753 | 7 | if ($this->properties !== []) { |
|
| 754 | 2 | $this->checkType(null, $value); |
|
| 755 | } |
||
| 756 | |||
| 757 | 6 | $this->array[] = $value; |
|
| 758 | } else { |
||
| 759 | 21 | $this->internalSet( |
|
| 760 | 21 | $offset, |
|
| 761 | 21 | $value, |
|
| 762 | 21 | true |
|
| 763 | ); |
||
| 764 | } |
||
| 765 | 27 | } |
|
| 766 | |||
| 767 | /** |
||
| 768 | * Unset an offset. |
||
| 769 | * |
||
| 770 | * @param int|string $offset |
||
| 771 | * |
||
| 772 | * @return void |
||
| 773 | * <p>(Mutable) Return nothing.</p> |
||
| 774 | */ |
||
| 775 | 26 | public function offsetUnset($offset) |
|
| 776 | { |
||
| 777 | 26 | $this->generatorToArray(); |
|
| 778 | |||
| 779 | 26 | if ($this->array === []) { |
|
| 780 | 6 | return; |
|
| 781 | } |
||
| 782 | |||
| 783 | 21 | if ($this->keyExists($offset)) { |
|
| 784 | 14 | unset($this->array[$offset]); |
|
| 785 | |||
| 786 | 14 | return; |
|
| 787 | } |
||
| 788 | |||
| 789 | /** |
||
| 790 | * https://github.com/vimeo/psalm/issues/2536 |
||
| 791 | * |
||
| 792 | * @psalm-suppress PossiblyInvalidArgument |
||
| 793 | * @psalm-suppress InvalidScalarArgument |
||
| 794 | */ |
||
| 795 | View Code Duplication | if ( |
|
| 796 | 10 | $this->pathSeparator |
|
| 797 | && |
||
| 798 | 10 | (string) $offset === $offset |
|
| 799 | && |
||
| 800 | 10 | \strpos($offset, $this->pathSeparator) !== false |
|
| 801 | ) { |
||
| 802 | 7 | $path = \explode($this->pathSeparator, (string) $offset); |
|
| 803 | |||
| 804 | 7 | if ($path !== false) { |
|
| 805 | 7 | $pathToUnset = \array_pop($path); |
|
| 806 | |||
| 807 | /** |
||
| 808 | * @psalm-suppress MissingClosureReturnType |
||
| 809 | * @psalm-suppress MissingClosureParamType |
||
| 810 | */ |
||
| 811 | 7 | $this->callAtPath( |
|
| 812 | 7 | \implode($this->pathSeparator, $path), |
|
| 813 | static function (&$offset) use ($pathToUnset) { |
||
| 814 | 6 | if (\is_array($offset)) { |
|
| 815 | 5 | unset($offset[$pathToUnset]); |
|
| 816 | } else { |
||
| 817 | 1 | $offset = null; |
|
| 818 | } |
||
| 819 | 7 | } |
|
| 820 | ); |
||
| 821 | } |
||
| 822 | } |
||
| 823 | |||
| 824 | 10 | unset($this->array[$offset]); |
|
| 825 | 10 | } |
|
| 826 | |||
| 827 | /** |
||
| 828 | * Serialize the current "Arrayy"-object. |
||
| 829 | * |
||
| 830 | * EXAMPLE: <code> |
||
| 831 | * a([1, 4, 7])->serialize(); |
||
| 832 | * </code> |
||
| 833 | * |
||
| 834 | * @return string |
||
| 835 | */ |
||
| 836 | 2 | public function serialize(): string |
|
| 837 | { |
||
| 838 | 2 | $this->generatorToArray(); |
|
| 839 | |||
| 840 | 2 | if (\PHP_VERSION_ID < 70400) { |
|
| 841 | 2 | return parent::serialize(); |
|
| 842 | } |
||
| 843 | |||
| 844 | return \serialize($this); |
||
| 845 | } |
||
| 846 | |||
| 847 | /** |
||
| 848 | * Sets the iterator classname for the current "Arrayy"-object. |
||
| 849 | * |
||
| 850 | * @param string $iteratorClass |
||
| 851 | * |
||
| 852 | * @throws \InvalidArgumentException |
||
| 853 | * |
||
| 854 | * @return void |
||
| 855 | * |
||
| 856 | * @phpstan-param class-string<\Arrayy\ArrayyIterator> $iteratorClass |
||
| 857 | */ |
||
| 858 | 1202 | public function setIteratorClass($iteratorClass) |
|
| 859 | { |
||
| 860 | 1202 | if (\class_exists($iteratorClass)) { |
|
| 861 | 1202 | $this->iteratorClass = $iteratorClass; |
|
| 862 | |||
| 863 | 1202 | return; |
|
| 864 | } |
||
| 865 | |||
| 866 | if (\strpos($iteratorClass, '\\') === 0) { |
||
| 867 | /** @var class-string<\Arrayy\ArrayyIterator<TKey,T>> $iteratorClass */ |
||
| 868 | $iteratorClass = '\\' . $iteratorClass; |
||
| 869 | if (\class_exists($iteratorClass)) { |
||
| 870 | /** |
||
| 871 | * @psalm-suppress PropertyTypeCoercion |
||
| 872 | */ |
||
| 873 | $this->iteratorClass = $iteratorClass; |
||
| 874 | |||
| 875 | return; |
||
| 876 | } |
||
| 877 | } |
||
| 878 | |||
| 879 | throw new \InvalidArgumentException('The iterator class does not exist: ' . $iteratorClass); |
||
| 880 | } |
||
| 881 | |||
| 882 | /** |
||
| 883 | * Sort the entries with a user-defined comparison function and maintain key association. |
||
| 884 | * |
||
| 885 | * @param callable $function |
||
| 886 | * |
||
| 887 | * @throws \InvalidArgumentException |
||
| 888 | * |
||
| 889 | * @return $this |
||
| 890 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 891 | * |
||
| 892 | * @phpstan-return static<TKey,T> |
||
| 893 | */ |
||
| 894 | 8 | public function uasort($function): self |
|
| 895 | { |
||
| 896 | 8 | if (!\is_callable($function)) { |
|
| 897 | throw new \InvalidArgumentException('Passed function must be callable'); |
||
| 898 | } |
||
| 899 | |||
| 900 | 8 | $this->generatorToArray(); |
|
| 901 | |||
| 902 | 8 | \uasort($this->array, $function); |
|
| 903 | |||
| 904 | 8 | return $this; |
|
| 905 | } |
||
| 906 | |||
| 907 | /** |
||
| 908 | * Sort the entries with a user-defined comparison function and maintain key association. |
||
| 909 | * |
||
| 910 | * @param callable $function |
||
| 911 | * |
||
| 912 | * @throws \InvalidArgumentException |
||
| 913 | * |
||
| 914 | * @return $this |
||
| 915 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 916 | * |
||
| 917 | * @phpstan-return static<TKey,T> |
||
| 918 | * @psalm-mutation-free |
||
| 919 | */ |
||
| 920 | 4 | public function uasortImmutable($function): self |
|
| 921 | { |
||
| 922 | 4 | $that = clone $this; |
|
| 923 | |||
| 924 | /** |
||
| 925 | * @psalm-suppress ImpureMethodCall - object is already cloned |
||
| 926 | */ |
||
| 927 | 4 | $that->uasort($function); |
|
| 928 | |||
| 929 | 4 | return $that; |
|
| 930 | } |
||
| 931 | |||
| 932 | /** |
||
| 933 | * Sort the entries by keys using a user-defined comparison function. |
||
| 934 | * |
||
| 935 | * @param callable $function |
||
| 936 | * |
||
| 937 | * @throws \InvalidArgumentException |
||
| 938 | * |
||
| 939 | * @return static |
||
| 940 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 941 | * |
||
| 942 | * @phpstan-return static<TKey,T> |
||
| 943 | */ |
||
| 944 | 5 | public function uksort($function): self |
|
| 945 | { |
||
| 946 | 5 | return $this->customSortKeys($function); |
|
| 947 | } |
||
| 948 | |||
| 949 | /** |
||
| 950 | * Sort the entries by keys using a user-defined comparison function. |
||
| 951 | * |
||
| 952 | * @param callable $function |
||
| 953 | * |
||
| 954 | * @throws \InvalidArgumentException |
||
| 955 | * |
||
| 956 | * @return static |
||
| 957 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 958 | * |
||
| 959 | * @phpstan-return static<TKey,T> |
||
| 960 | * @psalm-mutation-free |
||
| 961 | */ |
||
| 962 | 1 | public function uksortImmutable($function): self |
|
| 963 | { |
||
| 964 | 1 | return $this->customSortKeysImmutable($function); |
|
| 965 | } |
||
| 966 | |||
| 967 | /** |
||
| 968 | * Unserialize an string and return the instance of the "Arrayy"-class. |
||
| 969 | * |
||
| 970 | * EXAMPLE: <code> |
||
| 971 | * $serialized = a([1, 4, 7])->serialize(); |
||
| 972 | * a()->unserialize($serialized); |
||
| 973 | * </code> |
||
| 974 | * |
||
| 975 | * @param string $string |
||
| 976 | * |
||
| 977 | * @return $this |
||
| 978 | * |
||
| 979 | * @phpstan-return static<TKey,T> |
||
| 980 | */ |
||
| 981 | 2 | public function unserialize($string): self |
|
| 982 | { |
||
| 983 | 2 | if (\PHP_VERSION_ID < 70400) { |
|
| 984 | 2 | parent::unserialize($string); |
|
| 985 | |||
| 986 | 2 | return $this; |
|
| 987 | } |
||
| 988 | |||
| 989 | return \unserialize($string, ['allowed_classes' => [__CLASS__, TypeCheckPhpDoc::class]]); |
||
| 990 | } |
||
| 991 | |||
| 992 | /** |
||
| 993 | * Append a (key) + values to the current array. |
||
| 994 | * |
||
| 995 | * EXAMPLE: <code> |
||
| 996 | * a(['fòô' => ['bàř']])->appendArrayValues(['foo1', 'foo2'], 'fòô'); // Arrayy['fòô' => ['bàř', 'foo1', 'foo2']] |
||
| 997 | * </code> |
||
| 998 | * |
||
| 999 | * @param array $values |
||
| 1000 | * @param mixed $key |
||
| 1001 | * |
||
| 1002 | * @return $this |
||
| 1003 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
| 1004 | * |
||
| 1005 | * @phpstan-param array<array-key,T> $values |
||
| 1006 | * @phpstan-param TKey|null $key |
||
| 1007 | * @phpstan-return static<TKey,T> |
||
| 1008 | */ |
||
| 1009 | 1 | public function appendArrayValues(array $values, $key = null) |
|
| 1010 | { |
||
| 1011 | 1 | $this->generatorToArray(); |
|
| 1012 | |||
| 1013 | 1 | if ($key !== null) { |
|
| 1014 | if ( |
||
| 1015 | 1 | isset($this->array[$key]) |
|
| 1016 | && |
||
| 1017 | 1 | \is_array($this->array[$key]) |
|
| 1018 | ) { |
||
| 1019 | 1 | foreach ($values as $value) { |
|
| 1020 | 1 | $this->array[$key][] = $value; |
|
| 1021 | } |
||
| 1022 | } else { |
||
| 1023 | foreach ($values as $value) { |
||
| 1024 | 1 | $this->array[$key] = $value; |
|
| 1025 | } |
||
| 1026 | } |
||
| 1027 | } else { |
||
| 1028 | foreach ($values as $value) { |
||
| 1029 | $this->array[] = $value; |
||
| 1030 | } |
||
| 1031 | } |
||
| 1032 | |||
| 1033 | 1 | return $this; |
|
| 1034 | } |
||
| 1035 | |||
| 1036 | /** |
||
| 1037 | * Add a suffix to each key. |
||
| 1038 | * |
||
| 1039 | * @param int|string $prefix |
||
| 1040 | * |
||
| 1041 | * @return static |
||
| 1042 | * <p>(Immutable) Return an Arrayy object, with the prefixed keys.</p> |
||
| 1043 | * |
||
| 1044 | * @phpstan-return static<TKey,T> |
||
| 1045 | * @psalm-mutation-free |
||
| 1046 | */ |
||
| 1047 | 10 | View Code Duplication | public function appendToEachKey($prefix): self |
| 1048 | { |
||
| 1049 | // init |
||
| 1050 | 10 | $result = []; |
|
| 1051 | |||
| 1052 | 10 | foreach ($this->getGenerator() as $key => $item) { |
|
| 1053 | 9 | if ($item instanceof self) { |
|
| 1054 | $result[$prefix . $key] = $item->appendToEachKey($prefix); |
||
| 1055 | 9 | } elseif (\is_array($item)) { |
|
| 1056 | $result[$prefix . $key] = self::create($item, $this->iteratorClass, false) |
||
| 1057 | ->appendToEachKey($prefix) |
||
| 1058 | ->toArray(); |
||
| 1059 | } else { |
||
| 1060 | 9 | $result[$prefix . $key] = $item; |
|
| 1061 | } |
||
| 1062 | } |
||
| 1063 | |||
| 1064 | 10 | return self::create( |
|
| 1065 | 10 | $result, |
|
| 1066 | 10 | $this->iteratorClass, |
|
| 1067 | 10 | false |
|
| 1068 | ); |
||
| 1069 | } |
||
| 1070 | |||
| 1071 | /** |
||
| 1072 | * Add a prefix to each value. |
||
| 1073 | * |
||
| 1074 | * @param float|int|string $prefix |
||
| 1075 | * |
||
| 1076 | * @return static |
||
| 1077 | * <p>(Immutable) Return an Arrayy object, with the prefixed values.</p> |
||
| 1078 | * |
||
| 1079 | * @phpstan-return static<TKey,T> |
||
| 1080 | * @psalm-mutation-free |
||
| 1081 | */ |
||
| 1082 | 10 | View Code Duplication | public function appendToEachValue($prefix): self |
| 1083 | { |
||
| 1084 | // init |
||
| 1085 | 10 | $result = []; |
|
| 1086 | |||
| 1087 | 10 | foreach ($this->getGenerator() as $key => $item) { |
|
| 1088 | 9 | if ($item instanceof self) { |
|
| 1089 | $result[$key] = $item->appendToEachValue($prefix); |
||
| 1090 | 9 | } elseif (\is_array($item)) { |
|
| 1091 | $result[$key] = self::create($item, $this->iteratorClass, false)->appendToEachValue($prefix)->toArray(); |
||
| 1092 | 9 | } elseif (\is_object($item) === true) { |
|
| 1093 | 1 | $result[$key] = $item; |
|
| 1094 | } else { |
||
| 1095 | 9 | $result[$key] = $prefix . $item; |
|
| 1096 | } |
||
| 1097 | } |
||
| 1098 | |||
| 1099 | 10 | return self::create($result, $this->iteratorClass, false); |
|
| 1100 | } |
||
| 1101 | |||
| 1102 | /** |
||
| 1103 | * Sort an array in reverse order and maintain index association. |
||
| 1104 | * |
||
| 1105 | * @return $this |
||
| 1106 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1107 | * |
||
| 1108 | * @phpstan-return static<TKey,T> |
||
| 1109 | */ |
||
| 1110 | 4 | public function arsort(): self |
|
| 1111 | { |
||
| 1112 | 4 | $this->generatorToArray(); |
|
| 1113 | |||
| 1114 | 4 | \arsort($this->array); |
|
| 1115 | |||
| 1116 | 4 | return $this; |
|
| 1117 | } |
||
| 1118 | |||
| 1119 | /** |
||
| 1120 | * Sort an array in reverse order and maintain index association. |
||
| 1121 | * |
||
| 1122 | * @return $this |
||
| 1123 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 1124 | * |
||
| 1125 | * @phpstan-return static<TKey,T> |
||
| 1126 | * @psalm-mutation-free |
||
| 1127 | */ |
||
| 1128 | 10 | public function arsortImmutable(): self |
|
| 1129 | { |
||
| 1130 | 10 | $that = clone $this; |
|
| 1131 | |||
| 1132 | 10 | $that->generatorToArray(); |
|
| 1133 | |||
| 1134 | 10 | \arsort($that->array); |
|
| 1135 | |||
| 1136 | 10 | return $that; |
|
| 1137 | } |
||
| 1138 | |||
| 1139 | /** |
||
| 1140 | * Iterate over the current array and execute a callback for each loop. |
||
| 1141 | * |
||
| 1142 | * EXAMPLE: <code> |
||
| 1143 | * $result = A::create(); |
||
| 1144 | * $closure = function ($value, $key) use ($result) { |
||
| 1145 | * $result[$key] = ':' . $value . ':'; |
||
| 1146 | * }; |
||
| 1147 | * a(['foo', 'bar' => 'bis'])->at($closure); // Arrayy[':foo:', 'bar' => ':bis:'] |
||
| 1148 | * </code> |
||
| 1149 | * |
||
| 1150 | * @param \Closure $closure |
||
| 1151 | * |
||
| 1152 | * @return static |
||
| 1153 | * <p>(Immutable)</p> |
||
| 1154 | * |
||
| 1155 | * @phpstan-param \Closure(T=,TKey=):mixed $closure <p>INFO: \Closure result is not used, but void is not supported in PHP 7.0</p> |
||
| 1156 | * @phpstan-return static<TKey,T> |
||
| 1157 | * @psalm-mutation-free |
||
| 1158 | */ |
||
| 1159 | 3 | public function at(\Closure $closure): self |
|
| 1173 | |||
| 1174 | /** |
||
| 1175 | * Returns the average value of the current array. |
||
| 1176 | * |
||
| 1177 | * EXAMPLE: <code> |
||
| 1178 | * a([-9, -8, -7, 1.32])->average(2); // -5.67 |
||
| 1179 | * </code> |
||
| 1180 | * |
||
| 1181 | * @param int $decimals <p>The number of decimal-numbers to return.</p> |
||
| 1182 | * |
||
| 1183 | * @return float|int |
||
| 1184 | * <p>The average value.</p> |
||
| 1185 | * @psalm-mutation-free |
||
| 1186 | */ |
||
| 1187 | 10 | public function average($decimals = 0) |
|
| 1201 | |||
| 1202 | /** |
||
| 1203 | * Changes all keys in an array. |
||
| 1204 | * |
||
| 1205 | * @param int $case [optional] <p> Either <strong>CASE_UPPER</strong><br /> |
||
| 1206 | * or <strong>CASE_LOWER</strong> (default)</p> |
||
| 1207 | * |
||
| 1208 | * @return static |
||
| 1209 | * <p>(Immutable)</p> |
||
| 1210 | * |
||
| 1211 | * @phpstan-return static<TKey,T> |
||
| 1212 | * @psalm-mutation-free |
||
| 1213 | */ |
||
| 1214 | 1 | public function changeKeyCase(int $case = \CASE_LOWER): self |
|
| 1243 | |||
| 1244 | /** |
||
| 1245 | * Change the path separator of the array wrapper. |
||
| 1246 | * |
||
| 1247 | * By default, the separator is: "." |
||
| 1248 | * |
||
| 1249 | * @param string $separator <p>Separator to set.</p> |
||
| 1250 | * |
||
| 1251 | * @return $this |
||
| 1252 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1253 | * |
||
| 1254 | * @phpstan-return static<TKey,T> |
||
| 1255 | */ |
||
| 1256 | 11 | public function changeSeparator($separator): self |
|
| 1262 | |||
| 1263 | /** |
||
| 1264 | * Create a chunked version of the current array. |
||
| 1265 | * |
||
| 1266 | * EXAMPLE: <code> |
||
| 1267 | * a([-9, -8, -7, 1.32])->chunk(2); // Arrayy[[-9, -8], [-7, 1.32]] |
||
| 1268 | * </code> |
||
| 1269 | * |
||
| 1270 | * @param int $size <p>Size of each chunk.</p> |
||
| 1271 | * @param bool $preserveKeys <p>Whether array keys are preserved or no.</p> |
||
| 1272 | * |
||
| 1273 | * @return static |
||
| 1274 | * <p>(Immutable) A new array of chunks from the original array.</p> |
||
| 1275 | * |
||
| 1276 | * @phpstan-return static<TKey,T> |
||
| 1277 | * @psalm-mutation-free |
||
| 1278 | */ |
||
| 1279 | 5 | public function chunk($size, $preserveKeys = false): self |
|
| 1329 | |||
| 1330 | /** |
||
| 1331 | * Clean all falsy values from the current array. |
||
| 1332 | * |
||
| 1333 | * EXAMPLE: <code> |
||
| 1334 | * a([-8 => -9, 1, 2 => false])->clean(); // Arrayy[-8 => -9, 1] |
||
| 1335 | * </code> |
||
| 1336 | * |
||
| 1337 | * @return static |
||
| 1338 | * <p>(Immutable)</p> |
||
| 1339 | * |
||
| 1340 | * @phpstan-return static<TKey,T> |
||
| 1341 | * @psalm-mutation-free |
||
| 1342 | */ |
||
| 1343 | 8 | public function clean(): self |
|
| 1351 | |||
| 1352 | /** |
||
| 1353 | * WARNING!!! -> Clear the current full array or a $key of it. |
||
| 1354 | * |
||
| 1355 | * EXAMPLE: <code> |
||
| 1356 | * a([-8 => -9, 1, 2 => false])->clear(); // Arrayy[] |
||
| 1357 | * </code> |
||
| 1358 | * |
||
| 1359 | * @param int|int[]|string|string[]|null $key |
||
| 1360 | * |
||
| 1361 | * @return $this |
||
| 1362 | * <p>(Mutable) Return this Arrayy object, with an empty array.</p> |
||
| 1363 | * |
||
| 1364 | * @phpstan-return static<TKey,T> |
||
| 1365 | */ |
||
| 1366 | 10 | public function clear($key = null): self |
|
| 1385 | |||
| 1386 | /** |
||
| 1387 | * Check if an item is in the current array. |
||
| 1388 | * |
||
| 1389 | * EXAMPLE: <code> |
||
| 1390 | * a([1, true])->contains(true); // true |
||
| 1391 | * </code> |
||
| 1392 | * |
||
| 1393 | * @param float|int|string $value |
||
| 1394 | * @param bool $recursive |
||
| 1395 | * @param bool $strict |
||
| 1396 | * |
||
| 1397 | * @return bool |
||
| 1398 | * @psalm-mutation-free |
||
| 1399 | */ |
||
| 1400 | 24 | public function contains($value, bool $recursive = false, bool $strict = true): bool |
|
| 1422 | |||
| 1423 | /** |
||
| 1424 | * Check if an (case-insensitive) string is in the current array. |
||
| 1425 | * |
||
| 1426 | * EXAMPLE: <code> |
||
| 1427 | * a(['E', 'é'])->containsCaseInsensitive('É'); // true |
||
| 1428 | * </code> |
||
| 1429 | * |
||
| 1430 | * @param mixed $value |
||
| 1431 | * @param bool $recursive |
||
| 1432 | * |
||
| 1433 | * @return bool |
||
| 1434 | * @psalm-mutation-free |
||
| 1435 | * |
||
| 1436 | * @psalm-suppress InvalidCast - hack for int|float|bool support |
||
| 1437 | */ |
||
| 1438 | 26 | public function containsCaseInsensitive($value, $recursive = false): bool |
|
| 1469 | |||
| 1470 | /** |
||
| 1471 | * Check if the given key/index exists in the array. |
||
| 1472 | * |
||
| 1473 | * EXAMPLE: <code> |
||
| 1474 | * a([1 => true])->containsKey(1); // true |
||
| 1475 | * </code> |
||
| 1476 | * |
||
| 1477 | * @param int|string $key <p>key/index to search for</p> |
||
| 1478 | * |
||
| 1479 | * @return bool |
||
| 1480 | * <p>Returns true if the given key/index exists in the array, false otherwise.</p> |
||
| 1481 | * |
||
| 1482 | * @psalm-mutation-free |
||
| 1483 | */ |
||
| 1484 | 4 | public function containsKey($key): bool |
|
| 1488 | |||
| 1489 | /** |
||
| 1490 | * Check if all given needles are present in the array as key/index. |
||
| 1491 | * |
||
| 1492 | * EXAMPLE: <code> |
||
| 1493 | * a([1 => true])->containsKeys(array(1 => 0)); // true |
||
| 1494 | * </code> |
||
| 1495 | * |
||
| 1496 | * @param array $needles <p>The keys you are searching for.</p> |
||
| 1497 | * @param bool $recursive |
||
| 1498 | * |
||
| 1499 | * @return bool |
||
| 1500 | * <p>Returns true if all the given keys/indexes exists in the array, false otherwise.</p> |
||
| 1501 | * |
||
| 1502 | * @phpstan-param array<array-key>|array<TKey> $needles |
||
| 1503 | * @psalm-mutation-free |
||
| 1504 | */ |
||
| 1505 | 2 | public function containsKeys(array $needles, $recursive = false): bool |
|
| 1533 | |||
| 1534 | /** |
||
| 1535 | * Check if all given needles are present in the array as key/index. |
||
| 1536 | * |
||
| 1537 | * @param array $needles <p>The keys you are searching for.</p> |
||
| 1538 | * |
||
| 1539 | * @return bool |
||
| 1540 | * <p>Returns true if all the given keys/indexes exists in the array, false otherwise.</p> |
||
| 1541 | * |
||
| 1542 | * @phpstan-param array<array-key>|array<TKey> $needles |
||
| 1543 | * @psalm-mutation-free |
||
| 1544 | */ |
||
| 1545 | 1 | public function containsKeysRecursive(array $needles): bool |
|
| 1549 | |||
| 1550 | /** |
||
| 1551 | * alias: for "Arrayy->contains()" |
||
| 1552 | * |
||
| 1553 | * @param float|int|string $value |
||
| 1554 | * |
||
| 1555 | * @return bool |
||
| 1556 | * |
||
| 1557 | * @see Arrayy::contains() |
||
| 1558 | * @psalm-mutation-free |
||
| 1559 | */ |
||
| 1560 | 9 | public function containsValue($value): bool |
|
| 1564 | |||
| 1565 | /** |
||
| 1566 | * alias: for "Arrayy->contains($value, true)" |
||
| 1567 | * |
||
| 1568 | * @param float|int|string $value |
||
| 1569 | * |
||
| 1570 | * @return bool |
||
| 1571 | * |
||
| 1572 | * @see Arrayy::contains() |
||
| 1573 | * @psalm-mutation-free |
||
| 1574 | */ |
||
| 1575 | 18 | public function containsValueRecursive($value): bool |
|
| 1579 | |||
| 1580 | /** |
||
| 1581 | * Check if all given needles are present in the array. |
||
| 1582 | * |
||
| 1583 | * EXAMPLE: <code> |
||
| 1584 | * a([1, true])->containsValues(array(1, true)); // true |
||
| 1585 | * </code> |
||
| 1586 | * |
||
| 1587 | * @param array $needles |
||
| 1588 | * |
||
| 1589 | * @return bool |
||
| 1590 | * <p>Returns true if all the given values exists in the array, false otherwise.</p> |
||
| 1591 | * |
||
| 1592 | * @phpstan-param array<mixed>|array<T> $needles |
||
| 1593 | * @psalm-mutation-free |
||
| 1594 | */ |
||
| 1595 | 1 | public function containsValues(array $needles): bool |
|
| 1610 | |||
| 1611 | /** |
||
| 1612 | * Counts all the values of an array |
||
| 1613 | * |
||
| 1614 | * @see http://php.net/manual/en/function.array-count-values.php |
||
| 1615 | * |
||
| 1616 | * @return static |
||
| 1617 | * <p> |
||
| 1618 | * (Immutable) |
||
| 1619 | * An associative Arrayy-object of values from input as |
||
| 1620 | * keys and their count as value. |
||
| 1621 | * </p> |
||
| 1622 | * |
||
| 1623 | * @phpstan-return static<TKey,T> |
||
| 1624 | * @psalm-mutation-free |
||
| 1625 | */ |
||
| 1626 | 7 | public function countValues(): self |
|
| 1630 | |||
| 1631 | /** |
||
| 1632 | * Creates an Arrayy object. |
||
| 1633 | * |
||
| 1634 | * @param mixed $data |
||
| 1635 | * @param string $iteratorClass |
||
| 1636 | * @param bool $checkPropertiesInConstructor |
||
| 1637 | * |
||
| 1638 | * @return static |
||
| 1639 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1640 | * |
||
| 1641 | * @phpstan-param array<array-key,T>|\Traversable<array-key,T>|callable():\Generator<TKey,T>|(T&\Traversable) $data |
||
| 1642 | * @phpstan-param class-string<\Arrayy\ArrayyIterator> $iteratorClass |
||
| 1643 | * @phpstan-return static<TKey,T> |
||
| 1644 | * @psalm-mutation-free |
||
| 1645 | */ |
||
| 1646 | 729 | public static function create( |
|
| 1657 | |||
| 1658 | /** |
||
| 1659 | * Flatten an array with the given character as a key delimiter. |
||
| 1660 | * |
||
| 1661 | * EXAMPLE: <code> |
||
| 1662 | * $dot = a(['foo' => ['abc' => 'xyz', 'bar' => ['baz']]]); |
||
| 1663 | * $flatten = $dot->flatten(); |
||
| 1664 | * $flatten['foo.abc']; // 'xyz' |
||
| 1665 | * $flatten['foo.bar.0']; // 'baz' |
||
| 1666 | * </code> |
||
| 1667 | * |
||
| 1668 | * @param string $delimiter |
||
| 1669 | * @param string $prepend |
||
| 1670 | * @param array|null $items |
||
| 1671 | * |
||
| 1672 | * @return array |
||
| 1673 | */ |
||
| 1674 | 2 | public function flatten($delimiter = '.', $prepend = '', $items = null) |
|
| 1697 | |||
| 1698 | /** |
||
| 1699 | * WARNING: Creates an Arrayy object by reference. |
||
| 1700 | * |
||
| 1701 | * @param array $array |
||
| 1702 | * |
||
| 1703 | * @return $this |
||
| 1704 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1705 | * |
||
| 1706 | * @phpstan-param array<TKey,T> $array |
||
| 1707 | * @phpstan-return $this<TKey,T> |
||
| 1708 | * |
||
| 1709 | * @internal this will not check any types because it's set directly as reference |
||
| 1710 | */ |
||
| 1711 | 27 | public function createByReference(array &$array = []): self |
|
| 1718 | |||
| 1719 | /** |
||
| 1720 | * Create an new instance from a callable function which will return an Generator. |
||
| 1721 | * |
||
| 1722 | * @param callable $generatorFunction |
||
| 1723 | * |
||
| 1724 | * @return static |
||
| 1725 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1726 | * |
||
| 1727 | * @phpstan-param callable():\Generator<TKey,T> $generatorFunction |
||
| 1728 | * @phpstan-return static<TKey,T> |
||
| 1729 | * @psalm-mutation-free |
||
| 1730 | */ |
||
| 1731 | 7 | public static function createFromGeneratorFunction(callable $generatorFunction): self |
|
| 1735 | |||
| 1736 | /** |
||
| 1737 | * Create an new instance filled with a copy of values from a "Generator"-object. |
||
| 1738 | * |
||
| 1739 | * @param \Generator $generator |
||
| 1740 | * |
||
| 1741 | * @return static |
||
| 1742 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1743 | * |
||
| 1744 | * @phpstan-param \Generator<TKey,T> $generator |
||
| 1745 | * @phpstan-return static<TKey,T> |
||
| 1746 | * @psalm-mutation-free |
||
| 1747 | */ |
||
| 1748 | 4 | public static function createFromGeneratorImmutable(\Generator $generator): self |
|
| 1752 | |||
| 1753 | /** |
||
| 1754 | * Create an new Arrayy object via JSON. |
||
| 1755 | * |
||
| 1756 | * @param string $json |
||
| 1757 | * |
||
| 1758 | * @return static |
||
| 1759 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1760 | * |
||
| 1761 | * @phpstan-return static<int|string,mixed> |
||
| 1762 | * @psalm-mutation-free |
||
| 1763 | */ |
||
| 1764 | 5 | public static function createFromJson(string $json): self |
|
| 1768 | |||
| 1769 | /** |
||
| 1770 | * Create an new Arrayy object via JSON. |
||
| 1771 | * |
||
| 1772 | * @param array $array |
||
| 1773 | * |
||
| 1774 | * @return static |
||
| 1775 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1776 | * |
||
| 1777 | * @phpstan-param array<TKey,T> $array |
||
| 1778 | * @phpstan-return static<TKey,T> |
||
| 1779 | * @psalm-mutation-free |
||
| 1780 | */ |
||
| 1781 | 1 | public static function createFromArray(array $array): self |
|
| 1785 | |||
| 1786 | /** |
||
| 1787 | * Create an new instance filled with values from an object that is iterable. |
||
| 1788 | * |
||
| 1789 | * @param \Traversable $object <p>iterable object</p> |
||
| 1790 | * |
||
| 1791 | * @return static |
||
| 1792 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1793 | * |
||
| 1794 | * @phpstan-param \Traversable<array-key,T> $object |
||
| 1795 | * @phpstan-return static<array-key,T> |
||
| 1796 | * @psalm-mutation-free |
||
| 1797 | */ |
||
| 1798 | 4 | public static function createFromObject(\Traversable $object): self |
|
| 1818 | |||
| 1819 | /** |
||
| 1820 | * Create an new instance filled with values from an object. |
||
| 1821 | * |
||
| 1822 | * @param object $object |
||
| 1823 | * |
||
| 1824 | * @return static |
||
| 1825 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1826 | * |
||
| 1827 | * @phpstan-return static<array-key,mixed> |
||
| 1828 | * @psalm-mutation-free |
||
| 1829 | */ |
||
| 1830 | 5 | public static function createFromObjectVars($object): self |
|
| 1834 | |||
| 1835 | /** |
||
| 1836 | * Create an new Arrayy object via string. |
||
| 1837 | * |
||
| 1838 | * @param string $str <p>The input string.</p> |
||
| 1839 | * @param string|null $delimiter <p>The boundary string.</p> |
||
| 1840 | * @param string|null $regEx <p>Use the $delimiter or the $regEx, so if $pattern is null, $delimiter will be |
||
| 1841 | * used.</p> |
||
| 1842 | * |
||
| 1843 | * @return static |
||
| 1844 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1845 | * |
||
| 1846 | * @phpstan-return static<int,string> |
||
| 1847 | * @psalm-mutation-free |
||
| 1848 | */ |
||
| 1849 | 10 | public static function createFromString(string $str, string $delimiter = null, string $regEx = null): self |
|
| 1881 | |||
| 1882 | /** |
||
| 1883 | * Create an new instance filled with a copy of values from a "Traversable"-object. |
||
| 1884 | * |
||
| 1885 | * @param \Traversable $traversable |
||
| 1886 | * @param bool $use_keys [optional] <p> |
||
| 1887 | * Whether to use the iterator element keys as index. |
||
| 1888 | * </p> |
||
| 1889 | * |
||
| 1890 | * @return static |
||
| 1891 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1892 | * |
||
| 1893 | * @phpstan-param \Traversable<array-key|TKey,T> $traversable |
||
| 1894 | * @phpstan-return static<int|TKey,T> |
||
| 1895 | * @psalm-mutation-free |
||
| 1896 | */ |
||
| 1897 | 1 | public static function createFromTraversableImmutable(\Traversable $traversable, bool $use_keys = true): self |
|
| 1901 | |||
| 1902 | /** |
||
| 1903 | * Create an new instance containing a range of elements. |
||
| 1904 | * |
||
| 1905 | * @param float|int|string $low <p>First value of the sequence.</p> |
||
| 1906 | * @param float|int|string $high <p>The sequence is ended upon reaching the end value.</p> |
||
| 1907 | * @param float|int $step <p>Used as the increment between elements in the sequence.</p> |
||
| 1908 | * |
||
| 1909 | * @return static |
||
| 1910 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1911 | * |
||
| 1912 | * @phpstan-return static<int,int|string> |
||
| 1913 | * @psalm-mutation-free |
||
| 1914 | */ |
||
| 1915 | 2 | public static function createWithRange($low, $high, $step = 1): self |
|
| 1919 | |||
| 1920 | /** |
||
| 1921 | * Gets the element of the array at the current internal iterator position. |
||
| 1922 | * |
||
| 1923 | * @return false|mixed |
||
| 1924 | * |
||
| 1925 | * @phpstan-return false|T |
||
| 1926 | */ |
||
| 1927 | public function current() |
||
| 1935 | |||
| 1936 | /** |
||
| 1937 | * Custom sort by index via "uksort". |
||
| 1938 | * |
||
| 1939 | * EXAMPLE: <code> |
||
| 1940 | * $callable = function ($a, $b) { |
||
| 1941 | * if ($a == $b) { |
||
| 1942 | * return 0; |
||
| 1943 | * } |
||
| 1944 | * return ($a > $b) ? 1 : -1; |
||
| 1945 | * }; |
||
| 1946 | * $arrayy = a(['three' => 3, 'one' => 1, 'two' => 2]); |
||
| 1947 | * $resultArrayy = $arrayy->customSortKeys($callable); // Arrayy['one' => 1, 'three' => 3, 'two' => 2] |
||
| 1948 | * </code> |
||
| 1949 | * |
||
| 1950 | * @see http://php.net/manual/en/function.uksort.php |
||
| 1951 | * |
||
| 1952 | * @param callable $function |
||
| 1953 | * |
||
| 1954 | * @throws \InvalidArgumentException |
||
| 1955 | * |
||
| 1956 | * @return $this |
||
| 1957 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1958 | * |
||
| 1959 | * @phpstan-return static<TKey,T> |
||
| 1960 | */ |
||
| 1961 | 5 | public function customSortKeys(callable $function): self |
|
| 1969 | |||
| 1970 | /** |
||
| 1971 | * Custom sort by index via "uksort". |
||
| 1972 | * |
||
| 1973 | * @see http://php.net/manual/en/function.uksort.php |
||
| 1974 | * |
||
| 1975 | * @param callable $function |
||
| 1976 | * |
||
| 1977 | * @throws \InvalidArgumentException |
||
| 1978 | * |
||
| 1979 | * @return $this |
||
| 1980 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 1981 | * |
||
| 1982 | * @phpstan-return static<TKey,T> |
||
| 1983 | * @psalm-mutation-free |
||
| 1984 | */ |
||
| 1985 | 1 | public function customSortKeysImmutable(callable $function): self |
|
| 1998 | |||
| 1999 | /** |
||
| 2000 | * Custom sort by value via "usort". |
||
| 2001 | * |
||
| 2002 | * EXAMPLE: <code> |
||
| 2003 | * $callable = function ($a, $b) { |
||
| 2004 | * if ($a == $b) { |
||
| 2005 | * return 0; |
||
| 2006 | * } |
||
| 2007 | * return ($a > $b) ? 1 : -1; |
||
| 2008 | * }; |
||
| 2009 | * $arrayy = a(['three' => 3, 'one' => 1, 'two' => 2]); |
||
| 2010 | * $resultArrayy = $arrayy->customSortValues($callable); // Arrayy['one' => 1, 'two' => 2, 'three' => 3] |
||
| 2011 | * </code> |
||
| 2012 | * |
||
| 2013 | * @see http://php.net/manual/en/function.usort.php |
||
| 2014 | * |
||
| 2015 | * @param callable $function |
||
| 2016 | * |
||
| 2017 | * @return $this |
||
| 2018 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 2019 | * |
||
| 2020 | * @phpstan-return static<TKey,T> |
||
| 2021 | */ |
||
| 2022 | 10 | public function customSortValues(callable $function): self |
|
| 2023 | { |
||
| 2024 | 10 | $this->generatorToArray(); |
|
| 2025 | |||
| 2026 | 10 | \usort($this->array, $function); |
|
| 2027 | |||
| 2028 | 10 | return $this; |
|
| 2029 | } |
||
| 2030 | |||
| 2031 | /** |
||
| 2032 | * Custom sort by value via "usort". |
||
| 2033 | * |
||
| 2034 | * @see http://php.net/manual/en/function.usort.php |
||
| 2035 | * |
||
| 2036 | * @param callable $function |
||
| 2037 | * |
||
| 2038 | * @throws \InvalidArgumentException |
||
| 2039 | * |
||
| 2040 | * @return $this |
||
| 2041 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 2042 | * |
||
| 2043 | * @phpstan-return static<TKey,T> |
||
| 2044 | * @psalm-mutation-free |
||
| 2045 | */ |
||
| 2046 | 4 | public function customSortValuesImmutable($function): self |
|
| 2057 | |||
| 2058 | /** |
||
| 2059 | * Delete the given key or keys. |
||
| 2060 | * |
||
| 2061 | * @param int|int[]|string|string[] $keyOrKeys |
||
| 2062 | * |
||
| 2063 | * @return void |
||
| 2064 | */ |
||
| 2065 | 9 | public function delete($keyOrKeys) |
|
| 2073 | |||
| 2074 | /** |
||
| 2075 | * Return elements where the values that are only in the current array. |
||
| 2076 | * |
||
| 2077 | * EXAMPLE: <code> |
||
| 2078 | * a([1 => 1, 2 => 2])->diff([1 => 1]); // Arrayy[2 => 2] |
||
| 2079 | * </code> |
||
| 2080 | * |
||
| 2081 | * @param array ...$array |
||
| 2082 | * |
||
| 2083 | * @return static |
||
| 2084 | * <p>(Immutable)</p> |
||
| 2085 | * |
||
| 2086 | * @phpstan-param array<TKey,T> ...$array |
||
| 2087 | * @phpstan-return static<TKey,T> |
||
| 2088 | * @psalm-mutation-free |
||
| 2089 | */ |
||
| 2090 | 13 | View Code Duplication | public function diff(array ...$array): self |
| 2112 | |||
| 2113 | /** |
||
| 2114 | * Return elements where the keys are only in the current array. |
||
| 2115 | * |
||
| 2116 | * @param array ...$array |
||
| 2117 | * |
||
| 2118 | * @return static |
||
| 2119 | * <p>(Immutable)</p> |
||
| 2120 | * |
||
| 2121 | * @phpstan-param array<TKey,T> ...$array |
||
| 2122 | * @phpstan-return static<TKey,T> |
||
| 2123 | * @psalm-mutation-free |
||
| 2124 | */ |
||
| 2125 | 9 | View Code Duplication | public function diffKey(array ...$array): self |
| 2147 | |||
| 2148 | /** |
||
| 2149 | * Return elements where the values and keys are only in the current array. |
||
| 2150 | * |
||
| 2151 | * @param array ...$array |
||
| 2152 | * |
||
| 2153 | * @return static |
||
| 2154 | * <p>(Immutable)</p> |
||
| 2155 | * |
||
| 2156 | * @phpstan-param array<TKey,T> $array |
||
| 2157 | * @phpstan-return static<TKey,T> |
||
| 2158 | * @psalm-mutation-free |
||
| 2159 | */ |
||
| 2160 | 9 | public function diffKeyAndValue(array ...$array): self |
|
| 2188 | |||
| 2189 | /** |
||
| 2190 | * Return elements where the values are only in the current multi-dimensional array. |
||
| 2191 | * |
||
| 2192 | * EXAMPLE: <code> |
||
| 2193 | * a([1 => [1 => 1], 2 => [2 => 2]])->diffRecursive([1 => [1 => 1]]); // Arrayy[2 => [2 => 2]] |
||
| 2194 | * </code> |
||
| 2195 | * |
||
| 2196 | * @param array $array |
||
| 2197 | * @param array|\Generator|null $helperVariableForRecursion <p>(only for internal usage)</p> |
||
| 2198 | * |
||
| 2199 | * @return static |
||
| 2200 | * <p>(Immutable)</p> |
||
| 2201 | * |
||
| 2202 | * @phpstan-param array<TKey,T> $array |
||
| 2203 | * @phpstan-param null|array<TKey,T>|\Generator<TKey,T> $helperVariableForRecursion |
||
| 2204 | * @phpstan-return static<TKey,T> |
||
| 2205 | * @psalm-mutation-free |
||
| 2206 | */ |
||
| 2207 | 1 | public function diffRecursive(array $array = [], $helperVariableForRecursion = null): self |
|
| 2242 | |||
| 2243 | /** |
||
| 2244 | * Return elements where the values that are only in the new $array. |
||
| 2245 | * |
||
| 2246 | * EXAMPLE: <code> |
||
| 2247 | * a([1 => 1])->diffReverse([1 => 1, 2 => 2]); // Arrayy[2 => 2] |
||
| 2248 | * </code> |
||
| 2249 | * |
||
| 2250 | * @param array $array |
||
| 2251 | * |
||
| 2252 | * @return static |
||
| 2253 | * <p>(Immutable)</p> |
||
| 2254 | * |
||
| 2255 | * @phpstan-param array<TKey,T> $array |
||
| 2256 | * @phpstan-return static<TKey,T> |
||
| 2257 | * @psalm-mutation-free |
||
| 2258 | */ |
||
| 2259 | 8 | public function diffReverse(array $array = []): self |
|
| 2267 | |||
| 2268 | /** |
||
| 2269 | * Divide an array into two arrays. One with keys and the other with values. |
||
| 2270 | * |
||
| 2271 | * EXAMPLE: <code> |
||
| 2272 | * a(['a' => 1, 'b' => ''])->divide(); // Arrayy[Arrayy['a', 'b'], Arrayy[1, '']] |
||
| 2273 | * </code> |
||
| 2274 | * |
||
| 2275 | * @return static |
||
| 2276 | * <p>(Immutable)</p> |
||
| 2277 | * |
||
| 2278 | * @phpstan-return static<TKey,T> |
||
| 2279 | * @psalm-mutation-free |
||
| 2280 | */ |
||
| 2281 | 1 | public function divide(): self |
|
| 2292 | |||
| 2293 | /** |
||
| 2294 | * Iterate over the current array and modify the array's value. |
||
| 2295 | * |
||
| 2296 | * EXAMPLE: <code> |
||
| 2297 | * $result = A::create(); |
||
| 2298 | * $closure = function ($value) { |
||
| 2299 | * return ':' . $value . ':'; |
||
| 2300 | * }; |
||
| 2301 | * a(['foo', 'bar' => 'bis'])->each($closure); // Arrayy[':foo:', 'bar' => ':bis:'] |
||
| 2302 | * </code> |
||
| 2303 | * |
||
| 2304 | * @param \Closure $closure |
||
| 2305 | * |
||
| 2306 | * @return static |
||
| 2307 | * <p>(Immutable)</p> |
||
| 2308 | * |
||
| 2309 | * @phpstan-param \Closure(T=):T|\Closure(T=,TKey=):T $closure |
||
| 2310 | * @phpstan-return static<TKey,T> |
||
| 2311 | * @psalm-mutation-free |
||
| 2312 | */ |
||
| 2313 | 5 | View Code Duplication | public function each(\Closure $closure): self |
| 2328 | |||
| 2329 | /** |
||
| 2330 | * Sets the internal iterator to the last element in the array and returns this element. |
||
| 2331 | * |
||
| 2332 | * @return false|mixed |
||
| 2333 | * |
||
| 2334 | * @phpstan-return T|false |
||
| 2335 | */ |
||
| 2336 | public function end() |
||
| 2354 | |||
| 2355 | /** |
||
| 2356 | * Check if a value is in the current array using a closure. |
||
| 2357 | * |
||
| 2358 | * EXAMPLE: <code> |
||
| 2359 | * $callable = function ($value, $key) { |
||
| 2360 | * return 2 === $key and 'two' === $value; |
||
| 2361 | * }; |
||
| 2362 | * a(['foo', 2 => 'two'])->exists($callable); // true |
||
| 2363 | * </code> |
||
| 2364 | * |
||
| 2365 | * @param \Closure $closure |
||
| 2366 | * |
||
| 2367 | * @return bool |
||
| 2368 | * <p>Returns true if the given value is found, false otherwise.</p> |
||
| 2369 | * |
||
| 2370 | * @phpstan-param \Closure(T=,TKey=):bool $closure |
||
| 2371 | */ |
||
| 2372 | 4 | public function exists(\Closure $closure): bool |
|
| 2387 | |||
| 2388 | /** |
||
| 2389 | * Fill the array until "$num" with "$default" values. |
||
| 2390 | * |
||
| 2391 | * EXAMPLE: <code> |
||
| 2392 | * a(['bar'])->fillWithDefaults(3, 'foo'); // Arrayy['bar', 'foo', 'foo'] |
||
| 2393 | * </code> |
||
| 2394 | * |
||
| 2395 | * @param int $num |
||
| 2396 | * @param mixed $default |
||
| 2397 | * |
||
| 2398 | * @return static |
||
| 2399 | * <p>(Immutable)</p> |
||
| 2400 | * |
||
| 2401 | * @phpstan-param T $default |
||
| 2402 | * @phpstan-return static<TKey,T> |
||
| 2403 | * @psalm-mutation-free |
||
| 2404 | */ |
||
| 2405 | 8 | public function fillWithDefaults(int $num, $default = null): self |
|
| 2428 | |||
| 2429 | /** |
||
| 2430 | * Find all items in an array that pass the truth test. |
||
| 2431 | * |
||
| 2432 | * EXAMPLE: <code> |
||
| 2433 | * $closure = function ($value) { |
||
| 2434 | * return $value % 2 !== 0; |
||
| 2435 | * } |
||
| 2436 | * a([1, 2, 3, 4])->filter($closure); // Arrayy[0 => 1, 2 => 3] |
||
| 2437 | * </code> |
||
| 2438 | * |
||
| 2439 | * @param \Closure|null $closure [optional] <p> |
||
| 2440 | * The callback function to use |
||
| 2441 | * </p> |
||
| 2442 | * <p> |
||
| 2443 | * If no callback is supplied, all entries of |
||
| 2444 | * input equal to false (see |
||
| 2445 | * converting to |
||
| 2446 | * boolean) will be removed. |
||
| 2447 | * </p> |
||
| 2448 | * @param int $flag [optional] <p> |
||
| 2449 | * Flag determining what arguments are sent to <i>callback</i>: |
||
| 2450 | * </p> |
||
| 2451 | * <ul> |
||
| 2452 | * <li> |
||
| 2453 | * <b>ARRAY_FILTER_USE_KEY</b> (1) - pass key as the only argument |
||
| 2454 | * to <i>callback</i> instead of the value |
||
| 2455 | * </li> |
||
| 2456 | * <li> |
||
| 2457 | * <b>ARRAY_FILTER_USE_BOTH</b> (2) - pass both value and key as |
||
| 2458 | * arguments to <i>callback</i> instead of the value |
||
| 2459 | * </li> |
||
| 2460 | * </ul> |
||
| 2461 | * |
||
| 2462 | * @return static |
||
| 2463 | * <p>(Immutable)</p> |
||
| 2464 | * |
||
| 2465 | * @phpstan-param null|\Closure(T=,TKey=):bool|\Closure(T=):bool|\Closure(TKey=):bool $closure |
||
| 2466 | * @phpstan-return static<TKey,T> |
||
| 2467 | * @psalm-mutation-free |
||
| 2468 | */ |
||
| 2469 | 12 | public function filter($closure = null, int $flag = \ARRAY_FILTER_USE_BOTH) |
|
| 2519 | |||
| 2520 | /** |
||
| 2521 | * Filters an array of objects (or a numeric array of associative arrays) based on the value of a particular |
||
| 2522 | * property within that. |
||
| 2523 | * |
||
| 2524 | * @param string $property |
||
| 2525 | * @param mixed $value |
||
| 2526 | * @param string|null $comparisonOp |
||
| 2527 | * <p> |
||
| 2528 | * 'eq' (equals),<br /> |
||
| 2529 | * 'gt' (greater),<br /> |
||
| 2530 | * 'gte' || 'ge' (greater or equals),<br /> |
||
| 2531 | * 'lt' (less),<br /> |
||
| 2532 | * 'lte' || 'le' (less or equals),<br /> |
||
| 2533 | * 'ne' (not equals),<br /> |
||
| 2534 | * 'contains',<br /> |
||
| 2535 | * 'notContains',<br /> |
||
| 2536 | * 'newer' (via strtotime),<br /> |
||
| 2537 | * 'older' (via strtotime),<br /> |
||
| 2538 | * </p> |
||
| 2539 | * |
||
| 2540 | * @return static |
||
| 2541 | * <p>(Immutable)</p> |
||
| 2542 | * |
||
| 2543 | * @phpstan-param mixed|T $value |
||
| 2544 | * @phpstan-return static<TKey,T> |
||
| 2545 | * @psalm-mutation-free |
||
| 2546 | * |
||
| 2547 | * @psalm-suppress MissingClosureReturnType |
||
| 2548 | * @psalm-suppress MissingClosureParamType |
||
| 2549 | */ |
||
| 2550 | 1 | public function filterBy( |
|
| 2622 | |||
| 2623 | /** |
||
| 2624 | * Find the first item in an array that passes the truth test, otherwise return false. |
||
| 2625 | * |
||
| 2626 | * EXAMPLE: <code> |
||
| 2627 | * $search = 'foo'; |
||
| 2628 | * $closure = function ($value, $key) use ($search) { |
||
| 2629 | * return $value === $search; |
||
| 2630 | * }; |
||
| 2631 | * a(['foo', 'bar', 'lall'])->find($closure); // 'foo' |
||
| 2632 | * </code> |
||
| 2633 | * |
||
| 2634 | * @param \Closure $closure |
||
| 2635 | * |
||
| 2636 | * @return false|mixed |
||
| 2637 | * <p>Return false if we did not find the value.</p> |
||
| 2638 | * |
||
| 2639 | * @phpstan-param \Closure(T=,TKey=):bool $closure |
||
| 2640 | * @phpstan-return T|false |
||
| 2641 | */ |
||
| 2642 | 8 | View Code Duplication | public function find(\Closure $closure) |
| 2652 | |||
| 2653 | /** |
||
| 2654 | * find by ... |
||
| 2655 | * |
||
| 2656 | * EXAMPLE: <code> |
||
| 2657 | * $array = [ |
||
| 2658 | * 0 => ['id' => 123, 'name' => 'foo', 'group' => 'primary', 'value' => 123456, 'when' => '2014-01-01'], |
||
| 2659 | * 1 => ['id' => 456, 'name' => 'bar', 'group' => 'primary', 'value' => 1468, 'when' => '2014-07-15'], |
||
| 2660 | * ]; |
||
| 2661 | * a($array)->filterBy('name', 'foo'); // Arrayy[0 => ['id' => 123, 'name' => 'foo', 'group' => 'primary', 'value' => 123456, 'when' => '2014-01-01']] |
||
| 2662 | * </code> |
||
| 2663 | * |
||
| 2664 | * @param string $property |
||
| 2665 | * @param mixed $value |
||
| 2666 | * @param string $comparisonOp |
||
| 2667 | * |
||
| 2668 | * @return static |
||
| 2669 | * <p>(Immutable)</p> |
||
| 2670 | * |
||
| 2671 | * @phpstan-param mixed|T $value |
||
| 2672 | * @phpstan-return static<TKey,T> |
||
| 2673 | * @psalm-mutation-free |
||
| 2674 | */ |
||
| 2675 | 1 | public function findBy(string $property, $value, string $comparisonOp = 'eq'): self |
|
| 2679 | |||
| 2680 | /** |
||
| 2681 | * Get the first value from the current array. |
||
| 2682 | * |
||
| 2683 | * EXAMPLE: <code> |
||
| 2684 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->first(); // 'foo' |
||
| 2685 | * </code> |
||
| 2686 | * |
||
| 2687 | * @return mixed|null |
||
| 2688 | * <p>Return null if there wasn't a element.</p> |
||
| 2689 | * |
||
| 2690 | * @phpstan-return T|null |
||
| 2691 | * @psalm-mutation-free |
||
| 2692 | */ |
||
| 2693 | 23 | public function first() |
|
| 2702 | |||
| 2703 | /** |
||
| 2704 | * Get the first key from the current array. |
||
| 2705 | * |
||
| 2706 | * @return mixed|null |
||
| 2707 | * <p>Return null if there wasn't a element.</p> |
||
| 2708 | * |
||
| 2709 | * @psalm-mutation-free |
||
| 2710 | */ |
||
| 2711 | 30 | public function firstKey() |
|
| 2717 | |||
| 2718 | /** |
||
| 2719 | * Get the first value(s) from the current array. |
||
| 2720 | * And will return an empty array if there was no first entry. |
||
| 2721 | * |
||
| 2722 | * EXAMPLE: <code> |
||
| 2723 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->firstsImmutable(2); // Arrayy[0 => 'foo', 1 => 'bar'] |
||
| 2724 | * </code> |
||
| 2725 | * |
||
| 2726 | * @param int|null $number <p>How many values you will take?</p> |
||
| 2727 | * |
||
| 2728 | * @return static |
||
| 2729 | * <p>(Immutable)</p> |
||
| 2730 | * |
||
| 2731 | * @phpstan-return static<TKey,T> |
||
| 2732 | * @psalm-mutation-free |
||
| 2733 | */ |
||
| 2734 | 37 | public function firstsImmutable(int $number = null): self |
|
| 2750 | |||
| 2751 | /** |
||
| 2752 | * Get the first value(s) from the current array. |
||
| 2753 | * And will return an empty array if there was no first entry. |
||
| 2754 | * |
||
| 2755 | * @param int|null $number <p>How many values you will take?</p> |
||
| 2756 | * |
||
| 2757 | * @return static |
||
| 2758 | * <p>(Immutable)</p> |
||
| 2759 | * |
||
| 2760 | * @phpstan-return static<TKey,T> |
||
| 2761 | * @psalm-mutation-free |
||
| 2762 | */ |
||
| 2763 | 3 | View Code Duplication | public function firstsKeys(int $number = null): self |
| 2779 | |||
| 2780 | /** |
||
| 2781 | * Get and remove the first value(s) from the current array. |
||
| 2782 | * And will return an empty array if there was no first entry. |
||
| 2783 | * |
||
| 2784 | * EXAMPLE: <code> |
||
| 2785 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->firstsMutable(); // 'foo' |
||
| 2786 | * </code> |
||
| 2787 | * |
||
| 2788 | * @param int|null $number <p>How many values you will take?</p> |
||
| 2789 | * |
||
| 2790 | * @return $this |
||
| 2791 | * <p>(Mutable)</p> |
||
| 2792 | * |
||
| 2793 | * @phpstan-return static<TKey,T> |
||
| 2794 | */ |
||
| 2795 | 34 | public function firstsMutable(int $number = null): self |
|
| 2807 | |||
| 2808 | /** |
||
| 2809 | * Exchanges all keys with their associated values in an array. |
||
| 2810 | * |
||
| 2811 | * EXAMPLE: <code> |
||
| 2812 | * a([0 => 'foo', 1 => 'bar'])->flip(); // Arrayy['foo' => 0, 'bar' => 1] |
||
| 2813 | * </code> |
||
| 2814 | * |
||
| 2815 | * @return static |
||
| 2816 | * <p>(Immutable)</p> |
||
| 2817 | * |
||
| 2818 | * @phpstan-return static<array-key,TKey> |
||
| 2819 | * @psalm-mutation-free |
||
| 2820 | */ |
||
| 2821 | 1 | public function flip(): self |
|
| 2835 | |||
| 2836 | /** |
||
| 2837 | * Get a value from an array (optional using dot-notation). |
||
| 2838 | * |
||
| 2839 | * EXAMPLE: <code> |
||
| 2840 | * $arrayy = a(['user' => ['lastname' => 'Moelleken']]); |
||
| 2841 | * $arrayy->get('user.lastname'); // 'Moelleken' |
||
| 2842 | * // --- |
||
| 2843 | * $arrayy = new A(); |
||
| 2844 | * $arrayy['user'] = ['lastname' => 'Moelleken']; |
||
| 2845 | * $arrayy['user.firstname'] = 'Lars'; |
||
| 2846 | * $arrayy['user']['lastname']; // Moelleken |
||
| 2847 | * $arrayy['user.lastname']; // Moelleken |
||
| 2848 | * $arrayy['user.firstname']; // Lars |
||
| 2849 | * </code> |
||
| 2850 | * |
||
| 2851 | * @param int|string $key <p>The key to look for.</p> |
||
| 2852 | * @param mixed $fallback <p>Value to fallback to.</p> |
||
| 2853 | * @param array|null $array <p>The array to get from, if it's set to "null" we use the current array from the |
||
| 2854 | * class.</p> |
||
| 2855 | * @param bool $useByReference |
||
| 2856 | * |
||
| 2857 | * @return mixed|static |
||
| 2858 | * |
||
| 2859 | * @phpstan-param array-key $key |
||
| 2860 | * @phpstan-param array<array-key,mixed>|array<TKey,T> $array |
||
| 2861 | * @psalm-mutation-free |
||
| 2862 | */ |
||
| 2863 | 248 | public function get( |
|
| 3036 | |||
| 3037 | /** |
||
| 3038 | * alias: for "Arrayy->toArray()" |
||
| 3039 | * |
||
| 3040 | * @return array |
||
| 3041 | * |
||
| 3042 | * @see Arrayy::getArray() |
||
| 3043 | * |
||
| 3044 | * @phpstan-return array<TKey,T> |
||
| 3045 | */ |
||
| 3046 | 15 | public function getAll(): array |
|
| 3050 | |||
| 3051 | /** |
||
| 3052 | * Get the current array from the "Arrayy"-object. |
||
| 3053 | * |
||
| 3054 | * alias for "toArray()" |
||
| 3055 | * |
||
| 3056 | * @param bool $convertAllArrayyElements <p> |
||
| 3057 | * Convert all Child-"Arrayy" objects also to arrays. |
||
| 3058 | * </p> |
||
| 3059 | * @param bool $preserveKeys <p> |
||
| 3060 | * e.g.: A generator maybe return the same key more then once, |
||
| 3061 | * so maybe you will ignore the keys. |
||
| 3062 | * </p> |
||
| 3063 | * |
||
| 3064 | * @return array |
||
| 3065 | * |
||
| 3066 | * @phpstan-return array<TKey,T> |
||
| 3067 | * @psalm-mutation-free |
||
| 3068 | * |
||
| 3069 | * @see Arrayy::toArray() |
||
| 3070 | */ |
||
| 3071 | 512 | public function getArray( |
|
| 3080 | |||
| 3081 | /** |
||
| 3082 | * @param string $json |
||
| 3083 | * |
||
| 3084 | * @return $this |
||
| 3085 | */ |
||
| 3086 | 3 | public static function createFromJsonMapper(string $json) |
|
| 3102 | |||
| 3103 | /** |
||
| 3104 | * @return array<int|string,TypeCheckInterface>|mixed|TypeCheckArray<int|string,TypeCheckInterface>|TypeInterface |
||
| 3105 | * |
||
| 3106 | * @internal |
||
| 3107 | */ |
||
| 3108 | 6 | public function getPhpDocPropertiesFromClass() |
|
| 3116 | |||
| 3117 | /** |
||
| 3118 | * Get the current array from the "Arrayy"-object as list. |
||
| 3119 | * |
||
| 3120 | * alias for "toList()" |
||
| 3121 | * |
||
| 3122 | * @param bool $convertAllArrayyElements <p> |
||
| 3123 | * Convert all Child-"Arrayy" objects also to arrays. |
||
| 3124 | * </p> |
||
| 3125 | * |
||
| 3126 | * @return array |
||
| 3127 | * |
||
| 3128 | * @phpstan-return list<mixed>|list<T> |
||
| 3129 | * @psalm-mutation-free |
||
| 3130 | * |
||
| 3131 | * @see Arrayy::toList() |
||
| 3132 | */ |
||
| 3133 | 1 | public function getList(bool $convertAllArrayyElements = false): array |
|
| 3137 | |||
| 3138 | /** |
||
| 3139 | * Returns the values from a single column of the input array, identified by |
||
| 3140 | * the $columnKey, can be used to extract data-columns from multi-arrays. |
||
| 3141 | * |
||
| 3142 | * EXAMPLE: <code> |
||
| 3143 | * a([['foo' => 'bar', 'id' => 1], ['foo => 'lall', 'id' => 2]])->getColumn('foo', 'id'); // Arrayy[1 => 'bar', 2 => 'lall'] |
||
| 3144 | * </code> |
||
| 3145 | * |
||
| 3146 | * INFO: Optionally, you may provide an $indexKey to index the values in the returned |
||
| 3147 | * array by the values from the $indexKey column in the input array. |
||
| 3148 | * |
||
| 3149 | * @param int|string|null $columnKey |
||
| 3150 | * @param int|string|null $indexKey |
||
| 3151 | * |
||
| 3152 | * @return static |
||
| 3153 | * <p>(Immutable)</p> |
||
| 3154 | * |
||
| 3155 | * @phpstan-return static<TKey,T> |
||
| 3156 | * @psalm-mutation-free |
||
| 3157 | */ |
||
| 3158 | 1 | public function getColumn($columnKey = null, $indexKey = null): self |
|
| 3218 | |||
| 3219 | /** |
||
| 3220 | * Get the current array from the "Arrayy"-object as generator by reference. |
||
| 3221 | * |
||
| 3222 | * @return \Generator |
||
| 3223 | * |
||
| 3224 | * @phpstan-return \Generator<mixed,T>|\Generator<TKey,T> |
||
| 3225 | */ |
||
| 3226 | 75 | public function &getGeneratorByReference(): \Generator |
|
| 3245 | |||
| 3246 | /** |
||
| 3247 | * Get the current array from the "Arrayy"-object as generator. |
||
| 3248 | * |
||
| 3249 | * @return \Generator |
||
| 3250 | * |
||
| 3251 | * @phpstan-return \Generator<mixed,T>|\Generator<TKey,T> |
||
| 3252 | * @psalm-mutation-free |
||
| 3253 | */ |
||
| 3254 | 1072 | public function getGenerator(): \Generator |
|
| 3264 | |||
| 3265 | /** |
||
| 3266 | * alias: for "Arrayy->keys()" |
||
| 3267 | * |
||
| 3268 | * @return static |
||
| 3269 | * <p>(Immutable)</p> |
||
| 3270 | * |
||
| 3271 | * @see Arrayy::keys() |
||
| 3272 | * |
||
| 3273 | * @phpstan-return static<int,TKey> |
||
| 3274 | * @psalm-mutation-free |
||
| 3275 | */ |
||
| 3276 | 2 | public function getKeys() |
|
| 3280 | |||
| 3281 | /** |
||
| 3282 | * Get the current array from the "Arrayy"-object as object. |
||
| 3283 | * |
||
| 3284 | * @return \stdClass |
||
| 3285 | */ |
||
| 3286 | 4 | public function getObject(): \stdClass |
|
| 3290 | |||
| 3291 | /** |
||
| 3292 | * alias: for "Arrayy->randomImmutable()" |
||
| 3293 | * |
||
| 3294 | * @return static |
||
| 3295 | * <p>(Immutable)</p> |
||
| 3296 | * |
||
| 3297 | * @see Arrayy::randomImmutable() |
||
| 3298 | * |
||
| 3299 | * @phpstan-return static<int|array-key,T> |
||
| 3300 | */ |
||
| 3301 | 4 | public function getRandom(): self |
|
| 3305 | |||
| 3306 | /** |
||
| 3307 | * alias: for "Arrayy->randomKey()" |
||
| 3308 | * |
||
| 3309 | * @return mixed |
||
| 3310 | * <p>Get a key/index or null if there wasn't a key/index.</p> |
||
| 3311 | * |
||
| 3312 | * @see Arrayy::randomKey() |
||
| 3313 | */ |
||
| 3314 | 3 | public function getRandomKey() |
|
| 3318 | |||
| 3319 | /** |
||
| 3320 | * alias: for "Arrayy->randomKeys()" |
||
| 3321 | * |
||
| 3322 | * @param int $number |
||
| 3323 | * |
||
| 3324 | * @return static |
||
| 3325 | * <p>(Immutable)</p> |
||
| 3326 | * |
||
| 3327 | * @see Arrayy::randomKeys() |
||
| 3328 | * |
||
| 3329 | * @phpstan-return static<TKey,T> |
||
| 3330 | */ |
||
| 3331 | 8 | public function getRandomKeys(int $number): self |
|
| 3335 | |||
| 3336 | /** |
||
| 3337 | * alias: for "Arrayy->randomValue()" |
||
| 3338 | * |
||
| 3339 | * @return mixed |
||
| 3340 | * <p>Get a random value or null if there wasn't a value.</p> |
||
| 3341 | * |
||
| 3342 | * @see Arrayy::randomValue() |
||
| 3343 | */ |
||
| 3344 | 3 | public function getRandomValue() |
|
| 3348 | |||
| 3349 | /** |
||
| 3350 | * alias: for "Arrayy->randomValues()" |
||
| 3351 | * |
||
| 3352 | * @param int $number |
||
| 3353 | * |
||
| 3354 | * @return static |
||
| 3355 | * <p>(Immutable)</p> |
||
| 3356 | * |
||
| 3357 | * @see Arrayy::randomValues() |
||
| 3358 | * |
||
| 3359 | * @phpstan-return static<TKey,T> |
||
| 3360 | */ |
||
| 3361 | 6 | public function getRandomValues(int $number): self |
|
| 3365 | |||
| 3366 | /** |
||
| 3367 | * Gets all values. |
||
| 3368 | * |
||
| 3369 | * @return static |
||
| 3370 | * <p>The values of all elements in this array, in the order they |
||
| 3371 | * appear in the array.</p> |
||
| 3372 | * |
||
| 3373 | * @phpstan-return static<TKey,T> |
||
| 3374 | */ |
||
| 3375 | 4 | public function getValues() |
|
| 3385 | |||
| 3386 | /** |
||
| 3387 | * Gets all values via Generator. |
||
| 3388 | * |
||
| 3389 | * @return \Generator |
||
| 3390 | * <p>The values of all elements in this array, in the order they |
||
| 3391 | * appear in the array as Generator.</p> |
||
| 3392 | * |
||
| 3393 | * @phpstan-return \Generator<TKey,T> |
||
| 3394 | */ |
||
| 3395 | 4 | public function getValuesYield(): \Generator |
|
| 3399 | |||
| 3400 | /** |
||
| 3401 | * Group values from a array according to the results of a closure. |
||
| 3402 | * |
||
| 3403 | * @param callable|string $grouper <p>A callable function name.</p> |
||
| 3404 | * @param bool $saveKeys |
||
| 3405 | * |
||
| 3406 | * @return static |
||
| 3407 | * <p>(Immutable)</p> |
||
| 3408 | * |
||
| 3409 | * @phpstan-return static<TKey,T> |
||
| 3410 | * @psalm-mutation-free |
||
| 3411 | */ |
||
| 3412 | 4 | public function group($grouper, bool $saveKeys = false): self |
|
| 3453 | |||
| 3454 | /** |
||
| 3455 | * Check if an array has a given key. |
||
| 3456 | * |
||
| 3457 | * @param mixed $key |
||
| 3458 | * |
||
| 3459 | * @return bool |
||
| 3460 | */ |
||
| 3461 | 30 | public function has($key): bool |
|
| 3487 | |||
| 3488 | /** |
||
| 3489 | * Check if an array has a given value. |
||
| 3490 | * |
||
| 3491 | * INFO: If you need to search recursive please use ```contains($value, true)```. |
||
| 3492 | * |
||
| 3493 | * @param mixed $value |
||
| 3494 | * |
||
| 3495 | * @return bool |
||
| 3496 | */ |
||
| 3497 | 1 | public function hasValue($value): bool |
|
| 3501 | |||
| 3502 | /** |
||
| 3503 | * Implodes the values of this array. |
||
| 3504 | * |
||
| 3505 | * EXAMPLE: <code> |
||
| 3506 | * a([0 => -9, 1, 2])->implode('|'); // '-9|1|2' |
||
| 3507 | * </code> |
||
| 3508 | * |
||
| 3509 | * @param string $glue |
||
| 3510 | * @param string $prefix |
||
| 3511 | * |
||
| 3512 | * @return string |
||
| 3513 | * @psalm-mutation-free |
||
| 3514 | */ |
||
| 3515 | 28 | public function implode(string $glue = '', string $prefix = ''): string |
|
| 3519 | |||
| 3520 | /** |
||
| 3521 | * Implodes the keys of this array. |
||
| 3522 | * |
||
| 3523 | * @param string $glue |
||
| 3524 | * |
||
| 3525 | * @return string |
||
| 3526 | * @psalm-mutation-free |
||
| 3527 | */ |
||
| 3528 | 8 | public function implodeKeys(string $glue = ''): string |
|
| 3532 | |||
| 3533 | /** |
||
| 3534 | * Given a list and an iterate-function that returns |
||
| 3535 | * a key for each element in the list (or a property name), |
||
| 3536 | * returns an object with an index of each item. |
||
| 3537 | * |
||
| 3538 | * @param mixed $key |
||
| 3539 | * |
||
| 3540 | * @return static |
||
| 3541 | * <p>(Immutable)</p> |
||
| 3542 | * |
||
| 3543 | * @phpstan-return static<TKey,T> |
||
| 3544 | * @psalm-mutation-free |
||
| 3545 | */ |
||
| 3546 | 4 | View Code Duplication | public function indexBy($key): self |
| 3563 | |||
| 3564 | /** |
||
| 3565 | * alias: for "Arrayy->searchIndex()" |
||
| 3566 | * |
||
| 3567 | * @param mixed $value <p>The value to search for.</p> |
||
| 3568 | * |
||
| 3569 | * @return false|mixed |
||
| 3570 | * |
||
| 3571 | * @see Arrayy::searchIndex() |
||
| 3572 | */ |
||
| 3573 | 4 | public function indexOf($value) |
|
| 3577 | |||
| 3578 | /** |
||
| 3579 | * Get everything but the last..$to items. |
||
| 3580 | * |
||
| 3581 | * EXAMPLE: <code> |
||
| 3582 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->initial(2); // Arrayy[0 => 'foo'] |
||
| 3583 | * </code> |
||
| 3584 | * |
||
| 3585 | * @param int $to |
||
| 3586 | * |
||
| 3587 | * @return static |
||
| 3588 | * <p>(Immutable)</p> |
||
| 3589 | * |
||
| 3590 | * @phpstan-return static<TKey,T> |
||
| 3591 | * @psalm-mutation-free |
||
| 3592 | */ |
||
| 3593 | 12 | public function initial(int $to = 1): self |
|
| 3597 | |||
| 3598 | /** |
||
| 3599 | * Return an array with all elements found in input array. |
||
| 3600 | * |
||
| 3601 | * EXAMPLE: <code> |
||
| 3602 | * a(['foo', 'bar'])->intersection(['bar', 'baz']); // Arrayy['bar'] |
||
| 3603 | * </code> |
||
| 3604 | * |
||
| 3605 | * @param array $search |
||
| 3606 | * @param bool $keepKeys |
||
| 3607 | * |
||
| 3608 | * @return static |
||
| 3609 | * <p>(Immutable)</p> |
||
| 3610 | * |
||
| 3611 | * @phpstan-param array<TKey,T> $search |
||
| 3612 | * @phpstan-return static<TKey,T> |
||
| 3613 | * @psalm-mutation-free |
||
| 3614 | */ |
||
| 3615 | 4 | public function intersection(array $search, bool $keepKeys = false): self |
|
| 3641 | |||
| 3642 | /** |
||
| 3643 | * Return an array with all elements found in input array. |
||
| 3644 | * |
||
| 3645 | * @param array ...$array |
||
| 3646 | * |
||
| 3647 | * @return static |
||
| 3648 | * <p>(Immutable)</p> |
||
| 3649 | * |
||
| 3650 | * @phpstan-param array<array<TKey,T>> ...$array |
||
| 3651 | * @phpstan-return static<TKey,T> |
||
| 3652 | * @psalm-mutation-free |
||
| 3653 | */ |
||
| 3654 | 1 | public function intersectionMulti(...$array): self |
|
| 3662 | |||
| 3663 | /** |
||
| 3664 | * Return a boolean flag which indicates whether the two input arrays have any common elements. |
||
| 3665 | * |
||
| 3666 | * EXAMPLE: <code> |
||
| 3667 | * a(['foo', 'bar'])->intersects(['föö', 'bär']); // false |
||
| 3668 | * </code> |
||
| 3669 | * |
||
| 3670 | * @param array $search |
||
| 3671 | * |
||
| 3672 | * @return bool |
||
| 3673 | * |
||
| 3674 | * @phpstan-param array<TKey,T> $search |
||
| 3675 | */ |
||
| 3676 | 1 | public function intersects(array $search): bool |
|
| 3680 | |||
| 3681 | /** |
||
| 3682 | * Invoke a function on all of an array's values. |
||
| 3683 | * |
||
| 3684 | * @param callable $callable |
||
| 3685 | * @param mixed $arguments |
||
| 3686 | * |
||
| 3687 | * @return static |
||
| 3688 | * <p>(Immutable)</p> |
||
| 3689 | * |
||
| 3690 | * @phpstan-param callable(T=,mixed):mixed $callable |
||
| 3691 | * @phpstan-return static<TKey,T> |
||
| 3692 | * @psalm-mutation-free |
||
| 3693 | */ |
||
| 3694 | 1 | public function invoke($callable, $arguments = []): self |
|
| 3718 | |||
| 3719 | /** |
||
| 3720 | * Check whether array is associative or not. |
||
| 3721 | * |
||
| 3722 | * EXAMPLE: <code> |
||
| 3723 | * a(['foo' => 'bar', 2, 3])->isAssoc(); // true |
||
| 3724 | * </code> |
||
| 3725 | * |
||
| 3726 | * @param bool $recursive |
||
| 3727 | * |
||
| 3728 | * @return bool |
||
| 3729 | * <p>Returns true if associative, false otherwise.</p> |
||
| 3730 | */ |
||
| 3731 | 15 | View Code Duplication | public function isAssoc(bool $recursive = false): bool |
| 3746 | |||
| 3747 | /** |
||
| 3748 | * Check if a given key or keys are empty. |
||
| 3749 | * |
||
| 3750 | * @param int|int[]|string|string[]|null $keys |
||
| 3751 | * |
||
| 3752 | * @return bool |
||
| 3753 | * <p>Returns true if empty, false otherwise.</p> |
||
| 3754 | * @psalm-mutation-free |
||
| 3755 | */ |
||
| 3756 | 45 | public function isEmpty($keys = null): bool |
|
| 3774 | |||
| 3775 | /** |
||
| 3776 | * Check if the current array is equal to the given "$array" or not. |
||
| 3777 | * |
||
| 3778 | * EXAMPLE: <code> |
||
| 3779 | * a(['💩'])->isEqual(['💩']); // true |
||
| 3780 | * </code> |
||
| 3781 | * |
||
| 3782 | * @param array $array |
||
| 3783 | * |
||
| 3784 | * @return bool |
||
| 3785 | * |
||
| 3786 | * @phpstan-param array<int|string,mixed> $array |
||
| 3787 | */ |
||
| 3788 | 1 | public function isEqual(array $array): bool |
|
| 3792 | |||
| 3793 | /** |
||
| 3794 | * Check if the current array is a multi-array. |
||
| 3795 | * |
||
| 3796 | * EXAMPLE: <code> |
||
| 3797 | * a(['foo' => [1, 2 , 3]])->isMultiArray(); // true |
||
| 3798 | * </code> |
||
| 3799 | * |
||
| 3800 | * @return bool |
||
| 3801 | */ |
||
| 3802 | 22 | public function isMultiArray(): bool |
|
| 3812 | |||
| 3813 | /** |
||
| 3814 | * Check whether array is numeric or not. |
||
| 3815 | * |
||
| 3816 | * @return bool |
||
| 3817 | * <p>Returns true if numeric, false otherwise.</p> |
||
| 3818 | */ |
||
| 3819 | 5 | View Code Duplication | public function isNumeric(): bool |
| 3834 | |||
| 3835 | /** |
||
| 3836 | * Check if the current array is sequential [0, 1, 2, 3, 4, 5 ...] or not. |
||
| 3837 | * |
||
| 3838 | * EXAMPLE: <code> |
||
| 3839 | * a([0 => 'foo', 1 => 'lall', 2 => 'foobar'])->isSequential(); // true |
||
| 3840 | * </code> |
||
| 3841 | * |
||
| 3842 | * INFO: If the array is empty we count it as non-sequential. |
||
| 3843 | * |
||
| 3844 | * @param bool $recursive |
||
| 3845 | * |
||
| 3846 | * @return bool |
||
| 3847 | * @psalm-mutation-free |
||
| 3848 | */ |
||
| 3849 | 10 | public function isSequential(bool $recursive = false): bool |
|
| 3878 | |||
| 3879 | /** |
||
| 3880 | * @return array |
||
| 3881 | * |
||
| 3882 | * @phpstan-return array<TKey,T> |
||
| 3883 | */ |
||
| 3884 | 2 | public function jsonSerialize(): array |
|
| 3888 | |||
| 3889 | /** |
||
| 3890 | * Gets the key/index of the element at the current internal iterator position. |
||
| 3891 | * |
||
| 3892 | * @return int|string|null |
||
| 3893 | * @phpstan-return array-key|null |
||
| 3894 | */ |
||
| 3895 | public function key() |
||
| 3903 | |||
| 3904 | /** |
||
| 3905 | * Checks if the given key exists in the provided array. |
||
| 3906 | * |
||
| 3907 | * INFO: This method only use "array_key_exists()" if you want to use "dot"-notation, |
||
| 3908 | * then you need to use "Arrayy->offsetExists()". |
||
| 3909 | * |
||
| 3910 | * @param int|string $key the key to look for |
||
| 3911 | * |
||
| 3912 | * @return bool |
||
| 3913 | * @psalm-mutation-free |
||
| 3914 | */ |
||
| 3915 | 174 | public function keyExists($key): bool |
|
| 3925 | |||
| 3926 | /** |
||
| 3927 | * Get all keys from the current array. |
||
| 3928 | * |
||
| 3929 | * EXAMPLE: <code> |
||
| 3930 | * a([1 => 'foo', 2 => 'foo2', 3 => 'bar'])->keys(); // Arrayy[1, 2, 3] |
||
| 3931 | * </code> |
||
| 3932 | * |
||
| 3933 | * @param bool $recursive [optional] <p> |
||
| 3934 | * Get all keys, also from all sub-arrays from an multi-dimensional array. |
||
| 3935 | * </p> |
||
| 3936 | * @param mixed|null $search_values [optional] <p> |
||
| 3937 | * If specified, then only keys containing these values are returned. |
||
| 3938 | * </p> |
||
| 3939 | * @param bool $strict [optional] <p> |
||
| 3940 | * Determines if strict comparison (===) should be used during the search. |
||
| 3941 | * </p> |
||
| 3942 | * |
||
| 3943 | * @return static |
||
| 3944 | * <p>(Immutable) An array of all the keys in input.</p> |
||
| 3945 | * |
||
| 3946 | * @phpstan-return static<int,TKey> |
||
| 3947 | * @psalm-mutation-free |
||
| 3948 | */ |
||
| 3949 | 29 | public function keys( |
|
| 4020 | |||
| 4021 | /** |
||
| 4022 | * Sort an array by key in reverse order. |
||
| 4023 | * |
||
| 4024 | * @param int $sort_flags [optional] <p> |
||
| 4025 | * You may modify the behavior of the sort using the optional |
||
| 4026 | * parameter sort_flags, for details |
||
| 4027 | * see sort. |
||
| 4028 | * </p> |
||
| 4029 | * |
||
| 4030 | * @return $this |
||
| 4031 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 4032 | * |
||
| 4033 | * @phpstan-return static<TKey,T> |
||
| 4034 | */ |
||
| 4035 | 4 | public function krsort(int $sort_flags = 0): self |
|
| 4043 | |||
| 4044 | /** |
||
| 4045 | * Sort an array by key in reverse order. |
||
| 4046 | * |
||
| 4047 | * @param int $sort_flags [optional] <p> |
||
| 4048 | * You may modify the behavior of the sort using the optional |
||
| 4049 | * parameter sort_flags, for details |
||
| 4050 | * see sort. |
||
| 4051 | * </p> |
||
| 4052 | * |
||
| 4053 | * @return $this |
||
| 4054 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 4055 | * |
||
| 4056 | * @phpstan-return static<TKey,T> |
||
| 4057 | * @psalm-mutation-free |
||
| 4058 | */ |
||
| 4059 | 4 | public function krsortImmutable(int $sort_flags = 0): self |
|
| 4070 | |||
| 4071 | /** |
||
| 4072 | * Get the last value from the current array. |
||
| 4073 | * |
||
| 4074 | * EXAMPLE: <code> |
||
| 4075 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->last(); // 'lall' |
||
| 4076 | * </code> |
||
| 4077 | * |
||
| 4078 | * @return mixed|null |
||
| 4079 | * <p>Return null if there wasn't a element.</p> |
||
| 4080 | * |
||
| 4081 | * @phpstan-return T|null |
||
| 4082 | * @psalm-mutation-free |
||
| 4083 | */ |
||
| 4084 | 17 | public function last() |
|
| 4093 | |||
| 4094 | /** |
||
| 4095 | * Get the last key from the current array. |
||
| 4096 | * |
||
| 4097 | * @return mixed|null |
||
| 4098 | * <p>Return null if there wasn't a element.</p> |
||
| 4099 | * @psalm-mutation-free |
||
| 4100 | */ |
||
| 4101 | 21 | public function lastKey() |
|
| 4107 | |||
| 4108 | /** |
||
| 4109 | * Get the last value(s) from the current array. |
||
| 4110 | * |
||
| 4111 | * EXAMPLE: <code> |
||
| 4112 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->lasts(2); // Arrayy[0 => 'bar', 1 => 'lall'] |
||
| 4113 | * </code> |
||
| 4114 | * |
||
| 4115 | * @param int|null $number |
||
| 4116 | * |
||
| 4117 | * @return static |
||
| 4118 | * <p>(Immutable)</p> |
||
| 4119 | * |
||
| 4120 | * @phpstan-return static<TKey,T> |
||
| 4121 | * @psalm-mutation-free |
||
| 4122 | */ |
||
| 4123 | 13 | public function lastsImmutable(int $number = null): self |
|
| 4153 | |||
| 4154 | /** |
||
| 4155 | * Get the last value(s) from the current array. |
||
| 4156 | * |
||
| 4157 | * EXAMPLE: <code> |
||
| 4158 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->lasts(2); // Arrayy[0 => 'bar', 1 => 'lall'] |
||
| 4159 | * </code> |
||
| 4160 | * |
||
| 4161 | * @param int|null $number |
||
| 4162 | * |
||
| 4163 | * @return $this |
||
| 4164 | * <p>(Mutable)</p> |
||
| 4165 | * |
||
| 4166 | * @phpstan-return static<TKey,T> |
||
| 4167 | */ |
||
| 4168 | 13 | public function lastsMutable(int $number = null): self |
|
| 4179 | |||
| 4180 | /** |
||
| 4181 | * Count the values from the current array. |
||
| 4182 | * |
||
| 4183 | * alias: for "Arrayy->count()" |
||
| 4184 | * |
||
| 4185 | * @param int $mode |
||
| 4186 | * |
||
| 4187 | * @return int |
||
| 4188 | * |
||
| 4189 | * @see Arrayy::count() |
||
| 4190 | */ |
||
| 4191 | 20 | public function length(int $mode = \COUNT_NORMAL): int |
|
| 4195 | |||
| 4196 | /** |
||
| 4197 | * Apply the given function to the every element of the array, |
||
| 4198 | * collecting the results. |
||
| 4199 | * |
||
| 4200 | * EXAMPLE: <code> |
||
| 4201 | * a(['foo', 'Foo'])->map('mb_strtoupper'); // Arrayy['FOO', 'FOO'] |
||
| 4202 | * </code> |
||
| 4203 | * |
||
| 4204 | * @param callable $callable |
||
| 4205 | * @param bool $useKeyAsSecondParameter |
||
| 4206 | * @param mixed ...$arguments |
||
| 4207 | * |
||
| 4208 | * @return static |
||
| 4209 | * <p>(Immutable) Arrayy object with modified elements.</p> |
||
| 4210 | * |
||
| 4211 | * @template T2 |
||
| 4212 | * <p>The output value type.</p> |
||
| 4213 | * |
||
| 4214 | * @phpstan-param callable(T,TKey=,mixed=):T2 $callable |
||
| 4215 | * @phpstan-return static<TKey,T2> |
||
| 4216 | * @psalm-mutation-free |
||
| 4217 | */ |
||
| 4218 | 6 | public function map( |
|
| 4251 | |||
| 4252 | /** |
||
| 4253 | * Check if all items in current array match a truth test. |
||
| 4254 | * |
||
| 4255 | * EXAMPLE: <code> |
||
| 4256 | * $closure = function ($value, $key) { |
||
| 4257 | * return ($value % 2 === 0); |
||
| 4258 | * }; |
||
| 4259 | * a([2, 4, 8])->matches($closure); // true |
||
| 4260 | * </code> |
||
| 4261 | * |
||
| 4262 | * @param \Closure $closure |
||
| 4263 | * |
||
| 4264 | * @return bool |
||
| 4265 | * |
||
| 4266 | * @phpstan-param \Closure(T=,TKey=):bool $closure |
||
| 4267 | */ |
||
| 4268 | 15 | View Code Duplication | public function matches(\Closure $closure): bool |
| 4284 | |||
| 4285 | /** |
||
| 4286 | * Check if any item in the current array matches a truth test. |
||
| 4287 | * |
||
| 4288 | * EXAMPLE: <code> |
||
| 4289 | * $closure = function ($value, $key) { |
||
| 4290 | * return ($value % 2 === 0); |
||
| 4291 | * }; |
||
| 4292 | * a([1, 4, 7])->matches($closure); // true |
||
| 4293 | * </code> |
||
| 4294 | * |
||
| 4295 | * @param \Closure $closure |
||
| 4296 | * |
||
| 4297 | * @return bool |
||
| 4298 | * |
||
| 4299 | * @phpstan-param \Closure(T=,TKey=):bool $closure |
||
| 4300 | */ |
||
| 4301 | 14 | View Code Duplication | public function matchesAny(\Closure $closure): bool |
| 4317 | |||
| 4318 | /** |
||
| 4319 | * Get the max value from an array. |
||
| 4320 | * |
||
| 4321 | * EXAMPLE: <code> |
||
| 4322 | * a([-9, -8, -7, 1.32])->max(); // 1.32 |
||
| 4323 | * </code> |
||
| 4324 | * |
||
| 4325 | * @return false|float|int|string |
||
| 4326 | * <p>Will return false if there are no values.</p> |
||
| 4327 | */ |
||
| 4328 | 10 | View Code Duplication | public function max() |
| 4348 | |||
| 4349 | /** |
||
| 4350 | * Merge the new $array into the current array. |
||
| 4351 | * |
||
| 4352 | * - keep key,value from the current array, also if the index is in the new $array |
||
| 4353 | * |
||
| 4354 | * EXAMPLE: <code> |
||
| 4355 | * $array1 = [1 => 'one', 'foo' => 'bar1']; |
||
| 4356 | * $array2 = ['foo' => 'bar2', 3 => 'three']; |
||
| 4357 | * a($array1)->mergeAppendKeepIndex($array2); // Arrayy[1 => 'one', 'foo' => 'bar2', 3 => 'three'] |
||
| 4358 | * // --- |
||
| 4359 | * $array1 = [0 => 'one', 1 => 'foo']; |
||
| 4360 | * $array2 = [0 => 'foo', 1 => 'bar2']; |
||
| 4361 | * a($array1)->mergeAppendKeepIndex($array2); // Arrayy[0 => 'foo', 1 => 'bar2'] |
||
| 4362 | * </code> |
||
| 4363 | * |
||
| 4364 | * @param array $array |
||
| 4365 | * @param bool $recursive |
||
| 4366 | * |
||
| 4367 | * @return static |
||
| 4368 | * <p>(Immutable)</p> |
||
| 4369 | * |
||
| 4370 | * @phpstan-param array<int|TKey,T> $array |
||
| 4371 | * @phpstan-return static<int|TKey,T> |
||
| 4372 | * @psalm-mutation-free |
||
| 4373 | */ |
||
| 4374 | 33 | View Code Duplication | public function mergeAppendKeepIndex(array $array = [], bool $recursive = false): self |
| 4389 | |||
| 4390 | /** |
||
| 4391 | * Merge the new $array into the current array. |
||
| 4392 | * |
||
| 4393 | * - replace duplicate assoc-keys from the current array with the key,values from the new $array |
||
| 4394 | * - create new indexes |
||
| 4395 | * |
||
| 4396 | * EXAMPLE: <code> |
||
| 4397 | * $array1 = [1 => 'one', 'foo' => 'bar1']; |
||
| 4398 | * $array2 = ['foo' => 'bar2', 3 => 'three']; |
||
| 4399 | * a($array1)->mergeAppendNewIndex($array2); // Arrayy[0 => 'one', 'foo' => 'bar2', 1 => 'three'] |
||
| 4400 | * // --- |
||
| 4401 | * $array1 = [0 => 'one', 1 => 'foo']; |
||
| 4402 | * $array2 = [0 => 'foo', 1 => 'bar2']; |
||
| 4403 | * a($array1)->mergeAppendNewIndex($array2); // Arrayy[0 => 'one', 1 => 'foo', 2 => 'foo', 3 => 'bar2'] |
||
| 4404 | * </code> |
||
| 4405 | * |
||
| 4406 | * @param array $array |
||
| 4407 | * @param bool $recursive |
||
| 4408 | * |
||
| 4409 | * @return static |
||
| 4410 | * <p>(Immutable)</p> |
||
| 4411 | * |
||
| 4412 | * @phpstan-param array<TKey,T> $array |
||
| 4413 | * @phpstan-return static<int,T> |
||
| 4414 | * @psalm-mutation-free |
||
| 4415 | */ |
||
| 4416 | 20 | View Code Duplication | public function mergeAppendNewIndex(array $array = [], bool $recursive = false): self |
| 4431 | |||
| 4432 | /** |
||
| 4433 | * Merge the the current array into the $array. |
||
| 4434 | * |
||
| 4435 | * - use key,value from the new $array, also if the index is in the current array |
||
| 4436 | * |
||
| 4437 | * EXAMPLE: <code> |
||
| 4438 | * $array1 = [1 => 'one', 'foo' => 'bar1']; |
||
| 4439 | * $array2 = ['foo' => 'bar2', 3 => 'three']; |
||
| 4440 | * a($array1)->mergePrependKeepIndex($array2); // Arrayy['foo' => 'bar1', 3 => 'three', 1 => 'one'] |
||
| 4441 | * // --- |
||
| 4442 | * $array1 = [0 => 'one', 1 => 'foo']; |
||
| 4443 | * $array2 = [0 => 'foo', 1 => 'bar2']; |
||
| 4444 | * a($array1)->mergePrependKeepIndex($array2); // Arrayy[0 => 'one', 1 => 'foo'] |
||
| 4445 | * </code> |
||
| 4446 | * |
||
| 4447 | * @param array $array |
||
| 4448 | * @param bool $recursive |
||
| 4449 | * |
||
| 4450 | * @return static |
||
| 4451 | * <p>(Immutable)</p> |
||
| 4452 | * |
||
| 4453 | * @phpstan-param array<TKey,T> $array |
||
| 4454 | * @phpstan-return static<TKey,T> |
||
| 4455 | * @psalm-mutation-free |
||
| 4456 | */ |
||
| 4457 | 17 | View Code Duplication | public function mergePrependKeepIndex(array $array = [], bool $recursive = false): self |
| 4472 | |||
| 4473 | /** |
||
| 4474 | * Merge the current array into the new $array. |
||
| 4475 | * |
||
| 4476 | * - replace duplicate assoc-keys from new $array with the key,values from the current array |
||
| 4477 | * - create new indexes |
||
| 4478 | * |
||
| 4479 | * EXAMPLE: <code> |
||
| 4480 | * $array1 = [1 => 'one', 'foo' => 'bar1']; |
||
| 4481 | * $array2 = ['foo' => 'bar2', 3 => 'three']; |
||
| 4482 | * a($array1)->mergePrependNewIndex($array2); // Arrayy['foo' => 'bar1', 0 => 'three', 1 => 'one'] |
||
| 4483 | * // --- |
||
| 4484 | * $array1 = [0 => 'one', 1 => 'foo']; |
||
| 4485 | * $array2 = [0 => 'foo', 1 => 'bar2']; |
||
| 4486 | * a($array1)->mergePrependNewIndex($array2); // Arrayy[0 => 'foo', 1 => 'bar2', 2 => 'one', 3 => 'foo'] |
||
| 4487 | * </code> |
||
| 4488 | * |
||
| 4489 | * @param array $array |
||
| 4490 | * @param bool $recursive |
||
| 4491 | * |
||
| 4492 | * @return static |
||
| 4493 | * <p>(Immutable)</p> |
||
| 4494 | * |
||
| 4495 | * @phpstan-param array<TKey,T> $array |
||
| 4496 | * @phpstan-return static<int,T> |
||
| 4497 | * @psalm-mutation-free |
||
| 4498 | */ |
||
| 4499 | 21 | View Code Duplication | public function mergePrependNewIndex(array $array = [], bool $recursive = false): self |
| 4514 | |||
| 4515 | /** |
||
| 4516 | * @return ArrayyMeta|mixed|static |
||
| 4517 | */ |
||
| 4518 | 18 | public static function meta() |
|
| 4522 | |||
| 4523 | /** |
||
| 4524 | * Get the min value from an array. |
||
| 4525 | * |
||
| 4526 | * EXAMPLE: <code> |
||
| 4527 | * a([-9, -8, -7, 1.32])->min(); // -9 |
||
| 4528 | * </code> |
||
| 4529 | * |
||
| 4530 | * @return false|mixed |
||
| 4531 | * <p>Will return false if there are no values.</p> |
||
| 4532 | */ |
||
| 4533 | 10 | View Code Duplication | public function min() |
| 4553 | |||
| 4554 | /** |
||
| 4555 | * Get the most used value from the array. |
||
| 4556 | * |
||
| 4557 | * @return mixed|null |
||
| 4558 | * <p>(Immutable) Return null if there wasn't a element.</p> |
||
| 4559 | * |
||
| 4560 | * @phpstan-return T|null |
||
| 4561 | * @psalm-mutation-free |
||
| 4562 | */ |
||
| 4563 | 3 | public function mostUsedValue() |
|
| 4567 | |||
| 4568 | /** |
||
| 4569 | * Get the most used value from the array. |
||
| 4570 | * |
||
| 4571 | * @param int|null $number <p>How many values you will take?</p> |
||
| 4572 | * |
||
| 4573 | * @return static |
||
| 4574 | * <p>(Immutable)</p> |
||
| 4575 | * |
||
| 4576 | * @phpstan-return static<TKey,T> |
||
| 4577 | * @psalm-mutation-free |
||
| 4578 | */ |
||
| 4579 | 3 | public function mostUsedValues(int $number = null): self |
|
| 4583 | |||
| 4584 | /** |
||
| 4585 | * Move an array element to a new index. |
||
| 4586 | * |
||
| 4587 | * EXAMPLE: <code> |
||
| 4588 | * $arr2 = new A(['A' => 'a', 'B' => 'b', 'C' => 'c', 'D' => 'd', 'E' => 'e']); |
||
| 4589 | * $newArr2 = $arr2->moveElement('D', 1); // Arrayy['A' => 'a', 'D' => 'd', 'B' => 'b', 'C' => 'c', 'E' => 'e'] |
||
| 4590 | * </code> |
||
| 4591 | * |
||
| 4592 | * @param int|string $from |
||
| 4593 | * @param int $to |
||
| 4594 | * |
||
| 4595 | * @return static |
||
| 4596 | * <p>(Immutable)</p> |
||
| 4597 | * |
||
| 4598 | * @phpstan-return static<TKey,T> |
||
| 4599 | * @psalm-mutation-free |
||
| 4600 | */ |
||
| 4601 | 1 | public function moveElement($from, $to): self |
|
| 4634 | |||
| 4635 | /** |
||
| 4636 | * Move an array element to the first place. |
||
| 4637 | * |
||
| 4638 | * INFO: Instead of "Arrayy->moveElement()" this method will NOT |
||
| 4639 | * loss the keys of an indexed array. |
||
| 4640 | * |
||
| 4641 | * @param int|string $key |
||
| 4642 | * |
||
| 4643 | * @return static |
||
| 4644 | * <p>(Immutable)</p> |
||
| 4645 | * |
||
| 4646 | * @phpstan-return static<TKey,T> |
||
| 4647 | * @psalm-mutation-free |
||
| 4648 | */ |
||
| 4649 | 1 | View Code Duplication | public function moveElementToFirstPlace($key): self |
| 4665 | |||
| 4666 | /** |
||
| 4667 | * Move an array element to the last place. |
||
| 4668 | * |
||
| 4669 | * INFO: Instead of "Arrayy->moveElement()" this method will NOT |
||
| 4670 | * loss the keys of an indexed array. |
||
| 4671 | * |
||
| 4672 | * @param int|string $key |
||
| 4673 | * |
||
| 4674 | * @return static |
||
| 4675 | * <p>(Immutable)</p> |
||
| 4676 | * |
||
| 4677 | * @phpstan-return static<TKey,T> |
||
| 4678 | * @psalm-mutation-free |
||
| 4679 | */ |
||
| 4680 | 1 | View Code Duplication | public function moveElementToLastPlace($key): self |
| 4696 | |||
| 4697 | /** |
||
| 4698 | * Moves the internal iterator position to the next element and returns this element. |
||
| 4699 | * |
||
| 4700 | * @return false|mixed |
||
| 4701 | * <p>(Mutable) Will return false if there are no values.</p> |
||
| 4702 | * |
||
| 4703 | * @phpstan-return false|T |
||
| 4704 | */ |
||
| 4705 | public function next() |
||
| 4715 | |||
| 4716 | /** |
||
| 4717 | * Get the next nth keys and values from the array. |
||
| 4718 | * |
||
| 4719 | * @param int $step |
||
| 4720 | * @param int $offset |
||
| 4721 | * |
||
| 4722 | * @return static |
||
| 4723 | * <p>(Immutable)</p> |
||
| 4724 | * |
||
| 4725 | * @phpstan-return static<TKey,T> |
||
| 4726 | * @psalm-mutation-free |
||
| 4727 | */ |
||
| 4728 | 1 | public function nth(int $step, int $offset = 0): self |
|
| 4747 | |||
| 4748 | /** |
||
| 4749 | * Get a subset of the items from the given array. |
||
| 4750 | * |
||
| 4751 | * @param int[]|string[] $keys |
||
| 4752 | * |
||
| 4753 | * @return static |
||
| 4754 | * <p>(Immutable)</p> |
||
| 4755 | * |
||
| 4756 | * @phpstan-param array-key[] $keys |
||
| 4757 | * @phpstan-return static<TKey,T> |
||
| 4758 | * @psalm-mutation-free |
||
| 4759 | */ |
||
| 4760 | 1 | View Code Duplication | public function only(array $keys): self |
| 4778 | |||
| 4779 | /** |
||
| 4780 | * Pad array to the specified size with a given value. |
||
| 4781 | * |
||
| 4782 | * @param int $size <p>Size of the result array.</p> |
||
| 4783 | * @param mixed $value <p>Empty value by default.</p> |
||
| 4784 | * |
||
| 4785 | * @return static |
||
| 4786 | * <p>(Immutable) Arrayy object padded to $size with $value.</p> |
||
| 4787 | * |
||
| 4788 | * @phpstan-return static<TKey,T> |
||
| 4789 | * @psalm-mutation-free |
||
| 4790 | */ |
||
| 4791 | 5 | public function pad(int $size, $value): self |
|
| 4799 | |||
| 4800 | /** |
||
| 4801 | * Partitions this array in two array according to a predicate. |
||
| 4802 | * Keys are preserved in the resulting array. |
||
| 4803 | * |
||
| 4804 | * @param \Closure $closure |
||
| 4805 | * <p>The predicate on which to partition.</p> |
||
| 4806 | * |
||
| 4807 | * @return array<int, static> |
||
| 4808 | * <p>An array with two elements. The first element contains the array |
||
| 4809 | * of elements where the predicate returned TRUE, the second element |
||
| 4810 | * contains the array of elements where the predicate returned FALSE.</p> |
||
| 4811 | * |
||
| 4812 | * @phpstan-param \Closure(T=,TKey=):bool $closure |
||
| 4813 | * @phpstan-return array<int, static<TKey,T>> |
||
| 4814 | */ |
||
| 4815 | 1 | public function partition(\Closure $closure): array |
|
| 4831 | |||
| 4832 | /** |
||
| 4833 | * Pop a specified value off the end of the current array. |
||
| 4834 | * |
||
| 4835 | * @return mixed|null |
||
| 4836 | * <p>(Mutable) The popped element from the current array or null if the array is e.g. empty.</p> |
||
| 4837 | * |
||
| 4838 | * @phpstan-return T|null |
||
| 4839 | */ |
||
| 4840 | 5 | public function pop() |
|
| 4846 | |||
| 4847 | /** |
||
| 4848 | * Prepend a (key) + value to the current array. |
||
| 4849 | * |
||
| 4850 | * EXAMPLE: <code> |
||
| 4851 | * a(['fòô' => 'bàř'])->prepend('foo'); // Arrayy[0 => 'foo', 'fòô' => 'bàř'] |
||
| 4852 | * </code> |
||
| 4853 | * |
||
| 4854 | * @param mixed $value |
||
| 4855 | * @param mixed $key |
||
| 4856 | * |
||
| 4857 | * @return $this |
||
| 4858 | * <p>(Mutable) Return this Arrayy object, with the prepended value.</p> |
||
| 4859 | * |
||
| 4860 | * @phpstan-param T $value |
||
| 4861 | * @phpstan-param TKey|null $key |
||
| 4862 | * @phpstan-return static<TKey,T> |
||
| 4863 | */ |
||
| 4864 | 11 | public function prepend($value, $key = null) |
|
| 4880 | |||
| 4881 | /** |
||
| 4882 | * Prepend a (key) + value to the current array. |
||
| 4883 | * |
||
| 4884 | * EXAMPLE: <code> |
||
| 4885 | * a(['fòô' => 'bàř'])->prependImmutable('foo')->getArray(); // [0 => 'foo', 'fòô' => 'bàř'] |
||
| 4886 | * </code> |
||
| 4887 | * |
||
| 4888 | * @param mixed $value |
||
| 4889 | * @param mixed $key |
||
| 4890 | * |
||
| 4891 | * @return $this |
||
| 4892 | * <p>(Immutable) Return this Arrayy object, with the prepended value.</p> |
||
| 4893 | * |
||
| 4894 | * @phpstan-param T $value |
||
| 4895 | * @phpstan-param TKey $key |
||
| 4896 | * @phpstan-return static<TKey,T> |
||
| 4897 | * @psalm-mutation-free |
||
| 4898 | */ |
||
| 4899 | 1 | View Code Duplication | public function prependImmutable($value, $key = null) |
| 4924 | |||
| 4925 | /** |
||
| 4926 | * Add a suffix to each key. |
||
| 4927 | * |
||
| 4928 | * @param float|int|string $suffix |
||
| 4929 | * |
||
| 4930 | * @return static |
||
| 4931 | * <p>(Immutable) Return an Arrayy object, with the prepended keys.</p> |
||
| 4932 | * |
||
| 4933 | * @phpstan-return static<TKey,T> |
||
| 4934 | * @psalm-mutation-free |
||
| 4935 | */ |
||
| 4936 | 10 | View Code Duplication | public function prependToEachKey($suffix): self |
| 4962 | |||
| 4963 | /** |
||
| 4964 | * Add a suffix to each value. |
||
| 4965 | * |
||
| 4966 | * @param float|int|string $suffix |
||
| 4967 | * |
||
| 4968 | * @return static |
||
| 4969 | * <p>(Immutable) Return an Arrayy object, with the prepended values.</p> |
||
| 4970 | * |
||
| 4971 | * @phpstan-return static<TKey,T> |
||
| 4972 | * @psalm-mutation-free |
||
| 4973 | */ |
||
| 4974 | 10 | View Code Duplication | public function prependToEachValue($suffix): self |
| 5002 | |||
| 5003 | /** |
||
| 5004 | * Return the value of a given key and |
||
| 5005 | * delete the key. |
||
| 5006 | * |
||
| 5007 | * @param int|int[]|string|string[]|null $keyOrKeys |
||
| 5008 | * @param mixed $fallback |
||
| 5009 | * |
||
| 5010 | * @return mixed |
||
| 5011 | */ |
||
| 5012 | 6 | public function pull($keyOrKeys = null, $fallback = null) |
|
| 5034 | |||
| 5035 | /** |
||
| 5036 | * Push one or more values onto the end of array at once. |
||
| 5037 | * |
||
| 5038 | * @param mixed ...$args |
||
| 5039 | * |
||
| 5040 | * @return $this |
||
| 5041 | * <p>(Mutable) Return this Arrayy object, with pushed elements to the end of array.</p> |
||
| 5042 | * |
||
| 5043 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
| 5044 | * |
||
| 5045 | * @phpstan-param array<TKey,T> ...$args |
||
| 5046 | * @phpstan-return static<TKey,T> |
||
| 5047 | */ |
||
| 5048 | 9 | View Code Duplication | public function push(...$args) |
| 5066 | |||
| 5067 | /** |
||
| 5068 | * Get a random value from the current array. |
||
| 5069 | * |
||
| 5070 | * EXAMPLE: <code> |
||
| 5071 | * a([1, 2, 3, 4])->randomImmutable(2); // e.g.: Arrayy[1, 4] |
||
| 5072 | * </code> |
||
| 5073 | * |
||
| 5074 | * @param int|null $number <p>How many values you will take?</p> |
||
| 5075 | * |
||
| 5076 | * @return static |
||
| 5077 | * <p>(Immutable)</p> |
||
| 5078 | * |
||
| 5079 | * @phpstan-return static<int|array-key,T> |
||
| 5080 | */ |
||
| 5081 | 19 | public function randomImmutable(int $number = null): self |
|
| 5114 | |||
| 5115 | /** |
||
| 5116 | * Pick a random key/index from the keys of this array. |
||
| 5117 | * |
||
| 5118 | * EXAMPLE: <code> |
||
| 5119 | * $arrayy = A::create([1 => 'one', 2 => 'two']); |
||
| 5120 | * $arrayy->randomKey(); // e.g. 2 |
||
| 5121 | * </code> |
||
| 5122 | * |
||
| 5123 | * @throws \RangeException If array is empty |
||
| 5124 | * |
||
| 5125 | * @return mixed |
||
| 5126 | * <p>Get a key/index or null if there wasn't a key/index.</p> |
||
| 5127 | */ |
||
| 5128 | 4 | public function randomKey() |
|
| 5138 | |||
| 5139 | /** |
||
| 5140 | * Pick a given number of random keys/indexes out of this array. |
||
| 5141 | * |
||
| 5142 | * EXAMPLE: <code> |
||
| 5143 | * a([1 => 'one', 2 => 'two'])->randomKeys(); // e.g. Arrayy[1, 2] |
||
| 5144 | * </code> |
||
| 5145 | * |
||
| 5146 | * @param int $number <p>The number of keys/indexes (should be <= \count($this->array))</p> |
||
| 5147 | * |
||
| 5148 | * @throws \RangeException If array is empty |
||
| 5149 | * |
||
| 5150 | * @return static |
||
| 5151 | * <p>(Immutable)</p> |
||
| 5152 | * |
||
| 5153 | * @phpstan-return static<TKey,T> |
||
| 5154 | */ |
||
| 5155 | 13 | public function randomKeys(int $number): self |
|
| 5183 | |||
| 5184 | /** |
||
| 5185 | * Get a random value from the current array. |
||
| 5186 | * |
||
| 5187 | * EXAMPLE: <code> |
||
| 5188 | * a([1, 2, 3, 4])->randomMutable(2); // e.g.: Arrayy[1, 4] |
||
| 5189 | * </code> |
||
| 5190 | * |
||
| 5191 | * @param int|null $number <p>How many values you will take?</p> |
||
| 5192 | * |
||
| 5193 | * @return $this |
||
| 5194 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 5195 | * |
||
| 5196 | * @phpstan-return static<TKey,T> |
||
| 5197 | */ |
||
| 5198 | 17 | public function randomMutable(int $number = null): self |
|
| 5223 | |||
| 5224 | /** |
||
| 5225 | * Pick a random value from the values of this array. |
||
| 5226 | * |
||
| 5227 | * EXAMPLE: <code> |
||
| 5228 | * a([1 => 'one', 2 => 'two'])->randomValue(); // e.g. 'one' |
||
| 5229 | * </code> |
||
| 5230 | * |
||
| 5231 | * @return mixed |
||
| 5232 | * <p>Get a random value or null if there wasn't a value.</p> |
||
| 5233 | */ |
||
| 5234 | 4 | public function randomValue() |
|
| 5244 | |||
| 5245 | /** |
||
| 5246 | * Pick a given number of random values out of this array. |
||
| 5247 | * |
||
| 5248 | * EXAMPLE: <code> |
||
| 5249 | * a([1 => 'one', 2 => 'two'])->randomValues(); // e.g. Arrayy['one', 'two'] |
||
| 5250 | * </code> |
||
| 5251 | * |
||
| 5252 | * @param int $number |
||
| 5253 | * |
||
| 5254 | * @return static |
||
| 5255 | * <p>(Mutable)</p> |
||
| 5256 | * |
||
| 5257 | * @phpstan-return static<TKey,T> |
||
| 5258 | */ |
||
| 5259 | 7 | public function randomValues(int $number): self |
|
| 5263 | |||
| 5264 | /** |
||
| 5265 | * Get a random value from an array, with the ability to skew the results. |
||
| 5266 | * |
||
| 5267 | * EXAMPLE: <code> |
||
| 5268 | * a([0 => 3, 1 => 4])->randomWeighted([1 => 4]); // e.g.: Arrayy[4] (has a 66% chance of returning 4) |
||
| 5269 | * </code> |
||
| 5270 | * |
||
| 5271 | * @param array $array |
||
| 5272 | * @param int|null $number <p>How many values you will take?</p> |
||
| 5273 | * |
||
| 5274 | * @return static<int,mixed> |
||
| 5275 | * <p>(Immutable)</p> |
||
| 5276 | * |
||
| 5277 | * @phpstan-param array<T,int> $array |
||
| 5278 | * @phpstan-return static<(int|string),T> |
||
| 5279 | */ |
||
| 5280 | 9 | public function randomWeighted(array $array, int $number = null): self |
|
| 5295 | |||
| 5296 | /** |
||
| 5297 | * Reduce the current array via callable e.g. anonymous-function and return the end result. |
||
| 5298 | * |
||
| 5299 | * EXAMPLE: <code> |
||
| 5300 | * a([1, 2, 3, 4])->reduce( |
||
| 5301 | * function ($carry, $item) { |
||
| 5302 | * return $carry * $item; |
||
| 5303 | * }, |
||
| 5304 | * 1 |
||
| 5305 | * ); // Arrayy[24] |
||
| 5306 | * </code> |
||
| 5307 | * |
||
| 5308 | * @param callable $callable |
||
| 5309 | * @param mixed $initial |
||
| 5310 | * |
||
| 5311 | * @return static |
||
| 5312 | * <p>(Immutable)</p> |
||
| 5313 | * |
||
| 5314 | * @template T2 |
||
| 5315 | * <p>The output value type.</p> |
||
| 5316 | * |
||
| 5317 | * @phpstan-param callable(T2, T, TKey): T2 $callable |
||
| 5318 | * @phpstan-param T2 $initial |
||
| 5319 | * |
||
| 5320 | * @phpstan-return static<TKey,T2> |
||
| 5321 | * @psalm-mutation-free |
||
| 5322 | */ |
||
| 5323 | 18 | View Code Duplication | public function reduce($callable, $initial = []): self |
| 5335 | |||
| 5336 | /** |
||
| 5337 | * @param bool $unique |
||
| 5338 | * |
||
| 5339 | * @return static |
||
| 5340 | * <p>(Immutable)</p> |
||
| 5341 | * |
||
| 5342 | * @phpstan-return static<int,mixed> |
||
| 5343 | * @psalm-mutation-free |
||
| 5344 | */ |
||
| 5345 | 14 | public function reduce_dimension(bool $unique = true): self |
|
| 5368 | |||
| 5369 | /** |
||
| 5370 | * Create a numerically re-indexed Arrayy object. |
||
| 5371 | * |
||
| 5372 | * EXAMPLE: <code> |
||
| 5373 | * a([2 => 1, 3 => 2])->reindex(); // Arrayy[0 => 1, 1 => 2] |
||
| 5374 | * </code> |
||
| 5375 | * |
||
| 5376 | * @return $this |
||
| 5377 | * <p>(Mutable) Return this Arrayy object, with re-indexed array-elements.</p> |
||
| 5378 | * |
||
| 5379 | * @phpstan-return static<TKey,T> |
||
| 5380 | */ |
||
| 5381 | 9 | public function reindex(): self |
|
| 5389 | |||
| 5390 | /** |
||
| 5391 | * Return all items that fail the truth test. |
||
| 5392 | * |
||
| 5393 | * EXAMPLE: <code> |
||
| 5394 | * $closure = function ($value) { |
||
| 5395 | * return $value % 2 !== 0; |
||
| 5396 | * } |
||
| 5397 | * a([1, 2, 3, 4])->reject($closure); // Arrayy[1 => 2, 3 => 4] |
||
| 5398 | * </code> |
||
| 5399 | * |
||
| 5400 | * @param \Closure $closure |
||
| 5401 | * |
||
| 5402 | * @return static |
||
| 5403 | * <p>(Immutable)</p> |
||
| 5404 | * |
||
| 5405 | * @phpstan-param \Closure(T=,TKey=):bool $closure |
||
| 5406 | * @phpstan-return static<TKey,T> |
||
| 5407 | * @psalm-mutation-free |
||
| 5408 | */ |
||
| 5409 | 1 | View Code Duplication | public function reject(\Closure $closure): self |
| 5426 | |||
| 5427 | /** |
||
| 5428 | * Remove a value from the current array (optional using dot-notation). |
||
| 5429 | * |
||
| 5430 | * EXAMPLE: <code> |
||
| 5431 | * a([1 => 'bar', 'foo' => 'foo'])->remove(1); // Arrayy['foo' => 'foo'] |
||
| 5432 | * </code> |
||
| 5433 | * |
||
| 5434 | * @param mixed $key |
||
| 5435 | * |
||
| 5436 | * @return static |
||
| 5437 | * <p>(Mutable)</p> |
||
| 5438 | * |
||
| 5439 | * @phpstan-param TKey $key |
||
| 5440 | * @phpstan-return static<TKey,T> |
||
| 5441 | */ |
||
| 5442 | 22 | public function remove($key) |
|
| 5465 | |||
| 5466 | /** |
||
| 5467 | * alias: for "Arrayy->removeValue()" |
||
| 5468 | * |
||
| 5469 | * @param mixed $element |
||
| 5470 | * |
||
| 5471 | * @return static |
||
| 5472 | * <p>(Immutable)</p> |
||
| 5473 | * |
||
| 5474 | * @phpstan-param T $element |
||
| 5475 | * @phpstan-return static<TKey,T> |
||
| 5476 | * @psalm-mutation-free |
||
| 5477 | */ |
||
| 5478 | 8 | public function removeElement($element) |
|
| 5482 | |||
| 5483 | /** |
||
| 5484 | * Remove the first value from the current array. |
||
| 5485 | * |
||
| 5486 | * EXAMPLE: <code> |
||
| 5487 | * a([1 => 'bar', 'foo' => 'foo'])->removeFirst(); // Arrayy['foo' => 'foo'] |
||
| 5488 | * </code> |
||
| 5489 | * |
||
| 5490 | * @return static |
||
| 5491 | * <p>(Immutable)</p> |
||
| 5492 | * |
||
| 5493 | * @phpstan-return static<TKey,T> |
||
| 5494 | * @psalm-mutation-free |
||
| 5495 | */ |
||
| 5496 | 7 | View Code Duplication | public function removeFirst(): self |
| 5508 | |||
| 5509 | /** |
||
| 5510 | * Remove the last value from the current array. |
||
| 5511 | * |
||
| 5512 | * EXAMPLE: <code> |
||
| 5513 | * a([1 => 'bar', 'foo' => 'foo'])->removeLast(); // Arrayy[1 => 'bar'] |
||
| 5514 | * </code> |
||
| 5515 | * |
||
| 5516 | * @return static |
||
| 5517 | * <p>(Immutable)</p> |
||
| 5518 | * |
||
| 5519 | * @phpstan-return static<TKey,T> |
||
| 5520 | * @psalm-mutation-free |
||
| 5521 | */ |
||
| 5522 | 7 | View Code Duplication | public function removeLast(): self |
| 5534 | |||
| 5535 | /** |
||
| 5536 | * Removes a particular value from an array (numeric or associative). |
||
| 5537 | * |
||
| 5538 | * EXAMPLE: <code> |
||
| 5539 | * a([1 => 'bar', 'foo' => 'foo'])->removeValue('foo'); // Arrayy[1 => 'bar'] |
||
| 5540 | * </code> |
||
| 5541 | * |
||
| 5542 | * @param mixed $value |
||
| 5543 | * |
||
| 5544 | * @return static |
||
| 5545 | * <p>(Immutable)</p> |
||
| 5546 | * |
||
| 5547 | * @phpstan-param T $value |
||
| 5548 | * @phpstan-return static<TKey,T> |
||
| 5549 | * @psalm-mutation-free |
||
| 5550 | */ |
||
| 5551 | 8 | public function removeValue($value): self |
|
| 5575 | |||
| 5576 | /** |
||
| 5577 | * Generate array of repeated arrays. |
||
| 5578 | * |
||
| 5579 | * @param int $times <p>How many times has to be repeated.</p> |
||
| 5580 | * |
||
| 5581 | * @return static |
||
| 5582 | * <p>(Immutable)</p> |
||
| 5583 | * |
||
| 5584 | * @phpstan-return static<TKey,T> |
||
| 5585 | * @psalm-mutation-free |
||
| 5586 | */ |
||
| 5587 | 1 | public function repeat($times): self |
|
| 5599 | |||
| 5600 | /** |
||
| 5601 | * Replace a key with a new key/value pair. |
||
| 5602 | * |
||
| 5603 | * EXAMPLE: <code> |
||
| 5604 | * $arrayy = a([1 => 'foo', 2 => 'foo2', 3 => 'bar']); |
||
| 5605 | * $arrayy->replace(2, 'notfoo', 'notbar'); // Arrayy[1 => 'foo', 'notfoo' => 'notbar', 3 => 'bar'] |
||
| 5606 | * </code> |
||
| 5607 | * |
||
| 5608 | * @param mixed $oldKey |
||
| 5609 | * @param mixed $newKey |
||
| 5610 | * @param mixed $newValue |
||
| 5611 | * |
||
| 5612 | * @return static |
||
| 5613 | * <p>(Immutable)</p> |
||
| 5614 | * |
||
| 5615 | * @phpstan-return static<TKey,T> |
||
| 5616 | * @psalm-mutation-free |
||
| 5617 | */ |
||
| 5618 | 5 | public function replace($oldKey, $newKey, $newValue): self |
|
| 5628 | |||
| 5629 | /** |
||
| 5630 | * Create an array using the current array as values and the other array as keys. |
||
| 5631 | * |
||
| 5632 | * EXAMPLE: <code> |
||
| 5633 | * $firstArray = [ |
||
| 5634 | * 1 => 'one', |
||
| 5635 | * 2 => 'two', |
||
| 5636 | * 3 => 'three', |
||
| 5637 | * ]; |
||
| 5638 | * $secondArray = [ |
||
| 5639 | * 'one' => 1, |
||
| 5640 | * 1 => 'one', |
||
| 5641 | * 2 => 2, |
||
| 5642 | * ]; |
||
| 5643 | * $arrayy = a($firstArray); |
||
| 5644 | * $arrayy->replaceAllKeys($secondArray); // Arrayy[1 => "one", 'one' => "two", 2 => "three"] |
||
| 5645 | * </code> |
||
| 5646 | * |
||
| 5647 | * @param int[]|string[] $keys <p>An array of keys.</p> |
||
| 5648 | * |
||
| 5649 | * @return static |
||
| 5650 | * <p>(Immutable) Arrayy object with keys from the other array, empty Arrayy object if the number of elements |
||
| 5651 | * for each array isn't equal or if the arrays are empty. |
||
| 5652 | * </p> |
||
| 5653 | * |
||
| 5654 | * @phpstan-param array<array-key,TKey> $keys |
||
| 5655 | * @phpstan-return static<TKey,T> |
||
| 5656 | * @psalm-mutation-free |
||
| 5657 | */ |
||
| 5658 | 2 | View Code Duplication | public function replaceAllKeys(array $keys): self |
| 5671 | |||
| 5672 | /** |
||
| 5673 | * Create an array using the current array as keys and the other array as values. |
||
| 5674 | * |
||
| 5675 | * EXAMPLE: <code> |
||
| 5676 | * $firstArray = [ |
||
| 5677 | * 1 => 'one', |
||
| 5678 | * 2 => 'two', |
||
| 5679 | * 3 => 'three', |
||
| 5680 | * ]; |
||
| 5681 | * $secondArray = [ |
||
| 5682 | * 'one' => 1, |
||
| 5683 | * 1 => 'one', |
||
| 5684 | * 2 => 2, |
||
| 5685 | * ]; |
||
| 5686 | * $arrayy = a($firstArray); |
||
| 5687 | * $arrayy->replaceAllValues($secondArray); // Arrayy['one' => 1, 'two' => 'one', 'three' => 2] |
||
| 5688 | * </code> |
||
| 5689 | * |
||
| 5690 | * @param array $array <p>An array of values.</p> |
||
| 5691 | * |
||
| 5692 | * @return static |
||
| 5693 | * <p>(Immutable) Arrayy object with values from the other array, empty Arrayy object if the number of elements |
||
| 5694 | * for each array isn't equal or if the arrays are empty. |
||
| 5695 | * </p> |
||
| 5696 | * |
||
| 5697 | * @phpstan-param array<array-key,T> $array |
||
| 5698 | * @phpstan-return static<TKey,T> |
||
| 5699 | * @psalm-mutation-free |
||
| 5700 | */ |
||
| 5701 | 2 | View Code Duplication | public function replaceAllValues(array $array): self |
| 5714 | |||
| 5715 | /** |
||
| 5716 | * Replace the keys in an array with another set. |
||
| 5717 | * |
||
| 5718 | * EXAMPLE: <code> |
||
| 5719 | * a([1 => 'bar', 'foo' => 'foo'])->replaceKeys([1 => 2, 'foo' => 'replaced']); // Arrayy[2 => 'bar', 'replaced' => 'foo'] |
||
| 5720 | * </code> |
||
| 5721 | * |
||
| 5722 | * @param array $keys <p>An array of keys matching the array's size.</p> |
||
| 5723 | * |
||
| 5724 | * @return static |
||
| 5725 | * <p>(Immutable)</p> |
||
| 5726 | * |
||
| 5727 | * @phpstan-param array<array-key,TKey> $keys |
||
| 5728 | * @phpstan-return static<TKey,T> |
||
| 5729 | * @psalm-mutation-free |
||
| 5730 | */ |
||
| 5731 | 1 | View Code Duplication | public function replaceKeys(array $keys): self |
| 5745 | |||
| 5746 | /** |
||
| 5747 | * Replace the first matched value in an array. |
||
| 5748 | * |
||
| 5749 | * EXAMPLE: <code> |
||
| 5750 | * $testArray = ['bar', 'foo' => 'foo', 'foobar' => 'foobar']; |
||
| 5751 | * a($testArray)->replaceOneValue('foo', 'replaced'); // Arrayy['bar', 'foo' => 'replaced', 'foobar' => 'foobar'] |
||
| 5752 | * </code> |
||
| 5753 | * |
||
| 5754 | * @param mixed $search <p>The value to replace.</p> |
||
| 5755 | * @param mixed $replacement <p>The value to replace.</p> |
||
| 5756 | * |
||
| 5757 | * @return static |
||
| 5758 | * <p>(Immutable)</p> |
||
| 5759 | * |
||
| 5760 | * @phpstan-return static<TKey,T> |
||
| 5761 | * @psalm-mutation-free |
||
| 5762 | */ |
||
| 5763 | 3 | public function replaceOneValue($search, $replacement = ''): self |
|
| 5778 | |||
| 5779 | /** |
||
| 5780 | * Replace values in the current array. |
||
| 5781 | * |
||
| 5782 | * EXAMPLE: <code> |
||
| 5783 | * $testArray = ['bar', 'foo' => 'foo', 'foobar' => 'foobar']; |
||
| 5784 | * a($testArray)->replaceValues('foo', 'replaced'); // Arrayy['bar', 'foo' => 'replaced', 'foobar' => 'replacedbar'] |
||
| 5785 | * </code> |
||
| 5786 | * |
||
| 5787 | * @param string $search <p>The value to replace.</p> |
||
| 5788 | * @param string $replacement <p>What to replace it with.</p> |
||
| 5789 | * |
||
| 5790 | * @return static |
||
| 5791 | * <p>(Immutable)</p> |
||
| 5792 | * |
||
| 5793 | * @phpstan-return static<TKey,T> |
||
| 5794 | * @psalm-mutation-free |
||
| 5795 | */ |
||
| 5796 | 1 | public function replaceValues($search, $replacement = ''): self |
|
| 5805 | |||
| 5806 | /** |
||
| 5807 | * Get the last elements from index $from until the end of this array. |
||
| 5808 | * |
||
| 5809 | * EXAMPLE: <code> |
||
| 5810 | * a([2 => 'foo', 3 => 'bar', 4 => 'lall'])->rest(2); // Arrayy[0 => 'lall'] |
||
| 5811 | * </code> |
||
| 5812 | * |
||
| 5813 | * @param int $from |
||
| 5814 | * |
||
| 5815 | * @return static |
||
| 5816 | * <p>(Immutable)</p> |
||
| 5817 | * |
||
| 5818 | * @phpstan-return static<TKey,T> |
||
| 5819 | * @psalm-mutation-free |
||
| 5820 | */ |
||
| 5821 | 15 | View Code Duplication | public function rest(int $from = 1): self |
| 5831 | |||
| 5832 | /** |
||
| 5833 | * Return the array in the reverse order. |
||
| 5834 | * |
||
| 5835 | * EXAMPLE: <code> |
||
| 5836 | * a([1, 2, 3])->reverse(); // self[3, 2, 1] |
||
| 5837 | * </code> |
||
| 5838 | * |
||
| 5839 | * @return $this |
||
| 5840 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 5841 | * |
||
| 5842 | * @phpstan-return static<TKey,T> |
||
| 5843 | */ |
||
| 5844 | 9 | public function reverse(): self |
|
| 5852 | |||
| 5853 | /** |
||
| 5854 | * Sort an array in reverse order. |
||
| 5855 | * |
||
| 5856 | * @param int $sort_flags [optional] <p> |
||
| 5857 | * You may modify the behavior of the sort using the optional |
||
| 5858 | * parameter sort_flags, for details |
||
| 5859 | * see sort. |
||
| 5860 | * </p> |
||
| 5861 | * |
||
| 5862 | * @return $this |
||
| 5863 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 5864 | * |
||
| 5865 | * @phpstan-return static<TKey,T> |
||
| 5866 | */ |
||
| 5867 | 4 | public function rsort(int $sort_flags = 0): self |
|
| 5875 | |||
| 5876 | /** |
||
| 5877 | * Sort an array in reverse order. |
||
| 5878 | * |
||
| 5879 | * @param int $sort_flags [optional] <p> |
||
| 5880 | * You may modify the behavior of the sort using the optional |
||
| 5881 | * parameter sort_flags, for details |
||
| 5882 | * see sort. |
||
| 5883 | * </p> |
||
| 5884 | * |
||
| 5885 | * @return $this |
||
| 5886 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 5887 | * |
||
| 5888 | * @phpstan-return static<TKey,T> |
||
| 5889 | * @psalm-mutation-free |
||
| 5890 | */ |
||
| 5891 | 4 | public function rsortImmutable(int $sort_flags = 0): self |
|
| 5902 | |||
| 5903 | /** |
||
| 5904 | * Search for the first index of the current array via $value. |
||
| 5905 | * |
||
| 5906 | * EXAMPLE: <code> |
||
| 5907 | * a(['fòô' => 'bàř', 'lall' => 'bàř'])->searchIndex('bàř'); // Arrayy[0 => 'fòô'] |
||
| 5908 | * </code> |
||
| 5909 | * |
||
| 5910 | * @param mixed $value |
||
| 5911 | * |
||
| 5912 | * @return false|float|int|string |
||
| 5913 | * <p>Will return <b>FALSE</b> if the value can't be found.</p> |
||
| 5914 | * @psalm-mutation-free |
||
| 5915 | */ |
||
| 5916 | 21 | public function searchIndex($value) |
|
| 5926 | |||
| 5927 | /** |
||
| 5928 | * Search for the value of the current array via $index. |
||
| 5929 | * |
||
| 5930 | * EXAMPLE: <code> |
||
| 5931 | * a(['fòô' => 'bàř'])->searchValue('fòô'); // Arrayy[0 => 'bàř'] |
||
| 5932 | * </code> |
||
| 5933 | * |
||
| 5934 | * @param mixed $index |
||
| 5935 | * |
||
| 5936 | * @return static |
||
| 5937 | * <p>(Immutable) Will return a empty Arrayy if the value wasn't found.</p> |
||
| 5938 | * |
||
| 5939 | * @phpstan-return static<TKey,T> |
||
| 5940 | * @psalm-mutation-free |
||
| 5941 | */ |
||
| 5942 | 9 | public function searchValue($index): self |
|
| 5972 | |||
| 5973 | /** |
||
| 5974 | * Set a value for the current array (optional using dot-notation). |
||
| 5975 | * |
||
| 5976 | * EXAMPLE: <code> |
||
| 5977 | * $arrayy = a(['Lars' => ['lastname' => 'Moelleken']]); |
||
| 5978 | * $arrayy->set('Lars.lastname', 'Müller'); // Arrayy['Lars', ['lastname' => 'Müller']]] |
||
| 5979 | * </code> |
||
| 5980 | * |
||
| 5981 | * @param string $key <p>The key to set.</p> |
||
| 5982 | * @param mixed $value <p>Its value.</p> |
||
| 5983 | * |
||
| 5984 | * @return $this |
||
| 5985 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 5986 | * |
||
| 5987 | * @phpstan-param TKey $key |
||
| 5988 | * @phpstan-param T $value |
||
| 5989 | * @phpstan-return static<TKey,T> |
||
| 5990 | */ |
||
| 5991 | 28 | public function set($key, $value): self |
|
| 5997 | |||
| 5998 | /** |
||
| 5999 | * Get a value from a array and set it if it was not. |
||
| 6000 | * |
||
| 6001 | * WARNING: this method only set the value, if the $key is not already set |
||
| 6002 | * |
||
| 6003 | * EXAMPLE: <code> |
||
| 6004 | * $arrayy = a([1 => 1, 2 => 2, 3 => 3]); |
||
| 6005 | * $arrayy->setAndGet(1, 4); // 1 |
||
| 6006 | * $arrayy->setAndGet(0, 4); // 4 |
||
| 6007 | * </code> |
||
| 6008 | * |
||
| 6009 | * @param mixed $key <p>The key</p> |
||
| 6010 | * @param mixed $fallback <p>The default value to set if it isn't.</p> |
||
| 6011 | * |
||
| 6012 | * @return mixed |
||
| 6013 | * <p>(Mutable)</p> |
||
| 6014 | */ |
||
| 6015 | 11 | public function setAndGet($key, $fallback = null) |
|
| 6026 | |||
| 6027 | /** |
||
| 6028 | * Shifts a specified value off the beginning of array. |
||
| 6029 | * |
||
| 6030 | * @return mixed |
||
| 6031 | * <p>(Mutable) A shifted element from the current array.</p> |
||
| 6032 | */ |
||
| 6033 | 5 | public function shift() |
|
| 6039 | |||
| 6040 | /** |
||
| 6041 | * Shuffle the current array. |
||
| 6042 | * |
||
| 6043 | * EXAMPLE: <code> |
||
| 6044 | * a([1 => 'bar', 'foo' => 'foo'])->shuffle(); // e.g.: Arrayy[['foo' => 'foo', 1 => 'bar']] |
||
| 6045 | * </code> |
||
| 6046 | * |
||
| 6047 | * @param bool $secure <p>using a CSPRNG | @link https://paragonie.com/b/JvICXzh_jhLyt4y3</p> |
||
| 6048 | * @param array|null $array [optional] |
||
| 6049 | * |
||
| 6050 | * @return static |
||
| 6051 | * <p>(Immutable)</p> |
||
| 6052 | * |
||
| 6053 | * @phpstan-param array<TKey,T> $array |
||
| 6054 | * @phpstan-return static<TKey,T> |
||
| 6055 | * |
||
| 6056 | * @noinspection BadExceptionsProcessingInspection |
||
| 6057 | * @noinspection NonSecureShuffleUsageInspection |
||
| 6058 | */ |
||
| 6059 | 2 | public function shuffle(bool $secure = false, array $array = null): self |
|
| 6101 | |||
| 6102 | /** |
||
| 6103 | * Count the values from the current array. |
||
| 6104 | * |
||
| 6105 | * alias: for "Arrayy->count()" |
||
| 6106 | * |
||
| 6107 | * @param int $mode |
||
| 6108 | * |
||
| 6109 | * @return int |
||
| 6110 | */ |
||
| 6111 | 20 | public function size(int $mode = \COUNT_NORMAL): int |
|
| 6115 | |||
| 6116 | /** |
||
| 6117 | * Checks whether array has exactly $size items. |
||
| 6118 | * |
||
| 6119 | * @param int $size |
||
| 6120 | * |
||
| 6121 | * @return bool |
||
| 6122 | */ |
||
| 6123 | 1 | public function sizeIs(int $size): bool |
|
| 6139 | |||
| 6140 | /** |
||
| 6141 | * Checks whether array has between $fromSize to $toSize items. $toSize can be |
||
| 6142 | * smaller than $fromSize. |
||
| 6143 | * |
||
| 6144 | * @param int $fromSize |
||
| 6145 | * @param int $toSize |
||
| 6146 | * |
||
| 6147 | * @return bool |
||
| 6148 | */ |
||
| 6149 | 1 | public function sizeIsBetween(int $fromSize, int $toSize): bool |
|
| 6169 | |||
| 6170 | /** |
||
| 6171 | * Checks whether array has more than $size items. |
||
| 6172 | * |
||
| 6173 | * @param int $size |
||
| 6174 | * |
||
| 6175 | * @return bool |
||
| 6176 | */ |
||
| 6177 | 1 | View Code Duplication | public function sizeIsGreaterThan(int $size): bool |
| 6191 | |||
| 6192 | /** |
||
| 6193 | * Checks whether array has less than $size items. |
||
| 6194 | * |
||
| 6195 | * @param int $size |
||
| 6196 | * |
||
| 6197 | * @return bool |
||
| 6198 | */ |
||
| 6199 | 1 | View Code Duplication | public function sizeIsLessThan(int $size): bool |
| 6213 | |||
| 6214 | /** |
||
| 6215 | * Counts all elements in an array, or something in an object. |
||
| 6216 | * |
||
| 6217 | * <p> |
||
| 6218 | * For objects, if you have SPL installed, you can hook into count() by implementing interface {@see Countable}. |
||
| 6219 | * The interface has exactly one method, {@see Countable::count()}, which returns the return value for the count() |
||
| 6220 | * function. Please see the {@see Array} section of the manual for a detailed explanation of how arrays are |
||
| 6221 | * implemented and used in PHP. |
||
| 6222 | * </p> |
||
| 6223 | * |
||
| 6224 | * @return int |
||
| 6225 | * <p> |
||
| 6226 | * The number of elements in var, which is |
||
| 6227 | * typically an array, since anything else will have one |
||
| 6228 | * element. |
||
| 6229 | * </p> |
||
| 6230 | * <p> |
||
| 6231 | * If var is not an array or an object with |
||
| 6232 | * implemented Countable interface, |
||
| 6233 | * 1 will be returned. |
||
| 6234 | * There is one exception, if var is &null;, |
||
| 6235 | * 0 will be returned. |
||
| 6236 | * </p> |
||
| 6237 | * <p> |
||
| 6238 | * Caution: count may return 0 for a variable that isn't set, |
||
| 6239 | * but it may also return 0 for a variable that has been initialized with an |
||
| 6240 | * empty array. Use isset to test if a variable is set. |
||
| 6241 | * </p> |
||
| 6242 | */ |
||
| 6243 | 10 | public function sizeRecursive(): int |
|
| 6247 | |||
| 6248 | /** |
||
| 6249 | * Extract a slice of the array. |
||
| 6250 | * |
||
| 6251 | * @param int $offset <p>Slice begin index.</p> |
||
| 6252 | * @param int|null $length <p>Length of the slice.</p> |
||
| 6253 | * @param bool $preserveKeys <p>Whether array keys are preserved or no.</p> |
||
| 6254 | * |
||
| 6255 | * @return static |
||
| 6256 | * <p>(Immutable) A slice of the original array with length $length.</p> |
||
| 6257 | * |
||
| 6258 | * @phpstan-return static<TKey,T> |
||
| 6259 | * @psalm-mutation-free |
||
| 6260 | */ |
||
| 6261 | 5 | public function slice(int $offset, int $length = null, bool $preserveKeys = false) |
|
| 6274 | |||
| 6275 | /** |
||
| 6276 | * Sort the current array and optional you can keep the keys. |
||
| 6277 | * |
||
| 6278 | * EXAMPLE: <code> |
||
| 6279 | * a(3 => 'd', 2 => 'f', 0 => 'a')->sort(SORT_ASC, SORT_NATURAL, false); // Arrayy[0 => 'a', 1 => 'd', 2 => 'f'] |
||
| 6280 | * </code> |
||
| 6281 | * |
||
| 6282 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 6283 | * @param int $strategy <p>sort_flags => use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 6284 | * <strong>SORT_NATURAL</strong></p> |
||
| 6285 | * @param bool $keepKeys |
||
| 6286 | * |
||
| 6287 | * @return static |
||
| 6288 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 6289 | * |
||
| 6290 | * @phpstan-return static<int|TKey,T> |
||
| 6291 | */ |
||
| 6292 | 20 | public function sort( |
|
| 6306 | |||
| 6307 | /** |
||
| 6308 | * Sort the current array and optional you can keep the keys. |
||
| 6309 | * |
||
| 6310 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 6311 | * @param int $strategy <p>sort_flags => use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 6312 | * <strong>SORT_NATURAL</strong></p> |
||
| 6313 | * @param bool $keepKeys |
||
| 6314 | * |
||
| 6315 | * @return static |
||
| 6316 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 6317 | * |
||
| 6318 | * @phpstan-return static<int|TKey,T> |
||
| 6319 | */ |
||
| 6320 | 12 | public function sortImmutable( |
|
| 6336 | |||
| 6337 | /** |
||
| 6338 | * Sort the current array by key. |
||
| 6339 | * |
||
| 6340 | * EXAMPLE: <code> |
||
| 6341 | * a([1 => 2, 0 => 1])->sortKeys(\SORT_ASC); // Arrayy[0 => 1, 1 => 2] |
||
| 6342 | * </code> |
||
| 6343 | * |
||
| 6344 | * @see http://php.net/manual/en/function.ksort.php |
||
| 6345 | * @see http://php.net/manual/en/function.krsort.php |
||
| 6346 | * |
||
| 6347 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 6348 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 6349 | * <strong>SORT_NATURAL</strong></p> |
||
| 6350 | * |
||
| 6351 | * @return $this |
||
| 6352 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 6353 | * |
||
| 6354 | * @phpstan-return static<TKey,T> |
||
| 6355 | */ |
||
| 6356 | 18 | public function sortKeys( |
|
| 6366 | |||
| 6367 | /** |
||
| 6368 | * Sort the current array by key. |
||
| 6369 | * |
||
| 6370 | * @see http://php.net/manual/en/function.ksort.php |
||
| 6371 | * @see http://php.net/manual/en/function.krsort.php |
||
| 6372 | * |
||
| 6373 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 6374 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 6375 | * <strong>SORT_NATURAL</strong></p> |
||
| 6376 | * |
||
| 6377 | * @return $this |
||
| 6378 | * <p>(Immutable) Return this Arrayy object.</p> |
||
| 6379 | * |
||
| 6380 | * @phpstan-return static<TKey,T> |
||
| 6381 | * @psalm-mutation-free |
||
| 6382 | */ |
||
| 6383 | 8 | public function sortKeysImmutable( |
|
| 6396 | |||
| 6397 | /** |
||
| 6398 | * Sort the current array by value. |
||
| 6399 | * |
||
| 6400 | * EXAMPLE: <code> |
||
| 6401 | * a(3 => 'd', 2 => 'f', 0 => 'a')->sortValueKeepIndex(SORT_ASC, SORT_REGULAR); // Arrayy[0 => 'a', 3 => 'd', 2 => 'f'] |
||
| 6402 | * </code> |
||
| 6403 | * |
||
| 6404 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 6405 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 6406 | * <strong>SORT_NATURAL</strong></p> |
||
| 6407 | * |
||
| 6408 | * @return static |
||
| 6409 | * <p>(Mutable)</p> |
||
| 6410 | * |
||
| 6411 | * @phpstan-return static<int|TKey,T> |
||
| 6412 | */ |
||
| 6413 | 1 | public function sortValueKeepIndex( |
|
| 6419 | |||
| 6420 | /** |
||
| 6421 | * Sort the current array by value. |
||
| 6422 | * |
||
| 6423 | * EXAMPLE: <code> |
||
| 6424 | * a(3 => 'd', 2 => 'f', 0 => 'a')->sortValueNewIndex(SORT_ASC, SORT_NATURAL); // Arrayy[0 => 'a', 1 => 'd', 2 => 'f'] |
||
| 6425 | * </code> |
||
| 6426 | * |
||
| 6427 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 6428 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 6429 | * <strong>SORT_NATURAL</strong></p> |
||
| 6430 | * |
||
| 6431 | * @return static |
||
| 6432 | * <p>(Mutable)</p> |
||
| 6433 | * |
||
| 6434 | * @phpstan-return static<int|TKey,T> |
||
| 6435 | */ |
||
| 6436 | 1 | public function sortValueNewIndex($direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
| 6440 | |||
| 6441 | /** |
||
| 6442 | * Sort a array by value or by a closure. |
||
| 6443 | * |
||
| 6444 | * - If the sorter is null, the array is sorted naturally. |
||
| 6445 | * - Associative (string) keys will be maintained, but numeric keys will be re-indexed. |
||
| 6446 | * |
||
| 6447 | * EXAMPLE: <code> |
||
| 6448 | * $testArray = range(1, 5); |
||
| 6449 | * $under = a($testArray)->sorter( |
||
| 6450 | * function ($value) { |
||
| 6451 | * return $value % 2 === 0; |
||
| 6452 | * } |
||
| 6453 | * ); |
||
| 6454 | * var_dump($under); // Arrayy[1, 3, 5, 2, 4] |
||
| 6455 | * </code> |
||
| 6456 | * |
||
| 6457 | * @param callable|mixed|null $sorter |
||
| 6458 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or |
||
| 6459 | * <strong>SORT_DESC</strong></p> |
||
| 6460 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 6461 | * <strong>SORT_NATURAL</strong></p> |
||
| 6462 | * |
||
| 6463 | * @return static |
||
| 6464 | * <p>(Immutable)</p> |
||
| 6465 | * |
||
| 6466 | * @pslam-param callable|T|null $sorter |
||
| 6467 | * @phpstan-return static<TKey,T> |
||
| 6468 | * @psalm-mutation-free |
||
| 6469 | */ |
||
| 6470 | 1 | public function sorter($sorter = null, $direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
| 6511 | |||
| 6512 | /** |
||
| 6513 | * @param int $offset |
||
| 6514 | * @param int|null $length |
||
| 6515 | * @param array $replacement |
||
| 6516 | * |
||
| 6517 | * @return static |
||
| 6518 | * <p>(Immutable)</p> |
||
| 6519 | * |
||
| 6520 | * @phpstan-param array<mixed,T> $replacement |
||
| 6521 | * @phpstan-return static<TKey,T> |
||
| 6522 | * @psalm-mutation-free |
||
| 6523 | */ |
||
| 6524 | 1 | public function splice(int $offset, int $length = null, $replacement = []): self |
|
| 6541 | |||
| 6542 | /** |
||
| 6543 | * Split an array in the given amount of pieces. |
||
| 6544 | * |
||
| 6545 | * EXAMPLE: <code> |
||
| 6546 | * a(['a' => 1, 'b' => 2])->split(2, true); // Arrayy[['a' => 1], ['b' => 2]] |
||
| 6547 | * </code> |
||
| 6548 | * |
||
| 6549 | * @param int $numberOfPieces |
||
| 6550 | * @param bool $keepKeys |
||
| 6551 | * |
||
| 6552 | * @return static |
||
| 6553 | * <p>(Immutable)</p> |
||
| 6554 | * |
||
| 6555 | * @phpstan-return static<TKey,T> |
||
| 6556 | * @psalm-mutation-free |
||
| 6557 | */ |
||
| 6558 | 1 | public function split(int $numberOfPieces = 2, bool $keepKeys = false): self |
|
| 6614 | |||
| 6615 | /** |
||
| 6616 | * Strip all empty items from the current array. |
||
| 6617 | * |
||
| 6618 | * EXAMPLE: <code> |
||
| 6619 | * a(['a' => 1, 'b' => ''])->stripEmpty(); // Arrayy[['a' => 1]] |
||
| 6620 | * </code> |
||
| 6621 | * |
||
| 6622 | * @return static |
||
| 6623 | * <p>(Immutable)</p> |
||
| 6624 | * |
||
| 6625 | * @phpstan-return static<TKey,T> |
||
| 6626 | * @psalm-mutation-free |
||
| 6627 | */ |
||
| 6628 | 1 | public function stripEmpty(): self |
|
| 6640 | |||
| 6641 | /** |
||
| 6642 | * Swap two values between positions by key. |
||
| 6643 | * |
||
| 6644 | * EXAMPLE: <code> |
||
| 6645 | * a(['a' => 1, 'b' => ''])->swap('a', 'b'); // Arrayy[['a' => '', 'b' => 1]] |
||
| 6646 | * </code> |
||
| 6647 | * |
||
| 6648 | * @param int|string $swapA <p>a key in the array</p> |
||
| 6649 | * @param int|string $swapB <p>a key in the array</p> |
||
| 6650 | * |
||
| 6651 | * @return static |
||
| 6652 | * <p>(Immutable)</p> |
||
| 6653 | * |
||
| 6654 | * @phpstan-return static<TKey,T> |
||
| 6655 | * @psalm-mutation-free |
||
| 6656 | */ |
||
| 6657 | 1 | public function swap($swapA, $swapB): self |
|
| 6669 | |||
| 6670 | /** |
||
| 6671 | * Get the current array from the "Arrayy"-object. |
||
| 6672 | * alias for "getArray()" |
||
| 6673 | * |
||
| 6674 | * @param bool $convertAllArrayyElements <p> |
||
| 6675 | * Convert all Child-"Arrayy" objects also to arrays. |
||
| 6676 | * </p> |
||
| 6677 | * @param bool $preserveKeys <p> |
||
| 6678 | * e.g.: A generator maybe return the same key more then once, |
||
| 6679 | * so maybe you will ignore the keys. |
||
| 6680 | * </p> |
||
| 6681 | * |
||
| 6682 | * @return array |
||
| 6683 | * |
||
| 6684 | * @phpstan-return array<TKey,T> |
||
| 6685 | * @psalm-mutation-free |
||
| 6686 | */ |
||
| 6687 | 941 | public function toArray( |
|
| 6716 | |||
| 6717 | /** |
||
| 6718 | * Get the current array from the "Arrayy"-object as list. |
||
| 6719 | * |
||
| 6720 | * @param bool $convertAllArrayyElements <p> |
||
| 6721 | * Convert all Child-"Arrayy" objects also to arrays. |
||
| 6722 | * </p> |
||
| 6723 | * |
||
| 6724 | * @return array |
||
| 6725 | * |
||
| 6726 | * @phpstan-return list<mixed>|list<T> |
||
| 6727 | * @psalm-mutation-free |
||
| 6728 | */ |
||
| 6729 | 1 | public function toList(bool $convertAllArrayyElements = false): array |
|
| 6736 | |||
| 6737 | /** |
||
| 6738 | * Convert the current array to JSON. |
||
| 6739 | * |
||
| 6740 | * EXAMPLE: <code> |
||
| 6741 | * a(['bar', ['foo']])->toJson(); // '["bar",{"1":"foo"}]' |
||
| 6742 | * </code> |
||
| 6743 | * |
||
| 6744 | * @param int $options [optional] <p>e.g. JSON_PRETTY_PRINT</p> |
||
| 6745 | * @param int $depth [optional] <p>Set the maximum depth. Must be greater than zero.</p> |
||
| 6746 | * |
||
| 6747 | * @return string |
||
| 6748 | */ |
||
| 6749 | 12 | public function toJson(int $options = 0, int $depth = 512): string |
|
| 6758 | |||
| 6759 | /** |
||
| 6760 | * @param string[]|null $items [optional] |
||
| 6761 | * @param string[] $helper [optional] |
||
| 6762 | * |
||
| 6763 | * @return static|static[] |
||
| 6764 | * |
||
| 6765 | * @phpstan-return static<int, static<TKey,T>> |
||
| 6766 | */ |
||
| 6767 | 1 | public function toPermutation(array $items = null, array $helper = []): self |
|
| 6800 | |||
| 6801 | /** |
||
| 6802 | * Implodes array to a string with specified separator. |
||
| 6803 | * |
||
| 6804 | * @param string $separator [optional] <p>The element's separator.</p> |
||
| 6805 | * |
||
| 6806 | * @return string |
||
| 6807 | * <p>The string representation of array, separated by ",".</p> |
||
| 6808 | */ |
||
| 6809 | 19 | public function toString(string $separator = ','): string |
|
| 6813 | |||
| 6814 | /** |
||
| 6815 | * Return a duplicate free copy of the current array. |
||
| 6816 | * |
||
| 6817 | * EXAMPLE: <code> |
||
| 6818 | * a([2 => 1, 3 => 2, 4 => 2])->uniqueNewIndex(); // Arrayy[1, 2] |
||
| 6819 | * </code> |
||
| 6820 | * |
||
| 6821 | * @return $this |
||
| 6822 | * <p>(Mutable)</p> |
||
| 6823 | * |
||
| 6824 | * @phpstan-return static<int,T> |
||
| 6825 | */ |
||
| 6826 | 13 | public function uniqueNewIndex(): self |
|
| 6844 | |||
| 6845 | /** |
||
| 6846 | * Return a duplicate free copy of the current array. (with the old keys) |
||
| 6847 | * |
||
| 6848 | * EXAMPLE: <code> |
||
| 6849 | * a([2 => 1, 3 => 2, 4 => 2])->uniqueNewIndex(); // Arrayy[2 => 1, 3 => 2] |
||
| 6850 | * </code> |
||
| 6851 | * |
||
| 6852 | * @return $this |
||
| 6853 | * <p>(Mutable)</p> |
||
| 6854 | * |
||
| 6855 | * @phpstan-return static<TKey,T> |
||
| 6856 | */ |
||
| 6857 | 11 | public function uniqueKeepIndex(): self |
|
| 6883 | |||
| 6884 | /** |
||
| 6885 | * alias: for "Arrayy->uniqueNewIndex()" |
||
| 6886 | * |
||
| 6887 | * @return static |
||
| 6888 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
| 6889 | * |
||
| 6890 | * @see Arrayy::unique() |
||
| 6891 | * |
||
| 6892 | * @phpstan-return static<int,T> |
||
| 6893 | */ |
||
| 6894 | 13 | public function unique(): self |
|
| 6898 | |||
| 6899 | /** |
||
| 6900 | * Prepends one or more values to the beginning of array at once. |
||
| 6901 | * |
||
| 6902 | * @param mixed ...$args |
||
| 6903 | * |
||
| 6904 | * @return $this |
||
| 6905 | * <p>(Mutable) Return this Arrayy object, with prepended elements to the beginning of array.</p> |
||
| 6906 | * |
||
| 6907 | * @phpstan-param array<TKey,T> ...$args |
||
| 6908 | * @phpstan-return static<TKey,T> |
||
| 6909 | */ |
||
| 6910 | 6 | View Code Duplication | public function unshift(...$args): self |
| 6928 | |||
| 6929 | /** |
||
| 6930 | * Tests whether the given closure return something valid for all elements of this array. |
||
| 6931 | * |
||
| 6932 | * @param \Closure $closure the predicate |
||
| 6933 | * |
||
| 6934 | * @return bool |
||
| 6935 | * <p>TRUE, if the predicate yields TRUE for all elements, FALSE otherwise.</p> |
||
| 6936 | * |
||
| 6937 | * @phpstan-param \Closure(T=,TKey=):bool $closure |
||
| 6938 | */ |
||
| 6939 | 1 | View Code Duplication | public function validate(\Closure $closure): bool |
| 6949 | |||
| 6950 | /** |
||
| 6951 | * Get all values from a array. |
||
| 6952 | * |
||
| 6953 | * EXAMPLE: <code> |
||
| 6954 | * $arrayy = a([1 => 'foo', 2 => 'foo2', 3 => 'bar']); |
||
| 6955 | * $arrayyTmp->values(); // Arrayy[0 => 'foo', 1 => 'foo2', 2 => 'bar'] |
||
| 6956 | * </code> |
||
| 6957 | * |
||
| 6958 | * @return static |
||
| 6959 | * <p>(Immutable)</p> |
||
| 6960 | * |
||
| 6961 | * @phpstan-return static<TKey,T> |
||
| 6962 | * @psalm-mutation-free |
||
| 6963 | */ |
||
| 6964 | 2 | public function values(): self |
|
| 6977 | |||
| 6978 | /** |
||
| 6979 | * Apply the given function to every element in the array, discarding the results. |
||
| 6980 | * |
||
| 6981 | * EXAMPLE: <code> |
||
| 6982 | * $callable = function (&$value, $key) { |
||
| 6983 | * $value = $key; |
||
| 6984 | * }; |
||
| 6985 | * $arrayy = a([1, 2, 3]); |
||
| 6986 | * $arrayy->walk($callable); // Arrayy[0, 1, 2] |
||
| 6987 | * </code> |
||
| 6988 | * |
||
| 6989 | * @param callable $callable |
||
| 6990 | * @param bool $recursive [optional] <p>Whether array will be walked recursively or no</p> |
||
| 6991 | * @param mixed $userData [optional] <p> |
||
| 6992 | * If the optional $userData parameter is supplied, |
||
| 6993 | * it will be passed as the third parameter to the $callable. |
||
| 6994 | * </p> |
||
| 6995 | * |
||
| 6996 | * @return $this |
||
| 6997 | * <p>(Mutable) Return this Arrayy object, with modified elements.</p> |
||
| 6998 | * |
||
| 6999 | * @phpstan-return static<TKey,T> |
||
| 7000 | */ |
||
| 7001 | 12 | public function walk( |
|
| 7027 | |||
| 7028 | /** |
||
| 7029 | * Returns a collection of matching items. |
||
| 7030 | * |
||
| 7031 | * @param string $keyOrPropertyOrMethod the property or method to evaluate |
||
| 7032 | * @param mixed $value the value to match |
||
| 7033 | * |
||
| 7034 | * @throws \InvalidArgumentException if property or method is not defined |
||
| 7035 | * |
||
| 7036 | * @return static |
||
| 7037 | * |
||
| 7038 | * @phpstan-return static<TKey,T> |
||
| 7039 | */ |
||
| 7040 | 1 | public function where(string $keyOrPropertyOrMethod, $value): self |
|
| 7053 | |||
| 7054 | /** |
||
| 7055 | * Convert an array into a object. |
||
| 7056 | * |
||
| 7057 | * @param array $array |
||
| 7058 | * |
||
| 7059 | * @return \stdClass |
||
| 7060 | * |
||
| 7061 | * @phpstan-param array<int|string,mixed> $array |
||
| 7062 | */ |
||
| 7063 | 4 | final protected static function arrayToObject(array $array = []): \stdClass |
|
| 7082 | |||
| 7083 | /** |
||
| 7084 | * @param array|\Generator|null $input <p> |
||
| 7085 | * An array containing keys to return. |
||
| 7086 | * </p> |
||
| 7087 | * @param mixed|null $search_values [optional] <p> |
||
| 7088 | * If specified, then only keys containing these values are returned. |
||
| 7089 | * </p> |
||
| 7090 | * @param bool $strict [optional] <p> |
||
| 7091 | * Determines if strict comparison (===) should be used during the |
||
| 7092 | * search. |
||
| 7093 | * </p> |
||
| 7094 | * |
||
| 7095 | * @return array |
||
| 7096 | * <p>An array of all the keys in input.</p> |
||
| 7097 | * |
||
| 7098 | * @phpstan-param array<mixed>|null $input |
||
| 7099 | * @phpstan-return array<mixed> |
||
| 7100 | * @psalm-mutation-free |
||
| 7101 | */ |
||
| 7102 | 11 | protected function array_keys_recursive( |
|
| 7163 | |||
| 7164 | /** |
||
| 7165 | * @param mixed $path |
||
| 7166 | * @param callable $callable |
||
| 7167 | * @param array|null $currentOffset |
||
| 7168 | * |
||
| 7169 | * @return void |
||
| 7170 | * |
||
| 7171 | * @phpstan-param array<TKey,T>|null $currentOffset |
||
| 7172 | * @psalm-mutation-free |
||
| 7173 | */ |
||
| 7174 | 10 | protected function callAtPath($path, $callable, &$currentOffset = null) |
|
| 7203 | |||
| 7204 | /** |
||
| 7205 | * Extracts the value of the given property or method from the object. |
||
| 7206 | * |
||
| 7207 | * @param static $object <p>The object to extract the value from.</p> |
||
| 7208 | * @param string $keyOrPropertyOrMethod <p>The property or method for which the |
||
| 7209 | * value should be extracted.</p> |
||
| 7210 | * |
||
| 7211 | * @throws \InvalidArgumentException if the method or property is not defined |
||
| 7212 | * |
||
| 7213 | * @return mixed |
||
| 7214 | * <p>The value extracted from the specified property or method.</p> |
||
| 7215 | * |
||
| 7216 | * @phpstan-param self<TKey,T> $object |
||
| 7217 | */ |
||
| 7218 | 1 | final protected function extractValue(self $object, string $keyOrPropertyOrMethod) |
|
| 7240 | |||
| 7241 | /** |
||
| 7242 | * create a fallback for array |
||
| 7243 | * |
||
| 7244 | * 1. use the current array, if it's a array |
||
| 7245 | * 2. fallback to empty array, if there is nothing |
||
| 7246 | * 3. call "getArray()" on object, if there is a "Arrayy"-object |
||
| 7247 | * 4. call "createFromObject()" on object, if there is a "\Traversable"-object |
||
| 7248 | * 5. call "__toArray()" on object, if the method exists |
||
| 7249 | * 6. cast a string or object with "__toString()" into an array |
||
| 7250 | * 7. throw a "InvalidArgumentException"-Exception |
||
| 7251 | * |
||
| 7252 | * @param mixed $data |
||
| 7253 | * |
||
| 7254 | * @throws \InvalidArgumentException |
||
| 7255 | * |
||
| 7256 | * @return array |
||
| 7257 | * |
||
| 7258 | * @phpstan-return array<mixed>|array<TKey,T> |
||
| 7259 | */ |
||
| 7260 | 1212 | protected function fallbackForArray(&$data): array |
|
| 7270 | |||
| 7271 | /** |
||
| 7272 | * @param bool $preserveKeys <p> |
||
| 7273 | * e.g.: A generator maybe return the same key more then once, |
||
| 7274 | * so maybe you will ignore the keys. |
||
| 7275 | * </p> |
||
| 7276 | * |
||
| 7277 | * @return bool |
||
| 7278 | * |
||
| 7279 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
| 7280 | * @psalm-mutation-free :/ |
||
| 7281 | */ |
||
| 7282 | 1121 | protected function generatorToArray(bool $preserveKeys = true) |
|
| 7293 | |||
| 7294 | /** |
||
| 7295 | * Get correct PHP constant for direction. |
||
| 7296 | * |
||
| 7297 | * @param int|string $direction |
||
| 7298 | * |
||
| 7299 | * @return int |
||
| 7300 | * @psalm-mutation-free |
||
| 7301 | */ |
||
| 7302 | 43 | protected function getDirection($direction): int |
|
| 7324 | |||
| 7325 | /** |
||
| 7326 | * @return TypeCheckInterface[] |
||
| 7327 | * |
||
| 7328 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
| 7329 | */ |
||
| 7330 | 24 | protected function getPropertiesFromPhpDoc() |
|
| 7385 | |||
| 7386 | /** |
||
| 7387 | * @param mixed $glue |
||
| 7388 | * @param mixed $pieces |
||
| 7389 | * @param bool $useKeys |
||
| 7390 | * |
||
| 7391 | * @return string |
||
| 7392 | * |
||
| 7393 | * @phpstan-param scalar|object|self<TKey|T>|array<TKey,T> $pieces |
||
| 7394 | * @psalm-mutation-free |
||
| 7395 | */ |
||
| 7396 | 36 | protected function implode_recursive( |
|
| 7433 | |||
| 7434 | /** |
||
| 7435 | * @param mixed $needle <p> |
||
| 7436 | * The searched value. |
||
| 7437 | * </p> |
||
| 7438 | * <p> |
||
| 7439 | * If needle is a string, the comparison is done |
||
| 7440 | * in a case-sensitive manner. |
||
| 7441 | * </p> |
||
| 7442 | * @param array|\Generator|null $haystack <p> |
||
| 7443 | * The array. |
||
| 7444 | * </p> |
||
| 7445 | * @param bool $strict [optional] <p> |
||
| 7446 | * If the third parameter strict is set to true |
||
| 7447 | * then the in_array function will also check the |
||
| 7448 | * types of the |
||
| 7449 | * needle in the haystack. |
||
| 7450 | * </p> |
||
| 7451 | * |
||
| 7452 | * @return bool |
||
| 7453 | * <p>true if needle is found in the array, false otherwise</p> |
||
| 7454 | * |
||
| 7455 | * @phpstan-param (array&T)|array<TKey,T>|\Generator<TKey,T>|null $haystack |
||
| 7456 | * @psalm-mutation-free |
||
| 7457 | */ |
||
| 7458 | 19 | protected function in_array_recursive($needle, $haystack = null, $strict = true): bool |
|
| 7483 | |||
| 7484 | /** |
||
| 7485 | * @param mixed $data |
||
| 7486 | * |
||
| 7487 | * @return array<mixed>|null |
||
| 7488 | */ |
||
| 7489 | 1212 | protected function internalGetArray(&$data) |
|
| 7540 | |||
| 7541 | /** |
||
| 7542 | * Internal mechanics of remove method. |
||
| 7543 | * |
||
| 7544 | * @param mixed $key |
||
| 7545 | * |
||
| 7546 | * @return bool |
||
| 7547 | */ |
||
| 7548 | 22 | protected function internalRemove($key): bool |
|
| 7581 | |||
| 7582 | /** |
||
| 7583 | * Internal mechanic of set method. |
||
| 7584 | * |
||
| 7585 | * @param int|string|null $key |
||
| 7586 | * @param mixed $value |
||
| 7587 | * @param bool $checkProperties |
||
| 7588 | * |
||
| 7589 | * @return bool |
||
| 7590 | */ |
||
| 7591 | 1062 | protected function internalSet( |
|
| 7650 | |||
| 7651 | /** |
||
| 7652 | * Convert a object into an array. |
||
| 7653 | * |
||
| 7654 | * @param mixed|object $object |
||
| 7655 | * |
||
| 7656 | * @return array|mixed |
||
| 7657 | * |
||
| 7658 | * @psalm-mutation-free |
||
| 7659 | */ |
||
| 7660 | 5 | protected static function objectToArray($object) |
|
| 7673 | |||
| 7674 | /** |
||
| 7675 | * @param array $data |
||
| 7676 | * @param bool $checkPropertiesInConstructor |
||
| 7677 | * |
||
| 7678 | * @return void |
||
| 7679 | * |
||
| 7680 | * @phpstan-param array<mixed,T> $data |
||
| 7681 | */ |
||
| 7682 | 1210 | protected function setInitialValuesAndProperties(array &$data, bool $checkPropertiesInConstructor) |
|
| 7727 | |||
| 7728 | /** |
||
| 7729 | * sorting keys |
||
| 7730 | * |
||
| 7731 | * @param array $elements |
||
| 7732 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 7733 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 7734 | * <strong>SORT_NATURAL</strong></p> |
||
| 7735 | * |
||
| 7736 | * @return $this |
||
| 7737 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 7738 | * |
||
| 7739 | * @phpstan-param array<mixed|TKey,T> $elements |
||
| 7740 | * @phpstan-return static<TKey,T> |
||
| 7741 | */ |
||
| 7742 | 18 | protected function sorterKeys( |
|
| 7763 | |||
| 7764 | /** |
||
| 7765 | * @param array $elements <p>Warning: used as reference</p> |
||
| 7766 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 7767 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 7768 | * <strong>SORT_NATURAL</strong></p> |
||
| 7769 | * @param bool $keepKeys |
||
| 7770 | * |
||
| 7771 | * @return $this |
||
| 7772 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 7773 | * |
||
| 7774 | * @phpstan-param array<mixed|TKey,T> $elements |
||
| 7775 | * @phpstan-return static<int|TKey,T> |
||
| 7776 | */ |
||
| 7777 | 24 | protected function sorting( |
|
| 7811 | |||
| 7812 | /** |
||
| 7813 | * @param array $array |
||
| 7814 | * |
||
| 7815 | * @return array |
||
| 7816 | * |
||
| 7817 | * @psalm-mutation-free |
||
| 7818 | */ |
||
| 7819 | 25 | private function getArrayRecursiveHelperArrayy(array $array) |
|
| 7841 | |||
| 7842 | /** |
||
| 7843 | * @param int|string|null $key |
||
| 7844 | * @param mixed $value |
||
| 7845 | * |
||
| 7846 | * @return void |
||
| 7847 | */ |
||
| 7848 | 117 | private function checkType($key, $value) |
|
| 7866 | } |
||
| 7867 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..