Completed
Push — master ( c5047e...3a177f )
by Gabriel
03:52
created

MorphTo   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 39
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getWithClass() 0 6 1
A getMorphType() 0 9 2
A addParams() 0 5 1
1
<?php
2
3
namespace Nip\Records\Relations;
4
5
use Nip\Records\AbstractModels\Record;
6
use Nip\Records\Relations\Exceptions\ModelNotLoadedInRelation;
7
use Nip\Records\Relations\Traits\HasMorphTypeTrait;
8
9
/**
10
 * Class MorphToMany
11
 * @package Nip\Records\Relations
12
 */
13
class MorphTo extends BelongsTo
14
{
15
    use HasMorphTypeTrait;
16
17
    /** @noinspection PhpMissingParentCallCommonInspection
18
     * @return string
19
     * @throws ModelNotLoadedInRelation
20
     */
21 3
    public function getWithClass()
22
    {
23 3
        $type = $this->getMorphType();
24 2
        $typePlural = inflector()->pluralize($type);
25 2
        return $typePlural;
26
    }
27
28
    /**
29
     * @return mixed
30
     * @throws ModelNotLoadedInRelation
31
     */
32 3
    public function getMorphType()
33
    {
34 3
        if ($this->getItem() instanceof Record) {
35 2
            return $this->getItem()->{$this->getMorphTypeField()};
36
        }
37 1
        throw new ModelNotLoadedInRelation(
38 1
            $this->debugString()
39
        );
40
    }
41
42
    /**
43
     * @param $params
44
     */
45 1
    public function addParams($params)
46
    {
47 1
        $this->checkParamMorphPrefix($params);
48 1
        parent::addParams($params);
49 1
    }
50
51
}
52