Passed
Push — master ( 5acb2c...3be486 )
by Gabriel
07:50
created

Command::getModelRegistry()   A

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 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
4
namespace Nip\Records\Locator\Resolver\Commands;
5
6
use Nip\Records\AbstractModels\RecordManager;
7
use Nip\Records\Instantiator\HasInstantiatorTrait;
8
use Nip\Records\Locator\Configuration\Configuration;
9
use Nip\Records\Registry\HasModelRegistry;
10
use Nip\Records\Registry\ModelRegistry;
11
12
/**
13
 * Class Command
14
 * @package Nip\Records\Locator\Resolver\Commands
15
 */
16
class Command
17
{
18
    use HasInstantiatorTrait;
19
    use HasModelRegistry;
20
21
    /**
22
     * @var string
23
     */
24
    protected $alias;
25
26
    /**
27
     * @var Configuration
28
     */
29
    protected $configuration;
30
31
    /**
32
     * @var []
0 ignored issues
show
Documentation Bug introduced by
The doc comment [] at position 0 could not be parsed: Unknown type name '[' at position 0 in [].
Loading history...
33
     */
34
    protected $tries = [];
35
36
    /**
37
     * @var RecordManager
38
     */
39
    protected $instance = null;
40
41
    /**
42
     * @return string
43
     */
44 3
    public function getAlias(): string
45
    {
46 3
        return $this->alias;
47
    }
48
49
    /**
50
     * @param string $alias
51
     */
52 3
    public function setAlias(string $alias)
53
    {
54 3
        $this->alias = $alias;
55 3
    }
56
57
    /**
58
     * @return bool
59
     */
60
    public function hasConfiguration()
61
    {
62
        return $this->getConfiguration() instanceof Configuration;
63
    }
64
65
    /**
66
     * @return Configuration
67
     */
68 3
    public function getConfiguration(): Configuration
69
    {
70 3
        return $this->configuration;
71
    }
72
73
    /**
74
     * @param Configuration $configuration
75
     */
76 3
    public function setConfiguration(Configuration $configuration)
77
    {
78 3
        $this->configuration = $configuration;
79 3
    }
80
81
    /**
82
     * @return bool
83
     */
84 3
    public function hasInstance()
85
    {
86 3
        return $this->getInstance() instanceof RecordManager;
87
    }
88
89
    /**
90
     * @return RecordManager|null
91
     */
92 3
    public function getInstance()
93
    {
94 3
        return $this->instance;
95
    }
96
97
    /**
98
     * @param RecordManager $instance
99
     */
100 2
    public function setInstance(RecordManager $instance)
101
    {
102 2
        $this->instance = $instance;
103 2
    }
104
105
    /**
106
     * @return bool
107
     */
108 3
    public function hasNamespaces()
109
    {
110 3
        return $this->getConfiguration()->hasNamespaces();
111
    }
112
113
    /**
114
     * @return array
115
     */
116 2
    public function getNamespaces()
117
    {
118 2
        return $this->hasNamespaces() ? $this->getConfiguration()->getNamespaces() : [];
119
    }
120
121
    /**
122
     * @return ModelRegistry
123
     */
124 1
    public function getTries(): array
125
    {
126 1
        return $this->tries;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->tries returns the type array which is incompatible with the documented return type Nip\Records\Registry\ModelRegistry.
Loading history...
127
    }
128
129
    /**
130
     * @param $class
131
     */
132 3
    public function addTry($class)
133
    {
134 3
        $this->tries[] = $class;
135 3
    }
136
}
137