Conditions | 20 |
Paths | 864 |
Total Lines | 78 |
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 |
||
123 | function jetpack_get_revue_button( $attributes ) { |
||
124 | $classes = array( 'wp-block-button__link' ); |
||
125 | $styles = array(); |
||
126 | |||
127 | $text = jetpack_get_revue_attribute( 'text', $attributes ); |
||
128 | $has_class_name = array_key_exists( 'className', $attributes ); |
||
129 | $has_named_text_color = array_key_exists( 'textColor', $attributes ); |
||
130 | $has_custom_text_color = array_key_exists( 'customTextColor', $attributes ); |
||
131 | $has_named_background_color = array_key_exists( 'backgroundColor', $attributes ); |
||
132 | $has_custom_background_color = array_key_exists( 'customBackgroundColor', $attributes ); |
||
133 | $has_named_gradient = array_key_exists( 'gradient', $attributes ); |
||
134 | $has_custom_gradient = array_key_exists( 'customGradient', $attributes ); |
||
135 | $has_border_radius = array_key_exists( 'borderRadius', $attributes ); |
||
136 | |||
137 | if ( $has_class_name ) { |
||
138 | $classes[] = $attributes['className']; |
||
139 | } |
||
140 | |||
141 | if ( $has_named_text_color || $has_custom_text_color ) { |
||
142 | $classes[] = 'has-text-color'; |
||
143 | } |
||
144 | if ( $has_named_text_color ) { |
||
145 | $classes[] = sprintf( 'has-%s-color', $attributes['textColor'] ); |
||
146 | } elseif ( $has_custom_text_color ) { |
||
147 | $styles[] = sprintf( 'color: %s;', $attributes['customTextColor'] ); |
||
148 | } |
||
149 | |||
150 | if ( |
||
151 | $has_named_background_color || |
||
152 | $has_custom_background_color || |
||
153 | $has_named_gradient || |
||
154 | $has_custom_gradient |
||
155 | ) { |
||
156 | $classes[] = 'has-background'; |
||
157 | } |
||
158 | if ( $has_named_background_color && ! $has_custom_gradient ) { |
||
159 | $classes[] = sprintf( 'has-%s-background-color', $attributes['backgroundColor'] ); |
||
160 | } |
||
161 | if ( $has_named_gradient ) { |
||
162 | $classes[] = sprintf( 'has-%s-gradient-background', $attributes['gradient'] ); |
||
163 | } elseif ( $has_custom_gradient ) { |
||
164 | $styles[] = sprintf( 'background: %s;', $attributes['customGradient'] ); |
||
165 | } |
||
166 | if ( |
||
167 | $has_custom_background_color && |
||
168 | ! $has_named_background_color && |
||
169 | ! $has_named_gradient && |
||
170 | ! $has_custom_gradient |
||
171 | ) { |
||
172 | $styles[] = sprintf( 'background-color: %s;', $attributes['customBackgroundColor'] ); |
||
173 | } |
||
174 | |||
175 | if ( $has_border_radius ) { |
||
176 | // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison |
||
177 | if ( 0 == $attributes['borderRadius'] ) { |
||
178 | $classes[] = 'no-border-radius'; |
||
179 | } else { |
||
180 | $styles[] = sprintf( 'border-radius: %spx;', $attributes['borderRadius'] ); |
||
181 | } |
||
182 | } |
||
183 | |||
184 | ob_start(); |
||
185 | ?> |
||
186 | |||
187 | <div class="wp-block-button"> |
||
188 | <button |
||
189 | class="<?php echo esc_attr( implode( ' ', $classes ) ); ?>" |
||
190 | name="member[subscribe]" |
||
191 | style="<?php echo esc_attr( implode( ' ', $styles ) ); ?>" |
||
192 | type="submit" |
||
193 | > |
||
194 | <?php echo wp_kses_post( $text ); ?> |
||
195 | </button> |
||
196 | </div> |
||
197 | |||
198 | <?php |
||
199 | return ob_get_clean(); |
||
200 | } |
||
201 | |||
231 |