Complex classes like CollectionTrait 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 CollectionTrait, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
7 | trait CollectionTrait |
||
8 | { |
||
9 | /** |
||
10 | * Converts $collection to array. If there are multiple items with the same key, only the last will be preserved. |
||
11 | * |
||
12 | * @return array |
||
13 | */ |
||
14 | 70 | public function toArray() |
|
18 | |||
19 | /** |
||
20 | * Returns a lazy collection of items for which $function returned true. |
||
21 | * |
||
22 | * @param callable|null $function ($value, $key) |
||
23 | * @return Collection |
||
24 | */ |
||
25 | 2 | public function filter(callable $function = null) |
|
29 | |||
30 | /** |
||
31 | * Returns a lazy collection of distinct items. The comparison is the same as in in_array. |
||
32 | * |
||
33 | * @return Collection |
||
34 | */ |
||
35 | 1 | public function distinct() |
|
39 | |||
40 | /** |
||
41 | * Returns a lazy collection with items from all $collections passed as argument appended together |
||
42 | * |
||
43 | * @param array|\Traversable ...$collections |
||
44 | * @return Collection |
||
45 | */ |
||
46 | 1 | public function concat(...$collections) |
|
50 | |||
51 | /** |
||
52 | * Returns collection where each item is changed to the output of executing $function on each key/item. |
||
53 | * |
||
54 | * @param callable $function |
||
55 | * @return Collection |
||
56 | */ |
||
57 | 8 | public function map(callable $function) |
|
61 | |||
62 | /** |
||
63 | * Reduces the collection to single value by iterating over the collection and calling $function while |
||
64 | * passing $startValue and current key/item as parameters. The output of $function is used as $startValue in |
||
65 | * next iteration. The output of $function on last element is the return value of this function. If |
||
66 | * $convertToCollection is true and the return value is a collection (array|Traversable) an instance of Collection |
||
67 | * is returned. |
||
68 | * |
||
69 | * @param callable $function ($tmpValue, $value, $key) |
||
70 | * @param mixed $startValue |
||
71 | * @param bool $convertToCollection |
||
72 | * @return mixed|Collection |
||
73 | */ |
||
74 | 2 | public function reduce(callable $function, $startValue, $convertToCollection = false) |
|
80 | |||
81 | /** |
||
82 | * Returns a lazy collection with one or multiple levels of nesting flattened. Removes all nesting when no value |
||
83 | * is passed. |
||
84 | * |
||
85 | * @param int $depth How many levels should be flatten, default (-1) is infinite. |
||
86 | * @return Collection |
||
87 | */ |
||
88 | 1 | public function flatten($depth = -1) |
|
92 | |||
93 | /** |
||
94 | * Returns a non-lazy collection sorted using $function($item1, $item2, $key1, $key2 ). $function should |
||
95 | * return true if first item is larger than the second and false otherwise. |
||
96 | * |
||
97 | * @param callable $function ($value1, $value2, $key1, $key2) |
||
98 | * @return Collection |
||
99 | */ |
||
100 | 2 | public function sort(callable $function) |
|
104 | |||
105 | /** |
||
106 | * Returns lazy collection items of which are part of the original collection from item number $from to item |
||
107 | * number $to. The items before $from are also iterated over, just not returned. |
||
108 | * |
||
109 | * @param int $from |
||
110 | * @param int $to If omitted, will slice until end |
||
111 | * @return Collection |
||
112 | */ |
||
113 | 1 | public function slice($from, $to = -1) |
|
117 | |||
118 | /** |
||
119 | * Returns collection which items are separated into groups indexed by the return value of $function. |
||
120 | * |
||
121 | * @param callable $function ($value, $key) |
||
122 | * @return Collection |
||
123 | */ |
||
124 | 1 | public function groupBy(callable $function) |
|
128 | |||
129 | /** |
||
130 | * Returns collection where items are separated into groups indexed by the value at given key. |
||
131 | * |
||
132 | * @param mixed $key |
||
133 | * @return Collection |
||
134 | */ |
||
135 | 1 | public function groupByKey($key) |
|
139 | |||
140 | /** |
||
141 | * Returns a lazy collection in which $function is executed for each item. |
||
142 | * |
||
143 | * @param callable $function ($value, $key) |
||
144 | * @return Collection |
||
145 | */ |
||
146 | 1 | public function each(callable $function) |
|
150 | |||
151 | /** |
||
152 | * Returns the number of items in this collection. |
||
153 | * |
||
154 | * @return int |
||
155 | */ |
||
156 | 6 | public function size() |
|
160 | |||
161 | /** |
||
162 | * Returns value at the key $key. If multiple values have this key, return first. If no value has this key, throw |
||
163 | * ItemNotFound. If $convertToCollection is true and the return value is a collection (array|Traversable) an |
||
164 | * instance of Collection will be returned. |
||
165 | * |
||
166 | * @param mixed $key |
||
167 | * @param bool $convertToCollection |
||
168 | * @return mixed|Collection |
||
169 | * @throws \DusanKasan\Knapsack\Exceptions\ItemNotFound |
||
170 | */ |
||
171 | 5 | public function get($key, $convertToCollection = false) |
|
177 | |||
178 | /** |
||
179 | * Returns item at the key $key. If multiple items have this key, return first. If no item has this key, return |
||
180 | * $ifNotFound. If no value has this key, throw ItemNotFound. If $convertToCollection is true and the return value |
||
181 | * is a collection (array|Traversable) an instance of Collection will be returned. |
||
182 | * |
||
183 | * @param mixed $key |
||
184 | * @param mixed $default |
||
185 | * @param bool $convertToCollection |
||
186 | * @return mixed|Collection |
||
187 | * @throws \DusanKasan\Knapsack\Exceptions\ItemNotFound |
||
188 | */ |
||
189 | 1 | public function getOrDefault($key, $default = null, $convertToCollection = false) |
|
195 | |||
196 | /** |
||
197 | * Returns first value matched by $function. If no value matches, return $default. If $convertToCollection is true |
||
198 | * and the return value is a collection (array|Traversable) an instance of Collection will be returned. |
||
199 | * |
||
200 | * @param callable $function |
||
201 | * @param mixed|null $default |
||
202 | * @param bool $convertToCollection |
||
203 | * @return mixed|Collection |
||
204 | */ |
||
205 | 1 | public function find(callable $function, $default = null, $convertToCollection = false) |
|
211 | |||
212 | /** |
||
213 | * Returns a non-lazy collection of items whose keys are the return values of $function and values are the number of |
||
214 | * items in this collection for which the $function returned this value. |
||
215 | * |
||
216 | * @param callable $function |
||
217 | * @return Collection |
||
218 | */ |
||
219 | 1 | public function countBy(callable $function) |
|
223 | |||
224 | /** |
||
225 | * Returns a lazy collection by changing keys of this collection for each item to the result of $function for |
||
226 | * that item. |
||
227 | * |
||
228 | * @param callable $function |
||
229 | * @return Collection |
||
230 | */ |
||
231 | 3 | public function indexBy(callable $function) |
|
235 | |||
236 | /** |
||
237 | * Returns true if $function returns true for every item in this collection, false otherwise. |
||
238 | * |
||
239 | * @param callable $function |
||
240 | * @return bool |
||
241 | */ |
||
242 | 1 | public function every(callable $function) |
|
246 | |||
247 | /** |
||
248 | * Returns true if $function returns true for at least one item in this collection, false otherwise. |
||
249 | * |
||
250 | * @param callable $function |
||
251 | * @return bool |
||
252 | */ |
||
253 | 1 | public function some(callable $function) |
|
257 | |||
258 | /** |
||
259 | * Returns true if $value is present in the collection. |
||
260 | * |
||
261 | * @param mixed $value |
||
262 | * @return bool |
||
263 | */ |
||
264 | 1 | public function contains($value) |
|
268 | |||
269 | /** |
||
270 | * Returns collection of items in this collection in reverse order. |
||
271 | * |
||
272 | * @return Collection |
||
273 | */ |
||
274 | 1 | public function reverse() |
|
278 | |||
279 | /** |
||
280 | * Reduce the collection to single value. Walks from right to left. If $convertToCollection is true and the return |
||
281 | * value is a collection (array|Traversable) an instance of Collection is returned. |
||
282 | * |
||
283 | * @param callable $function Must take 2 arguments, intermediate value and item from the iterator. |
||
284 | * @param mixed $startValue |
||
285 | * @param bool $convertToCollection |
||
286 | * @return mixed|Collection |
||
287 | */ |
||
288 | 1 | public function reduceRight(callable $function, $startValue, $convertToCollection = false) |
|
294 | |||
295 | /** |
||
296 | * A form of slice that returns first $numberOfItems items. |
||
297 | * |
||
298 | * @param int $numberOfItems |
||
299 | * @return Collection |
||
300 | */ |
||
301 | 9 | public function take($numberOfItems) |
|
305 | |||
306 | /** |
||
307 | * A form of slice that returns all but first $numberOfItems items. |
||
308 | * |
||
309 | * @param int $numberOfItems |
||
310 | * @return Collection |
||
311 | */ |
||
312 | 2 | public function drop($numberOfItems) |
|
316 | |||
317 | /** |
||
318 | * Returns collection of values from this collection but with keys being numerical from 0 upwards. |
||
319 | * |
||
320 | * @return Collection |
||
321 | */ |
||
322 | 13 | public function values() |
|
326 | |||
327 | /** |
||
328 | * Returns a lazy collection without elements matched by $function. |
||
329 | * |
||
330 | * @param callable $function |
||
331 | * @return Collection |
||
332 | */ |
||
333 | 1 | public function reject(callable $function) |
|
337 | |||
338 | /** |
||
339 | * Returns a lazy collection of the keys of this collection. |
||
340 | * |
||
341 | * @return Collection |
||
342 | */ |
||
343 | 1 | public function keys() |
|
347 | |||
348 | /** |
||
349 | * Returns a lazy collection of items of this collection separated by $separator |
||
350 | * |
||
351 | * @param mixed $separator |
||
352 | * @return Collection |
||
353 | */ |
||
354 | 1 | public function interpose($separator) |
|
358 | |||
359 | /** |
||
360 | * Returns a lazy collection with last $numberOfItems items skipped. These are still iterated over, just skipped. |
||
361 | * |
||
362 | * @param int $numberOfItems |
||
363 | * @return Collection |
||
364 | */ |
||
365 | 1 | public function dropLast($numberOfItems = 1) |
|
369 | |||
370 | /** |
||
371 | * Returns a lazy collection of first item from first collection, first item from second, second from first and |
||
372 | * so on. Accepts any number of collections. |
||
373 | * |
||
374 | * @param array|\Traversable ...$collections |
||
375 | * @return Collection |
||
376 | */ |
||
377 | 1 | public function interleave(...$collections) |
|
381 | |||
382 | /** |
||
383 | * Returns an infinite lazy collection of items in this collection repeated infinitely. |
||
384 | * |
||
385 | * @return Collection |
||
386 | */ |
||
387 | 1 | public function cycle() |
|
391 | |||
392 | /** |
||
393 | * Returns a lazy collection of items of this collection with $value added as first element. If $key is not provided |
||
394 | * it will be next integer index. |
||
395 | * |
||
396 | * @param mixed $value |
||
397 | * @param mixed|null $key |
||
398 | * @return Collection |
||
399 | */ |
||
400 | 2 | public function prepend($value, $key = null) |
|
404 | |||
405 | /** |
||
406 | * Returns a lazy collection of items of this collection with $value added as last element. If $key is not provided |
||
407 | * it will be next integer index. |
||
408 | * |
||
409 | * @param mixed $value |
||
410 | * @param mixed $key |
||
411 | * @return Collection |
||
412 | */ |
||
413 | 6 | public function append($value, $key = null) |
|
417 | |||
418 | /** |
||
419 | * Returns a lazy collection by removing items from this collection until first item for which $function returns |
||
420 | * false. |
||
421 | * |
||
422 | * @param callable $function |
||
423 | * @return Collection |
||
424 | */ |
||
425 | 1 | public function dropWhile(callable $function) |
|
429 | |||
430 | /** |
||
431 | * Returns a lazy collection which is a result of calling map($function) and then flatten(1) |
||
432 | * |
||
433 | * @param callable $function |
||
434 | * @return Collection |
||
435 | */ |
||
436 | 1 | public function mapcat(callable $function) |
|
440 | |||
441 | /** |
||
442 | * Returns a lazy collection of items from the start of the ollection until the first item for which $function |
||
443 | * returns false. |
||
444 | * |
||
445 | * @param callable $function |
||
446 | * @return Collection |
||
447 | */ |
||
448 | 1 | public function takeWhile(callable $function) |
|
452 | |||
453 | /** |
||
454 | * Returns a collection of [take($position), drop($position)] |
||
455 | * |
||
456 | * @param int $position |
||
457 | * @return Collection |
||
458 | */ |
||
459 | 1 | public function splitAt($position) |
|
463 | |||
464 | /** |
||
465 | * Returns a collection of [takeWhile($predicament), dropWhile($predicament] |
||
466 | * |
||
467 | * @param callable $function |
||
468 | * @return Collection |
||
469 | */ |
||
470 | 5 | public function splitWith(callable $function) |
|
474 | |||
475 | /** |
||
476 | * Returns a lazy collection with items from this collection but values that are found in keys of $replacementMap |
||
477 | * are replaced by their values. |
||
478 | * |
||
479 | * @param array|\Traversable $replacementMap |
||
480 | * @return Collection |
||
481 | */ |
||
482 | 1 | public function replace($replacementMap) |
|
486 | |||
487 | /** |
||
488 | * Returns a lazy collection of reduction steps. |
||
489 | * |
||
490 | * @param callable $function |
||
491 | * @param mixed $startValue |
||
492 | * @return Collection |
||
493 | */ |
||
494 | 1 | public function reductions(callable $function, $startValue) |
|
498 | |||
499 | /** |
||
500 | * Returns a lazy collection of every nth item in this collection |
||
501 | * |
||
502 | * @param int $step |
||
503 | * @return Collection |
||
504 | */ |
||
505 | 1 | public function takeNth($step) |
|
509 | |||
510 | /** |
||
511 | * Returns a non-collection of shuffled items from this collection |
||
512 | * |
||
513 | * @return Collection |
||
514 | */ |
||
515 | 1 | public function shuffle() |
|
519 | |||
520 | /** |
||
521 | * Returns a lazy collection of collections of $numberOfItems items each, at $step step |
||
522 | * apart. If $step is not supplied, defaults to $numberOfItems, i.e. the partitions |
||
523 | * do not overlap. If a $padding collection is supplied, use its elements as |
||
524 | * necessary to complete last partition up to $numberOfItems items. In case there are |
||
525 | * not enough padding elements, return a partition with less than $numberOfItems items. |
||
526 | * |
||
527 | * @param int $numberOfItems |
||
528 | * @param int $step |
||
529 | * @param array|\Traversable $padding |
||
530 | * @return Collection |
||
531 | */ |
||
532 | 1 | public function partition($numberOfItems, $step = 0, $padding = []) |
|
536 | |||
537 | /** |
||
538 | * Creates a lazy collection of collections created by partitioning this collection every time $function will |
||
539 | * return different result. |
||
540 | * |
||
541 | * @param callable $function |
||
542 | * @return Collection |
||
543 | */ |
||
544 | 1 | public function partitionBy(callable $function) |
|
548 | |||
549 | /** |
||
550 | * Returns true if this collection is empty. False otherwise. |
||
551 | * |
||
552 | * @return bool |
||
553 | */ |
||
554 | 3 | public function isEmpty() |
|
558 | |||
559 | /** |
||
560 | * Opposite of isEmpty. |
||
561 | * |
||
562 | * @return bool |
||
563 | */ |
||
564 | 2 | public function isNotEmpty() |
|
568 | |||
569 | /** |
||
570 | * Returns a collection where keys are distinct items from this collection and their values are number of |
||
571 | * occurrences of each value. |
||
572 | * |
||
573 | * @return Collection |
||
574 | */ |
||
575 | 1 | public function frequencies() |
|
579 | |||
580 | /** |
||
581 | * Returns first item of this collection. If the collection is empty, throws ItemNotFound. If $convertToCollection |
||
582 | * is true and the return value is a collection (array|Traversable) an instance of Collection is returned. |
||
583 | * |
||
584 | * @param bool $convertToCollection |
||
585 | * @return mixed|Collection |
||
586 | * @throws \DusanKasan\Knapsack\Exceptions\ItemNotFound |
||
587 | */ |
||
588 | 11 | public function first($convertToCollection = false) |
|
594 | |||
595 | /** |
||
596 | * Returns last item of this collection. If the collection is empty, throws ItemNotFound. If $convertToCollection |
||
597 | * is true and the return value is a collection (array|Traversable) it is converted to Collection. |
||
598 | * |
||
599 | * @param bool $convertToCollection |
||
600 | * @return mixed|Collection |
||
601 | * @throws \DusanKasan\Knapsack\Exceptions\ItemNotFound |
||
602 | */ |
||
603 | 2 | public function last($convertToCollection = false) |
|
609 | |||
610 | /** |
||
611 | * Realizes collection - turns lazy collection into non-lazy one by iterating over it and storing the key/values. |
||
612 | * |
||
613 | * @return Collection |
||
614 | */ |
||
615 | 1 | public function realize() |
|
619 | |||
620 | /** |
||
621 | * Returns the second item in this collection or throws ItemNotFound if the collection is empty or has 1 item. If |
||
622 | * $convertToCollection is true and the return value is a collection (array|Traversable) it is converted to |
||
623 | * Collection. |
||
624 | * |
||
625 | * @param bool $convertToCollection |
||
626 | * @return mixed|Collection |
||
627 | * @throws \DusanKasan\Knapsack\Exceptions\ItemNotFound |
||
628 | */ |
||
629 | 6 | public function second($convertToCollection = false) |
|
635 | |||
636 | /** |
||
637 | * Combines the values of this collection as keys, with values of $collection as values. The resulting collection |
||
638 | * has length equal to the size of smaller collection. |
||
639 | * |
||
640 | * @param array|\Traversable $collection |
||
641 | * @return Collection |
||
642 | * @throws \DusanKasan\Knapsack\Exceptions\ItemNotFound |
||
643 | */ |
||
644 | 1 | public function combine($collection) |
|
648 | |||
649 | /** |
||
650 | * Returns a lazy collection without the items associated to any of the keys from $keys. |
||
651 | * |
||
652 | * @param array|\Traversable $keys |
||
653 | * @return Collection |
||
654 | */ |
||
655 | 1 | public function except($keys) |
|
659 | |||
660 | /** |
||
661 | * Returns a lazy collection of items associated to any of the keys from $keys. |
||
662 | * |
||
663 | * @param array|\Traversable $keys |
||
664 | * @return Collection |
||
665 | */ |
||
666 | 1 | public function only($keys) |
|
670 | |||
671 | /** |
||
672 | * Returns a lazy collection of items that are in $this but are not in any of the other arguments, indexed by the |
||
673 | * keys from the first collection. Note that the ...$collections are iterated non-lazily. |
||
674 | * |
||
675 | * @param array|\Traversable ...$collections |
||
676 | * @return Collection |
||
677 | */ |
||
678 | 1 | public function diff(...$collections) |
|
682 | |||
683 | /** |
||
684 | * Returns a lazy collection where keys and values are flipped. |
||
685 | * |
||
686 | * @return Collection |
||
687 | */ |
||
688 | 1 | public function flip() |
|
692 | |||
693 | /** |
||
694 | * Checks for the existence of an item with$key in this collection. |
||
695 | * |
||
696 | * @param mixed $key |
||
697 | * @return bool |
||
698 | */ |
||
699 | 1 | public function has($key) |
|
703 | |||
704 | /** |
||
705 | * Returns a lazy collection of non-lazy collections of items from nth position from this collection and each |
||
706 | * passed collection. Stops when any of the collections don't have an item at the nth position. |
||
707 | * |
||
708 | * @param array|\Traversable ...$collections |
||
709 | * @return Collection |
||
710 | */ |
||
711 | 1 | public function zip(...$collections) |
|
717 | |||
718 | /** |
||
719 | * Uses a $transformer callable that takes a Collection and returns Collection on itself. |
||
720 | * |
||
721 | * @param callable $transformer Collection => Collection |
||
722 | * @return Collection |
||
723 | * @throws InvalidReturnValue |
||
724 | */ |
||
725 | 1 | public function transform(callable $transformer) |
|
737 | |||
738 | /** |
||
739 | * Transpose each item in a collection, interchanging the row and column indexes. |
||
740 | * Can only transpose collections of collections. Otherwise an InvalidArgument is raised. |
||
741 | * |
||
742 | * @return Collection |
||
743 | */ |
||
744 | 3 | public function transpose() |
|
748 | |||
749 | /** |
||
750 | * Extracts data from collection items by dot separated key path. Supports the * wildcard. If a key contains \ or |
||
751 | * it must be escaped using \ character. |
||
752 | * |
||
753 | * @param mixed $keyPath |
||
754 | * @return Collection |
||
755 | */ |
||
756 | 1 | public function extract($keyPath) |
|
760 | |||
761 | /** |
||
762 | * Returns a lazy collection of items that are in $this and all the other arguments, indexed by the keys from |
||
763 | * the first collection. Note that the ...$collections are iterated non-lazily. |
||
764 | * |
||
765 | * @param array|\Traversable ...$collections |
||
766 | * @return Collection |
||
767 | */ |
||
768 | 1 | public function intersect(...$collections) |
|
772 | |||
773 | /** |
||
774 | * Checks whether this collection has exactly $size items. |
||
775 | * |
||
776 | * @param int $size |
||
777 | * @return bool |
||
778 | */ |
||
779 | 1 | public function sizeIs($size) |
|
783 | |||
784 | /** |
||
785 | * Checks whether this collection has less than $size items. |
||
786 | * |
||
787 | * @param int $size |
||
788 | * @return bool |
||
789 | */ |
||
790 | 1 | public function sizeIsLessThan($size) |
|
794 | |||
795 | /** |
||
796 | * Checks whether this collection has more than $size items. |
||
797 | * |
||
798 | * @param int $size |
||
799 | * @return bool |
||
800 | */ |
||
801 | 1 | public function sizeIsGreaterThan($size) |
|
805 | |||
806 | /** |
||
807 | * Checks whether this collection has between $fromSize to $toSize items. $toSize can be |
||
808 | * smaller than $fromSize. |
||
809 | * |
||
810 | * @param int $fromSize |
||
811 | * @param int $toSize |
||
812 | * @return bool |
||
813 | */ |
||
814 | 1 | public function sizeIsBetween($fromSize, $toSize) |
|
818 | |||
819 | /** |
||
820 | * Returns a sum of all values in this collection. |
||
821 | * |
||
822 | * @return int|float |
||
823 | */ |
||
824 | 1 | public function sum() |
|
828 | |||
829 | /** |
||
830 | * Returns average of values from this collection. |
||
831 | * |
||
832 | * @return int|float |
||
833 | */ |
||
834 | 2 | public function average() |
|
838 | |||
839 | /** |
||
840 | * Returns maximal value from this collection. |
||
841 | * |
||
842 | * @return mixed |
||
843 | */ |
||
844 | 2 | public function max() |
|
848 | |||
849 | /** |
||
850 | * Returns minimal value from this collection. |
||
851 | * |
||
852 | * @return mixed |
||
853 | */ |
||
854 | 2 | public function min() |
|
858 | |||
859 | /** |
||
860 | * Returns a string by concatenating the collection values into a string. |
||
861 | * |
||
862 | * @return string |
||
863 | */ |
||
864 | 1 | public function toString() |
|
868 | |||
869 | /** |
||
870 | * Returns a lazy collection with items from $collection, but items with keys that are found in keys of |
||
871 | * $replacementMap are replaced by their values. |
||
872 | * |
||
873 | * @param array|\Traversable $replacementMap |
||
874 | * @return Collection |
||
875 | */ |
||
876 | 1 | public function replaceByKeys($replacementMap) |
|
880 | |||
881 | /** |
||
882 | * /** |
||
883 | * Dumps this collection into array (recursively). |
||
884 | * |
||
885 | * - scalars are returned as they are, |
||
886 | * - array of class name => properties (name => value and only properties accessible for this class) |
||
887 | * is returned for objects, |
||
888 | * - arrays or Traversables are returned as arrays, |
||
889 | * - for anything else result of calling gettype($input) is returned |
||
890 | * |
||
891 | * If specified, $maxItemsPerCollection will only leave specified number of items in collection, |
||
892 | * appending a new element at end '>>>' if original collection was longer. |
||
893 | * |
||
894 | * If specified, $maxDepth will only leave specified n levels of nesting, replacing elements |
||
895 | * with '^^^' once the maximum nesting level was reached. |
||
896 | * |
||
897 | * If a collection with duplicate keys is encountered, the duplicate keys (except the first one) |
||
898 | * will be change into a format originalKey//duplicateCounter where duplicateCounter starts from |
||
899 | * 1 at the first duplicate. So [0 => 1, 0 => 2] will become [0 => 1, '0//1' => 2] |
||
900 | * |
||
901 | * @param int|null $maxItemsPerCollection |
||
902 | * @param int|null $maxDepth |
||
903 | * @return array |
||
904 | */ |
||
905 | 1 | public function dump($maxItemsPerCollection = null, $maxDepth = null) |
|
909 | |||
910 | /** |
||
911 | * Calls dump on this collection and then prints it using the var_export. |
||
912 | * |
||
913 | * @param int|null $maxItemsPerCollection |
||
914 | * @param int|null $maxDepth |
||
915 | * @return Collection |
||
916 | */ |
||
917 | 1 | public function printDump($maxItemsPerCollection = null, $maxDepth = null) |
|
921 | |||
922 | /** |
||
923 | * @return array|\Traversable |
||
924 | */ |
||
925 | 103 | protected function getItems() |
|
929 | } |
||
930 |