MorphOneOrMany::setMorphValue()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 2
Metric Value
cc 1
eloc 1
c 2
b 0
f 2
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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 4
    public function getMorphValue(): string
27
    {
28 4
        if ($this->morphValue == null) {
29 4
            $this->initMorphValue();
30
        }
31 4
        return $this->morphValue;
32
    }
33
34
    /**
35
     * @param string $morphValue
36
     */
37 4
    public function setMorphValue(string $morphValue)
38
    {
39 4
        $this->morphValue = $morphValue;
40 4
    }
41
42
    /**
43
     * @return string
44
     */
45 4
    protected function initMorphValue()
46
    {
47 4
        $this->setMorphValue(
48 4
            $this->getManager()->getMorphName()
0 ignored issues
show
Bug introduced by
The method getMorphName() does not exist on Nip\Records\AbstractModels\RecordManager. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

48
            $this->getManager()->/** @scrutinizer ignore-call */ getMorphName()
Loading history...
Bug introduced by
$this->getManager()->getMorphName() of type Nip\Records\AbstractMode...ections\Collection|true is incompatible with the type string expected by parameter $morphValue of Nip\Records\Relations\Mo...OrMany::setMorphValue(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

48
            /** @scrutinizer ignore-type */ $this->getManager()->getMorphName()
Loading history...
49
        );
50 4
    }
51
52
    /**
53
     * @param $params
54
     * @throws \Exception
55
     */
56 1
    public function addParams($params)
57
    {
58 1
        $this->checkParamMorphPrefix($params);
59 1
        $this->checkParamMorphTypeField($params);
60 1
        parent::addParams($params);
61 1
    }
62
}
63