| Conditions | 15 |
| Paths | 768 |
| Total Lines | 61 |
| Code Lines | 36 |
| Lines | 6 |
| Ratio | 9.84 % |
| 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 |
||
| 164 | public function update( $new_instance, $old_instance ) { |
||
| 165 | $instance = array(); |
||
| 166 | $defaults = $this->defaults(); |
||
| 167 | |||
| 168 | $instance['hide'] = $this->filter_value( $new_instance['hide'], $this->hide_options ); |
||
| 169 | $instance['text'] = $this->filter_value( $new_instance['text'], $this->text_options ); |
||
| 170 | $instance['color-scheme'] = $this->filter_value( $new_instance['color-scheme'], $this->color_scheme_options ); |
||
| 171 | $instance['policy-url'] = $this->filter_value( $new_instance['policy-url'], $this->policy_url_options ); |
||
| 172 | |||
| 173 | if ( isset( $new_instance['hide-timeout'] ) ) { |
||
| 174 | // Time can be a value between 3 and 1000 seconds. |
||
| 175 | $instance['hide-timeout'] = min( 1000, max( 3, intval( $new_instance['hide-timeout'] ) ) ); |
||
| 176 | } |
||
| 177 | |||
| 178 | if ( isset( $new_instance['customtext'] ) ) { |
||
| 179 | $instance['customtext'] = mb_substr( wp_kses( $new_instance['customtext'], array() ), 0, 4096 ); |
||
| 180 | } else { |
||
| 181 | $instance['text'] = $this->text_options[0]; |
||
| 182 | } |
||
| 183 | |||
| 184 | if ( isset( $new_instance['policy-url'] ) ) { |
||
| 185 | $instance['policy-url'] = 'custom' === $new_instance['policy-url'] |
||
| 186 | ? 'custom' |
||
| 187 | : 'default'; |
||
| 188 | } else { |
||
| 189 | $instance['policy-url'] = $this->policy_url_options[0]; |
||
| 190 | } |
||
| 191 | |||
| 192 | if ( 'custom' === $instance['policy-url'] && isset( $new_instance['custom-policy-url'] ) ) { |
||
| 193 | $instance['custom-policy-url'] = esc_url( $new_instance['custom-policy-url'], array( 'http', 'https' ) ); |
||
| 194 | |||
| 195 | if ( strlen( $instance['custom-policy-url'] ) < 10 ) { |
||
| 196 | unset( $instance['custom-policy-url'] ); |
||
| 197 | global $wp_customize; |
||
| 198 | if ( ! isset( $wp_customize ) ) { |
||
| 199 | $instance['policy-url'] = $this->policy_url_options[0]; |
||
| 200 | } |
||
| 201 | } |
||
| 202 | } |
||
| 203 | |||
| 204 | View Code Duplication | if ( isset( $new_instance['policy-link-text'] ) ) { |
|
| 205 | $instance['policy-link-text'] = trim( mb_substr( wp_kses( $new_instance['policy-link-text'], array() ), 0, 100 ) ); |
||
| 206 | } |
||
| 207 | |||
| 208 | if ( empty( $instance['policy-link-text'] ) || $instance['policy-link-text'] == $defaults['policy-link-text'] ) { |
||
| 209 | unset( $instance['policy-link-text'] ); |
||
| 210 | } |
||
| 211 | |||
| 212 | View Code Duplication | if ( isset( $new_instance['button'] ) ) { |
|
| 213 | $instance['button'] = trim( mb_substr( wp_kses( $new_instance['button'], array() ), 0, 100 ) ); |
||
| 214 | } |
||
| 215 | |||
| 216 | if ( empty( $instance['button'] ) || $instance['button'] == $defaults['button'] ) { |
||
| 217 | unset( $instance['button'] ); |
||
| 218 | } |
||
| 219 | |||
| 220 | // Show the banner again if a setting has been changed. |
||
| 221 | setcookie( self::$cookie_name, '', time() - 86400, '/' ); |
||
| 222 | |||
| 223 | return $instance; |
||
| 224 | } |
||
| 225 | |||
| 250 |