| Conditions | 11 |
| Paths | 29 |
| Total Lines | 62 |
| Code Lines | 51 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | 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 |
||
| 37 | public function handle() |
||
| 38 | { |
||
| 39 | $countQuery = Release::query(); |
||
| 40 | if ($this->option('misc')) { |
||
| 41 | $countQuery->whereIn('categories_id', Category::OTHERS_GROUP); |
||
| 42 | } elseif ($this->option('all')) { |
||
| 43 | $countQuery->where('iscategorized', 0); |
||
| 44 | } elseif ($this->option('group')) { |
||
| 45 | $countQuery->where('groups_id', $this->option('group')); |
||
| 46 | } elseif ($this->option('groups')) { |
||
| 47 | $countQuery->whereIn('groups_id', explode(',', $this->option('groups'))); |
||
| 48 | } elseif ($this->option('category')) { |
||
| 49 | $countQuery->where('categories_id', $this->option('category')); |
||
| 50 | } elseif ($this->option('categories')) { |
||
| 51 | $countQuery->whereIn('categories_id', explode(',', $this->option('categories'))); |
||
| 52 | } elseif ($this->option('test')) { |
||
| 53 | $countQuery->where('iscategorized', 0); |
||
| 54 | } else { |
||
| 55 | $this->error('You must specify at least one option. See: --help'); |
||
| 56 | exit(); |
||
|
|
|||
| 57 | } |
||
| 58 | |||
| 59 | $count = $countQuery->count(); |
||
| 60 | |||
| 61 | $cat = new Categorize(); |
||
| 62 | $results = $countQuery->select(['id', 'searchname', 'fromname', 'groups_id', 'categories_id'])->get(); |
||
| 63 | $bar = $this->output->createProgressBar($count); |
||
| 64 | $bar->start(); |
||
| 65 | foreach ($results as $result) { |
||
| 66 | $bar->advance(); |
||
| 67 | $catId = $cat->determineCategory($result->groups_id, $result->searchname, $result->fromname); |
||
| 68 | if ((int) $result->categories_id !== (int) $catId['categories_id']) { |
||
| 69 | if ($this->option('test')) { |
||
| 70 | $this->info('Would have changed '.$result->searchname.' from '.$result->categories_id.' to '.$catId['categories_id']); |
||
| 71 | } else { |
||
| 72 | Release::query()->where('id', $result->id)->update([ |
||
| 73 | 'iscategorized' => 1, |
||
| 74 | 'videos_id' => 0, |
||
| 75 | 'tv_episodes_id' => 0, |
||
| 76 | 'imdbid' => null, |
||
| 77 | 'musicinfo_id' => null, |
||
| 78 | 'consoleinfo_id' => null, |
||
| 79 | 'gamesinfo_id' => 0, |
||
| 80 | 'bookinfo_id' => 0, |
||
| 81 | 'anidbid' => null, |
||
| 82 | 'xxxinfo_id' => 0, |
||
| 83 | 'categories_id' => $catId['categories_id'], |
||
| 84 | ]); |
||
| 85 | |||
| 86 | NameFixer::echoChangedReleaseName([ |
||
| 87 | 'new_name' => $result->searchname, |
||
| 88 | 'old_name' => $result->searchname, |
||
| 89 | 'new_category' => $catId['categories_id'], |
||
| 90 | 'old_category' => $result->categories_id, |
||
| 91 | 'group' => $result->group->name, |
||
| 92 | 'releases_id' => $result->id, |
||
| 93 | 'method' => 'Recategorize', |
||
| 94 | ]); |
||
| 95 | } |
||
| 96 | } |
||
| 97 | } |
||
| 98 | $bar->finish(); |
||
| 99 | } |
||
| 101 |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.