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