Conditions | 8 |
Paths | 14 |
Total Lines | 57 |
Code Lines | 31 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
85 | public static function route(App $app, array $argv): Cmd { |
||
86 | |||
87 | $cmd = $app->setup(); |
||
88 | |||
89 | $appspecs = $cmd->getOptionCollection(); |
||
90 | |||
91 | $parser = new ContinuousOptionParser($appspecs); |
||
92 | |||
93 | try { |
||
94 | $cmd->optionResult = $parser->parse($argv); |
||
95 | } catch (Exception $e) { |
||
96 | $cmd->optionParseException = $e; |
||
97 | return $cmd; |
||
98 | } |
||
99 | |||
100 | while (!$parser->isEnd()) { |
||
101 | |||
102 | $currentArgument = $parser->getCurrentArgument(); |
||
103 | |||
104 | $subcommand = null; |
||
105 | if ($cmd->hasSubCmd($currentArgument)) { |
||
106 | $_cmd = $cmd->getSubCmd($currentArgument); |
||
107 | |||
108 | if($_cmd !== null) { |
||
109 | $subcommand = $_cmd; |
||
110 | } |
||
111 | } |
||
112 | |||
113 | if($subcommand !== null) { |
||
114 | |||
115 | $cmd = $subcommand; |
||
116 | $parser->advance(); |
||
117 | |||
118 | $cmd->optionResult = new OptionResult(); |
||
119 | |||
120 | if (!empty($cmd->optionSpecs)) { |
||
121 | |||
122 | $specs = $cmd->getOptionCollection(); |
||
123 | |||
124 | $parser->setSpecs($specs); |
||
125 | |||
126 | try { |
||
127 | $cmd->optionResult = $parser->continueParse(); |
||
128 | } catch (Exception $e) { |
||
129 | $cmd->optionParseException = $e; |
||
130 | return $cmd; |
||
131 | } |
||
132 | |||
133 | continue; |
||
134 | } |
||
135 | |||
136 | } else { |
||
137 | $cmd->arguments[] = $parser->advance(); |
||
138 | } |
||
139 | } |
||
140 | |||
141 | return $cmd; |
||
142 | } |
||
145 | } |