Completed
Push — master ( 624099...e6e67e )
by Anton
01:21
created

Definition::getFactory()   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 0
crap 1
1
<?php declare(strict_types=1);
2
3
namespace Phact\Container\Definition;
4
5
use Phact\Container\Details\HasCallsTrait;
6
use Phact\Container\Details\HasPropertiesTrait;
7
8
class Definition implements DefinitionInterface
9
{
10
    use HasPropertiesTrait;
11
    use HasCallsTrait;
12
13
    /**
14
     * @var string
15
     */
16
    protected $class;
17
18
    /**
19
     * @var array
20
     */
21
    protected $arguments = [];
22
23
    /**
24
     * @var string[]
25
     */
26
    protected $aliases = [];
27
28
    /**
29
     * @var string|null
30
     */
31
    protected $constructMethod;
32
33
    /**
34
     * @var string|callable|null|array
35
     */
36
    protected $factory;
37
38
    /**
39
     * @var bool
40
     */
41
    protected $shared = true;
42
43 73
    public function __construct(string $class)
44
    {
45 73
        $this->class = $class;
46 73
    }
47
48
    /**
49
     * @return string
50
     */
51 43
    public function getClass(): string
52
    {
53 43
        return $this->class;
54
    }
55
56
    /**
57
     * @return array
58
     */
59 37
    public function getArguments(): array
60
    {
61 37
        return $this->arguments;
62
    }
63
64
    /**
65
     * @param array $arguments
66
     * @return Definition
67
     */
68 14
    public function setArguments(array $arguments): Definition
69
    {
70 14
        $this->arguments = $arguments;
71 14
        return $this;
72
    }
73
74
    /**
75
     * @return string[]
76
     */
77 23
    public function getAliases(): array
78
    {
79 23
        return $this->aliases;
80
    }
81
82
    /**
83
     * @param string[] $aliases
84
     * @return self
85
     */
86 5
    public function addAliases(array $aliases): self
87
    {
88 5
        foreach ($aliases as $alias) {
89 5
            $this->addAlias($alias);
90
        }
91 5
        return $this;
92
    }
93
    /**
94
     * @param string $alias
95
     * @return self
96
     */
97 6
    public function addAlias(string $alias): self
98
    {
99 6
        $this->aliases[] = $alias;
100 6
        return $this;
101
    }
102
103
    /**
104
     * @return string|null
105
     */
106 34
    public function getConstructMethod(): ?string
107
    {
108 34
        return $this->constructMethod;
109
    }
110
111
    /**
112
     * @param string|null $constructMethod
113
     */
114 6
    public function setConstructMethod(?string $constructMethod): void
115
    {
116 6
        $this->constructMethod = $constructMethod;
117 6
    }
118
119
    /**
120
     * @return callable|string|null|array
121
     */
122 41
    public function getFactory()
123
    {
124 41
        return $this->factory;
125
    }
126
127
    /**
128
     * @param callable|string|null|array $factory
129
     */
130 13
    public function setFactory($factory): void
131
    {
132 13
        $this->factory = $factory;
133 13
    }
134
135
    /**
136
     * @return bool
137
     */
138 10
    public function isShared(): bool
139
    {
140 10
        return $this->shared;
141
    }
142
143
    /**
144
     * @param bool $shared
145
     * @return Definition
146
     */
147 4
    public function setShared(bool $shared = true): self
148
    {
149 4
        $this->shared = $shared;
150 4
        return $this;
151
    }
152
}
153