Completed
Push — master ( fe7ae6...ea593a )
by claudio
07:25
created
app/Console/Commands/Optimise/Optimise.php 1 patch
Braces   +26 added lines, -18 removed lines patch added patch discarded remove patch
@@ -158,11 +158,12 @@  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) {
162
-            if(!$e->isEmpty())
163
-                \Event::fire(new ErrorEvent($this->company, $e->getMessage()));
161
+        } catch(OptimiseException $e) {
162
+            if(!$e->isEmpty()) {
163
+                            \Event::fire(new ErrorEvent($this->company, $e->getMessage()));
164
+            }
164 165
             throw $e;
165
-        }catch (\Exception $e) {
166
+        } catch (\Exception $e) {
166 167
             //TODO use the correct exceptions to avoid to share private data
167 168
             \Event::fire(new ErrorEvent($this->company, $e->getMessage()));
168 169
             throw new OptimiseException('Optimising error', 0, $e);
@@ -207,8 +208,9 @@  discard block
 block discarded – undo
207 208
     {
208 209
         //since we consider busy timeslots, we need to get all users
209 210
         $users = $this->company->employees->pluck('id')->toArray();
210
-        if(count($users) == 0)
211
-            throw ((new OptimiseException("No users for this company"))->withEmpty(true));
211
+        if(count($users) == 0) {
212
+                    throw ((new OptimiseException("No users for this company"))->withEmpty(true));
213
+        }
212 214
         return $solver->setUsers($users);
213 215
     }
214 216
 
@@ -223,8 +225,9 @@  discard block
 block discarded – undo
223 225
          * @var $meetings \Illuminate\Support\Collection
224 226
          */
225 227
         $meetings = collect($this->company->getMeetingsTimeSlots($this->startTime, $this->endTime));
226
-        if($meetings->count() == 0)
227
-            throw ((new OptimiseException("No meetings for this week"))->withEmpty(true));
228
+        if($meetings->count() == 0) {
229
+                    throw ((new OptimiseException("No meetings for this week"))->withEmpty(true));
230
+        }
228 231
         $timeslots = $meetings->groupBy('id')->map(function ($item) { //convert timeslots
229 232
             return $this->durationConverter($this->timeSlotsConverter($item));
230 233
         });
@@ -314,8 +317,9 @@  discard block
 block discarded – undo
314 317
     static private function fillTimeSlots(array $array, $id, \Illuminate\Support\Collection $timeSlots, $fill = '0')
315 318
     {
316 319
         foreach ($timeSlots as $timeSlot) {
317
-            if (!isset($array[$id]))
318
-                $array[$id] = [];
320
+            if (!isset($array[$id])) {
321
+                            $array[$id] = [];
322
+            }
319 323
             $array[$id] = self::arrayPadInterval($array[$id], $timeSlot->time_start, $timeSlot->time_end, $fill);
320 324
         }
321 325
         return $array;
@@ -330,8 +334,9 @@  discard block
 block discarded – undo
330 334
      */
331 335
     static private function arrayPadInterval(array $array, $from, $to, $pad = '0')
332 336
     {
333
-        for ($i = $from; $i < $to; $i++)
334
-            $array[$i] = $pad;
337
+        for ($i = $from; $i < $to; $i++) {
338
+                    $array[$i] = $pad;
339
+        }
335 340
         return $array;
336 341
     }
337 342
 
@@ -344,8 +349,9 @@  discard block
 block discarded – undo
344 349
     static private function fillRow(array $array, $id, $until, $fill = '0')
345 350
     {
346 351
         for ($i = 1; $i <= $until; $i++) {
347
-            if (!isset($array[$id][$i]))
348
-                $array[$id][$i] = $fill;
352
+            if (!isset($array[$id][$i])) {
353
+                            $array[$id][$i] = $fill;
354
+            }
349 355
         }
350 356
 
351 357
         return $array;
@@ -362,8 +368,9 @@  discard block
 block discarded – undo
362 368
          * @var $users \Illuminate\Support\Collection
363 369
          */
364 370
         $users = collect($this->company->getEmployeesTimeSlots($this->startTime, $this->endTime));
365
-        if($users->count() == 0)
366
-            throw ((new OptimiseException("No users for this company"))->withEmpty(true));
371
+        if($users->count() == 0) {
372
+                    throw ((new OptimiseException("No users for this company"))->withEmpty(true));
373
+        }
367 374
         $timeslots = $users->groupBy('id')->map(function ($item) { //convert timeslots
368 375
             return $this->timeSlotsConverter($item);
369 376
         });
@@ -383,8 +390,9 @@  discard block
 block discarded – undo
383 390
          * @var $usersMeetings \Illuminate\Support\Collection
384 391
          */
385 392
         $usersMeetings = collect($this->company->getUsersMeetings($users, $meetings))->groupBy('employee_id');
386
-        if($usersMeetings->count() == 0)
387
-            throw ((new OptimiseException("No users for any meeting"))->withEmpty(true));
393
+        if($usersMeetings->count() == 0) {
394
+                    throw ((new OptimiseException("No users for any meeting"))->withEmpty(true));
395
+        }
388 396
 
389 397
         return $solver->setUsersMeetings(self::getUsersMeetingsArray($users, $meetings, $usersMeetings));
390 398
     }
Please login to merge, or discard this patch.
app/Console/Commands/Optimise/OptimiseCommand.php 1 patch
Braces   +15 added lines, -11 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,7 +75,7 @@  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
+        } catch(OptimiseException $e) {
78 79
             if ($e->isEmpty()) {
79 80
                 $mex = 'Company ' . $company->id . ' doesn\'t have sufficient data';
80 81
                 $this->warn($mex);
@@ -94,13 +95,15 @@  discard block
 block discarded – undo
94 95
         if ($this->option('background')) {
95 96
             \Log::debug(self::BACKGROUND_MOD_MEX);
96 97
             $this->info(self::BACKGROUND_MOD_MEX);
97
-            foreach ($companies as $company)
98
-                $this->makeBackground($company);
98
+            foreach ($companies as $company) {
99
+                            $this->makeBackground($company);
100
+            }
99 101
             \Log::debug(self::BACKGROUND_COMPLETED_MEX);
100 102
             $this->info(self::BACKGROUND_COMPLETED_MEX);
101
-        } else
102
-            foreach ($companies as $company)
103
+        } else {
104
+                    foreach ($companies as $company)
103 105
                 $this->makeForeground($company);
106
+        }
104 107
     }
105 108
 
106 109
     /**
@@ -110,7 +113,8 @@  discard block
 block discarded – undo
110 113
     private function makeBackground(Company $company)
111 114
     {
112 115
         $event = $this->schedule->command('optimise:meetings ' . $company->id)->withoutOverlapping();
113
-        if ($event->isDue($this->laravel))
114
-            $event->run($this->laravel);
116
+        if ($event->isDue($this->laravel)) {
117
+                    $event->run($this->laravel);
118
+        }
115 119
     }
116 120
 }
Please login to merge, or discard this patch.