Completed
Push — master ( 35fe2c...cfa2d2 )
by Veaceslav
03:15
created

InfiniteStartRange::setStartTime()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 3
Ratio 100 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 3
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 DateTimeImmutable;
6
use DateTimeInterface;
7
use Zee\DateRange\DateRangeException;
8
9
/**
10
 * Class InfiniteStartRange.
11
 */
12 View Code Duplication
final class InfiniteStartRange extends UndefinedRange
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...
13
{
14
    /**
15
     * @var DateTimeInterface
16
     */
17
    private $endTime;
18
19
    /**
20
     * @param DateTimeInterface $endTime
21
     */
22 3
    public function __construct(DateTimeInterface $endTime)
23
    {
24 3
        $this->endTime = $endTime;
25
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30 1
    public function __toString(): string
31
    {
32 1
        return sprintf('-/%s', $this->endTime->format('c'));
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 1
    public function jsonSerialize(): array
39
    {
40 1
        return ['startTime' => null, 'endTime' => $this->endTime->format('c')];
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 1
    public function hasStartTime(): bool
47
    {
48 1
        return false;
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54 1
    public function hasEndTime(): bool
55
    {
56 1
        return true;
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62 1
    public function getStartTime(): DateTimeInterface
63
    {
64 1
        throw new DateRangeException('Date range is undefined');
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70 2
    public function getEndTime(): DateTimeInterface
71
    {
72 2
        return $this->endTime;
73
    }
74
75
    /**
76
     * {@inheritdoc}
77
     */
78 1
    public function setStartTime(DateTimeInterface $time): RangeState
79
    {
80 1
        return new FiniteRange($time, $this->endTime);
81
    }
82
83
    /**
84
     * {@inheritdoc}
85
     */
86 1
    public function setEndTime(DateTimeInterface $time): RangeState
87
    {
88 1
        return new InfiniteStartRange($time);
89
    }
90
91
    /**
92
     * {@inheritdoc}
93
     */
94 1
    public function isEndAt(DateTimeInterface $time): bool
95
    {
96 1
        return $this->endTime->getTimestamp() === $time->getTimestamp();
97
    }
98
99
    /**
100
     * {@inheritdoc}
101
     */
102 1
    public function isStarted(): bool
103
    {
104 1
        return true;
105
    }
106
107
    /**
108
     * {@inheritdoc}
109
     */
110 1
    public function isEnded(): bool
111
    {
112 1
        return $this->endTime <= new DateTimeImmutable();
113
    }
114
}
115