Total Complexity | 12 |
Total Lines | 101 |
Duplicated Lines | 100 % |
Coverage | 100% |
Changes | 0 |
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 |
||
12 | View Code Duplication | final class InfiniteStartRange extends UndefinedRange |
|
|
|||
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 |
|
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 |
|
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 |
|
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 |
|
113 | } |
||
114 | } |
||
115 |
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.