Complex classes like FrmFieldFormHtml 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 FrmFieldFormHtml, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 6 | class FrmFieldFormHtml { |
||
| 7 | |||
| 8 | private $html; |
||
| 9 | |||
| 10 | private $html_id; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * @var FrmFieldType |
||
| 14 | */ |
||
| 15 | private $field_obj; |
||
| 16 | |||
| 17 | private $field_id; |
||
| 18 | |||
| 19 | private $form = array(); |
||
| 20 | |||
| 21 | private $pass_args = array(); |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @since 3.0 |
||
| 25 | * |
||
| 26 | * @param array $atts |
||
| 27 | */ |
||
| 28 | public function __construct( $atts ) { |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @since 3.0 |
||
| 39 | * |
||
| 40 | * @param string $param |
||
| 41 | * @param array $atts |
||
| 42 | */ |
||
| 43 | private function _set( $param, $atts ) { |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @since 3.0 |
||
| 51 | * |
||
| 52 | * @param array $atts |
||
| 53 | */ |
||
| 54 | private function set_html( $atts ) { |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @since 3.0 |
||
| 66 | * |
||
| 67 | * @param array $atts |
||
| 68 | */ |
||
| 69 | private function set_field_id( $atts ) { |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @since 3.0 |
||
| 81 | * |
||
| 82 | * @param array $atts |
||
| 83 | */ |
||
| 84 | private function set_pass_args( $atts ) { |
||
| 94 | |||
| 95 | /** |
||
| 96 | * @since 3.0 |
||
| 97 | * |
||
| 98 | * @param array $atts |
||
| 99 | * @param array $set |
||
| 100 | */ |
||
| 101 | private function set_from_field( $atts, $set ) { |
||
| 108 | |||
| 109 | public function get_html() { |
||
| 116 | |||
| 117 | /** |
||
| 118 | * @since 3.0 |
||
| 119 | */ |
||
| 120 | private function replace_shortcodes_before_input() { |
||
| 137 | |||
| 138 | /** |
||
| 139 | * @since 3.0 |
||
| 140 | */ |
||
| 141 | private function replace_field_values() { |
||
| 154 | |||
| 155 | /** |
||
| 156 | * @since 3.0 |
||
| 157 | */ |
||
| 158 | private function replace_required_label_shortcode() { |
||
| 162 | |||
| 163 | /** |
||
| 164 | * If this is an HTML field, the values are included in the description. |
||
| 165 | * In this case, we don't want to run the wp shortcodes with the description included. |
||
| 166 | * |
||
| 167 | * @since 3.0 |
||
| 168 | */ |
||
| 169 | private function maybe_replace_description_shortcode( $wp_processed = false ) { |
||
| 176 | |||
| 177 | /** |
||
| 178 | * @since 3.0 |
||
| 179 | */ |
||
| 180 | private function replace_description_shortcode() { |
||
| 185 | |||
| 186 | /** |
||
| 187 | * Add an ID to the description for aria-describedby. |
||
| 188 | * This ID was added to the HTML in v3.0. |
||
| 189 | * |
||
| 190 | * @since 3.0 |
||
| 191 | */ |
||
| 192 | private function maybe_add_description_id() { |
||
| 198 | |||
| 199 | /** |
||
| 200 | * Insert an ID if it doesn't exist. |
||
| 201 | * |
||
| 202 | * @since 3.06.02 |
||
| 203 | */ |
||
| 204 | private function add_element_id( $param, $id ) { |
||
| 222 | |||
| 223 | /** |
||
| 224 | * @since 3.0 |
||
| 225 | */ |
||
| 226 | private function replace_error_shortcode() { |
||
| 231 | |||
| 232 | /** |
||
| 233 | * Add an ID to the error message for aria-describedby. |
||
| 234 | * This ID was added to the HTML in v3.06.02. |
||
| 235 | * |
||
| 236 | * @since 3.06.02 |
||
| 237 | */ |
||
| 238 | private function maybe_add_error_id() { |
||
| 245 | |||
| 246 | /** |
||
| 247 | * Replace [required_class] |
||
| 248 | * |
||
| 249 | * @since 3.0 |
||
| 250 | */ |
||
| 251 | private function replace_required_class() { |
||
| 255 | |||
| 256 | /** |
||
| 257 | * @since 3.0 |
||
| 258 | */ |
||
| 259 | private function replace_form_shortcodes() { |
||
| 270 | |||
| 271 | /** |
||
| 272 | * @since 3.0 |
||
| 273 | */ |
||
| 274 | public function replace_shortcodes_after_input() { |
||
| 282 | |||
| 283 | /** |
||
| 284 | * @since 3.0 |
||
| 285 | */ |
||
| 286 | private function filter_for_more_shortcodes() { |
||
| 298 | |||
| 299 | /** |
||
| 300 | * Remove [collapse_this] if it's still included after all processing |
||
| 301 | * |
||
| 302 | * @since 3.0 |
||
| 303 | * |
||
| 304 | * @param string $html |
||
| 305 | */ |
||
| 306 | public function remove_collapse_shortcode( &$html ) { |
||
| 311 | |||
| 312 | /** |
||
| 313 | * @since 3.0 |
||
| 314 | */ |
||
| 315 | private function replace_shortcodes_with_atts() { |
||
| 333 | |||
| 334 | /** |
||
| 335 | * @param array $shortcode_atts |
||
| 336 | * |
||
| 337 | * @return string |
||
| 338 | */ |
||
| 339 | private function replace_input_shortcode( $shortcode_atts ) { |
||
| 343 | |||
| 344 | /** |
||
| 345 | * @param array $shortcode_atts |
||
| 346 | * |
||
| 347 | * @return array |
||
| 348 | */ |
||
| 349 | private function prepare_input_shortcode_atts( $shortcode_atts ) { |
||
| 369 | |||
| 370 | /** |
||
| 371 | * Add the label position class into the HTML |
||
| 372 | * If the label position is inside, add a class to show the label if the field has a value. |
||
| 373 | * |
||
| 374 | * @since 3.0 |
||
| 375 | */ |
||
| 376 | private function add_class_to_label() { |
||
| 383 | |||
| 384 | /** |
||
| 385 | * Replace [entry_key] |
||
| 386 | * |
||
| 387 | * @since 3.0 |
||
| 388 | */ |
||
| 389 | private function replace_entry_key() { |
||
| 393 | |||
| 394 | /** |
||
| 395 | * Add classes to a field div |
||
| 396 | * |
||
| 397 | * @since 3.0 |
||
| 398 | */ |
||
| 399 | private function add_field_div_classes() { |
||
| 408 | |||
| 409 | |||
| 410 | /** |
||
| 411 | * Get the classes for a field div |
||
| 412 | * |
||
| 413 | * @since 3.0 |
||
| 414 | * |
||
| 415 | * @return string $classes |
||
| 416 | */ |
||
| 417 | private function get_field_div_classes() { |
||
| 441 | |||
| 442 | /** |
||
| 443 | * This filters shortcodes in the field HTML |
||
| 444 | * |
||
| 445 | * @since 3.0 |
||
| 446 | */ |
||
| 447 | private function process_wp_shortcodes() { |
||
| 452 | } |
||
| 453 |