Conditions | 3 |
Paths | 4 |
Total Lines | 29 |
Code Lines | 19 |
Lines | 0 |
Ratio | 0 % |
Tests | 4 |
CRAP Score | 3 |
Changes | 0 |
1 | <?php |
||
22 | 5 | public function getPaymentAmounts( |
|
23 | 5 | array $periods, |
|
24 | float $presentValue, |
||
25 | 4 | float $interestRate, |
|
26 | float $futureValue = 0.0 |
||
27 | ): array { |
||
28 | 9 | $paymentAmounts = array(); |
|
29 | |||
30 | $discountFactor = 0; |
||
31 | $futureValueDenominator = 1; |
||
32 | |||
33 | foreach ($periods as $sequenceNo => $periodsLength) { |
||
34 | $partialDiscountFactor = pow(1 + ($interestRate / 360 / 100 * $periodsLength), |
||
35 | -$sequenceNo); |
||
36 | |||
37 | $discountFactor = $discountFactor + $partialDiscountFactor; |
||
38 | |||
39 | $partialFutureValueDenominator = 1 + ($interestRate / 360 / 100 * $periodsLength); |
||
40 | $futureValueDenominator = $futureValueDenominator * $partialFutureValueDenominator; |
||
41 | } |
||
42 | |||
43 | $paymentAmount = ($presentValue - ($futureValue / $futureValueDenominator)) / $discountFactor; |
||
44 | |||
45 | foreach ($periods as $sequenceNo => $periodsLength) { |
||
46 | $paymentAmounts[$sequenceNo] = $paymentAmount; |
||
47 | } |
||
48 | |||
49 | return $paymentAmounts; |
||
50 | } |
||
51 | |||
53 |