Conditions | 20 |
Paths | 864 |
Total Lines | 78 |
Lines | 16 |
Ratio | 20.51 % |
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 |
||
175 | function get_deprecated_v1_revue_button( $attributes ) { |
||
176 | $classes = array( 'wp-block-button__link' ); |
||
177 | $styles = array(); |
||
178 | |||
179 | $text = get_revue_attribute( 'text', $attributes ); |
||
180 | $has_class_name = array_key_exists( 'className', $attributes ); |
||
181 | $has_named_text_color = array_key_exists( 'textColor', $attributes ); |
||
182 | $has_custom_text_color = array_key_exists( 'customTextColor', $attributes ); |
||
183 | $has_named_background_color = array_key_exists( 'backgroundColor', $attributes ); |
||
184 | $has_custom_background_color = array_key_exists( 'customBackgroundColor', $attributes ); |
||
185 | $has_named_gradient = array_key_exists( 'gradient', $attributes ); |
||
186 | $has_custom_gradient = array_key_exists( 'customGradient', $attributes ); |
||
187 | $has_border_radius = array_key_exists( 'borderRadius', $attributes ); |
||
188 | |||
189 | if ( $has_class_name ) { |
||
190 | $classes[] = $attributes['className']; |
||
191 | } |
||
192 | |||
193 | if ( $has_named_text_color || $has_custom_text_color ) { |
||
194 | $classes[] = 'has-text-color'; |
||
195 | } |
||
196 | if ( $has_named_text_color ) { |
||
197 | $classes[] = sprintf( 'has-%s-color', $attributes['textColor'] ); |
||
198 | } elseif ( $has_custom_text_color ) { |
||
199 | $styles[] = sprintf( 'color: %s;', $attributes['customTextColor'] ); |
||
200 | } |
||
201 | |||
202 | if ( |
||
203 | $has_named_background_color || |
||
204 | $has_custom_background_color || |
||
205 | $has_named_gradient || |
||
206 | $has_custom_gradient |
||
207 | ) { |
||
208 | $classes[] = 'has-background'; |
||
209 | } |
||
210 | if ( $has_named_background_color && ! $has_custom_gradient ) { |
||
211 | $classes[] = sprintf( 'has-%s-background-color', $attributes['backgroundColor'] ); |
||
212 | } |
||
213 | if ( $has_named_gradient ) { |
||
214 | $classes[] = sprintf( 'has-%s-gradient-background', $attributes['gradient'] ); |
||
215 | } elseif ( $has_custom_gradient ) { |
||
216 | $styles[] = sprintf( 'background: %s;', $attributes['customGradient'] ); |
||
217 | } |
||
218 | View Code Duplication | if ( |
|
219 | $has_custom_background_color && |
||
220 | ! $has_named_background_color && |
||
221 | ! $has_named_gradient && |
||
222 | ! $has_custom_gradient |
||
223 | ) { |
||
224 | $styles[] = sprintf( 'background-color: %s;', $attributes['customBackgroundColor'] ); |
||
225 | } |
||
226 | |||
227 | View Code Duplication | if ( $has_border_radius ) { |
|
228 | // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison |
||
229 | if ( 0 == $attributes['borderRadius'] ) { |
||
230 | $classes[] = 'no-border-radius'; |
||
231 | } else { |
||
232 | $styles[] = sprintf( 'border-radius: %spx;', $attributes['borderRadius'] ); |
||
233 | } |
||
234 | } |
||
235 | |||
236 | ob_start(); |
||
237 | ?> |
||
238 | |||
239 | <div class="wp-block-button"> |
||
240 | <button |
||
241 | class="<?php echo esc_attr( implode( ' ', $classes ) ); ?>" |
||
242 | name="member[subscribe]" |
||
243 | style="<?php echo esc_attr( implode( ' ', $styles ) ); ?>" |
||
244 | type="submit" |
||
245 | > |
||
246 | <?php echo wp_kses_post( $text ); ?> |
||
247 | </button> |
||
248 | </div> |
||
249 | |||
250 | <?php |
||
251 | return ob_get_clean(); |
||
252 | } |
||
253 |