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

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