| Conditions | 25 |
| Paths | 117 |
| Total Lines | 90 |
| Code Lines | 76 |
| 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 |
||
| 33 | public function handle(NameFixingService $nameFixingService, NNTP $nntp): int |
||
| 34 | { |
||
| 35 | $method = $this->argument('method'); |
||
| 36 | $update = (bool) $this->option('update'); |
||
| 37 | $setStatus = (bool) $this->option('set-status'); |
||
| 38 | $show = $this->option('show'); |
||
| 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 | |||
| 57 | return 1; |
||
| 58 | } |
||
| 59 | } |
||
| 60 | |||
| 61 | switch ($method) { |
||
| 62 | case '3': |
||
| 63 | $nameFixingService->fixNamesWithNfo(1, $update, $other, $setStatus, $show); |
||
|
|
|||
| 64 | break; |
||
| 65 | case '4': |
||
| 66 | $nameFixingService->fixNamesWithNfo(2, $update, $other, $setStatus, $show); |
||
| 67 | break; |
||
| 68 | case '5': |
||
| 69 | $nameFixingService->fixNamesWithFiles(1, $update, $other, $setStatus, $show); |
||
| 70 | break; |
||
| 71 | case '6': |
||
| 72 | $nameFixingService->fixNamesWithFiles(2, $update, $other, $setStatus, $show); |
||
| 73 | break; |
||
| 74 | case '7': |
||
| 75 | $nameFixingService->fixNamesWithPar2(1, $update, $other, $setStatus, $show, $nntp); |
||
| 76 | break; |
||
| 77 | case '8': |
||
| 78 | $nameFixingService->fixNamesWithPar2(2, $update, $other, $setStatus, $show, $nntp); |
||
| 79 | break; |
||
| 80 | case '9': |
||
| 81 | $nameFixingService->fixNamesWithMedia(1, $update, $other, $setStatus, $show); |
||
| 82 | break; |
||
| 83 | case '10': |
||
| 84 | $nameFixingService->fixNamesWithMedia(2, $update, $other, $setStatus, $show); |
||
| 85 | break; |
||
| 86 | case '11': |
||
| 87 | $nameFixingService->fixXXXNamesWithFiles(1, $update, $other, $setStatus, $show); |
||
| 88 | break; |
||
| 89 | case '12': |
||
| 90 | $nameFixingService->fixXXXNamesWithFiles(2, $update, $other, $setStatus, $show); |
||
| 91 | break; |
||
| 92 | case '13': |
||
| 93 | $nameFixingService->fixNamesWithSrr(1, $update, $other, $setStatus, $show); |
||
| 94 | break; |
||
| 95 | case '14': |
||
| 96 | $nameFixingService->fixNamesWithSrr(2, $update, $other, $setStatus, $show); |
||
| 97 | break; |
||
| 98 | case '15': |
||
| 99 | $nameFixingService->fixNamesWithParHash(1, $update, $other, $setStatus, $show); |
||
| 100 | break; |
||
| 101 | case '16': |
||
| 102 | $nameFixingService->fixNamesWithParHash(2, $update, $other, $setStatus, $show); |
||
| 103 | break; |
||
| 104 | case '17': |
||
| 105 | $nameFixingService->fixNamesWithMediaMovieName(1, $update, $other, $setStatus, $show); |
||
| 106 | break; |
||
| 107 | case '18': |
||
| 108 | $nameFixingService->fixNamesWithMediaMovieName(2, $update, $other, $setStatus, $show); |
||
| 109 | break; |
||
| 110 | case '19': |
||
| 111 | $nameFixingService->fixNamesWithCrc(1, $update, $other, $setStatus, $show); |
||
| 112 | break; |
||
| 113 | case '20': |
||
| 114 | $nameFixingService->fixNamesWithCrc(2, $update, $other, $setStatus, $show); |
||
| 115 | break; |
||
| 116 | default: |
||
| 117 | $this->showHelp(); |
||
| 118 | |||
| 119 | return 1; |
||
| 120 | } |
||
| 121 | |||
| 122 | return 0; |
||
| 123 | } |
||
| 160 |