Conditions | 2 |
Paths | 2 |
Total Lines | 61 |
Code Lines | 36 |
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 |
||
36 | protected function showEditPermissions() |
||
37 | { |
||
38 | $permissionsData = Permission::all(['id', 'name'])->map(function($permission){ |
||
39 | $permission['name'] = trans(ucwords($permission['name'])); |
||
40 | |||
41 | return $permission; |
||
42 | })->toArray(); |
||
43 | |||
44 | $table = $this->columns()->addColumn()->add(['Table', 'selectable'])->addStyle('cursor', 'pointer'); |
||
|
|||
45 | $table->setModel($this->getModel($permissionsData), false); |
||
46 | |||
47 | $table->addColumn('name', 'Text', ['caption' => __('Permissions')]); |
||
48 | |||
49 | $table->addColumn(null, new Template([['i', 'class' => 'indicator arrow circle right icon']]), ['caption' => 'Test'])->setAttr('class', ['right aligned']); |
||
50 | |||
51 | eval_css(' |
||
52 | table.selectable tr:not(.active) .indicator { |
||
53 | display: none; |
||
54 | }'); |
||
55 | |||
56 | $table->on('click', 'tr', $this->reload(new jsExpression('$(this).data("id")'))); |
||
57 | |||
58 | if ($permissionId = $this->permissionId()) { |
||
59 | $permission = Permission::findById($permissionId); |
||
60 | |||
61 | $this->putModuleVariable('permission', $permissionId); |
||
62 | |||
63 | $table->js(true)->find("tr[data-id=$permission->id]")->addClass('active'); |
||
64 | |||
65 | $rolesData = $permission->roles()->get()->map(function($role) { |
||
66 | $role['name'] = trans($role['name']); |
||
67 | |||
68 | return $role; |
||
69 | })->toArray(); |
||
70 | |||
71 | $column = $this->columns()->addColumn(); |
||
72 | $rolesTable = $column->add('Table'); |
||
73 | $rolesTable->setModel($this->getModel($rolesData), false); |
||
74 | |||
75 | $rolesTable->addColumn('name', 'Text', ['caption' => __('Roles allowed to :permission', ['permission' => $permission->name])]); |
||
76 | |||
77 | $roleActions = $rolesTable->addColumn(null, 'Actions'); |
||
78 | $roleActions->addAction($this->deleteButton(), function($jQuery, $roleId) use ($permission) { |
||
79 | Role::findById($roleId)->revokePermissionTo($permission); |
||
80 | |||
81 | return $this->reload(); |
||
82 | }, __('Revoke permission to role?')); |
||
83 | |||
84 | $usersData = $permission->users()->get()->toArray(); |
||
85 | |||
86 | $usersTable = $column->add('Table'); |
||
87 | $usersTable->setModel($this->getModel($usersData), false); |
||
88 | |||
89 | $usersTable->addColumn('name', 'Text', ['caption' => __('Users allowed to :permission', ['permission' => $permission->name])]); |
||
90 | |||
91 | $userActions = $usersTable->addColumn(null, 'Actions'); |
||
92 | $userActions->addAction($this->deleteButton(), function($jQuery, $userId) use ($permission) { |
||
93 | User::find($userId)->revokePermissionTo($permission); |
||
94 | |||
95 | return $this->reload(); |
||
96 | }, __('Revoke permission to user?')); |
||
97 | } |
||
178 |