Completed
Push — master ( 4ac004...470d43 )
by Gabriel
06:41
created

HasItemTrait::getItemValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 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 8
    public function getItem()
24
    {
25 8
        return $this->item;
26
    }
27
28
    /**
29
     * @param Record|HasRelationsRecordTrait $item
30
     * @return $this
31
     */
32 9
    public function setItem(Record $item)
33
    {
34 9
        $this->item = $item;
35
36 9
        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?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

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