RangeState::formatStartDate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Zee\DateRange\States;
4
5
use DateTimeInterface;
6
7
/**
8
 * Date range abstract state.
9
 */
10
abstract class RangeState
11
{
12
    /**
13
     * @return bool
14
     */
15 3
    public function hasStartDate(): bool
16
    {
17 3
        return false;
18
    }
19
20
    /**
21
     * @return bool
22
     */
23 1
    public function hasEndDate(): bool
24
    {
25 1
        return false;
26
    }
27
28
    /**
29
     * @return DateTimeInterface
30
     */
31
    abstract public function getStartDate(): DateTimeInterface;
32
33
    /**
34
     * @return DateTimeInterface
35
     */
36
    abstract public function getEndDate(): DateTimeInterface;
37
38
    /**
39
     * @param DateTimeInterface $start
40
     *
41
     * @return RangeState
42
     */
43
    abstract public function setStartDate(DateTimeInterface $start): RangeState;
44
45
    /**
46
     * @param DateTimeInterface $end
47
     *
48
     * @return RangeState
49
     */
50
    abstract public function setEndDate(DateTimeInterface $end): RangeState;
51
52
    /**
53
     * Compares start date with specific date.
54
     *
55
     * Returns 0 if dates are equals, negative if start date is less than given date,
56
     * and positive if start date is greater.
57
     *
58
     * @param DateTimeInterface $date
59
     *
60
     * @return int
61
     */
62 5
    public function compareStartDate(DateTimeInterface $date): int
63
    {
64 5
        return $this->getStartDate()->getTimestamp() <=> $date->getTimestamp();
65
    }
66
67
    /**
68
     * Compares end date with specific date.
69
     *
70
     * Returns 0 if dates are equals, negative if end date is less than given date
71
     * and positive if end date is greater.
72
     *
73
     * @param DateTimeInterface $date
74
     *
75
     * @return int
76
     */
77 6
    public function compareEndDate(DateTimeInterface $date): int
78
    {
79 6
        return $this->getEndDate()->getTimestamp() <=> $date->getTimestamp();
80
    }
81
82
    /**
83
     * @param string $format
84
     *
85
     * @return null|string
86
     */
87 4
    public function formatStartDate(string $format = 'c'): ?string
88
    {
89 4
        return $this->getStartDate()->format($format);
90
    }
91
92
    /**
93
     * @param string $format
94
     *
95
     * @return null|string
96
     */
97 4
    public function formatEndDate(string $format = 'c'): ?string
98
    {
99 4
        return $this->getEndDate()->format($format);
100
    }
101
}
102