Passed
Push — master ( b66789...fff5ae )
by Kauri
54s
created

PaymentAmountCalculator   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 11 2
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Kauri\Loan;
6
7
8
class PaymentAmountCalculator implements PaymentAmountCalculatorInterface
9
{
10
    /**
11
     * @see http://www.financeformulas.net/Annuity_Payment_Formula.html
12
     * @param float $presentValue
13
     * @param float $ratePerPeriod
14
     * @param float $numberOfPeriods
15
     * @return float
16
     */
17 6
    public function getPaymentAmount(float $presentValue, float $ratePerPeriod, float $numberOfPeriods): float
18
    {
19 6
        if ($ratePerPeriod > 0) {
20 3
            $payment = (($ratePerPeriod / 100) * $presentValue) / (1 - pow(1 + ($ratePerPeriod / 100),
21 3
                        -$numberOfPeriods));
22
        } else {
23 3
            $payment = $presentValue / $numberOfPeriods;
24
        }
25
26 6
        return $payment;
27
    }
28
}
29