| Conditions | 4 |
| Paths | 5 |
| Total Lines | 87 |
| 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 | |||
| 39 | Jetpack_Gutenberg::load_assets_as_required( 'revue' ); |
||
| 40 | |||
| 41 | ob_start(); |
||
| 42 | ?> |
||
| 43 | |||
| 44 | <div class="wp-block-jetpack-revue"> |
||
| 45 | <form |
||
| 46 | action="<?php echo esc_url( $url ); ?>" |
||
| 47 | class="wp-block-jetpack-revue__form is-visible" |
||
| 48 | method="post" |
||
| 49 | name="revue-form" |
||
| 50 | target="_blank" |
||
| 51 | > |
||
| 52 | <div> |
||
| 53 | <label> |
||
| 54 | <?php echo esc_html( $email_label ); ?> |
||
| 55 | <span class="required"><?php esc_html_e( '(required)', 'jetpack' ); ?></span> |
||
| 56 | <input |
||
| 57 | class="wp-block-jetpack-revue__email" |
||
| 58 | name="member[email]" |
||
| 59 | placeholder="<?php echo esc_attr( $email_placeholder ); ?>" |
||
| 60 | required |
||
| 61 | type="email" |
||
| 62 | /> |
||
| 63 | </label> |
||
| 64 | </div> |
||
| 65 | <?php if ( $first_name_show ) : ?> |
||
| 66 | <div> |
||
| 67 | <label> |
||
| 68 | <?php echo esc_html( $first_name_label ); ?> |
||
| 69 | <input |
||
| 70 | class="wp-block-jetpack-revue__first-name" |
||
| 71 | name="member[first_name]" |
||
| 72 | placeholder="<?php echo esc_attr( $first_name_placeholder ); ?>" |
||
| 73 | type="text" |
||
| 74 | /> |
||
| 75 | </label> |
||
| 76 | </div> |
||
| 77 | <?php |
||
| 78 | endif; |
||
| 79 | if ( $last_name_show ) : |
||
| 80 | ?> |
||
| 81 | <div> |
||
| 82 | <label> |
||
| 83 | <?php echo esc_html( $last_name_label ); ?> |
||
| 84 | <input |
||
| 85 | class="wp-block-jetpack-revue__last-name" |
||
| 86 | name="member[last_name]" |
||
| 87 | placeholder="<?php echo esc_attr( $last_name_placeholder ); ?>" |
||
| 88 | type="text" |
||
| 89 | /> |
||
| 90 | </label> |
||
| 91 | </div> |
||
| 92 | <?php |
||
| 93 | endif; |
||
| 94 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
||
| 95 | echo jetpack_get_revue_button( $attributes ); |
||
| 96 | ?> |
||
| 97 | </form> |
||
| 98 | <div class="wp-block-jetpack-revue__message"> |
||
| 99 | <p> |
||
| 100 | <strong><?php esc_html_e( 'Subscription received!', 'jetpack' ); ?></strong> |
||
| 101 | </p> |
||
| 102 | <p> |
||
| 103 | <?php esc_html_e( 'Please check your email to confirm your newsletter subscription.', 'jetpack' ); ?> |
||
| 104 | </p> |
||
| 105 | </div> |
||
| 106 | </div> |
||
| 107 | |||
| 108 | <?php |
||
| 109 | return ob_get_clean(); |
||
| 110 | } |
||
| 111 | |||
| 229 |