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 ) { |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @since 3.0 |
||
| 60 | * |
||
| 61 | * @param array $atts |
||
| 62 | */ |
||
| 63 | private function set_field_id( $atts ) { |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @since 3.0 |
||
| 69 | * |
||
| 70 | * @param array $atts |
||
| 71 | */ |
||
| 72 | private function set_pass_args( $atts ) { |
||
| 82 | |||
| 83 | /** |
||
| 84 | * @since 3.0 |
||
| 85 | * |
||
| 86 | * @param array $atts |
||
| 87 | * @param array $set |
||
| 88 | */ |
||
| 89 | private function set_from_field( $atts, $set ) { |
||
| 96 | |||
| 97 | public function get_html() { |
||
| 104 | |||
| 105 | /** |
||
| 106 | * @since 3.0 |
||
| 107 | */ |
||
| 108 | private function replace_shortcodes_before_input() { |
||
| 129 | |||
| 130 | /** |
||
| 131 | * @since 3.0 |
||
| 132 | */ |
||
| 133 | private function replace_field_values() { |
||
| 146 | |||
| 147 | /** |
||
| 148 | * If field type is section heading, add class so a bottom margin |
||
| 149 | * can be added to either the h3 or description |
||
| 150 | * |
||
| 151 | * @since 3.0 |
||
| 152 | */ |
||
| 153 | private function add_class_to_divider() { |
||
| 162 | |||
| 163 | /** |
||
| 164 | * @since 3.0 |
||
| 165 | */ |
||
| 166 | private function replace_required_label_shortcode() { |
||
| 170 | |||
| 171 | /** |
||
| 172 | * @since 3.0 |
||
| 173 | */ |
||
| 174 | private function replace_description_shortcode() { |
||
| 178 | |||
| 179 | /** |
||
| 180 | * @since 3.0 |
||
| 181 | */ |
||
| 182 | private function replace_error_shortcode() { |
||
| 186 | |||
| 187 | /** |
||
| 188 | * replace [required_class] |
||
| 189 | * |
||
| 190 | * @since 3.0 |
||
| 191 | */ |
||
| 192 | private function replace_required_class() { |
||
| 196 | |||
| 197 | /** |
||
| 198 | * @since 3.0 |
||
| 199 | */ |
||
| 200 | private function replace_form_shortcodes() { |
||
| 211 | |||
| 212 | /** |
||
| 213 | * @since 3.0 |
||
| 214 | */ |
||
| 215 | public function replace_shortcodes_after_input() { |
||
| 227 | |||
| 228 | /** |
||
| 229 | * @since 3.0 |
||
| 230 | */ |
||
| 231 | private function filter_for_more_shortcodes() { |
||
| 240 | |||
| 241 | /** |
||
| 242 | * @since 3.0 |
||
| 243 | */ |
||
| 244 | private function filter_html_field_shortcodes() { |
||
| 252 | |||
| 253 | /** |
||
| 254 | * Remove [collapse_this] if it's still included after all processing |
||
| 255 | * @since 3.0 |
||
| 256 | */ |
||
| 257 | private function remove_collapse_shortcode() { |
||
| 262 | |||
| 263 | /** |
||
| 264 | * @since 3.0 |
||
| 265 | */ |
||
| 266 | private function replace_shortcodes_with_atts() { |
||
| 284 | |||
| 285 | /** |
||
| 286 | * @param array $shortcode_atts |
||
| 287 | * |
||
| 288 | * @return string |
||
| 289 | */ |
||
| 290 | private function replace_input_shortcode( $shortcode_atts ) { |
||
| 294 | |||
| 295 | /** |
||
| 296 | * @param array $shortcode_atts |
||
| 297 | * |
||
| 298 | * @return array |
||
| 299 | */ |
||
| 300 | private function prepare_input_shortcode_atts( $shortcode_atts ) { |
||
| 316 | |||
| 317 | /** |
||
| 318 | * Add the label position class into the HTML |
||
| 319 | * If the label position is inside, add a class to show the label if the field has a value. |
||
| 320 | * |
||
| 321 | * @since 3.0 |
||
| 322 | */ |
||
| 323 | private function add_class_to_label() { |
||
| 330 | |||
| 331 | /** |
||
| 332 | * replace [entry_key] |
||
| 333 | * |
||
| 334 | * @since 3.0 |
||
| 335 | */ |
||
| 336 | private function replace_entry_key() { |
||
| 340 | |||
| 341 | /** |
||
| 342 | * Add classes to a field div |
||
| 343 | * |
||
| 344 | * @since 3.0 |
||
| 345 | */ |
||
| 346 | private function add_field_div_classes() { |
||
| 355 | |||
| 356 | |||
| 357 | /** |
||
| 358 | * Get the classes for a field div |
||
| 359 | * |
||
| 360 | * @since 3.0 |
||
| 361 | * |
||
| 362 | * @return string $classes |
||
| 363 | */ |
||
| 364 | private function get_field_div_classes() { |
||
| 387 | |||
| 388 | /** |
||
| 389 | * This filters shortcodes in the field HTML |
||
| 390 | * |
||
| 391 | * @since 3.0 |
||
| 392 | */ |
||
| 393 | private function process_wp_shortcodes() { |
||
| 398 | } |
||
| 399 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.