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 FrmDeprecated 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 FrmDeprecated, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 9 | class FrmDeprecated { |
||
| 10 | |||
| 11 | /** |
||
| 12 | * @deprecated 2.3 |
||
| 13 | */ |
||
| 14 | public static function deprecated( $function, $version ) { |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @deprecated 3.04.03 |
||
| 20 | */ |
||
| 21 | public static function get_licenses() { |
||
| 49 | |||
| 50 | |||
| 51 | /** |
||
| 52 | * Don't allow subsite addon licenses to be fetched |
||
| 53 | * unless the current user has super admin permissions |
||
| 54 | * |
||
| 55 | * @since 2.03.10 |
||
| 56 | * @deprecated 3.04.03 |
||
| 57 | */ |
||
| 58 | private static function allow_autofill() { |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @deprecated 3.04.03 |
||
| 71 | */ |
||
| 72 | private static function send_api_request( $url, $transient = array() ) { |
||
| 96 | |||
| 97 | /** |
||
| 98 | * Add a filter to shorten the EDD filename for Formidable plugin, and add-on, updates |
||
| 99 | * |
||
| 100 | * @since 2.03.08 |
||
| 101 | * @deprecated 3.04.03 |
||
| 102 | * |
||
| 103 | * @param boolean $return |
||
| 104 | * @param string $package |
||
| 105 | * |
||
| 106 | * @return boolean |
||
| 107 | */ |
||
| 108 | public static function add_shorten_edd_filename_filter( $return, $package ) { |
||
| 117 | |||
| 118 | /** |
||
| 119 | * Shorten the EDD filename for automatic updates |
||
| 120 | * Decreases size of file path so file path limit is not hit on Windows servers |
||
| 121 | * |
||
| 122 | * @since 2.03.08 |
||
| 123 | * @deprecated 3.04.03 |
||
| 124 | * |
||
| 125 | * @param string $filename |
||
| 126 | * @param string $ext |
||
| 127 | * |
||
| 128 | * @return string |
||
| 129 | */ |
||
| 130 | public static function shorten_edd_filename( $filename, $ext ) { |
||
| 138 | |||
| 139 | /** |
||
| 140 | * Filter shortcodes in text widgets |
||
| 141 | * |
||
| 142 | * @deprecated 2.5.4 |
||
| 143 | */ |
||
| 144 | public static function widget_text_filter( $content ) { |
||
| 149 | |||
| 150 | /** |
||
| 151 | * Used to filter shortcode in text widgets |
||
| 152 | * |
||
| 153 | * @deprecated 2.5.4 |
||
| 154 | */ |
||
| 155 | public static function widget_text_filter_callback( $matches ) { |
||
| 159 | |||
| 160 | /** |
||
| 161 | * Deprecated in favor of wpmu_upgrade_site |
||
| 162 | * |
||
| 163 | * @deprecated 2.3 |
||
| 164 | */ |
||
| 165 | public static function front_head() { |
||
| 171 | |||
| 172 | /** |
||
| 173 | * @deprecated 3.0.04 |
||
| 174 | */ |
||
| 175 | public static function activation_install() { |
||
| 181 | |||
| 182 | /** |
||
| 183 | * Routes for wordpress pages -- we're just replacing content |
||
| 184 | * |
||
| 185 | * @deprecated 3.0 |
||
| 186 | */ |
||
| 187 | public static function page_route( $content ) { |
||
| 197 | |||
| 198 | /** |
||
| 199 | * @deprecated 1.07.05 |
||
| 200 | */ |
||
| 201 | public static function get_form_shortcode( $atts ) { |
||
| 205 | |||
| 206 | /** |
||
| 207 | * @deprecated 1.07.05 |
||
| 208 | */ |
||
| 209 | public static function show_form( $id = '', $key = '', $title = false, $description = false ) { |
||
| 213 | |||
| 214 | /** |
||
| 215 | * @deprecated 1.07.05 |
||
| 216 | */ |
||
| 217 | public static function get_form( $filename, $form, $title, $description ) { |
||
| 221 | |||
| 222 | /** |
||
| 223 | * @deprecated 3.0 |
||
| 224 | */ |
||
| 225 | public static function edit_name( $field = 'name', $id = '' ) { |
||
| 254 | |||
| 255 | /** |
||
| 256 | * Load a single field in the form builder along with all needed variables |
||
| 257 | * |
||
| 258 | * @deprecated 3.0 |
||
| 259 | * |
||
| 260 | * @param int $field_id |
||
| 261 | * @param array $values |
||
| 262 | * @param int $form_id |
||
| 263 | * |
||
| 264 | * @return array |
||
| 265 | */ |
||
| 266 | public static function include_single_field( $field_id, $values, $form_id = 0 ) { |
||
| 274 | |||
| 275 | /** |
||
| 276 | * @deprecated 3.0 |
||
| 277 | */ |
||
| 278 | public static function bulk_create_template( $ids ) { |
||
| 288 | |||
| 289 | /** |
||
| 290 | * @deprecated 2.03 |
||
| 291 | */ |
||
| 292 | public static function register_pro_scripts() { |
||
| 298 | |||
| 299 | /** |
||
| 300 | * @deprecated 3.0 |
||
| 301 | */ |
||
| 302 | public static function edit_key() { |
||
| 308 | |||
| 309 | /** |
||
| 310 | * @deprecated 3.0 |
||
| 311 | */ |
||
| 312 | public static function edit_description() { |
||
| 318 | |||
| 319 | /** |
||
| 320 | * @deprecated 3.0 |
||
| 321 | */ |
||
| 322 | private static function edit_in_place_value( $field ) { |
||
| 336 | |||
| 337 | /** |
||
| 338 | * @deprecated 1.07.05 |
||
| 339 | */ |
||
| 340 | public static function add_default_templates( $path, $default = true, $template = true ) { |
||
| 381 | |||
| 382 | /** |
||
| 383 | * @deprecated 3.01 |
||
| 384 | */ |
||
| 385 | public static function sanitize_array( &$values ) { |
||
| 389 | |||
| 390 | /** |
||
| 391 | * Prepare and save settings in styles and actions |
||
| 392 | * |
||
| 393 | * @param array $settings |
||
| 394 | * @param string $group |
||
| 395 | * |
||
| 396 | * @since 2.0.6 |
||
| 397 | * @deprecated 2.05.06 |
||
| 398 | */ |
||
| 399 | public static function save_settings( $settings, $group ) { |
||
| 403 | |||
| 404 | /** |
||
| 405 | * Since actions are JSON encoded, we don't want any filters messing with it. |
||
| 406 | * Remove the filters and then add them back in case any posts or views are |
||
| 407 | * also being imported. |
||
| 408 | * |
||
| 409 | * Used when saving form actions and styles |
||
| 410 | * |
||
| 411 | * @since 2.0.4 |
||
| 412 | * @deprecated 2.05.06 |
||
| 413 | */ |
||
| 414 | public static function save_json_post( $settings ) { |
||
| 418 | |||
| 419 | /** |
||
| 420 | * Check cache before fetching values and saving to cache |
||
| 421 | * |
||
| 422 | * @since 2.0 |
||
| 423 | * @deprecated 2.05.06 |
||
| 424 | * |
||
| 425 | * @param string $cache_key The unique name for this cache |
||
| 426 | * @param string $group The name of the cache group |
||
| 427 | * @param string $query If blank, don't run a db call |
||
| 428 | * @param string $type The wpdb function to use with this query |
||
| 429 | * @return mixed $results The cache or query results |
||
| 430 | */ |
||
| 431 | public static function check_cache( $cache_key, $group = '', $query = '', $type = 'get_var', $time = 300 ) { |
||
| 435 | |||
| 436 | /** |
||
| 437 | * @deprecated 2.05.06 |
||
| 438 | */ |
||
| 439 | public static function set_cache( $cache_key, $results, $group = '', $time = 300 ) { |
||
| 443 | |||
| 444 | /** |
||
| 445 | * Keep track of the keys cached in each group so they can be deleted |
||
| 446 | * in Redis and Memcache |
||
| 447 | * @deprecated 2.05.06 |
||
| 448 | */ |
||
| 449 | public static function add_key_to_group_cache( $key, $group ) { |
||
| 453 | |||
| 454 | /** |
||
| 455 | * @deprecated 2.05.06 |
||
| 456 | */ |
||
| 457 | public static function get_group_cached_keys( $group ) { |
||
| 461 | |||
| 462 | /** |
||
| 463 | * @since 2.0 |
||
| 464 | * @deprecated 2.05.06 |
||
| 465 | * @param string $cache_key |
||
| 466 | */ |
||
| 467 | public static function delete_cache_and_transient( $cache_key, $group = 'default' ) { |
||
| 471 | |||
| 472 | /** |
||
| 473 | * @since 2.0 |
||
| 474 | * @deprecated 2.05.06 |
||
| 475 | * |
||
| 476 | * @param string $group The name of the cache group |
||
| 477 | */ |
||
| 478 | public static function cache_delete_group( $group ) { |
||
| 482 | |||
| 483 | /** |
||
| 484 | * Added for < WP 4.0 compatability |
||
| 485 | * |
||
| 486 | * @since 1.07.10 |
||
| 487 | * @deprecated 2.05.06 |
||
| 488 | * |
||
| 489 | * @param string $term The value to escape |
||
| 490 | * @return string The escaped value |
||
| 491 | */ |
||
| 492 | public static function esc_like( $term ) { |
||
| 496 | |||
| 497 | /** |
||
| 498 | * @param string $order_query |
||
| 499 | * @deprecated 2.05.06 |
||
| 500 | */ |
||
| 501 | public static function esc_order( $order_query ) { |
||
| 505 | |||
| 506 | /** |
||
| 507 | * Make sure this is ordering by either ASC or DESC |
||
| 508 | * @deprecated 2.05.06 |
||
| 509 | */ |
||
| 510 | public static function esc_order_by( &$order_by ) { |
||
| 514 | |||
| 515 | /** |
||
| 516 | * @param string $limit |
||
| 517 | * @deprecated 2.05.06 |
||
| 518 | */ |
||
| 519 | public static function esc_limit( $limit ) { |
||
| 523 | |||
| 524 | /** |
||
| 525 | * Get an array of values ready to go through $wpdb->prepare |
||
| 526 | * @since 2.0 |
||
| 527 | * @deprecated 2.05.06 |
||
| 528 | */ |
||
| 529 | public static function prepare_array_values( $array, $type = '%s' ) { |
||
| 533 | |||
| 534 | /** |
||
| 535 | * @deprecated 2.05.06 |
||
| 536 | */ |
||
| 537 | public static function prepend_and_or_where( $starts_with = ' WHERE ', $where = '' ) { |
||
| 541 | |||
| 542 | /** |
||
| 543 | * @deprecated 2.05.06 |
||
| 544 | */ |
||
| 545 | public static function upgrade() { |
||
| 549 | |||
| 550 | /** |
||
| 551 | * @deprecated 2.05.06 |
||
| 552 | */ |
||
| 553 | public static function collation() { |
||
| 557 | |||
| 558 | /** |
||
| 559 | * @deprecated 2.05.06 |
||
| 560 | */ |
||
| 561 | public static function uninstall() { |
||
| 565 | |||
| 566 | /** |
||
| 567 | * @deprecated 3.0 |
||
| 568 | * |
||
| 569 | * @param string $html |
||
| 570 | * @param array $field |
||
| 571 | * @param array $errors |
||
| 572 | * @param object $form |
||
| 573 | * @param array $args |
||
| 574 | * |
||
| 575 | * @return string |
||
| 576 | */ |
||
| 577 | public static function replace_shortcodes( $html, $field, $errors = array(), $form = false, $args = array() ) { |
||
| 582 | |||
| 583 | /** |
||
| 584 | * @deprecated 3.0 |
||
| 585 | */ |
||
| 586 | public static function get_default_field_opts( $type, $field = null, $limit = false ) { |
||
| 597 | |||
| 598 | /** |
||
| 599 | * @deprecated 2.02.07 |
||
| 600 | */ |
||
| 601 | public static function dropdown_categories( $args ) { |
||
| 613 | |||
| 614 | /** |
||
| 615 | * @deprecated 3.0 |
||
| 616 | */ |
||
| 617 | public static function remove_inline_conditions( $no_vars, $code, $replace_with, &$html ) { |
||
| 621 | |||
| 622 | /** |
||
| 623 | * @deprecated 3.0 |
||
| 624 | */ |
||
| 625 | public static function get_shortcode_tag( $shortcodes, $short_key, $args ) { |
||
| 629 | |||
| 630 | /** |
||
| 631 | * @deprecated 3.01 |
||
| 632 | */ |
||
| 633 | public static function get_sigle_label_postitions() { |
||
| 637 | |||
| 638 | /** |
||
| 639 | * @deprecated 3.02.03 |
||
| 640 | */ |
||
| 641 | public static function jquery_themes() { |
||
| 674 | |||
| 675 | /** |
||
| 676 | * @deprecated 3.02.03 |
||
| 677 | */ |
||
| 678 | public static function enqueue_jquery_css() { |
||
| 687 | |||
| 688 | /** |
||
| 689 | * @deprecated 3.02.03 |
||
| 690 | */ |
||
| 691 | public static function jquery_css_url( $theme_css ) { |
||
| 714 | |||
| 715 | /** |
||
| 716 | * @deprecated 3.02.03 |
||
| 717 | */ |
||
| 718 | public static function get_form_for_page() { |
||
| 733 | |||
| 734 | /** |
||
| 735 | * @deprecated 3.0 |
||
| 736 | */ |
||
| 737 | public static function validate_url_field( &$errors, $field, $value, $args ) { |
||
| 746 | |||
| 747 | /** |
||
| 748 | * @deprecated 3.0 |
||
| 749 | */ |
||
| 750 | View Code Duplication | public static function validate_email_field( &$errors, $field, $value, $args ) { |
|
| 759 | |||
| 760 | /** |
||
| 761 | * @deprecated 3.0 |
||
| 762 | */ |
||
| 763 | View Code Duplication | public static function validate_number_field( &$errors, $field, $value, $args ) { |
|
| 773 | |||
| 774 | /** |
||
| 775 | * @deprecated 3.0 |
||
| 776 | */ |
||
| 777 | View Code Duplication | public static function validate_recaptcha( &$errors, $field, $args ) { |
|
| 786 | } |
||
| 787 |
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.