Complex classes like CollectionProxy 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 CollectionProxy, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 10 | class CollectionProxy extends EntityCollection implements ProxyInterface |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * Indicate if the relationship has been lazy loaded. |
||
| 14 | * |
||
| 15 | * @var bool |
||
| 16 | */ |
||
| 17 | protected $relationshipLoaded = false; |
||
| 18 | |||
| 19 | protected $addedItems = []; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Create a new collection. |
||
| 23 | * |
||
| 24 | * @param mixed $entity |
||
| 25 | * @param string $relation |
||
| 26 | * |
||
| 27 | * @return void |
||
|
|
|||
| 28 | */ |
||
| 29 | public function __construct($entity, $relation) |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Return Items that has been added without lady loading |
||
| 37 | * the underlying collection. |
||
| 38 | * |
||
| 39 | * @return array |
||
| 40 | */ |
||
| 41 | public function getAddedItems() |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Force initialization of the proxy. |
||
| 48 | * |
||
| 49 | * @return bool true if the proxy could be initialized |
||
| 50 | */ |
||
| 51 | public function initializeProxy() : bool |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Retrieves current initialization status of the proxy. |
||
| 71 | * |
||
| 72 | * @return bool |
||
| 73 | */ |
||
| 74 | public function isProxyInitialized() : bool |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Get all of the items in the collection. |
||
| 81 | * |
||
| 82 | * @return array |
||
| 83 | */ |
||
| 84 | public function all() |
||
| 90 | |||
| 91 | /** |
||
| 92 | * Get the average value of a given key. |
||
| 93 | * |
||
| 94 | * @param callable|string|null $callback |
||
| 95 | * |
||
| 96 | * @return mixed |
||
| 97 | */ |
||
| 98 | public function avg($callback = null) |
||
| 104 | |||
| 105 | /** |
||
| 106 | * Get the median of a given key. |
||
| 107 | * |
||
| 108 | * @param null $key |
||
| 109 | * |
||
| 110 | * @return mixed|null |
||
| 111 | */ |
||
| 112 | public function median($key = null) |
||
| 118 | |||
| 119 | /** |
||
| 120 | * Get the mode of a given key. |
||
| 121 | * |
||
| 122 | * @param mixed $key |
||
| 123 | * |
||
| 124 | * @return array |
||
| 125 | */ |
||
| 126 | public function mode($key = null) |
||
| 132 | |||
| 133 | /** |
||
| 134 | * Collapse the collection of items into a single array. |
||
| 135 | * |
||
| 136 | * @return static |
||
| 137 | */ |
||
| 138 | public function collapse() |
||
| 144 | |||
| 145 | /** |
||
| 146 | * Determine if an item exists in the collection. |
||
| 147 | * |
||
| 148 | * @param mixed $key |
||
| 149 | * @param mixed $value |
||
| 150 | * |
||
| 151 | * @return bool |
||
| 152 | */ |
||
| 153 | public function contains($key, $operator = null, $value = null) |
||
| 154 | { |
||
| 155 | $this->initializeProxy(); |
||
| 156 | |||
| 157 | return parent::contains($key, $operator, $value); |
||
| 158 | } |
||
| 159 | |||
| 160 | /** |
||
| 161 | * Determine if an item exists in the collection using strict comparison. |
||
| 162 | * |
||
| 163 | * @param mixed $key |
||
| 164 | * @param mixed $value |
||
| 165 | * |
||
| 166 | * @return bool |
||
| 167 | */ |
||
| 168 | public function containsStrict($key, $value = null) |
||
| 174 | |||
| 175 | /** |
||
| 176 | * Get the items in the collection that are not present in the given items. |
||
| 177 | * |
||
| 178 | * @param mixed $items |
||
| 179 | * |
||
| 180 | * @return static |
||
| 181 | */ |
||
| 182 | public function diff($items) |
||
| 188 | |||
| 189 | /** |
||
| 190 | * Get the items in the collection whose keys are not present in the given items. |
||
| 191 | * |
||
| 192 | * @param mixed $items |
||
| 193 | * |
||
| 194 | * @return static |
||
| 195 | */ |
||
| 196 | public function diffKeys($items) |
||
| 202 | |||
| 203 | /** |
||
| 204 | * Execute a callback over each item. |
||
| 205 | * |
||
| 206 | * @param callable $callback |
||
| 207 | * |
||
| 208 | * @return $this |
||
| 209 | */ |
||
| 210 | public function each(callable $callback) |
||
| 216 | |||
| 217 | /** |
||
| 218 | * Create a new collection consisting of every n-th element. |
||
| 219 | * |
||
| 220 | * @param int $step |
||
| 221 | * @param int $offset |
||
| 222 | * |
||
| 223 | * @return static |
||
| 224 | */ |
||
| 225 | public function every($key, $operator = null, $value = null) |
||
| 226 | { |
||
| 227 | $this->initializeProxy(); |
||
| 228 | |||
| 229 | return parent::every($key, $operator, $value); |
||
| 230 | } |
||
| 231 | |||
| 232 | /** |
||
| 233 | * Get all items except for those with the specified keys. |
||
| 234 | * |
||
| 235 | * @param mixed $keys |
||
| 236 | * |
||
| 237 | * @return static |
||
| 238 | */ |
||
| 239 | public function except($keys) |
||
| 245 | |||
| 246 | /** |
||
| 247 | * Run a filter over each of the items. |
||
| 248 | * |
||
| 249 | * @param callable|null $callback |
||
| 250 | * |
||
| 251 | * @return static |
||
| 252 | */ |
||
| 253 | public function filter(callable $callback = null) |
||
| 259 | |||
| 260 | /** |
||
| 261 | * Filter items by the given key value pair. |
||
| 262 | * |
||
| 263 | * @param string $key |
||
| 264 | * @param mixed $operator |
||
| 265 | * @param mixed $value |
||
| 266 | * |
||
| 267 | * @return static |
||
| 268 | */ |
||
| 269 | public function where($key, $operator, $value = null) |
||
| 275 | |||
| 276 | /** |
||
| 277 | * Filter items by the given key value pair using strict comparison. |
||
| 278 | * |
||
| 279 | * @param string $key |
||
| 280 | * @param mixed $value |
||
| 281 | * |
||
| 282 | * @return static |
||
| 283 | */ |
||
| 284 | public function whereStrict($key, $value) |
||
| 290 | |||
| 291 | /** |
||
| 292 | * Filter items by the given key value pair. |
||
| 293 | * |
||
| 294 | * @param string $key |
||
| 295 | * @param mixed $values |
||
| 296 | * @param bool $strict |
||
| 297 | * |
||
| 298 | * @return static |
||
| 299 | */ |
||
| 300 | public function whereIn($key, $values, $strict = false) |
||
| 306 | |||
| 307 | /** |
||
| 308 | * Filter items by the given key value pair using strict comparison. |
||
| 309 | * |
||
| 310 | * @param string $key |
||
| 311 | * @param mixed $values |
||
| 312 | * |
||
| 313 | * @return static |
||
| 314 | */ |
||
| 315 | public function whereInStrict($key, $values) |
||
| 321 | |||
| 322 | /** |
||
| 323 | * Get the first item from the collection. |
||
| 324 | * |
||
| 325 | * @param callable|null $callback |
||
| 326 | * @param mixed $default |
||
| 327 | * |
||
| 328 | * @return mixed |
||
| 329 | */ |
||
| 330 | public function first(callable $callback = null, $default = null) |
||
| 337 | |||
| 338 | /** |
||
| 339 | * Get a flattened array of the items in the collection. |
||
| 340 | * |
||
| 341 | * @param int $depth |
||
| 342 | * |
||
| 343 | * @return static |
||
| 344 | */ |
||
| 345 | public function flatten($depth = INF) |
||
| 351 | |||
| 352 | /** |
||
| 353 | * Flip the items in the collection. |
||
| 354 | * |
||
| 355 | * @return static |
||
| 356 | */ |
||
| 357 | public function flip() |
||
| 363 | |||
| 364 | /** |
||
| 365 | * Remove an item from the collection by key. |
||
| 366 | * |
||
| 367 | * @param string|array $keys |
||
| 368 | * |
||
| 369 | * @return $this |
||
| 370 | */ |
||
| 371 | public function forget($keys) |
||
| 380 | |||
| 381 | /** |
||
| 382 | * Get an item from the collection by key. |
||
| 383 | * |
||
| 384 | * @param mixed $key |
||
| 385 | * @param mixed $default |
||
| 386 | * |
||
| 387 | * @return mixed |
||
| 388 | */ |
||
| 389 | public function get($key, $default = null) |
||
| 397 | |||
| 398 | /** |
||
| 399 | * Group an associative array by a field or using a callback. |
||
| 400 | * |
||
| 401 | * @param callable|string $groupBy |
||
| 402 | * @param bool $preserveKeys |
||
| 403 | * |
||
| 404 | * @return static |
||
| 405 | */ |
||
| 406 | public function groupBy($groupBy, $preserveKeys = false) |
||
| 412 | |||
| 413 | /** |
||
| 414 | * Key an associative array by a field or using a callback. |
||
| 415 | * |
||
| 416 | * @param callable|string $keyBy |
||
| 417 | * |
||
| 418 | * @return static |
||
| 419 | */ |
||
| 420 | public function keyBy($keyBy) |
||
| 426 | |||
| 427 | /** |
||
| 428 | * Determine if an item exists in the collection by key. |
||
| 429 | * |
||
| 430 | * @param mixed $key |
||
| 431 | * |
||
| 432 | * @return bool |
||
| 433 | */ |
||
| 434 | public function has($key) |
||
| 445 | |||
| 446 | /** |
||
| 447 | * Concatenate values of a given key as a string. |
||
| 448 | * |
||
| 449 | * @param string $value |
||
| 450 | * @param string $glue |
||
| 451 | * |
||
| 452 | * @return string |
||
| 453 | */ |
||
| 454 | public function implode($value, $glue = null) |
||
| 460 | |||
| 461 | /** |
||
| 462 | * Intersect the collection with the given items. |
||
| 463 | * |
||
| 464 | * @param mixed $items |
||
| 465 | * |
||
| 466 | * @return static |
||
| 467 | */ |
||
| 468 | public function intersect($items) |
||
| 474 | |||
| 475 | /** |
||
| 476 | * Determine if the collection is empty or not. |
||
| 477 | * |
||
| 478 | * @return bool |
||
| 479 | */ |
||
| 480 | public function isEmpty() |
||
| 486 | |||
| 487 | /** |
||
| 488 | * Get the keys of the collection items. |
||
| 489 | * |
||
| 490 | * @return static |
||
| 491 | */ |
||
| 492 | public function keys() |
||
| 498 | |||
| 499 | /** |
||
| 500 | * Get the last item from the collection. |
||
| 501 | * |
||
| 502 | * @param callable|null $callback |
||
| 503 | * @param mixed $default |
||
| 504 | * |
||
| 505 | * @return mixed |
||
| 506 | */ |
||
| 507 | public function last(callable $callback = null, $default = null) |
||
| 514 | |||
| 515 | /** |
||
| 516 | * Get the values of a given key. |
||
| 517 | * |
||
| 518 | * @param string $value |
||
| 519 | * @param string|null $key |
||
| 520 | * |
||
| 521 | * @return static |
||
| 522 | */ |
||
| 523 | public function pluck($value, $key = null) |
||
| 530 | |||
| 531 | /** |
||
| 532 | * Run a map over each of the items. |
||
| 533 | * |
||
| 534 | * @param callable $callback |
||
| 535 | * |
||
| 536 | * @return static |
||
| 537 | */ |
||
| 538 | public function map(callable $callback) |
||
| 544 | |||
| 545 | /** |
||
| 546 | * Run an associative map over each of the items. |
||
| 547 | * |
||
| 548 | * The callback should return an associative array with a single key/value pair. |
||
| 549 | * |
||
| 550 | * @param callable $callback |
||
| 551 | * |
||
| 552 | * @return static |
||
| 553 | */ |
||
| 554 | public function mapWithKeys(callable $callback) |
||
| 560 | |||
| 561 | /** |
||
| 562 | * Map a collection and flatten the result by a single level. |
||
| 563 | * |
||
| 564 | * @param callable $callback |
||
| 565 | * |
||
| 566 | * @return static |
||
| 567 | */ |
||
| 568 | public function flatMap(callable $callback) |
||
| 574 | |||
| 575 | /** |
||
| 576 | * Get the max value of a given key. |
||
| 577 | * |
||
| 578 | * @param callable|string|null $callback |
||
| 579 | * |
||
| 580 | * @return mixed |
||
| 581 | */ |
||
| 582 | public function max($callback = null) |
||
| 588 | |||
| 589 | /** |
||
| 590 | * Merge the collection with the given items. |
||
| 591 | * |
||
| 592 | * @param mixed $items |
||
| 593 | * |
||
| 594 | * @return static |
||
| 595 | */ |
||
| 596 | public function merge($items) |
||
| 605 | |||
| 606 | /** |
||
| 607 | * Create a collection by using this collection for keys and another for its values. |
||
| 608 | * |
||
| 609 | * @param mixed $values |
||
| 610 | * |
||
| 611 | * @return static |
||
| 612 | */ |
||
| 613 | public function combine($values) |
||
| 622 | |||
| 623 | /** |
||
| 624 | * Union the collection with the given items. |
||
| 625 | * |
||
| 626 | * @param mixed $items |
||
| 627 | * |
||
| 628 | * @return static |
||
| 629 | */ |
||
| 630 | public function union($items) |
||
| 639 | |||
| 640 | /** |
||
| 641 | * Get the min value of a given key. |
||
| 642 | * |
||
| 643 | * @param callable|string|null $callback |
||
| 644 | * |
||
| 645 | * @return mixed |
||
| 646 | */ |
||
| 647 | public function min($callback = null) |
||
| 656 | |||
| 657 | /** |
||
| 658 | * Create a new collection consisting of every n-th element. |
||
| 659 | * |
||
| 660 | * @param int $step |
||
| 661 | * @param int $offset |
||
| 662 | * |
||
| 663 | * @return static |
||
| 664 | */ |
||
| 665 | public function nth($step, $offset = 0) |
||
| 671 | |||
| 672 | /** |
||
| 673 | * Get the items with the specified keys. |
||
| 674 | * |
||
| 675 | * @param mixed $keys |
||
| 676 | * |
||
| 677 | * @return static |
||
| 678 | */ |
||
| 679 | public function only($keys) |
||
| 687 | |||
| 688 | /** |
||
| 689 | * "Paginate" the collection by slicing it into a smaller collection. |
||
| 690 | * |
||
| 691 | * @param int $page |
||
| 692 | * @param int $perPage |
||
| 693 | * |
||
| 694 | * @return static |
||
| 695 | */ |
||
| 696 | public function forPage($page, $perPage) |
||
| 704 | |||
| 705 | /** |
||
| 706 | * Partition the collection into two arrays using the given callback or key. |
||
| 707 | * |
||
| 708 | * @param callable|string $callback |
||
| 709 | * |
||
| 710 | * @return static |
||
| 711 | */ |
||
| 712 | public function partition($callback) |
||
| 718 | |||
| 719 | /** |
||
| 720 | * Pass the collection to the given callback and return the result. |
||
| 721 | * |
||
| 722 | * @param callable $callback |
||
| 723 | * |
||
| 724 | * @return mixed |
||
| 725 | */ |
||
| 726 | public function pipe(callable $callback) |
||
| 732 | |||
| 733 | /** |
||
| 734 | * Get and remove the last item from the collection. |
||
| 735 | * |
||
| 736 | * @return mixed |
||
| 737 | */ |
||
| 738 | public function pop() |
||
| 744 | |||
| 745 | /** |
||
| 746 | * Push an item onto the beginning of the collection. |
||
| 747 | * |
||
| 748 | * @param mixed $value |
||
| 749 | * @param mixed $key |
||
| 750 | * |
||
| 751 | * @return $this |
||
| 752 | */ |
||
| 753 | public function prepend($value, $key = null) |
||
| 763 | |||
| 764 | /** |
||
| 765 | * Push an item onto the end of the collection. |
||
| 766 | * |
||
| 767 | * @param mixed $value |
||
| 768 | * |
||
| 769 | * @return $this |
||
| 770 | */ |
||
| 771 | public function push($value) |
||
| 781 | |||
| 782 | /** |
||
| 783 | * Get and remove an item from the collection. |
||
| 784 | * |
||
| 785 | * @param mixed $key |
||
| 786 | * @param mixed $default |
||
| 787 | * |
||
| 788 | * @return mixed |
||
| 789 | */ |
||
| 790 | public function pull($key, $default = null) |
||
| 799 | |||
| 800 | /** |
||
| 801 | * Put an item in the collection by key. |
||
| 802 | * |
||
| 803 | * @param mixed $key |
||
| 804 | * @param mixed $value |
||
| 805 | * |
||
| 806 | * @return $this |
||
| 807 | */ |
||
| 808 | public function put($key, $value) |
||
| 816 | |||
| 817 | /** |
||
| 818 | * Get one or more items randomly from the collection. |
||
| 819 | * |
||
| 820 | * @param int $amount |
||
| 821 | * |
||
| 822 | * @throws \InvalidArgumentException |
||
| 823 | * |
||
| 824 | * @return mixed |
||
| 825 | */ |
||
| 826 | public function random($amount = 1) |
||
| 836 | |||
| 837 | /** |
||
| 838 | * Reduce the collection to a single value. |
||
| 839 | * |
||
| 840 | * @param callable $callback |
||
| 841 | * @param mixed $initial |
||
| 842 | * |
||
| 843 | * @return mixed |
||
| 844 | */ |
||
| 845 | public function reduce(callable $callback, $initial = null) |
||
| 851 | |||
| 852 | /** |
||
| 853 | * Create a collection of all elements that do not pass a given truth test. |
||
| 854 | * |
||
| 855 | * @param callable|mixed $callback |
||
| 856 | * |
||
| 857 | * @return static |
||
| 858 | */ |
||
| 859 | public function reject($callback) |
||
| 865 | |||
| 866 | /** |
||
| 867 | * Reverse items order. |
||
| 868 | * |
||
| 869 | * @return static |
||
| 870 | */ |
||
| 871 | public function reverse() |
||
| 877 | |||
| 878 | /** |
||
| 879 | * Search the collection for a given value and return the corresponding key if successful. |
||
| 880 | * |
||
| 881 | * @param mixed $value |
||
| 882 | * @param bool $strict |
||
| 883 | * |
||
| 884 | * @return mixed |
||
| 885 | */ |
||
| 886 | public function search($value, $strict = false) |
||
| 892 | |||
| 893 | /** |
||
| 894 | * Get and remove the first item from the collection. |
||
| 895 | * |
||
| 896 | * @return mixed |
||
| 897 | */ |
||
| 898 | public function shift() |
||
| 906 | |||
| 907 | /** |
||
| 908 | * Shuffle the items in the collection. |
||
| 909 | * |
||
| 910 | * @param int $seed |
||
| 911 | * |
||
| 912 | * @return static |
||
| 913 | */ |
||
| 914 | public function shuffle($seed = null) |
||
| 920 | |||
| 921 | /** |
||
| 922 | * Slice the underlying collection array. |
||
| 923 | * |
||
| 924 | * @param int $offset |
||
| 925 | * @param int $length |
||
| 926 | * |
||
| 927 | * @return static |
||
| 928 | */ |
||
| 929 | public function slice($offset, $length = null) |
||
| 935 | |||
| 936 | /** |
||
| 937 | * Split a collection into a certain number of groups. |
||
| 938 | * |
||
| 939 | * @param int $numberOfGroups |
||
| 940 | * |
||
| 941 | * @return static |
||
| 942 | */ |
||
| 943 | public function split($numberOfGroups) |
||
| 949 | |||
| 950 | /** |
||
| 951 | * Chunk the underlying collection array. |
||
| 952 | * |
||
| 953 | * @param int $size |
||
| 954 | * |
||
| 955 | * @return static |
||
| 956 | */ |
||
| 957 | public function chunk($size) |
||
| 964 | |||
| 965 | /** |
||
| 966 | * Sort through each item with a callback. |
||
| 967 | * |
||
| 968 | * @param callable|null $callback |
||
| 969 | * |
||
| 970 | * @return static |
||
| 971 | */ |
||
| 972 | public function sort(callable $callback = null) |
||
| 978 | |||
| 979 | /** |
||
| 980 | * Sort the collection using the given callback. |
||
| 981 | * |
||
| 982 | * @param callable|string $callback |
||
| 983 | * @param int $options |
||
| 984 | * @param bool $descending |
||
| 985 | * |
||
| 986 | * @return static |
||
| 987 | */ |
||
| 988 | public function sortBy($callback, $options = SORT_REGULAR, $descending = false) |
||
| 994 | |||
| 995 | /** |
||
| 996 | * Splice a portion of the underlying collection array. |
||
| 997 | * |
||
| 998 | * @param int $offset |
||
| 999 | * @param int|null $length |
||
| 1000 | * @param mixed $replacement |
||
| 1001 | * |
||
| 1002 | * @return static |
||
| 1003 | */ |
||
| 1004 | public function splice($offset, $length = null, $replacement = []) |
||
| 1010 | |||
| 1011 | /** |
||
| 1012 | * Get the sum of the given values. |
||
| 1013 | * |
||
| 1014 | * @param callable|string|null $callback |
||
| 1015 | * |
||
| 1016 | * @return mixed |
||
| 1017 | */ |
||
| 1018 | public function sum($callback = null) |
||
| 1024 | |||
| 1025 | /** |
||
| 1026 | * Take the first or last {$limit} items. |
||
| 1027 | * |
||
| 1028 | * @param int $limit |
||
| 1029 | * |
||
| 1030 | * @return static |
||
| 1031 | */ |
||
| 1032 | public function take($limit) |
||
| 1039 | |||
| 1040 | /** |
||
| 1041 | * Transform each item in the collection using a callback. |
||
| 1042 | * |
||
| 1043 | * @param callable $callback |
||
| 1044 | * |
||
| 1045 | * @return $this |
||
| 1046 | */ |
||
| 1047 | public function transform(callable $callback) |
||
| 1053 | |||
| 1054 | /** |
||
| 1055 | * Return only unique items from the collection array. |
||
| 1056 | * |
||
| 1057 | * @param string|callable|null $key |
||
| 1058 | * @param bool $strict |
||
| 1059 | * |
||
| 1060 | * @return static |
||
| 1061 | */ |
||
| 1062 | public function unique($key = null, $strict = false) |
||
| 1068 | |||
| 1069 | /** |
||
| 1070 | * Reset the keys on the underlying array. |
||
| 1071 | * |
||
| 1072 | * @return static |
||
| 1073 | */ |
||
| 1074 | public function values() |
||
| 1080 | |||
| 1081 | /** |
||
| 1082 | * Zip the collection together with one or more arrays. |
||
| 1083 | * |
||
| 1084 | * e.g. new Collection([1, 2, 3])->zip([4, 5, 6]); |
||
| 1085 | * => [[1, 4], [2, 5], [3, 6]] |
||
| 1086 | * |
||
| 1087 | * @param mixed ...$items |
||
| 1088 | * |
||
| 1089 | * @return static |
||
| 1090 | */ |
||
| 1091 | public function zip($items) |
||
| 1097 | |||
| 1098 | /** |
||
| 1099 | * Get the collection of items as a plain array. |
||
| 1100 | * |
||
| 1101 | * @return array |
||
| 1102 | */ |
||
| 1103 | public function toArray() |
||
| 1113 | |||
| 1114 | /** |
||
| 1115 | * Convert the object into something JSON serializable. |
||
| 1116 | * |
||
| 1117 | * @return array |
||
| 1118 | */ |
||
| 1119 | public function jsonSerialize() |
||
| 1129 | |||
| 1130 | /** |
||
| 1131 | * Get the collection of items as JSON. |
||
| 1132 | * |
||
| 1133 | * @param int $options |
||
| 1134 | * |
||
| 1135 | * @return string |
||
| 1136 | */ |
||
| 1137 | public function toJson($options = 0) |
||
| 1147 | |||
| 1148 | /** |
||
| 1149 | * Get an iterator for the items. |
||
| 1150 | * |
||
| 1151 | * @return \ArrayIterator |
||
| 1152 | */ |
||
| 1153 | public function getIterator() |
||
| 1159 | |||
| 1160 | /** |
||
| 1161 | * Get a CachingIterator instance. |
||
| 1162 | * |
||
| 1163 | * @param int $flags |
||
| 1164 | * |
||
| 1165 | * @return \CachingIterator |
||
| 1166 | */ |
||
| 1167 | public function getCachingIterator($flags = CachingIterator::CALL_TOSTRING) |
||
| 1173 | |||
| 1174 | /** |
||
| 1175 | * Count the number of items in the collection. |
||
| 1176 | * |
||
| 1177 | * @return int |
||
| 1178 | */ |
||
| 1179 | public function count() |
||
| 1186 | |||
| 1187 | /** |
||
| 1188 | * Get a base Support collection instance from this collection. |
||
| 1189 | * |
||
| 1190 | * @return \Illuminate\Support\Collection |
||
| 1191 | */ |
||
| 1192 | public function toBase() |
||
| 1198 | |||
| 1199 | /** |
||
| 1200 | * Determine if an item exists at an offset. |
||
| 1201 | * |
||
| 1202 | * @param mixed $key |
||
| 1203 | * |
||
| 1204 | * @return bool |
||
| 1205 | */ |
||
| 1206 | public function offsetExists($key) |
||
| 1214 | |||
| 1215 | /** |
||
| 1216 | * Get an item at a given offset. |
||
| 1217 | * |
||
| 1218 | * @param mixed $key |
||
| 1219 | * |
||
| 1220 | * @return mixed |
||
| 1221 | */ |
||
| 1222 | public function offsetGet($key) |
||
| 1230 | |||
| 1231 | /** |
||
| 1232 | * Set the item at a given offset. |
||
| 1233 | * |
||
| 1234 | * @param mixed $key |
||
| 1235 | * @param mixed $value |
||
| 1236 | * |
||
| 1237 | * @return void |
||
| 1238 | */ |
||
| 1239 | public function offsetSet($key, $value) |
||
| 1247 | |||
| 1248 | /** |
||
| 1249 | * Unset the item at a given offset. |
||
| 1250 | * |
||
| 1251 | * @param string $key |
||
| 1252 | * |
||
| 1253 | * @return void |
||
| 1254 | */ |
||
| 1255 | public function offsetUnset($key) |
||
| 1263 | |||
| 1264 | /** |
||
| 1265 | * Dynamically access collection proxies. |
||
| 1266 | * |
||
| 1267 | * @param string $key |
||
| 1268 | * |
||
| 1269 | * @throws \Exception |
||
| 1270 | * |
||
| 1271 | * @return mixed |
||
| 1272 | */ |
||
| 1273 | public function __get($key) |
||
| 1277 | |||
| 1278 | /** |
||
| 1279 | * Dynamically handle calls to the class. |
||
| 1280 | * |
||
| 1281 | * @param string $method |
||
| 1282 | * @param array $parameters |
||
| 1283 | * |
||
| 1284 | * @throws \BadMethodCallException |
||
| 1285 | * |
||
| 1286 | * @return mixed |
||
| 1287 | */ |
||
| 1288 | public function __call($method, $parameters) |
||
| 1294 | } |
||
| 1295 |
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.