Total Complexity | 8 |
Total Lines | 69 |
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 |
||
10 | View Code Duplication | final class InfiniteEndRange extends UndefinedRange |
|
|
|||
11 | { |
||
12 | /** |
||
13 | * @var DateTimeInterface |
||
14 | */ |
||
15 | private $startTime; |
||
16 | |||
17 | /** |
||
18 | * @param DateTimeInterface $startTime |
||
19 | */ |
||
20 | 7 | public function __construct(DateTimeInterface $startTime) |
|
21 | { |
||
22 | 7 | $this->startTime = $startTime; |
|
23 | } |
||
24 | |||
25 | /** |
||
26 | * {@inheritdoc} |
||
27 | */ |
||
28 | 1 | public function __toString(): string |
|
29 | { |
||
30 | 1 | return sprintf('%s/-', $this->startTime->format('c')); |
|
31 | } |
||
32 | |||
33 | /** |
||
34 | * {@inheritdoc} |
||
35 | */ |
||
36 | 1 | public function jsonSerialize(): array |
|
39 | } |
||
40 | |||
41 | /** |
||
42 | * {@inheritdoc} |
||
43 | */ |
||
44 | 1 | public function hasStartTime(): bool |
|
45 | { |
||
46 | 1 | return true; |
|
47 | } |
||
48 | |||
49 | /** |
||
50 | * {@inheritdoc} |
||
51 | */ |
||
52 | 2 | public function getStartTime(): DateTimeInterface |
|
53 | { |
||
54 | 2 | return $this->startTime; |
|
55 | } |
||
56 | |||
57 | /** |
||
58 | * {@inheritdoc} |
||
59 | */ |
||
60 | 1 | public function setStartTime(DateTimeInterface $time): RangeState |
|
63 | } |
||
64 | |||
65 | /** |
||
66 | * {@inheritdoc} |
||
67 | */ |
||
68 | 5 | public function setEndTime(DateTimeInterface $time): RangeState |
|
71 | } |
||
72 | |||
73 | /** |
||
74 | * {@inheritdoc} |
||
75 | */ |
||
76 | 1 | public function compareStartTime(DateTimeInterface $time): int |
|
79 | } |
||
80 | } |
||
81 |
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.