Passed
Push — master ( 812350...21b36f )
by Gabriel
02:32
created

HasMorphTypeTrait::checkParamMorphTypeField()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2.5

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 3
c 1
b 0
f 1
nc 2
nop 1
dl 0
loc 5
ccs 2
cts 4
cp 0.5
crap 2.5
rs 10
1
<?php
2
3
namespace Nip\Records\Relations\Traits;
4
5
/**
6
 * Trait HasMorphTypeTrait
7
 * @package Nip\Records\Relations\Traits
8
 */
9
trait HasMorphTypeTrait
10
{
11
    protected $morphPrefix = 'parent';
12
13
    protected $morphTypeField = null;
14
15
16
    /**
17
     * @param $params
18
     */
19 2
    public function checkParamMorphPrefix($params)
20
    {
21 2
        if (isset($params['morphPrefix'])) {
22 2
            $this->setMorphPrefix($params['morphPrefix']);
23 2
            unset($params['morphPrefix']);
24
        }
25 2
    }
26
27
    /**
28
     * @param $params
29
     */
30 2
    public function checkParamMorphTypeField($params)
31
    {
32 2
        if (isset($params['morphTypeField'])) {
33
            $this->setMorphTypeField($params['morphTypeField']);
34
            unset($params['morphTypeField']);
35
        }
36 2
    }
37
38
    /**
39
     * @return string
40
     */
41 11
    public function getMorphPrefix(): string
42
    {
43 11
        return $this->morphPrefix;
44
    }
45
46
    /**
47
     * @param string $morphPrefix
48
     */
49 2
    public function setMorphPrefix(string $morphPrefix)
50
    {
51 2
        $this->morphPrefix = $morphPrefix;
52 2
    }
53
54
    /** @noinspection PhpMissingParentCallCommonInspection
55
     * @return string
56
     */
57 10
    public function generateFK()
58
    {
59 10
        return $this->getMorphPrefix() . '_id';
60
    }
61
62
    /**
63
     * @return null
64
     */
65 11
    public function getMorphTypeField()
66
    {
67 11
        if ($this->morphTypeField === null) {
68 11
            $this->setMorphTypeField(
69 11
                $this->getMorphPrefix() . '_type'
70
            );
71
        }
72 11
        return $this->morphTypeField;
73
    }
74
75
    /**
76
     * @param null $morphTypeField
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $morphTypeField is correct as it would always require null to be passed?
Loading history...
77
     * @return void
78
     */
79 11
    public function setMorphTypeField($morphTypeField)
80
    {
81 11
        $this->morphTypeField = $morphTypeField;
82 11
    }
83
}
84