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

InfiniteEndRange::isStartAt()   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 InfiniteEndRange.
11
 */
12 View Code Duplication
final class InfiniteEndRange 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 $startTime;
18
19
    /**
20
     * @param DateTimeInterface $startTime
21
     */
22 7
    public function __construct(DateTimeInterface $startTime)
23
    {
24 7
        $this->startTime = $startTime;
25
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30 1
    public function __toString(): string
31
    {
32 1
        return sprintf('%s/-', $this->startTime->format('c'));
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 1
    public function jsonSerialize(): array
39
    {
40 1
        return ['startTime' => $this->startTime->format('c'), 'endTime' => null];
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 1
    public function hasStartTime(): bool
47
    {
48 1
        return true;
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54 1
    public function hasEndTime(): bool
55
    {
56 1
        return false;
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62 2
    public function getStartTime(): DateTimeInterface
63
    {
64 2
        return $this->startTime;
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70 1
    public function getEndTime(): DateTimeInterface
71
    {
72 1
        throw new DateRangeException('Date range is undefined');
73
    }
74
75
    /**
76
     * {@inheritdoc}
77
     */
78 1
    public function setStartTime(DateTimeInterface $time): RangeState
79
    {
80 1
        return new InfiniteEndRange($time);
81
    }
82
83
    /**
84
     * {@inheritdoc}
85
     */
86 5
    public function setEndTime(DateTimeInterface $time): RangeState
87
    {
88 5
        return new FiniteRange($this->startTime, $time);
89
    }
90
91
    /**
92
     * {@inheritdoc}
93
     */
94 1
    public function isStartAt(DateTimeInterface $time): bool
95
    {
96 1
        return $this->startTime->getTimestamp() === $time->getTimestamp();
97
    }
98
99
    /**
100
     * {@inheritdoc}
101
     */
102 1
    public function isStarted(): bool
103
    {
104 1
        return $this->startTime <= new DateTimeImmutable();
105
    }
106
}
107