Completed
Push — master ( d0cc87...6d3818 )
by Valentin
03:32
created

WorkflowInstance   A

Complexity

Total Complexity 38

Size/Duplication

Total Lines 386
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 11
Bugs 0 Features 0
Metric Value
wmc 38
eloc 80
c 11
b 0
f 0
dl 0
loc 386
ccs 94
cts 94
cp 1
rs 9.36

34 Methods

Rating   Name   Duplication   Size   Complexity  
A getComment() 0 3 1
A setRetryingTasks() 0 4 1
A setName() 0 4 1
A getScheduleId() 0 3 1
A setHost() 0 4 1
A getEvqid() 0 3 1
A setErrors() 0 4 1
A setEvqid() 0 4 1
A getRunningTasks() 0 3 1
A getStartTime() 0 3 1
A getId() 0 3 1
A updateStatus() 0 13 5
A setComment() 0 4 1
A setJobInstances() 0 4 1
A getEndTime() 0 3 1
A removeJobInstance() 0 4 1
A setNodeName() 0 4 1
A getErrors() 0 3 1
A getNodeName() 0 3 1
A setQueuedTasks() 0 4 1
A getName() 0 3 1
A setStartTime() 0 4 1
A setId() 0 4 1
A setRunningTasks() 0 4 1
A getStatus() 0 3 1
A __construct() 0 5 1
A setEndTime() 0 4 1
A getHost() 0 3 1
A getJobInstances() 0 3 1
A addJobInstance() 0 4 1
A setStatus() 0 4 1
A getRetryingTasks() 0 3 1
A getQueuedTasks() 0 3 1
A setScheduleId() 0 4 1
1
<?php
2
3
4
namespace Pheanstalk\Structure;
5
6
use Doctrine\Common\Collections\ArrayCollection;
7
8
class WorkflowInstance extends ParameterManipulations
9
{
10
    const STATUS_QUEUED = "QUEUED";
11
    const STATUS_RUNNING = "RUNNING";
12
    const STATUS_RETRYING = "RETRYING";
13
    const STATUS_FAILED = "FAILED";
14
15
    /** @var string|null $comment */
16
    protected $comment;
17
18
    /** @var \DateTime|null $endTime */
19
    protected $endTime;
20
21
    /** @var int|null $errors */
22
    protected $errors;
23
24
    /** @var string|null $host */
25
    protected $host;
26
27
    /** @var int $id */
28
    protected $id;
29
30
    /** @var string $name */
31
    protected $name;
32
33
    /** @var string|null $nodeName */
34
    protected $nodeName;
35
36
    /** @var int|null $scheduleId */
37
    protected $scheduleId;
38
39
    /** @var \DateTime $startTime */
40
    protected $startTime;
41
42
    /** @var string $status */
43
    protected $status;
44
45
    /** @var int|null $evqid */
46
    protected $evqid;
47
48
    /** @var int|null $queuedTasks */
49
    protected $queuedTasks;
50
51
    /** @var int|null $runningTasks */
52
    protected $runningTasks;
53
54
    /** @var int|null $retryingTasks */
55
    protected $retryingTasks;
56
57
    /** @var ArrayCollection */
58
    protected $jobInstances;
59
60
    /**
61
     * @inheritDoc
62
     */
63 36
    public function __construct(array $params)
64
    {
65 36
        $this->jobInstances = new ArrayCollection([]);
66 36
        parent::__construct($params);
67 36
        $this->updateStatus();
68
    }
69
70
    /**
71
     * @return null|string
72
     */
73 2
    public function getComment(): ?string
74
    {
75 2
        return $this->comment;
76
    }
77
78
    /**
79
     * @param string $comment
80
     *
81
     * @return WorkflowInstance
82
     */
83 1
    public function setComment(string $comment): WorkflowInstance
84
    {
85 1
        $this->comment = $comment;
86 1
        return $this;
87
    }
88
89
    /**
90
     * @return null|\DateTime
91
     */
92 2
    public function getEndTime(): ?\DateTime
93
    {
94 2
        return $this->endTime;
95
    }
96
97
    /**
98
     * @param \DateTime $endTime
99
     *
100
     * @return WorkflowInstance
101
     */
102 1
    public function setEndTime(\DateTime $endTime): WorkflowInstance
103
    {
104 1
        $this->endTime = $endTime;
105 1
        return $this;
106
    }
107
108
    /**
109
     * @return null|int
110
     */
111 36
    public function getErrors(): ?int
112
    {
113 36
        return $this->errors ?? 0;
114
    }
115
116
    /**
117
     * @param null|int $errors
118
     *
119
     * @return WorkflowInstance
120
     */
121 1
    public function setErrors(?int $errors): WorkflowInstance
122
    {
123 1
        $this->errors = $errors;
124 1
        return $this;
125
    }
126
127
    /**
128
     * @return null|string
129
     */
130 2
    public function getHost(): ?string
131
    {
132 2
        return $this->host;
133
    }
134
135
    /**
136
     * @param string $host
137
     *
138
     * @return WorkflowInstance
139
     */
140 1
    public function setHost(string $host): WorkflowInstance
141
    {
142 1
        $this->host = $host;
143 1
        return $this;
144
    }
145
146
    /**
147
     * @return int
148
     */
149 5
    public function getId(): int
150
    {
151 5
        return $this->id;
152
    }
153
154
    /**
155
     * @param int $id
156
     *
157
     * @return WorkflowInstance
158
     */
159 1
    public function setId(int $id): WorkflowInstance
160
    {
161 1
        $this->id = $id;
162 1
        return $this;
163
    }
164
165
    /**
166
     * @return string
167
     */
168 2
    public function getName(): string
169
    {
170 2
        return $this->name;
171
    }
172
173
    /**
174
     * @param string $name
175
     *
176
     * @return WorkflowInstance
177
     */
178 1
    public function setName(string $name): WorkflowInstance
179
    {
180 1
        $this->name = $name;
181 1
        return $this;
182
    }
183
184
    /**
185
     * @return null|string
186
     */
187 2
    public function getNodeName(): ?string
188
    {
189 2
        return $this->nodeName;
190
    }
191
192
    /**
193
     * @param string $nodeName
194
     *
195
     * @return WorkflowInstance
196
     */
197 1
    public function setNodeName(string $nodeName): WorkflowInstance
198
    {
199 1
        $this->nodeName = $nodeName;
200 1
        return $this;
201
    }
202
203
    /**
204
     * @return null|int
205
     */
206 2
    public function getScheduleId(): ?int
207
    {
208 2
        return $this->scheduleId;
209
    }
210
211
    /**
212
     * @param int $scheduleId
213
     *
214
     * @return WorkflowInstance
215
     */
216 1
    public function setScheduleId(int $scheduleId): WorkflowInstance
217
    {
218 1
        $this->scheduleId = $scheduleId;
219 1
        return $this;
220
    }
221
222
    /**
223
     * @return \DateTime
224
     */
225 2
    public function getStartTime(): \DateTime
226
    {
227 2
        return $this->startTime;
228
    }
229
230
    /**
231
     * @param \DateTime $startTime
232
     *
233
     * @return WorkflowInstance
234
     */
235 1
    public function setStartTime(\DateTime $startTime): WorkflowInstance
236
    {
237 1
        $this->startTime = $startTime;
238 1
        return $this;
239
    }
240
241
    /**
242
     * @return string
243
     */
244 3
    public function getStatus(): string
245
    {
246 3
        return $this->status;
247
    }
248
249
    /**
250
     * @return void
251
     */
252 36
    public function updateStatus()
253
    {
254 36
        if ($this->getRunningTasks() > 0) {
255 4
            $this->setStatus(self::STATUS_RUNNING);
256
        }
257 36
        if ($this->getQueuedTasks() > 0) {
258 4
            $this->setStatus(self::STATUS_QUEUED);
259
        }
260 36
        if ($this->getRetryingTasks() > 0) {
261 2
            $this->setStatus(self::STATUS_RETRYING);
262
        }
263 36
        if ($this->getErrors() > 0) {
264 2
            $this->setStatus(self::STATUS_FAILED);
265
        }
266
    }
267
268
    /**
269
     * @param string $status
270
     *
271
     * @return WorkflowInstance
272
     */
273 8
    public function setStatus(string $status): WorkflowInstance
274
    {
275 8
        $this->status = $status;
276 8
        return $this;
277
    }
278
279
    /**
280
     * @return int|null
281
     */
282 2
    public function getEvqid(): ?int
283
    {
284 2
        return $this->evqid;
285
    }
286
287
    /**
288
     * @param int|null $evqid
289
     *
290
     * @return WorkflowInstance
291
     */
292 1
    public function setEvqid(?int $evqid): WorkflowInstance
293
    {
294 1
        $this->evqid = $evqid;
295 1
        return $this;
296
    }
297
298
    /**
299
     * @return int|null
300
     */
301 36
    public function getQueuedTasks(): ?int
302
    {
303 36
        return $this->queuedTasks ?? 0;
304
    }
305
306
    /**
307
     * @param int|null $queuedTasks
308
     *
309
     * @return WorkflowInstance
310
     */
311 1
    public function setQueuedTasks(?int $queuedTasks): WorkflowInstance
312
    {
313 1
        $this->queuedTasks = $queuedTasks;
314 1
        return $this;
315
    }
316
317
    /**
318
     * @return int|null
319
     */
320 36
    public function getRunningTasks(): ?int
321
    {
322 36
        return $this->runningTasks ?? 0;
323
    }
324
325
    /**
326
     * @param int|null $runningTasks
327
     *
328
     * @return WorkflowInstance
329
     */
330 1
    public function setRunningTasks(?int $runningTasks): WorkflowInstance
331
    {
332 1
        $this->runningTasks = $runningTasks;
333 1
        return $this;
334
    }
335
336
    /**
337
     * @return int|null
338
     */
339 36
    public function getRetryingTasks(): ?int
340
    {
341 36
        return $this->retryingTasks ?? 0;
342
    }
343
344
    /**
345
     * @param int|null $retryingTasks
346
     *
347
     * @return WorkflowInstance
348
     */
349 1
    public function setRetryingTasks(?int $retryingTasks): WorkflowInstance
350
    {
351 1
        $this->retryingTasks = $retryingTasks;
352 1
        return $this;
353
    }
354
355
    /**
356
     * @return ArrayCollection
357
     */
358 5
    public function getJobInstances(): ArrayCollection
359
    {
360 5
        return $this->jobInstances;
361
    }
362
363
    /**
364
     * @param ArrayCollection $jobInstances
365
     *
366
     * @return WorkflowInstance
367
     */
368 4
    public function setJobInstances(ArrayCollection $jobInstances): WorkflowInstance
369
    {
370 4
        $this->jobInstances = $jobInstances;
371 4
        return $this;
372
    }
373
374
    /**
375
     * @param JobInstance $jobInstance
376
     *
377
     * @return WorkflowInstance
378
     */
379 2
    public function addJobInstance(JobInstance $jobInstance): WorkflowInstance
380
    {
381 2
        $this->jobInstances[] = $jobInstance;
382 2
        return $this;
383
    }
384
385
    /**
386
     * @param JobInstance $jobInstance
387
     *
388
     * @return WorkflowInstance
389
     */
390 1
    public function removeJobInstance(JobInstance $jobInstance): WorkflowInstance
391
    {
392 1
        $this->jobInstances->removeElement($jobInstance);
393 1
        return $this;
394
    }
395
}
396