| Conditions | 10 | 
| Paths | 14 | 
| Total Lines | 33 | 
| Code Lines | 22 | 
| 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 | ||
| 24 | 	protected function process_output( $output, $value ) { | ||
| 25 | |||
| 26 | $output = wp_parse_args( $output, array( | ||
| 27 | 'element' => '', | ||
| 28 | 'property' => '', | ||
| 29 | 'media_query' => 'global', | ||
| 30 | 'prefix' => '', | ||
| 31 | 'suffix' => '', | ||
| 32 | ) ); | ||
| 33 | |||
| 34 | 		if ( is_array( $value ) ) { | ||
| 35 | 			foreach ( $value as $key => $sub_value ) { | ||
| 36 | |||
| 37 | $property = ( empty( $output['property'] ) ) ? $key : $output['property'] . '-' . $key; | ||
| 38 | 				if ( isset( $output['choice'] ) && $output['property'] ) { | ||
| 39 | 					if ( $key === $output['choice'] ) { | ||
| 40 | $property = $output['property']; | ||
| 41 | 					} else { | ||
| 42 | continue; | ||
| 43 | } | ||
| 44 | } | ||
| 45 | 				if ( false !== strpos( $output['property'], '%%' ) ) { | ||
| 46 | $property = str_replace( '%%', $key, $output['property'] ); | ||
| 47 | } | ||
| 48 | $this->styles[ $output['media_query'] ][ $output['element'] ][ $property ] = $output['prefix'] . $this->process_property_value( $property, $value[ $key ] ) . $output['suffix']; | ||
| 49 | } | ||
| 50 | 		} elseif ( isset( $output['choice'] ) ) { | ||
| 51 | 			if ( false !== strpos( $output['property'], '%%' ) ) { | ||
| 52 | $output['property'] = str_replace( '%%', $key, $output['property'] ); | ||
|  | |||
| 53 | } | ||
| 54 | $this->styles[ $output['media_query'] ][ $output['element'] ][ $output['property'] ] = $output['prefix'] . $this->process_property_value( $output['property'], $value ) . $output['suffix']; | ||
| 55 | } | ||
| 56 | } | ||
| 57 | } | ||
| 58 | 
This error can happen if you refactor code and forget to move the variable initialization.
Let’s take a look at a simple example:
The above code is perfectly fine. Now imagine that we re-order the statements:
In that case,
$xwould be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.