| Conditions | 29 |
| Paths | > 20000 |
| Total Lines | 194 |
| Code Lines | 117 |
| 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 |
||
| 219 | public function update(Request $request) |
||
| 220 | { |
||
| 221 | if ($request->ajax()) { |
||
| 222 | |||
| 223 | if (($response = DBM::authorize('database.update')) !== true) { |
||
| 224 | return $response; |
||
| 225 | } |
||
| 226 | |||
| 227 | if (!is_array($request->table)) { |
||
| 228 | $table = json_decode($request->table, true); |
||
| 229 | } |
||
| 230 | |||
| 231 | $tableName = $table['oldName']; |
||
| 232 | $newName = $table['name']; |
||
| 233 | $columns = $table['columns']; |
||
| 234 | |||
| 235 | try |
||
| 236 | { |
||
| 237 | // Update Template |
||
| 238 | if (is_array($request->templates) && count($request->templates) > 0) { |
||
| 239 | |||
| 240 | foreach ($request->templates as $field) { |
||
| 241 | |||
| 242 | if ($template = DBM::Template()->where('old_name', $field['oldName'])->first()) { |
||
| 243 | |||
| 244 | $template->name = $field['name']; |
||
| 245 | $template->old_name = $field['name']; |
||
| 246 | $template->type = $field['type']['name']; |
||
| 247 | $template->length = $field['length']; |
||
| 248 | $template->index = $field['index']; |
||
| 249 | $template->default = $field['default']; |
||
| 250 | $template->notnull = $field['notnull']; |
||
| 251 | $template->unsigned = $field['unsigned']; |
||
| 252 | $template->auto_increment = $field['autoincrement']; |
||
| 253 | |||
| 254 | $template->update(); |
||
| 255 | } |
||
| 256 | } |
||
| 257 | } |
||
| 258 | |||
| 259 | if (Table::exists($tableName)) { |
||
| 260 | |||
| 261 | if (Driver::isMongoDB()) { |
||
| 262 | |||
| 263 | if ($collection = DBM_Collection::where('name', $tableName)->first()) { |
||
| 264 | if ($tableName != $newName) { |
||
| 265 | $collection->name = $newName; |
||
| 266 | $collection->old_name = $newName; |
||
| 267 | $collection->update(); |
||
| 268 | } |
||
| 269 | } else { |
||
| 270 | $collection = new DBM_Collection; |
||
| 271 | $collection->name = $newName; |
||
| 272 | $collection->old_name = $newName; |
||
| 273 | $collection->save(); |
||
| 274 | } |
||
| 275 | |||
| 276 | if ($collection) { |
||
| 277 | |||
| 278 | $id = $collection->_id; |
||
| 279 | $fieldNames = (!empty($collection->fields)) ? $collection->fields->pluck('old_name')->toArray() : []; |
||
| 280 | |||
| 281 | foreach ($columns as $column) { |
||
| 282 | |||
| 283 | if (in_array($column['oldName'], $fieldNames)) { |
||
| 284 | |||
| 285 | $collection_field = CollectionField::where('old_name', $column['oldName'])->first(); |
||
| 286 | |||
| 287 | $collection_field->name = $column['name']; |
||
| 288 | $collection_field->old_name = $column['oldName']; |
||
| 289 | $collection_field->type = $column['type']['name']; |
||
| 290 | $collection_field->update(); |
||
| 291 | $fieldNames = array_values(array_diff($fieldNames, [$column['oldName']])); |
||
| 292 | } else { |
||
| 293 | |||
| 294 | $collection_field = new CollectionField; |
||
| 295 | |||
| 296 | $collection_field->dbm_collection_id = $id; |
||
| 297 | $collection_field->name = $column['name']; |
||
| 298 | $collection_field->old_name = $column['name']; |
||
| 299 | $collection_field->type = $column['type']['name']; |
||
| 300 | $collection_field->index = ''; |
||
| 301 | $collection_field->extra = []; |
||
| 302 | |||
| 303 | $collection_field->save(); |
||
| 304 | } |
||
| 305 | } |
||
| 306 | |||
| 307 | if (count($fieldNames) > 0) { |
||
| 308 | foreach ($fieldNames as $fieldName) { |
||
| 309 | $field = CollectionField::where([ |
||
| 310 | 'dbm_collection_id' => $id, |
||
| 311 | 'name' => $fieldName])->first(); |
||
| 312 | $field->delete(); |
||
| 313 | } |
||
| 314 | } |
||
| 315 | |||
| 316 | } |
||
| 317 | } |
||
| 318 | |||
| 319 | // Update Database |
||
| 320 | Table::update($request->table); |
||
| 321 | |||
| 322 | // Update Crud fields |
||
| 323 | if ($tableName != $newName) { |
||
| 324 | |||
| 325 | DBM::Object()->where('slug', Str::slug($tableName))->update([ |
||
| 326 | 'name' => $newName, |
||
| 327 | 'slug' => Str::slug($newName), |
||
| 328 | 'display_name' => ucfirst($newName), |
||
| 329 | ]); |
||
| 330 | |||
| 331 | $tableName = $newName; |
||
| 332 | } |
||
| 333 | |||
| 334 | if ($object = DBM::Object()::where('slug', Str::slug($tableName))->first()) { |
||
| 335 | |||
| 336 | $fieldNames = $object->fields->pluck('name')->toArray(); |
||
| 337 | $relationshipItems = []; |
||
| 338 | |||
| 339 | foreach ($columns as $column) { |
||
| 340 | |||
| 341 | $columnType = $column['type']; |
||
| 342 | |||
| 343 | if (in_array($column['oldName'], $fieldNames)) { |
||
| 344 | |||
| 345 | $field = DBM::Field()->where([ |
||
| 346 | 'dbm_object_id' => $object->id, |
||
| 347 | 'name' => $column['oldName'], |
||
| 348 | ])->first(); |
||
| 349 | |||
| 350 | $field->name = $column['name']; |
||
| 351 | if ($column['oldName'] != $column['name']) { |
||
| 352 | $field->display_name = ucfirst($column['name']); |
||
| 353 | } |
||
| 354 | $field->order = $column['order']; |
||
| 355 | $field->update(); |
||
| 356 | |||
| 357 | $fieldNames = array_values(array_diff($fieldNames, [$column['oldName']])); |
||
| 358 | } else { |
||
| 359 | |||
| 360 | if (DBM::Field()->where([ |
||
| 361 | 'dbm_object_id' => $object->id, |
||
| 362 | 'name' => $column['name']])->first()) { |
||
| 363 | return response()->json([ |
||
| 364 | 'success' => false, |
||
| 365 | 'errors' => ["Field name must be unique. " . $column['name'] . " are duplicate"], |
||
| 366 | ], 400); |
||
| 367 | } |
||
| 368 | |||
| 369 | $field = DBM::Field(); |
||
| 370 | $field->dbm_object_id = $object->id; |
||
| 371 | $field->name = $column['name']; |
||
| 372 | $field->display_name = ucfirst($column['name']); |
||
| 373 | $field->type = static::getInputType($columnType['name']); |
||
| 374 | $field->order = $column['order']; |
||
| 375 | |||
| 376 | if ($column['autoincrement'] == true) { |
||
| 377 | $field->create = false; |
||
| 378 | $field->read = false; |
||
| 379 | $field->edit = false; |
||
| 380 | $field->delete = false; |
||
| 381 | } |
||
| 382 | |||
| 383 | $field->save(); |
||
| 384 | } |
||
| 385 | |||
| 386 | } |
||
| 387 | |||
| 388 | if (count($fieldNames) > 0) { |
||
| 389 | foreach ($fieldNames as $fieldName) { |
||
| 390 | $field = DBM::Field()->where([ |
||
| 391 | 'dbm_object_id' => $object->id, |
||
| 392 | 'name' => $fieldName])->first(); |
||
| 393 | if ($field->type != 'relationship') { |
||
| 394 | $field->delete(); |
||
| 395 | } |
||
| 396 | } |
||
| 397 | } |
||
| 398 | } |
||
| 399 | |||
| 400 | return response()->json(['success' => true]); |
||
| 401 | } |
||
| 402 | |||
| 403 | } catch (\Exception $e) { |
||
| 404 | |||
| 405 | return response()->json([ |
||
| 406 | 'success' => false, |
||
| 407 | 'errors' => [$e->getMessage()], |
||
| 408 | ], 400); |
||
| 409 | } |
||
| 410 | } |
||
| 411 | |||
| 412 | return response()->json(['success' => false]); |
||
| 413 | |||
| 611 |
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