Passed
Push — master ( 07d32f...817bfa )
by Kauri
03:00
created

Period::getStart()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

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
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Kauri\Loan;
6
7
/**
8
 * Class Period
9
 * @package Kauri\Loan
10
 */
11
class Period implements PeriodInterface
12
{
13
    /**
14
     * @var \DateTimeInterface
15
     */
16
    private $start;
17
    /**
18
     * @var \DateTimeInterface
19
     */
20
    private $end;
21
    /**
22
     * @var int
23
     */
24
    private $length;
25
26
    /**
27
     * Period constructor.
28
     * @param \DateTimeInterface $start
29
     * @param \DateTimeInterface $end
30
     */
31 3
    public function __construct(\DateTimeInterface $start, \DateTimeInterface $end)
32
    {
33 3
        $this->start = $start;
34 3
        $this->end = $end;
35 3
        $this->length = self::calculatePeriodLength($start, $end);
36 3
    }
37
38
    /**
39
     * @return int
40
     */
41 3
    public function getLength(): int
42
    {
43 3
        return $this->length;
44
    }
45
46
    /**
47
     * @return \DateTimeInterface
48
     */
49 3
    public function getEnd(): \DateTimeInterface
50
    {
51 3
        return $this->end;
52
    }
53
54 3
    public function getStart(): \DateTimeInterface
55
    {
56 3
        return $this->start;
57
    }
58
59
    /**
60
     * @param \DateTimeInterface $periodStart
61
     * @param \DateTimeInterface $periodEnd
62
     * @return int
63
     */
64 3
    private static function calculatePeriodLength(\DateTimeInterface $periodStart, \DateTimeInterface $periodEnd): int
65
    {
66 3
        $diff = (int) $periodEnd->diff($periodStart)->days + 1;
67 3
        return $diff;
68
    }
69
70
}
71