| Conditions | 3 |
| Paths | 4 |
| Total Lines | 14 |
| Code Lines | 6 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 7 |
| CRAP Score | 3 |
| Changes | 0 | ||
| 1 | <?php |
||
| 9 | 166 | public static function instance(string $key, $attributes = []) |
|
| 10 | { |
||
| 11 | 166 | $class = $key; |
|
| 12 | |||
| 13 | // We assume the key is the full namespaced class or a string altered by the relation morph map. |
||
| 14 | 166 | if ($morphedModel = Relation::getMorphedModel($key)) { |
|
| 15 | 85 | $class = $morphedModel; |
|
| 16 | } |
||
| 17 | |||
| 18 | 166 | if (!class_exists($class)) { |
|
| 19 | 1 | throw new NotFoundMorphKey('No class found by morphkey [' . $class . ']. Make sure that the morphkey is a valid class reference.'); |
|
| 20 | } |
||
| 21 | |||
| 22 | 165 | return new $class($attributes); |
|
| 23 | } |
||
| 25 |