Complex classes like Kirki_Util 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_Util, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
16 | class Kirki_Util { |
||
17 | |||
18 | /** |
||
19 | * Constructor. |
||
20 | * |
||
21 | * @since 3.0.9 |
||
22 | * @access public |
||
23 | */ |
||
24 | public function __construct() { |
||
28 | |||
29 | /** |
||
30 | * Determine if Kirki is installed as a plugin. |
||
31 | * |
||
32 | * @static |
||
33 | * @access public |
||
34 | * @since 3.0.0 |
||
35 | * @return bool |
||
36 | */ |
||
37 | public static function is_plugin() { |
||
68 | |||
69 | /** |
||
70 | * Build the variables. |
||
71 | * |
||
72 | * @static |
||
73 | * @access public |
||
74 | * @since 3.0.9 |
||
75 | * @return array Formatted as array( 'variable-name' => value ). |
||
76 | */ |
||
77 | public static function get_variables() { |
||
115 | |||
116 | /** |
||
117 | * HTTP Request injection. |
||
118 | * |
||
119 | * @access public |
||
120 | * @since 3.0.0 |
||
121 | * @param array $request The request params. |
||
122 | * @param string $url The request URL. |
||
123 | * @return array |
||
124 | */ |
||
125 | public function http_request( $request = array(), $url = '' ) { |
||
158 | |||
159 | /** |
||
160 | * Returns the $wp_version. |
||
161 | * |
||
162 | * @static |
||
163 | * @access public |
||
164 | * @since 3.0.12 |
||
165 | * @param string $context Use 'minor' or 'major'. |
||
166 | * @param boolean $only_numeric Set to true if you want to skip the alpha/beta etc parts. |
||
167 | * @return int|float|string Returns integer when getting the 'major' version. |
||
168 | * Returns float when getting the 'minor' version with $only_numeric set to true. |
||
169 | * Returns string when getting the 'minor' version with $only_numeric set to false. |
||
170 | */ |
||
171 | public static function get_wp_version( $context = 'minor', $only_numeric = true ) { |
||
192 | } |
||
193 |