Conditions | 13 |
Paths | 79 |
Total Lines | 129 |
Code Lines | 69 |
Lines | 0 |
Ratio | 0 % |
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 |
||
64 | public function recalculate(Invoice $invoice, $overdueDays): bool |
||
65 | { |
||
66 | /** @var Invoice $invoice */ |
||
67 | $loan = $invoice->getLoan(); |
||
68 | |||
69 | if (! $this->checkerService->isCalculationAllowed($invoice, $overdueDays)) { |
||
70 | return false; |
||
71 | } |
||
72 | $disableLoanZeroInterestSetting = $this |
||
73 | ->settingsReader |
||
74 | ->get('financial_services.loan_zero_interest_disable_after_duedays'); |
||
75 | |||
76 | $disableLoanZeroInterest = ($disableLoanZeroInterestSetting > 0 && $overdueDays >= $disableLoanZeroInterestSetting + 1); |
||
77 | |||
78 | if (! $disableLoanZeroInterest) { |
||
79 | return false; |
||
80 | } |
||
81 | |||
82 | $finVersionNum = $loan->getFinancialServiceVersion()->getVersion(); |
||
83 | $loanPaidPrincipal = new MoneyMath($invoice->getLoan()->getPaidPrincipalAmount()); |
||
84 | |||
85 | $loanAmountModel = new LoanAmountModel($loan); |
||
86 | |||
87 | /** @var LoanItem $loanItem */ |
||
88 | foreach ($loan->getLoanItems() as $loanItem) { |
||
89 | if ($loanPaidPrincipal->isGreaterThenOrEqualTo($loanItem->getPrincipalAmount())) { |
||
90 | $loanPaidPrincipal->sub($loanItem->getPrincipalAmount()); |
||
91 | |||
92 | continue; |
||
93 | } |
||
94 | |||
95 | /** @var Application $application */ |
||
96 | $application = $loanItem->getApplication(); |
||
97 | |||
98 | $currentLoanItemPrincipal = new MoneyMath($loanItem->getPrincipalAmount()); |
||
99 | |||
100 | if ($this->checkerService->isPrincipalDecreaseAllowed($loanPaidPrincipal)) { |
||
101 | $currentLoanItemPrincipal->sub($loanPaidPrincipal->getResult()); |
||
102 | $loanPaidPrincipal->zero(); |
||
103 | } |
||
104 | |||
105 | $applicationTypeEnum = ($application->isItemTypeAdditional() |
||
106 | ? ApplicationTypeEnum::ADDITIONAL() |
||
107 | : ApplicationTypeEnum::MAIN()); |
||
108 | |||
109 | // TODO TD lesser evil |
||
110 | $payload = new CalculatorConstructorPayload( |
||
111 | new FinanceServiceModel($application->getServiceTypeEnum(), $finVersionNum), |
||
112 | $currentLoanItemPrincipal->getResult(), |
||
113 | $application->getAppDate(), |
||
114 | $application->getTerm(), // TODO KZ + dueDays |
||
115 | // $term, // TODO KZ + dueDays |
||
116 | /* |
||
117 | * PL 30 |
||
118 | * KZ 30 +1 (daily 30) |
||
119 | */ |
||
120 | $applicationTypeEnum |
||
121 | ); |
||
122 | |||
123 | $payload |
||
124 | ->setIsDiscountEnabled(false) |
||
125 | ->setUseRecalculation(true) |
||
126 | ; |
||
127 | |||
128 | $calcResult = $this->arithmeticResolver->calculate($payload); |
||
129 | |||
130 | // TODO TD lesser evil |
||
131 | if (($invoice->getDueDays() < 0) && 'kz' == getenv('COUNTRY_ENV')) { |
||
132 | $days = (int) NumberTool::add($application->getTerm()->getValue(), abs($invoice->getDueDays())); |
||
133 | if ($days > 60) { |
||
134 | $days = 60; |
||
135 | } |
||
136 | |||
137 | $term = TimePeriod::fromDays($days); |
||
138 | |||
139 | // TODO TD lesser evil |
||
140 | $fakePayload = new CalculatorConstructorPayload( |
||
141 | new FinanceServiceModel($application->getServiceTypeEnum(), $finVersionNum), |
||
142 | $currentUnpaidLoanItemPrincipal->getResult(), |
||
143 | $application->getAppDate(), |
||
144 | $term, // TODO KZ + dueDays |
||
145 | // $application->getTerm(), // TODO KZ + dueDays |
||
146 | /* |
||
147 | * PL 30 |
||
148 | * KZ 30 +1 (daily 30) |
||
149 | */ |
||
150 | $applicationTypeEnum |
||
151 | ); |
||
152 | |||
153 | $fakePayload |
||
154 | ->setIsDiscountEnabled(false) |
||
155 | ->setUseRecalculation(true) |
||
156 | ; |
||
157 | |||
158 | $fakeCalcResult = $this->arithmeticResolver->calculate($fakePayload); |
||
159 | |||
160 | $calcResult->setInterestAmount($fakeCalcResult->getInterestAmount()); |
||
161 | $calcResult->setInterestRate($fakeCalcResult->getInterestRate()); |
||
162 | } |
||
163 | |||
164 | $result = $this->loanItemService->calculate($loanItem, $calcResult, $loanAmountModel); |
||
165 | |||
166 | if (getenv('COUNTRY_ENV')) { |
||
167 | $maxOverall = NumberTool::percent($loan->getPrincipalAmount()->getAmount(), 100); |
||
168 | $overallAmount = NumberTool::addAll( |
||
169 | $result->getServiceFeeAmount()->getAmount(), |
||
170 | $result->getInterestAmount()->getAmount(), |
||
171 | $loan->getRemindersAmount()->getAmount(), |
||
172 | $loan->getFinesAmount()->getAmount() |
||
173 | ); |
||
174 | |||
175 | if (NumberTool::gt($overallAmount, $maxOverall)) { |
||
176 | return false; |
||
177 | } |
||
178 | } |
||
179 | |||
180 | $loanItem |
||
181 | ->setServiceFeeAmount($result->getServiceFeeAmount()) |
||
182 | ->setInterestAmount($result->getInterestAmount()) |
||
183 | ->setTotalRepayableAmount($result->getTotalRepayableAmount()) |
||
184 | ->setPeriodEndRepayableAmount($result->getTotalRepayableAmount()) |
||
185 | ; |
||
186 | } |
||
187 | |||
188 | $invoice->setHasRecalculateInterest(true); |
||
189 | |||
190 | $loan->doUpdateAmountsFromLoanItems(); |
||
191 | |||
192 | return true; |
||
193 | } |
||
195 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths