| Conditions | 12 |
| Paths | 4 |
| Total Lines | 44 |
| Lines | 18 |
| Ratio | 40.91 % |
| 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 |
||
| 19 | function create_legacy_buttons_markup( $attributes, $content, $block ) { |
||
| 20 | $button_styles = array(); |
||
| 21 | View Code Duplication | if ( ! empty( $attributes['customBackgroundButtonColor'] ) ) { |
|
| 22 | array_push( |
||
| 23 | $button_styles, |
||
| 24 | sprintf( |
||
| 25 | 'background-color: %s', |
||
| 26 | isset( $attributes['customBackgroundButtonColor'] ) ? sanitize_hex_color( $attributes['customBackgroundButtonColor'] ) : 'transparent' |
||
| 27 | ) |
||
| 28 | ); |
||
| 29 | } |
||
| 30 | View Code Duplication | if ( ! empty( $attributes['customTextButtonColor'] ) ) { |
|
| 31 | array_push( |
||
| 32 | $button_styles, |
||
| 33 | sprintf( |
||
| 34 | 'color: %s', |
||
| 35 | isset( $attributes['customTextButtonColor'] ) ? sanitize_hex_color( $attributes['customTextButtonColor'] ) : 'inherit' |
||
| 36 | ) |
||
| 37 | ); |
||
| 38 | } |
||
| 39 | $button_styles = implode( ';', $button_styles ); |
||
| 40 | |||
| 41 | $login_button = sprintf( |
||
| 42 | '<div class="wp-block-button"><a role="button" href="%1$s" class="%2$s" style="%3$s">%4$s</a></div>', |
||
| 43 | subscription_service()->access_url(), |
||
| 44 | empty( $attributes['buttonClasses'] ) ? 'wp-block-button__link' : esc_attr( $attributes['buttonClasses'] ), |
||
| 45 | esc_attr( $button_styles ), |
||
| 46 | empty( $attributes['loginButtonText'] ) ? __( 'Log In', 'jetpack' ) : $attributes['loginButtonText'] |
||
| 47 | ); |
||
| 48 | |||
| 49 | $subscribe_button = \Jetpack_Memberships::get_instance()->render_button( |
||
| 50 | array( |
||
| 51 | 'planId' => empty( $block->context['premium-content/planId'] ) ? 0 : $block->context['premium-content/planId'], |
||
| 52 | 'submitButtonClasses' => empty( $attributes['buttonClasses'] ) ? 'wp-block-button__link' : esc_attr( $attributes['buttonClasses'] ), |
||
| 53 | 'customTextButtonColor' => empty( $attributes['customTextButtonColor'] ) ? '' : esc_attr( $attributes['customTextButtonColor'] ), |
||
| 54 | 'customBackgroundButtonColor' => empty( $attributes['customBackgroundButtonColor'] ) ? '' : esc_attr( $attributes['customBackgroundButtonColor'] ), |
||
| 55 | 'submitButtonText' => empty( $attributes['subscribeButtonText'] ) ? __( 'Subscribe', 'jetpack' ) : esc_attr( $attributes['subscribeButtonText'] ), |
||
| 56 | ), |
||
| 57 | $content, |
||
| 58 | $block |
||
| 59 | ); |
||
| 60 | |||
| 61 | return "<div class='wp-block-premium-content-logged-out-view__buttons'>{$subscribe_button}{$login_button}</div>"; |
||
| 62 | } |
||
| 63 |