HasPivotPrimaryKey::setPivotPrimaryKey()   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 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
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\Traits;
4
5
use Nip\Records\AbstractModels\RecordManager;
6
7
/**
8
 * Trait HasPivotPrimaryKey
9
 * @package Nip\Records\Relations\Traits
10
 *
11
 * @method RecordManager getWith
12
 */
13
trait HasPivotPrimaryKey
14
{
15
    /**
16
     * @var null|string
17
     */
18
    protected $pivotPrimaryKey = null;
19
20
    /**
21
     * @param $params
22
     */
23
    public function checkParamPivotPrimaryKey($params)
24
    {
25
        if (isset($params['pivotPrimaryKey'])) {
26
            $this->setPivotPrimaryKey($params['pivotPrimaryKey']);
27
            unset($params['pivotPrimaryKey']);
28
        }
29
    }
30
31
32
    /**
33
     * @return string
34
     */
35 1
    public function getPivotPrimaryKey()
36
    {
37 1
        if ($this->pivotPrimaryKey == null) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $this->pivotPrimaryKey of type null|string against null; this is ambiguous if the string can be empty. Consider using a strict comparison === instead.
Loading history...
38 1
            $this->initPivotPrimaryKey();
39
        }
40
41 1
        return $this->pivotPrimaryKey;
42
    }
43
44
    /**
45
     * @param $name
46
     */
47 1
    public function setPivotPrimaryKey($name)
48
    {
49 1
        $this->pivotPrimaryKey = $name;
50 1
    }
51
52 1
    protected function initPivotPrimaryKey()
53
    {
54 1
        $this->setPivotPrimaryKey($this->generatePivotPrimaryKey());
55 1
    }
56
57
    /**
58
     * @return string
59
     */
60 1
    protected function generatePivotPrimaryKey()
61
    {
62 1
        return $this->getWith()->getPrimaryKey();
63
    }
64
}
65