Conditions | 14 |
Paths | 2049 |
Total Lines | 26 |
Code Lines | 20 |
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 |
||
58 | private function get_output( $output ) { |
||
59 | if ( ! isset( $output['element'] ) ) { |
||
60 | return array(); |
||
61 | } |
||
62 | if ( ! isset( $output['sanitize_callback'] ) && isset( $output['callback'] ) ) { |
||
63 | $output['sanitize_callback'] = $output['callback']; |
||
64 | } |
||
65 | // Convert element arrays to strings. |
||
66 | if ( is_array( $output['element'] ) ) { |
||
67 | $output['element'] = array_unique( $output['element'] ); |
||
68 | sort( $output['element'] ); |
||
69 | $output['element'] = implode( ',', $output['element'] ); |
||
70 | } |
||
71 | return array( |
||
72 | 'element' => $output['element'], |
||
73 | 'property' => ( isset( $output['property'] ) ) ? $output['property'] : '', |
||
74 | 'media_query' => ( isset( $output['media_query'] ) ) ? $output['media_query'] : 'global', |
||
75 | 'sanitize_callback' => ( isset( $output['sanitize_callback'] ) ) ? $output['sanitize_callback'] : '', |
||
76 | 'units' => ( isset( $output['units'] ) ) ? $output['units'] : '', |
||
77 | 'prefix' => ( isset( $output['prefix'] ) ) ? $output['prefix'] : '', |
||
78 | 'suffix' => ( isset( $output['suffix'] ) ) ? $output['suffix'] : '', |
||
79 | 'exclude' => ( isset( $output['exclude'] ) ) ? $output['exclude'] : false, |
||
80 | 'value_pattern' => ( isset( $output['value_pattern'] ) ) ? $output['value_pattern'] : '$', |
||
81 | 'pattern_replace' => ( isset( $output['pattern_replace'] ) ) ? $output['pattern_replace'] : array(), |
||
82 | ); |
||
83 | } |
||
84 | } |
||
85 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: