Complex classes like Jetpack_Site 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 Jetpack_Site, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 7 | class Jetpack_Site extends Abstract_Jetpack_Site { |
||
| 8 | |||
| 9 | protected function get_mock_option( $name ) { |
||
| 12 | |||
| 13 | protected function get_constant( $name ) { |
||
| 19 | |||
| 20 | protected function main_network_site() { |
||
| 23 | |||
| 24 | protected function wp_version() { |
||
| 28 | |||
| 29 | protected function max_upload_size() { |
||
| 32 | |||
| 33 | protected function wp_memory_limit() { |
||
| 36 | |||
| 37 | protected function wp_max_memory_limit() { |
||
| 40 | |||
| 41 | protected function is_main_network() { |
||
| 44 | |||
| 45 | public function is_multisite() { |
||
| 48 | |||
| 49 | public function is_single_user_site() { |
||
| 52 | |||
| 53 | protected function is_version_controlled() { |
||
| 56 | |||
| 57 | protected function file_system_write_access() { |
||
| 60 | |||
| 61 | protected function current_theme_supports( $feature_name ) { |
||
| 64 | |||
| 65 | protected function get_theme_support( $feature_name ) { |
||
| 68 | |||
| 69 | public function get_updates() { |
||
| 72 | |||
| 73 | function get_id() { |
||
| 76 | |||
| 77 | function has_videopress() { |
||
| 86 | |||
| 87 | function upgraded_filetypes_enabled() { |
||
| 90 | |||
| 91 | function is_mapped_domain() { |
||
| 94 | |||
| 95 | function is_redirect() { |
||
| 98 | |||
| 99 | function is_following() { |
||
| 102 | |||
| 103 | function has_wordads() { |
||
| 106 | |||
| 107 | /** |
||
| 108 | * Creates a nonce to allow an iframed block editor to make authenticated requests to a Jetpack site. |
||
| 109 | * |
||
| 110 | * Disabled here in Jetpack because the nonce is only needed when making calls from dotcom domains, |
||
| 111 | * not when making calls on the same origin as we would be doing from `wp-admin/post.php` and friends. |
||
| 112 | */ |
||
| 113 | function get_frame_nonce() { |
||
| 116 | |||
| 117 | /** |
||
| 118 | * Creates a post preview nonce to use if the current user is logged out. |
||
| 119 | * |
||
| 120 | * Disabled here in Jetpack because the nonce is only needed when making calls from dotcom domains, |
||
| 121 | * in the case where users create a post in Calypso but are logged out from their Jetpack site. |
||
| 122 | */ |
||
| 123 | function get_frame_nonce_site_only() { |
||
| 126 | |||
| 127 | function is_headstart_fresh() { |
||
| 130 | |||
| 131 | function allowed_file_types() { |
||
| 145 | |||
| 146 | function is_private() { |
||
| 149 | |||
| 150 | function get_plan() { |
||
| 153 | |||
| 154 | function get_subscribers_count() { |
||
| 157 | |||
| 158 | function get_capabilities() { |
||
| 161 | |||
| 162 | function get_locale() { |
||
| 165 | |||
| 166 | function is_jetpack() { |
||
| 169 | |||
| 170 | public function get_jetpack_version() { |
||
| 173 | |||
| 174 | function get_ak_vp_bundle_enabled() {} |
||
| 175 | |||
| 176 | function get_jetpack_seo_front_page_description() { |
||
| 179 | |||
| 180 | function get_jetpack_seo_title_formats() { |
||
| 183 | |||
| 184 | function get_verification_services_codes() { |
||
| 187 | |||
| 188 | function get_podcasting_archive() { |
||
| 191 | |||
| 192 | function is_connected_site() { |
||
| 195 | |||
| 196 | function current_user_can( $role ) { |
||
| 199 | |||
| 200 | /** |
||
| 201 | * Post functions |
||
| 202 | */ |
||
| 203 | |||
| 204 | function wrap_post( $post, $context ) { |
||
| 207 | |||
| 208 | } |
||
| 209 |