Complex classes like Jetpack_Sync_Settings 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_Sync_Settings, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 5 | class Jetpack_Sync_Settings { |
||
| 6 | const SETTINGS_OPTION_PREFIX = 'jetpack_sync_settings_'; |
||
| 7 | |||
| 8 | static $valid_settings = array( |
||
| 9 | 'dequeue_max_bytes' => true, |
||
| 10 | 'upload_max_bytes' => true, |
||
| 11 | 'upload_max_rows' => true, |
||
| 12 | 'sync_wait_time' => true, |
||
| 13 | 'sync_wait_threshold' => true, |
||
| 14 | 'enqueue_wait_time' => true, |
||
| 15 | 'max_queue_size' => true, |
||
| 16 | 'max_queue_lag' => true, |
||
| 17 | 'queue_max_writes_sec' => true, |
||
| 18 | 'post_types_blacklist' => true, |
||
| 19 | 'disable' => true, |
||
| 20 | 'network_disable' => true, |
||
| 21 | 'render_filtered_content' => true, |
||
| 22 | 'post_meta_whitelist' => true, |
||
| 23 | 'comment_meta_whitelist' => true, |
||
| 24 | 'max_enqueue_full_sync' => true, |
||
| 25 | 'max_queue_size_full_sync' => true, |
||
| 26 | 'sync_via_cron' => true, |
||
| 27 | 'cron_sync_time_limit' => true, |
||
| 28 | ); |
||
| 29 | |||
| 30 | static $is_importing; |
||
| 31 | static $is_doing_cron; |
||
| 32 | static $is_syncing; |
||
| 33 | static $is_sending; |
||
| 34 | |||
| 35 | static $settings_cache = array(); // some settings can be expensive to compute - let's cache them |
||
| 36 | |||
| 37 | static function get_settings() { |
||
| 45 | |||
| 46 | // Fetches the setting. It saves it if the setting doesn't exist, so that it gets |
||
| 47 | // autoloaded on page load rather than re-queried every time. |
||
| 48 | static function get_setting( $setting ) { |
||
| 108 | |||
| 109 | static function update_settings( $new_settings ) { |
||
| 132 | |||
| 133 | static function is_network_setting( $setting ) { |
||
| 136 | |||
| 137 | // returns escapted SQL that can be injected into a WHERE clause |
||
| 138 | static function get_blacklisted_post_types_sql() { |
||
| 141 | |||
| 142 | static function get_whitelisted_post_meta_sql() { |
||
| 145 | |||
| 146 | static function get_whitelisted_comment_meta_sql() { |
||
| 149 | |||
| 150 | static function get_comments_filter_sql() { |
||
| 153 | |||
| 154 | static function reset_data() { |
||
| 165 | |||
| 166 | static function set_importing( $is_importing ) { |
||
| 170 | |||
| 171 | static function is_importing() { |
||
| 178 | |||
| 179 | static function is_sync_enabled() { |
||
| 182 | |||
| 183 | static function set_doing_cron( $is_doing_cron ) { |
||
| 187 | |||
| 188 | static function is_doing_cron() { |
||
| 195 | |||
| 196 | static function is_syncing() { |
||
| 199 | |||
| 200 | static function set_is_syncing( $is_syncing ) { |
||
| 203 | |||
| 204 | static function is_sending() { |
||
| 207 | |||
| 208 | static function set_is_sending( $is_sending ) { |
||
| 211 | } |
||
| 212 |
This check looks for access to properties that are not accessible from the current context.
If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.