Passed
Push — main ( 339e0e...566c5c )
by Thierry
09:09 queued 03:32
created
src/Service/Meeting/Credit/DebtCalculator.php 1 patch
Spacing   +15 added lines, -18 removed lines patch added patch discarded remove patch
@@ -61,10 +61,10 @@  discard block
 block discarded – undo
61 61
     private function getRefundFilter(Session $current, bool $withCurrent): Closure
62 62
     {
63 63
         return $withCurrent ?
64
-            function(PartialRefund|Refund $refund) use($current) {
64
+            function(PartialRefund | Refund $refund) use($current) {
65 65
                 return $refund->session->start_at <= $current->start_at;
66 66
             } :
67
-            function(PartialRefund|Refund $refund) use($current) {
67
+            function(PartialRefund | Refund $refund) use($current) {
68 68
                 return $refund->session->start_at < $current->start_at;
69 69
             };
70 70
     }
@@ -122,10 +122,10 @@  discard block
 block discarded – undo
122 122
         // Take refunds before the end session and sort by session date.
123 123
         $partialRefunds = $this->getPartialRefunds($principalDebt, $endSession, false)
124 124
             ->sortBy('session.start_at');
125
-        foreach($partialRefunds as $refund)
125
+        foreach ($partialRefunds as $refund)
126 126
         {
127 127
             $sessionCount = $this->getSessionCount($startSession, $refund->session);
128
-            $interestAmount += (int)($loanAmount * $interestRate * $sessionCount);
128
+            $interestAmount += (int) ($loanAmount * $interestRate * $sessionCount);
129 129
             // For the next loop
130 130
             $loanAmount -= $refund->amount;
131 131
             $startSession = $refund->session;
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
         $lastSession = $this->getLastSession($principalDebt, $endSession);
135 135
         $sessionCount = $this->getSessionCount($startSession, $lastSession);
136 136
 
137
-        return $interestAmount + (int)($loanAmount * $interestRate * $sessionCount);
137
+        return $interestAmount + (int) ($loanAmount * $interestRate * $sessionCount);
138 138
     }
139 139
 
140 140
     /**
@@ -159,10 +159,10 @@  discard block
 block discarded – undo
159 159
         // Take refunds before the current session and sort by session date.
160 160
         $partialRefunds = $this->getPartialRefunds($principalDebt, $endSession, false)
161 161
             ->sortBy('session.start_at');
162
-        foreach($partialRefunds as $refund)
162
+        foreach ($partialRefunds as $refund)
163 163
         {
164 164
             $sessionCount = $this->getSessionCount($startSession, $refund->session);
165
-            $interestAmount += (int)($loanAmount * (pow(1 + $interestRate, $sessionCount) - 1));
165
+            $interestAmount += (int) ($loanAmount * (pow(1 + $interestRate, $sessionCount) - 1));
166 166
             // For the next loop
167 167
             $loanAmount -= $refund->amount - $interestAmount;
168 168
             $startSession = $refund->session;
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
         $lastSession = $this->getLastSession($principalDebt, $endSession);
172 172
         $sessionCount = $this->getSessionCount($startSession, $lastSession);
173 173
 
174
-        return $interestAmount + (int)($loanAmount * (pow(1 + $interestRate, $sessionCount) - 1));
174
+        return $interestAmount + (int) ($loanAmount * (pow(1 + $interestRate, $sessionCount) - 1));
175 175
     }
176 176
 
177 177
     /**
@@ -184,14 +184,13 @@  discard block
 block discarded – undo
184 184
      */
185 185
     public function getDebtAmount(Debt $debt, Session $session): int
186 186
     {
187
-        if($debt->is_principal || $debt->refund || $debt->loan->fixed_interest)
187
+        if ($debt->is_principal || $debt->refund || $debt->loan->fixed_interest)
188 188
         {
189 189
             return $debt->amount;
190 190
         }
191 191
 
192 192
         return $debt->loan->simple_interest ?
193
-            $this->getSimpleInterestAmount($debt, $session) :
194
-            $this->getCompoundInterestAmount($debt, $session);
193
+            $this->getSimpleInterestAmount($debt, $session) : $this->getCompoundInterestAmount($debt, $session);
195 194
     }
196 195
 
197 196
     /**
@@ -204,8 +203,7 @@  discard block
 block discarded – undo
204 203
      */
205 204
     public function getDebtPaidAmount(Debt $debt, Session $session): int
206 205
     {
207
-        return $debt->refund !== null ? $debt->amount :
208
-            $this->getPartialRefunds($debt, $session, true)->sum('amount');
206
+        return $debt->refund !== null ? $debt->amount : $this->getPartialRefunds($debt, $session, true)->sum('amount');
209 207
     }
210 208
 
211 209
     /**
@@ -248,11 +246,11 @@  discard block
 block discarded – undo
248 246
      */
249 247
     public function getDebtPayableAmount(Debt $debt, Session $session): int
250 248
     {
251
-        if($debt->refund !== null)
249
+        if ($debt->refund !== null)
252 250
         {
253 251
             return 0;
254 252
         }
255
-        if($debt->is_principal || $debt->loan->fixed_interest)
253
+        if ($debt->is_principal || $debt->loan->fixed_interest)
256 254
         {
257 255
             return $debt->amount - $debt->partial_refunds()->sum('amount');
258 256
         }
@@ -261,8 +259,7 @@  discard block
 block discarded – undo
261 259
         // must take into account the partial refunds after the current session.
262 260
         $lastPartialRefund = $this->getLastPartialRefund($debt, $session);
263 261
         return $lastPartialRefund === null ?
264
-            $this->getDebtDueAmount($debt, $session, true) :
265
-            min($this->getDebtDueAmount($debt, $session, true),
262
+            $this->getDebtDueAmount($debt, $session, true) : min($this->getDebtDueAmount($debt, $session, true),
266 263
                 $this->getDebtDueAmount($debt, $lastPartialRefund->session, true));
267 264
     }
268 265
 
@@ -278,7 +275,7 @@  discard block
 block discarded – undo
278 275
     public function getDebtDueAmount(Debt $debt, Session $session, bool $withCurrent): int
279 276
     {
280 277
         $refundFilter = $this->getRefundFilter($session, $withCurrent);
281
-        if($debt->refund !== null && $refundFilter($debt->refund))
278
+        if ($debt->refund !== null && $refundFilter($debt->refund))
282 279
         {
283 280
             return 0; // The debt was refunded before the current session.
284 281
         }
Please login to merge, or discard this patch.