Campaign::getSkipped()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Copyright (c) 2017 Francois-Xavier Soubirou.
4
 *
5
 * This file is part of ci-report.
6
 *
7
 * ci-report is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation, either version 3 of the License, or
10
 * (at your option) any later version.
11
 *
12
 * ci-report is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with ci-report. If not, see <http://www.gnu.org/licenses/>.
19
 */
20
declare(strict_types=1);
21
22
namespace App\Entity;
23
24
use App\DTO\CampaignDTO;
25
use DateTime;
26
use Doctrine\ORM\Mapping as ORM;
27
use Gedmo\Mapping\Annotation as Gedmo;
28
use JMS\Serializer\Annotation as Serializer;
29
use Symfony\Component\Validator\Constraints as Assert;
30
31
/**
32
 * Campaign entity class.
33
 *
34
 * @category  ci-report app
35
 *
36
 * @author    Francois-Xavier Soubirou <[email protected]>
37
 * @copyright 2017 Francois-Xavier Soubirou
38
 * @license   http://www.gnu.org/licenses/   GPLv3
39
 *
40
 * @see      https://www.ci-report.io
41
 *
42
 * @ORM\Table(name="cir_campaign")
43
 * @ORM\Entity(repositoryClass="App\Repository\CampaignRepository")
44
 */
