Complex classes like 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 Settings, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
5 | class 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 | 'taxonomies_blacklist' => true, |
||
20 | 'disable' => true, |
||
21 | 'network_disable' => true, |
||
22 | 'render_filtered_content' => true, |
||
23 | 'post_meta_whitelist' => true, |
||
24 | 'comment_meta_whitelist' => true, |
||
25 | 'max_enqueue_full_sync' => true, |
||
26 | 'max_queue_size_full_sync' => true, |
||
27 | 'sync_via_cron' => true, |
||
28 | 'cron_sync_time_limit' => true, |
||
29 | 'known_importers' => true, |
||
30 | ); |
||
31 | |||
32 | static $is_importing; |
||
33 | static $is_doing_cron; |
||
34 | static $is_syncing; |
||
35 | static $is_sending; |
||
36 | |||
37 | static $settings_cache = array(); // some settings can be expensive to compute - let's cache them |
||
38 | |||
39 | static function get_settings() { |
||
47 | |||
48 | // Fetches the setting. It saves it if the setting doesn't exist, so that it gets |
||
49 | // autoloaded on page load rather than re-queried every time. |
||
50 | static function get_setting( $setting ) { |
||
116 | |||
117 | static function update_settings( $new_settings ) { |
||
139 | |||
140 | static function is_network_setting( $setting ) { |
||
143 | |||
144 | // returns escapted SQL that can be injected into a WHERE clause |
||
145 | static function get_blacklisted_post_types_sql() { |
||
148 | |||
149 | static function get_blacklisted_taxonomies_sql() { |
||
152 | |||
153 | static function get_whitelisted_post_meta_sql() { |
||
156 | |||
157 | static function get_whitelisted_comment_meta_sql() { |
||
160 | |||
161 | static function get_comments_filter_sql() { |
||
164 | |||
165 | static function reset_data() { |
||
176 | |||
177 | static function set_importing( $is_importing ) { |
||
181 | |||
182 | static function is_importing() { |
||
189 | |||
190 | static function is_sync_enabled() { |
||
193 | |||
194 | static function set_doing_cron( $is_doing_cron ) { |
||
198 | |||
199 | static function is_doing_cron() { |
||
206 | |||
207 | static function is_syncing() { |
||
210 | |||
211 | static function set_is_syncing( $is_syncing ) { |
||
214 | |||
215 | static function is_sending() { |
||
218 | |||
219 | static function set_is_sending( $is_sending ) { |
||
222 | } |
||
223 |
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.