We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 4 |
Paths | 8 |
Total Lines | 52 |
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 |
||
12 | public function setup() |
||
13 | { |
||
14 | $role_model = config('permission.models.role'); |
||
15 | $permission_model = config('permission.models.permission'); |
||
16 | |||
17 | $this->crud->setModel($role_model); |
||
18 | $this->crud->setEntityNameStrings(trans('backpack::permissionmanager.role'), trans('backpack::permissionmanager.roles')); |
||
|
|||
19 | $this->crud->setRoute(config('backpack.base.route_prefix').'/role'); |
||
20 | |||
21 | $this->crud->setColumns([ |
||
22 | [ |
||
23 | 'name' => 'name', |
||
24 | 'label' => trans('backpack::permissionmanager.name'), |
||
25 | 'type' => 'text', |
||
26 | ], |
||
27 | [ |
||
28 | // n-n relationship (with pivot table) |
||
29 | 'label' => ucfirst(trans('backpack::permissionmanager.permission_plural')), |
||
30 | 'type' => 'select_multiple', |
||
31 | 'name' => 'permissions', // the method that defines the relationship in your Model |
||
32 | 'entity' => 'permissions', // the method that defines the relationship in your Model |
||
33 | 'attribute' => 'name', // foreign key attribute that is shown to user |
||
34 | 'model' => $permission_model, // foreign key model |
||
35 | 'pivot' => true, // on create&update, do you need to add/delete pivot table entries? |
||
36 | ], |
||
37 | ]); |
||
38 | |||
39 | $this->crud->addField([ |
||
40 | 'name' => 'name', |
||
41 | 'label' => trans('backpack::permissionmanager.name'), |
||
42 | 'type' => 'text', |
||
43 | ]); |
||
44 | $this->crud->addField([ |
||
45 | 'label' => ucfirst(trans('backpack::permissionmanager.permission_plural')), |
||
46 | 'type' => 'checklist', |
||
47 | 'name' => 'permissions', |
||
48 | 'entity' => 'permissions', |
||
49 | 'attribute' => 'name', |
||
50 | 'model' => $permission_model, |
||
51 | 'pivot' => true, |
||
52 | ]); |
||
53 | |||
54 | if (config('backpack.permissionmanager.allow_role_create') == false) { |
||
55 | $this->crud->denyAccess('create'); |
||
56 | } |
||
57 | if (config('backpack.permissionmanager.allow_role_update') == false) { |
||
58 | $this->crud->denyAccess('update'); |
||
59 | } |
||
60 | if (config('backpack.permissionmanager.allow_role_delete') == false) { |
||
61 | $this->crud->denyAccess('delete'); |
||
62 | } |
||
63 | } |
||
64 | |||
81 |
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.