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:
| 1 | <?php |
||
| 6 | class FrmWelcomeController { |
||
| 7 | |||
| 8 | public static $menu_slug = 'formidable-welcome'; |
||
| 9 | |||
| 10 | public static $option_name = 'frm_activation_redirect'; |
||
| 11 | |||
| 12 | private static $last_redirect = 'frm_welcome_redirect'; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * Register all of the hooks related to the welcome screen functionality |
||
| 16 | * |
||
| 17 | * @access public |
||
| 18 | */ |
||
| 19 | public static function load_hooks() { |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Performs a safe (local) redirect to the welcome screen |
||
| 33 | * when the plugin is activated |
||
| 34 | * |
||
| 35 | * @return void |
||
| 36 | */ |
||
| 37 | public static function redirect() { |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Don't redirect every time the plugin is activated. |
||
| 68 | */ |
||
| 69 | private static function already_redirected() { |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Add a submenu welcome screen for the formidable parent menu |
||
| 81 | * |
||
| 82 | * @return void |
||
| 83 | */ |
||
| 84 | public static function screen_page() { |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Include html content for the welcome screem |
||
| 90 | * |
||
| 91 | * @return void |
||
| 92 | */ |
||
| 93 | public static function screen_content() { |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Remove the welcome screen submenu page from the formidable parent menu |
||
| 100 | * since it is not necessary to show that link there |
||
| 101 | * |
||
| 102 | * @return void |
||
| 103 | */ |
||
| 104 | public static function remove_menu() { |
||
| 107 | |||
| 108 | /** |
||
| 109 | * Register the stylesheets for the welcome screen. |
||
| 110 | * |
||
| 111 | * @return void |
||
| 112 | */ |
||
| 113 | public static function enqueue_styles() { |
||
| 117 | |||
| 118 | /** |
||
| 119 | * Helps to confirm if the user is currently on the welcome screen |
||
| 120 | * |
||
| 121 | * @return bool |
||
| 122 | */ |
||
| 123 | public static function is_welcome_screen() { |
||
| 127 | |||
| 128 | /** |
||
| 129 | * Build the admin URL link for the welcome screen |
||
| 130 | * |
||
| 131 | * @return string |
||
| 132 | */ |
||
| 133 | public static function settings_link() { |
||
| 136 | |||
| 137 | public static function upgrade_to_pro_button() { |
||
| 146 | |||
| 147 | public static function maybe_show_license_box() { |
||
| 152 | |||
| 153 | public static function maybe_show_conditional_action_button( $plugin, $upgrade_link_args ) { |
||
| 159 | } |
||
| 160 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.