Completed
Push — master ( 3a177f...0ba58c )
by Gabriel
03:15
created

MorphOneOrMany::addParams()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Nip\Records\Relations;
4
5
use Nip\Records\Relations\Traits\HasMorphTypeTrait;
6
7
/**
8
 * Class MorphOneOrMany
9
 * @package Nip\Records\Relations
10
 */
11
abstract class MorphOneOrMany extends HasOneOrMany
12
{
13
    use HasMorphTypeTrait;
14
15
    /**
16
     * The class name of model manager
17
     * This value is saved in the morph type collumn
18
     *
19
     * @var string
20
     */
21
    protected $morphValue = null;
22
23
    /**
24
     * @return string
25
     */
26 2
    public function getMorphValue(): string
27
    {
28 2
        if ($this->morphValue == null) {
29 2
            $this->initMorphValue();
30
        }
31 2
        return $this->morphValue;
32
    }
33
34
    /**
35
     * @param string $morphValue
36
     */
37 2
    public function setMorphValue(string $morphValue)
38
    {
39 2
        $this->morphValue = $morphValue;
40 2
    }
41
42
    /**
43
     * @return string
44
     */
45 2
    protected function initMorphValue()
46
    {
47 2
        $this->setMorphValue(
48 2
            $this->getManager()->getMorphName()
0 ignored issues
show
Documentation Bug introduced by
The method getMorphName does not exist on object<Nip\Records\AbstractModels\RecordManager>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
49
        );
50 2
    }
51
52
    /**
53
     * @param $params
54
     * @throws \Exception
55
     */
56 1
    public function addParams($params)
57
    {
58 1
        $this->checkParamMorphPrefix($params);
59 1
        parent::addParams($params);
60 1
    }
61
}
62