Completed
Push — master ( 730a89...20ec0c )
by Brandon
28s
created
app/Device.php 1 patch
Braces   +10 added lines, -8 removed lines patch added patch discarded remove patch
@@ -75,8 +75,9 @@  discard block
 block discarded – undo
75 75
         $time = new Carbon($value, 'UTC');
76 76
         
77 77
         //If the user is logged in then use there preferred timezone
78
-        if (Auth::check())
79
-            $time = $time->setTimezone(Auth::user()->timezone);
78
+        if (Auth::check()) {
79
+                    $time = $time->setTimezone(Auth::user()->timezone);
80
+        }
80 81
 
81 82
         return $time->format('H:i');
82 83
     }
@@ -94,8 +95,9 @@  discard block
 block discarded – undo
94 95
         $time = new Carbon($value, 'UTC');
95 96
     
96 97
         //If the user is logged in then use there preferred timezone
97
-        if (Auth::check())
98
-            $time = $time->setTimezone(Auth::user()->timezone);
98
+        if (Auth::check()) {
99
+                    $time = $time->setTimezone(Auth::user()->timezone);
100
+        }
99 101
         
100 102
         return $time->format('H:i');
101 103
     }
@@ -115,9 +117,9 @@  discard block
 block discarded – undo
115 117
         {
116 118
             $time = new Carbon($value, Auth::user()->timezone);
117 119
             $time = $time->setTimezone('UTC');
120
+        } else {
121
+                    $time = new Carbon($value, 'UTC');
118 122
         }
119
-        else
120
-            $time = new Carbon($value, 'UTC');
121 123
         
122 124
         $this->attributes['open_time'] = $time;
123 125
     }
@@ -137,9 +139,9 @@  discard block
 block discarded – undo
137 139
         {
138 140
             $time = new Carbon($value, Auth::user()->timezone);
139 141
             $time = $time->setTimezone('UTC');
142
+        } else {
143
+                    $time = new Carbon($value, 'UTC');
140 144
         }
141
-        else
142
-            $time = new Carbon($value, 'UTC');
143 145
         
144 146
         $this->attributes['close_time'] = $time;
145 147
     }
Please login to merge, or discard this patch.
app/Http/Controllers/DashboardController.php 1 patch
Braces   +21 added lines, -17 removed lines patch added patch discarded remove patch
@@ -34,8 +34,7 @@  discard block
 block discarded – undo
34 34
             //Todo use the users preferred device
35 35
             //Get the first device that doesn't have a null location_id
36 36
             $device = Device::publicDashData()->where('location_id', '!=', 'null')->orderBy('id', 'ASC')->first();
37
-        }
38
-        catch(ModelNotFoundException $e)
37
+        } catch(ModelNotFoundException $e)
39 38
         {
40 39
             //If no device is found then redirect the user to the home page and display a message about registering a device
41 40
             return redirect('home')->with('no_devices', 'To access the dashboard page there must be at least one registered device assigned to a location.');
@@ -85,14 +84,15 @@  discard block
 block discarded – undo
85 84
         //Get the given device if it is still at the same location
86 85
         $device = Device::publicDashData()->where('location_id', '=', $request->location_id)->find($request->device_id);
87 86
         
88
-        if (empty($site))                 //Check if the site still exists
87
+        if (empty($site)) {
88
+            //Check if the site still exists
89 89
         {
90 90
             try
91 91
             {
92 92
                 //Get the first site and if no sites exist throw an error
93 93
                 $site = Site::select('id', 'name')->firstOrFail();
94
-            }
95
-            catch(ModelNotFoundException $e)
94
+        }
95
+            } catch(ModelNotFoundException $e)
96 96
             {
97 97
                 //If no device is found then redirect the user to the home page and display a message about registering a device
98 98
                 return redirect('home')->with('no_devices', 'To access the dashboard page there must be at least one registered device assigned to a location.');
@@ -102,19 +102,21 @@  discard block
 block discarded – undo
102 102
             $location = $site->locations()->select('id', 'name', 'site_id')->firstOrFail();
103 103
             //Get the first device from the location
104 104
             $device = $location->devices()->publicDashData()->firstOrFail();
105
-        }
106
-        else if (empty($location))        //Check if the location still exists
105
+        } else if (empty($location)) {
106
+            //Check if the location still exists
107 107
         {
108 108
             //Get the first location from the given site
109 109
             $location = $site->locations()->select('id', 'name', 'site_id')->firstOrFail();
110
+        }
110 111
             //Get the first device from the location
111 112
             $device = $location->devices()->publicDashData()->firstOrFail();
112
-        }
113
-        else if (empty($device))        //Check if the device still exists at the given location
113
+        } else if (empty($device)) {
114
+            //Check if the device still exists at the given location
114 115
         {
115 116
             //Get the first device from the location
116 117
             $device = $location->devices()->publicDashData()->firstOrFail();
117 118
         }
119
+        }
118 120
         
