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

Period   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 60
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getLength() 0 4 1
A getEnd() 0 4 1
A calculatePeriodLength() 0 5 1
A getStart() 0 4 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