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