Completed
Push — 0.3 ( da43ab...625b56 )
by Ben
96:17 queued 52:29
created

Morphables   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 7
dl 0
loc 16
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A instance() 0 14 3
1
<?php
2
3
namespace Thinktomorrow\Chief\Concerns\Morphable;
4
5
use Illuminate\Database\Eloquent\Relations\Relation;
6
7
class Morphables
8
{
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.');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 143 characters

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.

Loading history...
20
        }
21
22 149
        return new $class($attributes);
23
    }
24
}
25