Conditions | 16 |
Paths | 39 |
Total Lines | 24 |
Code Lines | 18 |
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 /** MicroConsoleResolver */ |
||
58 | public function getOption($char = '', $name = '', $required = null) |
||
59 | { |
||
60 | if (!$char && !$name) { |
||
61 | return false; |
||
62 | } |
||
63 | if ($char && (1 < strlen($char) || 1 !== preg_match('/^\w$/', $char))) { |
||
64 | return false; |
||
65 | } |
||
66 | if ($name && (1 !== preg_match('/^\w+$/', $name))) { |
||
67 | return false; |
||
68 | } |
||
69 | switch ($required) { |
||
70 | case true: |
||
71 | $char = $char ? $char . ':' : $char; |
||
72 | $name = $name ? $name . ':' : $name; |
||
73 | break; |
||
74 | case false: |
||
75 | $char = $char ? $char . '::' : $char; |
||
76 | $name = $name ? $name . '::' : $name; |
||
77 | break; |
||
78 | } |
||
79 | $argv = ($opts = getopt($char, [$name])) ? array_shift($opts) : []; |
||
80 | return is_array($argv) ? array_shift($argv) : $argv; |
||
81 | } |
||
82 | } |
||
83 |