| Conditions | 20 |
| Paths | 864 |
| Total Lines | 78 |
| Lines | 16 |
| Ratio | 20.51 % |
| 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 |
||
| 176 | function get_deprecated_v1_revue_button( $attributes ) { |
||
| 177 | $classes = array( 'wp-block-button__link' ); |
||
| 178 | $styles = array(); |
||
| 179 | |||
| 180 | $text = get_revue_attribute( 'text', $attributes ); |
||
| 181 | $has_class_name = array_key_exists( 'className', $attributes ); |
||
| 182 | $has_named_text_color = array_key_exists( 'textColor', $attributes ); |
||
| 183 | $has_custom_text_color = array_key_exists( 'customTextColor', $attributes ); |
||
| 184 | $has_named_background_color = array_key_exists( 'backgroundColor', $attributes ); |
||
| 185 | $has_custom_background_color = array_key_exists( 'customBackgroundColor', $attributes ); |
||
| 186 | $has_named_gradient = array_key_exists( 'gradient', $attributes ); |
||
| 187 | $has_custom_gradient = array_key_exists( 'customGradient', $attributes ); |
||
| 188 | $has_border_radius = array_key_exists( 'borderRadius', $attributes ); |
||
| 189 | |||
| 190 | if ( $has_class_name ) { |
||
| 191 | $classes[] = $attributes['className']; |
||
| 192 | } |
||
| 193 | |||
| 194 | if ( $has_named_text_color || $has_custom_text_color ) { |
||
| 195 | $classes[] = 'has-text-color'; |
||
| 196 | } |
||
| 197 | if ( $has_named_text_color ) { |
||
| 198 | $classes[] = sprintf( 'has-%s-color', $attributes['textColor'] ); |
||
| 199 | } elseif ( $has_custom_text_color ) { |
||
| 200 | $styles[] = sprintf( 'color: %s;', $attributes['customTextColor'] ); |
||
| 201 | } |
||
| 202 | |||
| 203 | if ( |
||
| 204 | $has_named_background_color || |
||
| 205 | $has_custom_background_color || |
||
| 206 | $has_named_gradient || |
||
| 207 | $has_custom_gradient |
||
| 208 | ) { |
||
| 209 | $classes[] = 'has-background'; |
||
| 210 | } |
||
| 211 | if ( $has_named_background_color && ! $has_custom_gradient ) { |
||
| 212 | $classes[] = sprintf( 'has-%s-background-color', $attributes['backgroundColor'] ); |
||
| 213 | } |
||
| 214 | if ( $has_named_gradient ) { |
||
| 215 | $classes[] = sprintf( 'has-%s-gradient-background', $attributes['gradient'] ); |
||
| 216 | } elseif ( $has_custom_gradient ) { |
||
| 217 | $styles[] = sprintf( 'background: %s;', $attributes['customGradient'] ); |
||
| 218 | } |
||
| 219 | View Code Duplication | if ( |
|
| 220 | $has_custom_background_color && |
||
| 221 | ! $has_named_background_color && |
||
| 222 | ! $has_named_gradient && |
||
| 223 | ! $has_custom_gradient |
||
| 224 | ) { |
||
| 225 | $styles[] = sprintf( 'background-color: %s;', $attributes['customBackgroundColor'] ); |
||
| 226 | } |
||
| 227 | |||
| 228 | View Code Duplication | if ( $has_border_radius ) { |
|
| 229 | // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison |
||
| 230 | if ( 0 == $attributes['borderRadius'] ) { |
||
| 231 | $classes[] = 'no-border-radius'; |
||
| 232 | } else { |
||
| 233 | $styles[] = sprintf( 'border-radius: %spx;', $attributes['borderRadius'] ); |
||
| 234 | } |
||
| 235 | } |
||
| 236 | |||
| 237 | ob_start(); |
||
| 238 | ?> |
||
| 239 | |||
| 240 | <div class="wp-block-button"> |
||
| 241 | <button |
||
| 242 | class="<?php echo esc_attr( implode( ' ', $classes ) ); ?>" |
||
| 243 | name="member[subscribe]" |
||
| 244 | style="<?php echo esc_attr( implode( ' ', $styles ) ); ?>" |
||
| 245 | type="submit" |
||
| 246 | > |
||
| 247 | <?php echo wp_kses_post( $text ); ?> |
||
| 248 | </button> |
||
| 249 | </div> |
||
| 250 | |||
| 251 | <?php |
||
| 252 | return ob_get_clean(); |
||
| 253 | } |
||
| 254 |