119 121
         $data = $this->dashData($site, $location, $device);
120 122
         
@@ -199,8 +201,9 @@  discard block
 block discarded – undo
199 201
         ])->validate();
200 202
         
201 203
         //Check that device isn't currently in use or has an error
202
-        if ($device->cover_status === 'opening' || $device->cover_status === 'closing' || $device->cover_status === 'error')
203
-            return response()->json("Device is currently in use.", 403);
204
+        if ($device->cover_status === 'opening' || $device->cover_status === 'closing' || $device->cover_status === 'error') {
205
+                    return response()->json("Device is currently in use.", 403);
206
+        }
204 207
         
205 208
         //1 = open, 2 = close, 3 = lock
206 209
         switch($request->command)
@@ -238,13 +241,14 @@  discard block
 block discarded – undo
238 241
             $time_now = Carbon::now(Auth::user()->timezone);
239 242
             
240 243
             //Check if the current time is during the open schedule or not
241
-            if (($time_now > $open_time) && ($time_now < $close_time))
242
-                $command =  'open';
243
-            else
244
-                $command =  'close';
244
+            if (($time_now > $open_time) && ($time_now < $close_time)) {
245
+                            $command =  'open';
246
+            } else {
247
+                            $command =  'close';
248
+            }
249
+        } else {
250
+                    $command =  'lock';
245 251
         }
246
-        else
247
-            $command =  'lock';
248 252
         
249 253
         return $command;
250 254
     }
Please login to merge, or discard this patch.
app/Http/Controllers/SensorController.php 1 patch
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -10,42 +10,42 @@  discard block
 block discarded – undo
10 10
 class SensorController extends Controller 
