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 get_post_type_features() { |
||
28 | global $_wp_post_type_features; |
||
32 | |||
33 | public static function get_hosting_provider() { |
||
34 | if ( defined( 'GD_SYSTEM_PLUGIN_DIR' ) || class_exists( '\\WPaaS\\Plugin' ) ) { |
||
35 | return 'gd-managed-wp'; |
||
36 | } |
||
37 | if ( defined( 'MM_BASE_DIR' ) ) { |
||
38 | return 'bh'; |
||
39 | } |
||
40 | if ( defined( 'IS_PRESSABLE' ) ) { |
||
41 | return 'pressable'; |
||
42 | } |
||
43 | if ( function_exists( 'is_wpe' ) || function_exists( 'is_wpe_snapshot' ) ) { |
||
44 | return 'wpe'; |
||
45 | } |
||
46 | return 'unknown'; |
||
47 | } |
||
48 | |||
49 | public static function rest_api_allowed_post_types() { |
||
53 | |||
54 | public static function rest_api_allowed_public_metadata() { |
||
58 | |||
59 | /** |
||
60 | * Finds out if a site is using a version control system. |
||
61 | * @return bool |
||
62 | **/ |
||
63 | public static function is_version_controlled() { |
||
72 | |||
73 | /** |
||
74 | * Returns true if the site has file write access false otherwise. |
||
75 | * @return bool |
||
76 | **/ |
||
77 | public static function file_system_write_access() { |
||
98 | |||
99 | public static function home_url() { |
||
102 | |||
103 | public static function site_url() { |
||
106 | |||
107 | public static function main_network_site_url() { |
||
110 | |||
111 | public static function preserve_scheme( $option, $url_function, $normalize_www = false ) { |
||
158 | |||
159 | public static function get_plugins() { |
||
167 | |||
168 | public static function wp_version() { |
||
173 | |||
174 | public static function site_icon_url() { |
||
181 | } |
||
182 |