Days::getNewStartDate()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
namespace CL\DateUtils;
4
5
use DateTime;
6
7
/**
8
 * @author    Ivan Kerin <[email protected]>
9
 * @copyright 2015, Clippings Ltd.
10
 * @license   http://spdx.org/licenses/BSD-3-Clause
11
 */
12
class Days
13
{
14
    /**
15
     * @var integer
16
     */
17
    private $days;
18
19
    /**
20
     * @param integer $days
21
     */
22 3
    public function __construct($days)
23
    {
24 3
        $this->days = (int) $days;
25 3
    }
26
27
    /**
28
     * @return integer
29
     */
30 3
    public function getDays()
31
    {
32 3
        return $this->days;
33
    }
34
35
    /**
36
     * @param  Days $days
37
     * @return self
38
     */
39 1
    public function add(Days $days)
40
    {
41 1
        $this->days = $this->days + $days->days;
42
43 1
        return $this;
44
    }
45
46
    /**
47
     * @param  DateTime|null $start
48
     * @return DateTime
49
     */
50 2
    public function getNewStartDate(DateTime $start = null)
51
    {
52 2
        return $start ? clone $start : new DateTime('now');
53
    }
54
55
    /**
56
     * @param  DateTime|null $start
57
     * @return DateTime
58
     */
59 2
    public function toDateTime(DateTime $start = null)
60
    {
61 2
        return $this->getNewStartDate($start)->modify("+ {$this->days} days");
62
    }
63
64
    /**
65
     * @return string
66
     */
67 3
    public function humanize()
68
    {
69 3
        return "{$this->days} days";
70
    }
71
}
72