Completed
Push — master ( c5047e...3a177f )
by Gabriel
03:52
created

HasManagerTrait::getManager()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
crap 2
1
<?php
2
3
namespace Nip\Records\Relations\Traits;
4
5
use Nip\Records\AbstractModels\Record;
6
use Nip\Records\AbstractModels\RecordManager;
7
use Nip\Records\Traits\Relations\HasRelationsRecordsTrait;
8
9
/**
10
 * Class HasManagerTrait
11
 * @package Nip\Records\Relations\Traits
12
 *
13
 * @method Record getItem()
14
 */
15
trait HasManagerTrait
16
{
17
18
    /**
19
     * @var RecordManager
20
     */
21
    protected $manager = null;
22
23
    /**
24
     * @return RecordManager|\Nip\Records\RecordManager
25
     */
26 3
    public function getManager()
27
    {
28 3
        if ($this->manager == null) {
29 1
            $this->initManager();
30
        }
31
32 3
        return $this->manager;
33
    }
34
35
    /**
36
     * @param HasRelationsRecordsTrait $manager
0 ignored issues
show
introduced by
The type HasRelationsRecordsTrait for parameter $manager is a trait, and thus cannot be used for type-hinting in PHP. Maybe consider adding an interface and use that for type-hinting?
Loading history...
37
     */
38 4
    public function setManager($manager)
39
    {
40 4
        $this->manager = $manager;
0 ignored issues
show
Documentation Bug introduced by
It seems like $manager of type object<Nip\Records\Trait...sRelationsRecordsTrait> is incompatible with the declared type object<Nip\Records\AbstractModels\RecordManager> of property $manager.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
41 4
    }
42
43
    /**
44
     * @return void
45
     */
46 1
    public function initManager()
47
    {
48 1
        $this->manager = $this->getItem()->getManager();
49 1
    }
50
51
    /**
52
     * @return bool
53
     */
54 1
    public function hasManager()
55
    {
56 1
        return $this->manager instanceof RecordManager;
57
    }
58
}
59