FiniteState   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 72
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0
wmc 8

7 Methods

Rating   Name   Duplication   Size   Complexity  
A hasStartDate() 0 3 1
A getStartDate() 0 3 1
A hasEndDate() 0 3 1
A setEndDate() 0 3 1
A setStartDate() 0 3 1
A getEndDate() 0 3 1
A __construct() 0 8 2
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