Passed
Pull Request — main (#55)
by Thierry
05:38
created
app/Console/Commands/ConvertPoolProperties.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@
 block discarded – undo
27 27
     /**
28 28
      * Execute the console command.
29 29
      *
30
-      * @return int
30
+     * @return int
31 31
      */
32 32
     public function handle()
33 33
     {
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@
 block discarded – undo
29 29
     public function handle()
30 30
     {
31 31
         $pools = Pool::get();
32
-        foreach($pools as $pool)
32
+        foreach ($pools as $pool)
33 33
         {
34 34
             $currProperties = $pool->properties;
35 35
             $nextProperties = ['deposit' => [], 'remit' => []];
Please login to merge, or discard this patch.
src/Service/Meeting/Saving/ProfitService.php 1 patch
Spacing   +17 added lines, -20 removed lines patch added patch discarded remove patch
@@ -33,12 +33,12 @@  discard block
 block discarded – undo
33 33
      *
34 34
      * @return Builder|Relation
35 35
      */
36
-    private function getFundSessionsQuery(Session $currentSession, int $fundId): Builder|Relation
36
+    private function getFundSessionsQuery(Session $currentSession, int $fundId): Builder | Relation
37 37
     {
38 38
         $lastSessionDate = $currentSession->start_at->format('Y-m-d');
39 39
         // The closing sessions ids
40 40
         $closingSessionIds = array_keys($this->savingService->getFundClosings($fundId));
41
-        if(count($closingSessionIds) === 0)
41
+        if (count($closingSessionIds) === 0)
42 42
         {
43 43
             // No closing session yet
44 44
             return $this->tenantService->tontine()->sessions()
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
             ->whereDate('sessions.start_at', '<', $lastSessionDate)
52 52
             ->orderByDesc('sessions.start_at')
53 53
             ->get();
54
-        if($closingSessions->count() === 0)
54
+        if ($closingSessions->count() === 0)
55 55
         {
56 56
             // All the closing sessions are after the current session.
57 57
             return $this->tenantService->tontine()->sessions()
@@ -119,31 +119,31 @@  discard block
 block discarded – undo
119 119
         int $profitAmount): Collection
120 120
     {
121 121
         // Set savings durations and distributions
122
-        foreach($savings as $saving)
122
+        foreach ($savings as $saving)
123 123
         {
124 124
             $saving->duration = $this->getSavingDuration($sessions, $saving);
125 125
             $saving->distribution = $saving->amount * $saving->duration;
126 126
             $saving->profit = 0;
127 127
         }
128 128
         // Reduce the distributions
129
-        $distributionGcd = (int)$savings->reduce(function($gcd, $saving) {
130
-            if($gcd === 0)
129
+        $distributionGcd = (int) $savings->reduce(function($gcd, $saving) {
130
+            if ($gcd === 0)
131 131
             {
132 132
                 return $saving->distribution;
133 133
             }
134
-            if($saving->duration === 0)
134
+            if ($saving->duration === 0)
135 135
             {
136 136
                 return $gcd;
137 137
             }
138 138
             return gmp_gcd($gcd, $saving->distribution);
139 139
         }, $savings->first()->distribution);
140
-        if($distributionGcd > 0)
140
+        if ($distributionGcd > 0)
141 141
         {
142
-            $sum = (int)($savings->sum('distribution') / $distributionGcd);
143
-            foreach($savings as $saving)
142
+            $sum = (int) ($savings->sum('distribution') / $distributionGcd);
143
+            foreach ($savings as $saving)
144 144
             {
145 145
                 $saving->distribution /= $distributionGcd;
146
-                $saving->profit = (int)($profitAmount * $saving->distribution / $sum);
146
+                $saving->profit = (int) ($profitAmount * $saving->distribution / $sum);
147 147
             }
148 148
         }
149 149
 
@@ -171,9 +171,8 @@  discard block
 block discarded – undo
171 171
             ->orderBy('sessions.start_at', 'asc')
172 172
             ->with(['session', 'member']);
173 173
         $savings = $fundId > 0 ?
174
-            $query->where('savings.fund_id', $fundId)->get() :
175
-            $query->whereNull('savings.fund_id')->get();
176
-        if($savings->count() === 0)
174
+            $query->where('savings.fund_id', $fundId)->get() : $query->whereNull('savings.fund_id')->get();
175
+        if ($savings->count() === 0)
177 176
         {
178 177
             return $savings;
179 178
         }
@@ -193,13 +192,13 @@  discard block
 block discarded – undo
193 192
         // The part value makes sense only iwhen there is more than 2 savings
194 193
         // with distribution greater than 0.
195 194
         $savings = $savings->filter(fn($saving) => $saving->distribution > 0);
196
-        if($savings->count() < 2)
195
+        if ($savings->count() < 2)
197 196
         {
198 197
             return 0;
199 198
         }
200 199
 
201 200
         $saving = $savings->first();
202
-        return (int)($saving->amount * $saving->duration / $saving->distribution);
201
+        return (int) ($saving->amount * $saving->duration / $saving->distribution);
203 202
     }
204 203
 
205 204
     /**
@@ -226,8 +225,7 @@  discard block
 block discarded – undo
226 225
             ->select(DB::raw("sum(amount) as total"))
227 226
             ->whereIn('session_id', $sessionIds);
228 227
         $saving = $fundId > 0 ?
229
-            $query->where('savings.fund_id', $fundId)->first() :
230
-            $query->whereNull('savings.fund_id')->first();
228
+            $query->where('savings.fund_id', $fundId)->first() : $query->whereNull('savings.fund_id')->first();
231 229
         return $saving->total ?? 0;
232 230
     }
233 231
 
@@ -248,8 +246,7 @@  discard block
 block discarded – undo
248 246
             ->where('debts.type', Debt::TYPE_INTEREST)
249 247
             ->whereIn('refunds.session_id', $sessionIds);
250 248
         $refund = $fundId > 0 ?
251
-            $query->where('loans.fund_id', $fundId)->first() :
252
-            $query->whereNull('loans.fund_id')->first();
249
+            $query->where('loans.fund_id', $fundId)->first() : $query->whereNull('loans.fund_id')->first();
253 250
         return $refund->total ?? 0;
254 251
     }
255 252
 
Please login to merge, or discard this patch.
src/Service/Meeting/Pool/AuctionService.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
      *
30 30
      * @return Builder|Relation
31 31
      */
32
-    private function getQuery(Session $session, ?bool $onlyPaid = null): Builder|Relation
32
+    private function getQuery(Session $session, ?bool $onlyPaid = null): Builder | Relation
33 33
     {
34 34
         $sessionId = $session->id;
35 35
         $prevSessions = $this->sessionService->getRoundSessionIds($session, withCurr: false);
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
                         $query->where('session_id', $sessionId);
45 45
                     });
46 46
                 });
47
-                if($prevSessions->count() === 0)
47
+                if ($prevSessions->count() === 0)
48 48
                 {
49 49
                     return;
50 50
                 }
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
     public function toggleAuctionPayment(Session $session, int $auctionId)
114 114
     {
115 115
         $auction = $this->getQuery($session)->find($auctionId);
116
-        if(($auction))
116
+        if (($auction))
117 117
         {
118 118
             $auction->update(['paid' => !$auction->paid]);
119 119
         }
Please login to merge, or discard this patch.
src/Service/Meeting/Pool/PoolService.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@
 block discarded – undo
44 44
      *
45 45
      * @return Builder|Relation
46 46
      */
47
-    private function getQuery(Session $session): Builder|Relation
47
+    private function getQuery(Session $session): Builder | Relation
48 48
     {
49 49
         return Pool::ofSession($session)
50 50
             ->whereHas('subscriptions', function(Builder $query) use($session) {
Please login to merge, or discard this patch.
src/Service/Meeting/Credit/RefundService.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
      *
37 37
      * @return Builder|Relation
38 38
      */
39
-    private function getQuery(Session $session, ?bool $onlyPaid = null): Builder|Relation
39
+    private function getQuery(Session $session, ?bool $onlyPaid = null): Builder | Relation
40 40
     {
41 41
         $sessionId = $session->id;
42 42
         $prevSessions = $this->sessionService->getTontineSessionIds($session, withCurr: false);
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
                         $query->where('session_id', $sessionId);
55 55
                     });
56 56
                 });
57
-                if($prevSessions->count() === 0)
57
+                if ($prevSessions->count() === 0)
58 58
                 {
59 59
                     return;
60 60
                 }
@@ -145,11 +145,11 @@  discard block
 block discarded – undo
145 145
     public function createRefund(Session $session, int $debtId): void
146 146
     {
147 147
         $debt = $this->getDebt($session, $debtId);
148
-        if(!$debt || $debt->refund)
148
+        if (!$debt || $debt->refund)
149 149
         {
150 150
             throw new MessageException(trans('tontine.loan.errors.not_found'));
151 151
         }
152
-        if(!$this->debtCalculator->debtIsEditable($session, $debt))
152
+        if (!$this->debtCalculator->debtIsEditable($session, $debt))
153 153
         {
154 154
             throw new MessageException(trans('meeting.refund.errors.cannot_refund'));
155 155
         }
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
         DB::transaction(function() use($session, $debt, $refund) {
161 161
             $refund->save();
162 162
             // For simple or compound interest, also save the final amount.
163
-            if($debt->is_interest && !$debt->loan->fixed_interest)
163
+            if ($debt->is_interest && !$debt->loan->fixed_interest)
164 164
             {
165 165
                 $debt->amount = $this->debtCalculator->getDebtAmount($session, $debt);
166 166
                 $debt->save();
@@ -180,15 +180,15 @@  discard block
 block discarded – undo
180 180
     {
181 181
         $refund = Refund::with('debt')->where('session_id', $session->id)
182 182
             ->where('debt_id', $debtId)->first();
183
-        if(!$refund)
183
+        if (!$refund)
184 184
         {
185 185
             throw new MessageException(trans('meeting.refund.errors.not_found'));
186 186
         }
187
-        if((!$refund->editable))
187
+        if ((!$refund->editable))
188 188
         {
189 189
             throw new MessageException(trans('meeting.refund.errors.cannot_delete'));
190 190
         }
191
-        if(!$this->debtCalculator->debtIsEditable($session, $refund->debt))
191
+        if (!$this->debtCalculator->debtIsEditable($session, $refund->debt))
192 192
         {
193 193
             throw new MessageException(trans('meeting.refund.errors.cannot_refund'));
194 194
         }
@@ -261,12 +261,12 @@  discard block
 block discarded – undo
261 261
     public function createPartialRefund(Session $session, int $debtId, int $amount): void
262 262
     {
263 263
         $debt = $this->getDebt($session, $debtId);
264
-        if(!$debt || $debt->refund)
264
+        if (!$debt || $debt->refund)
265 265
         {
266 266
             throw new MessageException(trans('meeting.refund.errors.not_found'));
267 267
         }
268 268
         // A partial refund must not totally refund a debt
269
-        if($amount >= $debt->due_amount)
269
+        if ($amount >= $debt->due_amount)
270 270
         {
271 271
             throw new MessageException(trans('meeting.refund.errors.pr_amount'));
272 272
         }
@@ -290,11 +290,11 @@  discard block
 block discarded – undo
290 290
     {
291 291
         $refund = PartialRefund::where('session_id', $session->id)
292 292
             ->with(['debt.refund'])->find($refundId);
293
-        if(!$refund)
293
+        if (!$refund)
294 294
         {
295 295
             throw new MessageException(trans('meeting.refund.errors.not_found'));
296 296
         }
297
-        if($refund->debt->refund !== null || !$refund->editable)
297
+        if ($refund->debt->refund !== null || !$refund->editable)
298 298
         {
299 299
             throw new MessageException(trans('meeting.refund.errors.cannot_delete'));
300 300
         }
Please login to merge, or discard this patch.
src/Service/Meeting/Charge/SettlementTargetService.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@
 block discarded – undo
57 57
      *
58 58
      * @return Builder|Relation
59 59
      */
60
-    private function getMembersQuery(string $search = ''): Builder|Relation
60
+    private function getMembersQuery(string $search = ''): Builder | Relation
61 61
     {
62 62
         return $this->tenantService->tontine()->members()->active()
63 63
             ->when($search !== '', function($query) use($search) {
Please login to merge, or discard this patch.
src/Service/Meeting/Charge/BillService.php 1 patch
Spacing   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
      * @return Builder
35 35
      */
36 36
     private function getBillsQuery(Charge $charge, Session $session,
37
-        string $relation, string $search, ?bool $onlyPaid): Builder|Relation
37
+        string $relation, string $search, ?bool $onlyPaid): Builder | Relation
38 38
     {
39 39
         $relationFilter = function(Builder $query) use($charge, $session, $relation) {
40 40
             $query->where('charge_id', $charge->id)
@@ -90,9 +90,7 @@  discard block
 block discarded – undo
90 90
     private function getBillRelation(Charge $charge): string
91 91
     {
92 92
         // The intermediate relation to reach the member model.
93
-        return $charge->is_variable ? 'libre_bill' :
94
-            ($charge->period_session ? 'session_bill' :
95
-            ($charge->period_round ? 'round_bill' : 'tontine_bill'));
93
+        return $charge->is_variable ? 'libre_bill' : ($charge->period_session ? 'session_bill' : ($charge->period_round ? 'round_bill' : 'tontine_bill'));
96 94
     }
97 95
 
98 96
     /**
@@ -108,8 +106,7 @@  discard block
 block discarded – undo
108 106
         string $search = '', ?bool $onlyPaid = null, int $page = 0): Collection
109 107
     {
110 108
         $billRelation = $this->getBillRelation($charge);
111
-        $billRelations = !$charge->is_variable ? [$billRelation . '.member', 'settlement'] :
112
-            ['libre_bill.session', 'libre_bill.member', 'settlement'];
109
+        $billRelations = !$charge->is_variable ? [$billRelation . '.member', 'settlement'] : ['libre_bill.session', 'libre_bill.member', 'settlement'];
113 110
         $query = $this->getBillsQuery($charge, $session, $billRelation, $search, $onlyPaid);
114 111
 
115 112
         return $query->with($billRelations)
Please login to merge, or discard this patch.
src/Service/Meeting/Charge/LibreFeeService.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
      * @return Builder|Relation
177 177
      */
178 178
     private function getMembersQuery(Charge $charge, Session $session,
179
-        string $search = '', ?bool $filter): Builder|Relation
179
+        string $search = '', ?bool $filter): Builder | Relation
180 180
     {
181 181
         $filterFunction = function($query) use($charge, $session) {
182 182
             $query->where('charge_id', $charge->id)->where('session_id', $session->id);
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
                     $member->libre_bills->first()->bill : null;
222 222
             });
223 223
         // Check if there is a settlement target.
224
-        if(!($target = $this->targetService->getTarget($charge, $session)))
224
+        if (!($target = $this->targetService->getTarget($charge, $session)))
225 225
         {
226 226
             return $members;
227 227
         }
@@ -262,12 +262,12 @@  discard block
 block discarded – undo
262 262
         int $memberId, bool $paid, float $amount = 0): void
263 263
     {
264 264
         $member = $this->tenantService->tontine()->members()->find($memberId);
265
-        if(!$member)
265
+        if (!$member)
266 266
         {
267 267
             throw new MessageException(trans('tontine.member.errors.not_found'));
268 268
         }
269 269
 
270
-        if($amount !== 0)
270
+        if ($amount !== 0)
271 271
         {
272 272
             $amount = $this->localeService->convertMoneyToInt($amount);
273 273
         }
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
             $libreBill->session()->associate($session);
285 285
             $libreBill->bill()->associate($bill);
286 286
             $libreBill->save();
287
-            if($paid)
287
+            if ($paid)
288 288
             {
289 289
                 $settlement = new Settlement();
290 290
                 $settlement->bill()->associate($bill);
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
      */
304 304
     public function getBill(Charge $charge, Session $session, int $memberId): ?LibreBill
305 305
     {
306
-        if(!($member = $this->tenantService->tontine()->members()->find($memberId)))
306
+        if (!($member = $this->tenantService->tontine()->members()->find($memberId)))
307 307
         {
308 308
             throw new MessageException(trans('tontine.member.errors.not_found'));
309 309
         }
@@ -325,7 +325,7 @@  discard block
 block discarded – undo
325 325
      */
326 326
     public function updateBill(Charge $charge, Session $session, int $memberId, float $amount): void
327 327
     {
328
-        if(!($libreBill = $this->getBill($charge, $session, $memberId)))
328
+        if (!($libreBill = $this->getBill($charge, $session, $memberId)))
329 329
         {
330 330
             return; // throw new MessageException(trans('tontine.bill.errors.not_found'));
331 331
         }
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
      */
345 345
     public function deleteBill(Charge $charge, Session $session, int $memberId): void
346 346
     {
347
-        if(!($libreBill = $this->getBill($charge, $session, $memberId)))
347
+        if (!($libreBill = $this->getBill($charge, $session, $memberId)))
348 348
         {
349 349
             return; // throw new MessageException(trans('tontine.bill.errors.not_found'));
350 350
         }
@@ -352,10 +352,10 @@  discard block
 block discarded – undo
352 352
         DB::transaction(function() use($libreBill, $session) {
353 353
             $bill = $libreBill->bill;
354 354
             $libreBill->delete();
355
-            if($bill !== null)
355
+            if ($bill !== null)
356 356
             {
357 357
                 // Delete the settlement only if it is on the same session
358
-                if($bill->settlement !== null && $bill->settlement->session_id === $session->id)
358
+                if ($bill->settlement !== null && $bill->settlement->session_id === $session->id)
359 359
                 {
360 360
                     $bill->settlement->delete();
361 361
                 }
Please login to merge, or discard this patch.
app/Ajax/Web/Meeting/Credit/Loan.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
      */
74 74
     public function addLoan()
75 75
     {
76
-        if($this->session->closed)
76
+        if ($this->session->closed)
77 77
         {
78 78
             $this->notify->warning(trans('meeting.warnings.session.closed'));
79 79
             return $this->response;
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
             'title' => trans('common.actions.cancel'),
92 92
             'class' => 'btn btn-tertiary',
93 93
             'click' => 'close',
94
-        ],[
94
+        ], [
95 95
             'title' => trans('common.actions.save'),
96 96
             'class' => 'btn btn-primary',
97 97
             'click' => $this->rq()->createLoan(pm()->form('loan-form')),
@@ -108,14 +108,14 @@  discard block
 block discarded – undo
108 108
      */
109 109
     public function createLoan(array $formValues)
110 110
     {
111
-        if($this->session->closed)
111
+        if ($this->session->closed)
112 112
         {
113 113
             $this->notify->warning(trans('meeting.warnings.session.closed'));
114 114
             return $this->response;
115 115
         }
116 116
 
117 117
         $values = $this->validator->validateItem($formValues);
118
-        if(!($member = $this->memberService->getMember($values['member'])))
118
+        if (!($member = $this->memberService->getMember($values['member'])))
119 119
         {
120 120
             $this->notify->warning(trans('tontine.member.errors.not_found'));
121 121
             return $this->response;
@@ -133,19 +133,19 @@  discard block
 block discarded – undo
133 133
      */
134 134
     public function editLoan(int $loanId)
135 135
     {
136
-        if($this->session->closed)
136
+        if ($this->session->closed)
137 137
         {
138 138
             $this->notify->warning(trans('meeting.warnings.session.closed'));
139 139
             return $this->response;
140 140
         }
141 141
         $loan = $this->loanService->getSessionLoan($this->session, $loanId);
142
-        if(!$loan)
142
+        if (!$loan)
143 143
         {
144 144
             $this->notify->warning(trans('meeting.loan.errors.not_found'));
145 145
             return $this->response;
146 146
         }
147 147
         // A refunded loan cannot be updated.
148
-        if($loan->refunds_count > 0)
148
+        if ($loan->refunds_count > 0)
149 149
         {
150 150
             $this->notify->warning(trans('meeting.loan.errors.update'));
151 151
             return $this->response;
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
             'title' => trans('common.actions.cancel'),
163 163
             'class' => 'btn btn-tertiary',
164 164
             'click' => 'close',
165
-        ],[
165
+        ], [
166 166
             'title' => trans('common.actions.save'),
167 167
             'class' => 'btn btn-primary',
168 168
             'click' => $this->rq()->updateLoan($loanId, pm()->form('loan-form')),
@@ -179,26 +179,26 @@  discard block
 block discarded – undo
179 179
      */
180 180
     public function updateLoan(int $loanId, array $formValues)
181 181
     {
182
-        if($this->session->closed)
182
+        if ($this->session->closed)
183 183
         {
184 184
             $this->notify->warning(trans('meeting.warnings.session.closed'));
185 185
             return $this->response;
186 186
         }
187 187
         $loan = $this->loanService->getSessionLoan($this->session, $loanId);
188
-        if(!$loan)
188
+        if (!$loan)
189 189
         {
190 190
             $this->notify->warning(trans('meeting.loan.errors.not_found'));
191 191
             return $this->response;
192 192
         }
193 193
         // A refunded loan cannot be updated.
194
-        if($loan->refunds_count > 0)
194
+        if ($loan->refunds_count > 0)
195 195
         {
196 196
             $this->notify->warning(trans('meeting.loan.errors.update'));
197 197
             return $this->response;
198 198
         }
199 199
 
200 200
         $values = $this->validator->validateItem($formValues);
201
-        if(!($member = $this->memberService->getMember($values['member'])))
201
+        if (!($member = $this->memberService->getMember($values['member'])))
202 202
         {
203 203
             $this->notify->warning(trans('tontine.member.errors.not_found'));
204 204
             return $this->response;
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
      */
217 217
     public function deleteLoan(int $loanId)
218 218
     {
219
-        if($this->session->closed)
219
+        if ($this->session->closed)
220 220
         {
221 221
             $this->notify->warning(trans('meeting.warnings.session.closed'));
222 222
             return $this->response;
Please login to merge, or discard this patch.