Conditions | 11 |
Paths | 16 |
Total Lines | 45 |
Code Lines | 24 |
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 |
||
36 | public static function format( array $stats, $format = null ) { |
||
37 | |||
38 | $output = ''; |
||
39 | |||
40 | if ( $format === self::FORMAT_PLAIN ) { |
||
41 | foreach ( $stats as $key => $value ) { |
||
42 | $output .= '- ' . $key . "\n"; |
||
43 | |||
44 | if ( !is_array( $value ) ) { |
||
45 | continue; |
||
46 | } |
||
47 | |||
48 | foreach ( $value as $k => $v ) { |
||
49 | $output .= ' - ' . $k . ': ' . $v . "\n"; |
||
50 | } |
||
51 | } |
||
52 | } |
||
53 | |||
54 | if ( $format === self::FORMAT_HTML ) { |
||
55 | $output .= '<ul>'; |
||
56 | foreach ( $stats as $key => $value ) { |
||
57 | $output .= '<li>' . $key . '<ul>'; |
||
58 | |||
59 | if ( !is_array( $value ) ) { |
||
60 | continue; |
||
61 | } |
||
62 | |||
63 | foreach ( $value as $k => $v ) { |
||
64 | $output .= '<li>' . $k . ': ' . $v . "</li>"; |
||
65 | } |
||
66 | $output .= '</ul></li>'; |
||
67 | } |
||
68 | $output .= '</ul>'; |
||
69 | } |
||
70 | |||
71 | if ( $format === self::FORMAT_JSON ) { |
||
72 | $output .= json_encode( $stats, JSON_PRETTY_PRINT ); |
||
73 | } |
||
74 | |||
75 | if ( $format === null ) { |
||
76 | $output = $stats; |
||
77 | } |
||
78 | |||
79 | return $output; |
||
80 | } |
||
81 | |||
126 |