| Conditions | 7 |
| Paths | 20 |
| Total Lines | 51 |
| Code Lines | 28 |
| 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 |
||
| 47 | public function handle() |
||
| 48 | { |
||
| 49 | $data = array_filter([ |
||
| 50 | |||
| 51 | // Required ability attributes |
||
| 52 | 'name' => $this->option('name'), |
||
| 53 | 'slug' => $this->option('slug'), |
||
| 54 | 'description' => $this->option('description'), |
||
| 55 | |||
| 56 | ], [ |
||
| 57 | $this, |
||
| 58 | 'filter' |
||
| 59 | ]); |
||
| 60 | |||
| 61 | // Get required argument |
||
| 62 | $field = $this->argument('field') ?: $this->ask(Lang::get('rinvex.fort::artisan.ability.invalid')); |
||
| 63 | |||
| 64 | // Find single ability |
||
| 65 | if (intval($field)) { |
||
| 66 | $ability = $this->laravel['rinvex.fort.ability']->find($field); |
||
| 67 | } else { |
||
| 68 | $ability = $this->laravel['rinvex.fort.ability']->findWhere(['slug' => $field])->first(); |
||
| 69 | } |
||
| 70 | |||
| 71 | if (! $ability) { |
||
| 72 | return $this->error(Lang::get('rinvex.fort::artisan.ability.invalid', ['field' => $field])); |
||
| 73 | } |
||
| 74 | |||
| 75 | $rules = [ |
||
| 76 | 'name' => 'sometimes|required|max:255', |
||
| 77 | 'slug' => 'sometimes|required|max:255|unique:'.config('rinvex.fort.tables.abilities'), |
||
| 78 | ]; |
||
| 79 | |||
| 80 | if (! empty($data)) { |
||
| 81 | $validator = app(Factory::class)->make($data, $rules); |
||
| 82 | |||
| 83 | if ($validator->fails()) { |
||
| 84 | $this->error('Errors:'); |
||
| 85 | |||
| 86 | foreach ($validator->errors()->getMessages() as $key => $messages) { |
||
| 87 | $this->error('- '.$key.': '.$messages[0]); |
||
| 88 | } |
||
| 89 | } else { |
||
| 90 | $ability->update($data); |
||
| 91 | |||
| 92 | $this->info(Lang::get('rinvex.fort::artisan.ability.updated').' ['.Lang::get('rinvex.fort::artisan.ability.id').': '.$ability->id.', '.Lang::get('rinvex.fort::artisan.ability.name').': '.$ability->name.', '.Lang::get('rinvex.fort::artisan.ability.slug').': '.$ability->slug.']'); |
||
|
|
|||
| 93 | } |
||
| 94 | } else { |
||
| 95 | $this->info(Lang::get('rinvex.fort::artisan.ability.nothing')); |
||
| 96 | } |
||
| 97 | } |
||
| 98 | |||
| 111 |
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.