HasItemTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 8
c 1
b 0
f 1
dl 0
loc 43
ccs 10
cts 10
cp 1
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getItemRelationPrimaryKey() 0 4 1
A setItem() 0 5 1
A getItem() 0 3 1
A getItemValue() 0 3 1
1
<?php
2
3
namespace Nip\Records\Relations\Traits;
4
5
use Nip\Records\Record;
6
use Nip\Records\Traits\Relations\HasRelationsRecordTrait;
7
8
/**
9
 * Trait HasItemTrait
10
 * @package Nip\Records\Relations\Traits
11
 */
12
trait HasItemTrait
13
{
14
15
    /**
16
     * @var Record
17
     */
18
    protected $item;
19
20
    /**
21
     * @return Record
22
     */
23 9
    public function getItem()
24
    {
25 9
        return $this->item;
26
    }
27
28
    /**
29
     * @param Record|HasRelationsRecordTrait $item
30
     * @return $this
31
     */
32 10
    public function setItem(Record $item)
33
    {
34 10
        $this->item = $item;
35
36 10
        return $this;
37
    }
38
39
    /**
40
     * @return mixed
41
     */
42 2
    public function getItemRelationPrimaryKey()
43
    {
44 2
        $key = $this->getPrimaryKey();
0 ignored issues
show
Bug introduced by
It seems like getPrimaryKey() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

44
        /** @scrutinizer ignore-call */ 
45
        $key = $this->getPrimaryKey();
Loading history...
45 2
        return $this->getItemValue($key);
46
    }
47
48
    /**
49
     * @param $key
50
     * @return mixed
51
     */
52 2
    public function getItemValue($key)
53
    {
54 2
        return $this->getItem()->{$key};
55
    }
56
}
57