Completed
Push — master ( bbd96d...b6f152 )
by claudio
06:06
created
app/Console/Commands/Optimise/Solver.php 1 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/Path.php 1 patch
Braces   +13 added lines, -8 removed lines patch added patch discarded remove patch
@@ -48,8 +48,9 @@  discard block
 block discarded – undo
48 48
      */
49 49
     public function __destruct()
50 50
     {
51
-        if ($this->path && is_dir($this->path) && !self::delTree($this->path))
52
-            throw new OptimiseException('problems during removing of path directory');
51
+        if ($this->path && is_dir($this->path) && !self::delTree($this->path)) {
52
+                    throw new OptimiseException('problems during removing of path directory');
53
+        }
53 54
     }
54 55
 
55 56
     /**
@@ -76,12 +77,16 @@  discard block
 block discarded – undo
76 77
     {
77 78
         $path = new Path(tempnam(sys_get_temp_dir(), 'OPT')); //TODO check the return in case of errors this return false on failure
78 79
         unlink($path->getPath()); //remove file to create a dir
79
-        if(file_exists($path->getPath()))
80
-            throw new OptimiseException('problem during creation of tmp dir (the directory already exists)');
81
-        if(!@mkdir($path->getPath()))
82
-            throw new OptimiseException('problem during creation of tmp dir (mkdir problem)');;
83
-        if(! is_dir($path->getPath()))
84
-            throw new OptimiseException('problem during creation of tmp dir (it is not possible to create directory)');
80
+        if(file_exists($path->getPath())) {
81
+                    throw new OptimiseException('problem during creation of tmp dir (the directory already exists)');
82
+        }
83
+        if(!@mkdir($path->getPath())) {
84
+                    throw new OptimiseException('problem during creation of tmp dir (mkdir problem)');
85
+        }
86
+        ;
87
+        if(! is_dir($path->getPath())) {
88
+                    throw new OptimiseException('problem during creation of tmp dir (it is not possible to create directory)');
89
+        }
85 90
         return $path;
86 91
     }
87 92
 
Please login to merge, or discard this patch.