Passed
Push — master ( 5b33aa...3ced8d )
by Ferry
08:41
created
src/types/select/Hook.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -19,9 +19,9 @@  discard block
 block discarded – undo
19 19
      */
20 20
     public function query($query, $column)
21 21
     {
22
-        if($column->getOptionsFromTable()) {
22
+        if ($column->getOptionsFromTable()) {
23 23
             $option = $column->getOptionsFromTable();
24
-            $query->leftjoin($option["table"],$option["table"].'.'.$option["key_field"],"=", $column->getName());
24
+            $query->leftjoin($option["table"], $option["table"].'.'.$option["key_field"], "=", $column->getName());
25 25
             $query->addSelect($option['table'].'.'.$option['display_field'].' as '.$option['table'].'_'.$option['display_field']);
26 26
         }
27 27
         return $query;
@@ -33,13 +33,13 @@  discard block
 block discarded – undo
33 33
      */
34 34
     public function indexRender($row, $column)
35 35
     {
36
-        if($column->getOptionsFromTable()) {
36
+        if ($column->getOptionsFromTable()) {
37 37
             $option = $column->getOptionsFromTable();
38 38
             return $row->{ $option['table'].'_'.$option['display_field'] };
39
-        }else{
39
+        } else {
40 40
             $option = $column->getOptions();
41 41
             $key = $row->{ $column->getField() };
42
-            return @$option[ $key ];
42
+            return @$option[$key];
43 43
         }
44 44
     }
45 45
 
Please login to merge, or discard this patch.
src/controllers/CBController.php 1 patch
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -26,14 +26,14 @@  discard block
 block discarded – undo
26 26
 
27 27
     public function __call($method, $parameters)
28 28
     {
29
-        if($method == "getData") {
29
+        if ($method == "getData") {
30 30
             $key = $parameters[0];
31
-            if(isset($this->data[$key])) {
31
+            if (isset($this->data[$key])) {
32 32
                 return $this->data[$key];
33
-            }else{
33
+            } else {
34 34
                 return null;
35 35
             }
36
-        }else{
36
+        } else {
37 37
             return null;
38 38
         }
39 39
     }
@@ -47,13 +47,13 @@  discard block
 block discarded – undo
47 47
 
48 48
         $query->addSelect($this->data['table'].'.'.cb()->pk($this->data['table']).' as primary_key');
49 49
 
50
-        $softDelete = isset($this->data['disable_soft_delete'])?$this->data['disable_soft_delete']:true;
51
-        if($softDelete === true && Schema::hasColumn($this->data['table'],'deleted_at')) {
50
+        $softDelete = isset($this->data['disable_soft_delete']) ? $this->data['disable_soft_delete'] : true;
51
+        if ($softDelete === true && Schema::hasColumn($this->data['table'], 'deleted_at')) {
52 52
             $query->whereNull($this->data['table'].'.deleted_at');
53 53
         }
54 54
         
55
-        if(isset($joins)) {
56
-            foreach($joins as $join)
55
+        if (isset($joins)) {
56
+            foreach ($joins as $join)
57 57
             {
58 58
                 $query->join($join['target_table'],
59 59
                         $join['target_table_primary'],
@@ -63,14 +63,14 @@  discard block
 block discarded – undo
63 63
             }
64 64
         }
65 65
 
66
-        foreach($columns as $column) {
66
+        foreach ($columns as $column) {
67 67
             /** @var ColumnModel $column */
68
-            if($column->getType() != "custom") {
69
-                if(strpos($column->getField(),".") === false) {
70
-                    if(Schema::hasColumn($this->data['table'], $column->getField())) {
68
+            if ($column->getType() != "custom") {
69
+                if (strpos($column->getField(), ".") === false) {
70
+                    if (Schema::hasColumn($this->data['table'], $column->getField())) {
71 71
                         $query->addSelect($this->data['table'].'.'.$column->getField());
72 72
                     }
73
-                }else{
73
+                } else {
74 74
                     $query->addSelect($column->getField());
75 75
                 }
76 76
             }
@@ -78,20 +78,20 @@  discard block
 block discarded – undo
78 78
             $query = getTypeHook($column->getType())->query($query, $column);
79 79
         }
80 80
 
81
-        if(request()->has('q'))
81
+        if (request()->has('q'))
82 82
         {
83
-            if(isset($this->data['hook_search_query'])) {
83
+            if (isset($this->data['hook_search_query'])) {
84 84
                 $query = call_user_func($this->data['hook_search_query'], $query);
85
-            }else{
86
-                $query->where(function ($where) use ($columns) {
85
+            } else {
86
+                $query->where(function($where) use ($columns) {
87 87
                     /**
88 88
                      * @var $where Builder
89 89
                      */
90
-                    foreach($columns as $column)
90
+                    foreach ($columns as $column)
91 91
                     {
92
-                        if(strpos($column->getField(),".") === false) {
92
+                        if (strpos($column->getField(), ".") === false) {
93 93
                             $field = $this->data['table'].'.'.$column->getField();
94
-                        }else{
94
+                        } else {
95 95
                             $field = $column->getField();
96 96
                         }
97 97
                         $where->orWhere($field, 'like', '%'.request('q').'%');
@@ -100,17 +100,17 @@  discard block
 block discarded – undo
100 100
             }
101 101
         }
102 102
 
103
-        if(isset($this->data['hook_index_query']) && is_callable($this->data['hook_index_query'])) {
103
+        if (isset($this->data['hook_index_query']) && is_callable($this->data['hook_index_query'])) {
104 104
             $query = call_user_func($this->data['hook_index_query'], $query);
105 105
         }
106 106
 
107 107
 
108
-        if(request()->has(['order_by','order_sort']))
108
+        if (request()->has(['order_by', 'order_sort']))
109 109
         {
110
-            if(in_array(request('order_by'),columnSingleton()->getColumnNameOnly())) {
110
+            if (in_array(request('order_by'), columnSingleton()->getColumnNameOnly())) {
111 111
                 $query->orderBy(request('order_by'), request('order_sort'));
112 112
             }
113
-        }else{
113
+        } else {
114 114
             $query->orderBy($this->data['table'].'.'.cb()->findPrimaryKey($this->data['table']), "desc");
115 115
         }
116 116
 
@@ -119,10 +119,10 @@  discard block
 block discarded – undo
119 119
 
120 120
     public function getIndex()
121 121
     {
122
-        if(!module()->canBrowse()) return cb()->redirect(cb()->getAdminUrl(),"You do not have a privilege access to this area");
122
+        if (!module()->canBrowse()) return cb()->redirect(cb()->getAdminUrl(), "You do not have a privilege access to this area");
123 123
 
124 124
         $query = $this->repository();
125
-        $result = $query->paginate( request("limit")?:cbConfig("LIMIT_TABLE_DATA") );
125
+        $result = $query->paginate(request("limit") ?: cbConfig("LIMIT_TABLE_DATA"));
126 126
         $data['result'] = $result;
127 127
 
128 128
         return view("crudbooster::module.index.index", array_merge($data, $this->data));
@@ -134,29 +134,29 @@  discard block
 block discarded – undo
134 134
      */
135 135
     private function validation()
136 136
     {
137
-        if(isset($this->data['validation'])) {
137
+        if (isset($this->data['validation'])) {
138 138
             $validator = Validator::make(request()->all(), @$this->data['validation'], @$this->data['validation_messages']);
139 139
             if ($validator->fails()) {
140 140
                 $message = $validator->messages();
141 141
                 $message_all = $message->all();
142
-                throw new CBValidationException(implode(', ',$message_all));
142
+                throw new CBValidationException(implode(', ', $message_all));
143 143
             }
144 144
         }
145 145
     }
146 146
 
147 147
     public function getAdd()
148 148
     {
149
-        if(!module()->canCreate()) return cb()->redirect(cb()->getAdminUrl(),"You do not have a privilege access to this area");
149
+        if (!module()->canCreate()) return cb()->redirect(cb()->getAdminUrl(), "You do not have a privilege access to this area");
150 150
 
151 151
         $data = [];
152 152
         $data['page_title'] = $this->data['page_title'].' : Add';
153 153
         $data['action_url'] = module()->addSaveURL();
154
-        return view('crudbooster::module.form.form',array_merge($data, $this->data));
154
+        return view('crudbooster::module.form.form', array_merge($data, $this->data));
155 155
     }
156 156
 
157 157
     public function postAddSave()
158 158
     {
159
-        if(!module()->canCreate()) return cb()->redirect(cb()->getAdminUrl(),"You do not have a privilege access to this area");
159
+        if (!module()->canCreate()) return cb()->redirect(cb()->getAdminUrl(), "You do not have a privilege access to this area");
160 160
 
161 161
         try {
162 162
             $this->validation();
@@ -164,28 +164,28 @@  discard block
 block discarded – undo
164 164
             $data = columnSingleton()->getAssignmentData();
165 165
 
166 166
             //Clear data from Primary Key
167
-            unset($data[ cb()->pk($this->data['table']) ]);
167
+            unset($data[cb()->pk($this->data['table'])]);
168 168
 
169
-            if(Schema::hasColumn($this->data['table'], 'created_at')) {
169
+            if (Schema::hasColumn($this->data['table'], 'created_at')) {
170 170
                 $data['created_at'] = date('Y-m-d H:i:s');
171 171
             }
172 172
 
173
-            if(isset($this->data['hook_before_insert']) && is_callable($this->data['hook_before_insert'])) {
173
+            if (isset($this->data['hook_before_insert']) && is_callable($this->data['hook_before_insert'])) {
174 174
                 $data = call_user_func($this->data['hook_before_insert'], $data);
175 175
             }
176 176
 
177 177
             $id = DB::table($this->data['table'])->insertGetId($data);
178 178
 
179
-            if(isset($this->data['hook_after_insert']) && is_callable($this->data['hook_after_insert'])) {
179
+            if (isset($this->data['hook_after_insert']) && is_callable($this->data['hook_after_insert'])) {
180 180
                 call_user_func($this->data['hook_after_insert'], $id);
181 181
             }
182 182
 
183 183
         } catch (CBValidationException $e) {
184 184
             Log::debug($e);
185
-            return cb()->redirectBack($e->getMessage(),'info');
185
+            return cb()->redirectBack($e->getMessage(), 'info');
186 186
         } catch (\Exception $e) {
187 187
             Log::error($e);
188
-            return cb()->redirectBack($e->getMessage(),'warning');
188
+            return cb()->redirectBack($e->getMessage(), 'warning');
189 189
         }
190 190
 
191 191
         if (request('submit') == trans('crudbooster.button_save_more')) {
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
 
198 198
     public function getEdit($id)
199 199
     {
200
-        if(!module()->canUpdate()) return cb()->redirect(cb()->getAdminUrl(),"You do not have a privilege access to this area");
200
+        if (!module()->canUpdate()) return cb()->redirect(cb()->getAdminUrl(), "You do not have a privilege access to this area");
201 201
 
202 202
         $data = [];
203 203
         $data['row'] = $this->repository()->where($this->data['table'].'.'.getPrimaryKey($this->data['table']), $id)->first();
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
 
209 209
     public function postEditSave($id)
210 210
     {
211
-        if(!module()->canUpdate()) return cb()->redirect(cb()->getAdminUrl(),"You do not have a privilege access to this area");
211
+        if (!module()->canUpdate()) return cb()->redirect(cb()->getAdminUrl(), "You do not have a privilege access to this area");
212 212
 
213 213
         try {
214 214
             $this->validation();
@@ -216,13 +216,13 @@  discard block
 block discarded – undo
216 216
             $data = columnSingleton()->getAssignmentData();
217 217
 
218 218
             //Clear data from Primary Key
219
-            unset($data[ cb()->pk($this->data['table']) ]);
219
+            unset($data[cb()->pk($this->data['table'])]);
220 220
 
221
-            if(Schema::hasColumn($this->data['table'], 'updated_at')) {
221
+            if (Schema::hasColumn($this->data['table'], 'updated_at')) {
222 222
                 $data['updated_at'] = date('Y-m-d H:i:s');
223 223
             }
224 224
 
225
-            if(isset($this->data['hook_before_update']) && is_callable($this->data['hook_before_update'])) {
225
+            if (isset($this->data['hook_before_update']) && is_callable($this->data['hook_before_update'])) {
226 226
                 $data = call_user_func($this->data['hook_before_update'], $id, $data);
227 227
             }
228 228
 
@@ -230,16 +230,16 @@  discard block
 block discarded – undo
230 230
                 ->where(cb()->pk($this->data['table']), $id)
231 231
                 ->update($data);
232 232
 
233
-            if(isset($this->data['hook_after_update']) && is_callable($this->data['hook_after_update'])) {
233
+            if (isset($this->data['hook_after_update']) && is_callable($this->data['hook_after_update'])) {
234 234
                 call_user_func($this->data['hook_after_update'], $id);
235 235
             }
236 236
 
237 237
         } catch (CBValidationException $e) {
238 238
             Log::debug($e);
239
-            return cb()->redirectBack($e->getMessage(),'info');
239
+            return cb()->redirectBack($e->getMessage(), 'info');
240 240
         } catch (\Exception $e) {
241 241
             Log::error($e);
242
-            return cb()->redirectBack($e->getMessage(),'warning');
242
+            return cb()->redirectBack($e->getMessage(), 'warning');
243 243
         }
244 244
 
245 245
 
@@ -252,15 +252,15 @@  discard block
 block discarded – undo
252 252
 
253 253
     public function getDelete($id)
254 254
     {
255
-        if(!module()->canDelete()) return cb()->redirect(cb()->getAdminUrl(),"You do not have a privilege access to this area");
255
+        if (!module()->canDelete()) return cb()->redirect(cb()->getAdminUrl(), "You do not have a privilege access to this area");
256 256
 
257
-        if(isset($this->data['hook_before_delete']) && is_callable($this->data['hook_before_delete'])) {
257
+        if (isset($this->data['hook_before_delete']) && is_callable($this->data['hook_before_delete'])) {
258 258
             call_user_func($this->data['hook_before_delete'], $id);
259 259
         }
260 260
 
261
-        $softDelete = isset($this->data['disable_soft_delete'])?$this->data['disable_soft_delete']:true;
261
+        $softDelete = isset($this->data['disable_soft_delete']) ? $this->data['disable_soft_delete'] : true;
262 262
 
263
-        if ($softDelete === true && Schema::hasColumn($this->data['table'],'deleted_at')) {
263
+        if ($softDelete === true && Schema::hasColumn($this->data['table'], 'deleted_at')) {
264 264
             DB::table($this->data['table'])
265 265
                 ->where(getPrimaryKey($this->data['table']), $id)
266 266
                 ->update(['deleted_at' => date('Y-m-d H:i:s')]);
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
                 ->delete();
271 271
         }
272 272
 
273
-        if(isset($this->data['hook_after_delete']) && is_callable($this->data['hook_after_delete'])) {
273
+        if (isset($this->data['hook_after_delete']) && is_callable($this->data['hook_after_delete'])) {
274 274
             call_user_func($this->data['hook_after_delete'], $id);
275 275
         }
276 276
 
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
 
280 280
     public function getDetail($id)
281 281
     {
282
-        if(!module()->canRead()) return cb()->redirect(cb()->getAdminUrl(),"You do not have a privilege access to this area");
282
+        if (!module()->canRead()) return cb()->redirect(cb()->getAdminUrl(), "You do not have a privilege access to this area");
283 283
 
284 284
         $data = [];
285 285
         $data['row'] = $this->repository()->where($this->data['table'].'.'.getPrimaryKey($this->data['table']), $id)->first();
Please login to merge, or discard this patch.
src/helpers/CB.php 1 patch
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
 {
19 19
 
20 20
     public function getRoleByName($roleName) {
21
-        return $this->find("cb_roles",['name'=>$roleName]);
21
+        return $this->find("cb_roles", ['name'=>$roleName]);
22 22
     }
23 23
 
24 24
     public function fcm() {
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
     }
35 35
 
36 36
     public function getDeveloperUrl($path = null) {
37
-        $path = ($path)?"/".trim($path,"/"):null;
37
+        $path = ($path) ? "/".trim($path, "/") : null;
38 38
         return url(cbConfig("DEV_PATH")).$path;
39 39
     }
40 40
 
@@ -51,12 +51,12 @@  discard block
 block discarded – undo
51 51
     }
52 52
 
53 53
     public function getAdminUrl($path = null) {
54
-        $path = ($path)?"/".trim($path,"/"):null;
54
+        $path = ($path) ? "/".trim($path, "/") : null;
55 55
         return url(cbConfig("ADMIN_PATH")).$path;
56 56
     }
57 57
 
58 58
     public function getAppName() {
59
-        return env("APP_NAME","CRUDBOOSTER");
59
+        return env("APP_NAME", "CRUDBOOSTER");
60 60
     }
61 61
 
62 62
     /**
@@ -67,10 +67,10 @@  discard block
 block discarded – undo
67 67
     {
68 68
         $fileData = base64_decode($value);
69 69
         $mime_type = finfo_buffer(finfo_open(), $fileData, FILEINFO_MIME_TYPE);
70
-        if($mime_type) {
71
-            if($mime_type = explode('/', $mime_type)) {
70
+        if ($mime_type) {
71
+            if ($mime_type = explode('/', $mime_type)) {
72 72
                 $ext = $mime_type[1];
73
-                if($ext) {
73
+                if ($ext) {
74 74
                     $filePath = 'uploads/'.date('Y-m');
75 75
                     Storage::makeDirectory($filePath);
76 76
                     $filename = sha1(strRandom(5)).'.'.$ext;
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 
99 99
             $file = request()->file($name);
100 100
             $ext = strtolower($file->getClientOriginalExtension());
101
-            if(in_array($ext,cbConfig("UPLOAD_FILE_EXTENSION_ALLOWED"))) {
101
+            if (in_array($ext, cbConfig("UPLOAD_FILE_EXTENSION_ALLOWED"))) {
102 102
                 $filename = slug(pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME));
103 103
                 $file_path = 'uploads/'.date('Y-m');
104 104
 
@@ -112,14 +112,14 @@  discard block
 block discarded – undo
112 112
                 }
113 113
 
114 114
                 if (Storage::putFileAs($file_path, $file, $filename)) {
115
-                    if($resize_width || $resize_height) {
115
+                    if ($resize_width || $resize_height) {
116 116
                         $this->resizeImage($file_path.'/'.$filename, $resize_width, $resize_height);
117 117
                     }
118 118
                     return $file_path.'/'.$filename;
119 119
                 } else {
120 120
                     throw new \Exception("Something went wrong, file can't upload!");
121 121
                 }
122
-            }else{
122
+            } else {
123 123
                 throw new \Exception("The file format is not allowed!");
124 124
             }
125 125
 
@@ -142,22 +142,22 @@  discard block
 block discarded – undo
142 142
                 $img = Image::make(storage_path('app/'.$file_path.'/'.$filename));
143 143
                 $img->fit($resize_width, $resize_height);
144 144
                 $img->save(storage_path('app/'.$file_path.'/'.$filename), $qty);
145
-            } elseif ($resize_width && ! $resize_height) {
145
+            } elseif ($resize_width && !$resize_height) {
146 146
                 $img = Image::make(storage_path('app/'.$file_path.'/'.$filename));
147
-                $img->resize($resize_width, null, function ($constraint) {
147
+                $img->resize($resize_width, null, function($constraint) {
148 148
                     $constraint->aspectRatio();
149 149
                 });
150 150
                 $img->save(storage_path('app/'.$file_path.'/'.$filename), $qty);
151
-            } elseif (! $resize_width && $resize_height) {
151
+            } elseif (!$resize_width && $resize_height) {
152 152
                 $img = Image::make(storage_path('app/'.$file_path.'/'.$filename));
153
-                $img->resize(null, $resize_height, function ($constraint) {
153
+                $img->resize(null, $resize_height, function($constraint) {
154 154
                     $constraint->aspectRatio();
155 155
                 });
156 156
                 $img->save(storage_path('app/'.$file_path.'/'.$filename), $qty);
157 157
             } else {
158 158
                 $img = Image::make(storage_path('app/'.$file_path.'/'.$filename));
159 159
                 if ($img->width() > 1300) {
160
-                    $img->resize(1300, null, function ($constraint) {
160
+                    $img->resize(1300, null, function($constraint) {
161 161
                         $constraint->aspectRatio();
162 162
                     });
163 163
                 }
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
         $validator = Validator::make($input_arr, $rules, $messages);
270 270
         if ($validator->fails()) {
271 271
             $message = $validator->errors()->all();
272
-            throw new CBValidationException(implode("; ",$message));
272
+            throw new CBValidationException(implode("; ", $message));
273 273
         }
274 274
     }
275 275
 
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
     public function findPrimaryKey($table)
282 282
     {
283 283
         $pk = DB::getDoctrineSchemaManager()->listTableDetails($table)->getPrimaryKey();
284
-        if(!$pk) {
284
+        if (!$pk) {
285 285
             return null;
286 286
         }
287 287
         return $pk->getColumns()[0];
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
             $string_parameters_array = explode('&', $string_parameters);
331 331
             foreach ($string_parameters_array as $s) {
332 332
                 $part = explode('=', $s);
333
-                if(isset($part[0]) && isset($part[1])) {
333
+                if (isset($part[0]) && isset($part[1])) {
334 334
                     $name = htmlspecialchars(urldecode($part[0]));
335 335
                     $name = strip_tags($name);
336 336
                     $value = htmlspecialchars(urldecode($part[1]));
@@ -347,16 +347,16 @@  discard block
 block discarded – undo
347 347
 
348 348
 
349 349
     public function routeGet($prefix, $controller) {
350
-        $alias = str_replace("@"," ", $controller);
350
+        $alias = str_replace("@", " ", $controller);
351 351
         $alias = ucwords($alias);
352
-        $alias = str_replace(" ","",$alias);
352
+        $alias = str_replace(" ", "", $alias);
353 353
         Route::get($prefix, ['uses' => $controller, 'as' => $alias]);
354 354
     }
355 355
 
356 356
     public function routePost($prefix, $controller) {
357
-        $alias = str_replace("@"," ", $controller);
357
+        $alias = str_replace("@", " ", $controller);
358 358
         $alias = ucwords($alias);
359
-        $alias = str_replace(" ","",$alias);
359
+        $alias = str_replace(" ", "", $alias);
360 360
         Route::post($prefix, ['uses' => $controller, 'as' => $alias]);
361 361
     }
362 362
 
@@ -381,7 +381,7 @@  discard block
 block discarded – undo
381 381
 
382 382
         $prefix = trim($prefix, '/').'/';
383 383
 
384
-        if(substr($controller,0,1) != "\\") {
384
+        if (substr($controller, 0, 1) != "\\") {
385 385
             $controller = "\App\Http\Controllers\\".$controller;
386 386
         }
387 387
 
Please login to merge, or discard this patch.