| Conditions | 26 |
| Paths | 234 |
| Total Lines | 88 |
| Code Lines | 76 |
| 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 |
||
| 33 | public function handle(NameFixer $nameFixer, NNTP $nntp): int |
||
| 34 | { |
||
| 35 | $method = $this->argument('method'); |
||
| 36 | $update = $this->option('update'); |
||
| 37 | $setStatus = $this->option('set-status'); |
||
| 38 | $show = $this->option('show') ? 1 : 2; |
||
| 39 | |||
| 40 | // Set category option |
||
| 41 | $categoryOption = $this->option('category'); |
||
| 42 | $other = 1; |
||
| 43 | if ($categoryOption === 'all') { |
||
| 44 | $other = 2; |
||
| 45 | } elseif ($categoryOption === 'predb_id') { |
||
| 46 | $other = 3; |
||
| 47 | } |
||
| 48 | |||
| 49 | // Connect to NNTP if method requires it |
||
| 50 | if ($method === '7' || $method === '8') { |
||
| 51 | $compressedHeaders = config('nntmux_nntp.compressed_headers'); |
||
| 52 | if ((config('nntmux_nntp.use_alternate_nntp_server') === true ? |
||
| 53 | $nntp->doConnect($compressedHeaders, true) : |
||
| 54 | $nntp->doConnect()) !== true) { |
||
| 55 | $this->error('Unable to connect to usenet.'); |
||
| 56 | return 1; |
||
| 57 | } |
||
| 58 | } |
||
| 59 | |||
| 60 | switch ($method) { |
||
| 61 | case '3': |
||
| 62 | $nameFixer->fixNamesWithNfo(1, $update, $other, $setStatus, $show); |
||
| 63 | break; |
||
| 64 | case '4': |
||
| 65 | $nameFixer->fixNamesWithNfo(2, $update, $other, $setStatus, $show); |
||
| 66 | break; |
||
| 67 | case '5': |
||
| 68 | $nameFixer->fixNamesWithFiles(1, $update, $other, $setStatus, $show); |
||
| 69 | break; |
||
| 70 | case '6': |
||
| 71 | $nameFixer->fixNamesWithFiles(2, $update, $other, $setStatus, $show); |
||
| 72 | break; |
||
| 73 | case '7': |
||
| 74 | $nameFixer->fixNamesWithPar2(1, $update, $other, $setStatus, $show, $nntp); |
||
| 75 | break; |
||
| 76 | case '8': |
||
| 77 | $nameFixer->fixNamesWithPar2(2, $update, $other, $setStatus, $show, $nntp); |
||
| 78 | break; |
||
| 79 | case '9': |
||
| 80 | $nameFixer->fixNamesWithMedia(1, $update, $other, $setStatus, $show); |
||
| 81 | break; |
||
| 82 | case '10': |
||
| 83 | $nameFixer->fixNamesWithMedia(2, $update, $other, $setStatus, $show); |
||
| 84 | break; |
||
| 85 | case '11': |
||
| 86 | $nameFixer->fixXXXNamesWithFiles(1, $update, $other, $setStatus, $show); |
||
| 87 | break; |
||
| 88 | case '12': |
||
| 89 | $nameFixer->fixXXXNamesWithFiles(2, $update, $other, $setStatus, $show); |
||
| 90 | break; |
||
| 91 | case '13': |
||
| 92 | $nameFixer->fixNamesWithSrr(1, $update, $other, $setStatus, $show); |
||
| 93 | break; |
||
| 94 | case '14': |
||
| 95 | $nameFixer->fixNamesWithSrr(2, $update, $other, $setStatus, $show); |
||
| 96 | break; |
||
| 97 | case '15': |
||
| 98 | $nameFixer->fixNamesWithParHash(1, $update, $other, $setStatus, $show); |
||
| 99 | break; |
||
| 100 | case '16': |
||
| 101 | $nameFixer->fixNamesWithParHash(2, $update, $other, $setStatus, $show); |
||
| 102 | break; |
||
| 103 | case '17': |
||
| 104 | $nameFixer->fixNamesWithMediaMovieName(1, $update, $other, $setStatus, $show); |
||
| 105 | break; |
||
| 106 | case '18': |
||
| 107 | $nameFixer->fixNamesWithMediaMovieName(2, $update, $other, $setStatus, $show); |
||
| 108 | break; |
||
| 109 | case '19': |
||
| 110 | $nameFixer->fixNamesWithCrc(1, $update, $other, $setStatus, $show); |
||
| 111 | break; |
||
| 112 | case '20': |
||
| 113 | $nameFixer->fixNamesWithCrc(2, $update, $other, $setStatus, $show); |
||
| 114 | break; |
||
| 115 | default: |
||
| 116 | $this->showHelp(); |
||
| 117 | return 1; |
||
| 118 | } |
||
| 119 | |||
| 120 | return 0; |
||
| 121 | } |
||
| 158 |