We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Conditions | 6 |
Paths | 32 |
Total Lines | 69 |
Lines | 15 |
Ratio | 21.74 % |
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('backpack.permissionmanager.models.role'); |
||
15 | $permission_model = config('backpack.permissionmanager.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(backpack_url('role')); |
||
20 | |||
21 | $this->crud->addColumn([ |
||
22 | 'name' => 'name', |
||
23 | 'label' => trans('backpack::permissionmanager.name'), |
||
24 | 'type' => 'text', |
||
25 | ]); |
||
26 | |||
27 | View Code Duplication | if (config('backpack.permissionmanager.multiple_guards')) { |
|
28 | $this->crud->addColumn([ |
||
29 | 'name' => 'guard_name', |
||
30 | 'label' => trans('backpack::permissionmanager.guard_type'), |
||
31 | 'type' => 'text', |
||
32 | ]); |
||
33 | } |
||
34 | |||
35 | $this->crud->addColumn([ |
||
36 | // n-n relationship (with pivot table) |
||
37 | 'label' => ucfirst(trans('backpack::permissionmanager.permission_plural')), |
||
38 | 'type' => 'select_multiple', |
||
39 | 'name' => 'permissions', // the method that defines the relationship in your Model |
||
40 | 'entity' => 'permissions', // the method that defines the relationship in your Model |
||
41 | 'attribute' => 'name', // foreign key attribute that is shown to user |
||
42 | 'model' => $permission_model, // foreign key model |
||
43 | 'pivot' => true, // on create&update, do you need to add/delete pivot table entries? |
||
44 | ]); |
||
45 | |||
46 | $this->crud->addField([ |
||
47 | 'name' => 'name', |
||
48 | 'label' => trans('backpack::permissionmanager.name'), |
||
49 | 'type' => 'text', |
||
50 | ]); |
||
51 | |||
52 | View Code Duplication | if (config('backpack.permissionmanager.multiple_guards')) { |
|
53 | $this->crud->addField([ |
||
54 | 'name' => 'guard_name', |
||
55 | 'label' => trans('backpack::permissionmanager.guard_type'), |
||
56 | 'type' => 'select_from_array', |
||
57 | 'options' => $this->getGuardTypes(), |
||
58 | ]); |
||
59 | } |
||
60 | |||
61 | $this->crud->addField([ |
||
62 | 'label' => ucfirst(trans('backpack::permissionmanager.permission_plural')), |
||
63 | 'type' => 'checklist', |
||
64 | 'name' => 'permissions', |
||
65 | 'entity' => 'permissions', |
||
66 | 'attribute' => 'name', |
||
67 | 'model' => $permission_model, |
||
68 | 'pivot' => true, |
||
69 | ]); |
||
70 | |||
71 | if (config('backpack.permissionmanager.allow_role_create') == false) { |
||
72 | $this->crud->denyAccess('create'); |
||
73 | } |
||
74 | if (config('backpack.permissionmanager.allow_role_update') == false) { |
||
75 | $this->crud->denyAccess('update'); |
||
76 | } |
||
77 | if (config('backpack.permissionmanager.allow_role_delete') == false) { |
||
78 | $this->crud->denyAccess('delete'); |
||
79 | } |
||
80 | } |
||
81 | |||
116 |
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.