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

InfiniteStartRange   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 101
Duplicated Lines 100 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 101
loc 101
ccs 24
cts 24
cp 1
rs 10
c 0
b 0
f 0
wmc 12

12 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 3 3 1
A getEndTime() 3 3 1
A __construct() 3 3 1
A hasEndTime() 3 3 1
A isEndAt() 3 3 1
A isEnded() 3 3 1
A getStartTime() 3 3 1
A setStartTime() 3 3 1
A hasStartTime() 3 3 1
A setEndTime() 3 3 1
A isStarted() 3 3 1
A jsonSerialize() 3 3 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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