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

PaymentAmountCalculator::getPaymentAmount()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 3
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
}