Complex classes like Collection 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 Collection, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
23 | class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSerializable |
||
24 | { |
||
25 | |||
26 | /** |
||
27 | * The items contained in the collection. |
||
28 | * |
||
29 | * @var array |
||
30 | */ |
||
31 | protected $items = []; |
||
32 | |||
33 | /** |
||
34 | * The methods that can be proxied. |
||
35 | * |
||
36 | * @var array |
||
37 | */ |
||
38 | protected static $proxies = [ |
||
39 | 'average', 'avg', 'contains', 'each', 'every', 'filter', 'first', 'flatMap', |
||
40 | 'keyBy', 'map', 'partition', 'reject', 'sortBy', 'sortByDesc', 'sum', |
||
41 | ]; |
||
42 | |||
43 | /** |
||
44 | * Create a new collection. |
||
45 | * |
||
46 | * @param mixed $items |
||
47 | * @return void |
||
|
|||
48 | */ |
||
49 | public function __construct($items = []) |
||
53 | |||
54 | /** |
||
55 | * Create a new collection instance if the value isn't one already. |
||
56 | * |
||
57 | * @param mixed $items |
||
58 | * @return static |
||
59 | */ |
||
60 | public static function make($items = []) |
||
64 | |||
65 | /** |
||
66 | * Wrap the given value in a collection if applicable. |
||
67 | * |
||
68 | * @param mixed $value |
||
69 | * @return static |
||
70 | */ |
||
71 | public static function wrap($value) |
||
77 | |||
78 | /** |
||
79 | * Get the underlying items from the given collection if applicable. |
||
80 | * |
||
81 | * @param array|static $value |
||
82 | * @return array |
||
83 | */ |
||
84 | public static function unwrap($value) |
||
88 | |||
89 | /** |
||
90 | * Create a new collection by invoking the callback a given amount of times. |
||
91 | * |
||
92 | * @param int $number |
||
93 | * @param callable $callback |
||
94 | * @return static |
||
95 | */ |
||
96 | public static function times($number, callable $callback = null) |
||
108 | |||
109 | /** |
||
110 | * Get all of the items in the collection. |
||
111 | * |
||
112 | * @return array |
||
113 | */ |
||
114 | public function all() |
||
118 | |||
119 | /** |
||
120 | * Get the average value of a given key. |
||
121 | * |
||
122 | * @param callable|string|null $callback |
||
123 | * @return mixed |
||
124 | */ |
||
125 | public function avg($callback = null) |
||
131 | |||
132 | /** |
||
133 | * Alias for the "avg" method. |
||
134 | * |
||
135 | * @param callable|string|null $callback |
||
136 | * @return mixed |
||
137 | */ |
||
138 | public function average($callback = null) |
||
142 | |||
143 | /** |
||
144 | * Get the median of a given key. |
||
145 | * |
||
146 | * @param null $key |
||
147 | * @return mixed |
||
148 | */ |
||
149 | public function median($key = null) |
||
170 | |||
171 | /** |
||
172 | * Get the mode of a given key. |
||
173 | * |
||
174 | * @param mixed $key |
||
175 | * @return array|null |
||
176 | */ |
||
177 | public function mode($key = null) |
||
201 | |||
202 | /** |
||
203 | * Collapse the collection of items into a single array. |
||
204 | * |
||
205 | * @return static |
||
206 | */ |
||
207 | public function collapse() |
||
211 | |||
212 | /** |
||
213 | * Determine if an item exists in the collection. |
||
214 | * |
||
215 | * @param mixed $key |
||
216 | * @param mixed $operator |
||
217 | * @param mixed $value |
||
218 | * @return bool |
||
219 | */ |
||
220 | public function contains($key, $operator = null, $value = null) |
||
240 | |||
241 | /** |
||
242 | * Determine if an item exists in the collection using strict comparison. |
||
243 | * |
||
244 | * @param mixed $key |
||
245 | * @param mixed $value |
||
246 | * @return bool |
||
247 | */ |
||
248 | public function containsStrict($key, $value = null) |
||
262 | |||
263 | /** |
||
264 | * Cross join with the given lists, returning all possible permutations. |
||
265 | * |
||
266 | * @param mixed ...$lists |
||
267 | * @return static |
||
268 | */ |
||
269 | public function crossJoin(...$lists) |
||
275 | |||
276 | /** |
||
277 | * Get the items in the collection that are not present in the given items. |
||
278 | * |
||
279 | * @param mixed $items |
||
280 | * @return static |
||
281 | */ |
||
282 | public function diff($items) |
||
286 | |||
287 | /** |
||
288 | * Get the items in the collection whose keys and values are not present in the given items. |
||
289 | * |
||
290 | * @param mixed $items |
||
291 | * @return static |
||
292 | */ |
||
293 | public function diffAssoc($items) |
||
297 | |||
298 | /** |
||
299 | * Get the items in the collection whose keys are not present in the given items. |
||
300 | * |
||
301 | * @param mixed $items |
||
302 | * @return static |
||
303 | */ |
||
304 | public function diffKeys($items) |
||
308 | |||
309 | /** |
||
310 | * Execute a callback over each item. |
||
311 | * |
||
312 | * @param callable $callback |
||
313 | * @return $this |
||
314 | */ |
||
315 | public function each(callable $callback) |
||
325 | |||
326 | /** |
||
327 | * Execute a callback over each nested chunk of items. |
||
328 | * |
||
329 | * @param callable $callback |
||
330 | * @return static |
||
331 | */ |
||
332 | public function eachSpread(callable $callback) |
||
340 | |||
341 | /** |
||
342 | * Determine if all items in the collection pass the given test. |
||
343 | * |
||
344 | * @param string|callable $key |
||
345 | * @param mixed $operator |
||
346 | * @param mixed $value |
||
347 | * @return bool |
||
348 | */ |
||
349 | public function every($key, $operator = null, $value = null) |
||
371 | |||
372 | /** |
||
373 | * Get all items except for those with the specified keys. |
||
374 | * |
||
375 | * @param mixed $keys |
||
376 | * @return static |
||
377 | */ |
||
378 | public function except($keys) |
||
384 | |||
385 | /** |
||
386 | * Run a filter over each of the items. |
||
387 | * |
||
388 | * @param callable|null $callback |
||
389 | * @return static |
||
390 | */ |
||
391 | public function filter(callable $callback = null) |
||
399 | |||
400 | /** |
||
401 | * Apply the callback if the value is truthy. |
||
402 | * |
||
403 | * @param bool $value |
||
404 | * @param callable $callback |
||
405 | * @param callable $default |
||
406 | * @return mixed |
||
407 | */ |
||
408 | public function when($value, callable $callback, callable $default = null) |
||
418 | |||
419 | /** |
||
420 | * Apply the callback if the value is falsy. |
||
421 | * |
||
422 | * @param bool $value |
||
423 | * @param callable $callback |
||
424 | * @param callable $default |
||
425 | * @return mixed |
||
426 | */ |
||
427 | public function unless($value, callable $callback, callable $default = null) |
||
431 | |||
432 | /** |
||
433 | * Filter items by the given key value pair. |
||
434 | * |
||
435 | * @param string $key |
||
436 | * @param mixed $operator |
||
437 | * @param mixed $value |
||
438 | * @return static |
||
439 | */ |
||
440 | public function where($key, $operator, $value = null) |
||
450 | |||
451 | /** |
||
452 | * Get an operator checker callback. |
||
453 | * |
||
454 | * @param string $key |
||
455 | * @param string $operator |
||
456 | * @param mixed $value |
||
457 | * @return \Closure |
||
458 | */ |
||
459 | protected function operatorForWhere($key, $operator, $value) |
||
491 | |||
492 | /** |
||
493 | * Filter items by the given key value pair using strict comparison. |
||
494 | * |
||
495 | * @param string $key |
||
496 | * @param mixed $value |
||
497 | * @return static |
||
498 | */ |
||
499 | public function whereStrict($key, $value) |
||
503 | |||
504 | /** |
||
505 | * Filter items by the given key value pair. |
||
506 | * |
||
507 | * @param string $key |
||
508 | * @param mixed $values |
||
509 | * @param bool $strict |
||
510 | * @return static |
||
511 | */ |
||
512 | public function whereIn($key, $values, $strict = false) |
||
520 | |||
521 | /** |
||
522 | * Filter items by the given key value pair using strict comparison. |
||
523 | * |
||
524 | * @param string $key |
||
525 | * @param mixed $values |
||
526 | * @return static |
||
527 | */ |
||
528 | public function whereInStrict($key, $values) |
||
532 | |||
533 | /** |
||
534 | * Filter items by the given key value pair. |
||
535 | * |
||
536 | * @param string $key |
||
537 | * @param mixed $values |
||
538 | * @param bool $strict |
||
539 | * @return static |
||
540 | */ |
||
541 | public function whereNotIn($key, $values, $strict = false) |
||
549 | |||
550 | /** |
||
551 | * Filter items by the given key value pair using strict comparison. |
||
552 | * |
||
553 | * @param string $key |
||
554 | * @param mixed $values |
||
555 | * @return static |
||
556 | */ |
||
557 | public function whereNotInStrict($key, $values) |
||
561 | |||
562 | /** |
||
563 | * Get the first item from the collection. |
||
564 | * |
||
565 | * @param callable|null $callback |
||
566 | * @param mixed $default |
||
567 | * @return mixed |
||
568 | */ |
||
569 | public function first(callable $callback = null, $default = null) |
||
573 | |||
574 | /** |
||
575 | * Get a flattened array of the items in the collection. |
||
576 | * |
||
577 | * @param int $depth |
||
578 | * @return static |
||
579 | */ |
||
580 | public function flatten($depth = INF) |
||
584 | |||
585 | /** |
||
586 | * Flip the items in the collection. |
||
587 | * |
||
588 | * @return static |
||
589 | */ |
||
590 | public function flip() |
||
594 | |||
595 | /** |
||
596 | * Remove an item from the collection by key. |
||
597 | * |
||
598 | * @param string|array $keys |
||
599 | * @return $this |
||
600 | */ |
||
601 | public function forget($keys) |
||
609 | |||
610 | /** |
||
611 | * Get an item from the collection by key. |
||
612 | * |
||
613 | * @param mixed $key |
||
614 | * @param mixed $default |
||
615 | * @return mixed |
||
616 | */ |
||
617 | public function get($key, $default = null) |
||
625 | |||
626 | /** |
||
627 | * Group an associative array by a field or using a callback. |
||
628 | * |
||
629 | * @param callable|string $groupBy |
||
630 | * @param bool $preserveKeys |
||
631 | * @return static |
||
632 | */ |
||
633 | public function groupBy($groupBy, $preserveKeys = false) |
||
659 | |||
660 | /** |
||
661 | * Key an associative array by a field or using a callback. |
||
662 | * |
||
663 | * @param callable|string $keyBy |
||
664 | * @return static |
||
665 | */ |
||
666 | public function keyBy($keyBy) |
||
684 | |||
685 | /** |
||
686 | * Determine if an item exists in the collection by key. |
||
687 | * |
||
688 | * @param mixed $key |
||
689 | * @return bool |
||
690 | */ |
||
691 | public function has($key) |
||
703 | |||
704 | /** |
||
705 | * Concatenate values of a given key as a string. |
||
706 | * |
||
707 | * @param string $value |
||
708 | * @param string $glue |
||
709 | * @return string |
||
710 | */ |
||
711 | public function implode($value, $glue = null) |
||
721 | |||
722 | /** |
||
723 | * Intersect the collection with the given items. |
||
724 | * |
||
725 | * @param mixed $items |
||
726 | * @return static |
||
727 | */ |
||
728 | public function intersect($items) |
||
732 | |||
733 | /** |
||
734 | * Intersect the collection with the given items by key. |
||
735 | * |
||
736 | * @param mixed $items |
||
737 | * @return static |
||
738 | */ |
||
739 | public function intersectByKeys($items) |
||
745 | |||
746 | /** |
||
747 | * Determine if the collection is empty or not. |
||
748 | * |
||
749 | * @return bool |
||
750 | */ |
||
751 | public function isEmpty() |
||
755 | |||
756 | /** |
||
757 | * Determine if the collection is not empty. |
||
758 | * |
||
759 | * @return bool |
||
760 | */ |
||
761 | public function isNotEmpty() |
||
765 | |||
766 | /** |
||
767 | * Determine if the given value is callable, but not a string. |
||
768 | * |
||
769 | * @param mixed $value |
||
770 | * @return bool |
||
771 | */ |
||
772 | protected function useAsCallable($value) |
||
776 | |||
777 | /** |
||
778 | * Get the keys of the collection items. |
||
779 | * |
||
780 | * @return static |
||
781 | */ |
||
782 | public function keys() |
||
786 | |||
787 | /** |
||
788 | * Get the last item from the collection. |
||
789 | * |
||
790 | * @param callable|null $callback |
||
791 | * @param mixed $default |
||
792 | * @return mixed |
||
793 | */ |
||
794 | public function last(callable $callback = null, $default = null) |
||
798 | |||
799 | /** |
||
800 | * Get the values of a given key. |
||
801 | * |
||
802 | * @param string|array $value |
||
803 | * @param string|null $key |
||
804 | * @return static |
||
805 | */ |
||
806 | public function pluck($value, $key = null) |
||
810 | |||
811 | /** |
||
812 | * Run a map over each of the items. |
||
813 | * |
||
814 | * @param callable $callback |
||
815 | * @return static |
||
816 | */ |
||
817 | public function map(callable $callback) |
||
825 | |||
826 | /** |
||
827 | * Run a map over each nested chunk of items. |
||
828 | * |
||
829 | * @param callable $callback |
||
830 | * @return static |
||
831 | */ |
||
832 | public function mapSpread(callable $callback) |
||
840 | |||
841 | /** |
||
842 | * Run a dictionary map over the items. |
||
843 | * The callback should return an associative array with a single key/value pair. |
||
844 | * |
||
845 | * @param callable $callback |
||
846 | * @return static |
||
847 | */ |
||
848 | public function mapToDictionary(callable $callback) |
||
858 | |||
859 | /** |
||
860 | * Run a grouping map over the items. |
||
861 | * The callback should return an associative array with a single key/value pair. |
||
862 | * |
||
863 | * @param callable $callback |
||
864 | * @return static |
||
865 | */ |
||
866 | public function mapToGroups(callable $callback) |
||
872 | |||
873 | /** |
||
874 | * Run an associative map over each of the items. |
||
875 | * The callback should return an associative array with a single key/value pair. |
||
876 | * |
||
877 | * @param callable $callback |
||
878 | * @return static |
||
879 | */ |
||
880 | public function mapWithKeys(callable $callback) |
||
894 | |||
895 | /** |
||
896 | * Map a collection and flatten the result by a single level. |
||
897 | * |
||
898 | * @param callable $callback |
||
899 | * @return static |
||
900 | */ |
||
901 | public function flatMap(callable $callback) |
||
905 | |||
906 | /** |
||
907 | * Map the values into a new class. |
||
908 | * |
||
909 | * @param string $class |
||
910 | * @return static |
||
911 | */ |
||
912 | public function mapInto($class) |
||
918 | |||
919 | /** |
||
920 | * Get the max value of a given key. |
||
921 | * |
||
922 | * @param callable|string|null $callback |
||
923 | * @return mixed |
||
924 | */ |
||
925 | public function max($callback = null) |
||
937 | |||
938 | /** |
||
939 | * Merge the collection with the given items. |
||
940 | * |
||
941 | * @param mixed $items |
||
942 | * @return static |
||
943 | */ |
||
944 | public function merge($items) |
||
948 | |||
949 | /** |
||
950 | * Create a collection by using this collection for keys and another for its values. |
||
951 | * |
||
952 | * @param mixed $values |
||
953 | * @return static |
||
954 | */ |
||
955 | public function combine($values) |
||
959 | |||
960 | /** |
||
961 | * Union the collection with the given items. |
||
962 | * |
||
963 | * @param mixed $items |
||
964 | * @return static |
||
965 | */ |
||
966 | public function union($items) |
||
970 | |||
971 | /** |
||
972 | * Get the min value of a given key. |
||
973 | * |
||
974 | * @param callable|string|null $callback |
||
975 | * @return mixed |
||
976 | */ |
||
977 | public function min($callback = null) |
||
989 | |||
990 | /** |
||
991 | * Create a new collection consisting of every n-th element. |
||
992 | * |
||
993 | * @param int $step |
||
994 | * @param int $offset |
||
995 | * @return static |
||
996 | */ |
||
997 | public function nth($step, $offset = 0) |
||
1013 | |||
1014 | /** |
||
1015 | * Get the items with the specified keys. |
||
1016 | * |
||
1017 | * @param mixed $keys |
||
1018 | * @return static |
||
1019 | */ |
||
1020 | public function only($keys) |
||
1030 | |||
1031 | /** |
||
1032 | * "Paginate" the collection by slicing it into a smaller collection. |
||
1033 | * |
||
1034 | * @param int $page |
||
1035 | * @param int $perPage |
||
1036 | * @return static |
||
1037 | */ |
||
1038 | public function forPage($page, $perPage) |
||
1044 | |||
1045 | /** |
||
1046 | * Partition the collection into two arrays using the given callback or key. |
||
1047 | * |
||
1048 | * @param callable|string $callback |
||
1049 | * @return static |
||
1050 | */ |
||
1051 | public function partition($callback) |
||
1063 | |||
1064 | /** |
||
1065 | * Pass the collection to the given callback and return the result. |
||
1066 | * |
||
1067 | * @param callable $callback |
||
1068 | * @return mixed |
||
1069 | */ |
||
1070 | public function pipe(callable $callback) |
||
1074 | |||
1075 | /** |
||
1076 | * Get and remove the last item from the collection. |
||
1077 | * |
||
1078 | * @return mixed |
||
1079 | */ |
||
1080 | public function pop() |
||
1084 | |||
1085 | /** |
||
1086 | * Push an item onto the beginning of the collection. |
||
1087 | * |
||
1088 | * @param mixed $value |
||
1089 | * @param mixed $key |
||
1090 | * @return $this |
||
1091 | */ |
||
1092 | public function prepend($value, $key = null) |
||
1098 | |||
1099 | /** |
||
1100 | * Push an item onto the end of the collection. |
||
1101 | * |
||
1102 | * @param mixed $value |
||
1103 | * @return $this |
||
1104 | */ |
||
1105 | public function push($value) |
||
1111 | |||
1112 | /** |
||
1113 | * Push all of the given items onto the collection. |
||
1114 | * |
||
1115 | * @param \Traversable $source |
||
1116 | * @return $this |
||
1117 | */ |
||
1118 | public function concat($source) |
||
1128 | |||
1129 | /** |
||
1130 | * Get and remove an item from the collection. |
||
1131 | * |
||
1132 | * @param mixed $key |
||
1133 | * @param mixed $default |
||
1134 | * @return mixed |
||
1135 | */ |
||
1136 | public function pull($key, $default = null) |
||
1140 | |||
1141 | /** |
||
1142 | * Put an item in the collection by key. |
||
1143 | * |
||
1144 | * @param mixed $key |
||
1145 | * @param mixed $value |
||
1146 | * @return $this |
||
1147 | */ |
||
1148 | public function put($key, $value) |
||
1154 | |||
1155 | /** |
||
1156 | * Get one or a specified number of items randomly from the collection. |
||
1157 | * |
||
1158 | * @param int|null $number |
||
1159 | * @return mixed |
||
1160 | * @throws \InvalidArgumentException |
||
1161 | */ |
||
1162 | public function random($number = null) |
||
1170 | |||
1171 | /** |
||
1172 | * Reduce the collection to a single value. |
||
1173 | * |
||
1174 | * @param callable $callback |
||
1175 | * @param mixed $initial |
||
1176 | * @return mixed |
||
1177 | */ |
||
1178 | public function reduce(callable $callback, $initial = null) |
||
1182 | |||
1183 | /** |
||
1184 | * Create a collection of all elements that do not pass a given truth test. |
||
1185 | * |
||
1186 | * @param callable|mixed $callback |
||
1187 | * @return static |
||
1188 | */ |
||
1189 | public function reject($callback) |
||
1201 | |||
1202 | /** |
||
1203 | * Reverse items order. |
||
1204 | * |
||
1205 | * @return static |
||
1206 | */ |
||
1207 | public function reverse() |
||
1211 | |||
1212 | /** |
||
1213 | * Search the collection for a given value and return the corresponding key if successful. |
||
1214 | * |
||
1215 | * @param mixed $value |
||
1216 | * @param bool $strict |
||
1217 | * @return mixed |
||
1218 | */ |
||
1219 | public function search($value, $strict = false) |
||
1233 | |||
1234 | /** |
||
1235 | * Get and remove the first item from the collection. |
||
1236 | * |
||
1237 | * @return mixed |
||
1238 | */ |
||
1239 | public function shift() |
||
1243 | |||
1244 | /** |
||
1245 | * Shuffle the items in the collection. |
||
1246 | * |
||
1247 | * @param int $seed |
||
1248 | * @return static |
||
1249 | */ |
||
1250 | public function shuffle($seed = null) |
||
1266 | |||
1267 | /** |
||
1268 | * Slice the underlying collection array. |
||
1269 | * |
||
1270 | * @param int $offset |
||
1271 | * @param int $length |
||
1272 | * @return static |
||
1273 | */ |
||
1274 | public function slice($offset, $length = null) |
||
1278 | |||
1279 | /** |
||
1280 | * Split a collection into a certain number of groups. |
||
1281 | * |
||
1282 | * @param int $numberOfGroups |
||
1283 | * @return static |
||
1284 | */ |
||
1285 | public function split($numberOfGroups) |
||
1295 | |||
1296 | /** |
||
1297 | * Chunk the underlying collection array. |
||
1298 | * |
||
1299 | * @param int $size |
||
1300 | * @return static |
||
1301 | */ |
||
1302 | public function chunk($size) |
||
1316 | |||
1317 | /** |
||
1318 | * Sort through each item with a callback. |
||
1319 | * |
||
1320 | * @param callable|null $callback |
||
1321 | * @return static |
||
1322 | */ |
||
1323 | public function sort(callable $callback = null) |
||
1333 | |||
1334 | /** |
||
1335 | * Sort the collection using the given callback. |
||
1336 | * |
||
1337 | * @param callable|string $callback |
||
1338 | * @param int $options |
||
1339 | * @param bool $descending |
||
1340 | * @return static |
||
1341 | */ |
||
1342 | public function sortBy($callback, $options = SORT_REGULAR, $descending = false) |
||
1367 | |||
1368 | /** |
||
1369 | * Sort the collection in descending order using the given callback. |
||
1370 | * |
||
1371 | * @param callable|string $callback |
||
1372 | * @param int $options |
||
1373 | * @return static |
||
1374 | */ |
||
1375 | public function sortByDesc($callback, $options = SORT_REGULAR) |
||
1379 | |||
1380 | /** |
||
1381 | * Splice a portion of the underlying collection array. |
||
1382 | * |
||
1383 | * @param int $offset |
||
1384 | * @param int|null $length |
||
1385 | * @param mixed $replacement |
||
1386 | * @return static |
||
1387 | */ |
||
1388 | public function splice($offset, $length = null, $replacement = []) |
||
1396 | |||
1397 | /** |
||
1398 | * Get the sum of the given values. |
||
1399 | * |
||
1400 | * @param callable|string|null $callback |
||
1401 | * @return mixed |
||
1402 | */ |
||
1403 | public function sum($callback = null) |
||
1415 | |||
1416 | /** |
||
1417 | * Take the first or last {$limit} items. |
||
1418 | * |
||
1419 | * @param int $limit |
||
1420 | * @return static |
||
1421 | */ |
||
1422 | public function take($limit) |
||
1430 | |||
1431 | /** |
||
1432 | * Pass the collection to the given callback and then return it. |
||
1433 | * |
||
1434 | * @param callable $callback |
||
1435 | * @return $this |
||
1436 | */ |
||
1437 | public function tap(callable $callback) |
||
1443 | |||
1444 | /** |
||
1445 | * Transform each item in the collection using a callback. |
||
1446 | * |
||
1447 | * @param callable $callback |
||
1448 | * @return $this |
||
1449 | */ |
||
1450 | public function transform(callable $callback) |
||
1456 | |||
1457 | /** |
||
1458 | * Return only unique items from the collection array. |
||
1459 | * |
||
1460 | * @param string|callable|null $key |
||
1461 | * @param bool $strict |
||
1462 | * @return static |
||
1463 | */ |
||
1464 | public function unique($key = null, $strict = false) |
||
1482 | |||
1483 | /** |
||
1484 | * Return only unique items from the collection array using strict comparison. |
||
1485 | * |
||
1486 | * @param string|callable|null $key |
||
1487 | * @return static |
||
1488 | */ |
||
1489 | public function uniqueStrict($key = null) |
||
1493 | |||
1494 | /** |
||
1495 | * Reset the keys on the underlying array. |
||
1496 | * |
||
1497 | * @return static |
||
1498 | */ |
||
1499 | public function values() |
||
1503 | |||
1504 | /** |
||
1505 | * Get a value retrieving callback. |
||
1506 | * |
||
1507 | * @param string $value |
||
1508 | * @return callable |
||
1509 | */ |
||
1510 | protected function valueRetriever($value) |
||
1520 | |||
1521 | /** |
||
1522 | * Zip the collection together with one or more arrays. |
||
1523 | * e.g. new Collection([1, 2, 3])->zip([4, 5, 6]); |
||
1524 | * => [[1, 4], [2, 5], [3, 6]] |
||
1525 | * |
||
1526 | * @param mixed ...$items |
||
1527 | * @return static |
||
1528 | */ |
||
1529 | public function zip($items) |
||
1543 | |||
1544 | /** |
||
1545 | * Pad collection to the specified length with a value. |
||
1546 | * |
||
1547 | * @param int $size |
||
1548 | * @param mixed $value |
||
1549 | * @return static |
||
1550 | */ |
||
1551 | public function pad($size, $value) |
||
1555 | |||
1556 | /** |
||
1557 | * Get the collection of items as a plain array. |
||
1558 | * |
||
1559 | * @return array |
||
1560 | */ |
||
1561 | public function toArray() |
||
1567 | |||
1568 | /** |
||
1569 | * Convert the object into something JSON serializable. |
||
1570 | * |
||
1571 | * @return array |
||
1572 | */ |
||
1573 | public function jsonSerialize() |
||
1582 | |||
1583 | /** |
||
1584 | * Get the collection of items as JSON. |
||
1585 | * |
||
1586 | * @param int $options |
||
1587 | * @return string |
||
1588 | */ |
||
1589 | public function toJson($options = 0) |
||
1593 | |||
1594 | /** |
||
1595 | * Get an iterator for the items. |
||
1596 | * |
||
1597 | * @return \ArrayIterator |
||
1598 | */ |
||
1599 | public function getIterator() |
||
1603 | |||
1604 | /** |
||
1605 | * Get a CachingIterator instance. |
||
1606 | * |
||
1607 | * @param int $flags |
||
1608 | * @return \CachingIterator |
||
1609 | */ |
||
1610 | public function getCachingIterator($flags = CachingIterator::CALL_TOSTRING) |
||
1614 | |||
1615 | /** |
||
1616 | * Count the number of items in the collection. |
||
1617 | * |
||
1618 | * @return int |
||
1619 | */ |
||
1620 | public function count() |
||
1624 | |||
1625 | /** |
||
1626 | * Get a base Support collection instance from this collection. |
||
1627 | * |
||
1628 | * @return \Illuminate\Support\Collection |
||
1629 | */ |
||
1630 | public function toBase() |
||
1634 | |||
1635 | /** |
||
1636 | * Determine if an item exists at an offset. |
||
1637 | * |
||
1638 | * @param mixed $key |
||
1639 | * @return bool |
||
1640 | */ |
||
1641 | public function offsetExists($key) |
||
1645 | |||
1646 | /** |
||
1647 | * Get an item at a given offset. |
||
1648 | * |
||
1649 | * @param mixed $key |
||
1650 | * @return mixed |
||
1651 | */ |
||
1652 | public function offsetGet($key) |
||
1656 | |||
1657 | /** |
||
1658 | * Set the item at a given offset. |
||
1659 | * |
||
1660 | * @param mixed $key |
||
1661 | * @param mixed $value |
||
1662 | * @return void |
||
1663 | */ |
||
1664 | public function offsetSet($key, $value) |
||
1672 | |||
1673 | /** |
||
1674 | * Unset the item at a given offset. |
||
1675 | * |
||
1676 | * @param string $key |
||
1677 | * @return void |
||
1678 | */ |
||
1679 | public function offsetUnset($key) |
||
1683 | |||
1684 | /** |
||
1685 | * Convert the collection to its string representation. |
||
1686 | * |
||
1687 | * @return string |
||
1688 | */ |
||
1689 | public function __toString() |
||
1693 | |||
1694 | /** |
||
1695 | * Results array of items from Collection or Arrayable. |
||
1696 | * |
||
1697 | * @param mixed $items |
||
1698 | * @return array |
||
1699 | */ |
||
1700 | protected function getArrayableItems($items) |
||
1718 | |||
1719 | /** |
||
1720 | * Add a method to the list of proxied methods. |
||
1721 | * |
||
1722 | * @param string $method |
||
1723 | * @return void |
||
1724 | */ |
||
1725 | public static function proxy($method) |
||
1729 | } |
Adding a
@return
annotation 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.