| Conditions | 6 |
| Paths | 6 |
| Total Lines | 119 |
| Code Lines | 84 |
| 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 namespace Afrittella\BackProject\Console\Commands; |
||
| 26 | public function handle() |
||
| 27 | { |
||
| 28 | |||
| 29 | $nodes = [ |
||
| 30 | 'name' => 'admin-menu', |
||
| 31 | 'title' => 'Administrator Menu', |
||
| 32 | 'description' => 'A default menu you can use for back office purposes', |
||
| 33 | 'route' => null, |
||
| 34 | 'icon' => null, |
||
| 35 | 'is_active' => 1, |
||
| 36 | 'is_protected' => 1, |
||
| 37 | 'children' => [ |
||
| 38 | [ |
||
| 39 | 'name' => 'dashboard', |
||
| 40 | 'permission' => 'backend', |
||
| 41 | 'title' => 'Dashboard', |
||
| 42 | 'description' => 'Your dashboard', |
||
| 43 | 'route' => config('back-project.route_prefix').'/dashboard', |
||
| 44 | 'icon' => 'fa fa-dashboard', |
||
| 45 | 'is_active' => 1, |
||
| 46 | 'is_protected' => 1, |
||
| 47 | ], |
||
| 48 | [ |
||
| 49 | 'name' => 'auth', |
||
| 50 | 'title' => 'Authorization', |
||
| 51 | 'description' => 'Manage Users, Roles and Permissions', |
||
| 52 | 'route' => null, |
||
| 53 | 'icon' => 'fa fa-key', |
||
| 54 | 'is_active' => 1, |
||
| 55 | 'children' => [ |
||
| 56 | [ |
||
| 57 | 'name' => 'users', |
||
| 58 | 'permission' => 'administration', |
||
| 59 | 'title' => 'Users', |
||
| 60 | 'description' => 'Manage Users', |
||
| 61 | 'route' => config('back-project.route_prefix').'/users', |
||
| 62 | 'icon' => 'fa fa-users', |
||
| 63 | 'is_active' => 1 |
||
| 64 | ], |
||
| 65 | [ |
||
| 66 | 'name' => 'roles', |
||
| 67 | 'permission' => 'administration', |
||
| 68 | 'title' => 'Roles', |
||
| 69 | 'description' => 'Manage Roles', |
||
| 70 | 'route' => config('back-project.route_prefix').'/roles', |
||
| 71 | 'icon' => 'fa fa-group', |
||
| 72 | 'is_active' => 1 |
||
| 73 | ], |
||
| 74 | [ |
||
| 75 | 'name' => 'permissions', |
||
| 76 | 'permission' => 'administration', |
||
| 77 | 'title' => 'Permissions', |
||
| 78 | 'description' => 'Manage Permissions', |
||
| 79 | 'route' => config('back-project.route_prefix').'/permissions', |
||
| 80 | 'icon' => 'fa fa-group', |
||
| 81 | 'is_active' => 1 |
||
| 82 | ] |
||
| 83 | ] |
||
| 84 | ], |
||
| 85 | [ |
||
| 86 | 'name' => 'menus', |
||
| 87 | 'permission' => 'administration', |
||
| 88 | 'title' => 'Menus', |
||
| 89 | 'description' => 'Manage menus', |
||
| 90 | 'route' => config('back-project.route_prefix').'/menus', |
||
| 91 | 'icon' => 'fa fa-ellipsis-v', |
||
| 92 | 'is_active' => 1, |
||
| 93 | 'is_protected' => 1, |
||
| 94 | ], |
||
| 95 | [ |
||
| 96 | 'name' => 'attachments', |
||
| 97 | 'permission' => 'backend', |
||
| 98 | 'title' => 'My Media', |
||
| 99 | 'description' => 'Manage attachments', |
||
| 100 | 'route' => config('back-project.route_prefix').'/attachments', |
||
| 101 | 'icon' => 'fa fa-user-circle-o', |
||
| 102 | 'is_active' => 1, |
||
| 103 | 'is_protected' => 1, |
||
| 104 | ], |
||
| 105 | [ |
||
| 106 | 'name' => 'admin-attachments', |
||
| 107 | 'permission' => 'administration', |
||
| 108 | 'title' => 'All Media', |
||
| 109 | 'description' => 'Manage all user\'s attachments', |
||
| 110 | 'route' => config('back-project.route_prefix').'/media', |
||
| 111 | 'icon' => 'fa fa-file-image-o', |
||
| 112 | 'is_active' => 1, |
||
| 113 | 'is_protected' => 1, |
||
| 114 | ], |
||
| 115 | ] |
||
| 116 | ]; |
||
| 117 | |||
| 118 | // Truncate menu table |
||
| 119 | DB::table('menus')->truncate(); |
||
| 120 | |||
| 121 | Menu::create($nodes); |
||
| 122 | |||
| 123 | $menus = DB::table('menus')->select('permission')->where('permission', '<>', '')->groupBy('permission')->get(); |
||
| 124 | |||
| 125 | $role = Role::where('name', '=', 'administrator')->first(); |
||
| 126 | $user_role = Role::where('name', '=', 'user')->first(); |
||
| 127 | |||
| 128 | foreach ($menus as $menu): |
||
| 129 | |||
| 130 | if (!empty($menu->permission)) { |
||
| 131 | $permission = Permission::firstOrCreate(['name' => $menu->permission]); |
||
|
|
|||
| 132 | |||
| 133 | if (!$role->hasPermissionTo($menu->permission)) { |
||
| 134 | $role->givePermissionTo($menu->permission); |
||
| 135 | } |
||
| 136 | |||
| 137 | if ($menu->permission == 'backend' and !$role->hasPermissionTo($menu->permission)) { |
||
| 138 | $user_role->givePermissionTo($menu->permission); |
||
| 139 | } |
||
| 140 | } |
||
| 141 | endforeach; |
||
| 142 | |||
| 143 | $this->info('Seeding admin-menu'.'...'); |
||
| 144 | } |
||
| 145 | } |
||
| 146 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.