| Conditions | 6 |
| Paths | 9 |
| Total Lines | 19 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 13 |
| CRAP Score | 6 |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 16 | 13 | public static function create($resourceName, $data, $params = [], $meta = []) |
|
| 17 | { |
||
| 18 | switch ($resourceName) { |
||
| 19 | 13 | case 'events': |
|
| 20 | 8 | $resourceClass = Event::class; |
|
| 21 | 8 | $createCollection = empty($params['id']) && empty($data['id']); |
|
| 22 | 8 | break; |
|
| 23 | 5 | case 'records': |
|
| 24 | 4 | $resourceClass = Record::class; |
|
| 25 | 4 | $createCollection = empty($params['id']) && empty($data['id']); |
|
| 26 | 4 | break; |
|
| 27 | default: |
||
| 28 | 1 | throw new InvalidArgumentException(sprintf('Unknown resource "%s"', $resourceName)); |
|
| 29 | } |
||
| 30 | 12 | if ($createCollection) { |
|
| 31 | // We have a collection |
||
| 32 | 5 | return (new Collection($data, $resourceClass))->withMeta($meta); |
|
| 33 | } |
||
| 34 | 7 | return new $resourceClass($data); |
|
| 35 | } |
||
| 47 |