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 |
||
| 7 | class Jetpack_Sync_Functions { |
||
| 8 | |||
| 9 | public static function get_modules() { |
||
| 10 | require_once( JETPACK__PLUGIN_DIR . 'class.jetpack-admin.php' ); |
||
| 11 | |||
| 12 | return Jetpack_Admin::init()->get_modules(); |
||
| 13 | } |
||
| 14 | |||
| 15 | public static function get_taxonomies() { |
||
| 16 | global $wp_taxonomies; |
||
| 17 | |||
| 18 | return $wp_taxonomies; |
||
| 19 | } |
||
| 20 | |||
| 21 | public static function get_post_types() { |
||
| 26 | |||
| 27 | public static function rest_api_allowed_post_types() { |
||
| 31 | |||
| 32 | public static function rest_api_allowed_public_metadata() { |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Finds out if a site is using a version control system. |
||
| 39 | * @return bool |
||
| 40 | **/ |
||
| 41 | public static function is_version_controlled() { |
||
| 42 | |||
| 43 | if ( ! class_exists( 'WP_Automatic_Updater' ) ) { |
||
| 44 | require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' ); |
||
| 45 | } |
||
| 46 | $updater = new WP_Automatic_Updater(); |
||
| 47 | |||
| 48 | return (bool) strval( $updater->is_vcs_checkout( $context = ABSPATH ) ); |
||
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Returns true if the site has file write access false otherwise. |
||
| 53 | * @return bool |
||
| 54 | **/ |
||
| 55 | public static function file_system_write_access() { |
||
| 76 | |||
| 77 | public static function home_url() { |
||
| 80 | |||
| 81 | public static function site_url() { |
||
| 84 | |||
| 85 | public static function main_network_site_url() { |
||
| 88 | |||
| 89 | public static function preserve_scheme( $option, $url, $normalize_www = false ) { |
||
| 90 | $option_url = get_option( $option ); |
||
| 127 | |||
| 128 | public static function get_plugins() { |
||
| 136 | |||
| 137 | public static function wp_version() { |
||
| 142 | } |
||
| 143 |