| Conditions | 9 |
| Paths | 17 |
| Total Lines | 58 |
| Code Lines | 41 |
| 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 |
||
| 35 | public function handle(): int |
||
| 36 | { |
||
| 37 | $type = $this->argument('type'); |
||
| 38 | $guid = $this->argument('guid'); |
||
| 39 | $renamed = $this->argument('renamed') ?? ''; |
||
| 40 | |||
| 41 | if (! $this->isValidChar($guid)) { |
||
| 42 | $this->error('GUID character must be a-f or 0-9.'); |
||
| 43 | |||
| 44 | return self::FAILURE; |
||
| 45 | } |
||
| 46 | |||
| 47 | try { |
||
| 48 | switch ($type) { |
||
| 49 | case 'additional': |
||
| 50 | $nntp = $this->getNntp(); |
||
| 51 | (new ProcessAdditional(['Echo' => true, 'NNTP' => $nntp]))->start('', $guid); |
||
|
|
|||
| 52 | break; |
||
| 53 | |||
| 54 | case 'nfo': |
||
| 55 | $nntp = $this->getNntp(); |
||
| 56 | (new Nfo)->processNfoFiles( |
||
| 57 | $nntp, |
||
| 58 | '', |
||
| 59 | $guid, |
||
| 60 | (int) Settings::settingValue('lookupimdb'), |
||
| 61 | (int) Settings::settingValue('lookuptv') |
||
| 62 | ); |
||
| 63 | break; |
||
| 64 | |||
| 65 | case 'movie': |
||
| 66 | (new PostProcess)->processMovies('', $guid, $renamed); |
||
| 67 | break; |
||
| 68 | |||
| 69 | case 'tv': |
||
| 70 | (new PostProcess)->processTv('', $guid, $renamed); |
||
| 71 | break; |
||
| 72 | |||
| 73 | case 'anime': |
||
| 74 | (new PostProcess)->processAnime('', $guid); |
||
| 75 | break; |
||
| 76 | |||
| 77 | case 'books': |
||
| 78 | (new PostProcess)->processBooks('', $guid); |
||
| 79 | break; |
||
| 80 | |||
| 81 | default: |
||
| 82 | $this->error('Invalid type. Must be: additional, nfo, movie, tv, anime, or books.'); |
||
| 83 | |||
| 84 | return self::FAILURE; |
||
| 85 | } |
||
| 86 | |||
| 87 | return self::SUCCESS; |
||
| 88 | } catch (\Throwable $e) { |
||
| 89 | Log::error($e->getTraceAsString()); |
||
| 90 | $this->error($e->getMessage()); |
||
| 91 | |||
| 92 | return self::FAILURE; |
||
| 93 | } |
||
| 124 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.