| Conditions | 18 |
| Paths | 76 |
| Total Lines | 57 |
| Code Lines | 47 |
| Lines | 12 |
| Ratio | 21.05 % |
| Changes | 2 | ||
| 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 |
||
| 53 | public function sanitize_setting_value( $setting, $raw_value ) { |
||
| 54 | switch ( $setting['type'] ) { |
||
| 55 | case 'checkbox' : |
||
| 56 | $default = ( ! empty( $setting['default'] ) ? $setting['default'] : 'no' ); |
||
| 57 | $value = ( in_array( $raw_value, array( 'yes', 'no' ) ) ? $raw_value : $default ); |
||
| 58 | break; |
||
| 59 | case 'email' : |
||
| 60 | $value = sanitize_email( $raw_value ); |
||
| 61 | $default = ( ! empty( $setting['default'] ) ? $setting['default'] : '' ); |
||
| 62 | $value = ( ! empty( $value ) ? $value : $default ); |
||
| 63 | break; |
||
| 64 | case 'textarea' : |
||
| 65 | $value = wp_kses( trim( $raw_value ), |
||
| 66 | array_merge( |
||
| 67 | array( |
||
| 68 | 'iframe' => array( 'src' => true, 'style' => true, 'id' => true, 'class' => true ) |
||
| 69 | ), |
||
| 70 | wp_kses_allowed_html( 'post' ) |
||
| 71 | ) |
||
| 72 | ); |
||
| 73 | break; |
||
| 74 | case 'multiselect' : |
||
| 75 | case 'multi_select_countries' : |
||
| 76 | $value = array_filter( array_map( 'wc_clean', (array) $raw_value ) ); |
||
| 77 | break; |
||
| 78 | View Code Duplication | case 'image_width' : |
|
| 79 | $value = array(); |
||
| 80 | if ( isset( $raw_value['width'] ) ) { |
||
| 81 | $value['width'] = wc_clean( $raw_value['width'] ); |
||
| 82 | $value['height'] = wc_clean( $raw_value['height'] ); |
||
| 83 | $value['crop'] = isset( $raw_value['crop'] ) ? 1 : 0; |
||
| 84 | } else { |
||
| 85 | $value['width'] = $setting['default']['width']; |
||
| 86 | $value['height'] = $setting['default']['height']; |
||
| 87 | $value['crop'] = $setting['default']['crop']; |
||
| 88 | } |
||
| 89 | break; |
||
| 90 | case 'select': |
||
| 91 | $options = array_keys( $setting['options'] ); |
||
| 92 | $default = ( empty( $setting['default'] ) ? $options[0] : $setting['default'] ); |
||
| 93 | $value = in_array( $raw_value, $options ) ? $raw_value : $default; |
||
| 94 | break; |
||
| 95 | default : |
||
| 96 | $value = wc_clean( $raw_value ); |
||
| 97 | break; |
||
| 98 | } |
||
| 99 | |||
| 100 | // A couple fields changed in the REST API -- we can just pass these too so old filters still work |
||
| 101 | $setting['desc'] = ( ! empty( $setting['description'] ) ? $setting['description'] : '' ); |
||
| 102 | $setting['title'] = ( ! empty( $setting['label'] ) ? $setting['label'] : '' ); |
||
| 103 | |||
| 104 | $value = apply_filters( 'woocommerce_admin_settings_sanitize_option', $value, $setting, $raw_value ); |
||
| 105 | $value = apply_filters( "woocommerce_admin_settings_sanitize_option_" . $setting['id'], $value, $setting, $raw_value ); |
||
| 106 | do_action( 'woocommerce_update_option', $setting ); |
||
| 107 | |||
| 108 | return $value; |
||
| 109 | } |
||
| 110 | |||
| 189 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.