| Conditions | 12 |
| Paths | 16 |
| Total Lines | 34 |
| Lines | 8 |
| Ratio | 23.53 % |
| 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 |
||
| 70 | function jetpack_get_button_styles( $attributes ) { |
||
| 71 | $styles = array(); |
||
| 72 | $has_named_text_color = array_key_exists( 'buttonTextColor', $attributes ); |
||
| 73 | $has_custom_text_color = array_key_exists( 'customButtonTextColor', $attributes ); |
||
| 74 | $has_named_background_color = array_key_exists( 'buttonBackgroundColor', $attributes ); |
||
| 75 | $has_custom_background_color = array_key_exists( 'customButtonBackgroundColor', $attributes ); |
||
| 76 | $has_named_gradient = array_key_exists( 'buttonGradient', $attributes ); |
||
| 77 | $has_custom_gradient = array_key_exists( 'customButtonGradient', $attributes ); |
||
| 78 | $has_border_radius = array_key_exists( 'buttonBorderRadius', $attributes ); |
||
| 79 | |||
| 80 | if ( ! $has_named_text_color && $has_custom_text_color ) { |
||
| 81 | $styles[] = sprintf( 'color: %s;', $attributes['customButtonTextColor'] ); |
||
| 82 | } |
||
| 83 | |||
| 84 | if ( ! $has_named_background_color && ! $has_named_gradient && $has_custom_gradient ) { |
||
| 85 | $styles[] = sprintf( 'background: %s;', $attributes['customButtonGradient'] ); |
||
| 86 | } |
||
| 87 | |||
| 88 | View Code Duplication | if ( |
|
| 89 | $has_custom_background_color && |
||
| 90 | ! $has_named_background_color && |
||
| 91 | ! $has_named_gradient && |
||
| 92 | ! $has_custom_gradient |
||
| 93 | ) { |
||
| 94 | $styles[] = sprintf( 'background-color: %s;', $attributes['customButtonBackgroundColor'] ); |
||
| 95 | } |
||
| 96 | |||
| 97 | // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison |
||
| 98 | if ( $has_border_radius && 0 != $attributes['buttonBorderRadius'] ) { |
||
| 99 | $styles[] = sprintf( 'border-radius: %spx;', $attributes['buttonBorderRadius'] ); |
||
| 100 | } |
||
| 101 | |||
| 102 | return implode( ' ', $styles ); |
||
| 103 | } |
||
| 104 | } |
||
| 105 |