| 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 |
||
| 136 | * |
||
| 137 | * @param string $attribute String containing the attribute name to get. |
||
| 138 | * @param array $attributes Array containing the Revue block attributes. |
||
| 139 | * |
||
| 140 | * @return mixed |
||
| 141 | */ |
||
| 142 | function get_revue_attribute( $attribute, $attributes ) { |
||
| 143 | if ( array_key_exists( $attribute, $attributes ) ) { |
||
| 144 | return $attributes[ $attribute ]; |
||
| 145 | } |
||
| 146 | |||
| 147 | $default_attributes = array( |
||
| 148 | 'text' => __( 'Subscribe', 'jetpack' ), |
||
| 149 | 'emailLabel' => __( 'Email address', 'jetpack' ), |
||
| 150 | 'emailPlaceholder' => __( 'Enter your email address', 'jetpack' ), |
||
| 151 | 'firstNameLabel' => __( 'First name', 'jetpack' ), |
||
| 152 | 'firstNamePlaceholder' => __( 'Enter your first name', 'jetpack' ), |
||
| 153 | 'firstNameShow' => true, |
||
| 154 | 'lastNameLabel' => __( 'Last name', 'jetpack' ), |
||
| 155 | 'lastNamePlaceholder' => __( 'Enter your last name', 'jetpack' ), |
||
| 156 | 'lastNameShow' => true, |
||
| 157 | ); |
||
| 158 | |||
| 159 | if ( array_key_exists( $attribute, $default_attributes ) ) { |
||
| 160 | return $default_attributes[ $attribute ]; |
||
| 161 | } |
||
| 162 | } |
||
| 163 | |||
| 164 | /** |
||
| 165 | * DEPRECATED V1 |
||
| 166 | */ |
||
| 167 | |||
| 168 | /** |
||
| 169 | * Create the Revue subscribe button. |
||
| 170 | * |
||
| 171 | * @param array $attributes Array containing the Revue block attributes. |
||
| 172 | * |
||
| 173 | * @return string |
||
| 174 | */ |
||
| 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'] ); |
||
| 253 |