| @@ -47,9 +47,9 @@ | ||
| 47 | 47 | * @param callable|null $callback |
| 48 | 48 | * |
| 49 | 49 | * @return $this |
| 50 | 50 | */ |
| 51 | - public function filter( ?callable $callback = null ) { | |
| 51 | + public function filter( callable $callback = null ) { | |
| 52 | 52 | if ( ! $callback ) { |
| 53 | 53 | return new static( array_filter( $this->items ) ); |
| 54 | 54 | } |
| 55 | 55 | |
| @@ -123,9 +123,9 @@ | ||
| 123 | 123 | |
| 124 | 124 | /** |
| 125 | 125 | * Run a map over each of the items. |
| 126 | 126 | * |
| 127 | - * @param callable $callback | |
| 127 | + * @param callable $callback | |
| 128 | 128 | * @return $this |
| 129 | 129 | */ |
| 130 | 130 | public function map( callable $callback ) { |
| 131 | 131 | $keys = array_keys( $this->items ); |
| @@ -166,12 +166,8 @@ | ||
| 166 | 166 | |
| 167 | 167 | return $result; |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | - public function reverse() { | |
| 171 | - return new static( array_reverse( $this->items ) ); | |
| 172 | - } | |
| 173 | - | |
| 174 | 170 | /** |
| 175 | 171 | * @param callable $callback |
| 176 | 172 | * |
| 177 | 173 | * @return $this |
| @@ -274,15 +270,15 @@ | ||
| 274 | 270 | /** |
| 275 | 271 | * Get specific item from the collection. |
| 276 | 272 | * |
| 277 | 273 | * @param $key |
| 278 | - * @param null $fallback | |
| 274 | + * @param null $default | |
| 279 | 275 | * |
| 280 | 276 | * @return mixed|null |
| 281 | 277 | */ |
| 282 | - public function get( $key, $fallback = null ) { | |
| 278 | + public function get( $key, $default = null ) { | |
| 283 | 279 | if ( ! array_key_exists( $key, $this->items ) ) { |
| 284 | - return $fallback; | |
| 280 | + return $default; | |
| 285 | 281 | } |
| 286 | 282 | |
| 287 | 283 | return $this->items[ $key ]; |
| 288 | 284 | } |
| @@ -289,15 +285,15 @@ | ||
| 289 | 285 | |
| 290 | 286 | /** |
| 291 | 287 | * Get the first item. |
| 292 | 288 | * |
| 293 | - * @param null $fallback | |
| 289 | + * @param null $default | |
| 294 | 290 | * |
| 295 | 291 | * @return mixed|null |
| 296 | 292 | */ |
| 297 | - public function first( $fallback = null ) { | |
| 293 | + public function first( $default = null ) { | |
| 298 | 294 | if ( $this->is_empty() ) { |
| 299 | - return $fallback; | |
| 295 | + return $default; | |
| 300 | 296 | } |
| 301 | 297 | |
| 302 | 298 | foreach ( $this->items as $item ) { |
| 303 | 299 | return $item; |
| @@ -307,13 +303,13 @@ | ||
| 307 | 303 | /** |
| 308 | 304 | * Find an element from the items. |
| 309 | 305 | * |
| 310 | 306 | * @param callable $callback |
| 311 | - * @param null $fallback | |
| 307 | + * @param null $default | |
| 312 | 308 | * |
| 313 | 309 | * @return mixed|null |
| 314 | 310 | */ |
| 315 | - public function find( callable $callback, $fallback = null ) { | |
| 311 | + public function find( callable $callback, $default = null ) { | |
| 316 | 312 | foreach ( $this->all() as $key => $item ) { |
| 317 | 313 | if ( $callback( $item, $key ) ) { |
| 318 | 314 | return $item; |
| 319 | 315 | } |
| @@ -318,9 +314,9 @@ | ||
| 318 | 314 | return $item; |
| 319 | 315 | } |
| 320 | 316 | } |
| 321 | 317 | |
| 322 | - return $fallback; | |
| 318 | + return $default; | |
| 323 | 319 | } |
| 324 | 320 | |
| 325 | 321 | /** |
| 326 | 322 | * @param callable|string|int $value |
| @@ -402,10 +398,13 @@ | ||
| 402 | 398 | return false; |
| 403 | 399 | } ); |
| 404 | 400 | } |
| 405 | 401 | |
| 402 | + /** | |
| 403 | + * @return array | |
| 404 | + */ | |
| 406 | 405 | public function keys() { |
| 407 | - return new static( array_keys( $this->items ) ); | |
| 406 | + return array_keys( $this->items ); | |
| 408 | 407 | } |
| 409 | 408 | |
| 410 | 409 | /** |
| 411 | 410 | * @return bool |
| @@ -452,12 +451,8 @@ | ||
| 452 | 451 | |
| 453 | 452 | return new static( $result ); |
| 454 | 453 | } |
| 455 | 454 | |
| 456 | - public function flip() { | |
| 457 | - return new static( array_flip( $this->items ) ); | |
| 458 | - } | |
| 459 | - | |
| 460 | 455 | /** |
| 461 | 456 | * @param array ...$values |
| 462 | 457 | * |
| 463 | 458 | * @return $this |
| @@ -485,18 +480,8 @@ | ||
| 485 | 480 | |
| 486 | 481 | return false; |
| 487 | 482 | } |
| 488 | 483 | |
| 489 | - public function every( callable $callback ) { | |
| 490 | - foreach ( $this->items as $key => $item ) { | |
| 491 | - if ( ! $callback( $item, $key ) ) { | |
| 492 | - return false; | |
| 493 | - } | |
| 494 | - } | |
| 495 | - | |
| 496 | - return true; | |
| 497 | - } | |
| 498 | - | |
| 499 | 484 | /** |
| 500 | 485 | * @param mixed $offset |
| 501 | 486 | * |
| 502 | 487 | * @return bool |
| @@ -555,14 +540,14 @@ | ||
| 555 | 540 | |
| 556 | 541 | /** |
| 557 | 542 | * @param $item |
| 558 | 543 | * @param $key |
| 559 | - * @param null $fallback | |
| 544 | + * @param null $default | |
| 560 | 545 | * |
| 561 | 546 | * @return mixed|null |
| 562 | 547 | */ |
| 563 | - private function get_item_value( $item, $key, $fallback = null ) { | |
| 564 | - $value = $fallback; | |
| 548 | + private function get_item_value( $item, $key, $default = null ) { | |
| 549 | + $value = $default; | |
| 565 | 550 | |
| 566 | 551 | if ( is_object( $item ) && isset( $item->{$key} ) ) { |
| 567 | 552 | $value = $item->{$key}; |
| 568 | 553 | } elseif ( is_array( $item ) && isset( $item[ $key ] ) ) { |