PaymentPeriods   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 55
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A add() 0 9 2
A getAvgPeriodLength() 0 4 1
A getPeriods() 0 4 1
A getNoOfPeriods() 0 4 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