Completed
Push — master ( ab9fdb...7d2071 )
by Veaceslav
02:00
created

FiniteRange   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
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 __construct() 0 8 2
A setStartDate() 0 3 1
A getEndDate() 0 3 1
A getStartDate() 0 3 1
A setEndDate() 0 3 1
A hasStartDate() 0 3 1
A hasEndDate() 0 3 1
1
<?php
2
3
namespace Zee\DateRange\States;
4
5
use DateTimeInterface;
6
use Zee\DateRange\DateRangeException;
7
8
/**
9
 * Class FiniteRange.
10
 */
11
final class FiniteRange 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 9
    public function __construct(DateTimeInterface $startDate, DateTimeInterface $endDate)
28
    {
29 9
        if ($endDate <= $startDate) {
30 2
            throw new DateRangeException('Invalid end date, must be after start');
31
        }
32
33 7
        $this->startDate = $startDate;
34 7
        $this->endDate = $endDate;
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40 2
    public function hasStartDate(): bool
41
    {
42 2
        return true;
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48 2
    public function hasEndDate(): bool
49
    {
50 2
        return true;
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56 7
    public function getStartDate(): DateTimeInterface
57
    {
58 7
        return $this->startDate;
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64 7
    public function getEndDate(): DateTimeInterface
65
    {
66 7
        return $this->endDate;
67
    }
68
69
    /**
70
     * {@inheritdoc}
71
     */
72 1
    public function setStartDate(DateTimeInterface $start): RangeState
73
    {
74 1
        return new FiniteRange($start, $this->endDate);
75
    }
76
77
    /**
78
     * {@inheritdoc}
79
     */
80 1
    public function setEndDate(DateTimeInterface $end): RangeState
81
    {
82 1
        return new FiniteRange($this->startDate, $end);
83
    }
84
}
85