StepRegistration::getAfters()   A
last analyzed

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
2
namespace PSB\Core\Pipeline;
3
4
5
use PSB\Core\ObjectBuilder\BuilderInterface;
6
use PSB\Core\Util\Guard;
7
8
class StepRegistration
9
{
10
    /**
11
     * @var string
12
     */
13
    private $stepId;
14
15
    /**
16
     * @var string
17
     */
18
    private $stepFqcn;
19
20
    /**
21
     * @var callable|null
22
     */
23
    private $factory;
24
25
    /**
26
     * @var null|string
27
     */
28
    private $description;
29
30
    /**
31
     * @var StepRegistrationDependency[]
32
     */
33
    private $befores = [];
34
35
    /**
36
     * @var StepRegistrationDependency[]
37
     */
38
    private $afters = [];
39
40
    /**
41
     * @param string        $stepId
42
     * @param string        $stepFqcn
43
     * @param callable|null $factory
44
     * @param string|null   $description
45
     */
46 32 View Code Duplication
    public function __construct($stepId, $stepFqcn, callable $factory = null, $description = null)
47
    {
48 32
        Guard::againstNullAndEmpty('stepId', $stepId);
49 31
        Guard::againstNullAndEmpty('stepClass', $stepFqcn);
50
51 30
        $this->stepId = $stepId;
52 30
        $this->stepFqcn = $stepFqcn;
53 30
        $this->factory = $factory;
54 30
        $this->description = $description;
55 30
    }
56
57
    /**
58
     * @param StepReplacement $replacement
59
     */
60 1
    public function replaceWith(StepReplacement $replacement)
61
    {
62 1
        $this->stepFqcn = $replacement->getStepFqcn();
63 1
        $this->description = $replacement->getDescription() ?: $this->description;
64 1
        $this->factory = $replacement->getFactory();
65 1
    }
66
67
    /**
68
     * @param BuilderInterface $builder
69
     */
70 2
    public function registerInBuilder(BuilderInterface $builder)
71
    {
72 2
        if ($this->factory) {
73 2
            $builder->defineSingleton($this->stepFqcn, $this->factory);
74
        }
75 2
    }
76
77
    /**
78
     * @return string
79
     */
80 17
    public function getStepId()
81
    {
82 17
        return $this->stepId;
83
    }
84
85
    /**
86
     * @return string
87
     */
88 11
    public function getStepFqcn()
89
    {
90 11
        return $this->stepFqcn;
91
    }
92
93
    /**
94
     * @return callable|null
95
     */
96 2
    public function getFactory()
97
    {
98 2
        return $this->factory;
99
    }
100
101
    /**
102
     * @return null|string
103
     */
104 2
    public function getDescription()
105
    {
106 2
        return $this->description;
107
    }
108
109
    /**
110
     * @return StepRegistrationDependency[]
111
     */
112 14
    public function getBefores()
113
    {
114 14
        return $this->befores;
115
    }
116
117
    /**
118
     * @return StepRegistrationDependency[]
119
     */
120 13
    public function getAfters()
121
    {
122 13
        return $this->afters;
123
    }
124
125
    /**
126
     * @param string $id
127
     */
128 1
    public function insertBeforeIfExists($id)
129
    {
130 1
        Guard::againstNullAndEmpty('id', $id);
131 1
        $this->befores[] = new StepRegistrationDependency($this->stepId, $id, false);
132 1
    }
133
134
    /**
135
     * @param string $id
136
     */
137 5
    public function insertBefore($id)
138
    {
139 5
        Guard::againstNullAndEmpty('id', $id);
140 4
        $this->befores[] = new StepRegistrationDependency($this->stepId, $id, true);
141 4
    }
142
143
    /**
144
     * @param string $id
145
     */
146 1
    public function insertAfterIfExists($id)
147
    {
148 1
        Guard::againstNullAndEmpty('id', $id);
149 1
        $this->afters[] = new StepRegistrationDependency($this->stepId, $id, false);
150 1
    }
151
152
    /**
153
     * @param string $id
154
     */
155 5
    public function insertAfter($id)
156
    {
157 5
        Guard::againstNullAndEmpty('id', $id);
158 4
        $this->afters[] = new StepRegistrationDependency($this->stepId, $id, true);
159 4
    }
160
}
161