| Conditions | 4 |
| Paths | 5 |
| Total Lines | 89 |
| 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 |
||
| 24 | function jetpack_render_revue_block( $attributes ) { |
||
| 25 | if ( ! array_key_exists( 'revueUsername', $attributes ) ) { |
||
| 26 | return ''; |
||
| 27 | } |
||
| 28 | |||
| 29 | $email_label = jetpack_get_revue_attribute( 'emailLabel', $attributes ); |
||
| 30 | $email_placeholder = jetpack_get_revue_attribute( 'emailPlaceholder', $attributes ); |
||
| 31 | $first_name_label = jetpack_get_revue_attribute( 'firstNameLabel', $attributes ); |
||
| 32 | $first_name_placeholder = jetpack_get_revue_attribute( 'firstNamePlaceholder', $attributes ); |
||
| 33 | $first_name_show = jetpack_get_revue_attribute( 'firstNameShow', $attributes ); |
||
| 34 | $last_name_label = jetpack_get_revue_attribute( 'lastNameLabel', $attributes ); |
||
| 35 | $last_name_placeholder = jetpack_get_revue_attribute( 'lastNamePlaceholder', $attributes ); |
||
| 36 | $last_name_show = jetpack_get_revue_attribute( 'lastNameShow', $attributes ); |
||
| 37 | $url = sprintf( 'https://www.getrevue.co/profile/%s/add_subscriber', $attributes['revueUsername'] ); |
||
| 38 | $base_class = Jetpack_Gutenberg::block_classes( 'revue', array() ) . '__'; |
||
| 39 | $classes = Jetpack_Gutenberg::block_classes( 'revue', $attributes ); |
||
| 40 | |||
| 41 | Jetpack_Gutenberg::load_assets_as_required( 'revue' ); |
||
| 42 | |||
| 43 | ob_start(); |
||
| 44 | ?> |
||
| 45 | |||
| 46 | <div class="<?php echo esc_attr( $classes ); ?>"> |
||
| 47 | <form |
||
| 48 | action="<?php echo esc_url( $url ); ?>" |
||
| 49 | class="<?php echo esc_attr( $base_class . 'form is-visible' ); ?>" |
||
| 50 | method="post" |
||
| 51 | name="revue-form" |
||
| 52 | target="_blank" |
||
| 53 | > |
||
| 54 | <div> |
||
| 55 | <label> |
||
| 56 | <?php echo esc_html( $email_label ); ?> |
||
| 57 | <span class="required"><?php esc_html_e( '(required)', 'jetpack' ); ?></span> |
||
| 58 | <input |
||
| 59 | class="<?php echo esc_attr( $base_class . 'email' ); ?>" |
||
| 60 | name="member[email]" |
||
| 61 | placeholder="<?php echo esc_attr( $email_placeholder ); ?>" |
||
| 62 | required |
||
| 63 | type="email" |
||
| 64 | /> |
||
| 65 | </label> |
||
| 66 | </div> |
||
| 67 | <?php if ( $first_name_show ) : ?> |
||
| 68 | <div> |
||
| 69 | <label> |
||
| 70 | <?php echo esc_html( $first_name_label ); ?> |
||
| 71 | <input |
||
| 72 | class="<?php echo esc_attr( $base_class . 'first-name' ); ?>" |
||
| 73 | name="member[first_name]" |
||
| 74 | placeholder="<?php echo esc_attr( $first_name_placeholder ); ?>" |
||
| 75 | type="text" |
||
| 76 | /> |
||
| 77 | </label> |
||
| 78 | </div> |
||
| 79 | <?php |
||
| 80 | endif; |
||
| 81 | if ( $last_name_show ) : |
||
| 82 | ?> |
||
| 83 | <div> |
||
| 84 | <label> |
||
| 85 | <?php echo esc_html( $last_name_label ); ?> |
||
| 86 | <input |
||
| 87 | class="<?php echo esc_attr( $base_class . 'last-name' ); ?>" |
||
| 88 | name="member[last_name]" |
||
| 89 | placeholder="<?php echo esc_attr( $last_name_placeholder ); ?>" |
||
| 90 | type="text" |
||
| 91 | /> |
||
| 92 | </label> |
||
| 93 | </div> |
||
| 94 | <?php |
||
| 95 | endif; |
||
| 96 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
||
| 97 | echo jetpack_get_revue_button( $attributes ); |
||
| 98 | ?> |
||
| 99 | </form> |
||
| 100 | <div class="<?php echo esc_attr( $base_class . 'message' ); ?>"> |
||
| 101 | <p> |
||
| 102 | <strong><?php esc_html_e( 'Subscription received!', 'jetpack' ); ?></strong> |
||
| 103 | </p> |
||
| 104 | <p> |
||
| 105 | <?php esc_html_e( 'Please check your email to confirm your newsletter subscription.', 'jetpack' ); ?> |
||
| 106 | </p> |
||
| 107 | </div> |
||
| 108 | </div> |
||
| 109 | |||
| 110 | <?php |
||
| 111 | return ob_get_clean(); |
||
| 112 | } |
||
| 113 | |||
| 231 |