Complex classes like FrmStylesHelper often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use FrmStylesHelper, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 2 | class FrmStylesHelper { |
||
| 3 | |||
| 4 | public static function get_upload_base() { |
||
| 12 | |||
| 13 | public static function style_menu( $active = '' ) { |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @since 2.05 |
||
| 25 | */ |
||
| 26 | public static function get_css_label_positions() { |
||
| 35 | |||
| 36 | public static function get_single_label_positions() { |
||
| 47 | |||
| 48 | public static function minus_icons() { |
||
| 72 | |||
| 73 | public static function arrow_icons() { |
||
| 112 | |||
| 113 | /** |
||
| 114 | * @since 2.0 |
||
| 115 | * @return The class for this icon |
||
| 116 | */ |
||
| 117 | public static function icon_key_to_class( $key, $icon = '+', $type = 'arrow' ) { |
||
| 142 | |||
| 143 | public static function bs_icon_select( $style, $frm_style, $type = 'arrow' ) { |
||
| 182 | |||
| 183 | public static function hex2rgb( $hex ) { |
||
| 191 | |||
| 192 | /** |
||
| 193 | * @param $hex string - The original color in hex format #ffffff |
||
| 194 | * @param $steps integer - should be between -255 and 255. Negative = darker, positive = lighter |
||
| 195 | * @since 2.3 |
||
| 196 | */ |
||
| 197 | public static function adjust_brightness( $hex, $steps ) { |
||
| 220 | |||
| 221 | /** |
||
| 222 | * @since 2.3 |
||
| 223 | */ |
||
| 224 | public static function get_settings_for_output( $style ) { |
||
| 225 | if ( self::previewing_style() ) { |
||
| 226 | if ( isset( $_POST['frm_style_setting'] ) && isset( $_POST['frm_style_setting']['post_content'] ) ) { |
||
| 227 | $settings = $_POST['frm_style_setting']['post_content']; |
||
| 228 | } else { |
||
| 229 | $settings = $_GET; |
||
| 230 | } |
||
| 231 | FrmAppHelper::sanitize_value( 'sanitize_text_field', $settings ); |
||
| 232 | |||
| 233 | $style_name = FrmAppHelper::get_param( 'style_name', '', 'get', 'sanitize_title' ); |
||
| 234 | $settings['style_class'] = ''; |
||
| 235 | if ( ! empty( $style_name ) ) { |
||
| 236 | $settings['style_class'] = $style_name . '.'; |
||
| 237 | } |
||
| 238 | } else { |
||
| 239 | $settings = $style->post_content; |
||
| 240 | $settings['style_class'] = 'frm_style_' . $style->post_name . '.'; |
||
| 241 | } |
||
| 242 | |||
| 243 | $settings['style_class'] .= 'with_frm_style'; |
||
| 244 | $settings['font'] = stripslashes( $settings['font'] ); |
||
| 245 | $settings['change_margin'] = self::description_margin_for_screensize( $settings['width'] ); |
||
| 246 | |||
| 247 | $checkbox_opts = array( 'important_style', 'auto_width', 'submit_style', 'collapse_icon', 'center_form' ); |
||
| 248 | foreach ( $checkbox_opts as $opt ) { |
||
| 249 | if ( ! isset( $settings[ $opt ] ) ) { |
||
| 250 | $settings[ $opt ] = 0; |
||
| 251 | } |
||
| 252 | } |
||
| 253 | |||
| 254 | self::prepare_color_output( $settings ); |
||
| 255 | |||
| 256 | return $settings; |
||
| 257 | } |
||
| 258 | |||
| 259 | /** |
||
| 260 | * @since 2.3 |
||
| 261 | */ |
||
| 262 | public static function prepare_color_output( &$settings, $allow_transparent = true ) { |
||
| 273 | |||
| 274 | /** |
||
| 275 | * @since 2.3 |
||
| 276 | */ |
||
| 277 | private static function allow_color_override() { |
||
| 288 | |||
| 289 | /** |
||
| 290 | * @since 2.3 |
||
| 291 | */ |
||
| 292 | private static function get_color_output( $default, &$color ) { |
||
| 300 | |||
| 301 | /** |
||
| 302 | * If left/right label is over a certain size, |
||
| 303 | * adjust the field description margin at a different screen size |
||
| 304 | * |
||
| 305 | * @since 2.3 |
||
| 306 | */ |
||
| 307 | private static function description_margin_for_screensize( $width ) { |
||
| 319 | |||
| 320 | /** |
||
| 321 | * @since 2.3 |
||
| 322 | */ |
||
| 323 | public static function previewing_style() { |
||
| 327 | |||
| 328 | /** |
||
| 329 | * @deprecated 3.01 |
||
| 330 | * @codeCoverageIgnore |
||
| 331 | */ |
||
| 332 | public static function get_sigle_label_postitions() { |
||
| 335 | |||
| 336 | /** |
||
| 337 | * @deprecated 3.02.03 |
||
| 338 | * @codeCoverageIgnore |
||
| 339 | */ |
||
| 340 | public static function jquery_themes() { |
||
| 343 | |||
| 344 | /** |
||
| 345 | * @deprecated 3.02.03 |
||
| 346 | * @codeCoverageIgnore |
||
| 347 | */ |
||
| 348 | public static function jquery_css_url( $theme_css ) { |
||
| 351 | |||
| 352 | /** |
||
| 353 | * @deprecated 3.02.03 |
||
| 354 | * @codeCoverageIgnore |
||
| 355 | */ |
||
| 356 | public static function enqueue_jquery_css() { |
||
| 359 | |||
| 360 | /** |
||
| 361 | * @deprecated 3.02.03 |
||
| 362 | * @codeCoverageIgnore |
||
| 363 | */ |
||
| 364 | public static function get_form_for_page() { |
||
| 367 | } |
||
| 368 |