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 | 90 |
Code Lines | 62 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 1 | Features | 1 |
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 |
||
14 | public function __construct() |
||
15 | { |
||
16 | parent::__construct(); |
||
17 | |||
18 | $this->crud->setModel("App\User"); |
||
19 | $this->crud->setEntityNameStrings('user', 'users'); |
||
20 | $this->crud->setRoute('admin/user'); |
||
21 | $this->crud->setColumns([ |
||
22 | [ |
||
23 | 'name' => 'name', |
||
24 | 'label' => 'Name', |
||
25 | 'type' => 'text', |
||
26 | ], |
||
27 | [ |
||
28 | 'name' => 'email', |
||
29 | 'label' => 'Email', |
||
30 | 'type' => 'email', |
||
31 | ], |
||
32 | ]); |
||
33 | |||
34 | $this->crud->addColumn([ // n-n relationship (with pivot table) |
||
35 | 'label' => "Roles", // Table column heading |
||
36 | 'type' => "select_multiple", |
||
37 | 'name' => 'roles', // the method that defines the relationship in your Model |
||
38 | 'entity' => 'roles', // the method that defines the relationship in your Model |
||
39 | 'attribute' => "name", // foreign key attribute that is shown to user |
||
40 | 'model' => "Backpack\PermissionManager\app\Models\Roles", // foreign key model |
||
41 | ]); |
||
42 | |||
43 | $this->crud->addColumn([ // n-n relationship (with pivot table) |
||
44 | 'label' => "Extra Permissions", // Table column heading |
||
45 | 'type' => "select_multiple", |
||
46 | 'name' => 'permissions', // the method that defines the relationship in your Model |
||
47 | 'entity' => 'permissions', // the method that defines the relationship in your Model |
||
48 | 'attribute' => "name", // foreign key attribute that is shown to user |
||
49 | 'model' => "Backpack\PermissionManager\app\Models\Permission", // foreign key model |
||
50 | ]); |
||
51 | |||
52 | $this->crud->addFields([ |
||
53 | [ |
||
54 | 'name' => 'name', |
||
55 | 'label' => 'Name', |
||
56 | 'type' => 'text', |
||
57 | ], |
||
58 | [ |
||
59 | 'name' => 'email', |
||
60 | 'label' => 'Email', |
||
61 | 'type' => 'email', |
||
62 | ], |
||
63 | [ |
||
64 | 'name' => 'password', |
||
65 | 'label' => 'Password', |
||
66 | 'type' => 'password', |
||
67 | ], |
||
68 | [ |
||
69 | 'name' => 'password_confirmation', |
||
70 | 'label' => 'Password Confirmation', |
||
71 | 'type' => 'password', |
||
72 | ], |
||
73 | [ |
||
74 | // two interconnected entities |
||
75 | 'label' => 'User Role Permissions', |
||
76 | 'field_unique_name' => 'user_role_permission', |
||
77 | 'type' => 'checklist_dependency', |
||
78 | 'name' => 'roles_and_permissions', // the methods that defines the relationship in your Model |
||
|
|||
79 | 'subfields' => [ |
||
80 | 'primary' => [ |
||
81 | 'label' => 'Roles', |
||
82 | 'name' => 'roles', // the method that defines the relationship in your Model |
||
83 | 'entity' => 'roles', // the method that defines the relationship in your Model |
||
84 | 'entity_secondary' => 'permissions', // the method that defines the relationship in your Model |
||
85 | 'attribute' => 'name', // foreign key attribute that is shown to user |
||
86 | 'model' => "Backpack\PermissionManager\app\Models\Role", // foreign key model |
||
87 | 'pivot' => true, // on create&update, do you need to add/delete pivot table entries?] |
||
88 | 'number_columns' => 3, //can be 1,2,3,4,6 |
||
89 | ], |
||
90 | 'secondary' => [ |
||
91 | 'label' => 'Permission', |
||
92 | 'name' => 'permissions', // the method that defines the relationship in your Model |
||
93 | 'entity' => 'permissions', // the method that defines the relationship in your Model |
||
94 | 'entity_primary' => 'roles', // the method that defines the relationship in your Model |
||
95 | 'attribute' => 'name', // foreign key attribute that is shown to user |
||
96 | 'model' => "Backpack\PermissionManager\app\Models\Permission", // foreign key model |
||
97 | 'pivot' => true, // on create&update, do you need to add/delete pivot table entries?] |
||
98 | 'number_columns' => 3, //can be 1,2,3,4,6 |
||
99 | ], |
||
100 | ], |
||
101 | ], |
||
102 | ]); |
||
103 | } |
||
104 | |||
159 |
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.