Passed
Push — master ( 817bfa...9a0237 )
by Kauri
02:53
created

Period::getSequenceNo()   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
     * @var int
28
     */
29
    private $sequenceNo;
30
31
    /**
32
     * Period constructor.
33
     * @param \DateTimeInterface $start
34
     * @param \DateTimeInterface $end
35
     */
36 3
    public function __construct(\DateTimeInterface $start, \DateTimeInterface $end)
37
    {
38 3
        $this->start = $start;
39 3
        $this->end = $end;
40 3
        $this->length = self::calculatePeriodLength($start, $end);
41 3
    }
42
43
    /**
44
     * @return int
45
     */
46 3
    public function getLength(): int
47
    {
48 3
        return $this->length;
49
    }
50
51
    /**
52
     * @return \DateTimeInterface
53
     */
54 3
    public function getEnd(): \DateTimeInterface
55
    {
56 3
        return $this->end;
57
    }
58
59 3
    public function getStart(): \DateTimeInterface
60
    {
61 3
        return $this->start;
62
    }
63
64
    /**
65
     * @param $sequenceNo
66
     * @return bool|int
67
     */
68 7
    public function setSequenceNo(int $sequenceNo)
69
    {
70 7
        if (is_null($this->sequenceNo)) {
71 7
            $this->sequenceNo = $sequenceNo;
72
        }
73
74 7
        return $this->sequenceNo;
75
    }
76
77
    /**
78
     * @return int
79
     */
80 7
    public function getSequenceNo(): int
81
    {
82 7
        return (int) $this->sequenceNo;
83
    }
84
85
    /**
86
     * @param \DateTimeInterface $periodStart
87
     * @param \DateTimeInterface $periodEnd
88
     * @return int
89
     */
90 3
    private static function calculatePeriodLength(\DateTimeInterface $periodStart, \DateTimeInterface $periodEnd): int
91
    {
92 3
        $diff = (int) $periodEnd->diff($periodStart)->days + 1;
93 3
        return $diff;
94
    }
95
96
}
97