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

InfiniteEndRange   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 93
Duplicated Lines 100 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 93
loc 93
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0
wmc 11

11 Methods

Rating   Name   Duplication   Size   Complexity  
A hasEndTime() 3 3 1
A jsonSerialize() 3 3 1
A setStartTime() 3 3 1
A setEndTime() 3 3 1
A __construct() 3 3 1
A isStarted() 3 3 1
A __toString() 3 3 1
A isStartAt() 3 3 1
A getEndTime() 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 DateTimeImmutable;
6
use DateTimeInterface;
7
use Zee\DateRange\DateRangeException;
8
9
/**
10
 * Class InfiniteEndRange.
11
 */
12 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...
13
{
14
    /**
15
     * @var DateTimeInterface
16
     */
17
    private $startTime;
18
19
    /**
20
     * @param DateTimeInterface $startTime
21
     */
22 7
    public function __construct(DateTimeInterface $startTime)
23
    {
24 7
        $this->startTime = $startTime;
25
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30 1
    public function __toString(): string
31
    {
32 1
        return sprintf('%s/-', $this->startTime->format('c'));
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 1
    public function jsonSerialize(): array
39
    {
40 1
        return ['startTime' => $this->startTime->format('c'), 'endTime' => null];
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 1
    public function hasStartTime(): bool
47
    {
48 1
        return true;
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54 1
    public function hasEndTime(): bool
55
    {
56 1
        return false;
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62 2
    public function getStartTime(): DateTimeInterface
63
    {
64 2
        return $this->startTime;
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70 1
    public function getEndTime(): DateTimeInterface
71
    {
72 1
        throw new DateRangeException('Date range is undefined');
73
    }
74
75
    /**
76
     * {@inheritdoc}
77
     */
78 1
    public function setStartTime(DateTimeInterface $time): RangeState
79
    {
80 1
        return new InfiniteEndRange($time);
81
    }
82
83
    /**
84
     * {@inheritdoc}
85
     */
86 5
    public function setEndTime(DateTimeInterface $time): RangeState
87
    {
88 5
        return new FiniteRange($this->startTime, $time);
89
    }
90
91
    /**
92
     * {@inheritdoc}
93
     */
94 1
    public function isStartAt(DateTimeInterface $time): bool
95
    {
96 1
        return $this->startTime->getTimestamp() === $time->getTimestamp();
97
    }
98
99
    /**
100
     * {@inheritdoc}
101
     */
102 1
    public function isStarted(): bool
103
    {
104 1
        return $this->startTime <= new DateTimeImmutable();
105
    }
106
}
107