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