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 | 54 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
116 | protected function addUserFields() |
||
117 | { |
||
118 | $this->crud->addFields([ |
||
119 | [ |
||
120 | 'name' => 'name', |
||
121 | 'label' => trans('backpack::permissionmanager.name'), |
||
122 | 'type' => 'text', |
||
123 | ], |
||
124 | [ |
||
125 | 'name' => 'email', |
||
126 | 'label' => trans('backpack::permissionmanager.email'), |
||
127 | 'type' => 'email', |
||
128 | ], |
||
129 | [ |
||
130 | 'name' => 'password', |
||
131 | 'label' => trans('backpack::permissionmanager.password'), |
||
132 | 'type' => 'password', |
||
133 | ], |
||
134 | [ |
||
135 | 'name' => 'password_confirmation', |
||
136 | 'label' => trans('backpack::permissionmanager.password_confirmation'), |
||
137 | 'type' => 'password', |
||
138 | ], |
||
139 | [ |
||
140 | // two interconnected entities |
||
141 | 'label' => trans('backpack::permissionmanager.user_role_permission'), |
||
142 | 'field_unique_name' => 'user_role_permission', |
||
143 | 'type' => 'checklist_dependency', |
||
144 | 'name' => 'roles_and_permissions', // the methods that defines the relationship in your Model |
||
145 | 'subfields' => [ |
||
146 | 'primary' => [ |
||
147 | 'label' => trans('backpack::permissionmanager.roles'), |
||
148 | 'name' => 'roles', // the method that defines the relationship in your Model |
||
149 | 'entity' => 'roles', // the method that defines the relationship in your Model |
||
150 | 'entity_secondary' => 'permissions', // the method that defines the relationship in your Model |
||
151 | 'attribute' => 'name', // foreign key attribute that is shown to user |
||
152 | 'model' => config('permission.models.role'), // foreign key model |
||
153 | 'pivot' => true, // on create&update, do you need to add/delete pivot table entries?] |
||
154 | 'number_columns' => 3, //can be 1,2,3,4,6 |
||
155 | ], |
||
156 | 'secondary' => [ |
||
157 | 'label' => ucfirst(trans('backpack::permissionmanager.permission_singular')), |
||
158 | 'name' => 'permissions', // the method that defines the relationship in your Model |
||
159 | 'entity' => 'permissions', // the method that defines the relationship in your Model |
||
160 | 'entity_primary' => 'roles', // the method that defines the relationship in your Model |
||
161 | 'attribute' => 'name', // foreign key attribute that is shown to user |
||
162 | 'model' => config('permission.models.permission'), // foreign key model |
||
163 | 'pivot' => true, // on create&update, do you need to add/delete pivot table entries?] |
||
164 | 'number_columns' => 3, //can be 1,2,3,4,6 |
||
165 | ], |
||
166 | ], |
||
167 | ], |
||
168 | ]); |
||
169 | } |
||
170 | } |
||
171 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.