Passed
Push — master ( ab8b9d...7e5c9a )
by Valentin
08:11 queued 06:26
created

Schedule::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
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 18
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 10
    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 10
        $this->workflow = $workflow;
50 10
        $this->schedule = $schedule;
51 10
        $this->onFailure = $onFailure;
52 10
        $this->active = $active;
53 10
        $this->comment = $comment;
54 10
        $this->user = $user;
55 10
        $this->host = $host;
56 10
        $this->node = $node;
57
    }
58
59
    /**
60
     * @return int|null
61
     */
62 2
    public function getId(): ?int
63
    {
64 2
        return $this->id;
65
    }
66
67
    /**
68
     * @param int|null $id
69
     *
70
     * @return Schedule
71
     */
72 2
    public function setId(?int $id): Schedule
73
    {
74 2
        $this->id = $id;
75 2
        return $this;
76
    }
77
78
    /**
79
     * @return bool
80
     */
81 2
    public function isActive(): bool
82
    {
83 2
        return $this->active;
84
    }
85
86
    /**
87
     * @param bool $active
88
     *
89
     * @return Schedule
90
     */
91 1
    public function setActive(bool $active): Schedule
92
    {
93 1
        $this->active = $active;
94 1
        return $this;
95
    }
96
97
    /**
98
     * @return string|null
99
     */
100 2
    public function getComment(): ?string
101
    {
102 2
        return $this->comment;
103
    }
104
105
    /**
106
     * @param string|null $comment
107
     *
108
     * @return Schedule
109
     */
110 1
    public function setComment(?string $comment): Schedule
111
    {
112 1
        $this->comment = $comment;
113 1
        return $this;
114
    }
115
116
    /**
117
     * @return string|null
118
     */
119 2
    public function getHost(): ?string
120
    {
121 2
        return $this->host;
122
    }
123
124
    /**
125
     * @param string|null $host
126
     *
127
     * @return Schedule
128
     */
129 1
    public function setHost(?string $host): Schedule
130
    {
131 1
        $this->host = $host;
132 1
        return $this;
133
    }
134
135
    /**
136
     * @return string|null
137
     */
138 2
    public function getNode(): ?string
139
    {
140 2
        return $this->node;
141
    }
142
143
    /**
144
     * @param string|null $node
145
     *
146
     * @return Schedule
147
     */
148 1
    public function setNode(?string $node): Schedule
149
    {
150 1
        $this->node = $node;
151 1
        return $this;
152
    }
153
154
    /**
155
     * @return string|null
156
     */
157 2
    public function getOnFailure(): ?string
158
    {
159 2
        return $this->onFailure;
160
    }
161
162
    /**
163
     * @param string|null $onFailure
164
     *
165
     * @return Schedule
166
     */
167 1
    public function setOnFailure(?string $onFailure): Schedule
168
    {
169 1
        $this->onFailure = $onFailure;
170 1
        return $this;
171
    }
172
173
    /**
174
     * @return TimeSchedule
175
     */
176 2
    public function getSchedule(): TimeSchedule
177
    {
178 2
        return $this->schedule;
179
    }
180
181
    /**
182
     * @param TimeSchedule $schedule
183
     *
184
     * @return Schedule
185
     */
186 2
    public function setSchedule(TimeSchedule $schedule): Schedule
187
    {
188 2
        $this->schedule = $schedule;
189 2
        return $this;
190
    }
191
192
    /**
193
     * @return string|null
194
     */
195 2
    public function getUser(): ?string
196
    {
197 2
        return $this->user;
198
    }
199
200
    /**
201
     * @param string|null $user
202
     *
203
     * @return Schedule
204
     */
205 1
    public function setUser(?string $user): Schedule
206
    {
207 1
        $this->user = $user;
208 1
        return $this;
209
    }
210
211
    /**
212
     * @return int
213
     */
214 2
    public function getWorkflow(): int
215
    {
216 2
        return $this->workflow;
217
    }
218
219
    /**
220
     * @param int $workflow
221
     *
222
     * @return Schedule
223
     */
224 1
    public function setWorkflow(int $workflow): Schedule
225
    {
226 1
        $this->workflow = $workflow;
227 1
        return $this;
228
    }
229
230
}