| Conditions | 14 |
| Paths | 18 |
| Total Lines | 16 |
| Code Lines | 15 |
| Lines | 6 |
| Ratio | 37.5 % |
| 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 |
||
| 41 | protected function parseArgs( $argv = null ) { |
||
| 42 | $argv = $argv ? $argv : $_SERVER['argv']; array_shift($argv); $o = []; |
||
| 43 | for ($i = 0, $j = count($argv); $i < $j; $i++) { $a = $argv[$i]; |
||
| 44 | if (substr($a, 0, 2) == '--') { $eq = strpos($a, '='); |
||
| 45 | if ($eq !== false) { $o[substr($a, 2, $eq - 2)] = substr($a, $eq + 1); } |
||
| 46 | View Code Duplication | else { $k = substr($a, 2); |
|
| 47 | if ($i + 1 < $j && $argv[$i + 1][0] !== '-') { $o[$k] = $argv[$i + 1]; $i++; } |
||
| 48 | else if (!isset($o[$k])) { $o[$k] = true; } } } |
||
| 49 | else if (substr($a, 0, 1) == '-') { |
||
| 50 | if (substr($a, 2, 1) == '=') { $o[substr($a, 1, 1)] = substr($a, 3); } |
||
| 51 | View Code Duplication | else { |
|
| 52 | foreach (str_split(substr($a, 1)) as $k) { if (!isset($o[$k])) { $o[$k] = true; } } |
||
| 53 | if ($i + 1 < $j && $argv[$i + 1][0] !== '-') { $o[$k] = $argv[$i + 1]; $i++; } } } |
||
| 54 | else { $o[] = $a; } } |
||
| 55 | return $o; |
||
| 56 | } |
||
| 57 | |||
| 123 | // EOF |