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 |
||
| 9 | class Jetpack_Site extends Abstract_Jetpack_Site { |
||
| 10 | |||
| 11 | protected function get_mock_option( $name ) { |
||
| 14 | |||
| 15 | protected function get_constant( $name ) { |
||
| 21 | |||
| 22 | protected function main_network_site() { |
||
| 25 | |||
| 26 | protected function wp_version() { |
||
| 30 | |||
| 31 | protected function max_upload_size() { |
||
| 34 | |||
| 35 | protected function wp_memory_limit() { |
||
| 38 | |||
| 39 | protected function wp_max_memory_limit() { |
||
| 42 | |||
| 43 | protected function is_main_network() { |
||
| 46 | |||
| 47 | public function is_multisite() { |
||
| 50 | |||
| 51 | public function is_single_user_site() { |
||
| 54 | |||
| 55 | protected function is_version_controlled() { |
||
| 58 | |||
| 59 | protected function file_system_write_access() { |
||
| 62 | |||
| 63 | protected function current_theme_supports( $feature_name ) { |
||
| 66 | |||
| 67 | protected function get_theme_support( $feature_name ) { |
||
| 70 | |||
| 71 | public function get_updates() { |
||
| 74 | |||
| 75 | function get_id() { |
||
| 78 | |||
| 79 | function has_videopress() { |
||
| 88 | |||
| 89 | function upgraded_filetypes_enabled() { |
||
| 92 | |||
| 93 | function is_mapped_domain() { |
||
| 96 | |||
| 97 | function get_unmapped_url() { |
||
| 101 | |||
| 102 | function is_redirect() { |
||
| 105 | |||
| 106 | function is_following() { |
||
| 109 | |||
| 110 | function has_wordads() { |
||
| 113 | |||
| 114 | function get_frame_nonce() { |
||
| 117 | |||
| 118 | function get_jetpack_frame_nonce() { |
||
| 121 | |||
| 122 | function is_headstart_fresh() { |
||
| 125 | |||
| 126 | function allowed_file_types() { |
||
| 140 | |||
| 141 | /** |
||
| 142 | * Return site's privacy status. |
||
| 143 | * |
||
| 144 | * @return boolean Is site private? |
||
| 145 | */ |
||
| 146 | function is_private() { |
||
| 149 | |||
| 150 | /** |
||
| 151 | * Return site's coming soon status. |
||
| 152 | * |
||
| 153 | * @return boolean Is site "Coming soon"? |
||
| 154 | */ |
||
| 155 | function is_coming_soon() { |
||
| 158 | |||
| 159 | /** |
||
| 160 | * Return site's launch status. |
||
| 161 | * |
||
| 162 | * @return string|boolean Launch status ('launched', 'unlaunched', or false). |
||
| 163 | */ |
||
| 164 | function get_launch_status() { |
||
| 167 | |||
| 168 | function get_atomic_cloud_site_option( $option ) { |
||
| 185 | |||
| 186 | function get_plan() { |
||
| 189 | |||
| 190 | function get_subscribers_count() { |
||
| 193 | |||
| 194 | function get_capabilities() { |
||
| 197 | |||
| 198 | function get_locale() { |
||
| 201 | |||
| 202 | /** |
||
| 203 | * The flag indicates that the site has Jetpack installed |
||
| 204 | * |
||
| 205 | * @return bool |
||
| 206 | */ |
||
| 207 | public function is_jetpack() { |
||
| 210 | |||
| 211 | /** |
||
| 212 | * The flag indicates that the site is connected to WP.com via Jetpack Connection |
||
| 213 | * |
||
| 214 | * @return bool |
||
| 215 | */ |
||
| 216 | public function is_jetpack_connection() { |
||
| 219 | |||
| 220 | public function get_jetpack_version() { |
||
| 223 | |||
| 224 | function get_ak_vp_bundle_enabled() {} |
||
| 225 | |||
| 226 | function get_jetpack_seo_front_page_description() { |
||
| 229 | |||
| 230 | function get_jetpack_seo_title_formats() { |
||
| 233 | |||
| 234 | function get_verification_services_codes() { |
||
| 237 | |||
| 238 | function get_podcasting_archive() { |
||
| 241 | |||
| 242 | function is_connected_site() { |
||
| 245 | |||
| 246 | function is_wpforteams_site() { |
||
| 249 | |||
| 250 | function current_user_can( $role ) { |
||
| 253 | |||
| 254 | /** |
||
| 255 | * Check if full site editing should be considered as currently active. Full site editing |
||
| 256 | * requires the FSE plugin to be installed and activated, as well the current |
||
| 257 | * theme to be FSE compatible. The plugin can also be explicitly disabled via the |
||
| 258 | * a8c_disable_full_site_editing filter. |
||
| 259 | * |
||
| 260 | * @since 7.7.0 |
||
| 261 | * |
||
| 262 | * @return bool true if full site editing is currently active. |
||
| 263 | */ |
||
| 264 | function is_fse_active() { |
||
| 270 | |||
| 271 | /** |
||
| 272 | * Check if site should be considered as eligible for full site editing. Full site editing |
||
| 273 | * requires the FSE plugin to be installed and activated. For this method to return true |
||
| 274 | * the current theme does not need to be FSE compatible. The plugin can also be explicitly |
||
| 275 | * disabled via the a8c_disable_full_site_editing filter. |
||
| 276 | * |
||
| 277 | * @since 8.1.0 |
||
| 278 | * |
||
| 279 | * @return bool true if site is eligible for full site editing |
||
| 280 | */ |
||
| 281 | public function is_fse_eligible() { |
||
| 287 | |||
| 288 | /** |
||
| 289 | * Check if site should be considered as eligible for use of the core Site Editor. |
||
| 290 | * The Site Editor requires a block based theme to be active. |
||
| 291 | * |
||
| 292 | * @return bool true if site is eligible for the Site Editor |
||
| 293 | */ |
||
| 294 | public function is_core_site_editor_enabled() { |
||
| 297 | |||
| 298 | /** |
||
| 299 | * Return the last engine used for an import on the site. |
||
| 300 | * |
||
| 301 | * This option is not used in Jetpack. |
||
| 302 | */ |
||
| 303 | function get_import_engine() { |
||
| 306 | |||
| 307 | /** |
||
| 308 | * Post functions |
||
| 309 | */ |
||
| 310 | |||
| 311 | function wrap_post( $post, $context ) { |
||
| 314 | |||
| 315 | /** |
||
| 316 | * Get the option storing the Anchor podcast ID that identifies a site as a podcasting site. |
||
| 317 | * |
||
| 318 | * @return string |
||
| 319 | */ |
||
| 320 | public function get_anchor_podcast() { |
||
| 323 | |||
| 324 | } |
||
| 325 |