| Conditions | 14 |
| Paths | 128 |
| Total Lines | 44 |
| 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 |
||
| 16 | function jetpack_get_button_classes( $attributes ) { |
||
| 17 | $classes = array( 'wp-block-button__link' ); |
||
| 18 | $has_class_name = array_key_exists( 'className', $attributes ); |
||
| 19 | $has_named_text_color = array_key_exists( 'buttonTextColor', $attributes ); |
||
| 20 | $has_custom_text_color = array_key_exists( 'customButtonTextColor', $attributes ); |
||
| 21 | $has_named_background_color = array_key_exists( 'buttonBackgroundColor', $attributes ); |
||
| 22 | $has_custom_background_color = array_key_exists( 'customButtonBackgroundColor', $attributes ); |
||
| 23 | $has_named_gradient = array_key_exists( 'buttonGradient', $attributes ); |
||
| 24 | $has_custom_gradient = array_key_exists( 'customButtonGradient', $attributes ); |
||
| 25 | $has_border_radius = array_key_exists( 'buttonBorderRadius', $attributes ); |
||
| 26 | |||
| 27 | if ( $has_class_name ) { |
||
| 28 | $classes[] = $attributes['className']; |
||
| 29 | } |
||
| 30 | |||
| 31 | if ( $has_named_text_color || $has_custom_text_color ) { |
||
| 32 | $classes[] = 'has-text-color'; |
||
| 33 | } |
||
| 34 | if ( $has_named_text_color ) { |
||
| 35 | $classes[] = sprintf( 'has-%s-color', $attributes['buttonTextColor'] ); |
||
| 36 | } |
||
| 37 | |||
| 38 | if ( |
||
| 39 | $has_named_background_color || |
||
| 40 | $has_custom_background_color || |
||
| 41 | $has_named_gradient || |
||
| 42 | $has_custom_gradient |
||
| 43 | ) { |
||
| 44 | $classes[] = 'has-background'; |
||
| 45 | } |
||
| 46 | if ( $has_named_background_color && ! $has_custom_gradient ) { |
||
| 47 | $classes[] = sprintf( 'has-%s-background-color', $attributes['buttonBackgroundColor'] ); |
||
| 48 | } |
||
| 49 | if ( $has_named_gradient ) { |
||
| 50 | $classes[] = sprintf( 'has-%s-gradient-background', $attributes['buttonGradient'] ); |
||
| 51 | } |
||
| 52 | |||
| 53 | // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison |
||
| 54 | if ( $has_border_radius && 0 == $attributes['buttonBorderRadius'] ) { |
||
| 55 | $classes[] = 'no-border-radius'; |
||
| 56 | } |
||
| 57 | |||
| 58 | return implode( ' ', $classes ); |
||
| 59 | } |
||
| 60 | } |
||
| 105 |