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 |
||
| 23 | class Arrayy extends \ArrayObject implements \IteratorAggregate, \ArrayAccess, \Serializable, \JsonSerializable, \Countable |
||
| 24 | { |
||
| 25 | const ARRAYY_HELPER_TYPES_FOR_ALL_PROPERTIES = '!!!!Arrayy_Helper_Types_For_All_Properties!!!!'; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var array |
||
| 29 | */ |
||
| 30 | protected $array = []; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var \Arrayy\ArrayyRewindableGenerator|null |
||
| 34 | */ |
||
| 35 | protected $generator; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @var string |
||
| 39 | * |
||
| 40 | * @psalm-var class-string<\ArrayIterator> |
||
| 41 | */ |
||
| 42 | protected $iteratorClass = ArrayyIterator::class; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var string |
||
| 46 | */ |
||
| 47 | protected $pathSeparator = '.'; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @var bool |
||
| 51 | */ |
||
| 52 | protected $checkPropertyTypes = false; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @var bool |
||
| 56 | */ |
||
| 57 | protected $checkForMissingPropertiesInConstructor = false; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @var bool |
||
| 61 | */ |
||
| 62 | protected $checkPropertiesMismatchInConstructor = false; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @var bool |
||
| 66 | */ |
||
| 67 | protected $checkPropertiesMismatch = true; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @var array<TypeCheckInterface>|\Arrayy\Type\TypeInterface|TypeCheckArray<TypeCheckInterface> |
||
| 71 | */ |
||
| 72 | protected $properties = []; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Initializes |
||
| 76 | * |
||
| 77 | * @param mixed $data <p> |
||
| 78 | * Should be an array or a generator, otherwise it will try |
||
| 79 | * to convert it into an array. |
||
| 80 | * </p> |
||
| 81 | * @param string $iteratorClass optional <p> |
||
| 82 | * You can overwrite the ArrayyIterator, but mostly you don't |
||
| 83 | * need this option. |
||
| 84 | * </p> |
||
| 85 | * @param bool $checkPropertiesInConstructor optional <p> |
||
| 86 | * You need to extend the "Arrayy"-class and you need to set |
||
| 87 | * the $checkPropertiesMismatchInConstructor class property |
||
| 88 | * to |
||
| 89 | * true, otherwise this option didn't not work anyway. |
||
| 90 | * </p> |
||
| 91 | * |
||
| 92 | * @psalm-param class-string<\ArrayIterator> $iteratorClass |
||
| 93 | */ |
||
| 94 | 1053 | public function __construct( |
|
| 95 | $data = [], |
||
| 96 | string $iteratorClass = ArrayyIterator::class, |
||
| 97 | bool $checkPropertiesInConstructor = true |
||
| 98 | ) { |
||
| 99 | 1053 | $data = $this->fallbackForArray($data); |
|
| 100 | |||
| 101 | // used only for serialize + unserialize, all other methods are overwritten |
||
| 102 | 1051 | parent::__construct([], 0, $iteratorClass); |
|
| 103 | |||
| 104 | 1051 | $this->setInitialValuesAndProperties($data, $checkPropertiesInConstructor); |
|
| 105 | |||
| 106 | 1044 | $this->setIteratorClass($iteratorClass); |
|
| 107 | 1044 | } |
|
| 108 | |||
| 109 | /** |
||
| 110 | * Call object as function. |
||
| 111 | * |
||
| 112 | * @param mixed $key |
||
| 113 | * |
||
| 114 | * @return mixed |
||
| 115 | */ |
||
| 116 | 1 | public function __invoke($key = null) |
|
| 117 | { |
||
| 118 | 1 | if ($key !== null) { |
|
| 119 | 1 | $this->generatorToArray(); |
|
| 120 | |||
| 121 | 1 | return $this->array[$key] ?? false; |
|
| 122 | } |
||
| 123 | |||
| 124 | return $this->getArray(); |
||
| 125 | } |
||
| 126 | |||
| 127 | /** |
||
| 128 | * Whether or not an element exists by key. |
||
| 129 | * |
||
| 130 | * @param mixed $key |
||
| 131 | * |
||
| 132 | * @return bool |
||
| 133 | * <p>True is the key/index exists, otherwise false.</p> |
||
| 134 | */ |
||
| 135 | public function __isset($key): bool |
||
| 136 | { |
||
| 137 | return $this->offsetExists($key); |
||
| 138 | } |
||
| 139 | |||
| 140 | /** |
||
| 141 | * Assigns a value to the specified element. |
||
| 142 | * |
||
| 143 | * @param mixed $key |
||
| 144 | * @param mixed $value |
||
| 145 | * |
||
| 146 | * @return void |
||
| 147 | */ |
||
| 148 | 2 | public function __set($key, $value) |
|
| 149 | { |
||
| 150 | 2 | $this->internalSet($key, $value); |
|
| 151 | 2 | } |
|
| 152 | |||
| 153 | /** |
||
| 154 | * magic to string |
||
| 155 | * |
||
| 156 | * @return string |
||
| 157 | */ |
||
| 158 | 15 | public function __toString(): string |
|
| 159 | { |
||
| 160 | 15 | return $this->toString(); |
|
| 161 | } |
||
| 162 | |||
| 163 | /** |
||
| 164 | * Unset element by key. |
||
| 165 | * |
||
| 166 | * @param mixed $key |
||
| 167 | */ |
||
| 168 | public function __unset($key) |
||
| 169 | { |
||
| 170 | $this->internalRemove($key); |
||
| 171 | } |
||
| 172 | |||
| 173 | /** |
||
| 174 | * Get a value by key. |
||
| 175 | * |
||
| 176 | * @param mixed $key |
||
| 177 | * |
||
| 178 | * @return mixed |
||
| 179 | * <p>Get a Value from the current array.</p> |
||
| 180 | */ |
||
| 181 | 4 | public function &__get($key) |
|
| 182 | { |
||
| 183 | 4 | $return = $this->get($key); |
|
| 184 | |||
| 185 | 4 | if (\is_array($return) === true) { |
|
| 186 | return static::create($return, $this->iteratorClass, false); |
||
| 187 | } |
||
| 188 | |||
| 189 | 4 | return $return; |
|
| 190 | } |
||
| 191 | |||
| 192 | /** |
||
| 193 | * alias: for "Arrayy->append()" |
||
| 194 | * |
||
| 195 | * @param mixed $value |
||
| 196 | * |
||
| 197 | * @return static |
||
| 198 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
| 199 | * |
||
| 200 | * @see Arrayy::append() |
||
| 201 | */ |
||
| 202 | 3 | public function add($value) |
|
| 203 | { |
||
| 204 | 3 | return $this->append($value); |
|
| 205 | } |
||
| 206 | |||
| 207 | /** |
||
| 208 | * Append a (key) + value to the current array. |
||
| 209 | * |
||
| 210 | * @param mixed $value |
||
| 211 | * @param mixed $key |
||
| 212 | * |
||
| 213 | * @return static |
||
| 214 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
| 215 | */ |
||
| 216 | 13 | public function append($value, $key = null): self |
|
| 217 | { |
||
| 218 | 13 | $this->generatorToArray(); |
|
| 219 | |||
| 220 | 13 | if ($this->properties !== []) { |
|
| 221 | 4 | $this->checkType($key, $value); |
|
| 222 | } |
||
| 223 | |||
| 224 | 12 | if ($key !== null) { |
|
| 225 | if ( |
||
| 226 | isset($this->array[$key]) |
||
| 227 | && |
||
| 228 | \is_array($this->array[$key]) === true |
||
| 229 | ) { |
||
| 230 | $this->array[$key][] = $value; |
||
| 231 | } else { |
||
| 232 | $this->array[$key] = $value; |
||
| 233 | } |
||
| 234 | } else { |
||
| 235 | 12 | $this->array[] = $value; |
|
| 236 | } |
||
| 237 | |||
| 238 | 12 | return $this; |
|
| 239 | } |
||
| 240 | |||
| 241 | /** |
||
| 242 | * Sort the entries by value. |
||
| 243 | * |
||
| 244 | * @param int $sort_flags [optional] <p> |
||
| 245 | * You may modify the behavior of the sort using the optional |
||
| 246 | * parameter sort_flags, for details |
||
| 247 | * see sort. |
||
| 248 | * </p> |
||
| 249 | * |
||
| 250 | * @return static |
||
| 251 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 252 | */ |
||
| 253 | 4 | public function asort(int $sort_flags = 0): self |
|
| 254 | { |
||
| 255 | 4 | $this->generatorToArray(); |
|
| 256 | |||
| 257 | 4 | \asort($this->array, $sort_flags); |
|
| 258 | |||
| 259 | 4 | return $this; |
|
| 260 | } |
||
| 261 | |||
| 262 | /** |
||
| 263 | * Counts all elements in an array, or something in an object. |
||
| 264 | * |
||
| 265 | * <p> |
||
| 266 | * For objects, if you have SPL installed, you can hook into count() by implementing interface {@see Countable}. |
||
| 267 | * The interface has exactly one method, {@see Countable::count()}, which returns the return value for the count() |
||
| 268 | * function. Please see the {@see Array} section of the manual for a detailed explanation of how arrays are |
||
| 269 | * implemented and used in PHP. |
||
| 270 | * </p> |
||
| 271 | * |
||
| 272 | * @see http://php.net/manual/en/function.count.php |
||
| 273 | * |
||
| 274 | * @param int $mode [optional] If the optional mode parameter is set to |
||
| 275 | * COUNT_RECURSIVE (or 1), count |
||
| 276 | * will recursively count the array. This is particularly useful for |
||
| 277 | * counting all the elements of a multidimensional array. count does not detect infinite recursion. |
||
| 278 | * |
||
| 279 | * @return int |
||
| 280 | * <p> |
||
| 281 | * The number of elements in var, which is |
||
| 282 | * typically an array, since anything else will have one |
||
| 283 | * element. |
||
| 284 | * </p> |
||
| 285 | * <p> |
||
| 286 | * If var is not an array or an object with |
||
| 287 | * implemented Countable interface, |
||
| 288 | * 1 will be returned. |
||
| 289 | * There is one exception, if var is &null;, |
||
| 290 | * 0 will be returned. |
||
| 291 | * </p> |
||
| 292 | * <p> |
||
| 293 | * Caution: count may return 0 for a variable that isn't set, |
||
| 294 | * but it may also return 0 for a variable that has been initialized with an |
||
| 295 | * empty array. Use isset to test if a variable is set. |
||
| 296 | * </p> |
||
| 297 | */ |
||
| 298 | 51 | public function count(int $mode = \COUNT_NORMAL): int |
|
| 299 | { |
||
| 300 | 51 | return \count($this->getArray(), $mode); |
|
| 301 | } |
||
| 302 | |||
| 303 | /** |
||
| 304 | * Exchange the array for another one. |
||
| 305 | * |
||
| 306 | * @param array|static $data |
||
| 307 | * |
||
| 308 | * @return array |
||
| 309 | */ |
||
| 310 | 1 | public function exchangeArray($data): array |
|
| 311 | { |
||
| 312 | 1 | $this->array = $this->fallbackForArray($data); |
|
| 313 | |||
| 314 | 1 | return $this->array; |
|
| 315 | } |
||
| 316 | |||
| 317 | /** |
||
| 318 | * Creates a copy of the ArrayyObject. |
||
| 319 | * |
||
| 320 | * @return array |
||
| 321 | */ |
||
| 322 | 5 | public function getArrayCopy(): array |
|
| 323 | { |
||
| 324 | 5 | $this->generatorToArray(); |
|
| 325 | |||
| 326 | 5 | return $this->array; |
|
| 327 | } |
||
| 328 | |||
| 329 | /** |
||
| 330 | * Returns a new iterator, thus implementing the \Iterator interface. |
||
| 331 | * |
||
| 332 | * @return \Iterator<mixed, mixed> |
||
|
|
|||
| 333 | * <p>An iterator for the values in the array.</p> |
||
| 334 | */ |
||
| 335 | 24 | public function getIterator(): \Iterator |
|
| 336 | { |
||
| 337 | 24 | if ($this->generator instanceof ArrayyRewindableGenerator) { |
|
| 338 | 1 | return $this->generator; |
|
| 339 | } |
||
| 340 | |||
| 341 | 23 | $iterator = $this->getIteratorClass(); |
|
| 342 | |||
| 343 | 23 | if ($iterator === ArrayyIterator::class) { |
|
| 344 | 23 | return new $iterator($this->getArray(), 0, static::class); |
|
| 345 | } |
||
| 346 | |||
| 347 | return new $iterator($this->getArray()); |
||
| 348 | } |
||
| 349 | |||
| 350 | /** |
||
| 351 | * Gets the iterator classname for the ArrayObject. |
||
| 352 | * |
||
| 353 | * @return string |
||
| 354 | */ |
||
| 355 | 23 | public function getIteratorClass(): string |
|
| 356 | { |
||
| 357 | 23 | return $this->iteratorClass; |
|
| 358 | } |
||
| 359 | |||
| 360 | /** |
||
| 361 | * Sort the entries by key |
||
| 362 | * |
||
| 363 | * @param int $sort_flags [optional] <p> |
||
| 364 | * You may modify the behavior of the sort using the optional |
||
| 365 | * parameter sort_flags, for details |
||
| 366 | * see sort. |
||
| 367 | * </p> |
||
| 368 | * |
||
| 369 | * @return static |
||
| 370 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 371 | */ |
||
| 372 | 4 | public function ksort(int $sort_flags = 0): self |
|
| 373 | { |
||
| 374 | 4 | $this->generatorToArray(); |
|
| 375 | |||
| 376 | 4 | \ksort($this->array, $sort_flags); |
|
| 377 | |||
| 378 | 4 | return $this; |
|
| 379 | } |
||
| 380 | |||
| 381 | /** |
||
| 382 | * Sort an array using a case insensitive "natural order" algorithm |
||
| 383 | * |
||
| 384 | * @return static |
||
| 385 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 386 | */ |
||
| 387 | public function natcasesort(): self |
||
| 388 | { |
||
| 389 | $this->generatorToArray(); |
||
| 390 | |||
| 391 | \natcasesort($this->array); |
||
| 392 | |||
| 393 | return $this; |
||
| 394 | } |
||
| 395 | |||
| 396 | /** |
||
| 397 | * Sort entries using a "natural order" algorithm |
||
| 398 | * |
||
| 399 | * @return static |
||
| 400 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 401 | */ |
||
| 402 | 1 | public function natsort(): self |
|
| 403 | { |
||
| 404 | 1 | $this->generatorToArray(); |
|
| 405 | |||
| 406 | 1 | \natsort($this->array); |
|
| 407 | |||
| 408 | 1 | return $this; |
|
| 409 | } |
||
| 410 | |||
| 411 | /** |
||
| 412 | * Whether or not an offset exists. |
||
| 413 | * |
||
| 414 | * @param bool|int|string $offset |
||
| 415 | * |
||
| 416 | * @return bool |
||
| 417 | * |
||
| 418 | * @noinspection PhpSillyAssignmentInspection |
||
| 419 | */ |
||
| 420 | 127 | public function offsetExists($offset): bool |
|
| 421 | { |
||
| 422 | 127 | $this->generatorToArray(); |
|
| 423 | |||
| 424 | 127 | if ($this->array === []) { |
|
| 425 | 5 | return false; |
|
| 426 | } |
||
| 427 | |||
| 428 | // php cast "bool"-index into "int"-index |
||
| 429 | 122 | if ((bool) $offset === $offset) { |
|
| 430 | 1 | $offset = (int) $offset; |
|
| 431 | } |
||
| 432 | |||
| 433 | /** @var int|string $offset - hint for phpstan */ |
||
| 434 | 122 | $offset = $offset; |
|
| 435 | |||
| 436 | 122 | $tmpReturn = $this->keyExists($offset); |
|
| 437 | |||
| 438 | if ( |
||
| 439 | 122 | $tmpReturn === true |
|
| 440 | || |
||
| 441 | ( |
||
| 442 | 89 | $tmpReturn === false |
|
| 443 | && |
||
| 444 | 122 | \strpos((string) $offset, $this->pathSeparator) === false |
|
| 445 | ) |
||
| 446 | ) { |
||
| 447 | 120 | return $tmpReturn; |
|
| 448 | } |
||
| 449 | |||
| 450 | 3 | $offsetExists = false; |
|
| 451 | |||
| 452 | if ( |
||
| 453 | 3 | $this->pathSeparator |
|
| 454 | && |
||
| 455 | 3 | (string) $offset === $offset |
|
| 456 | && |
||
| 457 | 3 | \strpos($offset, $this->pathSeparator) !== false |
|
| 458 | ) { |
||
| 459 | 3 | $explodedPath = \explode($this->pathSeparator, (string) $offset); |
|
| 460 | 3 | if ($explodedPath !== false) { |
|
| 461 | 3 | $lastOffset = \array_pop($explodedPath); |
|
| 462 | 3 | if ($lastOffset !== null) { |
|
| 463 | 3 | $containerPath = \implode($this->pathSeparator, $explodedPath); |
|
| 464 | |||
| 465 | 3 | $this->callAtPath( |
|
| 466 | 3 | $containerPath, |
|
| 467 | static function ($container) use ($lastOffset, &$offsetExists) { |
||
| 468 | 3 | $offsetExists = \array_key_exists($lastOffset, $container); |
|
| 469 | 3 | } |
|
| 470 | ); |
||
| 471 | } |
||
| 472 | } |
||
| 473 | } |
||
| 474 | |||
| 475 | 3 | return $offsetExists; |
|
| 476 | } |
||
| 477 | |||
| 478 | /** |
||
| 479 | * Returns the value at specified offset. |
||
| 480 | * |
||
| 481 | * @param int|string $offset |
||
| 482 | * |
||
| 483 | * @return mixed |
||
| 484 | * <p>Will return null if the offset did not exists.</p> |
||
| 485 | */ |
||
| 486 | 98 | public function offsetGet($offset) |
|
| 487 | { |
||
| 488 | 98 | return $this->offsetExists($offset) ? $this->get($offset) : null; |
|
| 489 | } |
||
| 490 | |||
| 491 | /** |
||
| 492 | * Assigns a value to the specified offset + check the type. |
||
| 493 | * |
||
| 494 | * @param int|string|null $offset |
||
| 495 | * @param mixed $value |
||
| 496 | * |
||
| 497 | * @return void |
||
| 498 | */ |
||
| 499 | 21 | public function offsetSet($offset, $value) |
|
| 500 | { |
||
| 501 | 21 | $this->generatorToArray(); |
|
| 502 | |||
| 503 | 21 | if ($offset === null) { |
|
| 504 | 5 | if ($this->properties !== []) { |
|
| 505 | 1 | $this->checkType(null, $value); |
|
| 506 | } |
||
| 507 | |||
| 508 | 4 | $this->array[] = $value; |
|
| 509 | } else { |
||
| 510 | 16 | $this->internalSet( |
|
| 511 | 16 | $offset, |
|
| 512 | 16 | $value, |
|
| 513 | 16 | true |
|
| 514 | ); |
||
| 515 | } |
||
| 516 | 20 | } |
|
| 517 | |||
| 518 | /** |
||
| 519 | * Unset an offset. |
||
| 520 | * |
||
| 521 | * @param int|string $offset |
||
| 522 | * |
||
| 523 | * @return void |
||
| 524 | */ |
||
| 525 | 12 | public function offsetUnset($offset) |
|
| 526 | { |
||
| 527 | 12 | $this->generatorToArray(); |
|
| 528 | |||
| 529 | 12 | if ($this->array === []) { |
|
| 530 | 3 | return; |
|
| 531 | } |
||
| 532 | |||
| 533 | 10 | if ($this->keyExists($offset)) { |
|
| 534 | 7 | unset($this->array[$offset]); |
|
| 535 | |||
| 536 | 7 | return; |
|
| 537 | } |
||
| 538 | |||
| 539 | if ( |
||
| 540 | 5 | $this->pathSeparator |
|
| 541 | && |
||
| 542 | 5 | (string) $offset === $offset |
|
| 543 | && |
||
| 544 | 5 | \strpos($offset, $this->pathSeparator) !== false |
|
| 545 | ) { |
||
| 546 | 2 | $path = \explode($this->pathSeparator, (string) $offset); |
|
| 547 | |||
| 548 | 2 | if ($path !== false) { |
|
| 549 | 2 | $pathToUnset = \array_pop($path); |
|
| 550 | |||
| 551 | 2 | $this->callAtPath( |
|
| 552 | 2 | \implode($this->pathSeparator, $path), |
|
| 553 | static function (&$offset) use ($pathToUnset) { |
||
| 554 | 2 | unset($offset[$pathToUnset]); |
|
| 555 | 2 | } |
|
| 556 | ); |
||
| 557 | } |
||
| 558 | } |
||
| 559 | |||
| 560 | 5 | unset($this->array[$offset]); |
|
| 561 | 5 | } |
|
| 562 | |||
| 563 | /** |
||
| 564 | * Serialize the current "Arrayy"-object. |
||
| 565 | * |
||
| 566 | * @return string |
||
| 567 | */ |
||
| 568 | 2 | public function serialize(): string |
|
| 569 | { |
||
| 570 | 2 | $this->generatorToArray(); |
|
| 571 | |||
| 572 | 2 | if (\PHP_VERSION_ID < 70400) { |
|
| 573 | 2 | return parent::serialize(); |
|
| 574 | } |
||
| 575 | |||
| 576 | return \serialize($this); |
||
| 577 | } |
||
| 578 | |||
| 579 | /** |
||
| 580 | * Sets the iterator classname for the current "Arrayy"-object. |
||
| 581 | * |
||
| 582 | * @param string $iteratorClass |
||
| 583 | * |
||
| 584 | * @throws \InvalidArgumentException |
||
| 585 | * |
||
| 586 | * @return void |
||
| 587 | * |
||
| 588 | * @psalm-param class-string<\ArrayIterator> $iteratorClass |
||
| 589 | */ |
||
| 590 | 1044 | public function setIteratorClass($iteratorClass) |
|
| 591 | { |
||
| 592 | 1044 | if (\class_exists($iteratorClass)) { |
|
| 593 | 1044 | $this->iteratorClass = $iteratorClass; |
|
| 594 | |||
| 595 | 1044 | return; |
|
| 596 | } |
||
| 597 | |||
| 598 | if (\strpos($iteratorClass, '\\') === 0) { |
||
| 599 | $iteratorClass = '\\' . $iteratorClass; |
||
| 600 | if (\class_exists($iteratorClass)) { |
||
| 601 | $this->iteratorClass = $iteratorClass; |
||
| 602 | |||
| 603 | return; |
||
| 604 | } |
||
| 605 | } |
||
| 606 | |||
| 607 | throw new \InvalidArgumentException('The iterator class does not exist: ' . $iteratorClass); |
||
| 608 | } |
||
| 609 | |||
| 610 | /** |
||
| 611 | * Sort the entries with a user-defined comparison function and maintain key association. |
||
| 612 | * |
||
| 613 | * @param callable $function |
||
| 614 | * |
||
| 615 | * @throws \InvalidArgumentException |
||
| 616 | * |
||
| 617 | * @return static |
||
| 618 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 619 | */ |
||
| 620 | View Code Duplication | public function uasort($function): self |
|
| 621 | { |
||
| 622 | if (!\is_callable($function)) { |
||
| 623 | throw new \InvalidArgumentException('Passed function must be callable'); |
||
| 624 | } |
||
| 625 | |||
| 626 | $this->generatorToArray(); |
||
| 627 | |||
| 628 | \uasort($this->array, $function); |
||
| 629 | |||
| 630 | return $this; |
||
| 631 | } |
||
| 632 | |||
| 633 | /** |
||
| 634 | * Sort the entries by keys using a user-defined comparison function. |
||
| 635 | * |
||
| 636 | * @param callable $function |
||
| 637 | * |
||
| 638 | * @throws \InvalidArgumentException |
||
| 639 | * |
||
| 640 | * @return static |
||
| 641 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 642 | */ |
||
| 643 | 5 | public function uksort($function): self |
|
| 644 | { |
||
| 645 | 5 | return $this->customSortKeys($function); |
|
| 646 | } |
||
| 647 | |||
| 648 | /** |
||
| 649 | * Unserialize an string and return the instance of the "Arrayy"-class. |
||
| 650 | * |
||
| 651 | * @param string $string |
||
| 652 | * |
||
| 653 | * @return static |
||
| 654 | */ |
||
| 655 | 2 | public function unserialize($string): self |
|
| 656 | { |
||
| 657 | 2 | if (\PHP_VERSION_ID < 70400) { |
|
| 658 | 2 | parent::unserialize($string); |
|
| 659 | |||
| 660 | 2 | return $this; |
|
| 661 | } |
||
| 662 | |||
| 663 | return \unserialize($string, ['allowed_classes' => [__CLASS__, TypeCheckPhpDoc::class]]); |
||
| 664 | } |
||
| 665 | |||
| 666 | /** |
||
| 667 | * Append a (key) + values to the current array. |
||
| 668 | * |
||
| 669 | * @param array $values |
||
| 670 | * @param mixed $key |
||
| 671 | * |
||
| 672 | * @return static |
||
| 673 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
| 674 | */ |
||
| 675 | 1 | public function appendArrayValues(array $values, $key = null) |
|
| 676 | { |
||
| 677 | 1 | $this->generatorToArray(); |
|
| 678 | |||
| 679 | 1 | if ($key !== null) { |
|
| 680 | if ( |
||
| 681 | 1 | isset($this->array[$key]) |
|
| 682 | && |
||
| 683 | 1 | \is_array($this->array[$key]) === true |
|
| 684 | ) { |
||
| 685 | 1 | foreach ($values as $value) { |
|
| 686 | 1 | $this->array[$key][] = $value; |
|
| 687 | } |
||
| 688 | } else { |
||
| 689 | 1 | foreach ($values as $value) { |
|
| 690 | $this->array[$key] = $value; |
||
| 691 | } |
||
| 692 | } |
||
| 693 | } else { |
||
| 694 | foreach ($values as $value) { |
||
| 695 | $this->array[] = $value; |
||
| 696 | } |
||
| 697 | } |
||
| 698 | |||
| 699 | 1 | return $this; |
|
| 700 | } |
||
| 701 | |||
| 702 | /** |
||
| 703 | * Add a suffix to each key. |
||
| 704 | * |
||
| 705 | * @param mixed $prefix |
||
| 706 | * |
||
| 707 | * @return static |
||
| 708 | * <p>(Immutable) Return an Arrayy object, with the prefixed keys.</p> |
||
| 709 | */ |
||
| 710 | 10 | View Code Duplication | public function appendToEachKey($prefix): self |
| 711 | { |
||
| 712 | // init |
||
| 713 | 10 | $result = []; |
|
| 714 | |||
| 715 | 10 | foreach ($this->getGenerator() as $key => $item) { |
|
| 716 | 9 | if ($item instanceof self) { |
|
| 717 | $result[$prefix . $key] = $item->appendToEachKey($prefix); |
||
| 718 | 9 | } elseif (\is_array($item) === true) { |
|
| 719 | $result[$prefix . $key] = self::create($item, $this->iteratorClass, false) |
||
| 720 | ->appendToEachKey($prefix) |
||
| 721 | ->toArray(); |
||
| 722 | } else { |
||
| 723 | 9 | $result[$prefix . $key] = $item; |
|
| 724 | } |
||
| 725 | } |
||
| 726 | |||
| 727 | 10 | return self::create($result, $this->iteratorClass, false); |
|
| 728 | } |
||
| 729 | |||
| 730 | /** |
||
| 731 | * Add a prefix to each value. |
||
| 732 | * |
||
| 733 | * @param mixed $prefix |
||
| 734 | * |
||
| 735 | * @return static |
||
| 736 | * <p>(Immutable) Return an Arrayy object, with the prefixed values.</p> |
||
| 737 | */ |
||
| 738 | 10 | View Code Duplication | public function appendToEachValue($prefix): self |
| 739 | { |
||
| 740 | // init |
||
| 741 | 10 | $result = []; |
|
| 742 | |||
| 743 | 10 | foreach ($this->getGenerator() as $key => $item) { |
|
| 744 | 9 | if ($item instanceof self) { |
|
| 745 | $result[$key] = $item->appendToEachValue($prefix); |
||
| 746 | 9 | } elseif (\is_array($item) === true) { |
|
| 747 | $result[$key] = self::create($item, $this->iteratorClass, false)->appendToEachValue($prefix)->toArray(); |
||
| 748 | 9 | } elseif (\is_object($item) === true) { |
|
| 749 | 1 | $result[$key] = $item; |
|
| 750 | } else { |
||
| 751 | 8 | $result[$key] = $prefix . $item; |
|
| 752 | } |
||
| 753 | } |
||
| 754 | |||
| 755 | 10 | return self::create($result, $this->iteratorClass, false); |
|
| 756 | } |
||
| 757 | |||
| 758 | /** |
||
| 759 | * Sort an array in reverse order and maintain index association. |
||
| 760 | * |
||
| 761 | * @return static |
||
| 762 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 763 | */ |
||
| 764 | 10 | public function arsort(): self |
|
| 765 | { |
||
| 766 | 10 | $this->generatorToArray(); |
|
| 767 | |||
| 768 | 10 | \arsort($this->array); |
|
| 769 | |||
| 770 | 10 | return $this; |
|
| 771 | } |
||
| 772 | |||
| 773 | /** |
||
| 774 | * Iterate over the current array and execute a callback for each loop. |
||
| 775 | * |
||
| 776 | * @param \Closure $closure |
||
| 777 | * |
||
| 778 | * @return static |
||
| 779 | * <p>(Immutable)</p> |
||
| 780 | */ |
||
| 781 | 2 | public function at(\Closure $closure): self |
|
| 782 | { |
||
| 783 | 2 | $arrayy = clone $this; |
|
| 784 | |||
| 785 | 2 | foreach ($arrayy->getGenerator() as $key => $value) { |
|
| 786 | 2 | $closure($value, $key); |
|
| 787 | } |
||
| 788 | |||
| 789 | 2 | return static::create( |
|
| 790 | 2 | $arrayy->toArray(), |
|
| 791 | 2 | $this->iteratorClass, |
|
| 792 | 2 | false |
|
| 793 | ); |
||
| 794 | } |
||
| 795 | |||
| 796 | /** |
||
| 797 | * Returns the average value of the current array. |
||
| 798 | * |
||
| 799 | * @param int $decimals <p>The number of decimal-numbers to return.</p> |
||
| 800 | * |
||
| 801 | * @return float|int |
||
| 802 | * <p>The average value.</p> |
||
| 803 | */ |
||
| 804 | 10 | public function average($decimals = 0) |
|
| 805 | { |
||
| 806 | 10 | $count = \count($this->getArray(), \COUNT_NORMAL); |
|
| 807 | |||
| 808 | 10 | if (!$count) { |
|
| 809 | 2 | return 0; |
|
| 810 | } |
||
| 811 | |||
| 812 | 8 | if ((int) $decimals !== $decimals) { |
|
| 813 | 3 | $decimals = 0; |
|
| 814 | } |
||
| 815 | |||
| 816 | 8 | return \round(\array_sum($this->getArray()) / $count, $decimals); |
|
| 817 | } |
||
| 818 | |||
| 819 | /** |
||
| 820 | * Changes all keys in an array. |
||
| 821 | * |
||
| 822 | * @param int $case [optional] <p> Either <strong>CASE_UPPER</strong><br /> |
||
| 823 | * or <strong>CASE_LOWER</strong> (default)</p> |
||
| 824 | * |
||
| 825 | * @return static |
||
| 826 | * <p>(Immutable)</p> |
||
| 827 | */ |
||
| 828 | 1 | public function changeKeyCase(int $case = \CASE_LOWER): self |
|
| 829 | { |
||
| 830 | if ( |
||
| 831 | 1 | $case !== \CASE_LOWER |
|
| 832 | && |
||
| 833 | 1 | $case !== \CASE_UPPER |
|
| 834 | ) { |
||
| 835 | $case = \CASE_LOWER; |
||
| 836 | } |
||
| 837 | |||
| 838 | 1 | $return = []; |
|
| 839 | 1 | foreach ($this->getGenerator() as $key => $value) { |
|
| 840 | 1 | if ($case === \CASE_LOWER) { |
|
| 841 | 1 | $key = \mb_strtolower((string) $key); |
|
| 842 | } else { |
||
| 843 | 1 | $key = \mb_strtoupper((string) $key); |
|
| 844 | } |
||
| 845 | |||
| 846 | 1 | $return[$key] = $value; |
|
| 847 | } |
||
| 848 | |||
| 849 | 1 | return static::create( |
|
| 850 | 1 | $return, |
|
| 851 | 1 | $this->iteratorClass, |
|
| 852 | 1 | false |
|
| 853 | ); |
||
| 854 | } |
||
| 855 | |||
| 856 | /** |
||
| 857 | * Change the path separator of the array wrapper. |
||
| 858 | * |
||
| 859 | * By default, the separator is: "." |
||
| 860 | * |
||
| 861 | * @param string $separator <p>Separator to set.</p> |
||
| 862 | * |
||
| 863 | * @return static |
||
| 864 | * <p>Mutable</p> |
||
| 865 | */ |
||
| 866 | 11 | public function changeSeparator($separator): self |
|
| 867 | { |
||
| 868 | 11 | $this->pathSeparator = $separator; |
|
| 869 | |||
| 870 | 11 | return $this; |
|
| 871 | } |
||
| 872 | |||
| 873 | /** |
||
| 874 | * Create a chunked version of the current array. |
||
| 875 | * |
||
| 876 | * @param int $size <p>Size of each chunk.</p> |
||
| 877 | * @param bool $preserveKeys <p>Whether array keys are preserved or no.</p> |
||
| 878 | * |
||
| 879 | * @return static |
||
| 880 | * <p>(Immutable) A new array of chunks from the original array.</p> |
||
| 881 | */ |
||
| 882 | 5 | public function chunk($size, $preserveKeys = false): self |
|
| 883 | { |
||
| 884 | 5 | return static::create( |
|
| 885 | 5 | \array_chunk($this->getArray(), $size, $preserveKeys), |
|
| 886 | 5 | $this->iteratorClass, |
|
| 887 | 5 | false |
|
| 888 | ); |
||
| 889 | } |
||
| 890 | |||
| 891 | /** |
||
| 892 | * Clean all falsy values from the current array. |
||
| 893 | * |
||
| 894 | * @return static |
||
| 895 | * <p>(Immutable)</p> |
||
| 896 | */ |
||
| 897 | 8 | public function clean(): self |
|
| 898 | { |
||
| 899 | 8 | return $this->filter( |
|
| 900 | static function ($value) { |
||
| 901 | 7 | return (bool) $value; |
|
| 902 | 8 | } |
|
| 903 | ); |
||
| 904 | } |
||
| 905 | |||
| 906 | /** |
||
| 907 | * WARNING!!! -> Clear the current array. |
||
| 908 | * |
||
| 909 | * @return static |
||
| 910 | * <p>(Mutable) Return this Arrayy object, with an empty array.</p> |
||
| 911 | */ |
||
| 912 | 5 | public function clear(): self |
|
| 913 | { |
||
| 914 | 5 | $this->array = []; |
|
| 915 | 5 | $this->generator = null; |
|
| 916 | |||
| 917 | 5 | return $this; |
|
| 918 | } |
||
| 919 | |||
| 920 | /** |
||
| 921 | * Check if an item is in the current array. |
||
| 922 | * |
||
| 923 | * @param float|int|string $value |
||
| 924 | * @param bool $recursive |
||
| 925 | * @param bool $strict |
||
| 926 | * |
||
| 927 | * @return bool |
||
| 928 | */ |
||
| 929 | 23 | public function contains($value, bool $recursive = false, bool $strict = true): bool |
|
| 930 | { |
||
| 931 | 23 | if ($recursive === true) { |
|
| 932 | 18 | return $this->in_array_recursive($value, $this->getArray(), $strict); |
|
| 933 | } |
||
| 934 | |||
| 935 | 14 | foreach ($this->getGenerator() as $valueFromArray) { |
|
| 936 | 11 | if ($strict) { |
|
| 937 | 11 | if ($value === $valueFromArray) { |
|
| 938 | 11 | return true; |
|
| 939 | } |
||
| 940 | } else { |
||
| 941 | /** @noinspection NestedPositiveIfStatementsInspection */ |
||
| 942 | if ($value == $valueFromArray) { |
||
| 943 | return true; |
||
| 944 | } |
||
| 945 | } |
||
| 946 | } |
||
| 947 | |||
| 948 | 7 | return false; |
|
| 949 | } |
||
| 950 | |||
| 951 | /** |
||
| 952 | * Check if an (case-insensitive) string is in the current array. |
||
| 953 | * |
||
| 954 | * @param string $value |
||
| 955 | * @param bool $recursive |
||
| 956 | * |
||
| 957 | * @return bool |
||
| 958 | */ |
||
| 959 | 26 | public function containsCaseInsensitive($value, $recursive = false): bool |
|
| 960 | { |
||
| 961 | 26 | if ($recursive === true) { |
|
| 962 | 26 | foreach ($this->getGenerator() as $key => $valueTmp) { |
|
| 963 | 22 | if (\is_array($valueTmp) === true) { |
|
| 964 | 5 | $return = (new self($valueTmp))->containsCaseInsensitive($value, $recursive); |
|
| 965 | 5 | if ($return === true) { |
|
| 966 | 5 | return $return; |
|
| 967 | } |
||
| 968 | 22 | } elseif (\mb_strtoupper((string) $valueTmp) === \mb_strtoupper((string) $value)) { |
|
| 969 | 16 | return true; |
|
| 970 | } |
||
| 971 | } |
||
| 972 | |||
| 973 | 10 | return false; |
|
| 974 | } |
||
| 975 | |||
| 976 | 13 | foreach ($this->getGenerator() as $key => $valueTmp) { |
|
| 977 | 11 | if (\mb_strtoupper((string) $valueTmp) === \mb_strtoupper((string) $value)) { |
|
| 978 | 8 | return true; |
|
| 979 | } |
||
| 980 | } |
||
| 981 | |||
| 982 | 5 | return false; |
|
| 983 | } |
||
| 984 | |||
| 985 | /** |
||
| 986 | * Check if the given key/index exists in the array. |
||
| 987 | * |
||
| 988 | * @param int|string $key <p>key/index to search for</p> |
||
| 989 | * |
||
| 990 | * @return bool |
||
| 991 | * <p>Returns true if the given key/index exists in the array, false otherwise.</p> |
||
| 992 | */ |
||
| 993 | 4 | public function containsKey($key): bool |
|
| 997 | |||
| 998 | /** |
||
| 999 | * Check if all given needles are present in the array as key/index. |
||
| 1000 | * |
||
| 1001 | * @param array $needles <p>The keys you are searching for.</p> |
||
| 1002 | * @param bool $recursive |
||
| 1003 | * |
||
| 1004 | * @return bool |
||
| 1005 | * <p>Returns true if all the given keys/indexes exists in the array, false otherwise.</p> |
||
| 1006 | */ |
||
| 1007 | 2 | public function containsKeys(array $needles, $recursive = false): bool |
|
| 1008 | { |
||
| 1009 | 2 | if ($recursive === true) { |
|
| 1010 | return |
||
| 1011 | 2 | \count( |
|
| 1012 | 2 | \array_intersect( |
|
| 1013 | 2 | $needles, |
|
| 1014 | 2 | $this->keys(true)->getArray() |
|
| 1015 | ), |
||
| 1016 | 2 | \COUNT_RECURSIVE |
|
| 1017 | ) |
||
| 1018 | === |
||
| 1019 | 2 | \count( |
|
| 1020 | 2 | $needles, |
|
| 1021 | 2 | \COUNT_RECURSIVE |
|
| 1022 | ); |
||
| 1023 | } |
||
| 1024 | |||
| 1025 | 1 | return \count( |
|
| 1026 | 1 | \array_intersect($needles, $this->keys()->getArray()), |
|
| 1027 | 1 | \COUNT_NORMAL |
|
| 1028 | ) |
||
| 1029 | === |
||
| 1030 | 1 | \count( |
|
| 1031 | 1 | $needles, |
|
| 1032 | 1 | \COUNT_NORMAL |
|
| 1033 | ); |
||
| 1034 | } |
||
| 1035 | |||
| 1036 | /** |
||
| 1037 | * Check if all given needles are present in the array as key/index. |
||
| 1038 | * |
||
| 1039 | * @param array $needles <p>The keys you are searching for.</p> |
||
| 1040 | * |
||
| 1041 | * @return bool |
||
| 1042 | * <p>Returns true if all the given keys/indexes exists in the array, false otherwise.</p> |
||
| 1043 | */ |
||
| 1044 | 1 | public function containsKeysRecursive(array $needles): bool |
|
| 1048 | |||
| 1049 | /** |
||
| 1050 | * alias: for "Arrayy->contains()" |
||
| 1051 | * |
||
| 1052 | * @param float|int|string $value |
||
| 1053 | * |
||
| 1054 | * @return bool |
||
| 1055 | * |
||
| 1056 | * @see Arrayy::contains() |
||
| 1057 | */ |
||
| 1058 | 9 | public function containsValue($value): bool |
|
| 1062 | |||
| 1063 | /** |
||
| 1064 | * alias: for "Arrayy->contains($value, true)" |
||
| 1065 | * |
||
| 1066 | * @param float|int|string $value |
||
| 1067 | * |
||
| 1068 | * @return bool |
||
| 1069 | * |
||
| 1070 | * @see Arrayy::contains() |
||
| 1071 | */ |
||
| 1072 | 18 | public function containsValueRecursive($value): bool |
|
| 1076 | |||
| 1077 | /** |
||
| 1078 | * Check if all given needles are present in the array. |
||
| 1079 | * |
||
| 1080 | * @param array $needles |
||
| 1081 | * |
||
| 1082 | * @return bool |
||
| 1083 | * <p>Returns true if all the given values exists in the array, false otherwise.</p> |
||
| 1084 | */ |
||
| 1085 | 1 | public function containsValues(array $needles): bool |
|
| 1091 | |||
| 1092 | /** |
||
| 1093 | * Counts all the values of an array |
||
| 1094 | * |
||
| 1095 | * @see http://php.net/manual/en/function.array-count-values.php |
||
| 1096 | * |
||
| 1097 | * @return static |
||
| 1098 | * <p> |
||
| 1099 | * (Immutable) |
||
| 1100 | * An associative Arrayy-object of values from input as |
||
| 1101 | * keys and their count as value. |
||
| 1102 | * </p> |
||
| 1103 | */ |
||
| 1104 | 7 | public function countValues(): self |
|
| 1108 | |||
| 1109 | /** |
||
| 1110 | * Creates an Arrayy object. |
||
| 1111 | * |
||
| 1112 | * @param mixed $data |
||
| 1113 | * @param string $iteratorClass |
||
| 1114 | * @param bool $checkPropertiesInConstructor |
||
| 1115 | * |
||
| 1116 | * @return static |
||
| 1117 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1118 | * |
||
| 1119 | * @psalm-param class-string<\ArrayIterator> $iteratorClass |
||
| 1120 | */ |
||
| 1121 | 660 | public static function create( |
|
| 1132 | |||
| 1133 | /** |
||
| 1134 | * WARNING: Creates an Arrayy object by reference. |
||
| 1135 | * |
||
| 1136 | * @param array $array |
||
| 1137 | * |
||
| 1138 | * @return static |
||
| 1139 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1140 | */ |
||
| 1141 | 1 | public function createByReference(array &$array = []): self |
|
| 1149 | |||
| 1150 | /** |
||
| 1151 | * Create an new instance from a callable function which will return an Generator. |
||
| 1152 | * |
||
| 1153 | * @param callable():Generator $generatorFunction |
||
| 1154 | * |
||
| 1155 | * @return static |
||
| 1156 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1157 | */ |
||
| 1158 | 5 | public static function createFromGeneratorFunction(callable $generatorFunction): self |
|
| 1162 | |||
| 1163 | /** |
||
| 1164 | * Create an new instance filled with a copy of values from a "Generator"-object. |
||
| 1165 | * |
||
| 1166 | * @param \Generator $generator |
||
| 1167 | * |
||
| 1168 | * @return static |
||
| 1169 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1170 | */ |
||
| 1171 | 4 | public static function createFromGeneratorImmutable(\Generator $generator): self |
|
| 1175 | |||
| 1176 | /** |
||
| 1177 | * Create an new Arrayy object via JSON. |
||
| 1178 | * |
||
| 1179 | * @param string $json |
||
| 1180 | * |
||
| 1181 | * @return static |
||
| 1182 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1183 | */ |
||
| 1184 | 5 | public static function createFromJson(string $json): self |
|
| 1188 | |||
| 1189 | /** |
||
| 1190 | * Create an new instance filled with values from an object that is iterable. |
||
| 1191 | * |
||
| 1192 | * @param \Traversable $object <p>iterable object</p> |
||
| 1193 | * |
||
| 1194 | * @return static |
||
| 1195 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1196 | */ |
||
| 1197 | 4 | public static function createFromObject(\Traversable $object): self |
|
| 1214 | |||
| 1215 | /** |
||
| 1216 | * Create an new instance filled with values from an object. |
||
| 1217 | * |
||
| 1218 | * @param object $object |
||
| 1219 | * |
||
| 1220 | * @return static |
||
| 1221 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1222 | */ |
||
| 1223 | 5 | public static function createFromObjectVars($object): self |
|
| 1227 | |||
| 1228 | /** |
||
| 1229 | * Create an new Arrayy object via string. |
||
| 1230 | * |
||
| 1231 | * @param string $str <p>The input string.</p> |
||
| 1232 | * @param string|null $delimiter <p>The boundary string.</p> |
||
| 1233 | * @param string|null $regEx <p>Use the $delimiter or the $regEx, so if $pattern is null, $delimiter will be |
||
| 1234 | * used.</p> |
||
| 1235 | * |
||
| 1236 | * @return static |
||
| 1237 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1238 | */ |
||
| 1239 | 10 | public static function createFromString(string $str, string $delimiter = null, string $regEx = null): self |
|
| 1268 | |||
| 1269 | /** |
||
| 1270 | * Create an new instance filled with a copy of values from a "Traversable"-object. |
||
| 1271 | * |
||
| 1272 | * @param \Traversable $traversable |
||
| 1273 | * |
||
| 1274 | * @return static |
||
| 1275 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1276 | */ |
||
| 1277 | 1 | public static function createFromTraversableImmutable(\Traversable $traversable): self |
|
| 1281 | |||
| 1282 | /** |
||
| 1283 | * Create an new instance containing a range of elements. |
||
| 1284 | * |
||
| 1285 | * @param mixed $low <p>First value of the sequence.</p> |
||
| 1286 | * @param mixed $high <p>The sequence is ended upon reaching the end value.</p> |
||
| 1287 | * @param int $step <p>Used as the increment between elements in the sequence.</p> |
||
| 1288 | * |
||
| 1289 | * @return static |
||
| 1290 | * <p>(Immutable) Returns an new instance of the Arrayy object.</p> |
||
| 1291 | */ |
||
| 1292 | 2 | public static function createWithRange($low, $high, int $step = 1): self |
|
| 1296 | |||
| 1297 | /** |
||
| 1298 | * Gets the element of the array at the current internal iterator position. |
||
| 1299 | * |
||
| 1300 | * @return false|mixed |
||
| 1301 | */ |
||
| 1302 | public function current() |
||
| 1306 | |||
| 1307 | /** |
||
| 1308 | * Custom sort by index via "uksort". |
||
| 1309 | * |
||
| 1310 | * @see http://php.net/manual/en/function.uksort.php |
||
| 1311 | * |
||
| 1312 | * @param callable $function |
||
| 1313 | * |
||
| 1314 | * @throws \InvalidArgumentException |
||
| 1315 | * |
||
| 1316 | * @return static |
||
| 1317 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1318 | */ |
||
| 1319 | 5 | View Code Duplication | public function customSortKeys($function): self |
| 1331 | |||
| 1332 | /** |
||
| 1333 | * Custom sort by value via "usort". |
||
| 1334 | * |
||
| 1335 | * @see http://php.net/manual/en/function.usort.php |
||
| 1336 | * |
||
| 1337 | * @param callable $function |
||
| 1338 | * |
||
| 1339 | * @throws \InvalidArgumentException |
||
| 1340 | * |
||
| 1341 | * @return static |
||
| 1342 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 1343 | */ |
||
| 1344 | 6 | View Code Duplication | public function customSortValues($function): self |
| 1356 | |||
| 1357 | /** |
||
| 1358 | * Delete the given key or keys. |
||
| 1359 | * |
||
| 1360 | * @param int|int[]|string|string[] $keyOrKeys |
||
| 1361 | * |
||
| 1362 | * @return void |
||
| 1363 | */ |
||
| 1364 | 4 | public function delete($keyOrKeys) |
|
| 1372 | |||
| 1373 | /** |
||
| 1374 | * Return values that are only in the current array. |
||
| 1375 | * |
||
| 1376 | * @param array ...$array |
||
| 1377 | * |
||
| 1378 | * @return static |
||
| 1379 | * <p>(Immutable)</p> |
||
| 1380 | */ |
||
| 1381 | 13 | public function diff(...$array): self |
|
| 1389 | |||
| 1390 | /** |
||
| 1391 | * Return values that are only in the current array. |
||
| 1392 | * |
||
| 1393 | * @param array ...$array |
||
| 1394 | * |
||
| 1395 | * @return static |
||
| 1396 | * <p>(Immutable)</p> |
||
| 1397 | */ |
||
| 1398 | 8 | public function diffKey(...$array): self |
|
| 1406 | |||
| 1407 | /** |
||
| 1408 | * Return values and Keys that are only in the current array. |
||
| 1409 | * |
||
| 1410 | * @param array $array |
||
| 1411 | * |
||
| 1412 | * @return static |
||
| 1413 | * <p>(Immutable)</p> |
||
| 1414 | */ |
||
| 1415 | 8 | public function diffKeyAndValue(array $array = []): self |
|
| 1423 | |||
| 1424 | /** |
||
| 1425 | * Return values that are only in the current multi-dimensional array. |
||
| 1426 | * |
||
| 1427 | * @param array $array |
||
| 1428 | * @param array|null $helperVariableForRecursion <p>(only for internal usage)</p> |
||
| 1429 | * |
||
| 1430 | * @return static |
||
| 1431 | * <p>(Immutable)</p> |
||
| 1432 | */ |
||
| 1433 | 1 | public function diffRecursive(array $array = [], $helperVariableForRecursion = null): self |
|
| 1468 | |||
| 1469 | /** |
||
| 1470 | * Return values that are only in the new $array. |
||
| 1471 | * |
||
| 1472 | * @param array $array |
||
| 1473 | * |
||
| 1474 | * @return static |
||
| 1475 | * <p>(Immutable)</p> |
||
| 1476 | */ |
||
| 1477 | 8 | public function diffReverse(array $array = []): self |
|
| 1485 | |||
| 1486 | /** |
||
| 1487 | * Divide an array into two arrays. One with keys and the other with values. |
||
| 1488 | * |
||
| 1489 | * @return static |
||
| 1490 | * <p>(Immutable)</p> |
||
| 1491 | */ |
||
| 1492 | 1 | public function divide(): self |
|
| 1503 | |||
| 1504 | /** |
||
| 1505 | * Iterate over the current array and modify the array's value. |
||
| 1506 | * |
||
| 1507 | * @param \Closure $closure |
||
| 1508 | * |
||
| 1509 | * @return static |
||
| 1510 | * <p>(Immutable)</p> |
||
| 1511 | */ |
||
| 1512 | 5 | View Code Duplication | public function each(\Closure $closure): self |
| 1527 | |||
| 1528 | /** |
||
| 1529 | * Sets the internal iterator to the last element in the array and returns this element. |
||
| 1530 | * |
||
| 1531 | * @return mixed |
||
| 1532 | */ |
||
| 1533 | public function end() |
||
| 1537 | |||
| 1538 | /** |
||
| 1539 | * Check if a value is in the current array using a closure. |
||
| 1540 | * |
||
| 1541 | * @param \Closure $closure |
||
| 1542 | * |
||
| 1543 | * @return bool |
||
| 1544 | * <p>Returns true if the given value is found, false otherwise.</p> |
||
| 1545 | */ |
||
| 1546 | 4 | public function exists(\Closure $closure): bool |
|
| 1561 | |||
| 1562 | /** |
||
| 1563 | * Fill the array until "$num" with "$default" values. |
||
| 1564 | * |
||
| 1565 | * @param int $num |
||
| 1566 | * @param mixed $default |
||
| 1567 | * |
||
| 1568 | * @return static |
||
| 1569 | * <p>(Immutable)</p> |
||
| 1570 | */ |
||
| 1571 | 8 | public function fillWithDefaults(int $num, $default = null): self |
|
| 1594 | |||
| 1595 | /** |
||
| 1596 | * Find all items in an array that pass the truth test. |
||
| 1597 | * |
||
| 1598 | * @param \Closure|null $closure [optional] <p> |
||
| 1599 | * The callback function to use |
||
| 1600 | * </p> |
||
| 1601 | * <p> |
||
| 1602 | * If no callback is supplied, all entries of |
||
| 1603 | * input equal to false (see |
||
| 1604 | * converting to |
||
| 1605 | * boolean) will be removed. |
||
| 1606 | * </p> |
||
| 1607 | * @param int $flag [optional] <p> |
||
| 1608 | * Flag determining what arguments are sent to <i>callback</i>: |
||
| 1609 | * </p><ul> |
||
| 1610 | * <li> |
||
| 1611 | * <b>ARRAY_FILTER_USE_KEY</b> [1] - pass key as the only argument |
||
| 1612 | * to <i>callback</i> instead of the value</span> |
||
| 1613 | * </li> |
||
| 1614 | * <li> |
||
| 1615 | * <b>ARRAY_FILTER_USE_BOTH</b> [2] - pass both value and key as |
||
| 1616 | * arguments to <i>callback</i> instead of the value</span> |
||
| 1617 | * </li> |
||
| 1618 | * </ul> |
||
| 1619 | * |
||
| 1620 | * @return static |
||
| 1621 | * <p>(Immutable)</p> |
||
| 1622 | */ |
||
| 1623 | 12 | public function filter($closure = null, int $flag = \ARRAY_FILTER_USE_BOTH) |
|
| 1635 | |||
| 1636 | /** |
||
| 1637 | * Filters an array of objects (or a numeric array of associative arrays) based on the value of a particular |
||
| 1638 | * property within that. |
||
| 1639 | * |
||
| 1640 | * @param string $property |
||
| 1641 | * @param string|string[] $value |
||
| 1642 | * @param string $comparisonOp |
||
| 1643 | * <p> |
||
| 1644 | * 'eq' (equals),<br /> |
||
| 1645 | * 'gt' (greater),<br /> |
||
| 1646 | * 'gte' || 'ge' (greater or equals),<br /> |
||
| 1647 | * 'lt' (less),<br /> |
||
| 1648 | * 'lte' || 'le' (less or equals),<br /> |
||
| 1649 | * 'ne' (not equals),<br /> |
||
| 1650 | * 'contains',<br /> |
||
| 1651 | * 'notContains',<br /> |
||
| 1652 | * 'newer' (via strtotime),<br /> |
||
| 1653 | * 'older' (via strtotime),<br /> |
||
| 1654 | * </p> |
||
| 1655 | * |
||
| 1656 | * @return static |
||
| 1657 | * <p>(Immutable)</p> |
||
| 1658 | */ |
||
| 1659 | 1 | public function filterBy(string $property, $value, string $comparisonOp = null): self |
|
| 1728 | |||
| 1729 | /** |
||
| 1730 | * Find the first item in an array that passes the truth test, |
||
| 1731 | * otherwise return false |
||
| 1732 | * |
||
| 1733 | * @param \Closure $closure |
||
| 1734 | * |
||
| 1735 | * @return false|mixed |
||
| 1736 | * <p>Return false if we did not find the value.</p> |
||
| 1737 | */ |
||
| 1738 | 8 | public function find(\Closure $closure) |
|
| 1748 | |||
| 1749 | /** |
||
| 1750 | * find by ... |
||
| 1751 | * |
||
| 1752 | * @param string $property |
||
| 1753 | * @param string|string[] $value |
||
| 1754 | * @param string $comparisonOp |
||
| 1755 | * |
||
| 1756 | * @return static |
||
| 1757 | * <p>(Immutable)</p> |
||
| 1758 | */ |
||
| 1759 | 1 | public function findBy(string $property, $value, string $comparisonOp = 'eq'): self |
|
| 1763 | |||
| 1764 | /** |
||
| 1765 | * Get the first value from the current array. |
||
| 1766 | * |
||
| 1767 | * @return mixed |
||
| 1768 | * <p>Return null if there wasn't a element.</p> |
||
| 1769 | */ |
||
| 1770 | 21 | public function first() |
|
| 1779 | |||
| 1780 | /** |
||
| 1781 | * Get the first key from the current array. |
||
| 1782 | * |
||
| 1783 | * @return mixed |
||
| 1784 | * <p>Return null if there wasn't a element.</p> |
||
| 1785 | */ |
||
| 1786 | 28 | public function firstKey() |
|
| 1792 | |||
| 1793 | /** |
||
| 1794 | * Get the first value(s) from the current array. |
||
| 1795 | * And will return an empty array if there was no first entry. |
||
| 1796 | * |
||
| 1797 | * @param int|null $number <p>How many values you will take?</p> |
||
| 1798 | * |
||
| 1799 | * @return static |
||
| 1800 | * <p>(Immutable)</p> |
||
| 1801 | */ |
||
| 1802 | 37 | View Code Duplication | public function firstsImmutable(int $number = null): self |
| 1819 | |||
| 1820 | /** |
||
| 1821 | * Get the first value(s) from the current array. |
||
| 1822 | * And will return an empty array if there was no first entry. |
||
| 1823 | * |
||
| 1824 | * @param int|null $number <p>How many values you will take?</p> |
||
| 1825 | * |
||
| 1826 | * @return static |
||
| 1827 | * <p>(Immutable)</p> |
||
| 1828 | */ |
||
| 1829 | 3 | View Code Duplication | public function firstsKeys(int $number = null): self |
| 1846 | |||
| 1847 | /** |
||
| 1848 | * Get and rmove the first value(s) from the current array. |
||
| 1849 | * And will return an empty array if there was no first entry. |
||
| 1850 | * |
||
| 1851 | * @param int|null $number <p>How many values you will take?</p> |
||
| 1852 | * |
||
| 1853 | * @return static |
||
| 1854 | * <p>(Mutable)</p> |
||
| 1855 | */ |
||
| 1856 | 34 | public function firstsMutable(int $number = null): self |
|
| 1869 | |||
| 1870 | /** |
||
| 1871 | * Exchanges all keys with their associated values in an array. |
||
| 1872 | * |
||
| 1873 | * @return static |
||
| 1874 | * <p>(Immutable)</p> |
||
| 1875 | */ |
||
| 1876 | 1 | public function flip(): self |
|
| 1884 | |||
| 1885 | /** |
||
| 1886 | * Tests whether the given predicate p holds for all elements of this array. |
||
| 1887 | * |
||
| 1888 | * @param \Closure $closure the predicate |
||
| 1889 | * |
||
| 1890 | * @return bool |
||
| 1891 | * <p>TRUE, if the predicate yields TRUE for all elements, FALSE otherwise.</p> |
||
| 1892 | */ |
||
| 1893 | public function forAll(\Closure $closure): bool |
||
| 1903 | |||
| 1904 | /** |
||
| 1905 | * Get a value from an array (optional using dot-notation). |
||
| 1906 | * |
||
| 1907 | * @param mixed $key <p>The key to look for.</p> |
||
| 1908 | * @param mixed $fallback <p>Value to fallback to.</p> |
||
| 1909 | * @param array $array <p>The array to get from, if it's set to "null" we use the current array from the |
||
| 1910 | * class.</p> |
||
| 1911 | * |
||
| 1912 | * @return mixed|static |
||
| 1913 | */ |
||
| 1914 | 169 | public function get($key, $fallback = null, array $array = null) |
|
| 2006 | |||
| 2007 | /** |
||
| 2008 | * alias: for "Arrayy->getArray()" |
||
| 2009 | * |
||
| 2010 | * @return array |
||
| 2011 | * |
||
| 2012 | * @see Arrayy::getArray() |
||
| 2013 | */ |
||
| 2014 | 1 | public function getAll(): array |
|
| 2018 | |||
| 2019 | /** |
||
| 2020 | * Get the current array from the "Arrayy"-object. |
||
| 2021 | * |
||
| 2022 | * @param bool $convertAllArrayyElements |
||
| 2023 | * |
||
| 2024 | * @return array |
||
| 2025 | */ |
||
| 2026 | 842 | public function getArray($convertAllArrayyElements = false): array |
|
| 2047 | |||
| 2048 | /** |
||
| 2049 | * Returns the values from a single column of the input array, identified by |
||
| 2050 | * the $columnKey, can be used to extract data-columns from multi-arrays. |
||
| 2051 | * |
||
| 2052 | * Info: Optionally, you may provide an $indexKey to index the values in the returned |
||
| 2053 | * array by the values from the $indexKey column in the input array. |
||
| 2054 | * |
||
| 2055 | * @param mixed $columnKey |
||
| 2056 | * @param mixed $indexKey |
||
| 2057 | * |
||
| 2058 | * @return static |
||
| 2059 | * <p>(Immutable)</p> |
||
| 2060 | */ |
||
| 2061 | 1 | public function getColumn($columnKey = null, $indexKey = null): self |
|
| 2069 | |||
| 2070 | /** |
||
| 2071 | * Get the current array from the "Arrayy"-object as generator. |
||
| 2072 | * |
||
| 2073 | * @return \Generator |
||
| 2074 | */ |
||
| 2075 | 920 | public function getGenerator(): \Generator |
|
| 2083 | |||
| 2084 | /** |
||
| 2085 | * alias: for "Arrayy->keys()" |
||
| 2086 | * |
||
| 2087 | * @return static |
||
| 2088 | * <p>(Immutable)</p> |
||
| 2089 | * |
||
| 2090 | * @see Arrayy::keys() |
||
| 2091 | */ |
||
| 2092 | 2 | public function getKeys() |
|
| 2096 | |||
| 2097 | /** |
||
| 2098 | * Get the current array from the "Arrayy"-object as object. |
||
| 2099 | * |
||
| 2100 | * @return \stdClass |
||
| 2101 | */ |
||
| 2102 | 4 | public function getObject(): \stdClass |
|
| 2106 | |||
| 2107 | /** |
||
| 2108 | * alias: for "Arrayy->randomImmutable()" |
||
| 2109 | * |
||
| 2110 | * @return static |
||
| 2111 | * <p>(Immutable)</p> |
||
| 2112 | * |
||
| 2113 | * @see Arrayy::randomImmutable() |
||
| 2114 | */ |
||
| 2115 | 4 | public function getRandom(): self |
|
| 2119 | |||
| 2120 | /** |
||
| 2121 | * alias: for "Arrayy->randomKey()" |
||
| 2122 | * |
||
| 2123 | * @return mixed |
||
| 2124 | * <p>Get a key/index or null if there wasn't a key/index.</p> |
||
| 2125 | * |
||
| 2126 | * @see Arrayy::randomKey() |
||
| 2127 | */ |
||
| 2128 | 3 | public function getRandomKey() |
|
| 2132 | |||
| 2133 | /** |
||
| 2134 | * alias: for "Arrayy->randomKeys()" |
||
| 2135 | * |
||
| 2136 | * @param int $number |
||
| 2137 | * |
||
| 2138 | * @return static |
||
| 2139 | * <p>(Immutable)</p> |
||
| 2140 | * |
||
| 2141 | * @see Arrayy::randomKeys() |
||
| 2142 | */ |
||
| 2143 | 8 | public function getRandomKeys(int $number): self |
|
| 2147 | |||
| 2148 | /** |
||
| 2149 | * alias: for "Arrayy->randomValue()" |
||
| 2150 | * |
||
| 2151 | * @return mixed |
||
| 2152 | * <p>Get a random value or null if there wasn't a value.</p> |
||
| 2153 | * |
||
| 2154 | * @see Arrayy::randomValue() |
||
| 2155 | */ |
||
| 2156 | 3 | public function getRandomValue() |
|
| 2160 | |||
| 2161 | /** |
||
| 2162 | * alias: for "Arrayy->randomValues()" |
||
| 2163 | * |
||
| 2164 | * @param int $number |
||
| 2165 | * |
||
| 2166 | * @return static |
||
| 2167 | * <p>(Immutable)</p> |
||
| 2168 | * |
||
| 2169 | * @see Arrayy::randomValues() |
||
| 2170 | */ |
||
| 2171 | 6 | public function getRandomValues(int $number): self |
|
| 2175 | |||
| 2176 | /** |
||
| 2177 | * Gets all values. |
||
| 2178 | * |
||
| 2179 | * @return static |
||
| 2180 | * <p>The values of all elements in this array, in the order they |
||
| 2181 | * appear in the array.</p> |
||
| 2182 | */ |
||
| 2183 | public function getValues() |
||
| 2193 | |||
| 2194 | /** |
||
| 2195 | * Gets all values via Generator. |
||
| 2196 | * |
||
| 2197 | * @return \Generator |
||
| 2198 | * <p>The values of all elements in this array, in the order they |
||
| 2199 | * appear in the array as Generator.</p> |
||
| 2200 | */ |
||
| 2201 | public function getValuesYield(): \Generator |
||
| 2205 | |||
| 2206 | /** |
||
| 2207 | * Group values from a array according to the results of a closure. |
||
| 2208 | * |
||
| 2209 | * @param callable|string $grouper <p>A callable function name.</p> |
||
| 2210 | * @param bool $saveKeys |
||
| 2211 | * |
||
| 2212 | * @return static |
||
| 2213 | * <p>(Immutable)</p> |
||
| 2214 | */ |
||
| 2215 | 4 | public function group($grouper, bool $saveKeys = false): self |
|
| 2256 | |||
| 2257 | /** |
||
| 2258 | * Check if an array has a given key. |
||
| 2259 | * |
||
| 2260 | * @param mixed $key |
||
| 2261 | * |
||
| 2262 | * @return bool |
||
| 2263 | */ |
||
| 2264 | 23 | public function has($key): bool |
|
| 2275 | |||
| 2276 | /** |
||
| 2277 | * Check if an array has a given value. |
||
| 2278 | * |
||
| 2279 | * INFO: if you need to search recursive please use ```contains()``` |
||
| 2280 | * |
||
| 2281 | * @param mixed $value |
||
| 2282 | * |
||
| 2283 | * @return bool |
||
| 2284 | */ |
||
| 2285 | 1 | public function hasValue($value): bool |
|
| 2289 | |||
| 2290 | /** |
||
| 2291 | * Implodes the values of this array. |
||
| 2292 | * |
||
| 2293 | * @param string $glue |
||
| 2294 | * |
||
| 2295 | * @return string |
||
| 2296 | */ |
||
| 2297 | 28 | public function implode(string $glue = ''): string |
|
| 2301 | |||
| 2302 | /** |
||
| 2303 | * Implodes the keys of this array. |
||
| 2304 | * |
||
| 2305 | * @param string $glue |
||
| 2306 | * |
||
| 2307 | * @return string |
||
| 2308 | */ |
||
| 2309 | 8 | public function implodeKeys(string $glue = ''): string |
|
| 2313 | |||
| 2314 | /** |
||
| 2315 | * Given a list and an iterate-function that returns |
||
| 2316 | * a key for each element in the list (or a property name), |
||
| 2317 | * returns an object with an index of each item. |
||
| 2318 | * |
||
| 2319 | * @param mixed $key |
||
| 2320 | * |
||
| 2321 | * @return static |
||
| 2322 | * <p>(Immutable)</p> |
||
| 2323 | */ |
||
| 2324 | 4 | public function indexBy($key): self |
|
| 2341 | |||
| 2342 | /** |
||
| 2343 | * alias: for "Arrayy->searchIndex()" |
||
| 2344 | * |
||
| 2345 | * @param mixed $value <p>The value to search for.</p> |
||
| 2346 | * |
||
| 2347 | * @return false|mixed |
||
| 2348 | * |
||
| 2349 | * @see Arrayy::searchIndex() |
||
| 2350 | */ |
||
| 2351 | 4 | public function indexOf($value) |
|
| 2355 | |||
| 2356 | /** |
||
| 2357 | * Get everything but the last..$to items. |
||
| 2358 | * |
||
| 2359 | * @param int $to |
||
| 2360 | * |
||
| 2361 | * @return static |
||
| 2362 | * <p>(Immutable)</p> |
||
| 2363 | */ |
||
| 2364 | 12 | public function initial(int $to = 1): self |
|
| 2368 | |||
| 2369 | /** |
||
| 2370 | * Return an array with all elements found in input array. |
||
| 2371 | * |
||
| 2372 | * @param array $search |
||
| 2373 | * @param bool $keepKeys |
||
| 2374 | * |
||
| 2375 | * @return static |
||
| 2376 | * <p>(Immutable)</p> |
||
| 2377 | */ |
||
| 2378 | 4 | public function intersection(array $search, bool $keepKeys = false): self |
|
| 2400 | |||
| 2401 | /** |
||
| 2402 | * Return an array with all elements found in input array. |
||
| 2403 | * |
||
| 2404 | * @param array ...$array |
||
| 2405 | * |
||
| 2406 | * @return static |
||
| 2407 | * <p>(Immutable)</p> |
||
| 2408 | */ |
||
| 2409 | 1 | public function intersectionMulti(...$array): self |
|
| 2417 | |||
| 2418 | /** |
||
| 2419 | * Return a boolean flag which indicates whether the two input arrays have any common elements. |
||
| 2420 | * |
||
| 2421 | * @param array $search |
||
| 2422 | * |
||
| 2423 | * @return bool |
||
| 2424 | */ |
||
| 2425 | 1 | public function intersects(array $search): bool |
|
| 2429 | |||
| 2430 | /** |
||
| 2431 | * Invoke a function on all of an array's values. |
||
| 2432 | * |
||
| 2433 | * @param callable $callable |
||
| 2434 | * @param mixed $arguments |
||
| 2435 | * |
||
| 2436 | * @return static |
||
| 2437 | * <p>(Immutable)</p> |
||
| 2438 | */ |
||
| 2439 | 1 | public function invoke($callable, $arguments = []): self |
|
| 2463 | |||
| 2464 | /** |
||
| 2465 | * Check whether array is associative or not. |
||
| 2466 | * |
||
| 2467 | * @param bool $recursive |
||
| 2468 | * |
||
| 2469 | * @return bool |
||
| 2470 | * <p>Returns true if associative, false otherwise.</p> |
||
| 2471 | */ |
||
| 2472 | 15 | View Code Duplication | public function isAssoc(bool $recursive = false): bool |
| 2486 | |||
| 2487 | /** |
||
| 2488 | * Check if a given key or keys are empty. |
||
| 2489 | * |
||
| 2490 | * @param int|int[]|string|string[]|null $keys |
||
| 2491 | * |
||
| 2492 | * @return bool |
||
| 2493 | * <p>Returns true if empty, false otherwise.</p> |
||
| 2494 | */ |
||
| 2495 | 38 | public function isEmpty($keys = null): bool |
|
| 2513 | |||
| 2514 | /** |
||
| 2515 | * Check if the current array is equal to the given "$array" or not. |
||
| 2516 | * |
||
| 2517 | * @param array $array |
||
| 2518 | * |
||
| 2519 | * @return bool |
||
| 2520 | */ |
||
| 2521 | 1 | public function isEqual(array $array): bool |
|
| 2525 | |||
| 2526 | /** |
||
| 2527 | * Check if the current array is a multi-array. |
||
| 2528 | * |
||
| 2529 | * @return bool |
||
| 2530 | */ |
||
| 2531 | 22 | public function isMultiArray(): bool |
|
| 2539 | |||
| 2540 | /** |
||
| 2541 | * Check whether array is numeric or not. |
||
| 2542 | * |
||
| 2543 | * @return bool |
||
| 2544 | * <p>Returns true if numeric, false otherwise.</p> |
||
| 2545 | */ |
||
| 2546 | 5 | View Code Duplication | public function isNumeric(): bool |
| 2560 | |||
| 2561 | /** |
||
| 2562 | * Check if the current array is sequential [0, 1, 2, 3, 4, 5 ...] or not. |
||
| 2563 | * |
||
| 2564 | * @param bool $recursive |
||
| 2565 | * |
||
| 2566 | * @return bool |
||
| 2567 | */ |
||
| 2568 | 9 | public function isSequential(bool $recursive = false): bool |
|
| 2585 | |||
| 2586 | /** |
||
| 2587 | * @return array |
||
| 2588 | */ |
||
| 2589 | public function jsonSerialize(): array |
||
| 2593 | |||
| 2594 | /** |
||
| 2595 | * Gets the key/index of the element at the current internal iterator position. |
||
| 2596 | * |
||
| 2597 | * @return int|string|null |
||
| 2598 | */ |
||
| 2599 | public function key() |
||
| 2603 | |||
| 2604 | /** |
||
| 2605 | * Checks if the given key exists in the provided array. |
||
| 2606 | * |
||
| 2607 | * INFO: This method only use "array_key_exists()" if you want to use "dot"-notation, |
||
| 2608 | * then you need to use "Arrayy->offsetExists()". |
||
| 2609 | * |
||
| 2610 | * @param int|string $key the key to look for |
||
| 2611 | * |
||
| 2612 | * @return bool |
||
| 2613 | */ |
||
| 2614 | 124 | public function keyExists($key): bool |
|
| 2618 | |||
| 2619 | /** |
||
| 2620 | * Get all keys from the current array. |
||
| 2621 | * |
||
| 2622 | * @param bool $recursive [optional] <p> |
||
| 2623 | * Get all keys, also from all sub-arrays from an multi-dimensional array. |
||
| 2624 | * </p> |
||
| 2625 | * @param mixed|null $search_values [optional] <p> |
||
| 2626 | * If specified, then only keys containing these values are returned. |
||
| 2627 | * </p> |
||
| 2628 | * @param bool $strict [optional] <p> |
||
| 2629 | * Determines if strict comparison (===) should be used during the search. |
||
| 2630 | * </p> |
||
| 2631 | * |
||
| 2632 | * @return static |
||
| 2633 | * <p>(Immutable) An array of all the keys in input.</p> |
||
| 2634 | */ |
||
| 2635 | 29 | public function keys( |
|
| 2705 | |||
| 2706 | /** |
||
| 2707 | * Sort an array by key in reverse order. |
||
| 2708 | * |
||
| 2709 | * @param int $sort_flags [optional] <p> |
||
| 2710 | * You may modify the behavior of the sort using the optional |
||
| 2711 | * parameter sort_flags, for details |
||
| 2712 | * see sort. |
||
| 2713 | * </p> |
||
| 2714 | * |
||
| 2715 | * @return static |
||
| 2716 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 2717 | */ |
||
| 2718 | 4 | public function krsort(int $sort_flags = 0): self |
|
| 2726 | |||
| 2727 | /** |
||
| 2728 | * Get the last value from the current array. |
||
| 2729 | * |
||
| 2730 | * @return mixed |
||
| 2731 | * <p>Return null if there wasn't a element.</p> |
||
| 2732 | */ |
||
| 2733 | 17 | public function last() |
|
| 2742 | |||
| 2743 | /** |
||
| 2744 | * Get the last key from the current array. |
||
| 2745 | * |
||
| 2746 | * @return mixed |
||
| 2747 | * <p>Return null if there wasn't a element.</p> |
||
| 2748 | */ |
||
| 2749 | 21 | public function lastKey() |
|
| 2755 | |||
| 2756 | /** |
||
| 2757 | * Get the last value(s) from the current array. |
||
| 2758 | * |
||
| 2759 | * @param int|null $number |
||
| 2760 | * |
||
| 2761 | * @return static |
||
| 2762 | * <p>(Immutable)</p> |
||
| 2763 | */ |
||
| 2764 | 13 | public function lastsImmutable(int $number = null): self |
|
| 2795 | |||
| 2796 | /** |
||
| 2797 | * Get the last value(s) from the current array. |
||
| 2798 | * |
||
| 2799 | * @param int|null $number |
||
| 2800 | * |
||
| 2801 | * @return static |
||
| 2802 | * <p>(Mutable)</p> |
||
| 2803 | */ |
||
| 2804 | 13 | public function lastsMutable(int $number = null): self |
|
| 2833 | |||
| 2834 | /** |
||
| 2835 | * Count the values from the current array. |
||
| 2836 | * |
||
| 2837 | * alias: for "Arrayy->count()" |
||
| 2838 | * |
||
| 2839 | * @param int $mode |
||
| 2840 | * |
||
| 2841 | * @return int |
||
| 2842 | * |
||
| 2843 | * @see Arrayy::count() |
||
| 2844 | */ |
||
| 2845 | 20 | public function length(int $mode = \COUNT_NORMAL): int |
|
| 2849 | |||
| 2850 | /** |
||
| 2851 | * Apply the given function to the every element of the array, |
||
| 2852 | * collecting the results. |
||
| 2853 | * |
||
| 2854 | * @param callable $callable |
||
| 2855 | * @param bool $useKeyAsSecondParameter |
||
| 2856 | * @param mixed ...$arguments |
||
| 2857 | * |
||
| 2858 | * @return static |
||
| 2859 | * <p>(Immutable) Arrayy object with modified elements.</p> |
||
| 2860 | */ |
||
| 2861 | 5 | public function map(callable $callable, bool $useKeyAsSecondParameter = false, ...$arguments) |
|
| 2888 | |||
| 2889 | /** |
||
| 2890 | * Check if all items in current array match a truth test. |
||
| 2891 | * |
||
| 2892 | * @param \Closure $closure |
||
| 2893 | * |
||
| 2894 | * @return bool |
||
| 2895 | */ |
||
| 2896 | 15 | View Code Duplication | public function matches(\Closure $closure): bool |
| 2912 | |||
| 2913 | /** |
||
| 2914 | * Check if any item in the current array matches a truth test. |
||
| 2915 | * |
||
| 2916 | * @param \Closure $closure |
||
| 2917 | * |
||
| 2918 | * @return bool |
||
| 2919 | */ |
||
| 2920 | 14 | View Code Duplication | public function matchesAny(\Closure $closure): bool |
| 2936 | |||
| 2937 | /** |
||
| 2938 | * Get the max value from an array. |
||
| 2939 | * |
||
| 2940 | * @return mixed |
||
| 2941 | */ |
||
| 2942 | 10 | View Code Duplication | public function max() |
| 2950 | |||
| 2951 | /** |
||
| 2952 | * Merge the new $array into the current array. |
||
| 2953 | * |
||
| 2954 | * - keep key,value from the current array, also if the index is in the new $array |
||
| 2955 | * |
||
| 2956 | * @param array $array |
||
| 2957 | * @param bool $recursive |
||
| 2958 | * |
||
| 2959 | * @return static |
||
| 2960 | * <p>(Immutable)</p> |
||
| 2961 | */ |
||
| 2962 | 25 | View Code Duplication | public function mergeAppendKeepIndex(array $array = [], bool $recursive = false): self |
| 2976 | |||
| 2977 | /** |
||
| 2978 | * Merge the new $array into the current array. |
||
| 2979 | * |
||
| 2980 | * - replace duplicate assoc-keys from the current array with the key,values from the new $array |
||
| 2981 | * - create new indexes |
||
| 2982 | * |
||
| 2983 | * @param array $array |
||
| 2984 | * @param bool $recursive |
||
| 2985 | * |
||
| 2986 | * @return static |
||
| 2987 | * <p>(Immutable)</p> |
||
| 2988 | */ |
||
| 2989 | 16 | View Code Duplication | public function mergeAppendNewIndex(array $array = [], bool $recursive = false): self |
| 3003 | |||
| 3004 | /** |
||
| 3005 | * Merge the the current array into the $array. |
||
| 3006 | * |
||
| 3007 | * - use key,value from the new $array, also if the index is in the current array |
||
| 3008 | * |
||
| 3009 | * @param array $array |
||
| 3010 | * @param bool $recursive |
||
| 3011 | * |
||
| 3012 | * @return static |
||
| 3013 | * <p>(Immutable)</p> |
||
| 3014 | */ |
||
| 3015 | 16 | View Code Duplication | public function mergePrependKeepIndex(array $array = [], bool $recursive = false): self |
| 3029 | |||
| 3030 | /** |
||
| 3031 | * Merge the current array into the new $array. |
||
| 3032 | * |
||
| 3033 | * - replace duplicate assoc-keys from new $array with the key,values from the current array |
||
| 3034 | * - create new indexes |
||
| 3035 | * |
||
| 3036 | * @param array $array |
||
| 3037 | * @param bool $recursive |
||
| 3038 | * |
||
| 3039 | * @return static |
||
| 3040 | * <p>(Immutable)</p> |
||
| 3041 | */ |
||
| 3042 | 17 | View Code Duplication | public function mergePrependNewIndex(array $array = [], bool $recursive = false): self |
| 3056 | |||
| 3057 | /** |
||
| 3058 | * @return ArrayyMeta|static |
||
| 3059 | */ |
||
| 3060 | 15 | public static function meta() |
|
| 3064 | |||
| 3065 | /** |
||
| 3066 | * Get the min value from an array. |
||
| 3067 | * |
||
| 3068 | * @return mixed |
||
| 3069 | */ |
||
| 3070 | 10 | View Code Duplication | public function min() |
| 3078 | |||
| 3079 | /** |
||
| 3080 | * Get the most used value from the array. |
||
| 3081 | * |
||
| 3082 | * @return mixed |
||
| 3083 | * <p>Return null if there wasn't a element.</p> |
||
| 3084 | */ |
||
| 3085 | 3 | public function mostUsedValue() |
|
| 3089 | |||
| 3090 | /** |
||
| 3091 | * Get the most used value from the array. |
||
| 3092 | * |
||
| 3093 | * @param int|null $number <p>How many values you will take?</p> |
||
| 3094 | * |
||
| 3095 | * @return static |
||
| 3096 | * <p>(Immutable)</p> |
||
| 3097 | */ |
||
| 3098 | 3 | public function mostUsedValues(int $number = null): self |
|
| 3102 | |||
| 3103 | /** |
||
| 3104 | * Move an array element to a new index. |
||
| 3105 | * |
||
| 3106 | * cherry-picked from: http://stackoverflow.com/questions/12624153/move-an-array-element-to-a-new-index-in-php |
||
| 3107 | * |
||
| 3108 | * @param int|string $from |
||
| 3109 | * @param int $to |
||
| 3110 | * |
||
| 3111 | * @return static |
||
| 3112 | * <p>(Immutable)</p> |
||
| 3113 | */ |
||
| 3114 | 1 | public function moveElement($from, $to): self |
|
| 3147 | |||
| 3148 | /** |
||
| 3149 | * Move an array element to the first place. |
||
| 3150 | * |
||
| 3151 | * INFO: Instead of "Arrayy->moveElement()" this method will NOT |
||
| 3152 | * loss the keys of an indexed array. |
||
| 3153 | * |
||
| 3154 | * @param int|string $key |
||
| 3155 | * |
||
| 3156 | * @return static |
||
| 3157 | * <p>(Immutable)</p> |
||
| 3158 | */ |
||
| 3159 | 1 | View Code Duplication | public function moveElementToFirstPlace($key): self |
| 3175 | |||
| 3176 | /** |
||
| 3177 | * Move an array element to the last place. |
||
| 3178 | * |
||
| 3179 | * INFO: Instead of "Arrayy->moveElement()" this method will NOT |
||
| 3180 | * loss the keys of an indexed array. |
||
| 3181 | * |
||
| 3182 | * @param int|string $key |
||
| 3183 | * |
||
| 3184 | * @return static |
||
| 3185 | * <p>(Immutable)</p> |
||
| 3186 | */ |
||
| 3187 | 1 | View Code Duplication | public function moveElementToLastPlace($key): self |
| 3203 | |||
| 3204 | /** |
||
| 3205 | * Moves the internal iterator position to the next element and returns this element. |
||
| 3206 | * |
||
| 3207 | * @return mixed |
||
| 3208 | */ |
||
| 3209 | public function next() |
||
| 3213 | |||
| 3214 | /** |
||
| 3215 | * Get a subset of the items from the given array. |
||
| 3216 | * |
||
| 3217 | * @param mixed[] $keys |
||
| 3218 | * |
||
| 3219 | * @return static |
||
| 3220 | * <p>(Immutable)</p> |
||
| 3221 | */ |
||
| 3222 | public function only(array $keys): self |
||
| 3232 | |||
| 3233 | /** |
||
| 3234 | * Pad array to the specified size with a given value. |
||
| 3235 | * |
||
| 3236 | * @param int $size <p>Size of the result array.</p> |
||
| 3237 | * @param mixed $value <p>Empty value by default.</p> |
||
| 3238 | * |
||
| 3239 | * @return static |
||
| 3240 | * <p>(Immutable) Arrayy object padded to $size with $value.</p> |
||
| 3241 | */ |
||
| 3242 | 5 | public function pad(int $size, $value): self |
|
| 3250 | |||
| 3251 | /** |
||
| 3252 | * Partitions this array in two array according to a predicate. |
||
| 3253 | * Keys are preserved in the resulting array. |
||
| 3254 | * |
||
| 3255 | * @param \Closure $closure |
||
| 3256 | * <p>The predicate on which to partition.</p> |
||
| 3257 | * |
||
| 3258 | * @return array<int, Arrayy> |
||
| 3259 | * <p>An array with two elements. The first element contains the array |
||
| 3260 | * of elements where the predicate returned TRUE, the second element |
||
| 3261 | * contains the array of elements where the predicate returned FALSE.</p> |
||
| 3262 | */ |
||
| 3263 | public function partition(\Closure $closure): array |
||
| 3279 | |||
| 3280 | /** |
||
| 3281 | * Pop a specified value off the end of the current array. |
||
| 3282 | * |
||
| 3283 | * @return mixed |
||
| 3284 | * <p>(Mutable) The popped element from the current array.</p> |
||
| 3285 | */ |
||
| 3286 | 5 | public function pop() |
|
| 3292 | |||
| 3293 | /** |
||
| 3294 | * Prepend a (key) + value to the current array. |
||
| 3295 | * |
||
| 3296 | * @param mixed $value |
||
| 3297 | * @param mixed $key |
||
| 3298 | * |
||
| 3299 | * @return static |
||
| 3300 | * <p>(Mutable) Return this Arrayy object, with the prepended value.</p> |
||
| 3301 | */ |
||
| 3302 | 11 | public function prepend($value, $key = null) |
|
| 3318 | |||
| 3319 | /** |
||
| 3320 | * Add a suffix to each key. |
||
| 3321 | * |
||
| 3322 | * @param mixed $suffix |
||
| 3323 | * |
||
| 3324 | * @return static |
||
| 3325 | * <p>(Immutable) Return an Arrayy object, with the prepended keys.</p> |
||
| 3326 | */ |
||
| 3327 | 10 | View Code Duplication | public function prependToEachKey($suffix): self |
| 3353 | |||
| 3354 | /** |
||
| 3355 | * Add a suffix to each value. |
||
| 3356 | * |
||
| 3357 | * @param mixed $suffix |
||
| 3358 | * |
||
| 3359 | * @return static |
||
| 3360 | * <p>(Immutable) Return an Arrayy object, with the prepended values.</p> |
||
| 3361 | */ |
||
| 3362 | 10 | View Code Duplication | public function prependToEachValue($suffix): self |
| 3390 | |||
| 3391 | /** |
||
| 3392 | * Return the value of a given key and |
||
| 3393 | * delete the key. |
||
| 3394 | * |
||
| 3395 | * @param int|int[]|string|string[]|null $keyOrKeys |
||
| 3396 | * @param mixed $fallback |
||
| 3397 | * |
||
| 3398 | * @return mixed |
||
| 3399 | */ |
||
| 3400 | 1 | public function pull($keyOrKeys = null, $fallback = null) |
|
| 3422 | |||
| 3423 | /** |
||
| 3424 | * Push one or more values onto the end of array at once. |
||
| 3425 | * |
||
| 3426 | * @param array ...$args |
||
| 3427 | * |
||
| 3428 | * @return static |
||
| 3429 | * <p>(Mutable) Return this Arrayy object, with pushed elements to the end of array.</p> |
||
| 3430 | * |
||
| 3431 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
| 3432 | */ |
||
| 3433 | 5 | public function push(...$args) |
|
| 3451 | |||
| 3452 | /** |
||
| 3453 | * Get a random value from the current array. |
||
| 3454 | * |
||
| 3455 | * @param int|null $number <p>How many values you will take?</p> |
||
| 3456 | * |
||
| 3457 | * @return static |
||
| 3458 | * <p>(Immutable)</p> |
||
| 3459 | */ |
||
| 3460 | 19 | public function randomImmutable(int $number = null): self |
|
| 3493 | |||
| 3494 | /** |
||
| 3495 | * Pick a random key/index from the keys of this array. |
||
| 3496 | * |
||
| 3497 | * @throws \RangeException If array is empty |
||
| 3498 | * |
||
| 3499 | * @return mixed |
||
| 3500 | * <p>Get a key/index or null if there wasn't a key/index.</p> |
||
| 3501 | */ |
||
| 3502 | 4 | public function randomKey() |
|
| 3512 | |||
| 3513 | /** |
||
| 3514 | * Pick a given number of random keys/indexes out of this array. |
||
| 3515 | * |
||
| 3516 | * @param int $number <p>The number of keys/indexes (should be <= \count($this->array))</p> |
||
| 3517 | * |
||
| 3518 | * @throws \RangeException If array is empty |
||
| 3519 | * |
||
| 3520 | * @return static |
||
| 3521 | * <p>(Immutable)</p> |
||
| 3522 | */ |
||
| 3523 | 13 | public function randomKeys(int $number): self |
|
| 3547 | |||
| 3548 | /** |
||
| 3549 | * Get a random value from the current array. |
||
| 3550 | * |
||
| 3551 | * @param int|null $number <p>How many values you will take?</p> |
||
| 3552 | * |
||
| 3553 | * @return static |
||
| 3554 | * <p>(Mutable)</p> |
||
| 3555 | */ |
||
| 3556 | 17 | public function randomMutable(int $number = null): self |
|
| 3581 | |||
| 3582 | /** |
||
| 3583 | * Pick a random value from the values of this array. |
||
| 3584 | * |
||
| 3585 | * @return mixed |
||
| 3586 | * <p>Get a random value or null if there wasn't a value.</p> |
||
| 3587 | */ |
||
| 3588 | 4 | public function randomValue() |
|
| 3598 | |||
| 3599 | /** |
||
| 3600 | * Pick a given number of random values out of this array. |
||
| 3601 | * |
||
| 3602 | * @param int $number |
||
| 3603 | * |
||
| 3604 | * @return static |
||
| 3605 | * <p>(Mutable)</p> |
||
| 3606 | */ |
||
| 3607 | 7 | public function randomValues(int $number): self |
|
| 3611 | |||
| 3612 | /** |
||
| 3613 | * Get a random value from an array, with the ability to skew the results. |
||
| 3614 | * |
||
| 3615 | * Example: randomWeighted(['foo' => 1, 'bar' => 2]) has a 66% chance of returning bar. |
||
| 3616 | * |
||
| 3617 | * @param array $array |
||
| 3618 | * @param int|null $number <p>How many values you will take?</p> |
||
| 3619 | * |
||
| 3620 | * @return static |
||
| 3621 | * <p>(Immutable)</p> |
||
| 3622 | */ |
||
| 3623 | 9 | public function randomWeighted(array $array, int $number = null): self |
|
| 3638 | |||
| 3639 | /** |
||
| 3640 | * Reduce the current array via callable e.g. anonymous-function. |
||
| 3641 | * |
||
| 3642 | * @param callable $callable |
||
| 3643 | * @param mixed $init |
||
| 3644 | * |
||
| 3645 | * @return static |
||
| 3646 | * <p>(Immutable)</p> |
||
| 3647 | */ |
||
| 3648 | 18 | public function reduce($callable, $init = []): self |
|
| 3678 | |||
| 3679 | /** |
||
| 3680 | * @param bool $unique |
||
| 3681 | * |
||
| 3682 | * @return static |
||
| 3683 | * <p>(Immutable)</p> |
||
| 3684 | */ |
||
| 3685 | 14 | public function reduce_dimension(bool $unique = true): self |
|
| 3704 | |||
| 3705 | /** |
||
| 3706 | * Create a numerically re-indexed Arrayy object. |
||
| 3707 | * |
||
| 3708 | * @return static |
||
| 3709 | * <p>(Mutable) Return this Arrayy object, with re-indexed array-elements.</p> |
||
| 3710 | */ |
||
| 3711 | 9 | public function reindex(): self |
|
| 3719 | |||
| 3720 | /** |
||
| 3721 | * Return all items that fail the truth test. |
||
| 3722 | * |
||
| 3723 | * @param \Closure $closure |
||
| 3724 | * |
||
| 3725 | * @return static |
||
| 3726 | * <p>(Immutable)</p> |
||
| 3727 | */ |
||
| 3728 | 1 | View Code Duplication | public function reject(\Closure $closure): self |
| 3745 | |||
| 3746 | /** |
||
| 3747 | * Remove a value from the current array (optional using dot-notation). |
||
| 3748 | * |
||
| 3749 | * @param mixed $key |
||
| 3750 | * |
||
| 3751 | * @return static |
||
| 3752 | * <p>(Mutable)</p> |
||
| 3753 | */ |
||
| 3754 | 18 | public function remove($key) |
|
| 3777 | |||
| 3778 | /** |
||
| 3779 | * alias: for "Arrayy->removeValue()" |
||
| 3780 | * |
||
| 3781 | * @param mixed $element |
||
| 3782 | * |
||
| 3783 | * @return static |
||
| 3784 | */ |
||
| 3785 | 8 | public function removeElement($element) |
|
| 3789 | |||
| 3790 | /** |
||
| 3791 | * Remove the first value from the current array. |
||
| 3792 | * |
||
| 3793 | * @return static |
||
| 3794 | * <p>(Immutable)</p> |
||
| 3795 | */ |
||
| 3796 | 7 | View Code Duplication | public function removeFirst(): self |
| 3808 | |||
| 3809 | /** |
||
| 3810 | * Remove the last value from the current array. |
||
| 3811 | * |
||
| 3812 | * @return static |
||
| 3813 | * <p>(Immutable)</p> |
||
| 3814 | */ |
||
| 3815 | 7 | View Code Duplication | public function removeLast(): self |
| 3827 | |||
| 3828 | /** |
||
| 3829 | * Removes a particular value from an array (numeric or associative). |
||
| 3830 | * |
||
| 3831 | * @param mixed $value |
||
| 3832 | * |
||
| 3833 | * @return static |
||
| 3834 | * <p>(Immutable)</p> |
||
| 3835 | */ |
||
| 3836 | 8 | public function removeValue($value): self |
|
| 3859 | |||
| 3860 | /** |
||
| 3861 | * Generate array of repeated arrays. |
||
| 3862 | * |
||
| 3863 | * @param int $times <p>How many times has to be repeated.</p> |
||
| 3864 | * |
||
| 3865 | * @return static |
||
| 3866 | * <p>(Immutable)</p> |
||
| 3867 | */ |
||
| 3868 | 1 | public function repeat($times): self |
|
| 3880 | |||
| 3881 | /** |
||
| 3882 | * Replace a key with a new key/value pair. |
||
| 3883 | * |
||
| 3884 | * @param mixed $replace |
||
| 3885 | * @param mixed $key |
||
| 3886 | * @param mixed $value |
||
| 3887 | * |
||
| 3888 | * @return static |
||
| 3889 | * <p>(Immutable)</p> |
||
| 3890 | */ |
||
| 3891 | 2 | public function replace($replace, $key, $value): self |
|
| 3898 | |||
| 3899 | /** |
||
| 3900 | * Create an array using the current array as values and the other array as keys. |
||
| 3901 | * |
||
| 3902 | * @param array $keys <p>An array of keys.</p> |
||
| 3903 | * |
||
| 3904 | * @return static |
||
| 3905 | * <p>(Immutable) Arrayy object with keys from the other array.</p> |
||
| 3906 | */ |
||
| 3907 | 2 | public function replaceAllKeys(array $keys): self |
|
| 3915 | |||
| 3916 | /** |
||
| 3917 | * Create an array using the current array as keys and the other array as values. |
||
| 3918 | * |
||
| 3919 | * @param array $array <p>An array o values.</p> |
||
| 3920 | * |
||
| 3921 | * @return static |
||
| 3922 | * <p>(Immutable) Arrayy object with values from the other array.</p> |
||
| 3923 | */ |
||
| 3924 | 2 | public function replaceAllValues(array $array): self |
|
| 3932 | |||
| 3933 | /** |
||
| 3934 | * Replace the keys in an array with another set. |
||
| 3935 | * |
||
| 3936 | * @param array $keys <p>An array of keys matching the array's size</p> |
||
| 3937 | * |
||
| 3938 | * @return static |
||
| 3939 | * <p>(Immutable)</p> |
||
| 3940 | */ |
||
| 3941 | 1 | public function replaceKeys(array $keys): self |
|
| 3952 | |||
| 3953 | /** |
||
| 3954 | * Replace the first matched value in an array. |
||
| 3955 | * |
||
| 3956 | * @param mixed $search <p>The value to replace.</p> |
||
| 3957 | * @param mixed $replacement <p>The value to replace.</p> |
||
| 3958 | * |
||
| 3959 | * @return static |
||
| 3960 | * <p>(Immutable)</p> |
||
| 3961 | */ |
||
| 3962 | 3 | public function replaceOneValue($search, $replacement = ''): self |
|
| 3977 | |||
| 3978 | /** |
||
| 3979 | * Replace values in the current array. |
||
| 3980 | * |
||
| 3981 | * @param mixed $search <p>The value to replace.</p> |
||
| 3982 | * @param mixed $replacement <p>What to replace it with.</p> |
||
| 3983 | * |
||
| 3984 | * @return static |
||
| 3985 | * <p>(Immutable)</p> |
||
| 3986 | */ |
||
| 3987 | 1 | public function replaceValues($search, $replacement = ''): self |
|
| 3995 | |||
| 3996 | /** |
||
| 3997 | * Get the last elements from index $from until the end of this array. |
||
| 3998 | * |
||
| 3999 | * @param int $from |
||
| 4000 | * |
||
| 4001 | * @return static |
||
| 4002 | * <p>(Immutable)</p> |
||
| 4003 | */ |
||
| 4004 | 15 | View Code Duplication | public function rest(int $from = 1): self |
| 4014 | |||
| 4015 | /** |
||
| 4016 | * Return the array in the reverse order. |
||
| 4017 | * |
||
| 4018 | * @return static |
||
| 4019 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 4020 | */ |
||
| 4021 | 9 | public function reverse(): self |
|
| 4029 | |||
| 4030 | /** |
||
| 4031 | * Sort an array in reverse order. |
||
| 4032 | * |
||
| 4033 | * @param int $sort_flags [optional] <p> |
||
| 4034 | * You may modify the behavior of the sort using the optional |
||
| 4035 | * parameter sort_flags, for details |
||
| 4036 | * see sort. |
||
| 4037 | * </p> |
||
| 4038 | * |
||
| 4039 | * @return static |
||
| 4040 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 4041 | */ |
||
| 4042 | 4 | public function rsort(int $sort_flags = 0): self |
|
| 4050 | |||
| 4051 | /** |
||
| 4052 | * Search for the first index of the current array via $value. |
||
| 4053 | * |
||
| 4054 | * @param mixed $value |
||
| 4055 | * |
||
| 4056 | * @return false|float|int|string |
||
| 4057 | * <p>Will return <b>FALSE</b> if the value can't be found.</p> |
||
| 4058 | */ |
||
| 4059 | 21 | public function searchIndex($value) |
|
| 4069 | |||
| 4070 | /** |
||
| 4071 | * Search for the value of the current array via $index. |
||
| 4072 | * |
||
| 4073 | * @param mixed $index |
||
| 4074 | * |
||
| 4075 | * @return static |
||
| 4076 | * <p>(Immutable) Will return a empty Arrayy if the value wasn't found.</p> |
||
| 4077 | */ |
||
| 4078 | 9 | public function searchValue($index): self |
|
| 4108 | |||
| 4109 | /** |
||
| 4110 | * Set a value for the current array (optional using dot-notation). |
||
| 4111 | * |
||
| 4112 | * @param string $key <p>The key to set.</p> |
||
| 4113 | * @param mixed $value <p>Its value.</p> |
||
| 4114 | * |
||
| 4115 | * @return static |
||
| 4116 | * <p>(Mutable)</p> |
||
| 4117 | */ |
||
| 4118 | 18 | public function set($key, $value): self |
|
| 4126 | |||
| 4127 | /** |
||
| 4128 | * Get a value from a array and set it if it was not. |
||
| 4129 | * |
||
| 4130 | * WARNING: this method only set the value, if the $key is not already set |
||
| 4131 | * |
||
| 4132 | * @param mixed $key <p>The key</p> |
||
| 4133 | * @param mixed $fallback <p>The default value to set if it isn't.</p> |
||
| 4134 | * |
||
| 4135 | * @return mixed |
||
| 4136 | * <p>(Mutable)</p> |
||
| 4137 | */ |
||
| 4138 | 11 | public function setAndGet($key, $fallback = null) |
|
| 4149 | |||
| 4150 | /** |
||
| 4151 | * Shifts a specified value off the beginning of array. |
||
| 4152 | * |
||
| 4153 | * @return mixed |
||
| 4154 | * <p>(Mutable) A shifted element from the current array.</p> |
||
| 4155 | */ |
||
| 4156 | 5 | public function shift() |
|
| 4162 | |||
| 4163 | /** |
||
| 4164 | * Shuffle the current array. |
||
| 4165 | * |
||
| 4166 | * @param bool $secure <p>using a CSPRNG | @link https://paragonie.com/b/JvICXzh_jhLyt4y3</p> |
||
| 4167 | * @param array $array [optional] |
||
| 4168 | * |
||
| 4169 | * @return static |
||
| 4170 | * <p>(Immutable)</p> |
||
| 4171 | */ |
||
| 4172 | 2 | public function shuffle(bool $secure = false, array $array = null): self |
|
| 4215 | |||
| 4216 | /** |
||
| 4217 | * Count the values from the current array. |
||
| 4218 | * |
||
| 4219 | * alias: for "Arrayy->count()" |
||
| 4220 | * |
||
| 4221 | * @param int $mode |
||
| 4222 | * |
||
| 4223 | * @return int |
||
| 4224 | */ |
||
| 4225 | 20 | public function size(int $mode = \COUNT_NORMAL): int |
|
| 4229 | |||
| 4230 | /** |
||
| 4231 | * Checks whether array has exactly $size items. |
||
| 4232 | * |
||
| 4233 | * @param int $size |
||
| 4234 | * |
||
| 4235 | * @return bool |
||
| 4236 | */ |
||
| 4237 | 1 | View Code Duplication | public function sizeIs(int $size): bool |
| 4251 | |||
| 4252 | /** |
||
| 4253 | * Checks whether array has between $fromSize to $toSize items. $toSize can be |
||
| 4254 | * smaller than $fromSize. |
||
| 4255 | * |
||
| 4256 | * @param int $fromSize |
||
| 4257 | * @param int $toSize |
||
| 4258 | * |
||
| 4259 | * @return bool |
||
| 4260 | */ |
||
| 4261 | 1 | public function sizeIsBetween(int $fromSize, int $toSize): bool |
|
| 4281 | |||
| 4282 | /** |
||
| 4283 | * Checks whether array has more than $size items. |
||
| 4284 | * |
||
| 4285 | * @param int $size |
||
| 4286 | * |
||
| 4287 | * @return bool |
||
| 4288 | */ |
||
| 4289 | 1 | View Code Duplication | public function sizeIsGreaterThan(int $size): bool |
| 4303 | |||
| 4304 | /** |
||
| 4305 | * Checks whether array has less than $size items. |
||
| 4306 | * |
||
| 4307 | * @param int $size |
||
| 4308 | * |
||
| 4309 | * @return bool |
||
| 4310 | */ |
||
| 4311 | 1 | View Code Duplication | public function sizeIsLessThan(int $size): bool |
| 4325 | |||
| 4326 | /** |
||
| 4327 | * Counts all elements in an array, or something in an object. |
||
| 4328 | * |
||
| 4329 | * <p> |
||
| 4330 | * For objects, if you have SPL installed, you can hook into count() by implementing interface {@see Countable}. |
||
| 4331 | * The interface has exactly one method, {@see Countable::count()}, which returns the return value for the count() |
||
| 4332 | * function. Please see the {@see Array} section of the manual for a detailed explanation of how arrays are |
||
| 4333 | * implemented and used in PHP. |
||
| 4334 | * </p> |
||
| 4335 | * |
||
| 4336 | * @return int |
||
| 4337 | * <p> |
||
| 4338 | * The number of elements in var, which is |
||
| 4339 | * typically an array, since anything else will have one |
||
| 4340 | * element. |
||
| 4341 | * </p> |
||
| 4342 | * <p> |
||
| 4343 | * If var is not an array or an object with |
||
| 4344 | * implemented Countable interface, |
||
| 4345 | * 1 will be returned. |
||
| 4346 | * There is one exception, if var is &null;, |
||
| 4347 | * 0 will be returned. |
||
| 4348 | * </p> |
||
| 4349 | * <p> |
||
| 4350 | * Caution: count may return 0 for a variable that isn't set, |
||
| 4351 | * but it may also return 0 for a variable that has been initialized with an |
||
| 4352 | * empty array. Use isset to test if a variable is set. |
||
| 4353 | * </p> |
||
| 4354 | */ |
||
| 4355 | 10 | public function sizeRecursive(): int |
|
| 4359 | |||
| 4360 | /** |
||
| 4361 | * Extract a slice of the array. |
||
| 4362 | * |
||
| 4363 | * @param int $offset <p>Slice begin index.</p> |
||
| 4364 | * @param int|null $length <p>Length of the slice.</p> |
||
| 4365 | * @param bool $preserveKeys <p>Whether array keys are preserved or no.</p> |
||
| 4366 | * |
||
| 4367 | * @return static |
||
| 4368 | * <p>A slice of the original array with length $length.</p> |
||
| 4369 | */ |
||
| 4370 | 5 | public function slice(int $offset, int $length = null, bool $preserveKeys = false) |
|
| 4383 | |||
| 4384 | /** |
||
| 4385 | * Sort the current array and optional you can keep the keys. |
||
| 4386 | * |
||
| 4387 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 4388 | * @param int $strategy <p>sort_flags => use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 4389 | * <strong>SORT_NATURAL</strong></p> |
||
| 4390 | * @param bool $keepKeys |
||
| 4391 | * |
||
| 4392 | * @return static |
||
| 4393 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 4394 | */ |
||
| 4395 | 20 | public function sort($direction = \SORT_ASC, int $strategy = \SORT_REGULAR, bool $keepKeys = false): self |
|
| 4406 | |||
| 4407 | /** |
||
| 4408 | * Sort the current array by key. |
||
| 4409 | * |
||
| 4410 | * @see http://php.net/manual/en/function.ksort.php |
||
| 4411 | * @see http://php.net/manual/en/function.krsort.php |
||
| 4412 | * |
||
| 4413 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 4414 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 4415 | * <strong>SORT_NATURAL</strong></p> |
||
| 4416 | * |
||
| 4417 | * @return static |
||
| 4418 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 4419 | */ |
||
| 4420 | 18 | public function sortKeys($direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
| 4428 | |||
| 4429 | /** |
||
| 4430 | * Sort the current array by value. |
||
| 4431 | * |
||
| 4432 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 4433 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 4434 | * <strong>SORT_NATURAL</strong></p> |
||
| 4435 | * |
||
| 4436 | * @return static |
||
| 4437 | * <p>(Mutable)</p> |
||
| 4438 | */ |
||
| 4439 | 1 | public function sortValueKeepIndex($direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
| 4443 | |||
| 4444 | /** |
||
| 4445 | * Sort the current array by value. |
||
| 4446 | * |
||
| 4447 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 4448 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 4449 | * <strong>SORT_NATURAL</strong></p> |
||
| 4450 | * |
||
| 4451 | * @return static |
||
| 4452 | * <p>(Mutable)</p> |
||
| 4453 | */ |
||
| 4454 | 1 | public function sortValueNewIndex($direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
| 4458 | |||
| 4459 | /** |
||
| 4460 | * Sort a array by value, by a closure or by a property. |
||
| 4461 | * |
||
| 4462 | * - If the sorter is null, the array is sorted naturally. |
||
| 4463 | * - Associative (string) keys will be maintained, but numeric keys will be re-indexed. |
||
| 4464 | * |
||
| 4465 | * @param callable|string|null $sorter |
||
| 4466 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or |
||
| 4467 | * <strong>SORT_DESC</strong></p> |
||
| 4468 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 4469 | * <strong>SORT_NATURAL</strong></p> |
||
| 4470 | * |
||
| 4471 | * @return static |
||
| 4472 | * <p>(Immutable)</p> |
||
| 4473 | */ |
||
| 4474 | 1 | public function sorter($sorter = null, $direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
| 4511 | |||
| 4512 | /** |
||
| 4513 | * @param int $offset |
||
| 4514 | * @param int|null $length |
||
| 4515 | * @param array $replacement |
||
| 4516 | * |
||
| 4517 | * @return static |
||
| 4518 | * <p>(Immutable)</p> |
||
| 4519 | */ |
||
| 4520 | 1 | public function splice(int $offset, int $length = null, $replacement = []): self |
|
| 4532 | |||
| 4533 | /** |
||
| 4534 | * Split an array in the given amount of pieces. |
||
| 4535 | * |
||
| 4536 | * @param int $numberOfPieces |
||
| 4537 | * @param bool $keepKeys |
||
| 4538 | * |
||
| 4539 | * @return static |
||
| 4540 | * <p>(Immutable)</p> |
||
| 4541 | */ |
||
| 4542 | 1 | public function split(int $numberOfPieces = 2, bool $keepKeys = false): self |
|
| 4561 | |||
| 4562 | /** |
||
| 4563 | * Stripe all empty items. |
||
| 4564 | * |
||
| 4565 | * @return static |
||
| 4566 | * <p>(Immutable)</p> |
||
| 4567 | */ |
||
| 4568 | 1 | public function stripEmpty(): self |
|
| 4580 | |||
| 4581 | /** |
||
| 4582 | * Swap two values between positions by key. |
||
| 4583 | * |
||
| 4584 | * @param int|string $swapA <p>a key in the array</p> |
||
| 4585 | * @param int|string $swapB <p>a key in the array</p> |
||
| 4586 | * |
||
| 4587 | * @return static |
||
| 4588 | * <p>(Immutable)</p> |
||
| 4589 | */ |
||
| 4590 | 1 | public function swap($swapA, $swapB): self |
|
| 4602 | |||
| 4603 | /** |
||
| 4604 | * alias: for "Arrayy->getArray()" |
||
| 4605 | * |
||
| 4606 | * @param bool $convertAllArrayyElements |
||
| 4607 | * |
||
| 4608 | * @return array |
||
| 4609 | * |
||
| 4610 | * @see Arrayy::getArray() |
||
| 4611 | */ |
||
| 4612 | 237 | public function toArray(bool $convertAllArrayyElements = false): array |
|
| 4616 | |||
| 4617 | /** |
||
| 4618 | * Convert the current array to JSON. |
||
| 4619 | * |
||
| 4620 | * @param int $options [optional] <p>e.g. JSON_PRETTY_PRINT</p> |
||
| 4621 | * @param int $depth [optional] <p>Set the maximum depth. Must be greater than zero.</p> |
||
| 4622 | * |
||
| 4623 | * @return string |
||
| 4624 | */ |
||
| 4625 | 7 | public function toJson(int $options = 0, int $depth = 512): string |
|
| 4634 | |||
| 4635 | /** |
||
| 4636 | * Implodes array to a string with specified separator. |
||
| 4637 | * |
||
| 4638 | * @param string $separator [optional] <p>The element's separator.</p> |
||
| 4639 | * |
||
| 4640 | * @return string |
||
| 4641 | * <p>The string representation of array, separated by ",".</p> |
||
| 4642 | */ |
||
| 4643 | 19 | public function toString(string $separator = ','): string |
|
| 4647 | |||
| 4648 | /** |
||
| 4649 | * Return a duplicate free copy of the current array. |
||
| 4650 | * |
||
| 4651 | * @return static |
||
| 4652 | * <p>(Mutable)</p> |
||
| 4653 | */ |
||
| 4654 | 13 | public function unique(): self |
|
| 4672 | |||
| 4673 | /** |
||
| 4674 | * Return a duplicate free copy of the current array. (with the old keys) |
||
| 4675 | * |
||
| 4676 | * @return static |
||
| 4677 | * <p>(Mutable)</p> |
||
| 4678 | */ |
||
| 4679 | 11 | public function uniqueKeepIndex(): self |
|
| 4707 | |||
| 4708 | /** |
||
| 4709 | * alias: for "Arrayy->unique()" |
||
| 4710 | * |
||
| 4711 | * @return static |
||
| 4712 | * <p>(Mutable) Return this Arrayy object, with the appended values.</p> |
||
| 4713 | * |
||
| 4714 | * @see Arrayy::unique() |
||
| 4715 | */ |
||
| 4716 | 10 | public function uniqueNewIndex(): self |
|
| 4720 | |||
| 4721 | /** |
||
| 4722 | * Prepends one or more values to the beginning of array at once. |
||
| 4723 | * |
||
| 4724 | * @param array ...$args |
||
| 4725 | * |
||
| 4726 | * @return static |
||
| 4727 | * <p>(Mutable) Return this Arrayy object, with prepended elements to the beginning of array.</p> |
||
| 4728 | */ |
||
| 4729 | 4 | public function unshift(...$args): self |
|
| 4737 | |||
| 4738 | /** |
||
| 4739 | * Get all values from a array. |
||
| 4740 | * |
||
| 4741 | * @return static |
||
| 4742 | * <p>(Immutable)</p> |
||
| 4743 | */ |
||
| 4744 | 2 | public function values(): self |
|
| 4757 | |||
| 4758 | /** |
||
| 4759 | * Apply the given function to every element in the array, discarding the results. |
||
| 4760 | * |
||
| 4761 | * @param callable $callable |
||
| 4762 | * @param bool $recursive <p>Whether array will be walked recursively or no</p> |
||
| 4763 | * |
||
| 4764 | * @return static |
||
| 4765 | * <p>(Mutable) Return this Arrayy object, with modified elements.</p> |
||
| 4766 | */ |
||
| 4767 | 12 | public function walk($callable, bool $recursive = false): self |
|
| 4779 | |||
| 4780 | /** |
||
| 4781 | * Convert an array into a object. |
||
| 4782 | * |
||
| 4783 | * @param array $array PHP array |
||
| 4784 | * |
||
| 4785 | * @return \stdClass |
||
| 4786 | */ |
||
| 4787 | 4 | protected static function arrayToObject(array $array = []): \stdClass |
|
| 4806 | |||
| 4807 | /** |
||
| 4808 | * @param array|\Generator|null $input <p> |
||
| 4809 | * An array containing keys to return. |
||
| 4810 | * </p> |
||
| 4811 | * @param mixed|null $search_values [optional] <p> |
||
| 4812 | * If specified, then only keys containing these values are returned. |
||
| 4813 | * </p> |
||
| 4814 | * @param bool $strict [optional] <p> |
||
| 4815 | * Determines if strict comparison (===) should be used during the |
||
| 4816 | * search. |
||
| 4817 | * </p> |
||
| 4818 | * |
||
| 4819 | * @return array |
||
| 4820 | * <p>an array of all the keys in input</p> |
||
| 4821 | */ |
||
| 4822 | 11 | protected function array_keys_recursive( |
|
| 4883 | |||
| 4884 | /** |
||
| 4885 | * @param mixed $path |
||
| 4886 | * @param callable $callable |
||
| 4887 | * @param array|null $currentOffset |
||
| 4888 | * |
||
| 4889 | * @return void |
||
| 4890 | */ |
||
| 4891 | 4 | protected function callAtPath($path, $callable, &$currentOffset = null) |
|
| 4920 | |||
| 4921 | /** |
||
| 4922 | * create a fallback for array |
||
| 4923 | * |
||
| 4924 | * 1. use the current array, if it's a array |
||
| 4925 | * 2. fallback to empty array, if there is nothing |
||
| 4926 | * 3. call "getArray()" on object, if there is a "Arrayy"-object |
||
| 4927 | * 4. call "createFromObject()" on object, if there is a "\Traversable"-object |
||
| 4928 | * 5. call "__toArray()" on object, if the method exists |
||
| 4929 | * 6. cast a string or object with "__toString()" into an array |
||
| 4930 | * 7. throw a "InvalidArgumentException"-Exception |
||
| 4931 | * |
||
| 4932 | * @param mixed $data |
||
| 4933 | * |
||
| 4934 | * @throws \InvalidArgumentException |
||
| 4935 | * |
||
| 4936 | * @return array |
||
| 4937 | */ |
||
| 4938 | 1053 | protected function fallbackForArray(&$data): array |
|
| 4948 | |||
| 4949 | /** |
||
| 4950 | * @return bool |
||
| 4951 | * |
||
| 4952 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
| 4953 | */ |
||
| 4954 | 970 | protected function generatorToArray() |
|
| 4965 | |||
| 4966 | /** |
||
| 4967 | * Get correct PHP constant for direction. |
||
| 4968 | * |
||
| 4969 | * @param int|string $direction |
||
| 4970 | * |
||
| 4971 | * @return int |
||
| 4972 | */ |
||
| 4973 | 39 | protected function getDirection($direction): int |
|
| 4995 | |||
| 4996 | /** |
||
| 4997 | * @return TypeCheckPhpDoc[] |
||
| 4998 | * |
||
| 4999 | * @noinspection ReturnTypeCanBeDeclaredInspection |
||
| 5000 | */ |
||
| 5001 | 16 | protected function getPropertiesFromPhpDoc() |
|
| 5026 | |||
| 5027 | /** |
||
| 5028 | * @param mixed $glue |
||
| 5029 | * @param mixed $pieces |
||
| 5030 | * @param bool $useKeys |
||
| 5031 | * |
||
| 5032 | * @return string |
||
| 5033 | */ |
||
| 5034 | 36 | protected function implode_recursive($glue = '', $pieces = [], bool $useKeys = false): string |
|
| 5064 | |||
| 5065 | /** |
||
| 5066 | * @param mixed $needle <p> |
||
| 5067 | * The searched value. |
||
| 5068 | * </p> |
||
| 5069 | * <p> |
||
| 5070 | * If needle is a string, the comparison is done |
||
| 5071 | * in a case-sensitive manner. |
||
| 5072 | * </p> |
||
| 5073 | * @param array|\Generator|null $haystack <p> |
||
| 5074 | * The array. |
||
| 5075 | * </p> |
||
| 5076 | * @param bool $strict [optional] <p> |
||
| 5077 | * If the third parameter strict is set to true |
||
| 5078 | * then the in_array function will also check the |
||
| 5079 | * types of the |
||
| 5080 | * needle in the haystack. |
||
| 5081 | * </p> |
||
| 5082 | * |
||
| 5083 | * @return bool |
||
| 5084 | * <p>true if needle is found in the array, false otherwise</p> |
||
| 5085 | */ |
||
| 5086 | 18 | protected function in_array_recursive($needle, $haystack = null, $strict = true): bool |
|
| 5111 | |||
| 5112 | /** |
||
| 5113 | * @param mixed $data |
||
| 5114 | * |
||
| 5115 | * @return array|null |
||
| 5116 | */ |
||
| 5117 | 1053 | protected function internalGetArray(&$data) |
|
| 5165 | |||
| 5166 | /** |
||
| 5167 | * Internal mechanics of remove method. |
||
| 5168 | * |
||
| 5169 | * @param mixed $key |
||
| 5170 | * |
||
| 5171 | * @return bool |
||
| 5172 | */ |
||
| 5173 | 18 | protected function internalRemove($key): bool |
|
| 5206 | |||
| 5207 | /** |
||
| 5208 | * Internal mechanic of set method. |
||
| 5209 | * |
||
| 5210 | * @param int|string|null $key |
||
| 5211 | * @param mixed $value |
||
| 5212 | * @param bool $checkProperties |
||
| 5213 | * |
||
| 5214 | * @return bool |
||
| 5215 | */ |
||
| 5216 | 927 | protected function internalSet( |
|
| 5262 | |||
| 5263 | /** |
||
| 5264 | * Convert a object into an array. |
||
| 5265 | * |
||
| 5266 | * @param object $object |
||
| 5267 | * |
||
| 5268 | * @return mixed |
||
| 5269 | */ |
||
| 5270 | 5 | protected static function objectToArray($object) |
|
| 5282 | |||
| 5283 | /** |
||
| 5284 | * @param array $data |
||
| 5285 | * @param bool $checkPropertiesInConstructor |
||
| 5286 | * |
||
| 5287 | * @return void |
||
| 5288 | */ |
||
| 5289 | 1051 | protected function setInitialValuesAndProperties(array &$data, bool $checkPropertiesInConstructor) |
|
| 5331 | |||
| 5332 | /** |
||
| 5333 | * sorting keys |
||
| 5334 | * |
||
| 5335 | * @param array $elements |
||
| 5336 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 5337 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 5338 | * <strong>SORT_NATURAL</strong></p> |
||
| 5339 | * |
||
| 5340 | * @return static |
||
| 5341 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 5342 | */ |
||
| 5343 | 18 | protected function sorterKeys(array &$elements, $direction = \SORT_ASC, int $strategy = \SORT_REGULAR): self |
|
| 5361 | |||
| 5362 | /** |
||
| 5363 | * @param array $elements <p>Warning: used as reference</p> |
||
| 5364 | * @param int|string $direction <p>use <strong>SORT_ASC</strong> (default) or <strong>SORT_DESC</strong></p> |
||
| 5365 | * @param int $strategy <p>use e.g.: <strong>SORT_REGULAR</strong> (default) or |
||
| 5366 | * <strong>SORT_NATURAL</strong></p> |
||
| 5367 | * @param bool $keepKeys |
||
| 5368 | * |
||
| 5369 | * @return static |
||
| 5370 | * <p>(Mutable) Return this Arrayy object.</p> |
||
| 5371 | */ |
||
| 5372 | 20 | protected function sorting(array &$elements, $direction = \SORT_ASC, int $strategy = \SORT_REGULAR, bool $keepKeys = false): self |
|
| 5402 | |||
| 5403 | /** |
||
| 5404 | * @param int|string|null $key |
||
| 5405 | * @param mixed $value |
||
| 5406 | * |
||
| 5407 | * @return void |
||
| 5408 | */ |
||
| 5409 | 84 | private function checkType($key, $value) |
|
| 5427 | } |
||
| 5428 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.