Completed
Pull Request — master (#48)
by claudio
05:21
created
app/Meeting.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -46,14 +46,14 @@
 block discarded – undo
46 46
      *
47 47
      * @var array
48 48
      */
49
-    protected $fillable = ['title', 'description', 'duration'];
49
+    protected $fillable = [ 'title', 'description', 'duration' ];
50 50
 
51 51
     /**
52 52
      * The attributes excluded from the model's JSON form.
53 53
      *
54 54
      * @var array
55 55
      */
56
-    protected $hidden = ['pivot'];
56
+    protected $hidden = [ 'pivot' ];
57 57
 
58 58
 
59 59
     /**
Please login to merge, or discard this patch.
app/Listeners/Caldav/OkListener.php 1 patch
Unused Use Statements   -2 removed lines patch added patch discarded remove patch
@@ -3,8 +3,6 @@
 block discarded – undo
3 3
 namespace plunner\Listeners;
4 4
 
5 5
 use plunner\Events\CaldavErrorEvent;
6
-use Illuminate\Queue\InteractsWithQueue;
7
-use Illuminate\Contracts\Queue\ShouldQueue;
8 6
 
9 7
 class CaldavErrorListener
10 8
 {
Please login to merge, or discard this patch.
app/Events/Caldav/OkEvent.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -39,6 +39,6 @@
 block discarded – undo
39 39
      */
40 40
     public function broadcastOn()
41 41
     {
42
-        return [];
42
+        return [ ];
43 43
     }
44 44
 }
Please login to merge, or discard this patch.
app/Console/Commands/Optimise/Optimise.php 5 patches
Unused Use Statements   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -9,8 +9,8 @@
 block discarded – undo
9 9
 namespace plunner\Console\Commands\Optimise;
10 10
 
11 11
 use Illuminate\Console\Scheduling\Schedule;
12
-use plunner\company;
13 12
 use plunner\Events\Optimise\ErrorEvent;
13
+use plunner\company;
14 14
 
15 15
 /**
16 16
  * Class Optimise
Please login to merge, or discard this patch.
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -1,10 +1,10 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * Created by PhpStorm.
4
- * User: claudio
5
- * Date: 12/12/15
6
- * Time: 15.41
7
- */
3
+     * Created by PhpStorm.
4
+     * User: claudio
5
+     * Date: 12/12/15
6
+     * Time: 15.41
7
+     */
8 8
 
9 9
 namespace plunner\Console\Commands\Optimise;
10 10
 
@@ -45,8 +45,8 @@  discard block
 block discarded – undo
45 45
     private $company;
46 46
 
47 47
     /**
48
-    * @var Schedule laravel schedule object needed to perform command in background
49
-    */
48
+     * @var Schedule laravel schedule object needed to perform command in background
49
+     */
50 50
     private $schedule;
51 51
 
52 52
     /**
@@ -413,7 +413,7 @@  discard block
 block discarded – undo
413 413
         $diff = explode(':',$diff->format('%R:%d:%h:%i:%s'));
414 414
         $diff = $diff[1]*86400 + $diff[2]*3600 + $diff[3]*60 + $diff[4];
415 415
         //if($diff[0] != '-' && $diff != 0)
416
-          //  throw new OptimiseException('timeslot time <= startTime');
416
+            //  throw new OptimiseException('timeslot time <= startTime');
417 417
         //TODO fix check
418 418
         //TODO check if diff makes sense
419 419
         //TODO check upper limit
Please login to merge, or discard this patch.
Braces   +12 added lines, -9 removed lines patch added patch discarded remove patch
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
             $solver = $this->setData($solver);
157 157
             $solver = $solver->solve();
158 158
             $this->solver = $solver;
159
-        }catch(\Exception $e)
159
+        } catch(\Exception $e)
160 160
         {
161 161
             \Event::fire(new ErrorEvent($this->company, $e->getMessage()));
162 162
             throw new OptimiseException('Optimising error', 0, $e);
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
         try {
181 181
             $this->saveMeetings($this->solver);
182 182
             $this->saveEmployeesMeetings($this->solver);
183
-        }catch(\Exception $e)
183
+        } catch(\Exception $e)
184 184
         {
185 185
             \Event::fire(new ErrorEvent($this->company, $e->getMessage()));
186 186
             throw new OptimiseException('Optimising error', 0, $e);
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
             foreach($meetings as $meeting){
328 328
                 if($usersMeetingsTmp->contains('meeting_id', $meeting)){
329 329
                     $ret[$user][$meeting] = 1;
330
-                }else{
330
+                } else{
331 331
                     $ret[$user][$meeting] = 0;
332 332
                 }
333 333
             }
@@ -373,8 +373,9 @@  discard block
 block discarded – undo
373 373
     static private function fillTimeSlots(array $array, $id, \Illuminate\Support\Collection $timeSlots, $fill = '0')
374 374
     {
375 375
         foreach($timeSlots as $timeSlot) {
376
-            if(!isset($array[$id]))
377
-                $array[$id] = [];
376
+            if(!isset($array[$id])) {
377
+                            $array[$id] = [];
378
+            }
378 379
             $array[$id] = self::arrayPadInterval($array[$id], $timeSlot->time_start, $timeSlot->time_end, $fill);
379 380
         }
380 381
         return $array;
@@ -389,8 +390,9 @@  discard block
 block discarded – undo
389 390
     static private function fillRow(array $array, $id, $until, $fill = '0')
390 391
     {
391 392
         for($i = 1; $i <= $until; $i++){
392
-            if(!isset($array[$id][$i]))
393
-                $array[$id][$i] = $fill;
393
+            if(!isset($array[$id][$i])) {
394
+                            $array[$id][$i] = $fill;
395
+            }
394 396
         }
395 397
 
396 398
         return $array;
@@ -405,8 +407,9 @@  discard block
 block discarded – undo
405 407
      */
406 408
     static private function arrayPadInterval(array $array, $from, $to, $pad = '0')
407 409
     {
408
-        for($i = $from; $i<$to; $i++)
409
-            $array[$i] = $pad;
410
+        for($i = $from; $i<$to; $i++) {
411
+                    $array[$i] = $pad;
412
+        }
410 413
         return $array;
411 414
     }
412 415
 
Please login to merge, or discard this patch.
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
     //TODo max timeslots can be an environment var
25 25
     const TIME_SLOT_DURATION = 900; //seconds -> 15 minutes
26 26
     const DEFAULT_MAX_TIME_SLOTS = 20; //max duration of a meeting in term of timeslots //20
27
-    const DEFAULT_TIME_SLOTS = 672;  //total amount of timeslots that must be optimised -> one week 4*24*7 = 672
27
+    const DEFAULT_TIME_SLOTS = 672; //total amount of timeslots that must be optimised -> one week 4*24*7 = 672
28 28
 
29 29
     private $max_time_slots = self::DEFAULT_MAX_TIME_SLOTS;
