We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 6 |
| Paths | 10 |
| Total Lines | 53 |
| Code Lines | 33 |
| 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 |
||
| 30 | public function handle() |
||
| 31 | { |
||
| 32 | $routeName = $this->argument('route'); |
||
| 33 | $permissions = ['list', 'create', 'update', 'reorder', 'delete']; |
||
| 34 | $permissionsAdded = 0; |
||
| 35 | $customPermissions = $this->option('permission'); |
||
| 36 | |||
| 37 | if( count($customPermissions) > 0 ){ |
||
| 38 | $permissions = $customPermissions; |
||
| 39 | } |
||
| 40 | |||
| 41 | $bar = $this->output->createProgressBar(count($permissions)); |
||
| 42 | |||
| 43 | foreach($permissions as $permission){ |
||
| 44 | |||
| 45 | $permissionName = trim($routeName, '/') . '/' . trim($permission, '/'); |
||
| 46 | $permissionName = strtolower($permissionName); |
||
| 47 | |||
| 48 | $existingPermission = Permission::where(['name' => $permissionName])->first(); |
||
| 49 | |||
| 50 | if( $existingPermission ){ |
||
| 51 | |||
| 52 | $continueAdding = $this->confirm("$permissionName already exists, do you want to carry on? [y|N]"); |
||
| 53 | |||
| 54 | if( $continueAdding ){ |
||
| 55 | $bar->setMessage("Skipping $permissionName"); |
||
| 56 | $bar->advance(); |
||
| 57 | continue; |
||
| 58 | } |
||
| 59 | else { |
||
| 60 | $bar->finish(); |
||
| 61 | return $this->error("\nCancelled adding any more permissions."); |
||
| 62 | } |
||
| 63 | } |
||
| 64 | else { |
||
| 65 | $newPermission = Permission::create(['name' => $permissionName]); |
||
| 66 | $newPermission->save(); |
||
| 67 | |||
| 68 | if( $newPermission->id ){ |
||
| 69 | $permissionsAdded++; |
||
| 70 | $bar->setMessage("$newPermission->name added with ID: $newPermission->id"); |
||
| 71 | $bar->advance(); |
||
| 72 | } |
||
| 73 | else { |
||
| 74 | $bar->setMessage("$permissionName could not be created."); |
||
| 75 | $bar->advance(); |
||
| 76 | } |
||
| 77 | } |
||
| 78 | } |
||
| 79 | |||
| 80 | $bar->finish(); |
||
| 81 | $this->info("\nFinished adding $permissionsAdded new permissions"); |
||
| 82 | } |
||
| 83 | } |
||
| 84 |
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.