| Conditions | 35 |
| Paths | 2534 |
| Total Lines | 159 |
| Code Lines | 101 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 173 | public function storeOrUpdate(Request $request) |
||
| 174 | { |
||
| 175 | if ($request->ajax()) { |
||
| 176 | |||
| 177 | if (($response = DBM::authorize('crud.browse')) !== true) { |
||
| 178 | return $response; |
||
| 179 | } |
||
| 180 | |||
| 181 | $table = $request->object; |
||
| 182 | $columns = $request->fields; |
||
| 183 | $action = ($request->isCrudExists) ? 'edit' : 'add'; |
||
| 184 | |||
| 185 | // return response()->json(['columns' => $columns, 'action' => $action]); |
||
| 186 | |||
| 187 | if ($action == 'add') { |
||
| 188 | |||
| 189 | if (($response = DBM::authorize('crud.create')) !== true) { |
||
| 190 | return $response; |
||
| 191 | } |
||
| 192 | |||
| 193 | try |
||
| 194 | { |
||
| 195 | if ($table['model'] == '' || $table['model'] == null) { |
||
| 196 | return response()->json([ |
||
| 197 | 'success' => false, |
||
| 198 | 'errors' => ["Model Must be provided"], |
||
| 199 | ], 400); |
||
| 200 | |||
| 201 | } |
||
| 202 | |||
| 203 | if ($table['makeModel'] == true && !class_exists($table['model'])) { |
||
| 204 | \DBM::makeModel($table['model'], $table['name']); |
||
| 205 | } else if ($table['makeModel'] == false && !class_exists($table['model'])) { |
||
| 206 | return response()->json([ |
||
| 207 | 'success' => false, |
||
| 208 | 'errors' => ["Create model '" . $table['model'] . "' first or checked create model option"], |
||
| 209 | ], 400); |
||
| 210 | } |
||
| 211 | |||
| 212 | if (!class_exists($table['controller'])) { |
||
| 213 | \DBM::makeController($table['controller']); |
||
| 214 | } |
||
| 215 | |||
| 216 | $object = DBM::Object(); |
||
| 217 | $object->name = $table['name']; |
||
| 218 | $object->slug = Str::slug($table['slug']); |
||
| 219 | $object->display_name = ucfirst($table['display_name']); |
||
| 220 | $object->model = $table['model']; |
||
| 221 | $object->controller = $table['controller']; |
||
| 222 | $object->details = [ |
||
| 223 | 'findColumn' => $table['findColumn'], |
||
| 224 | 'searchColumn' => $table['searchColumn'], |
||
| 225 | 'perPage' => $table['perPage'], |
||
| 226 | 'orderColumn' => $table['orderColumn'], |
||
| 227 | 'orderDisplayColumn' => $table['orderDisplayColumn'], |
||
| 228 | 'orderDirection' => $table['orderDirection'], |
||
| 229 | ]; |
||
| 230 | |||
| 231 | if ($object->save()) { |
||
| 232 | |||
| 233 | foreach ($columns as $column) { |
||
| 234 | |||
| 235 | $field = DBM::Field(); |
||
| 236 | $field->dbm_object_id = $object->id; |
||
| 237 | $field->name = $column['name']; |
||
| 238 | $field->display_name = ucfirst($column['display_name']); |
||
| 239 | $field->type = $column['type']; |
||
| 240 | // $field->required = isset($column['required']) ? $column['required'] : false; |
||
| 241 | $field->create = isset($column['create']) ? $column['create'] : false; |
||
| 242 | $field->read = isset($column['read']) ? $column['read'] : false; |
||
| 243 | $field->edit = isset($column['edit']) ? $column['edit'] : false; |
||
| 244 | $field->delete = isset($column['delete']) ? $column['delete'] : false; |
||
| 245 | $field->order = $column['order']; |
||
| 246 | $field->function_name = $column['function_name']; |
||
| 247 | $field->settings = json_decode($column['settings']); |
||
| 248 | |||
| 249 | $field->save(); |
||
| 250 | } |
||
| 251 | |||
| 252 | } |
||
| 253 | |||
| 254 | } catch (\Exception $e) { |
||
| 255 | return $this->generateError([$e->getMessage()]); |
||
| 256 | } |
||
| 257 | } else { |
||
| 258 | |||
| 259 | if (($response = DBM::authorize('crud.update')) !== true) { |
||
| 260 | return $response; |
||
| 261 | } |
||
| 262 | |||
| 263 | try |
||
| 264 | { |
||
| 265 | |||
| 266 | if ($table['model'] == '' || $table['model'] == null) { |
||
| 267 | return $this->generateError(["Model Must be provided"]); |
||
| 268 | |||
| 269 | } |
||
| 270 | |||
| 271 | if ($table['makeModel'] == true) { |
||
| 272 | \DBM::makeModel($table['model'], $table['name']); |
||
| 273 | } else if ($table['makeModel'] == false && !class_exists($table['model'])) { |
||
| 274 | return $this->generateError(["Create mode '" . $table['model'] . "' first."]); |
||
| 275 | } |
||
| 276 | |||
| 277 | if (!class_exists($table['controller'])) { |
||
| 278 | \DBM::makeController($table['controller']); |
||
| 279 | } |
||
| 280 | |||
| 281 | $object = DBM::Object()->where('name', $table['name'])->first(); |
||
| 282 | $object->slug = Str::slug($table['slug']); |
||
| 283 | $object->display_name = ucfirst($table['display_name']); |
||
| 284 | $object->model = $table['model']; |
||
| 285 | $object->controller = $table['controller']; |
||
| 286 | $object->details = [ |
||
| 287 | 'findColumn' => $table['findColumn'], |
||
| 288 | 'searchColumn' => $table['searchColumn'], |
||
| 289 | 'perPage' => $table['perPage'], |
||
| 290 | 'orderColumn' => $table['orderColumn'], |
||
| 291 | 'orderDisplayColumn' => $table['orderDisplayColumn'], |
||
| 292 | 'orderDirection' => $table['orderDirection'], |
||
| 293 | ]; |
||
| 294 | |||
| 295 | if ($object->update()) { |
||
| 296 | |||
| 297 | foreach ($columns as $column) { |
||
| 298 | |||
| 299 | $field = DBM::Field()->where([ |
||
| 300 | 'dbm_object_id' => $object->id, |
||
| 301 | 'name' => $column['name'], |
||
| 302 | ])->first(); |
||
| 303 | |||
| 304 | $field->display_name = ucfirst($column['display_name']); |
||
| 305 | $field->type = $column['type']; |
||
| 306 | // $field->required = isset($column['required']) ? $column['required'] : false; |
||
| 307 | $field->create = isset($column['create']) ? $column['create'] : false; |
||
| 308 | $field->read = isset($column['read']) ? $column['read'] : false; |
||
| 309 | $field->edit = isset($column['edit']) ? $column['edit'] : false; |
||
| 310 | $field->delete = isset($column['delete']) ? $column['delete'] : false; |
||
| 311 | $field->order = $column['order']; |
||
| 312 | $field->function_name = isset($column['function_name']) ? $column['function_name'] : ""; |
||
| 313 | $field->settings = json_decode($column['settings']); |
||
| 314 | |||
| 315 | $field->update(); |
||
| 316 | } |
||
| 317 | } |
||
| 318 | |||
| 319 | } catch (\Exception $e) { |
||
| 320 | return $this->generateError([$e->getMessage()]); |
||
| 321 | } |
||
| 322 | } |
||
| 323 | |||
| 324 | return response()->json([ |
||
| 325 | 'success' => true, |
||
| 326 | 'object' => $request->object, |
||
| 327 | 'fields' => $request->fields, |
||
| 328 | ]); |
||
| 329 | } |
||
| 330 | |||
| 331 | return response()->json(['success' => false]); |
||
| 332 | } |
||
| 515 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths