Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like FrmEntryFormat 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 FrmEntryFormat, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 3 | class FrmEntryFormat { |
||
| 4 | |||
| 5 | /*********************************************************************** |
||
| 6 | * Deprecated Functions |
||
| 7 | ************************************************************************/ |
||
| 8 | |||
| 9 | /** |
||
| 10 | * @deprecated 2.03.04 |
||
| 11 | */ |
||
| 12 | public static function textarea_display_value() { |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @deprecated 2.03.11 |
||
| 18 | */ |
||
| 19 | public static function single_html_row( $atts, &$content ) { |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @deprecated 2.03.11 |
||
| 25 | * |
||
| 26 | * @param stdClass $field |
||
| 27 | * @param array|string $val |
||
| 28 | */ |
||
| 29 | public static function flatten_multi_file_upload( $field, &$val ) { |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @deprecated 2.03.11 |
||
| 39 | */ |
||
| 40 | public static function fill_entry_user_info() { |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @deprecated 2.03.11 |
||
| 46 | */ |
||
| 47 | public static function get_entry_description_data() { |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @deprecated 2.03.11 |
||
| 55 | */ |
||
| 56 | public static function single_plain_text_row() { |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @deprecated 2.03.11 |
||
| 62 | */ |
||
| 63 | public static function html_field_row() { |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @deprecated 2.03.11 |
||
| 69 | */ |
||
| 70 | public static function fill_entry_values( $atts, $f, array &$values ) { |
||
| 112 | |||
| 113 | /** |
||
| 114 | * @deprecated 2.03.11 |
||
| 115 | */ |
||
| 116 | private static function fill_missing_fields( $atts, &$values ) { |
||
| 126 | |||
| 127 | /** |
||
| 128 | * @deprecated 2.03.11 |
||
| 129 | */ |
||
| 130 | public static function fill_values_from_entry( $atts, &$values ) { |
||
| 135 | |||
| 136 | /** |
||
| 137 | * @deprecated 2.03.11 |
||
| 138 | */ |
||
| 139 | public static function get_field_shortcodes_for_default_email( $f, &$values ) { |
||
| 151 | |||
| 152 | /** |
||
| 153 | * @deprecated 2.03.11 |
||
| 154 | */ |
||
| 155 | private static function get_field_value( $atts, &$val ) { |
||
| 174 | |||
| 175 | /** |
||
| 176 | * @since 2.03.02 |
||
| 177 | * |
||
| 178 | * @deprecated 2.03.11 |
||
| 179 | */ |
||
| 180 | public static function prepare_field_output( $atts, &$val ) { |
||
| 190 | |||
| 191 | /** |
||
| 192 | * @since 2.03.02 |
||
| 193 | * |
||
| 194 | * @deprecated 2.03.11 |
||
| 195 | */ |
||
| 196 | private static function flatten_array_value( $atts, &$val ) { |
||
| 207 | |||
| 208 | /** |
||
| 209 | * Strip HTML if from email value if plain text is selected |
||
| 210 | * |
||
| 211 | * @since 2.0.21 |
||
| 212 | * @param boolean $plain_text |
||
| 213 | * @param mixed $val |
||
| 214 | * |
||
| 215 | * @deprecated 2.03.11 |
||
| 216 | */ |
||
| 217 | private static function maybe_strip_html( $plain_text, &$val ) { |
||
| 228 | |||
| 229 | /** |
||
| 230 | * @deprecated 2.03.11 |
||
| 231 | */ |
||
| 232 | public static function get_browser( $u_agent ) { |
||
| 236 | |||
| 237 | /** |
||
| 238 | * @deprecated 2.03.11 |
||
| 239 | */ |
||
| 240 | public static function show_entry( $atts ) { |
||
| 244 | |||
| 245 | /** |
||
| 246 | * @deprecated 2.03.11 |
||
| 247 | */ |
||
| 248 | public static function convert_entry_to_content() { |
||
| 251 | } |
||
| 252 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.