Conditions | 10 |
Paths | 9 |
Total Lines | 28 |
Code Lines | 22 |
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 |
||
28 | private static function formatStation($idx, $station) { |
||
29 | $defaults = array( |
||
30 | 'file' => null, |
||
31 | 'line' => null, |
||
32 | 'class' => null, |
||
33 | 'function' => null, |
||
34 | 'type' => null, |
||
35 | 'args' => array(), |
||
36 | ); |
||
37 | $station = array_merge($defaults, $station); |
||
38 | self::p("#%- 3s%s:%d\n", $idx, $station['file'] ?: 'unknown', $station['line']); |
||
39 | if($station['class'] !== null || $station['function'] !== null) { |
||
40 | $params = array(); |
||
41 | foreach(is_array($station['args']) ? $station['args'] : array() as $argument) { |
||
42 | if(is_array($argument)) { |
||
43 | $params[] = sprintf('array%d', count($argument)); |
||
44 | } elseif(is_object($argument)) { |
||
45 | $params[] = sprintf('%s', get_class($argument)); |
||
46 | } else { |
||
47 | $params[] = gettype($argument); |
||
48 | } |
||
49 | } |
||
50 | if(strpos($station['function'], '{closure}') !== false && $station['class'] !== null) { |
||
51 | $station['function'] = '{closure}'; |
||
52 | } |
||
53 | self::p(" %s%s%s%s%s%s\n", $station['class'], $station['type'], $station['function'], "(", join(', ', $params), ")"); |
||
54 | } |
||
55 | } |
||
56 | |||
66 |