Passed
Pull Request — master (#4)
by Kauri
02:33
created

EqualPrincipalPaymentAmountCalculator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A getPaymentAmount() 0 12 2
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Kauri\Loan\PaymentAmountCalculator;
6
7
use Kauri\Loan\PaymentAmountCalculatorInterface;
8
9
class EqualPrincipalPaymentAmountCalculator implements PaymentAmountCalculatorInterface
10
{
11
    /**
12
     * @param float $presentValue
13
     * @param float $ratePerPeriod
14
     * @param float $numberOfPeriods
15
     * @return float
16
     */
17 5
    public function getPaymentAmount(float $presentValue, float $ratePerPeriod, float $numberOfPeriods): float
18
    {
19 5
        $principal = $presentValue / $numberOfPeriods;
20
21 5
        if ($ratePerPeriod > 0) {
22 3
            $payment = $principal + $presentValue * ($ratePerPeriod / 100);
23
        } else {
24 2
            $payment = $principal;
25
        }
26
27 5
        return $payment;
28
    }
29
}
30