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