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() { |
||
124 | |||
125 | /** |
||
126 | * @since 3.0 |
||
127 | */ |
||
128 | private function replace_field_values() { |
||
141 | |||
142 | /** |
||
143 | * @since 3.0 |
||
144 | */ |
||
145 | private function replace_required_label_shortcode() { |
||
149 | |||
150 | /** |
||
151 | * @since 3.0 |
||
152 | */ |
||
153 | private function replace_description_shortcode() { |
||
157 | |||
158 | /** |
||
159 | * @since 3.0 |
||
160 | */ |
||
161 | private function replace_error_shortcode() { |
||
165 | |||
166 | /** |
||
167 | * replace [required_class] |
||
168 | * |
||
169 | * @since 3.0 |
||
170 | */ |
||
171 | private function replace_required_class() { |
||
175 | |||
176 | /** |
||
177 | * @since 3.0 |
||
178 | */ |
||
179 | private function replace_form_shortcodes() { |
||
190 | |||
191 | /** |
||
192 | * @since 3.0 |
||
193 | */ |
||
194 | public function replace_shortcodes_after_input() { |
||
204 | |||
205 | /** |
||
206 | * @since 3.0 |
||
207 | */ |
||
208 | private function filter_for_more_shortcodes() { |
||
217 | |||
218 | /** |
||
219 | * Remove [collapse_this] if it's still included after all processing |
||
220 | * @since 3.0 |
||
221 | * |
||
222 | * @param string $html |
||
223 | */ |
||
224 | public function remove_collapse_shortcode( &$html ) { |
||
229 | |||
230 | /** |
||
231 | * @since 3.0 |
||
232 | */ |
||
233 | private function replace_shortcodes_with_atts() { |
||
251 | |||
252 | /** |
||
253 | * @param array $shortcode_atts |
||
254 | * |
||
255 | * @return string |
||
256 | */ |
||
257 | private function replace_input_shortcode( $shortcode_atts ) { |
||
261 | |||
262 | /** |
||
263 | * @param array $shortcode_atts |
||
264 | * |
||
265 | * @return array |
||
266 | */ |
||
267 | private function prepare_input_shortcode_atts( $shortcode_atts ) { |
||
283 | |||
284 | /** |
||
285 | * Add the label position class into the HTML |
||
286 | * If the label position is inside, add a class to show the label if the field has a value. |
||
287 | * |
||
288 | * @since 3.0 |
||
289 | */ |
||
290 | private function add_class_to_label() { |
||
297 | |||
298 | /** |
||
299 | * replace [entry_key] |
||
300 | * |
||
301 | * @since 3.0 |
||
302 | */ |
||
303 | private function replace_entry_key() { |
||
307 | |||
308 | /** |
||
309 | * Add classes to a field div |
||
310 | * |
||
311 | * @since 3.0 |
||
312 | */ |
||
313 | private function add_field_div_classes() { |
||
322 | |||
323 | |||
324 | /** |
||
325 | * Get the classes for a field div |
||
326 | * |
||
327 | * @since 3.0 |
||
328 | * |
||
329 | * @return string $classes |
||
330 | */ |
||
331 | private function get_field_div_classes() { |
||
352 | |||
353 | /** |
||
354 | * This filters shortcodes in the field HTML |
||
355 | * |
||
356 | * @since 3.0 |
||
357 | */ |
||
358 | private function process_wp_shortcodes() { |
||
363 | } |
||
364 |
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.