Completed
Pull Request — master (#28)
by claudio
05:35
created
app/Calendar.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@
 block discarded – undo
37 37
      *
38 38
      * @var array
39 39
      */
40
-    protected $fillable = ['name', 'enabled'];
40
+    protected $fillable = [ 'name', 'enabled' ];
41 41
 
42 42
     /**
43 43
      * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
Please login to merge, or discard this patch.
app/Http/routes.php 1 patch
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -18,36 +18,36 @@  discard block
 block discarded – undo
18 18
 /**
19 19
  * Companies
20 20
  */
21
-Route::group(['namespace' => 'Companies', 'prefix' => 'companies'], function() {
21
+Route::group([ 'namespace' => 'Companies', 'prefix' => 'companies' ], function() {
22 22
 
23 23
     //\Auth
24 24
 
25
-    Route::group(['namespace' => 'Auth'], function() {
26
-        Route::group(['prefix' => 'auth'], function () {
25
+    Route::group([ 'namespace' => 'Auth' ], function() {
26
+        Route::group([ 'prefix' => 'auth' ], function() {
27 27
             // Authentication routes...
28
-            Route::post('login', ['as' => 'companies.auth.login','uses'=>'AuthController@postLogin']);
28
+            Route::post('login', [ 'as' => 'companies.auth.login', 'uses'=>'AuthController@postLogin' ]);
29 29
 
30 30
             // Registration routes...
31
-            Route::post('register', ['as' => 'companies.auth.register', 'uses'=>'AuthController@postRegister']);
31
+            Route::post('register', [ 'as' => 'companies.auth.register', 'uses'=>'AuthController@postRegister' ]);
32 32
 
33 33
         });
34 34
 
35
-        Route::group(['prefix' => 'password'], function () {
35
+        Route::group([ 'prefix' => 'password' ], function() {
36 36
             // Password reset link request routes...
37
-            Route::post('email', ['as' => 'companies.auth.email', 'uses'=>'PasswordController@postEmail']);
37
+            Route::post('email', [ 'as' => 'companies.auth.email', 'uses'=>'PasswordController@postEmail' ]);
38 38
 
39 39
             // Password reset routes...
40
-            Route::post('reset', ['as' => 'companies.auth.reset', 'uses'=>'PasswordController@postReset']);
40
+            Route::post('reset', [ 'as' => 'companies.auth.reset', 'uses'=>'PasswordController@postReset' ]);
41 41
         });
42 42
     });
43 43
 
44
-    Route::group(['namespace' => 'Employees'], function() {
45
-        Route::resource('employees', 'EmployeesController', ['except' => ['create', 'edit']]);
44
+    Route::group([ 'namespace' => 'Employees' ], function() {
45
+        Route::resource('employees', 'EmployeesController', [ 'except' => [ 'create', 'edit' ] ]);
46 46
     });
47 47
 
48
-    Route::group(['namespace' => 'Groups'], function() {
49
-        Route::resource('groups', 'GroupsController', ['except' => ['create', 'edit']]);
50
-        Route::resource('groups.employees', 'EmployeesController', ['only' => ['store', 'index', 'destroy']]);
48
+    Route::group([ 'namespace' => 'Groups' ], function() {
49
+        Route::resource('groups', 'GroupsController', [ 'except' => [ 'create', 'edit' ] ]);
50
+        Route::resource('groups.employees', 'EmployeesController', [ 'only' => [ 'store', 'index', 'destroy' ] ]);
51 51
     });
52 52
 });
53 53
 
@@ -55,39 +55,39 @@  discard block
 block discarded – undo
55 55
 /**
56 56
  * Employees
57 57
  */
58
-Route::group(['namespace' => 'Employees', 'prefix' => 'employees'], function() {
58
+Route::group([ 'namespace' => 'Employees', 'prefix' => 'employees' ], function() {
59 59
 
60 60
     //\Auth
61
-    Route::group(['namespace' => 'Auth'], function() {
62
-        Route::group(['prefix' => 'auth'], function () {
61
+    Route::group([ 'namespace' => 'Auth' ], function() {
62
+        Route::group([ 'prefix' => 'auth' ], function() {
63 63
             // Authentication routes...
64
-            Route::post('login', ['as' => 'companies.auth.login', 'uses'=>'AuthController@postLogin']);
64
+            Route::post('login', [ 'as' => 'companies.auth.login', 'uses'=>'AuthController@postLogin' ]);
65 65
 
66 66
             // Registration routes...
67 67
             //Route::post('register', ['as' => 'companies.auth.register', 'uses'=>'AuthController@postRegister']); //the registration is managed by the company
68 68
 
69 69
         });
70 70
 
71
-        Route::group(['prefix' => 'password'], function () {
71
+        Route::group([ 'prefix' => 'password' ], function() {
72 72
             // Password reset link request routes...
73
-            Route::post('email', ['as' => 'companies.auth.email', 'uses'=>'PasswordController@postEmail']);
73
+            Route::post('email', [ 'as' => 'companies.auth.email', 'uses'=>'PasswordController@postEmail' ]);
74 74
 
75 75
             // Password reset routes...
76
-            Route::post('reset', ['as' => 'companies.auth.reset', 'uses'=>'PasswordController@postReset']);
76
+            Route::post('reset', [ 'as' => 'companies.auth.reset', 'uses'=>'PasswordController@postReset' ]);
77 77
         });
78 78
     });
79 79
 
80
-    Route::group(['namespace' => 'Calendars'], function() {
81
-        Route::resource('calendars', 'CalendarsController', ['except' => ['create', 'edit']]);
82
-        Route::post('calendars/caldav', ['as' => 'employees.calendars.caldav','uses'=>'CalendarsController@storeCaldav']);
83
-        Route::post('calendars/calendars', ['as' => 'employees.calendars.calendars','uses'=>'CalendarsController@getCalendars']); //TODO it's correct post? or not
80
+    Route::group([ 'namespace' => 'Calendars' ], function() {
81
+        Route::resource('calendars', 'CalendarsController', [ 'except' => [ 'create', 'edit' ] ]);
82
+        Route::post('calendars/caldav', [ 'as' => 'employees.calendars.caldav', 'uses'=>'CalendarsController@storeCaldav' ]);
83
+        Route::post('calendars/calendars', [ 'as' => 'employees.calendars.calendars', 'uses'=>'CalendarsController@getCalendars' ]); //TODO it's correct post? or not
84 84
     });
85 85
 
86
-    Route::group(['namespace' => 'Planners', 'prefix' => 'planners'], function() {
87
-        Route::resource('groups', 'GroupsController', ['only' => ['index', 'show']]);
86
+    Route::group([ 'namespace' => 'Planners', 'prefix' => 'planners' ], function() {
87
+        Route::resource('groups', 'GroupsController', [ 'only' => [ 'index', 'show' ] ]);
88 88
     });
89 89
 
90
-    Route::group(['namespace' => 'Groups'], function() {
91
-        Route::resource('groups', 'GroupsController', ['only' => ['index', 'show']]);
90
+    Route::group([ 'namespace' => 'Groups' ], function() {
91
+        Route::resource('groups', 'GroupsController', [ 'only' => [ 'index', 'show' ] ]);
92 92
     });
93 93
 });
94 94
\ No newline at end of file
Please login to merge, or discard this patch.
app/MeetingTimeslot.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@
 block discarded – undo
11 11
      *
12 12
      * @var array
13 13
      */
14
-    protected $fillable = ['time_start', 'time_end'];
14
+    protected $fillable = [ 'time_start', 'time_end' ];
15 15
 
16 16
     public function employees()
17 17
     {
Please login to merge, or discard this patch.
app/Http/Controllers/Employees/Calendars/CalendarsController.php 2 patches
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -17,8 +17,8 @@  discard block
 block discarded – undo
17 17
      */
18 18
     public function __construct()
19 19
     {
20
-        config(['auth.model' => \plunner\Employee::class]);
21
-        config(['jwt.user' => \plunner\Employee::class]);
20
+        config([ 'auth.model' => \plunner\Employee::class ]);
21
+        config([ 'jwt.user' => \plunner\Employee::class ]);
22 22
         $this->middleware('jwt.authandrefresh:mode-en');
23 23
     }
24 24
 
@@ -66,8 +66,8 @@  discard block
 block discarded – undo
66 66
         $employee = \Auth::user();
67 67
         $input = $request->all();
68 68
         $calendar = $employee->calendars()->create($input);
69
-        if(isset($input['password']))
70
-            $input['password'] = \Crypt::encrypt($input['password']);
69
+        if (isset($input[ 'password' ]))
70
+            $input[ 'password' ] = \Crypt::encrypt($input[ 'password' ]);
71 71
         $calendar->caldav()->create($input);
72 72
         //TODO test
73 73
         //TODO validator
@@ -104,17 +104,17 @@  discard block
 block discarded – undo
104 104
         $this->authorize($calendar);
105 105
         $input = $request->all();
106 106
         $caldav = $calendar->caldav;
107
-        if($caldav){
107
+        if ($caldav) {
108 108
             $this->validateCaldav($request);
109 109
         }
110
-        if(isset($input['password']))
111
-            $input['password'] = \Crypt::encrypt($input['password']);
110
+        if (isset($input[ 'password' ]))
111
+            $input[ 'password' ] = \Crypt::encrypt($input[ 'password' ]);
112 112
         $calendar->update($input);
113 113
         //TODO test
114 114
         //TODO validator
115 115
         //TODO check if caldav exists?
116 116
 
117
-        if($caldav)
117
+        if ($caldav)
118 118
             $caldav->update($input);
119 119
         return $calendar;
120 120
     }
@@ -148,9 +148,9 @@  discard block
 block discarded – undo
148 148
             $caldavClient->connect($request->input('url'), $request->input('username'), $request->input('password'));
149 149
             $calendars = $caldavClient->findCalendars();
150 150
             return array_keys($calendars);
151
-        }catch (\it\thecsea\caldav_client_adapter\CaldavException $e)
151
+        } catch (\it\thecsea\caldav_client_adapter\CaldavException $e)
152 152
         {
153
-            return Response::json(['error' => $e->getMessage()],422);
153
+            return Response::json([ 'error' => $e->getMessage() ], 422);
154 154
         }
155 155
     }
156 156
 
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
         $this->validate($request, [
163 163
             'url' => 'required|max:255',
164 164
             'username' => 'required|max:255',
165
-            'password' => ((\Route::current()->getName() == 'companies.calendars.caldav')?'required':''),
165
+            'password' => ((\Route::current()->getName() == 'companies.calendars.caldav') ? 'required' : ''),
166 166
             'calendar_name' => 'required|max:255',
167 167
         ]);
168 168
     }
Please login to merge, or discard this patch.
Braces   +10 added lines, -7 removed lines patch added patch discarded remove patch
@@ -66,8 +66,9 @@  discard block
 block discarded – undo
66 66
         $employee = \Auth::user();
67 67
         $input = $request->all();
68 68
         $calendar = $employee->calendars()->create($input);
69
-        if(isset($input['password']))
70
-            $input['password'] = \Crypt::encrypt($input['password']);
69
+        if(isset($input['password'])) {
70
+                    $input['password'] = \Crypt::encrypt($input['password']);
71
+        }
71 72
         $calendar->caldav()->create($input);
72 73
         //TODO test
73 74
         //TODO validator
@@ -107,15 +108,17 @@  discard block
 block discarded – undo
107 108
         if($caldav){
108 109
             $this->validateCaldav($request);
109 110
         }
110
-        if(isset($input['password']))
111
-            $input['password'] = \Crypt::encrypt($input['password']);
111
+        if(isset($input['password'])) {
112
+                    $input['password'] = \Crypt::encrypt($input['password']);
113
+        }
112 114
         $calendar->update($input);
113 115
         //TODO test
114 116
         //TODO validator
115 117
         //TODO check if caldav exists?
116 118
 
117
-        if($caldav)
118
-            $caldav->update($input);
119
+        if($caldav) {
120
+                    $caldav->update($input);
121
+        }
119 122
         return $calendar;
120 123
     }
121 124
 
@@ -148,7 +151,7 @@  discard block
 block discarded – undo
148 151
             $caldavClient->connect($request->input('url'), $request->input('username'), $request->input('password'));
149 152
             $calendars = $caldavClient->findCalendars();
150 153
             return array_keys($calendars);
151
-        }catch (\it\thecsea\caldav_client_adapter\CaldavException $e)
154
+        } catch (\it\thecsea\caldav_client_adapter\CaldavException $e)
152 155
         {
153 156
             return Response::json(['error' => $e->getMessage()],422);
154 157
         }
Please login to merge, or discard this patch.
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
Doc Comments   +6 added lines, -5 removed lines patch added patch discarded remove patch
@@ -303,10 +303,10 @@  discard block
 block discarded – undo
303 303
     }
304 304
 
305 305
     /**
306
-     * @param array $users
307
-     * @param array $meetings
306
+     * @param string[] $users
307
+     * @param string[] $meetings
308 308
      * @param \Illuminate\Support\Collection $usersMeetings
309
-     * @return array
309
+     * @return \string[]
310 310
      */
311 311
     static private function getUsersMeetingsArray($users, $meetings, \Illuminate\Support\Collection $usersMeetings)
312 312
     {
@@ -338,8 +338,9 @@  discard block
 block discarded – undo
338 338
 
339 339
     /**
340 340
      * @param \Illuminate\Support\Collection $timeSlots
341
-     * @param bool|true $free if true the array is filled with 1 for timeslots values else with 0 for timeslots values
342
-     * @return array
341
+     * @param boolean $free if true the array is filled with 1 for timeslots values else with 0 for timeslots values
342
+     * @param integer $timeslotsN
343
+     * @return \string[]
343 344
      */
344 345
     static private function getAvailabilityArray(\Illuminate\Support\Collection $timeSlots, $timeslotsN, $free=true)
345 346
     {
Please login to merge, or discard this patch.
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   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -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
     /**
@@ -423,7 +423,7 @@  discard block
 block discarded – undo
423 423
         $diff = explode(':',$diff->format('%R:%d:%h:%i:%s'));
424 424
         $diff = $diff[1]*86400 + $diff[2]*3600 + $diff[3]*60 + $diff[4];
425 425
         //if($diff[0] != '-' && $diff != 0)
426
-          //  throw new OptimiseException('timeslot time <= startTime');
426
+            //  throw new OptimiseException('timeslot time <= startTime');
427 427
         //TODO fix check
428 428
         //TODO check if diff makes sense
429 429
         //TODO check upper limit
Please login to merge, or discard this patch.
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -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());
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
                 return $this->timeSlotsConverter($item);
275 275
             });
276 276
         return $solver->setMeetings($timeslots->keys()->toArray())
277
-            ->setMeetingsDuration($meetings->pluck('duration','id')->toArray())
277
+            ->setMeetingsDuration($meetings->pluck('duration', 'id')->toArray())
278 278
             ->setMeetingsAvailability(self::getAvailabilityArray($timeslots, $this->time_slots));
279 279
     }
280 280
 
@@ -320,15 +320,15 @@  discard block
 block discarded – undo
320 320
      */
321 321
     static private function getUsersMeetingsArray($users, $meetings, \Illuminate\Support\Collection $usersMeetings)
322 322
     {
323
-        $ret = [];
324
-        foreach($users as $user)
323
+        $ret = [ ];
324
+        foreach ($users as $user)
325 325
         {
326 326
             $usersMeetingsTmp = $usersMeetings->get($user);
327
-            foreach($meetings as $meeting){
328
-                if($usersMeetingsTmp->contains('meeting_id', $meeting)){
329
-                    $ret[$user][$meeting] = 1;
330
-                }else{
331
-                    $ret[$user][$meeting] = 0;
327
+            foreach ($meetings as $meeting) {
328
+                if ($usersMeetingsTmp->contains('meeting_id', $meeting)) {
329
+                    $ret[ $user ][ $meeting ] = 1;
330
+                } else {
331
+                    $ret[ $user ][ $meeting ] = 0;
332 332
                 }
333 333
             }
334 334
         }
@@ -338,7 +338,7 @@  discard block
 block discarded – undo
338 338
 
339 339
     private function timeSlotsConverter($item)
340 340
     {
341
-        return $item->each(function($item2){
341
+        return $item->each(function($item2) {
342 342
             $item2->time_start = $this->toTimeSlot($item2->time_start);
343 343
             $item2->time_end = $this->toTimeSlot($item2->time_end);
344 344
             return $item2;
@@ -351,13 +351,13 @@  discard block
 block discarded – undo
351 351
      * @param bool|true $free if true the array is filled with 1 for timeslots values else with 0 for timeslots values
352 352
      * @return array
353 353
      */
354
-    static private function getAvailabilityArray(\Illuminate\Support\Collection $timeSlots, $timeslotsN, $free=true)
354
+    static private function getAvailabilityArray(\Illuminate\Support\Collection $timeSlots, $timeslotsN, $free = true)
355 355
     {
356
-        $ret = [];
357
-        foreach($timeSlots as $id=>$timeSlots2)
356
+        $ret = [ ];
357
+        foreach ($timeSlots as $id=>$timeSlots2)
358 358
         {
359
-            $ret = self::fillTimeSlots($ret, $id, $timeSlots2, $free?'1':'0');
360
-            $ret = self::fillRow($ret, $id, $timeslotsN, $free?'0':'1');
359
+            $ret = self::fillTimeSlots($ret, $id, $timeSlots2, $free ? '1' : '0');
360
+            $ret = self::fillRow($ret, $id, $timeslotsN, $free ? '0' : '1');
361 361
         }
362 362
 
363 363
         return $ret;
@@ -372,10 +372,10 @@  discard block
 block discarded – undo
372 372
      */
373 373
     static private function fillTimeSlots(array $array, $id, \Illuminate\Support\Collection $timeSlots, $fill = '0')
374 374
     {
375
-        foreach($timeSlots as $timeSlot) {
376
-            if(!isset($array[$id]))
377
-                $array[$id] = [];
378
-            $array[$id] = self::arrayPadInterval($array[$id], $timeSlot->time_start, $timeSlot->time_end, $fill);
375
+        foreach ($timeSlots as $timeSlot) {
376
+            if (!isset($array[ $id ]))
377
+                $array[ $id ] = [ ];
378
+            $array[ $id ] = self::arrayPadInterval($array[ $id ], $timeSlot->time_start, $timeSlot->time_end, $fill);
379 379
         }
380 380
         return $array;
381 381
     }
@@ -388,9 +388,9 @@  discard block
 block discarded – undo
388 388
      */
389 389
     static private function fillRow(array $array, $id, $until, $fill = '0')
390 390
     {
391
-        for($i = 1; $i <= $until; $i++){
392
-            if(!isset($array[$id][$i]))
393
-                $array[$id][$i] = $fill;
391
+        for ($i = 1; $i <= $until; $i++) {
392
+            if (!isset($array[ $id ][ $i ]))
393
+                $array[ $id ][ $i ] = $fill;
394 394
         }
395 395
 
396 396
         return $array;
@@ -405,8 +405,8 @@  discard block
 block discarded – undo
405 405
      */
406 406
     static private function arrayPadInterval(array $array, $from, $to, $pad = '0')
407 407
     {
408
-        for($i = $from; $i<$to; $i++)
409
-            $array[$i] = $pad;
408
+        for ($i = $from; $i < $to; $i++)
409
+            $array[ $i ] = $pad;
410 410
         return $array;
411 411
     }
412 412
 
@@ -420,14 +420,14 @@  discard block
 block discarded – undo
420 420
     {
421 421
         $dateTime = new \DateTime($time);
422 422
         $diff = $dateTime->diff($this->startTime);
423
-        $diff = explode(':',$diff->format('%R:%d:%h:%i:%s'));
424
-        $diff = $diff[1]*86400 + $diff[2]*3600 + $diff[3]*60 + $diff[4];
423
+        $diff = explode(':', $diff->format('%R:%d:%h:%i:%s'));
424
+        $diff = $diff[ 1 ] * 86400 + $diff[ 2 ] * 3600 + $diff[ 3 ] * 60 + $diff[ 4 ];
425 425
         //if($diff[0] != '-' && $diff != 0)
426 426
           //  throw new OptimiseException('timeslot time <= startTime');
427 427
         //TODO fix check
428 428
         //TODO check if diff makes sense
429 429
         //TODO check upper limit
430
-        return (int)(round($diff/self::TIME_SLOT_DURATION)+1); //TODO can round cause overlaps?
430
+        return (int) (round($diff / self::TIME_SLOT_DURATION) + 1); //TODO can round cause overlaps?
431 431
     }
432 432
 
433 433
     /**
@@ -437,6 +437,6 @@  discard block
 block discarded – undo
437 437
     private function toDateTime($timeslot)
438 438
     {
439 439
         $ret = clone $this->startTime;
440
-        return $ret->add(new \DateInterval('PT'.(($timeslot-1)*self::TIME_SLOT_DURATION).'S'));
440
+        return $ret->add(new \DateInterval('PT'.(($timeslot - 1) * self::TIME_SLOT_DURATION).'S'));
441 441
     }
442 442
 }
443 443
\ No newline at end of file
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.
app/Console/Commands/Optimise/Solver.php 4 patches
Doc Comments   +15 added lines, -13 removed lines patch added patch discarded remove patch
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 
120 120
     /**
121 121
      * remove a no empty dir
122
-     * @param $dir
122
+     * @param string $dir
123 123
      * @return bool
124 124
      */
125 125
     private static function delTree($dir) {
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
     }
174 174
 
175 175
     /**
176
-     * @return \string[]
176
+     * @return string[]
177 177
      */
178 178
     public function getUsers()
179 179
     {
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
     }
192 192
 
193 193
     /**
194
-     * @return \string[]
194
+     * @return string[]
195 195
      */
196 196
     public function getMeetings()
197 197
     {
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
     }
254 254
 
255 255
     /**
256
-     * @return \string[]
256
+     * @return string[]
257 257
      */
258 258
     public function getMeetingsAvailability()
259 259
     {
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
     }
283 283
 
284 284
     /**
285
-     * @return \string[]
285
+     * @return string[]
286 286
      */
287 287
     public function getMeetingsDuration()
288 288
     {
@@ -312,7 +312,7 @@  discard block
 block discarded – undo
312 312
     }
313 313
 
314 314
     /**
315
-     * @return \string[]
315
+     * @return string[]
316 316
      */
317 317
     public function getUsersAvailability()
318 318
     {
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
     }
343 343
 
344 344
     /**
345
-     * @return \string[]
345
+     * @return string[]
346 346
      */
347 347
     public function getUsersMeetings()
348 348
     {
@@ -419,7 +419,7 @@  discard block
 block discarded – undo
419 419
 
420 420
     /**
421 421
      * @param string $file
422
-     * @param array $data
422
+     * @param string[] $data
423 423
      * @throws OptimiseException
424 424
      */
425 425
     static private function writeCSVArrayNoKey($file, $data)
@@ -435,7 +435,7 @@  discard block
 block discarded – undo
435 435
 
436 436
     /**
437 437
      * @param string $file
438
-     * @param array $data
438
+     * @param string[] $data
439 439
      * @param string $name
440 440
      * @throws OptimiseException
441 441
      */
@@ -452,7 +452,7 @@  discard block
 block discarded – undo
452 452
 
453 453
     /**
454 454
      * @param string $file
455
-     * @param array $data
455
+     * @param string[] $data
456 456
      * @param string $name
457 457
      * @throws OptimiseException
458 458
      */
@@ -471,7 +471,7 @@  discard block
 block discarded – undo
471 471
     /**
472 472
      * @param string $file
473 473
      * @param array $data
474
-     * @param array $heading
474
+     * @param string[] $heading
475 475
      * @param \Closure $writer
476 476
      * @throws OptimiseException
477 477
      */
@@ -682,7 +682,7 @@  discard block
 block discarded – undo
682 682
     }
683 683
 
684 684
     /**
685
-     * @param $proprieties
685
+     * @param string[] $proprieties
686 686
      * @throws OptimiseException
687 687
      */
688 688
     private function checkArrayProprieties($proprieties)
@@ -693,7 +693,7 @@  discard block
 block discarded – undo
693 693
     }
694 694
 
695 695
     /**
696
-     * @param $proprieties
696
+     * @param string[] $proprieties
697 697
      * @throws OptimiseException
698 698
      */
699 699
     private function checkIntProprieties($proprieties)
@@ -707,6 +707,8 @@  discard block
 block discarded – undo
707 707
      * implementation of arraypad that doesn't change original keys<br/>
708 708
      * <strong>CAUTION: Only positive $len</strong>
709 709
      * @param array $array
710
+     * @param integer $len
711
+     * @param integer $pad
710 712
      * @return array
711 713
      */
712 714
     static private function arrayPad(array $array, $len, $pad)
Please login to merge, or discard this patch.
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.
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
      */
114 114
     static private function checkGlpsol()
115 115
     {
116
-        if(!(`which glpsol`))
116
+        if (!(`which glpsol`))
117 117
             throw new OptimiseException('glpsol is not installed');
118 118
     }
119 119
 
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
      * @return bool
124 124
      */
125 125
     private static function delTree($dir) {
126
-        $files = array_diff(scandir($dir), array('.','..'));
126
+        $files = array_diff(scandir($dir), array('.', '..'));
127 127
         foreach ($files as $file) {
128 128
             (is_dir("$dir/$file")) ? delTree("$dir/$file") : unlink("$dir/$file");
129 129
         }
@@ -138,11 +138,11 @@  discard block
 block discarded – undo
138 138
     {
139 139
         $this->path = tempnam(sys_get_temp_dir(), 'OPT'); //TODO check the return in case of errors this return false on failure
140 140
         unlink($this->path); //remove file to create a dir
141
-        if(file_exists($this->path))
141
+        if (file_exists($this->path))
142 142
             throw new OptimiseException('problem during creation of tmp dir (the directory already exists)');
143
-        if(!@mkdir($this->path))
144
-            throw new OptimiseException('problem during creation of tmp dir (mkdir problem)');;
145
-        if(! is_dir($this->path))
143
+        if (!@mkdir($this->path))
144
+            throw new OptimiseException('problem during creation of tmp dir (mkdir problem)'); ;
145
+        if (!is_dir($this->path))
146 146
             throw new OptimiseException('problem during creation of tmp dir (it is not possible to create directory)');
147 147
     }
148 148
 
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
      */
224 224
     public function setTimeSlots($timeSlots)
225 225
     {
226
-        if(!is_int($timeSlots) || $timeSlots <=0)
226
+        if (!is_int($timeSlots) || $timeSlots <= 0)
227 227
             throw new OptimiseException('$timeSlots is not integer or it is not >0');
228 228
 
229 229
         $this->timeSlots = $timeSlots;
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
      */
246 246
     public function setMaxTimeSlots($maxTimeSlots)
247 247
     {
248
-        if(!is_int($maxTimeSlots) || $maxTimeSlots <=0)
248
+        if (!is_int($maxTimeSlots) || $maxTimeSlots <= 0)
249 249
             throw new OptimiseException('$maxTimeSlots is not integer or it is not >0');
250 250
 
251 251
         $this->maxTimeSlots = $maxTimeSlots;
@@ -268,13 +268,13 @@  discard block
 block discarded – undo
268 268
     public function setMeetingsAvailability($meetingsAvailability)
269 269
     {
270 270
         $meetings = array_keys($meetingsAvailability);
271
-        if(array_diff($meetings, $this->meetings))
271
+        if (array_diff($meetings, $this->meetings))
272 272
             throw new OptimiseException('meetings different from meetings set');
273
-        foreach($meetingsAvailability as $key=>$meetingsAvailabilityS) {
273
+        foreach ($meetingsAvailability as $key=>$meetingsAvailabilityS) {
274 274
             $timeSlots = array_keys($meetingsAvailabilityS);
275
-            if(count($timeSlots) != $this->timeSlots)
275
+            if (count($timeSlots) != $this->timeSlots)
276 276
                 throw new OptimiseException('timeSlots different from timeSlots set');
277
-            $meetingsAvailability[$key] = self::arrayPad($meetingsAvailabilityS, $this->timeSlots + $this->maxTimeSlots, 0);
277
+            $meetingsAvailability[ $key ] = self::arrayPad($meetingsAvailabilityS, $this->timeSlots + $this->maxTimeSlots, 0);
278 278
         }
279 279
 
280 280
         $this->meetingsAvailability = $meetingsAvailability;
@@ -297,13 +297,13 @@  discard block
 block discarded – undo
297 297
     public function setMeetingsDuration($meetingsDuration)
298 298
     {
299 299
         $meetings = array_keys($meetingsDuration);
300
-        if(array_diff($meetings, $this->meetings)) {
300
+        if (array_diff($meetings, $this->meetings)) {
301 301
             print "";
302 302
             throw new OptimiseException('meetings different from meetings set');
303 303
         }
304
-        foreach($meetingsDuration as $duration) {
304
+        foreach ($meetingsDuration as $duration) {
305 305
             $duration = (int) $duration; //TODO fix this (fix for optimise)
306
-            if(!is_int($duration) || $duration <=0)
306
+            if (!is_int($duration) || $duration <= 0)
307 307
                 throw new OptimiseException('duration is not integer or it is not >0');
308 308
         }
309 309
 
@@ -327,14 +327,14 @@  discard block
 block discarded – undo
327 327
     public function setUsersAvailability($usersAvailability)
328 328
     {
329 329
         $users = array_keys($usersAvailability);
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($usersAvailability as $key=>$usersAvailabilityS) {
332
+        foreach ($usersAvailability as $key=>$usersAvailabilityS) {
333 333
             $timeSlots = array_keys($usersAvailabilityS);
334
-            if(count($timeSlots) != $this->timeSlots)
334
+            if (count($timeSlots) != $this->timeSlots)
335 335
                 throw new OptimiseException('timeSlots different from timeSlots set');
336 336
 
337
-            $usersAvailability[$key] = self::arrayPad($usersAvailabilityS, $this->timeSlots + $this->maxTimeSlots, 0);
337
+            $usersAvailability[ $key ] = self::arrayPad($usersAvailabilityS, $this->timeSlots + $this->maxTimeSlots, 0);
338 338
         }
339 339
 
340 340
         $this->usersAvailability = $usersAvailability;
@@ -357,11 +357,11 @@  discard block
 block discarded – undo
357 357
     public function setUsersMeetings($usersMeetings)
358 358
     {
359 359
         $users = array_keys($usersMeetings);
360
-        if(array_diff($users, $this->users))
360
+        if (array_diff($users, $this->users))
361 361
             throw new OptimiseException('users different from users set');
362
-        foreach($usersMeetings as $usersMeetingsS) {
362
+        foreach ($usersMeetings as $usersMeetingsS) {
363 363
             $meetings = array_keys($usersMeetingsS);
364
-            if(array_diff($meetings, $this->meetings))
364
+            if (array_diff($meetings, $this->meetings))
365 365
                 throw new OptimiseException('meetings different from meetings set');
366 366
         }
367 367
 
@@ -424,13 +424,13 @@  discard block
 block discarded – undo
424 424
      */
425 425
     static private function writeCSVArrayNoKey($file, $data)
426 426
     {
427
-        $f = function ($fp, $data){
427
+        $f = function($fp, $data) {
428 428
             foreach ($data as $field) {
429
-                fputcsv($fp, [$field]);
429
+                fputcsv($fp, [ $field ]);
430 430
             }
431 431
         };
432 432
 
433
-        self::writeCSV($file, $data, ['i'], $f);
433
+        self::writeCSV($file, $data, [ 'i' ], $f);
434 434
     }
435 435
 
436 436
     /**
@@ -441,13 +441,13 @@  discard block
 block discarded – undo
441 441
      */
442 442
     static private function writeCSVArray($file, $data, $name)
443 443
     {
444
-        $f = function ($fp, $data){
444
+        $f = function($fp, $data) {
445 445
             foreach ($data as $key=>$field) {
446
-                fputcsv($fp, [$key, $field]);
446
+                fputcsv($fp, [ $key, $field ]);
447 447
             }
448 448
         };
449 449
 
450
-        self::writeCSV($file, $data, ['i', $name], $f);
450
+        self::writeCSV($file, $data, [ 'i', $name ], $f);
451 451
     }
452 452
 
453 453
     /**
@@ -458,14 +458,14 @@  discard block
 block discarded – undo
458 458
      */
459 459
     static private function writeCSVMatrix($file, $data, $name)
460 460
     {
461
-        $f = function ($fp, $data){
461
+        $f = function($fp, $data) {
462 462
             foreach ($data as $key=>$field) {
463 463
                 foreach ($field as $key2=>$field2)
464
-                    fputcsv($fp, [$key, $key2, $field2]);
464
+                    fputcsv($fp, [ $key, $key2, $field2 ]);
465 465
             }
466 466
         };
467 467
 
468
-        self::writeCSV($file, $data, ['i', 'j', $name], $f);
468
+        self::writeCSV($file, $data, [ 'i', 'j', $name ], $f);
469 469
     }
470 470
 
471 471
     /**
@@ -478,7 +478,7 @@  discard block
 block discarded – undo
478 478
     static private function writeCSV($file, $data, $heading, \Closure $writer)
479 479
     {
480 480
         $fp = @fopen($file, 'w');
481
-        if(!$fp)
481
+        if (!$fp)
482 482
             throw new OptimiseException('problem during creation of a file');
483 483
 
484 484
         fputcsv($fp, $heading);
@@ -498,8 +498,8 @@  discard block
 block discarded – undo
498 498
     {
499 499
         $this->writeData();
500 500
         $this->writeModelFile();
501
-        $event = $this->schedule->exec('glpsol --math '.$this->getModelPath())->sendOutputTo($this->getOutputPath())->after(function () { }); //this just to execute in foreground
502
-        if($event->isDue($this->laravel))
501
+        $event = $this->schedule->exec('glpsol --math '.$this->getModelPath())->sendOutputTo($this->getOutputPath())->after(function() { }); //this just to execute in foreground
502
+        if ($event->isDue($this->laravel))
503 503
             $event->run($this->laravel);
504 504
         //TODO catch glpsol errors
505 505
         return $this;
@@ -513,9 +513,9 @@  discard block
 block discarded – undo
513 513
         $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}');
514 514
         $strReplaceR = array($this->getUsersPath(), $this->getMeetingsPath(), $this->getUsersAvailabilityPath(), $this->getMeetingsAvailabilityPath(), $this->getUsersMeetingsPath(), $this->getMeetingsDurationPath(), $this->timeSlots, $this->maxTimeSlots, $this->getXPath(), $this->getYPath());
515 515
         $f = @fopen($this->getModelPath(), "w");
516
-        if(!$f)
516
+        if (!$f)
517 517
             throw new OptimiseException('problem during creation of a file');
518
-        fwrite($f, str_replace($strReplaceS, $strReplaceR, file_get_contents(__DIR__ . "/model.stub")));
518
+        fwrite($f, str_replace($strReplaceS, $strReplaceR, file_get_contents(__DIR__."/model.stub")));
519 519
         fclose($f);
520 520
     }
521 521
 
@@ -543,7 +543,7 @@  discard block
 block discarded – undo
543 543
      */
544 544
     public function getOutput()
545 545
     {
546
-        if(!($data = file_get_contents($this->getOutputPath())))
546
+        if (!($data = file_get_contents($this->getOutputPath())))
547 547
             throw new OptimiseException('problems during reading the file');
548 548
         return $data;
549 549
     }
@@ -555,22 +555,22 @@  discard block
 block discarded – undo
555 555
      */
556 556
     static private function readCSVFile($file)
557 557
     {
558
-        if(!file_exists($file) || !filesize($file))
558
+        if (!file_exists($file) || !filesize($file))
559 559
             throw new OptimiseException('no results file');
560 560
 
561
-        $handle = @fopen($file,"r");
562
-        if(!$handle)
561
+        $handle = @fopen($file, "r");
562
+        if (!$handle)
563 563
             throw new OptimiseException('problems during reading the file');
564 564
 
565
-        $ret = [];
565
+        $ret = [ ];
566 566
         fgetcsv($handle); //skip head
567 567
         while (($data = fgetcsv($handle)) !== FALSE) {
568
-            if(count($data) != 3) {
568
+            if (count($data) != 3) {
569 569
                 fclose($handle);
570 570
                 throw new OptimiseException('problems during parsing the file');
571 571
             }
572 572
 
573
-            $ret[$data[0]][$data[1]] = $data[2];
573
+            $ret[ $data[ 0 ] ][ $data[ 1 ] ] = $data[ 2 ];
574 574
         }
575 575
 
576 576
         fclose($handle);
@@ -677,8 +677,8 @@  discard block
 block discarded – undo
677 677
      */
678 678
     private function checkData()
679 679
     {
680
-        $this->checkArrayProprieties(['users', 'meetings', 'meetingsAvailability', 'meetingsDuration', 'usersAvailability', 'usersMeetings']);
681
-        $this->checkIntProprieties(['timeSlots', 'maxTimeSlots']);
680
+        $this->checkArrayProprieties([ 'users', 'meetings', 'meetingsAvailability', 'meetingsDuration', 'usersAvailability', 'usersMeetings' ]);
681
+        $this->checkIntProprieties([ 'timeSlots', 'maxTimeSlots' ]);
682 682
     }
683 683
 
684 684
     /**
@@ -687,8 +687,8 @@  discard block
 block discarded – undo
687 687
      */
688 688
     private function checkArrayProprieties($proprieties)
689 689
     {
690
-        foreach($proprieties as $propriety)
691
-            if(count($this->$propriety)==0)
690
+        foreach ($proprieties as $propriety)
691
+            if (count($this->$propriety) == 0)
692 692
                 throw new OptimiseException($propriety.' is not set correctly');
693 693
     }
694 694
 
@@ -698,8 +698,8 @@  discard block
 block discarded – undo
698 698
      */
699 699
     private function checkIntProprieties($proprieties)
700 700
     {
701
-        foreach($proprieties as $propriety)
702
-            if(!is_int($this->$propriety) || $this->$propriety <= 0)
701
+        foreach ($proprieties as $propriety)
702
+            if (!is_int($this->$propriety) || $this->$propriety <= 0)
703 703
                 throw new OptimiseException($propriety.' is not set correctly');
704 704
     }
705 705
 
@@ -712,8 +712,8 @@  discard block
 block discarded – undo
712 712
     static private function arrayPad(array $array, $len, $pad)
713 713
     {
714 714
         $len = $len - count($array);
715
-        for($i = 0; $i<$len; $i++)
716
-            $array[] = $pad;
715
+        for ($i = 0; $i < $len; $i++)
716
+            $array[ ] = $pad;
717 717
         return $array;
718 718
     }
719 719
 }
720 720
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +73 added lines, -48 removed lines patch added patch discarded remove patch
@@ -104,8 +104,9 @@  discard block
 block discarded – undo
104 104
      */
105 105
     function __destruct()
106 106
     {
107
-        if ($this->path && is_dir($this->path) && !self::delTree($this->path))
108
-            throw new OptimiseException('problems during removing of path directory');
107
+        if ($this->path && is_dir($this->path) && !self::delTree($this->path)) {
108
+                    throw new OptimiseException('problems during removing of path directory');
109
+        }
109 110
     }
110 111
 
111 112
     /**
@@ -113,8 +114,9 @@  discard block
 block discarded – undo
113 114
      */
114 115
     static private function checkGlpsol()
115 116
     {
116
-        if(!(`which glpsol`))
117
-            throw new OptimiseException('glpsol is not installed');
117
+        if(!(`which glpsol`)) {
118
+                    throw new OptimiseException('glpsol is not installed');
119
+        }
118 120
     }
119 121
 
120 122
     /**
@@ -138,12 +140,16 @@  discard block
 block discarded – undo
138 140
     {
139 141
         $this->path = tempnam(sys_get_temp_dir(), 'OPT'); //TODO check the return in case of errors this return false on failure
140 142
         unlink($this->path); //remove file to create a dir
141
-        if(file_exists($this->path))
142
-            throw new OptimiseException('problem during creation of tmp dir (the directory already exists)');
143
-        if(!@mkdir($this->path))
144
-            throw new OptimiseException('problem during creation of tmp dir (mkdir problem)');;
145
-        if(! is_dir($this->path))
146
-            throw new OptimiseException('problem during creation of tmp dir (it is not possible to create directory)');
143
+        if(file_exists($this->path)) {
144
+                    throw new OptimiseException('problem during creation of tmp dir (the directory already exists)');
145
+        }
146
+        if(!@mkdir($this->path)) {
147
+                    throw new OptimiseException('problem during creation of tmp dir (mkdir problem)');
148
+        }
149
+        ;
150
+        if(! is_dir($this->path)) {
151
+                    throw new OptimiseException('problem during creation of tmp dir (it is not possible to create directory)');
152
+        }
147 153
     }
148 154
 
149 155
     /**
@@ -223,8 +229,9 @@  discard block
 block discarded – undo
223 229
      */
224 230
     public function setTimeSlots($timeSlots)
225 231
     {
226
-        if(!is_int($timeSlots) || $timeSlots <=0)
227
-            throw new OptimiseException('$timeSlots is not integer or it is not >0');
232
+        if(!is_int($timeSlots) || $timeSlots <=0) {
233
+                    throw new OptimiseException('$timeSlots is not integer or it is not >0');
234
+        }
228 235
 
229 236
         $this->timeSlots = $timeSlots;
230 237
         return $this;
@@ -245,8 +252,9 @@  discard block
 block discarded – undo
245 252
      */
246 253
     public function setMaxTimeSlots($maxTimeSlots)
247 254
     {
248
-        if(!is_int($maxTimeSlots) || $maxTimeSlots <=0)
249
-            throw new OptimiseException('$maxTimeSlots is not integer or it is not >0');
255
+        if(!is_int($maxTimeSlots) || $maxTimeSlots <=0) {
256
+                    throw new OptimiseException('$maxTimeSlots is not integer or it is not >0');
257
+        }
250 258
 
251 259
         $this->maxTimeSlots = $maxTimeSlots;
252 260
         return $this;
@@ -268,12 +276,14 @@  discard block
 block discarded – undo
268 276
     public function setMeetingsAvailability($meetingsAvailability)
269 277
     {
270 278
         $meetings = array_keys($meetingsAvailability);
271
-        if(array_diff($meetings, $this->meetings))
272
-            throw new OptimiseException('meetings different from meetings set');
279
+        if(array_diff($meetings, $this->meetings)) {
280
+                    throw new OptimiseException('meetings different from meetings set');
281
+        }
273 282
         foreach($meetingsAvailability as $key=>$meetingsAvailabilityS) {
274 283
             $timeSlots = array_keys($meetingsAvailabilityS);
275
-            if(count($timeSlots) != $this->timeSlots)
276
-                throw new OptimiseException('timeSlots different from timeSlots set');
284
+            if(count($timeSlots) != $this->timeSlots) {
285
+                            throw new OptimiseException('timeSlots different from timeSlots set');
286
+            }
277 287
             $meetingsAvailability[$key] = self::arrayPad($meetingsAvailabilityS, $this->timeSlots + $this->maxTimeSlots, 0);
278 288
         }
279 289
 
@@ -303,8 +313,9 @@  discard block
 block discarded – undo
303 313
         }
304 314
         foreach($meetingsDuration as $duration) {
305 315
             $duration = (int) $duration; //TODO fix this (fix for optimise)
306
-            if(!is_int($duration) || $duration <=0)
307
-                throw new OptimiseException('duration is not integer or it is not >0');
316
+            if(!is_int($duration) || $duration <=0) {
317
+                            throw new OptimiseException('duration is not integer or it is not >0');
318
+            }
308 319
         }
309 320
 
310 321
         $this->meetingsDuration = $meetingsDuration;
@@ -327,12 +338,14 @@  discard block
 block discarded – undo
327 338
     public function setUsersAvailability($usersAvailability)
328 339
     {
329 340
         $users = array_keys($usersAvailability);
330
-        if(array_diff($users, $this->users))
331
-            throw new OptimiseException('users different from users set');
341
+        if(array_diff($users, $this->users)) {
342
+                    throw new OptimiseException('users different from users set');
343
+        }
332 344
         foreach($usersAvailability as $key=>$usersAvailabilityS) {
333 345
             $timeSlots = array_keys($usersAvailabilityS);
334
-            if(count($timeSlots) != $this->timeSlots)
335
-                throw new OptimiseException('timeSlots different from timeSlots set');
346
+            if(count($timeSlots) != $this->timeSlots) {
347
+                            throw new OptimiseException('timeSlots different from timeSlots set');
348
+            }
336 349
 
337 350
             $usersAvailability[$key] = self::arrayPad($usersAvailabilityS, $this->timeSlots + $this->maxTimeSlots, 0);
338 351
         }
@@ -357,12 +370,14 @@  discard block
 block discarded – undo
357 370
     public function setUsersMeetings($usersMeetings)
358 371
     {
359 372
         $users = array_keys($usersMeetings);
360
-        if(array_diff($users, $this->users))
361
-            throw new OptimiseException('users different from users set');
373
+        if(array_diff($users, $this->users)) {
374
+                    throw new OptimiseException('users different from users set');
375
+        }
362 376
         foreach($usersMeetings as $usersMeetingsS) {
363 377
             $meetings = array_keys($usersMeetingsS);
364
-            if(array_diff($meetings, $this->meetings))
365
-                throw new OptimiseException('meetings different from meetings set');
378
+            if(array_diff($meetings, $this->meetings)) {
379
+                            throw new OptimiseException('meetings different from meetings set');
380
+            }
366 381
         }
367 382
 
368 383
         $this->usersMeetings = $usersMeetings;
@@ -460,8 +475,9 @@  discard block
 block discarded – undo
460 475
     {
461 476
         $f = function ($fp, $data){
462 477
             foreach ($data as $key=>$field) {
463
-                foreach ($field as $key2=>$field2)
464
-                    fputcsv($fp, [$key, $key2, $field2]);
478
+                foreach ($field as $key2=>$field2) {
479
+                                    fputcsv($fp, [$key, $key2, $field2]);
480
+                }
465 481
             }
466 482
         };
467 483
 
@@ -478,8 +494,9 @@  discard block
 block discarded – undo
478 494
     static private function writeCSV($file, $data, $heading, \Closure $writer)
479 495
     {
480 496
         $fp = @fopen($file, 'w');
481
-        if(!$fp)
482
-            throw new OptimiseException('problem during creation of a file');
497
+        if(!$fp) {
498
+                    throw new OptimiseException('problem during creation of a file');
499
+        }
483 500
 
484 501
         fputcsv($fp, $heading);
485 502
 
@@ -499,8 +516,9 @@  discard block
 block discarded – undo
499 516
         $this->writeData();
500 517
         $this->writeModelFile();
501 518
         $event = $this->schedule->exec('glpsol --math '.$this->getModelPath())->sendOutputTo($this->getOutputPath())->after(function () { }); //this just to execute in foreground
502
-        if($event->isDue($this->laravel))
503
-            $event->run($this->laravel);
519
+        if($event->isDue($this->laravel)) {
520
+                    $event->run($this->laravel);
521
+        }
504 522
         //TODO catch glpsol errors
505 523
         return $this;
506 524
     }
@@ -513,8 +531,9 @@  discard block
 block discarded – undo
513 531
         $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}');
514 532
         $strReplaceR = array($this->getUsersPath(), $this->getMeetingsPath(), $this->getUsersAvailabilityPath(), $this->getMeetingsAvailabilityPath(), $this->getUsersMeetingsPath(), $this->getMeetingsDurationPath(), $this->timeSlots, $this->maxTimeSlots, $this->getXPath(), $this->getYPath());
515 533
         $f = @fopen($this->getModelPath(), "w");
516
-        if(!$f)
517
-            throw new OptimiseException('problem during creation of a file');
534
+        if(!$f) {
535
+                    throw new OptimiseException('problem during creation of a file');
536
+        }
518 537
         fwrite($f, str_replace($strReplaceS, $strReplaceR, file_get_contents(__DIR__ . "/model.stub")));
519 538
         fclose($f);
520 539
     }
@@ -543,8 +562,9 @@  discard block
 block discarded – undo
543 562
      */
544 563
     public function getOutput()
545 564
     {
546
-        if(!($data = file_get_contents($this->getOutputPath())))
547
-            throw new OptimiseException('problems during reading the file');
565
+        if(!($data = file_get_contents($this->getOutputPath()))) {
566
+                    throw new OptimiseException('problems during reading the file');
567
+        }
548 568
         return $data;
549 569
     }
550 570
 
@@ -555,12 +575,14 @@  discard block
 block discarded – undo
555 575
      */
556 576
     static private function readCSVFile($file)
557 577
     {
558
-        if(!file_exists($file) || !filesize($file))
559
-            throw new OptimiseException('no results file');
578
+        if(!file_exists($file) || !filesize($file)) {
579
+                    throw new OptimiseException('no results file');
580
+        }
560 581
 
561 582
         $handle = @fopen($file,"r");
562
-        if(!$handle)
563
-            throw new OptimiseException('problems during reading the file');
583
+        if(!$handle) {
584
+                    throw new OptimiseException('problems during reading the file');
585
+        }
564 586
 
565 587
         $ret = [];
566 588
         fgetcsv($handle); //skip head
@@ -687,9 +709,10 @@  discard block
 block discarded – undo
687 709
      */
688 710
     private function checkArrayProprieties($proprieties)
689 711
     {
690
-        foreach($proprieties as $propriety)
691
-            if(count($this->$propriety)==0)
712
+        foreach($proprieties as $propriety) {
713
+                    if(count($this->$propriety)==0)
692 714
                 throw new OptimiseException($propriety.' is not set correctly');
715
+        }
693 716
     }
694 717
 
695 718
     /**
@@ -698,9 +721,10 @@  discard block
 block discarded – undo
698 721
      */
699 722
     private function checkIntProprieties($proprieties)
700 723
     {
701
-        foreach($proprieties as $propriety)
702
-            if(!is_int($this->$propriety) || $this->$propriety <= 0)
724
+        foreach($proprieties as $propriety) {
725
+                    if(!is_int($this->$propriety) || $this->$propriety <= 0)
703 726
                 throw new OptimiseException($propriety.' is not set correctly');
727
+        }
704 728
     }
705 729
 
706 730
     /**
@@ -712,8 +736,9 @@  discard block
 block discarded – undo
712 736
     static private function arrayPad(array $array, $len, $pad)
713 737
     {
714 738
         $len = $len - count($array);
715
-        for($i = 0; $i<$len; $i++)
716
-            $array[] = $pad;
739
+        for($i = 0; $i<$len; $i++) {
740
+                    $array[] = $pad;
741
+        }
717 742
         return $array;
718 743
     }
719 744
 }
720 745
\ No newline at end of file
Please login to merge, or discard this patch.