Conditions | 3 |
Paths | 4 |
Total Lines | 14 |
Code Lines | 6 |
Lines | 0 |
Ratio | 0 % |
Tests | 7 |
CRAP Score | 3 |
Changes | 0 |
1 | <?php |
||
9 | 150 | public static function instance(string $key, $attributes = []) |
|
10 | { |
||
11 | 150 | $class = $key; |
|
12 | |||
13 | // We assume the key is the full namespaced class or a string altered by the relation morph map. |
||
14 | 150 | if ($morphedModel = Relation::getMorphedModel($key)) { |
|
15 | 80 | $class = $morphedModel; |
|
16 | } |
||
17 | |||
18 | 150 | 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 | 149 | return new $class($attributes); |
|
23 | } |
||
25 |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.