PaymentPeriods::getPeriods()   A
last analyzed

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 PaymentPeriods
9
 * @package Kauri\Loan
10
 */
11
class PaymentPeriods implements PaymentPeriodsInterface
12
{
13
    /**
14
     * @var array
15
     */
16
    private $periods = array();
17
    /**
18
     * @var int
19
     */
20
    private $averagePeriodLenght;
21
22
    /**
23
     * PaymentPeriods constructor.
24
     * @param int $averagePeriodLength
25
     */
26 5
    public function __construct(int $averagePeriodLength)
27
    {
28 5
        $this->averagePeriodLenght = $averagePeriodLength;
29 5
    }
30
31
    /**
32
     * @param PeriodInterface $period
33
     * @param int|null $sequenceNo
34
     */
35 5
    public function add(PeriodInterface $period, int $sequenceNo = null): void
36
    {
37 5
        if (is_null($sequenceNo)) {
38 2
            $sequenceNo = $this->getNoOfPeriods() + 1;
39
        }
40
41 5
        $period->setSequenceNo($sequenceNo);
42 5
        $this->periods[$sequenceNo] = $period;
43 5
    }
44
45 3
    public function getAvgPeriodLength(): float
46
    {
47 3
        return $this->averagePeriodLenght;
48
    }
49
50
    /**
51
     * @return array
52
     */
53 5
    public function getPeriods(): array
54
    {
55 5
        return $this->periods;
56
    }
57
58
    /**
59
     * @return int
60
     */
61 2
    public function getNoOfPeriods(): int
62
    {
63 2
        return count($this->periods);
64
    }
65
}
66