Passed
Pull Request — master (#28)
by Valentin
49:48
created

Schedule::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 8
c 0
b 0
f 0
dl 0
loc 19
ccs 9
cts 9
cp 1
rs 10
cc 1
nc 1
nop 8
crap 1

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
4
namespace Pheanstalk\Structure;
5
6
7
class Schedule
8
{
9
    const FAILURE_TYPE_CONTINUE = "CONTINUE";
10
    const FAILURE_TYPE_SUSPEND = "SUSPEND";
11
12
    /** @var int|null $id */
13
    protected $id;
14
15
    /** @var bool $active */
16
    protected $active;
17
18
    /** @var string|null $comment */
19
    protected $comment;
20
21
    /** @var string|null $host */
22
    protected $host;
23
24
    /** @var string|null $node */
25
    protected $node;
26
27
    /** @var string|null $node */
28
    protected $onFailure;
29
30
    /** @var TimeSchedule $schedule */
31
    protected $schedule;
32
33
    /** @var string|null $user */
34
    protected $user;
35
36
    /** @var int $workflow */
37
    protected $workflow;
38
39 1
    public function __construct(
40
        int $workflow,
41
        TimeSchedule $schedule,
42
        $onFailure = self::FAILURE_TYPE_CONTINUE,
43
        $active = true,
44
        $comment = null,
45
        $user = null,
46
        $host = null,
47
        $node = "any"
48
    )
49
    {
0 ignored issues
show
Coding Style introduced by
The closing parenthesis and the opening brace of a multi-line function declaration must be on the same line
Loading history...
50 1
        $this->workflow = $workflow;
51 1
        $this->schedule = $schedule;
52 1
        $this->onFailure = $onFailure;
53 1
        $this->active = $active;
54 1
        $this->comment = $comment;
55 1
        $this->user = $user;
56 1
        $this->host = $host;
57 1
        $this->node = $node;
58
    }
59
60
    /**
61
     * @return int|null
62
     */
63 1
    public function getId(): ?int
64
    {
65 1
        return $this->id;
66
    }
67
68
    /**
69
     * @param int|null $id
70
     *
71
     * @return Schedule
72
     */
73 1
    public function setId(?int $id): Schedule
74
    {
75 1
        $this->id = $id;
76 1
        return $this;
77
    }
78
79
    /**
80
     * @return bool
81
     */
82 1
    public function isActive(): bool
83
    {
84 1
        return $this->active;
85
    }
86
87
    /**
88
     * @param bool $active
89
     *
90
     * @return Schedule
91
     */
92
    public function setActive(bool $active): Schedule
93
    {
94
        $this->active = $active;
95
        return $this;
96
    }
97
98
    /**
99
     * @return string|null
100
     */
101 1
    public function getComment(): ?string
102
    {
103 1
        return $this->comment;
104
    }
105
106
    /**
107
     * @param string|null $comment
108
     *
109
     * @return Schedule
110
     */
111
    public function setComment(?string $comment): Schedule
112
    {
113
        $this->comment = $comment;
114
        return $this;
115
    }
116
117
    /**
118
     * @return string|null
119
     */
120
    public function getHost(): ?string
121
    {
122
        return $this->host;
123
    }
124
125
    /**
126
     * @param string|null $host
127
     *
128
     * @return Schedule
129
     */
130
    public function setHost(?string $host): Schedule
131
    {
132
        $this->host = $host;
133
        return $this;
134
    }
135
136
    /**
137
     * @return string|null
138
     */
139 1
    public function getNode(): ?string
140
    {
141 1
        return $this->node;
142
    }
143
144
    /**
145
     * @param string|null $node
146
     *
147
     * @return Schedule
148
     */
149
    public function setNode(?string $node): Schedule
150
    {
151
        $this->node = $node;
152
        return $this;
153
    }
154
155
    /**
156
     * @return string|null
157
     */
158 1
    public function getOnFailure(): ?string
159
    {
160 1
        return $this->onFailure;
161
    }
162
163
    /**
164
     * @param string|null $onFailure
165
     *
166
     * @return Schedule
167
     */
168
    public function setOnFailure(?string $onFailure): Schedule
169
    {
170
        $this->onFailure = $onFailure;
171
        return $this;
172
    }
173
174
    /**
175
     * @return TimeSchedule
176
     */
177 1
    public function getSchedule(): TimeSchedule
178
    {
179 1
        return $this->schedule;
180
    }
181
182
    /**
183
     * @param TimeSchedule $schedule
184
     *
185
     * @return Schedule
186
     */
187
    public function setSchedule(TimeSchedule $schedule): Schedule
188
    {
189
        $this->schedule = $schedule;
190
        return $this;
191
    }
192
193
    /**
194
     * @return string|null
195
     */
196
    public function getUser(): ?string
197
    {
198
        return $this->user;
199
    }
200
201
    /**
202
     * @param string|null $user
203
     *
204
     * @return Schedule
205
     */
206
    public function setUser(?string $user): Schedule
207
    {
208
        $this->user = $user;
209
        return $this;
210
    }
211
212
    /**
213
     * @return int
214
     */
215 1
    public function getWorkflow(): int
216
    {
217 1
        return $this->workflow;
218
    }
219
220
    /**
221
     * @param int $workflow
222
     *
223
     * @return Schedule
224
     */
225
    public function setWorkflow(int $workflow): Schedule
226
    {
227
        $this->workflow = $workflow;
228
        return $this;
229
    }
230
231
}