Completed
Pull Request — develop (#143)
by Tony
04:52
created
app/DataTables/DeviceDataTable.php 1 patch
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -25,7 +25,6 @@
 block discarded – undo
25 25
 
26 26
 namespace App\DataTables;
27 27
 
28
-use App\Models\DeviceGroup;
29 28
 use App\Models\Device;
30 29
 
31 30
 class DeviceDataTable extends BaseDataTable
Please login to merge, or discard this patch.
app/Http/Controllers/DeviceController.php 2 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -3,7 +3,6 @@
 block discarded – undo
3 3
 namespace App\Http\Controllers;
4 4
 
5 5
 use App\DataTables\DeviceDataTable;
6
-use App\DataTables\DeviceGroupDataTable;
7 6
 use App\Models\DeviceGroup;
8 7
 use Dingo\Api\Http;
9 8
 use Dingo\Api\Routing\Helpers;
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -18,10 +18,10 @@
 block discarded – undo
18 18
      *
19 19
      * @return \Illuminate\Http\JsonResponse|\Illuminate\View\View
20 20
      */
21
-    public function index(DeviceDataTable $dataTable, $group_id=-1)
21
+    public function index(DeviceDataTable $dataTable, $group_id = -1)
22 22
     {
23 23
         $group_name = "";
24
-        if($group_id >= 0) {
24
+        if ($group_id >= 0) {
25 25
             $dataTable->addScope(new \App\DataTables\Scopes\DeviceGroup($group_id));
26 26
             $group_name = DeviceGroup::find($group_id)->name;
27 27
         }
Please login to merge, or discard this patch.
app/Http/Controllers/DeviceGroupController.php 3 patches
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
      * Store a newly created resource in storage.
59 59
      *
60 60
      * @param  \Illuminate\Http\Request $request
61
-     * @return \Illuminate\Http\Response
61
+     * @return \Illuminate\Http\JsonResponse
62 62
      */
63 63
     public function store(DeviceGroupRequest $request)
64 64
     {
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
      * Display the specified resource.
72 72
      *
73 73
      * @param  int $id
74
-     * @return \Illuminate\Http\Response
74
+     * @return \Illuminate\Http\RedirectResponse
75 75
      */
76 76
     public function show($id)
77 77
     {
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
      *
96 96
      * @param  \Illuminate\Http\Request $request
97 97
      * @param  int $id
98
-     * @return \Illuminate\Http\Response
98
+     * @return \Illuminate\Http\JsonResponse
99 99
      */
100 100
     public function update(DeviceGroupRequest $request, $id)
101 101
     {
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
      *
111 111
      * @param \Illuminate\Http\Request $request
112 112
      * @param  int $id
113
-     * @return \Illuminate\Http\Response
113
+     * @return \Illuminate\Http\JsonResponse
114 114
      * @throws \Exception
115 115
      */
116 116
     public function destroy(AdminOnlyRequest $request, $id)
Please login to merge, or discard this patch.
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -3,7 +3,6 @@
 block discarded – undo
3 3
 namespace App\Api\Controllers;
4 4
 
5 5
 use DB;
6
-use App\Http\Requests;
7 6
 use Illuminate\Http\Request;
8 7
 
9 8
 class ApiController extends Controller
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -195,7 +195,8 @@
 block discarded – undo
195 195
         $user = \Auth::user();
196 196
         if (!is_null($user) && $user->isAdmin()) {
197 197
             return false;
198
-        } else {
198
+        }
199
+        else {
199 200
             return 'auth';
200 201
         }
201 202
     }
Please login to merge, or discard this patch.
app/Models/DeviceGroup.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -203,7 +203,7 @@
 block discarded – undo
203 203
      * Convert a v1 device group pattern to v2 style
204 204
      *
205 205
      * @param $pattern
206
-     * @return array
206
+     * @return string
207 207
      */
208 208
     private function convertV1Pattern($pattern)
209 209
     {
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
         }
212 212
 
213 213
         foreach (Settings::get('alert.macros.group', []) as $macro => $value) {
214
-            $value = str_replace(['%', '&&', '||'], ['', 'AND', 'OR'], $value);  // this might need something more complex
214
+            $value = str_replace(['%', '&&', '||'], ['', 'AND', 'OR'], $value); // this might need something more complex
215 215
             if (!str_contains($macro, ' ')) {
216 216
                 $pattern = str_replace('macros.'.$macro, '('.$value.')', $pattern);
217 217
             }
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
         $related = $this->getRelation('deviceCountRelation')->first();
261 261
 
262 262
         // then return the count directly
263
-        return ($related) ? (int)$related->count : 0;
263
+        return ($related) ? (int) $related->count : 0;
264 264
     }
265 265
 
266 266
     /**
Please login to merge, or discard this patch.
Braces   +16 added lines, -8 removed lines patch added patch discarded remove patch
@@ -97,7 +97,8 @@  discard block
 block discarded – undo
97 97
         $query = null;
98 98
         if (count($tables) == 1) {
99 99
             $query = DB::table($tables[0])->select('device_id')->distinct();
100
-        } else {
100
+        }
101
+        else {
101 102
             $query = DB::table('devices')->select('devices.device_id')->distinct();
102 103
 
103 104
             foreach ($tables as $table) {
@@ -136,7 +137,8 @@  discard block
 block discarded – undo
136 137
             if (starts_with($cur, '%')) {
137 138
                 // table and column or macro
138 139
                 $out .= substr($cur, 1).' ';
139
-            } elseif (substr($cur, -1) == '~') {
140
+            }
141
+            elseif (substr($cur, -1) == '~') {
140 142
                 // like operator
141 143
                 $content = $parts[++$i]; // grab the content so we can format it
142 144
 
@@ -147,14 +149,18 @@  discard block
 block discarded – undo
147 149
 
148 150
                 $out .= "LIKE('".$this->convertRegexToLike($content)."') ";
149 151
 
150
-            } elseif ($cur == '&&') {
152
+            }
153
+            elseif ($cur == '&&') {
151 154
                 $out .= 'AND ';
152
-            } elseif ($cur == '||') {
155
+            }
156
+            elseif ($cur == '||') {
153 157
                 $out .= 'OR ';
154
-            } elseif (in_array($cur, $ops)) {
158
+            }
159
+            elseif (in_array($cur, $ops)) {
155 160
                 // pass-through operators
156 161
                 $out .= $cur.' ';
157
-            } else {
162
+            }
163
+            else {
158 164
                 // user supplied input
159 165
                 $out .= "'".trim($cur, '"\'')."' "; // TODO: remove trim, only needed with invalid input
160 166
             }
@@ -185,7 +191,8 @@  discard block
 block discarded – undo
185 191
         // add ends appropriately
186 192
         if ($startAnchor && !$endAnchor) {
187 193
             $pattern .= '%';
188
-        } elseif (!$startAnchor && $endAnchor) {
194
+        }
195
+        elseif (!$startAnchor && $endAnchor) {
189 196
             $pattern = '%'.$pattern;
190 197
         }
191 198
 
@@ -220,7 +227,8 @@  discard block
 block discarded – undo
220 227
         if (str_contains($pattern, 'macros.')) {
221 228
             if (++$x < 30) {
222 229
                 $pattern = self::applyGroupMacros($pattern, $x);
223
-            } else {
230
+            }
231
+            else {
224 232
                 return false;
225 233
             }
226 234
         }
Please login to merge, or discard this patch.
app/QueryBuilderFilter.php 1 patch
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -38,6 +38,9 @@
 block discarded – undo
38 38
         return json_encode(self::generateMacroFilter('alert.macros.rule', self::generateTableFilter()));
39 39
     }
40 40
 
41
+    /**
42
+     * @param string $setting
43
+     */
41 44
     private static function generateMacroFilter($setting, $filter = [])
42 45
     {
43 46
         foreach (Settings::get($setting, []) as $key => $value) {
Please login to merge, or discard this patch.