Completed
Push — master ( 345229...b82efc )
by Peter
01:52
created

EndDateCriterion::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 4
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace PtrTn\Battlerite\Query\Criterion;
4
5
use DateTime;
6
use PtrTn\Battlerite\Exception\InvalidQueryException;
7
8 View Code Duplication
class EndDateCriterion implements CriterionInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
9
{
10
    /**
11
     * @var DateTime
12
     */
13
    private $endDate;
14
15 3
    public function __construct(DateTime $endDate)
16
    {
17 3
        $this->endDate = $endDate;
18 3
    }
19
20 1
    public function toArray(): array
21
    {
22 1
        return ['filter[createdAt-end]' => $this->endDate->format(DateTime::ISO8601)];
23
    }
24
25 3
    public function checkCollisionWithCriteria(array $critera): void
26
    {
27 3
        foreach ($critera as $criterion) {
28 2
            if ($criterion instanceof StartDateCriterion) {
29 2
                if ($this->endDate < $criterion->getValue()) {
30 1
                    throw InvalidQueryException::criteriaCollision('End date must be later than start date');
31
                }
32
            }
33
        }
34 2
        return;
35
    }
36
37 1
    public function getValue(): DateTime
38
    {
39 1
        return $this->endDate;
40
    }
41
}
42