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 | function get_frame_nonce() { |
||
110 | |||
111 | function is_headstart_fresh() { |
||
114 | |||
115 | function allowed_file_types() { |
||
129 | |||
130 | function is_private() { |
||
133 | |||
134 | function get_plan() { |
||
137 | |||
138 | function get_subscribers_count() { |
||
141 | |||
142 | function get_capabilities() { |
||
145 | |||
146 | function get_locale() { |
||
149 | |||
150 | function is_jetpack() { |
||
153 | |||
154 | public function get_jetpack_version() { |
||
157 | |||
158 | function get_ak_vp_bundle_enabled() {} |
||
159 | |||
160 | function get_jetpack_seo_front_page_description() { |
||
163 | |||
164 | function get_jetpack_seo_title_formats() { |
||
167 | |||
168 | function get_verification_services_codes() { |
||
171 | |||
172 | function get_podcasting_archive() { |
||
175 | |||
176 | function is_connected_site() { |
||
179 | |||
180 | function current_user_can( $role ) { |
||
183 | |||
184 | /** |
||
185 | * Post functions |
||
186 | */ |
||
187 | |||
188 | function wrap_post( $post, $context ) { |
||
191 | |||
192 | } |
||
193 |