11 11
 {
12 12
     /**
13
-    * Create a new controller instance.
14
-    *
15
-    * @return void
16
-    */
13
+     * Create a new controller instance.
14
+     *
15
+     * @return void
16
+     */
17 17
     public function __construct()
18 18
     {
19 19
         $this->middleware('auth');
20 20
     }
21 21
 
22 22
     /**
23
-    * Display a listing of the resource.
24
-    *
25
-    * @param  SensorDataTable   $dataTable
26
-    * @return Response
27
-    */
23
+     * Display a listing of the resource.
24
+     *
25
+     * @param  SensorDataTable   $dataTable
26
+     * @return Response
27
+     */
28 28
     public function index(SensorDataTable $dataTable)
29 29
     {
30 30
         return $dataTable->render('sensor.index');
31 31
     }
32 32
 
33 33
     /**
34
-    * Show the form for creating a new resource.
35
-    *
36
-    * @return Response
37
-    */
34
+     * Show the form for creating a new resource.
35
+     *
36
+     * @return Response
37
+     */
38 38
     public function create()
39 39
     {
40 40
         return view('sensor.create');
41 41
     }
42 42
 
43 43
     /**
44
-    * Store a newly created resource in storage.
45
-    *
46
-    * @param Request $request
47
-    * @return Response
48
-    */
44
+     * Store a newly created resource in storage.
45
+     *
46
+     * @param Request $request
47
+     * @return Response
48
+     */
49 49
     public function store(Request $request)
50 50
     {
51 51
         request()->validate([
@@ -61,12 +61,12 @@  discard block
 block discarded – undo
61 61
     }
62 62
 
63 63
     /**
64
-    * Display the specified resource.
65
-    *
66
-    * @param  Request  $request
67
-    * @param  int  $id
68
-    * @return Response
69
-    */
64
+     * Display the specified resource.
65
+     *
66
+     * @param  Request  $request
67
+     * @param  int  $id
68
+     * @return Response
69
+     */
70 70
     public function show(Request $request, $id)
71 71
     {
72 72
         $sensor = Sensor::findOrFail($id);
@@ -75,12 +75,12 @@  discard block
 block discarded – undo
75 75
     }
76 76
 
77 77
     /**
78
-    * Show the form for editing the specified resource.
79
-    *
80
-    * @param  Request  $request
81
-    * @param  int  $id
82
-    * @return Response
83
-    */
78
+     * Show the form for editing the specified resource.
79
+     *
80
+     * @param  Request  $request
81
+     * @param  int  $id
82
+     * @return Response
83
+     */
84 84
     public function edit(Request $request, $id)
85 85
     {
86 86
         $sensor = Sensor::findOrFail($id);
@@ -89,12 +89,12 @@  discard block
 block discarded – undo
89 89
     }
90 90
 
91 91
     /**
92
-    * Update the specified resource in storage.
93
-    *
94
-    * @param  Request  $request
95
-    * @param  int  $id
96
-    * @return Response
97
-    */
92
+     * Update the specified resource in storage.
93
+     *
94
+     * @param  Request  $request
95
+     * @param  int  $id
96
+     * @return Response
97
+     */
98 98
     public function update(Request $request, $id)
99 99
     {
100 100
         request()->validate([
@@ -108,11 +108,11 @@  discard block
 block discarded – undo
108 108
     }
109 109
 
110 110
     /**
111
-    * Remove the specified resource from storage.
112
-    *
113
-    * @param  int  $id
114
-    * @return Response
115
-    */
111
+     * Remove the specified resource from storage.
112
+     *
113
+     * @param  int  $id
114
+     * @return Response
115
+     */
116 116
     public function destroy($id)
117 117
     {
118 118
         Sensor::findOrFail($id)->delete();
Please login to merge, or discard this patch.
app/Http/Controllers/SensorDataController.php 1 patch
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -9,42 +9,42 @@  discard block
 block discarded – undo
9 9
 class SensorDataController extends Controller 
10 10
 {
11 11
     /**
12
-    * Create a new controller instance.
13
-    *
14
-    * @return void
15
-    */
12
+     * Create a new controller instance.
13
+     *
14
+     * @return void
15
+     */
16 16
     public function __construct()
17 17
     {
18 18
         $this->middleware('auth');
19 19
     }
20 20
 
21 21
     /**
22
-    * Display a listing of the resource.
23
-    *
24
-    * @param SensorDataDataTable $dataTable
25
-    * @return Response
26
-    */
22
+     * Display a listing of the resource.
23
+     *
24
+     * @param SensorDataDataTable $dataTable
25
+     * @return Response
26
+     */
27 27
     public function index(SensorDataDataTable $dataTable)
28 28
     {
29 29
         return $dataTable->render('sensordata.index');
30 30
     }
31 31
 
32 32
     /**
33
-    * Show the form for creating a new resource.
34
-    *
35
-    * @return Response
36
-    */
33
+     * Show the form for creating a new resource.
34
+     *
35
+     * @return Response
36
+     */
37 37
     public function create()
38 38
     {
39 39
         return view('sensordata.create');
40 40
     }
41 41
 
42 42
     /**
43
-    * Store a newly created resource in storage.
44
-    *
45
-    * @param Request $request
46
-    * @return Response
47
-    */
43
+     * Store a newly created resource in storage.
44
+     *
45
+     * @param Request $request
46
+     * @return Response
47
+     */
48 48
     public function store(Request $request)
49 49
     {
50 50
         request()->validate([
@@ -59,12 +59,12 @@  discard block
 block discarded – undo
59 59
     }
60 60
 
61 61
     /**
62
-    * Display the specified resource.
63
-    *
64
-    * @param  Request  $request
65
-    * @param  int  $id
66
-    * @return Response
67
-    */
62
+     * Display the specified resource.
63
+     *
64
+     * @param  Request  $request
65
+     * @param  int  $id
66
+     * @return Response
67
+     */
68 68
     public function show(Request $request, $id)
69 69
     {
70 70
         $sensordata = SensorData::findOrFail($id);
@@ -73,11 +73,11 @@  discard block
 block discarded – undo
73 73
     }
74 74
 
75 75
     /**
76
-    * Show the form for editing the specified resource.
77
-    *
78
-    * @param  int  $id
79
-    * @return Response
80
-    */
76
+     * Show the form for editing the specified resource.
77
+     *
78
+     * @param  int  $id
79
+     * @return Response
80
+     */
81 81
     public function edit(Request $request, $id)
82 82
     {
83 83
         $sensordata = SensorData::findOrFail($id);
@@ -86,11 +86,11 @@  discard block
 block discarded – undo
86 86
     }
87 87
 
88 88
     /**
89
-    * Update the specified resource in storage.
90
-    *
91
-    * @param  int  $id
92
-    * @return Response
93
-    */
89
+     * Update the specified resource in storage.
90
+     *
91
+     * @param  int  $id
92
+     * @return Response
93
+     */
94 94
     public function update($id)
95 95
     {
96 96
         request()->validate([
@@ -103,11 +103,11 @@  discard block
 block discarded – undo
103 103
     }
104 104
 
105 105
     /**
106
-    * Remove the specified resource from storage.
107
-    *
108
-    * @param  int  $id
109
-    * @return Response
110
-    */
106
+     * Remove the specified resource from storage.
107
+     *
108
+     * @param  int  $id
109
+     * @return Response
110
+     */
111 111
     public function destroy($id)
112 112
     {
113 113
         SensorData::find($id)->delete();
Please login to merge, or discard this patch.
app/Http/Controllers/DeviceController.php 1 patch
Braces   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -84,8 +84,7 @@  discard block
 block discarded – undo
84 84
             $sites->prepend($location->site);
85 85
             //Add the current location to the front of the collection of locations
86 86
             $locations->prepend($location);
87
-        }
88
-        else
87
+        } else
89 88
         {
90 89
             //Set locations to null since there is no site or location attached to the selected device
91 90
             $locations = null;
@@ -93,10 +92,11 @@  discard block
 block discarded – undo
93 92
             $sites = Site::all();
94 93
         }
95 94
         
96
-        if (\Request::ajax())
97
-            return response()->json([ 'device' => $device, 'locations' => $locations, 'sites' => $sites ]);
98
-        else
99
-            return view('device.edit', [ 'device' => $device, 'locations' => $locations, 'sites' => $sites ]);
95
+        if (\Request::ajax()) {
96
+                    return response()->json([ 'device' => $device, 'locations' => $locations, 'sites' => $sites ]);
97
+        } else {
98
+                    return view('device.edit', [ 'device' => $device, 'locations' => $locations, 'sites' => $sites ]);
99
+        }
100 100
     }
101 101
     
102 102
     /**
@@ -110,8 +110,9 @@  discard block
 block discarded – undo
110 110
     {
111 111
         $locations = Location::bySite($site_id)->select('id', 'name', 'site_id')->get();
112 112
         
113
-        if ($locations->isEmpty())
114
-            $locations = null;
113
+        if ($locations->isEmpty()) {
114
+                    $locations = null;
115
+        }
115 116
     
116 117
         return response()->json($locations);
117 118
     }
@@ -151,8 +152,7 @@  discard block
 block discarded – undo
151 152
             //Create a new site
152 153
             $siteName = $request->input('new_site_name');
153 154
             $site_id = Site::createSite($siteName)->id;
154
-        }
155
-        else
155
+        } else
156 156
         {
157 157
             $site_id = $request->input('site');
158 158
         }
@@ -166,8 +166,7 @@  discard block
 block discarded – undo
166 166
             //Create a new location
167 167
             $locationName = $request->input('new_location_name');
168 168
             $location_id = Location::createLocation($locationName, $site_id)->id;
169
-        }
170
-        else
169
+        } else
171 170
         {
172 171
             $location_id = $request->input('location');
173 172
         }
@@ -188,11 +187,12 @@  discard block
 block discarded – undo
188 187
         //Remove any unused sites or locations
189 188
         $this->RemoveUnusedSiteLoc();
190 189
     
191
-        if (\Request::ajax())
192
-            return response()->json("Success");
193
-        else
194
-            return redirect()->route('device.show', $id)
190
+        if (\Request::ajax()) {
191
+                    return response()->json("Success");
192
+        } else {
193
+                    return redirect()->route('device.show', $id)
195 194
                 ->with('success', 'Device updated successfully');
195
+        }
196 196
     }
197 197
 
198 198
     /**
Please login to merge, or discard this patch.
app/Http/Controllers/LocationController.php 1 patch
Braces   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -54,9 +54,9 @@  discard block
 block discarded – undo
54 54
             //Create a new site
55 55
             $site = Site::create(['name' => $request->input('new_site_name')]);
56 56
             $site_id = $site->id;
57
+        } else {
58
+                    $site_id = $request->input('site');
57 59
         }
58
-        else
59
-            $site_id = $request->input('site');
60 60
     
61 61
         $location = Location::create(['name' => $request->input('name'), 'site_id' => $site_id]);
62 62
     
@@ -107,9 +107,9 @@  discard block
 block discarded – undo
107 107
             //Create a new site
108 108
             $site = Site::create(['name' => $request->input('new_site_name')]);
109 109
             $site_id = $site->id;
110
+        } else {
111
+                    $site_id = $request->input('site');
110 112
         }
111
-        else
112
-            $site_id = $request->input('site');
113 113
         
114 114
         //Update the location with the supplied name and the site
115 115
         Location::findOrFail($id)->update(['name' => $request->input('name'), 'site_id' => $site_id]);
Please login to merge, or discard this patch.