| Conditions | 13 | 
| Paths | 432 | 
| Total Lines | 42 | 
| 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  | 
            ||
| 68 | 	public function sanitize( $value = null ) { | 
            ||
| 69 | |||
| 70 | // Make sure value in an array.  | 
            ||
| 71 | $value = ( ! is_array( $value ) ) ? array() : $value;  | 
            ||
| 72 | |||
| 73 | 		if ( ! isset( $value['mode'] ) || 'linear' !== $value['mode'] || 'radial' !== $value['mode'] ) { | 
            ||
| 74 | $value['mode'] = 'linear';  | 
            ||
| 75 | }  | 
            ||
| 76 | 		foreach ( array( 'start', 'end' ) as $context ) { | 
            ||
| 77 | |||
| 78 | // Make sure value is array.  | 
            ||
| 79 | 			if ( ! isset( $value[ $context ] ) ) { | 
            ||
| 80 | $value[ $context ] = array();  | 
            ||
| 81 | }  | 
            ||
| 82 | |||
| 83 | // Sanitize colors.  | 
            ||
| 84 | 			if ( ! isset( $value[ $context ]['color'] ) ) { | 
            ||
| 85 | $value[ $context ]['color'] = '';  | 
            ||
| 86 | }  | 
            ||
| 87 | $value[ $context ]['color'] = esc_attr( $value[ $context ]['color'] );  | 
            ||
| 88 | |||
| 89 | // Sanitize positions.  | 
            ||
| 90 | 			if ( ! isset( $value[ $context ]['position'] ) ) { | 
            ||
| 91 | $value[ $context ]['position'] = 0;  | 
            ||
| 92 | };  | 
            ||
| 93 | $value[ $context ]['position'] = (int) $value[ $context ]['position'];  | 
            ||
| 94 | $value[ $context ]['position'] = max( min( $value[ $context ]['position'], 100 ), 0 );  | 
            ||
| 95 | }  | 
            ||
| 96 | |||
| 97 | // Sanitize angle.  | 
            ||
| 98 | 		if ( ! isset( $value['angle'] ) ) { | 
            ||
| 99 | $value['angle'] = 0;  | 
            ||
| 100 | }  | 
            ||
| 101 | $value['angle'] = (int) $value['angle'];  | 
            ||
| 102 | $value['angle'] = max( min( $value['angle'], 90 ), -90 );  | 
            ||
| 103 | |||
| 104 | // Sanitize the type.  | 
            ||
| 105 | $value['type'] = ( ! isset( $value['type'] ) || 'linear' !== $value['type'] || 'radial' !== $value['type'] ) ? 'linear' : $value['type'];  | 
            ||
| 106 | |||
| 107 | return $value;  | 
            ||
| 108 | |||
| 109 | }  | 
            ||
| 110 | |||
| 112 |