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 |
||
| 8 | * Defines the minimum version of WordPress required by BWP. |
||
| 9 | */ |
||
| 10 | const MIN_WP_VERSION = '3.9'; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * Defines the minimum version of PHP required by BWP. |
||
| 14 | */ |
||
| 15 | const MIN_PHP_VERSION = '5.3.2'; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * Setup the plugin defaults on activation |
||
| 19 | */ |
||
| 20 | public static function activate() { |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Cleanup on plugin deactivation |
||
| 42 | * |
||
| 43 | * Removes options and clears all cron schedules |
||
| 44 | */ |
||
| 45 | public static function deactivate() { |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Deletes the backup schedule database entries and WP Cron entries. |
||
| 59 | */ |
||
| 60 | public static function delete_schedules() { |
||
| 73 | |||
| 74 | public static function trim_prefix( $item ) { |
||
| 77 | |||
| 78 | /** |
||
| 79 | * Deletes the plugin's transients from the database. |
||
| 80 | */ |
||
| 81 | public static function delete_transients() { |
||
| 94 | |||
| 95 | /** |
||
| 96 | * Deactivate BackUpWordPress. |
||
| 97 | */ |
||
| 98 | public static function self_deactivate() { |
||
| 115 | |||
| 116 | /** |
||
| 117 | * Determine if this WordPress install meets the minimum requirements for BWP to run. |
||
| 118 | * |
||
| 119 | * @return bool |
||
| 120 | */ |
||
| 121 | public static function meets_requirements() { |
||
| 133 | |||
| 134 | /** |
||
| 135 | * Checks the current PHP version against the required version. |
||
| 136 | * |
||
| 137 | * @return bool 'Operator' parameter specified, returns a boolean. |
||
| 138 | */ |
||
| 139 | protected static function is_supported_php_version() { |
||
| 143 | |||
| 144 | /** |
||
| 145 | * Checks the current WordPress version against the required version. |
||
| 146 | * |
||
| 147 | * @return bool 'Operator' parameter specified, returns a boolean. |
||
| 148 | */ |
||
| 149 | protected static function is_supported_wp_version() { |
||
| 153 | |||
| 154 | /** |
||
| 155 | * Displays a user friendly message in the WordPress admin. |
||
| 156 | */ |
||
| 157 | public static function display_admin_notices() { |
||
| 162 | |||
| 163 | /** |
||
| 164 | * Returns a localized user friendly error message. |
||
| 165 | * |
||
| 166 | * @return string |
||
| 167 | */ |
||
| 168 | public static function get_notice_message() { |
||
| 180 | |||
| 181 | } |
||
| 182 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.