Conditions | 6 |
Paths | 5 |
Total Lines | 15 |
Code Lines | 8 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 42 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
21 | protected function toCollection($data, $collectionClass) |
||
22 | { |
||
23 | if ($data instanceof $collectionClass) { |
||
24 | return $data; |
||
25 | } |
||
26 | |||
27 | $data = $data ?: array(); |
||
28 | if (!is_array($data) && !$data instanceof Collection) { |
||
29 | throw new \InvalidArgumentException('Can transform only Collections or arrays.'); |
||
30 | } |
||
31 | |||
32 | return new $collectionClass( |
||
33 | is_array($data) ? $data : $data->toArray() |
||
34 | ); |
||
35 | } |
||
36 | } |
||
37 |