| Conditions | 1 |
| Paths | 1 |
| Total Lines | 64 |
| Code Lines | 30 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 17 | public function run() |
||
| 18 | { |
||
| 19 | // Default Roles ---------------------------------------------------------------- |
||
| 20 | // ------------------------------------------------------------------------------ |
||
| 21 | |||
| 22 | $roleAdmin = Role::create([ |
||
| 23 | 'name' => 'admin', |
||
| 24 | 'description' => 'Super Administrator', |
||
| 25 | 'display_name' => '', |
||
| 26 | ]); |
||
| 27 | |||
| 28 | $roleClient = Role::create([ |
||
| 29 | 'name' => 'client', |
||
| 30 | 'description' => 'Normal User', |
||
| 31 | 'display_name' => '', |
||
| 32 | ]); |
||
| 33 | |||
| 34 | // Default Permissions ---------------------------------------------------------- |
||
| 35 | // ------------------------------------------------------------------------------ |
||
| 36 | |||
| 37 | $p = Permission::create([ |
||
| 38 | 'name' => 'list-all-users', |
||
| 39 | 'description' => 'List all users in the system', |
||
| 40 | 'display_name' => '', |
||
| 41 | ]); |
||
| 42 | |||
| 43 | $roleAdmin->givePermissionTo($p); |
||
| 44 | |||
| 45 | // --------------------------------------- |
||
| 46 | |||
| 47 | $p = Permission::create([ |
||
| 48 | 'name' => 'delete-user', |
||
| 49 | 'description' => '', |
||
| 50 | 'display_name' => '', |
||
| 51 | ]); |
||
| 52 | |||
| 53 | $roleAdmin->givePermissionTo($p); |
||
| 54 | |||
| 55 | // --------------------------------------- |
||
| 56 | |||
| 57 | $p = Permission::create([ |
||
| 58 | 'name' => 'update-user', |
||
| 59 | 'description' => '', |
||
| 60 | 'display_name' => '', |
||
| 61 | ]); |
||
| 62 | |||
| 63 | $roleClient->givePermissionTo($p); |
||
| 64 | $roleAdmin->givePermissionTo($p); |
||
| 65 | |||
| 66 | // --------------------------------------- |
||
| 67 | |||
| 68 | $p = Permission::create([ |
||
| 69 | 'name' => 'manage-roles-permissions', |
||
| 70 | 'description' => 'Create, View, Modify, Assign, Attach.. Roles and Permissions for Users', |
||
| 71 | 'display_name' => '', |
||
| 72 | ]); |
||
| 73 | |||
| 74 | $roleAdmin->givePermissionTo($p); |
||
| 75 | |||
| 76 | // --------------------------------------- |
||
| 77 | |||
| 78 | // ... |
||
| 79 | |||
| 80 | } |
||
| 81 | } |
||
| 82 |