FiniteState::hasStartDate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Zee\DateRange\States;
4
5
use DateTimeInterface;
6
use Zee\DateRange\DateRangeException;
7
8
/**
9
 * State of the finite range.
10
 */
11
final class FiniteState extends RangeState
12
{
13
    /**
14
     * @var DateTimeInterface
15
     */
16
    private $startDate;
17
18
    /**
19
     * @var DateTimeInterface
20
     */
21
    private $endDate;
22
23
    /**
24
     * @param DateTimeInterface $startDate
25
     * @param DateTimeInterface $endDate
26
     */
27 14
    public function __construct(DateTimeInterface $startDate, DateTimeInterface $endDate)
28
    {
29 14
        if ($endDate <= $startDate) {
30 2
            throw new DateRangeException('Invalid end date, must be after start');
31
        }
32
33 14
        $this->startDate = $startDate;
34 14
        $this->endDate = $endDate;
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40 3
    public function hasStartDate(): bool
41
    {
42 3
        return true;
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48 3
    public function hasEndDate(): bool
49
    {
50 3
        return true;
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56 10
    public function getStartDate(): DateTimeInterface
57
    {
58 10
        return $this->startDate;
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64 10
    public function getEndDate(): DateTimeInterface
65
    {
66 10
        return $this->endDate;
67
    }
68
69
    /**
70
     * {@inheritdoc}
71
     */
72 2
    public function setStartDate(DateTimeInterface $start): RangeState
73
    {
74 2
        return new FiniteState($start, $this->endDate);
75
    }
76
77
    /**
78
     * {@inheritdoc}
79
     */
80 2
    public function setEndDate(DateTimeInterface $end): RangeState
81
    {
82 2
        return new FiniteState($this->startDate, $end);
83
    }
84
}
85