Schedule::__construct()   A
last analyzed

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