Completed
Push — master ( 18ebf0...848848 )
by claudio
08:43
created
app/Console/Commands/Optimise/Optimise.php 1 patch
Braces   +23 added lines, -16 removed lines patch added patch discarded remove patch
@@ -158,9 +158,9 @@  discard block
 block discarded – undo
158 158
             $solver = $this->setData($solver);
159 159
             $solver = $solver->solve();
160 160
             $this->solver = $solver;
161
-        }catch(OptimiseException $e) {
161
+        } catch(OptimiseException $e) {
162 162
             throw $e;
163
-        }catch (\Exception $e) {
163
+        } catch (\Exception $e) {
164 164
             \Event::fire(new ErrorEvent($this->company, $e->getMessage()));
165 165
             throw new OptimiseException('Optimising error', 0, $e);
166 166
             //TODO catch specif exception
@@ -204,8 +204,9 @@  discard block
 block discarded – undo
204 204
     {
205 205
         //since we consider busy timeslots, we need to get all users
206 206
         $users = $this->company->employees->pluck('id')->toArray();
207
-        if(count($users) == 0)
208
-            throw ((new OptimiseException("No users for this company"))->withEmpty(true));
207
+        if(count($users) == 0) {
208
+                    throw ((new OptimiseException("No users for this company"))->withEmpty(true));
209
+        }
209 210
         return $solver->setUsers($users);
210 211
     }
211 212
 
@@ -220,8 +221,9 @@  discard block
 block discarded – undo
220 221
          * @var $meetings \Illuminate\Support\Collection
221 222
          */
222 223
         $meetings = collect($this->company->getMeetingsTimeSlots($this->startTime, $this->endTime));
223
-        if($meetings->count() == 0)
224
-            throw ((new OptimiseException("No meetings for this week"))->withEmpty(true));
224
+        if($meetings->count() == 0) {
225
+                    throw ((new OptimiseException("No meetings for this week"))->withEmpty(true));
226
+        }
225 227
         $timeslots = $meetings->groupBy('id')->map(function ($item) { //convert timeslots
226 228
             return $this->durationConverter($this->timeSlotsConverter($item));
227 229
         });
@@ -311,8 +313,9 @@  discard block
 block discarded – undo
311 313
     static private function fillTimeSlots(array $array, $id, \Illuminate\Support\Collection $timeSlots, $fill = '0')
312 314
     {
313 315
         foreach ($timeSlots as $timeSlot) {
314
-            if (!isset($array[$id]))
315
-                $array[$id] = [];
316
+            if (!isset($array[$id])) {
317
+                            $array[$id] = [];
318
+            }
316 319
             $array[$id] = self::arrayPadInterval($array[$id], $timeSlot->time_start, $timeSlot->time_end, $fill);
317 320
         }
318 321
         return $array;
@@ -327,8 +330,9 @@  discard block
 block discarded – undo
327 330
      */
328 331
     static private function arrayPadInterval(array $array, $from, $to, $pad = '0')
329 332
     {
330
-        for ($i = $from; $i < $to; $i++)
331
-            $array[$i] = $pad;
333
+        for ($i = $from; $i < $to; $i++) {
334
+                    $array[$i] = $pad;
335
+        }
332 336
         return $array;
333 337
     }
334 338
 
@@ -341,8 +345,9 @@  discard block
 block discarded – undo
341 345
     static private function fillRow(array $array, $id, $until, $fill = '0')
342 346
     {
343 347
         for ($i = 1; $i <= $until; $i++) {
344
-            if (!isset($array[$id][$i]))
345
-                $array[$id][$i] = $fill;
348
+            if (!isset($array[$id][$i])) {
349
+                            $array[$id][$i] = $fill;
350
+            }
346 351
         }
347 352
 
348 353
         return $array;
@@ -359,8 +364,9 @@  discard block
 block discarded – undo
359 364
          * @var $users \Illuminate\Support\Collection
360 365
          */
361 366
         $users = collect($this->company->getEmployeesTimeSlots($this->startTime, $this->endTime));
362
-        if($users->count() == 0)
363
-            throw ((new OptimiseException("No users for this company"))->withEmpty(true));
367
+        if($users->count() == 0) {
368
+                    throw ((new OptimiseException("No users for this company"))->withEmpty(true));
369
+        }
364 370
         $timeslots = $users->groupBy('id')->map(function ($item) { //convert timeslots
365 371
             return $this->timeSlotsConverter($item);
366 372
         });
@@ -380,8 +386,9 @@  discard block
 block discarded – undo
380 386
          * @var $usersMeetings \Illuminate\Support\Collection
381 387
          */
382 388
         $usersMeetings = collect($this->company->getUsersMeetings($users, $meetings))->groupBy('employee_id');
383
-        if($usersMeetings->count() == 0)
384
-            throw ((new OptimiseException("No users for any meeting"))->withEmpty(true));
389
+        if($usersMeetings->count() == 0) {
390
+                    throw ((new OptimiseException("No users for any meeting"))->withEmpty(true));
391
+        }
385 392
 
386 393
         return $solver->setUsersMeetings(self::getUsersMeetingsArray($users, $meetings, $usersMeetings));
387 394
     }
Please login to merge, or discard this patch.
app/Console/Commands/Optimise/OptimiseCommand.php 1 patch
Braces   +21 added lines, -16 removed lines patch added patch discarded remove patch
@@ -58,10 +58,11 @@  discard block
 block discarded – undo
58 58
         //TODO insert a timeout
59 59
         //TODO try...catch with destruct
60 60
         $companyId = $this->argument('companyId');
61
-        if (is_numeric($companyId))
62
-            $this->makeForeground(Company::findOrFail($companyId));
63
-        else
64
-            $this->syncAll();
61
+        if (is_numeric($companyId)) {
62
+                    $this->makeForeground(Company::findOrFail($companyId));
63
+        } else {
64
+                    $this->syncAll();
65
+        }
65 66
     }
66 67
 
67 68
     /**
@@ -74,12 +75,13 @@  discard block
 block discarded – undo
74 75
         try {
75 76
             (new Optimise($company, $this->schedule, $this->laravel))->optimise()->save();
76 77
             $this->info('Optimisation ' . $company->id . ' completed');
77
-        }catch(OptimiseException $e){
78
-            if($e->isEmpty())
79
-                $this->warn('Company ' . $company->id . ' has no sufficient data');
80
-            else
81
-                $this->error('Error during optimisation of company ' . $company->id .': '. $e->getMessage());
82
-        }catch(\Exception $e) {
78
+        } catch(OptimiseException $e){
79
+            if($e->isEmpty()) {
80
+                            $this->warn('Company ' . $company->id . ' has no sufficient data');
81
+            } else {
82
+                            $this->error('Error during optimisation of company ' . $company->id .': '. $e->getMessage());
83
+            }
84
+        } catch(\Exception $e) {
83 85
             $this->error('Error during optimisation of company ' . $company->id .': '. $e->getMessage());
84 86
         }
85 87
     }
@@ -90,13 +92,15 @@  discard block
 block discarded – undo
90 92
         if ($this->option('background')) {
91 93
             \Log::debug(self::BACKGROUND_MOD_MEX);
92 94
             $this->info(self::BACKGROUND_MOD_MEX);
93
-            foreach ($companies as $company)
94
-                $this->makeBackground($company);
95
+            foreach ($companies as $company) {
96
+                            $this->makeBackground($company);
97
+            }
95 98
             \Log::debug(self::BACKGROUND_COMPLETED_MEX);
96 99
             $this->info(self::BACKGROUND_COMPLETED_MEX);
97
-        } else
98
-            foreach ($companies as $company)
100
+        } else {
101
+                    foreach ($companies as $company)
99 102
                 $this->makeForeground($company);
103
+        }
100 104
     }
101 105
 
102 106
     /**
@@ -106,7 +110,8 @@  discard block
 block discarded – undo
106 110
     private function makeBackground(Company $company)
107 111
     {
108 112
         $event = $this->schedule->command('optimise:meetings ' . $company->id)->withoutOverlapping();
109
-        if ($event->isDue($this->laravel))
110
-            $event->run($this->laravel);
113
+        if ($event->isDue($this->laravel)) {
114
+                    $event->run($this->laravel);
115
+        }
111 116
     }
112 117
 }
Please login to merge, or discard this patch.