Passed
Push — master ( f22158...709c4a )
by Kauri
31s
created

PaymentAmountCalculator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 0
dl 0
loc 21
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
    public function getPaymentAmount(float $presentValue, float $ratePerPeriod, float $numberOfPeriods): float
18
    {
19
        if ($ratePerPeriod > 0) {
20
            $payment = (($ratePerPeriod / 100) * $presentValue) / (1 - pow(1 + ($ratePerPeriod / 100),
21
                        -$numberOfPeriods));
22
        } else {
23
            $payment = $presentValue / $numberOfPeriods;
24
        }
25
26
        return $payment;
27
    }
28
}