We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 1 |
| Paths | 1 |
| Total Lines | 95 |
| Code Lines | 60 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| 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 |
||
| 12 | public function setup() |
||
| 13 | { |
||
| 14 | /* |
||
| 15 | |-------------------------------------------------------------------------- |
||
| 16 | | BASIC CRUD INFORMATION |
||
| 17 | |-------------------------------------------------------------------------- |
||
| 18 | */ |
||
| 19 | $this->crud->setModel(config('backpack.permissionmanager.user_model')); |
||
| 20 | $this->crud->setEntityNameStrings(trans('backpack::permissionmanager.user'), trans('backpack::permissionmanager.users')); |
||
|
|
|||
| 21 | $this->crud->setRoute(config('backpack.base.route_prefix').'/user'); |
||
| 22 | $this->crud->enableAjaxTable(); |
||
| 23 | |||
| 24 | // Columns. |
||
| 25 | $this->crud->setColumns([ |
||
| 26 | [ |
||
| 27 | 'name' => 'name', |
||
| 28 | 'label' => trans('backpack::permissionmanager.name'), |
||
| 29 | 'type' => 'text', |
||
| 30 | ], |
||
| 31 | [ |
||
| 32 | 'name' => 'email', |
||
| 33 | 'label' => trans('backpack::permissionmanager.email'), |
||
| 34 | 'type' => 'email', |
||
| 35 | ], |
||
| 36 | [ // n-n relationship (with pivot table) |
||
| 37 | 'label' => trans('backpack::permissionmanager.roles'), // Table column heading |
||
| 38 | 'type' => 'select_multiple', |
||
| 39 | 'name' => 'roles', // the method that defines the relationship in your Model |
||
| 40 | 'entity' => 'roles', // the method that defines the relationship in your Model |
||
| 41 | 'attribute' => 'name', // foreign key attribute that is shown to user |
||
| 42 | 'model' => config('laravel-permission.models.role'), // foreign key model |
||
| 43 | ], |
||
| 44 | [ // n-n relationship (with pivot table) |
||
| 45 | 'label' => trans('backpack::permissionmanager.extra_permissions'), // Table column heading |
||
| 46 | 'type' => 'select_multiple', |
||
| 47 | 'name' => 'permissions', // the method that defines the relationship in your Model |
||
| 48 | 'entity' => 'permissions', // the method that defines the relationship in your Model |
||
| 49 | 'attribute' => 'name', // foreign key attribute that is shown to user |
||
| 50 | 'model' => config('laravel-permission.models.permission'), // foreign key model |
||
| 51 | ], |
||
| 52 | ]); |
||
| 53 | |||
| 54 | // Fields |
||
| 55 | $this->crud->addFields([ |
||
| 56 | [ |
||
| 57 | 'name' => 'name', |
||
| 58 | 'label' => trans('backpack::permissionmanager.name'), |
||
| 59 | 'type' => 'text', |
||
| 60 | ], |
||
| 61 | [ |
||
| 62 | 'name' => 'email', |
||
| 63 | 'label' => trans('backpack::permissionmanager.email'), |
||
| 64 | 'type' => 'email', |
||
| 65 | ], |
||
| 66 | [ |
||
| 67 | 'name' => 'password', |
||
| 68 | 'label' => trans('backpack::permissionmanager.password'), |
||
| 69 | 'type' => 'password', |
||
| 70 | ], |
||
| 71 | [ |
||
| 72 | 'name' => 'password_confirmation', |
||
| 73 | 'label' => trans('backpack::permissionmanager.password_confirmation'), |
||
| 74 | 'type' => 'password', |
||
| 75 | ], |
||
| 76 | [ |
||
| 77 | // two interconnected entities |
||
| 78 | 'label' => trans('backpack::permissionmanager.user_role_permission'), |
||
| 79 | 'field_unique_name' => 'user_role_permission', |
||
| 80 | 'type' => 'checklist_dependency', |
||
| 81 | 'name' => 'roles_and_permissions', // the methods that defines the relationship in your Model |
||
| 82 | 'subfields' => [ |
||
| 83 | 'primary' => [ |
||
| 84 | 'label' => trans('backpack::permissionmanager.roles'), |
||
| 85 | 'name' => 'roles', // the method that defines the relationship in your Model |
||
| 86 | 'entity' => 'roles', // the method that defines the relationship in your Model |
||
| 87 | 'entity_secondary' => 'permissions', // the method that defines the relationship in your Model |
||
| 88 | 'attribute' => 'name', // foreign key attribute that is shown to user |
||
| 89 | 'model' => config('laravel-permission.models.role'), // foreign key model |
||
| 90 | 'pivot' => true, // on create&update, do you need to add/delete pivot table entries?] |
||
| 91 | 'number_columns' => 3, //can be 1,2,3,4,6 |
||
| 92 | ], |
||
| 93 | 'secondary' => [ |
||
| 94 | 'label' => ucfirst(trans('backpack::permissionmanager.permission_singular')), |
||
| 95 | 'name' => 'permissions', // the method that defines the relationship in your Model |
||
| 96 | 'entity' => 'permissions', // the method that defines the relationship in your Model |
||
| 97 | 'entity_primary' => 'roles', // the method that defines the relationship in your Model |
||
| 98 | 'attribute' => 'name', // foreign key attribute that is shown to user |
||
| 99 | 'model' => "Backpack\PermissionManager\app\Models\Permission", // foreign key model |
||
| 100 | 'pivot' => true, // on create&update, do you need to add/delete pivot table entries?] |
||
| 101 | 'number_columns' => 3, //can be 1,2,3,4,6 |
||
| 102 | ], |
||
| 103 | ], |
||
| 104 | ], |
||
| 105 | ]); |
||
| 106 | } |
||
| 107 | |||
| 154 |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.