Complex classes like Kirki_Init 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 Kirki_Init, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
16 | class Kirki_Init { |
||
17 | |||
18 | /** |
||
19 | * Control types. |
||
20 | * |
||
21 | * @access private |
||
22 | * @since 3.0.0 |
||
23 | * @var array |
||
24 | */ |
||
25 | private $control_types = array(); |
||
26 | |||
27 | /** |
||
28 | * The class constructor. |
||
29 | */ |
||
30 | public function __construct() { |
||
38 | |||
39 | /** |
||
40 | * Properly set the Kirki URL for assets. |
||
41 | * Determines if Kirki is installed as a plugin, in a child theme, or a parent theme |
||
42 | * and then does some calculations to get the proper URL for its CSS & JS assets. |
||
43 | */ |
||
44 | public function set_url() { |
||
61 | |||
62 | /** |
||
63 | * Add the default Kirki control types. |
||
64 | * |
||
65 | * @access public |
||
66 | * @since 3.0.0 |
||
67 | * @param array $control_types The control types array. |
||
68 | * @return array |
||
69 | */ |
||
70 | public function default_control_types( $control_types = array() ) { |
||
108 | |||
109 | /** |
||
110 | * Helper function that adds the fields, sections and panels to the customizer. |
||
111 | * |
||
112 | * @return void |
||
113 | */ |
||
114 | public function add_to_customizer() { |
||
122 | |||
123 | /** |
||
124 | * Register control types |
||
125 | * |
||
126 | * @return void |
||
127 | */ |
||
128 | public function register_control_types() { |
||
147 | |||
148 | /** |
||
149 | * Register our panels to the WordPress Customizer. |
||
150 | * |
||
151 | * @access public |
||
152 | */ |
||
153 | public function add_panels() { |
||
160 | |||
161 | /** |
||
162 | * Register our sections to the WordPress Customizer. |
||
163 | * |
||
164 | * @var object The WordPress Customizer object |
||
165 | * @return void |
||
166 | */ |
||
167 | public function add_sections() { |
||
174 | |||
175 | /** |
||
176 | * Create the settings and controls from the $fields array and register them. |
||
177 | * |
||
178 | * @var object The WordPress Customizer object |
||
179 | * @return void |
||
180 | */ |
||
181 | public function add_fields() { |
||
200 | |||
201 | /** |
||
202 | * Build the variables. |
||
203 | * |
||
204 | * @return array ('variable-name' => value) |
||
205 | */ |
||
206 | public static function get_variables() { |
||
245 | |||
246 | /** |
||
247 | * Process fields added using the 'kirki/fields' and 'kirki/controls' filter. |
||
248 | * These filters are no longer used, this is simply for backwards-compatibility. |
||
249 | */ |
||
250 | public function fields_from_filters() { |
||
262 | |||
263 | /** |
||
264 | * Handle saving of settings with "user_meta" storage type. |
||
265 | * |
||
266 | * @param string $value The value being saved. |
||
267 | * @param object $wp_customize_setting $WP_Customize_Setting The WP_Customize_Setting instance when saving is happening. |
||
268 | */ |
||
269 | public function update_user_meta( $value, $wp_customize_setting ) { |
||
272 | |||
273 | /** |
||
274 | * Changes select2 version in ACF. |
||
275 | * Fixes a plugin conflict that was causing select fields to crash |
||
276 | * because of a version mismatch between ACF's and Kirki's select2 scripts. |
||
277 | * Props @hellor0bot |
||
278 | * |
||
279 | * @see https://github.com/aristath/kirki/issues/1302 |
||
280 | * @access public |
||
281 | * @since 3.0.0 |
||
282 | * @param string $ver The Select2 script version. |
||
283 | * @return int |
||
|
|||
284 | */ |
||
285 | public function acf_select2_version( $ver ) { |
||
291 | |||
292 | /** |
||
293 | * Determine if Kirki is installed as a plugin. |
||
294 | * |
||
295 | * @static |
||
296 | * @access public |
||
297 | * @since 3.0.0 |
||
298 | * @return bool |
||
299 | */ |
||
300 | public static function is_plugin() { |
||
336 | } |
||
337 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.