45
class Campaign
46
{
47
    /**
48
     * @var int
49
     *
50
     * @ORM\Column(name="id", type="integer")
51
     * @ORM\Id
52
     * @ORM\GeneratedValue(strategy="AUTO")
53
     *
54
     * @Serializer\Exclude
55
     */
56
    private $id;
57
58
    /**
59
     * Total number of passed tests from all testsuites.
60
     *
61
     * @var int
62
     *
63
     * @ORM\Column(name="passed", type="integer")
64
     *
65
     * @Assert\NotBlank()
66
     * @Assert\Type("integer")
67
     *
68
     * @Serializer\Groups({"public", "private"})
69
     */
70
    private $passed = 0;
71
72
    /**
73
     * Total number of failed tests from all testsuites.
74
     *
75
     * @var int
76
     *
77
     * @ORM\Column(name="failed", type="integer")
78
     *
79
     * @Assert\NotBlank()
80
     * @Assert\Type("integer")
81
     *
82
     * @Serializer\Groups({"public", "private"})
83
     */
84
    private $failed = 0;
85
86
    /**
87
     * Total number of errored tests from all testsuites.
88
     *
89
     * @var int
90
     *
91
     * @ORM\Column(name="errored", type="integer")
92
     *
93
     * @Assert\NotBlank()
94
     * @Assert\Type("integer")
95
     *
96
     * @Serializer\Groups({"public", "private"})
97
     */
98
    private $errored = 0;
99
100
    /**
101
     * Total number of skipped tests from all testsuites.
102
     *
103
     * @var int
104
     *
105
     * @ORM\Column(name="skipped", type="integer")
106
     *
107
     * @Assert\NotBlank()
108
     * @Assert\Type("integer")
109
     *
110
     * @Serializer\Groups({"public", "private"})
111
     */
112
    private $skipped = 0;
113
114
    /**
115
     * Total number of disabled tests from all testsuites.
116
     *
117
     * @var int
118
     *
119
     * @ORM\Column(name="disabled", type="integer")
120
     *
121
     * @Assert\NotBlank()
122
     * @Assert\Type("integer")
123
     *
124
     * @Serializer\Groups({"public", "private"})
125
     */
126
    private $disabled = 0;
127
128
    /**
129
     * Status of campaign defined by lowest status of all suites. If no suite, status is unknown.
130
     *
131
     * @var int
132
     *
133
     * @ORM\Column(name="status", type="smallint")
134
     *
135
     * @Assert\NotBlank()
136
     * @Assert\Type("integer")
137
     *
138
     * @Serializer\Groups({"public", "private"})
139
     */
140
    private $status = 8;
141
142
    /**
143
     * Start Date time of the campaign in ISO 8601 format (2017-07-01T12:30:01+02:00).
144
     *
145
     * @var DateTime
146
     *
147
     * @ORM\Column(name="start", type="datetime")
148
     *
149
     * @Assert\NotBlank()
150
     * @Assert\DateTime()
151
     *
152
     * @Serializer\Groups({"public", "private"})
153
     */
154
    protected $start;
155
156
    /**
157
     * End Date time of the campaign in ISO 8601 format (2017-07-01T12:30:01+02:00). Returned if not null.
158
     *
159
     * @var DateTime
160
     *
161
     * @ORM\Column(name="end", type="datetime", nullable=true)
162
     *
163
     * @Assert\DateTime()
164
     *
165
     * @Serializer\Groups({"public", "private"})
166
     */
167
    protected $end;
168
169
    /**
170
     * @Gedmo\SortablePosition
171
     *
172
     * @ORM\Column(name="position", type="integer")
173
     * @Serializer\Exclude
174
     */
175
    private $position;
176
177
    /**
178
     * @var Project
179
     *
180
     * @Gedmo\SortableGroup
181
     *
182
     * @ORM\ManyToOne(targetEntity="Project")
183
     * @ORM\JoinColumn(name="project_id", referencedColumnName="id", nullable=false, onDelete="cascade")
184
     *
185
     * @Serializer\Exclude
186
     */
187
    private $project;
188
189
    /**
190
     * Constructor.
191
     *
192
     * @param Project $project
193
     */
194
    public function __construct(Project $project)
195
    {
196
        $this->setStart(new DateTime());
197
        $this->setProject($project);
198
    }
199
200
    /**
201
     * Get id.
202
     *
203
     * @return int
204
     */
205
    public function getId(): int
206
    {
207
        return $this->id;
208
    }
209
210
    /**
211
     * Set passed tests count.
212
     *
213
     * @param int $passed Passed tests
214
     *
215
     * @return Campaign
216
     */
217
    public function setpassed(int $passed): self
218
    {
219
        $this->passed = $passed;
220
221
        return $this;
222
    }
223
224
    /**
225
     * Get passed tests count.
226
     *
227
     * @return int
228
     */
229
    public function getPassed(): int
230
    {
231
        return $this->passed;
232
    }
233
234
    /**
235
     * Set failed tests count.
236
     *
237
     * @param int $failed Failed tests
238
     *
239
     * @return Campaign
240
     */
241
    public function setFailed(int $failed): self
242
    {
243
        $this->failed = $failed;
244
245
        return $this;
246
    }
247
248
    /**
249
     * Get failed tests count.
250
     *
251
     * @return int
252
     */
253
    public function getFailed(): int
254
    {
255
        return $this->failed;
256
    }
257
258
    /**
259
     * Set errored tests count.
260
     *
261
     * @param int $errored Errored tests
262
     *
263
     * @return Campaign
264
     */
265
    public function setErrored(int $errored): self
266
    {
267
        $this->errored = $errored;
268
269
        return $this;
270
    }
271
272
    /**
273
     * Get errored tests count.
274
     *
275
     * @return int
276
     */
277
    public function getErrored(): int
278
    {
279
        return $this->errored;
280
    }
281
282
    /**
283
     * Set skipped tests count.
284
     *
285
     * @param int $skipped Skipped tests
286
     *
287
     * @return Campaign
288
     */
289
    public function setSkipped(int $skipped): self
290
    {
291
        $this->skipped = $skipped;
292
293
        return $this;
294
    }
295
296
    /**
297
     * Get skipped tests count.
298
     *
299
     * @return int
300
     */
301
    public function getSkipped(): int
302
    {
303
        return $this->skipped;
304
    }
305
306
    /**
307
     * Set disabled tests count.
308
     *
309
     * @param int $disabled Disabled tests
310
     *
311
     * @return Campaign
312
     */
313
    public function setDisabled(int $disabled): self
314
    {
315
        $this->disabled = $disabled;
316
317
        return $this;
318
    }
319
320
    /**
321
     * Get disabled tests count.
322
     *
323
     * @return int
324
     */
325
    public function getDisabled(): int
326
    {
327
        return $this->disabled;
328
    }
329
330
    /**
331
     * Set status.
332
     *
333
     * @param int $status Status
334
     *
335
     * @return Campaign
336
     */
337
    public function setStatus(int $status): self
338
    {
339
        $this->status = $status;
340
341
        return $this;
342
    }
343
344
    /**
345
     * Get status of campaign.
346
     *
347
     * @return int
348
     */
349
    public function getStatus(): int
350
    {
351
        return $this->status;
352
    }
353
354
    /**
355
     * Set start datetime of campaign.
356
     *
357
     * @param DateTime $datetime start datetime of campaign.
358
     *
359
     * @return Campaign
360
     */
361
    public function setStart(DateTime $datetime): self
362
    {
363
        $this->start = $datetime;
364
365
        return $this;
366
    }
367
368
    /**
369
     * Get start datetime of campaign.
370
     *
371
     * @return DateTime
372
     */
373
    public function getStart(): DateTime
374
    {
375
        return $this->start;
376
    }
377
378
    /**
379
     * Set end datetime of campaign.
380
     *
381
     * @param DateTime $datetime end datetime of campaign.
382
     *
383
     * @return Campaign
384
     */
385
    public function setEnd(DateTime $datetime): self
386
    {
387
        $this->end = $datetime;
388
389
        return $this;
390
    }
391
392
    /**
393
     * Get end datetime of campaign.
394
     *
395
     * @return DateTime
396
     */
397
    public function getEnd(): ?DateTime
398
    {
399
        return $this->end;
400
    }
401
402
    /**
403
     * Set order.
404
     *
405
     * @param int $position The order.
406
     *
407
     * @return Campaign
408
     */
409
    public function setPosition(int $position): self
410
    {
411
        $this->position = $position;
412
413
        return $this;
414
    }
415
416
    /**
417
     * Get position.
418
     *
419
     * @return int
420
     */
421
    public function getPosition(): int
422
    {
423
        return $this->position;
424
    }
425
426
    /**
427
     * Get reference id (Incremental integer).
428
     *
429
     * @return int
430
     *
431
     * @Serializer\VirtualProperty
432
     * @Serializer\SerializedName("refid")
433
     * @Serializer\Type("int")
434
     * @Serializer\Groups({"public", "private"})
435
     */
436
    public function getRefid(): int
437
    {
438
        return $this->position + 1;
439
    }
440
441
    /**
442
     * Set project.
443
     *
444
     * @param Project $project
445
     *
446
     * @return Campaign
447
     */
448
    public function setProject(Project $project): self
449
    {
450
        $this->project = $project;
451
452
        return $this;
453
    }
454
455
    /**
456
     * Get project.
457
     *
458
     * @return Project
459
     */
460
    public function getProject(): Project
461
    {
462
        return $this->project;
463
    }
464
465
    /**
466
     * Get enabled tests.
467
     *
468
     * @return int
469
     */
470
    public function getEnabled(): int
471
    {
472
        return $this->passed
473
            + $this->failed
474
            + $this->errored
475
            + $this->skipped;
476
    }
477
478
    /**
479
     * Get percentage of successful tests.
480
     *
481
     * @return float
482
     */
483
    public function getPercentage(): float
484
    {
485
        if (0 !== $this->getEnabled()) {
486
            return round($this->passed / $this->getEnabled() * 100);
487
        }
488
489
        return 0;
490
    }
491
492
    /**
493
     * Set from DTO campaign.
494
     *
495
     * @param CampaignDTO $dto DTO object
496
     *
497
     * @return Campaign
498
     */
499
    public function setFromDTO(CampaignDTO $dto): self
500
    {
501
        if (null !== $dto->getStart()) {
502
            $this->setStart($dto->getStart());
503
        }
504
        if (null !== $dto->getEnd()) {
505
            $this->setEnd($dto->getEnd());
506
        }
507
508
        return $this;
509
    }
510
}
511