30 30
     private $time_slots = self::DEFAULT_TIME_SLOTS;
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
     {
86 86
         $this->startTime = clone $startTime;
87 87
         $this->endTime = clone $this->startTime;
88
-        $this->endTime->add(new \DateInterval('PT'.(($this->max_time_slots+$this->time_slots)*self::TIME_SLOT_DURATION).'S'));
88
+        $this->endTime->add(new \DateInterval('PT'.(($this->max_time_slots + $this->time_slots) * self::TIME_SLOT_DURATION).'S'));
89 89
     }
90 90
 
91 91
     /**
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
             $solver = $this->setData($solver);
157 157
             $solver = $solver->solve();
158 158
             $this->solver = $solver;
159
-        }catch(\Exception $e)
159
+        } catch (\Exception $e)
160 160
         {
161 161
             \Event::fire(new ErrorEvent($this->company, $e->getMessage()));
162 162
             throw new OptimiseException('Optimising error', 0, $e);
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
      */
171 171
     public function save()
172 172
     {
173
-        if(!($this->solver instanceof Solver)) {
173
+        if (!($this->solver instanceof Solver)) {
174 174
             \Event::fire(new ErrorEvent($this->company, 'solver is not an instace of Solver'));
175 175
             throw new OptimiseException('solver is not an instance of Solver');
176 176
             return;
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
         try {
181 181
             $this->saveMeetings($this->solver);
182 182
             $this->saveEmployeesMeetings($this->solver);
183
-        }catch(\Exception $e)
183
+        } catch (\Exception $e)
184 184
         {
185 185
             \Event::fire(new ErrorEvent($this->company, $e->getMessage()));
186 186
             throw new OptimiseException('Optimising error', 0, $e);
@@ -197,8 +197,8 @@  discard block
 block discarded – undo
197 197
     private function saveMeetings(Solver $solver)
198 198
     {
199 199
         $meetings = $solver->getYResults();
200
-        foreach($meetings as $id=>$meeting){
201
-            $meetingO = \plunner\Meeting::findOrFail($id);//TODO catch error
200
+        foreach ($meetings as $id=>$meeting) {
201
+            $meetingO = \plunner\Meeting::findOrFail($id); //TODO catch error
202 202
             $meetingO->start_time = $this->toDateTime(array_search('1', $meeting));
203 203
             $meetingO->save();
204 204
         }
@@ -210,11 +210,11 @@  discard block
 block discarded – undo
210 210
     private function saveEmployeesMeetings(Solver $solver)
211 211
     {
212 212
         $employeesMeetings = $solver->getXResults();
213
-        foreach($employeesMeetings as $eId =>$employeeMeetings)
213
+        foreach ($employeesMeetings as $eId =>$employeeMeetings)
214 214
         {
215 215
             $employee = \plunner\Employee::findOrFail($eId);
216 216
             $employeeMeetings = collect($employeeMeetings);
217
-            $employeeMeetings = $employeeMeetings->filter(function ($item) {
217
+            $employeeMeetings = $employeeMeetings->filter(function($item) {
218 218
                 return $item == 1;
219 219
             });
220 220
             $employee->meetings()->attach($employeeMeetings->keys()->toArray());
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
                 return $this->durationConverter($this->timeSlotsConverter($item));
273 273
             });
274 274
         return $solver->setMeetings($timeslots->keys()->toArray())
275
-            ->setMeetingsDuration($meetings->pluck('duration','id')->toArray())
275
+            ->setMeetingsDuration($meetings->pluck('duration', 'id')->toArray())
276 276
             ->setMeetingsAvailability(self::getAvailabilityArray($timeslots, $this->time_slots));
277 277
     }
278 278
 
@@ -318,15 +318,15 @@  discard block
 block discarded – undo
318 318
      */
319 319
     static private function getUsersMeetingsArray($users, $meetings, \Illuminate\Support\Collection $usersMeetings)
320 320
     {
321
-        $ret = [];
322
-        foreach($users as $user)
321
+        $ret = [ ];
322
+        foreach ($users as $user)
323 323
         {
324 324
             $usersMeetingsTmp = $usersMeetings->get($user);
325
-            foreach($meetings as $meeting){
326
-                if($usersMeetingsTmp->contains('meeting_id', $meeting)){
327
-                    $ret[$user][$meeting] = 1;
328
-                }else{
329
-                    $ret[$user][$meeting] = 0;
325
+            foreach ($meetings as $meeting) {
326
+                if ($usersMeetingsTmp->contains('meeting_id', $meeting)) {
327
+                    $ret[ $user ][ $meeting ] = 1;
328
+                } else {
329
+                    $ret[ $user ][ $meeting ] = 0;
330 330
                 }
331 331
             }
332 332
         }
@@ -340,7 +340,7 @@  discard block
 block discarded – undo
340 340
      */
341 341
     private function durationConverter($item)
342 342
     {
343
-        return $item->each(function($item2){
343
+        return $item->each(function($item2) {
344 344
             $item2->duration = $this->convertDuration((int) $item2->duration);
345 345
             return $item2;
346 346
             //TODO try catch
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
      */
354 354
     private function timeSlotsConverter($item)
355 355
     {
356
-        return $item->each(function($item2){
356
+        return $item->each(function($item2) {
357 357
             $item2->time_start = $this->toTimeSlot($item2->time_start);
358 358
             $item2->time_end = $this->toTimeSlot($item2->time_end);
359 359
             return $item2;
@@ -366,13 +366,13 @@  discard block
 block discarded – undo
366 366
      * @param bool|true $free if true the array is filled with 1 for timeslots values else with 0 for timeslots values
367 367
      * @return array
368 368
      */
369
-    static private function getAvailabilityArray(\Illuminate\Support\Collection $timeSlots, $timeslotsN, $free=true)
369
+    static private function getAvailabilityArray(\Illuminate\Support\Collection $timeSlots, $timeslotsN, $free = true)
370 370
     {
371
-        $ret = [];
372
-        foreach($timeSlots as $id=>$timeSlots2)
371
+        $ret = [ ];
372
+        foreach ($timeSlots as $id=>$timeSlots2)
373 373
         {
374
-            $ret = self::fillTimeSlots($ret, $id, $timeSlots2, $free?'1':'0');
375
-            $ret = self::fillRow($ret, $id, $timeslotsN, $free?'0':'1');
374
+            $ret = self::fillTimeSlots($ret, $id, $timeSlots2, $free ? '1' : '0');
375
+            $ret = self::fillRow($ret, $id, $timeslotsN, $free ? '0' : '1');
376 376
         }
377 377
 
378 378
         return $ret;
@@ -387,10 +387,10 @@  discard block
 block discarded – undo
387 387
      */
388 388
     static private function fillTimeSlots(array $array, $id, \Illuminate\Support\Collection $timeSlots, $fill = '0')
389 389
     {
390
-        foreach($timeSlots as $timeSlot) {
391
-            if(!isset($array[$id]))
392
-                $array[$id] = [];
393
-            $array[$id] = self::arrayPadInterval($array[$id], $timeSlot->time_start, $timeSlot->time_end, $fill);
390
+        foreach ($timeSlots as $timeSlot) {
391
+            if (!isset($array[ $id ]))
392
+                $array[ $id ] = [ ];
393
+            $array[ $id ] = self::arrayPadInterval($array[ $id ], $timeSlot->time_start, $timeSlot->time_end, $fill);
394 394
         }
395 395
         return $array;
396 396
     }
@@ -403,9 +403,9 @@  discard block
 block discarded – undo
403 403
      */
404 404
     static private function fillRow(array $array, $id, $until, $fill = '0')
405 405
     {
406
-        for($i = 1; $i <= $until; $i++){
407
-            if(!isset($array[$id][$i]))
408
-                $array[$id][$i] = $fill;
406
+        for ($i = 1; $i <= $until; $i++) {
407
+            if (!isset($array[ $id ][ $i ]))
408
+                $array[ $id ][ $i ] = $fill;
409 409
         }
410 410
 
411 411
         return $array;
@@ -420,8 +420,8 @@  discard block
 block discarded – undo
420 420
      */
421 421
     static private function arrayPadInterval(array $array, $from, $to, $pad = '0')
422 422
     {
423
-        for($i = $from; $i<$to; $i++)
424
-            $array[$i] = $pad;
423
+        for ($i = $from; $i < $to; $i++)
424
+            $array[ $i ] = $pad;
425 425
         return $array;
426 426
     }
427 427
 
@@ -435,14 +435,14 @@  discard block
 block discarded – undo
435 435
     {
436 436
         $dateTime = new \DateTime($time);
437 437
         $diff = $dateTime->diff($this->startTime);
438
-        $diff = explode(':',$diff->format('%R:%d:%h:%i:%s'));
439
-        $diff = $diff[1]*86400 + $diff[2]*3600 + $diff[3]*60 + $diff[4];
438
+        $diff = explode(':', $diff->format('%R:%d:%h:%i:%s'));
439
+        $diff = $diff[ 1 ] * 86400 + $diff[ 2 ] * 3600 + $diff[ 3 ] * 60 + $diff[ 4 ];
440 440
         //if($diff[0] != '-' && $diff != 0)
441 441
           //  throw new OptimiseException('timeslot time <= startTime');
442 442
         //TODO fix check
443 443
         //TODO check if diff makes sense
444 444
         //TODO check upper limit
445
-        return (int)(round($diff/self::TIME_SLOT_DURATION)+1); //TODO can round cause overlaps?
445
+        return (int) (round($diff / self::TIME_SLOT_DURATION) + 1); //TODO can round cause overlaps?
446 446
     }
447 447
 
448 448
     /**
@@ -452,7 +452,7 @@  discard block
 block discarded – undo
452 452
     private function toDateTime($timeslot)
453 453
     {
454 454
         $ret = clone $this->startTime;
455
-        return $ret->add(new \DateInterval('PT'.(($timeslot-1)*self::TIME_SLOT_DURATION).'S'));
455
+        return $ret->add(new \DateInterval('PT'.(($timeslot - 1) * self::TIME_SLOT_DURATION).'S'));
456 456
     }
457 457
 
458 458
     /**
@@ -461,6 +461,6 @@  discard block
 block discarded – undo
461 461
      */
462 462
     static private function convertDuration($duration)
463 463
     {
464
-        return (int)ceil($duration/self::TIME_SLOT_DURATION);
464
+        return (int) ceil($duration / self::TIME_SLOT_DURATION);
465 465
     }
466 466
 }
467 467
\ No newline at end of file
Please login to merge, or discard this patch.
Doc Comments   +6 added lines, -5 removed lines patch added patch discarded remove patch
@@ -311,10 +311,10 @@  discard block
 block discarded – undo
311 311
     }
312 312
 
313 313
     /**
314
-     * @param array $users
315
-     * @param array $meetings
314
+     * @param string[] $users
315
+     * @param string[] $meetings
316 316
      * @param \Illuminate\Support\Collection $usersMeetings
317
-     * @return array
317
+     * @return string[]
318 318
      */
319 319
     static private function getUsersMeetingsArray($users, $meetings, \Illuminate\Support\Collection $usersMeetings)
320 320
     {
@@ -363,8 +363,9 @@  discard block
 block discarded – undo
363 363
 
364 364
     /**
365 365
      * @param \Illuminate\Support\Collection $timeSlots
366
-     * @param bool|true $free if true the array is filled with 1 for timeslots values else with 0 for timeslots values
367
-     * @return array
366
+     * @param boolean $free if true the array is filled with 1 for timeslots values else with 0 for timeslots values
367
+     * @param integer $timeslotsN
368
+     * @return string[]
368 369
      */
369 370
     static private function getAvailabilityArray(\Illuminate\Support\Collection $timeSlots, $timeslotsN, $free=true)
370 371
     {
Please login to merge, or discard this patch.
app/Listeners/Optimise/ErrorListener.php 2 patches
Unused Use Statements   -2 removed lines patch added patch discarded remove patch
@@ -3,8 +3,6 @@
 block discarded – undo
3 3
 namespace plunner\Listeners;
4 4
 
5 5
 use plunner\Events\CaldavErrorEvent;
6
-use Illuminate\Queue\InteractsWithQueue;
7
-use Illuminate\Contracts\Queue\ShouldQueue;
8 6
 
9 7
 class CaldavErrorListener
10 8
 {
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@
 block discarded – undo
38 38
      */
39 39
     static private function sendEmail($email, $error)
40 40
     {
41
-        \Mail::queue('emails.optimise.error', ['error' => $error], function ($message) use($email) {
41
+        \Mail::queue('emails.optimise.error', [ 'error' => $error ], function($message) use($email) {
42 42
             $message->from(config('mail.from.address'), config('mail.from.name'));
43 43
             $message->to($email)->subject('Problems during optimisation');
44 44
         });
Please login to merge, or discard this patch.
app/Listeners/Optimise/OkListener.php 3 patches
Unused Use Statements   -2 removed lines patch added patch discarded remove patch
@@ -3,8 +3,6 @@
 block discarded – undo
3 3
 namespace plunner\Listeners;
4 4
 
5 5
 use plunner\Events\CaldavErrorEvent;
6
-use Illuminate\Queue\InteractsWithQueue;
7
-use Illuminate\Contracts\Queue\ShouldQueue;
8 6
 
9 7
 class CaldavErrorListener
10 8
 {
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
         self::sendCompanyEmail($event->getCompany()->email);
34 34
         //send emails to employees
35 35
         $employees = $event->getCompany()->employees()->with('meetings')->get();
36
-        foreach($employees as $employee)
36
+        foreach ($employees as $employee)
37 37
             self::sendEmployeeEmail($employee->email, $employee->meetings);
38 38
     }
39 39
 
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
      */
43 43
     static private function sendCompanyEmail($email)
44 44
     {
45
-        \Mail::queue('emails.optimise.ok.company', [], function ($message) use($email) {
45
+        \Mail::queue('emails.optimise.ok.company', [ ], function($message) use($email) {
46 46
             $message->from(config('mail.from.address'), config('mail.from.name'));
47 47
             $message->to($email)->subject('Meetings optimised');
48 48
         });
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
      */
55 55
     static private function sendEmployeeEmail($email, $meetings)
56 56
     {
57
-        \Mail::queue('emails.optimise.ok.employee', ['meetings' => $meetings], function ($message) use($email) {
57
+        \Mail::queue('emails.optimise.ok.employee', [ 'meetings' => $meetings ], function($message) use($email) {
58 58
             $message->from(config('mail.from.address'), config('mail.from.name'));
59 59
             $message->to($email)->subject('Meetings of next week');
60 60
         });
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -33,8 +33,9 @@
 block discarded – undo
33 33
         self::sendCompanyEmail($event->getCompany()->email);
34 34
         //send emails to employees
35 35
         $employees = $event->getCompany()->employees()->with('meetings')->get();
36
-        foreach($employees as $employee)
37
-            self::sendEmployeeEmail($employee->email, $employee->meetings);
36
+        foreach($employees as $employee) {
37
+                    self::sendEmployeeEmail($employee->email, $employee->meetings);
38
+        }
38 39
     }
39 40
 
40 41
     /**
Please login to merge, or discard this patch.
app/Console/Commands/Optimise/OptimiseCommand.php 3 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -32,8 +32,8 @@
 block discarded – undo
32 32
     protected $description = 'Optimise meetings';
33 33
 
34 34
     /**
35
-    * @var Schedule laravel schedule object needed to perform command in background
36
-    */
35
+     * @var Schedule laravel schedule object needed to perform command in background
36
+     */
37 37
     private $schedule;
38 38
 
39 39
     /**
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 
63 63
         //TODO try...catch with destruct
64 64
         $companyId = $this->argument('companyId');
65
-        if(is_numeric($companyId))
65
+        if (is_numeric($companyId))
66 66
             $this->makeForeground(Company::findOrFail($companyId));
67 67
         else
68 68
             $this->syncAll();
@@ -71,15 +71,15 @@  discard block
 block discarded – undo
71 71
     private function syncAll()
72 72
     {
73 73
         $calendars = Caldav::all();
74
-        if($this->option('background')) {
74
+        if ($this->option('background')) {
75 75
             \Log::debug(self::BACKGROUND_MOD_MEX);
76 76
             $this->info(self::BACKGROUND_MOD_MEX);
77 77
             foreach ($calendars as $calendar)
78 78
                 $this->makeBackground($calendar);
79 79
             \Log::debug(self::BACKGROUND_COMPLETED_MEX);
80 80
             $this->info(self::BACKGROUND_COMPLETED_MEX);
81
-        }else
82
-            foreach($calendars as $calendar)
81
+        } else
82
+            foreach ($calendars as $calendar)
83 83
                 $this->makeForeground($calendar);
84 84
     }
85 85
 
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
     private function makeBackground(Company $company)
91 91
     {
92 92
         $event = $this->schedule->command('optimise:meetings '.$company->id)->withoutOverlapping();
93
-        if($event->isDue($this->laravel))
93
+        if ($event->isDue($this->laravel))
94 94
             $event->run($this->laravel);
95 95
     }
96 96
 
@@ -100,8 +100,8 @@  discard block
 block discarded – undo
100 100
      */
101 101
     private function makeForeground(Company $company)
102 102
     {
103
-        $this->info('Optimisation company '. $company->id.' started');
103
+        $this->info('Optimisation company '.$company->id.' started');
104 104
         (new Optimise($company))->optimise()->save();
105
-        $this->info('Optimisation '. $company->id.' completed');
105
+        $this->info('Optimisation '.$company->id.' completed');
106 106
     }
107 107
 }
Please login to merge, or discard this patch.
Braces   +14 added lines, -10 removed lines patch added patch discarded remove patch
@@ -62,10 +62,11 @@  discard block
 block discarded – undo
62 62
 
63 63
         //TODO try...catch with destruct
64 64
         $companyId = $this->argument('companyId');
65
-        if(is_numeric($companyId))
66
-            $this->makeForeground(Company::findOrFail($companyId));
67
-        else
68
-            $this->syncAll();
65
+        if(is_numeric($companyId)) {
66
+                    $this->makeForeground(Company::findOrFail($companyId));
67
+        } else {
68
+                    $this->syncAll();
69
+        }
69 70
     }
70 71
 
71 72
     private function syncAll()
@@ -74,13 +75,15 @@  discard block
 block discarded – undo
74 75
         if($this->option('background')) {
75 76
             \Log::debug(self::BACKGROUND_MOD_MEX);
76 77
             $this->info(self::BACKGROUND_MOD_MEX);
77
-            foreach ($calendars as $calendar)
78
-                $this->makeBackground($calendar);
78
+            foreach ($calendars as $calendar) {
79
+                            $this->makeBackground($calendar);
80
+            }
79 81
             \Log::debug(self::BACKGROUND_COMPLETED_MEX);
80 82
             $this->info(self::BACKGROUND_COMPLETED_MEX);
81
-        }else
82
-            foreach($calendars as $calendar)
83
+        } else {
84
+                    foreach($calendars as $calendar)
83 85
                 $this->makeForeground($calendar);
86
+        }
84 87
     }
85 88
 
86 89
     /**
@@ -90,8 +93,9 @@  discard block
 block discarded – undo
90 93
     private function makeBackground(Company $company)
91 94
     {
92 95
         $event = $this->schedule->command('optimise:meetings '.$company->id)->withoutOverlapping();
93
-        if($event->isDue($this->laravel))
94
-            $event->run($this->laravel);
96
+        if($event->isDue($this->laravel)) {
97
+                    $event->run($this->laravel);
98
+        }
95 99
     }
96 100
 
97 101
     /**
Please login to merge, or discard this patch.
app/Console/Commands/Optimise/Solver.php 4 patches
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -1,21 +1,21 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * Created by PhpStorm.
4
- * User: Claudio Cardinale <[email protected]>
5
- * Date: 07/12/15
6
- * Time: 21.18
7
- * This program is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU General Public License
9
- * as published by the Free Software Foundation; either version 2
10
- * of the License, or (at your option) any later version.
11
- * This program is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
- * GNU General Public License for more details.
15
- * You should have received a copy of the GNU General Public License
16
- * along with this program; if not, write to the Free Software
17
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18
- */
3
+     * Created by PhpStorm.
4
+     * User: Claudio Cardinale <[email protected]>
5
+     * Date: 07/12/15
6
+     * Time: 21.18
7
+     * This program is free software; you can redistribute it and/or
8
+     * modify it under the terms of the GNU General Public License
9
+     * as published by the Free Software Foundation; either version 2
10
+     * of the License, or (at your option) any later version.
11
+     * This program is distributed in the hope that it will be useful,
12
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+     * GNU General Public License for more details.
15
+     * You should have received a copy of the GNU General Public License
16
+     * along with this program; if not, write to the Free Software
17
+     * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18
+     */
19 19
 
20 20
 namespace plunner\Console\Commands\Optimise;
21 21
 
@@ -69,8 +69,8 @@  discard block
 block discarded – undo
69 69
     private $usersMeetings;
70 70
 
71 71
     /**
72
-    * @var Schedule laravel schedule object needed to perform command in background
73
-    */
72
+     * @var Schedule laravel schedule object needed to perform command in background
73
+     */
74 74
     private $schedule;
75 75
 
76 76
     /**
Please login to merge, or discard this patch.
Doc Comments   +9 added lines, -7 removed lines patch added patch discarded remove patch
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
     }
144 144
 
145 145
     /**
146
-     * @return \string[]
146
+     * @return string[]
147 147
      */
148 148
     public function getUsers()
149 149
     {
@@ -389,7 +389,7 @@  discard block
 block discarded – undo
389 389
 
390 390
     /**
391 391
      * @param string $file
392
-     * @param array $data
392
+     * @param string[] $data
393 393
      * @throws OptimiseException
394 394
      */
395 395
     static private function writeCSVArrayNoKey($file, $data)
@@ -405,7 +405,7 @@  discard block
 block discarded – undo
405 405
 
406 406
     /**
407 407
      * @param string $file
408
-     * @param array $data
408
+     * @param string[] $data
409 409
      * @param string $name
410 410
      * @throws OptimiseException
411 411
      */
@@ -422,7 +422,7 @@  discard block
 block discarded – undo
422 422
 
423 423
     /**
424 424
      * @param string $file
425
-     * @param array $data
425
+     * @param string[] $data
426 426
      * @param string $name
427 427
      * @throws OptimiseException
428 428
      */
@@ -441,7 +441,7 @@  discard block
 block discarded – undo
441 441
     /**
442 442
      * @param string $file
443 443
      * @param array $data
444
-     * @param array $heading
444
+     * @param string[] $heading
445 445
      * @param \Closure $writer
446 446
      * @throws OptimiseException
447 447
      */
@@ -572,7 +572,7 @@  discard block
 block discarded – undo
572 572
     }
573 573
 
574 574
     /**
575
-     * @param $proprieties
575
+     * @param string[] $proprieties
576 576
      * @throws OptimiseException
577 577
      */
578 578
     private function checkArrayProprieties($proprieties)
@@ -583,7 +583,7 @@  discard block
 block discarded – undo
583 583
     }
584 584
 
585 585
     /**
586
-     * @param $proprieties
586
+     * @param string[] $proprieties
587 587
      * @throws OptimiseException
588 588
      */
589 589
     private function checkIntProprieties($proprieties)
@@ -597,6 +597,8 @@  discard block
 block discarded – undo
597 597
      * implementation of arraypad that doesn't change original keys<br/>
598 598
      * <strong>CAUTION: Only positive $len</strong>
599 599
      * @param array $array
600
+     * @param integer $len
601
+     * @param integer $pad
600 602
      * @return array
601 603
      */
602 604
     static private function arrayPad(array $array, $len, $pad)
Please login to merge, or discard this patch.
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
      */
113 113
     static private function checkGlpsol()
114 114
     {
115
-        if(!(`which glpsol`))
115
+        if (!(`which glpsol`))
116 116
             throw new OptimiseException('glpsol is not installed');
117 117
     }
118 118
 
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
      */
194 194
     public function setTimeSlots($timeSlots)
195 195
     {
196
-        if(!is_int($timeSlots) || $timeSlots <=0)
196
+        if (!is_int($timeSlots) || $timeSlots <= 0)
197 197
             throw new OptimiseException('$timeSlots is not integer or it is not >0');
198 198
 
199 199
         $this->timeSlots = $timeSlots;
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
      */
216 216
     public function setMaxTimeSlots($maxTimeSlots)
217 217
     {
218
-        if(!is_int($maxTimeSlots) || $maxTimeSlots <=0)
218
+        if (!is_int($maxTimeSlots) || $maxTimeSlots <= 0)
219 219
             throw new OptimiseException('$maxTimeSlots is not integer or it is not >0');
220 220
 
221 221
         $this->maxTimeSlots = $maxTimeSlots;
@@ -238,13 +238,13 @@  discard block
 block discarded – undo
238 238
     public function setMeetingsAvailability($meetingsAvailability)
239 239
     {
240 240
         $meetings = array_keys($meetingsAvailability);
241
-        if(array_diff($meetings, $this->meetings))
241
+        if (array_diff($meetings, $this->meetings))
242 242
             throw new OptimiseException('meetings different from meetings set');
243
-        foreach($meetingsAvailability as $key=>$meetingsAvailabilityS) {
243
+        foreach ($meetingsAvailability as $key=>$meetingsAvailabilityS) {
244 244
             $timeSlots = array_keys($meetingsAvailabilityS);
245
-            if(count($timeSlots) != $this->timeSlots)
245
+            if (count($timeSlots) != $this->timeSlots)
246 246
                 throw new OptimiseException('timeSlots different from timeSlots set');
247
-            $meetingsAvailability[$key] = self::arrayPad($meetingsAvailabilityS, $this->timeSlots + $this->maxTimeSlots, 0);
247
+            $meetingsAvailability[ $key ] = self::arrayPad($meetingsAvailabilityS, $this->timeSlots + $this->maxTimeSlots, 0);
248 248
         }
249 249
 
250 250
         $this->meetingsAvailability = $meetingsAvailability;
@@ -267,13 +267,13 @@  discard block
 block discarded – undo
267 267
     public function setMeetingsDuration($meetingsDuration)
268 268
     {
269 269
         $meetings = array_keys($meetingsDuration);
270
-        if(array_diff($meetings, $this->meetings)) {
270
+        if (array_diff($meetings, $this->meetings)) {
271 271
             print "";
272 272
             throw new OptimiseException('meetings different from meetings set');
273 273
         }
274
-        foreach($meetingsDuration as $duration) {
274
+        foreach ($meetingsDuration as $duration) {
275 275
             $duration = (int) $duration; //TODO fix this (fix for optimise)
276
-            if(!is_int($duration) || $duration <=0)
276
+            if (!is_int($duration) || $duration <= 0)
277 277
                 throw new OptimiseException('duration is not integer or it is not >0');
278 278
         }
279 279
 
@@ -297,14 +297,14 @@  discard block
 block discarded – undo
297 297
     public function setUsersAvailability($usersAvailability)
298 298
     {
299 299
         $users = array_keys($usersAvailability);
300
-        if(array_diff($users, $this->users))
300
+        if (array_diff($users, $this->users))
301 301
             throw new OptimiseException('users different from users set');
302
-        foreach($usersAvailability as $key=>$usersAvailabilityS) {
302
+        foreach ($usersAvailability as $key=>$usersAvailabilityS) {
303 303
             $timeSlots = array_keys($usersAvailabilityS);
304
-            if(count($timeSlots) != $this->timeSlots)
304
+            if (count($timeSlots) != $this->timeSlots)
305 305
                 throw new OptimiseException('timeSlots different from timeSlots set');
306 306
 
307
-            $usersAvailability[$key] = self::arrayPad($usersAvailabilityS, $this->timeSlots + $this->maxTimeSlots, 0);
307
+            $usersAvailability[ $key ] = self::arrayPad($usersAvailabilityS, $this->timeSlots + $this->maxTimeSlots, 0);
308 308
         }
309 309
 
310 310
         $this->usersAvailability = $usersAvailability;
@@ -327,11 +327,11 @@  discard block
 block discarded – undo
327 327
     public function setUsersMeetings($usersMeetings)
328 328
     {
329 329
         $users = array_keys($usersMeetings);
330
-        if(array_diff($users, $this->users))
330
+        if (array_diff($users, $this->users))
331 331
             throw new OptimiseException('users different from users set');
332
-        foreach($usersMeetings as $usersMeetingsS) {
332
+        foreach ($usersMeetings as $usersMeetingsS) {
333 333
             $meetings = array_keys($usersMeetingsS);
334
-            if(array_diff($meetings, $this->meetings))
334
+            if (array_diff($meetings, $this->meetings))
335 335
                 throw new OptimiseException('meetings different from meetings set');
336 336
         }
337 337
 
@@ -394,13 +394,13 @@  discard block
 block discarded – undo
394 394
      */
395 395
     static private function writeCSVArrayNoKey($file, $data)
396 396
     {
397
-        $f = function ($fp, $data){
397
+        $f = function($fp, $data) {
398 398
             foreach ($data as $field) {
399
-                fputcsv($fp, [$field]);
399
+                fputcsv($fp, [ $field ]);
400 400
             }
401 401
         };
402 402
 
403
-        self::writeCSV($file, $data, ['i'], $f);
403
+        self::writeCSV($file, $data, [ 'i' ], $f);
404 404
     }
405 405
 
406 406
     /**
@@ -411,13 +411,13 @@  discard block
 block discarded – undo
411 411
      */
412 412
     static private function writeCSVArray($file, $data, $name)
413 413
     {
414
-        $f = function ($fp, $data){
414
+        $f = function($fp, $data) {
415 415
             foreach ($data as $key=>$field) {
416
-                fputcsv($fp, [$key, $field]);
416
+                fputcsv($fp, [ $key, $field ]);
417 417
             }
418 418
         };
419 419
 
420
-        self::writeCSV($file, $data, ['i', $name], $f);
420
+        self::writeCSV($file, $data, [ 'i', $name ], $f);
421 421
     }
422 422
 
423 423
     /**
@@ -428,14 +428,14 @@  discard block
 block discarded – undo
428 428
      */
429 429
     static private function writeCSVMatrix($file, $data, $name)
430 430
     {
431
-        $f = function ($fp, $data){
431
+        $f = function($fp, $data) {
432 432
             foreach ($data as $key=>$field) {
433 433
                 foreach ($field as $key2=>$field2)
434
-                    fputcsv($fp, [$key, $key2, $field2]);
434
+                    fputcsv($fp, [ $key, $key2, $field2 ]);
435 435
             }
436 436
         };
437 437
 
438
-        self::writeCSV($file, $data, ['i', 'j', $name], $f);
438
+        self::writeCSV($file, $data, [ 'i', 'j', $name ], $f);
439 439
     }
440 440
 
441 441
     /**
@@ -448,7 +448,7 @@  discard block
 block discarded – undo
448 448
     static private function writeCSV($file, $data, $heading, \Closure $writer)
449 449
     {
450 450
         $fp = @fopen($file, 'w');
451
-        if(!$fp)
451
+        if (!$fp)
452 452
             throw new OptimiseException('problem during creation of a file');
453 453
 
454 454
         fputcsv($fp, $heading);
@@ -468,8 +468,8 @@  discard block
 block discarded – undo
468 468
     {
469 469
         $this->writeData();
470 470
         $this->writeModelFile();
471
-        $event = $this->schedule->exec('glpsol --math '.$this->path->getModelPath())->sendOutputTo($this->path->getOutputPath())->after(function () { }); //this just to execute in foreground
472
-        if($event->isDue($this->laravel))
471
+        $event = $this->schedule->exec('glpsol --math '.$this->path->getModelPath())->sendOutputTo($this->path->getOutputPath())->after(function() { }); //this just to execute in foreground
472
+        if ($event->isDue($this->laravel))
473 473
             $event->run($this->laravel);
474 474
         //TODO catch glpsol errors
475 475
         return $this;
@@ -483,9 +483,9 @@  discard block
 block discarded – undo
483 483
         $strReplaceS = array('{USERS_PATH}', '{MEETINGS_PATH}', '{USER_AVAILABILITY_PATH}', '{MEETINGS_AVAILABILITY_PATH}', '{USER_MEETINGS_PATH}', '{MEETINGS_DURATION_PATH}', '{TIME_SLOTS}', '{MAX_TIME_SLOTS}', '{X_OUT_PATH}', '{Y_OUT_PATH}');
484 484
         $strReplaceR = array($this->path->getUsersPath(), $this->path->getMeetingsPath(), $this->path->getUsersAvailabilityPath(), $this->path->getMeetingsAvailabilityPath(), $this->path->getUsersMeetingsPath(), $this->path->getMeetingsDurationPath(), $this->timeSlots, $this->maxTimeSlots, $this->path->getXPath(), $this->path->getYPath());
485 485
         $f = @fopen($this->path->getModelPath(), "w");
486
-        if(!$f)
486
+        if (!$f)
487 487
             throw new OptimiseException('problem during creation of a file');
488
-        fwrite($f, str_replace($strReplaceS, $strReplaceR, file_get_contents(__DIR__ . "/model.stub")));
488
+        fwrite($f, str_replace($strReplaceS, $strReplaceR, file_get_contents(__DIR__."/model.stub")));
489 489
         fclose($f);
490 490
     }
491 491
 
@@ -513,7 +513,7 @@  discard block
 block discarded – undo
513 513
      */
514 514
     public function getOutput()
515 515
     {
516
-        if(!($data = file_get_contents($this->path->getOutputPath())))
516
+        if (!($data = file_get_contents($this->path->getOutputPath())))
517 517
             throw new OptimiseException('problems during reading the file');
518 518
         return $data;
519 519
     }
@@ -525,22 +525,22 @@  discard block
 block discarded – undo
525 525
      */
526 526
     static private function readCSVFile($file)
527 527
     {
528
-        if(!file_exists($file) || !filesize($file))
528
+        if (!file_exists($file) || !filesize($file))
529 529
             throw new OptimiseException('no results file');
530 530
 
531
-        $handle = @fopen($file,"r");
532
-        if(!$handle)
531
+        $handle = @fopen($file, "r");
532
+        if (!$handle)
533 533
             throw new OptimiseException('problems during reading the file');
534 534
 
535
-        $ret = [];
535
+        $ret = [ ];
536 536
         fgetcsv($handle); //skip head
537 537
         while (($data = fgetcsv($handle)) !== FALSE) {
538
-            if(count($data) != 3) {
538
+            if (count($data) != 3) {
539 539
                 fclose($handle);
540 540
                 throw new OptimiseException('problems during parsing the file');
541 541
             }
542 542
 
543
-            $ret[$data[0]][$data[1]] = $data[2];
543
+            $ret[ $data[ 0 ] ][ $data[ 1 ] ] = $data[ 2 ];
544 544
         }
545 545
 
546 546
         fclose($handle);
@@ -567,8 +567,8 @@  discard block
 block discarded – undo
567 567
      */
568 568
     private function checkData()
569 569
     {
570
-        $this->checkArrayProprieties(['users', 'meetings', 'meetingsAvailability', 'meetingsDuration', 'usersAvailability', 'usersMeetings']);
571
-        $this->checkIntProprieties(['timeSlots', 'maxTimeSlots']);
570
+        $this->checkArrayProprieties([ 'users', 'meetings', 'meetingsAvailability', 'meetingsDuration', 'usersAvailability', 'usersMeetings' ]);
571
+        $this->checkIntProprieties([ 'timeSlots', 'maxTimeSlots' ]);
572 572
     }
573 573
 
574 574
     /**
@@ -577,8 +577,8 @@  discard block
 block discarded – undo
577 577
      */
578 578
     private function checkArrayProprieties($proprieties)
579 579
     {
580
-        foreach($proprieties as $propriety)
581
-            if(count($this->$propriety)==0)
580
+        foreach ($proprieties as $propriety)
581
+            if (count($this->$propriety) == 0)
582 582
                 throw new OptimiseException($propriety.' is not set correctly');
583 583
     }
584 584
 
@@ -588,8 +588,8 @@  discard block
 block discarded – undo
588 588
      */
589 589
     private function checkIntProprieties($proprieties)
590 590
     {
591
-        foreach($proprieties as $propriety)
592
-            if(!is_int($this->$propriety) || $this->$propriety <= 0)
591
+        foreach ($proprieties as $propriety)
592
+            if (!is_int($this->$propriety) || $this->$propriety <= 0)
593 593
                 throw new OptimiseException($propriety.' is not set correctly');
594 594
     }
595 595
 
@@ -602,8 +602,8 @@  discard block
 block discarded – undo
602 602
     static private function arrayPad(array $array, $len, $pad)
603 603
     {
604 604
         $len = $len - count($array);
605
-        for($i = 0; $i<$len; $i++)
606
-            $array[] = $pad;
605
+        for ($i = 0; $i < $len; $i++)
606
+            $array[ ] = $pad;
607 607
         return $array;
608 608
     }
609 609
 }
610 610
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +60 added lines, -40 removed lines patch added patch discarded remove patch
@@ -112,8 +112,9 @@  discard block
 block discarded – undo
112 112
      */
113 113
     static private function checkGlpsol()
114 114
     {
115
-        if(!(`which glpsol`))
116
-            throw new OptimiseException('glpsol is not installed');
115
+        if(!(`which glpsol`)) {
116
+                    throw new OptimiseException('glpsol is not installed');
117
+        }
117 118
     }
118 119
 
119 120
     /**
@@ -193,8 +194,9 @@  discard block
 block discarded – undo
193 194
      */
194 195
     public function setTimeSlots($timeSlots)
195 196
     {
196
-        if(!is_int($timeSlots) || $timeSlots <=0)
197
-            throw new OptimiseException('$timeSlots is not integer or it is not >0');
197
+        if(!is_int($timeSlots) || $timeSlots <=0) {
198
+                    throw new OptimiseException('$timeSlots is not integer or it is not >0');
199
+        }
198 200
 
199 201
         $this->timeSlots = $timeSlots;
200 202
         return $this;
@@ -215,8 +217,9 @@  discard block
 block discarded – undo
215 217
      */
216 218
     public function setMaxTimeSlots($maxTimeSlots)
217 219
     {
218
-        if(!is_int($maxTimeSlots) || $maxTimeSlots <=0)
219
-            throw new OptimiseException('$maxTimeSlots is not integer or it is not >0');
220
+        if(!is_int($maxTimeSlots) || $maxTimeSlots <=0) {
221
+                    throw new OptimiseException('$maxTimeSlots is not integer or it is not >0');
222
+        }
220 223
 
221 224
         $this->maxTimeSlots = $maxTimeSlots;
222 225
         return $this;
@@ -238,12 +241,14 @@  discard block
 block discarded – undo
238 241
     public function setMeetingsAvailability($meetingsAvailability)
239 242
     {
240 243
         $meetings = array_keys($meetingsAvailability);
241
-        if(array_diff($meetings, $this->meetings))
242
-            throw new OptimiseException('meetings different from meetings set');
244
+        if(array_diff($meetings, $this->meetings)) {
245
+                    throw new OptimiseException('meetings different from meetings set');
246
+        }
243 247
         foreach($meetingsAvailability as $key=>$meetingsAvailabilityS) {
244 248
             $timeSlots = array_keys($meetingsAvailabilityS);
245
-            if(count($timeSlots) != $this->timeSlots)
246
-                throw new OptimiseException('timeSlots different from timeSlots set');
249
+            if(count($timeSlots) != $this->timeSlots) {
250
+                            throw new OptimiseException('timeSlots different from timeSlots set');
251
+            }
247 252
             $meetingsAvailability[$key] = self::arrayPad($meetingsAvailabilityS, $this->timeSlots + $this->maxTimeSlots, 0);
248 253
         }
249 254
 
@@ -273,8 +278,9 @@  discard block
 block discarded – undo
273 278
         }
274 279
         foreach($meetingsDuration as $duration) {
275 280
             $duration = (int) $duration; //TODO fix this (fix for optimise)
276
-            if(!is_int($duration) || $duration <=0)
277
-                throw new OptimiseException('duration is not integer or it is not >0');
281
+            if(!is_int($duration) || $duration <=0) {
282
+                            throw new OptimiseException('duration is not integer or it is not >0');
283
+            }
278 284
         }
279 285
 
280 286
         $this->meetingsDuration = $meetingsDuration;
@@ -297,12 +303,14 @@  discard block
 block discarded – undo
297 303
     public function setUsersAvailability($usersAvailability)
298 304
     {
299 305
         $users = array_keys($usersAvailability);
300
-        if(array_diff($users, $this->users))
301
-            throw new OptimiseException('users different from users set');
306
+        if(array_diff($users, $this->users)) {
307
+                    throw new OptimiseException('users different from users set');
308
+        }
302 309
         foreach($usersAvailability as $key=>$usersAvailabilityS) {
303 310
             $timeSlots = array_keys($usersAvailabilityS);
304
-            if(count($timeSlots) != $this->timeSlots)
305
-                throw new OptimiseException('timeSlots different from timeSlots set');
311
+            if(count($timeSlots) != $this->timeSlots) {
312
+                            throw new OptimiseException('timeSlots different from timeSlots set');
313
+            }
306 314
 
307 315
             $usersAvailability[$key] = self::arrayPad($usersAvailabilityS, $this->timeSlots + $this->maxTimeSlots, 0);
308 316
         }
@@ -327,12 +335,14 @@  discard block
 block discarded – undo
327 335
     public function setUsersMeetings($usersMeetings)
328 336
     {
329 337
         $users = array_keys($usersMeetings);
330
-        if(array_diff($users, $this->users))
331
-            throw new OptimiseException('users different from users set');
338
+        if(array_diff($users, $this->users)) {
339
+                    throw new OptimiseException('users different from users set');
340
+        }
332 341
         foreach($usersMeetings as $usersMeetingsS) {
333 342
             $meetings = array_keys($usersMeetingsS);
334
-            if(array_diff($meetings, $this->meetings))
335
-                throw new OptimiseException('meetings different from meetings set');
343
+            if(array_diff($meetings, $this->meetings)) {
344
+                            throw new OptimiseException('meetings different from meetings set');
345
+            }
336 346
         }
337 347
 
338 348
         $this->usersMeetings = $usersMeetings;
@@ -430,8 +440,9 @@  discard block
 block discarded – undo
430 440
     {
431 441
         $f = function ($fp, $data){
432 442
             foreach ($data as $key=>$field) {
433
-                foreach ($field as $key2=>$field2)
434
-                    fputcsv($fp, [$key, $key2, $field2]);
443
+                foreach ($field as $key2=>$field2) {
444
+                                    fputcsv($fp, [$key, $key2, $field2]);
445
+                }
435 446
             }
436 447
         };
437 448
 
@@ -448,8 +459,9 @@  discard block
 block discarded – undo
448 459
     static private function writeCSV($file, $data, $heading, \Closure $writer)
449 460
     {
450 461
         $fp = @fopen($file, 'w');
451
-        if(!$fp)
452
-            throw new OptimiseException('problem during creation of a file');
462
+        if(!$fp) {
463
+                    throw new OptimiseException('problem during creation of a file');
464
+        }
453 465
 
454 466
         fputcsv($fp, $heading);
455 467
 
@@ -469,8 +481,9 @@  discard block
 block discarded – undo
469 481
         $this->writeData();
470 482
         $this->writeModelFile();
471 483
         $event = $this->schedule->exec('glpsol --math '.$this->path->getModelPath())->sendOutputTo($this->path->getOutputPath())->after(function () { }); //this just to execute in foreground
472
-        if($event->isDue($this->laravel))
473
-            $event->run($this->laravel);
484
+        if($event->isDue($this->laravel)) {
485
+                    $event->run($this->laravel);
486
+        }
474 487
         //TODO catch glpsol errors
475 488
         return $this;
476 489
     }
@@ -483,8 +496,9 @@  discard block
 block discarded – undo
483 496
         $strReplaceS = array('{USERS_PATH}', '{MEETINGS_PATH}', '{USER_AVAILABILITY_PATH}', '{MEETINGS_AVAILABILITY_PATH}', '{USER_MEETINGS_PATH}', '{MEETINGS_DURATION_PATH}', '{TIME_SLOTS}', '{MAX_TIME_SLOTS}', '{X_OUT_PATH}', '{Y_OUT_PATH}');
484 497
         $strReplaceR = array($this->path->getUsersPath(), $this->path->getMeetingsPath(), $this->path->getUsersAvailabilityPath(), $this->path->getMeetingsAvailabilityPath(), $this->path->getUsersMeetingsPath(), $this->path->getMeetingsDurationPath(), $this->timeSlots, $this->maxTimeSlots, $this->path->getXPath(), $this->path->getYPath());
485 498
         $f = @fopen($this->path->getModelPath(), "w");
486
-        if(!$f)
487
-            throw new OptimiseException('problem during creation of a file');
499
+        if(!$f) {
500
+                    throw new OptimiseException('problem during creation of a file');
501
+        }
488 502
         fwrite($f, str_replace($strReplaceS, $strReplaceR, file_get_contents(__DIR__ . "/model.stub")));
489 503
         fclose($f);
490 504
     }
@@ -513,8 +527,9 @@  discard block
 block discarded – undo
513 527
      */
514 528
     public function getOutput()
515 529
     {
516
-        if(!($data = file_get_contents($this->path->getOutputPath())))
517
-            throw new OptimiseException('problems during reading the file');
530
+        if(!($data = file_get_contents($this->path->getOutputPath()))) {
531
+                    throw new OptimiseException('problems during reading the file');
532
+        }
518 533
         return $data;
519 534
     }
520 535
 
@@ -525,12 +540,14 @@  discard block
 block discarded – undo
525 540
      */
526 541
     static private function readCSVFile($file)
527 542
     {
528
-        if(!file_exists($file) || !filesize($file))
529
-            throw new OptimiseException('no results file');
543
+        if(!file_exists($file) || !filesize($file)) {
544
+                    throw new OptimiseException('no results file');
545
+        }
530 546
 
531 547
         $handle = @fopen($file,"r");
532
-        if(!$handle)
533
-            throw new OptimiseException('problems during reading the file');
548
+        if(!$handle) {
549
+                    throw new OptimiseException('problems during reading the file');
550
+        }
534 551
 
535 552
         $ret = [];
536 553
         fgetcsv($handle); //skip head
@@ -577,9 +594,10 @@  discard block
 block discarded – undo
577 594
      */
578 595
     private function checkArrayProprieties($proprieties)
579 596
     {
580
-        foreach($proprieties as $propriety)
581
-            if(count($this->$propriety)==0)
597
+        foreach($proprieties as $propriety) {
598
+                    if(count($this->$propriety)==0)
582 599
                 throw new OptimiseException($propriety.' is not set correctly');
600
+        }
583 601
     }
584 602
 
585 603
     /**
@@ -588,9 +606,10 @@  discard block
 block discarded – undo
588 606
      */
589 607
     private function checkIntProprieties($proprieties)
590 608
     {
591
-        foreach($proprieties as $propriety)
592
-            if(!is_int($this->$propriety) || $this->$propriety <= 0)
609
+        foreach($proprieties as $propriety) {
610
+                    if(!is_int($this->$propriety) || $this->$propriety <= 0)
593 611
                 throw new OptimiseException($propriety.' is not set correctly');
612
+        }
594 613
     }
595 614
 
596 615
     /**
@@ -602,8 +621,9 @@  discard block
 block discarded – undo
602 621
     static private function arrayPad(array $array, $len, $pad)
603 622
     {
604 623
         $len = $len - count($array);
605
-        for($i = 0; $i<$len; $i++)
606
-            $array[] = $pad;
624
+        for($i = 0; $i<$len; $i++) {
625
+                    $array[] = $pad;
626
+        }
607 627
         return $array;
608 628
     }
609 629
 }
610 630
\ No newline at end of file
Please login to merge, or discard this patch.
app/Console/Commands/Optimise/OptimiseException.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -1,21 +1,21 @@
 block discarded – undo
1 1
 <?php
2 2
 /**
3
- * Created by PhpStorm.
4
- * User: Claudio Cardinale <[email protected]>
5
- * Date: 07/12/15
6
- * Time: 21.24
7
- * This program is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU General Public License
9
- * as published by the Free Software Foundation; either version 2
10
- * of the License, or (at your option) any later version.
11
- * This program is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
- * GNU General Public License for more details.
15
- * You should have received a copy of the GNU General Public License
16
- * along with this program; if not, write to the Free Software
17
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18
- */
3
+     * Created by PhpStorm.
4
+     * User: Claudio Cardinale <[email protected]>
5
+     * Date: 07/12/15
6
+     * Time: 21.24
7
+     * This program is free software; you can redistribute it and/or
8
+     * modify it under the terms of the GNU General Public License
9
+     * as published by the Free Software Foundation; either version 2
10
+     * of the License, or (at your option) any later version.
11
+     * This program is distributed in the hope that it will be useful,
12
+     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+     * GNU General Public License for more details.
15
+     * You should have received a copy of the GNU General Public License
16
+     * along with this program; if not, write to the Free Software
17
+     * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18
+     */
19 19
 
20 20
 namespace plunner\Console\Commands\Optimise;
21 21
 
Please login to merge, or discard this patch.