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

InfiniteEndRange   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 69
Duplicated Lines 100 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 69
loc 69
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A jsonSerialize() 3 3 1
A setStartTime() 3 3 1
A setEndTime() 3 3 1
A __construct() 3 3 1
A __toString() 3 3 1
A compareStartTime() 3 3 1
A getStartTime() 3 3 1
A hasStartTime() 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 DateTimeInterface;
6
7
/**
8
 * Class InfiniteEndRange.
9
 */
10 View Code Duplication
final class InfiniteEndRange 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...
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
37
    {
38 1
        return ['startTime' => $this->startTime->format('c'), 'endTime' => null];
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
61
    {
62 1
        return new InfiniteEndRange($time);
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68 5
    public function setEndTime(DateTimeInterface $time): RangeState
69
    {
70 5
        return new FiniteRange($this->startTime, $time);
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76 1
    public function compareStartTime(DateTimeInterface $time): int
77
    {
78 1
        return $this->startTime->getTimestamp() <=> $time->getTimestamp();
79
    }
80
}
81