Conditions | 9 |
Paths | 16 |
Total Lines | 59 |
Code Lines | 29 |
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 |
||
57 | public static function route(App $app, array $argv): ?Cmd { |
||
58 | |||
59 | $cmd = $app->setup(); |
||
60 | |||
61 | $appspecs = $cmd->getOptionCollection(); |
||
62 | |||
63 | $parser = new ContinuousOptionParser($appspecs); |
||
64 | |||
65 | try { |
||
66 | $cmd->optionResult = $parser->parse($argv); |
||
67 | } catch (Exception $e) { |
||
68 | $cmd->optionParseException = $e; |
||
69 | return $cmd; |
||
70 | } |
||
71 | |||
72 | while (!$parser->isEnd()) { |
||
73 | |||
74 | $currentArgument = $parser->getCurrentArgument(); |
||
75 | |||
76 | if ($cmd->hasSubCmd($currentArgument)) { |
||
77 | |||
78 | $parser->advance(); |
||
79 | |||
80 | $cmd = $cmd->getSubCmd($currentArgument); |
||
81 | } |
||
82 | |||
83 | if ($cmd instanceof Cmd) { |
||
84 | |||
85 | $options_parsed = $cmd->optionResult !== null; |
||
86 | |||
87 | if (!$options_parsed) { |
||
88 | |||
89 | $cmd->optionResult = new OptionResult(); |
||
90 | |||
91 | if (!empty($cmd->optionSpecs)) { |
||
92 | |||
93 | $specs = $cmd->getOptionCollection(); |
||
94 | |||
95 | $parser->setSpecs($specs); |
||
96 | |||
97 | try { |
||
98 | $cmd->optionResult = $parser->continueParse(); |
||
99 | } catch (Exception $e) { |
||
100 | $cmd->optionParseException = $e; |
||
101 | return $cmd; |
||
102 | } |
||
103 | |||
104 | continue; |
||
105 | } |
||
106 | } |
||
107 | |||
108 | if ($options_parsed) { |
||
109 | $cmd->arguments[] = $parser->advance(); |
||
110 | } |
||
111 | } |
||
112 | |||
113 | } |
||
114 | |||
115 | return $cmd; |
||
116 | } |
||
119 | } |