Code Duplication    Length = 71-71 lines in 2 locations

src/States/InfiniteEndRange.php 1 location

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

src/States/InfiniteStartRange.php 1 location

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