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

StartDateCriterion   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 34
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 34
loc 34
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A toArray() 4 4 1
A checkCollisionWithCriteria() 11 11 4
A getValue() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 StartDateCriterion 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 $startDate;
14
15 3
    public function __construct(DateTime $startDate)
16
    {
17 3
        $this->startDate = $startDate;
18 3
    }
19
20 1
    public function toArray(): array
21
    {
22 1
        return ['filter[createdAt-start]' => $this->startDate->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 EndDateCriterion) {
29 1
                if ($criterion->getValue() < $this->startDate) {
30 1
                    throw InvalidQueryException::criteriaCollision('End date must be later than start date');
31
                }
32
            }
33
        }
34 2
        return;
35
    }
36
37 2
    public function getValue(): DateTime
38
    {
39 2
        return $this->startDate;
40
    }
41
}
42