| Conditions | 3 |
| Paths | 3 |
| Total Lines | 63 |
| Code Lines | 31 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 23 |
| CRAP Score | 3 |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 40 | 4 | public function calculatePayments( |
|
| 41 | PaymentPeriodsInterface $paymentPeriods, |
||
| 42 | float $amountOfPrincipal, |
||
| 43 | float $yearlyInterestRate, |
||
| 44 | int $calculationMode, |
||
| 45 | float $futureValue |
||
| 46 | ): array { |
||
| 47 | 4 | $payments = array(); |
|
| 48 | |||
| 49 | 4 | $periodLengths = $this->getPeriodLengths($paymentPeriods, $calculationMode); |
|
| 50 | 4 | $paymentAmounts = $this->paymentAmountCalculator->getPaymentAmounts($periodLengths, $amountOfPrincipal, |
|
| 51 | 4 | $yearlyInterestRate, 0); |
|
| 52 | |||
| 53 | 4 | $principalLeft = $amountOfPrincipal; |
|
| 54 | |||
| 55 | 4 | foreach ($paymentPeriods->getPeriods() as $period) { |
|
| 56 | /** |
||
| 57 | * Get payment amount |
||
| 58 | */ |
||
| 59 | 4 | $paymentAmount = round($paymentAmounts[$period->getSequenceNo()], 2); |
|
| 60 | |||
| 61 | /** |
||
| 62 | * Get interest rate for period |
||
| 63 | */ |
||
| 64 | 4 | $ratePerPeriod = $this->interestAmountCalculator->getPeriodInterestRate($yearlyInterestRate, |
|
|
1 ignored issue
–
show
|
|||
| 65 | 4 | $period->getLength($calculationMode)); |
|
| 66 | |||
| 67 | /** |
||
| 68 | * Calculate interest part |
||
| 69 | */ |
||
| 70 | 4 | $interest = round($this->interestAmountCalculator->getInterestAmount($principalLeft, $ratePerPeriod), 2); |
|
| 71 | |||
| 72 | /** |
||
| 73 | * Calculate principal part |
||
| 74 | */ |
||
| 75 | 4 | if ($period->getSequenceNo() < $paymentPeriods->getNoOfPeriods()) { |
|
| 76 | 4 | $principal = $paymentAmount - $interest; |
|
| 77 | } else { |
||
| 78 | 4 | $principal = $principalLeft; |
|
| 79 | } |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Calculate balance left |
||
| 83 | */ |
||
| 84 | 4 | $principalLeft = $principalLeft - $principal; |
|
| 85 | |||
| 86 | /** |
||
| 87 | * Compose payment data |
||
| 88 | */ |
||
| 89 | $paymentData = array( |
||
| 90 | 4 | 'sequence_no' => $period->getSequenceNo(), |
|
| 91 | 4 | 'payment' => $interest + $principal, |
|
| 92 | 4 | 'principal' => $principal, |
|
| 93 | 4 | 'interest' => $interest, |
|
| 94 | 4 | 'principal_left' => $principalLeft, |
|
| 95 | 4 | 'period' => $period |
|
| 96 | ); |
||
| 97 | |||
| 98 | 4 | $payments[$period->getSequenceNo()] = $paymentData; |
|
| 99 | } |
||
| 100 | |||
| 101 | 4 | return $payments; |
|
| 102 | } |
||
| 103 | |||
| 121 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.