Test Setup Failed
Push — master ( d5239f...dc6834 )
by Albert
02:37 queued 54s
created

DateRange::cloneDate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace DateRanger;
4
5
use Countable;
6
use DateInterval;
7
use DatePeriod;
8
use DateTime;
9
use DateTimeImmutable;
10
use Iterator;
11
12
abstract class DateRange implements Iterator, Countable
13
{
14
    /** @var DateTime */
15
    protected $start;
16 14
    /** @var DateTime */
17
    protected $end;
18 14
    /** @var array */
19
    protected $dates = [];
20
21 12
    public function start(): DateTimeImmutable
22
    {
23 12
        return $this->start;
24
    }
25
26 3
    public function end(): DateTimeImmutable
27
    {
28 3
        return $this->end;
29
    }
30
31 9
    public function getPeriod($interval = 'P1D', DateTimeImmutable $start = null, DateTimeImmutable $end = null): DatePeriod
32
    {
33 9
        if (null === $start) {
34 9
            $start = $this->start;
35 9
        }
36 9
37
        if (null === $end) {
38 9
            $end = $this->end;
39 9
        }
40 9
41 9
        return new DatePeriod($start, new DateInterval($interval), $end);
42
    }
43 9
44
    public function equals(self $period): bool
45
    {
46 2
        return $this->start()->format('YmdHis') === $period->start()->format('YmdHis') && $this->end()->format('YmdHis') === $period->end()->format('YmdHis');
47
    }
48 2
49
    public function overlaps(self $period): bool
50
    {
51 1
        return $this->start() <= $period->end() && $this->end() >= $period->start();
52
    }
53 1
54
    public function isCurrent(): bool
55
    {
56 1
        $period = new static();
57
58 1
        return $this->equals($period);
59
    }
60 1
61
    public function current()
62
    {
63 3
        return current($this->dates);
64
    }
65 3
66
    public function next()
67
    {
68 3
        next($this->dates);
69
    }
70 3
71 3
    public function key()
72
    {
73 3
        return key($this->dates);
74
    }
75 3
76
    public function valid()
77
    {
78 3
        return current($this->dates);
79
    }
80 3
81
    public function rewind()
82
    {
83 3
        reset($this->dates);
84
    }
85 3
86 3
    public function count()
87
    {
88 1
        return count($this->dates);
89
    }
90
}
91