Completed
Push — master ( af3bdc...8a0335 )
by Veaceslav
01:57
created

InfiniteStartRange::jsonSerialize()   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 0
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 DateTimeInterface;
6
use Zee\DateRange\DateRangeException;
7
8
/**
9
 * Class InfiniteStartRange.
10
 */
11 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...
12
{
13
    /**
14
     * @var DateTimeInterface
15
     */
16
    private $endTime;
17
18
    /**
19
     * @param DateTimeInterface $endTime
20
     */
21 3
    public function __construct(DateTimeInterface $endTime)
22
    {
23 3
        $this->endTime = $endTime;
24
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29 1
    public function __toString(): string
30
    {
31 1
        return sprintf('-/%s', $this->endTime->format('c'));
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37 1
    public function jsonSerialize(): array
38
    {
39 1
        return ['startTime' => null, 'endTime' => $this->endTime->format('c')];
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45 1
    public function hasEndTime(): bool
46
    {
47 1
        return true;
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53 2
    public function getEndTime(): DateTimeInterface
54
    {
55 2
        return $this->endTime;
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61 1
    public function setStartTime(DateTimeInterface $time): RangeState
62
    {
63 1
        return new FiniteRange($time, $this->endTime);
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69 1
    public function setEndTime(DateTimeInterface $time): RangeState
70
    {
71 1
        return new InfiniteStartRange($time);
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77 1
    public function compareEndTime(DateTimeInterface $time): int
78
    {
79 1
        return $this->endTime->getTimestamp() <=> $time->getTimestamp();
80
    }
81
}
82