Passed
Pull Request — master (#4)
by Kauri
08:37
created

getPaymentAmount()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 3
crap 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