| Total Complexity | 40 |
| Total Lines | 193 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
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.
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() { |
||
| 27 | } |
||
| 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() { |
||
| 38 | |||
| 39 | $is_plugin = false; |
||
| 40 | if ( ! function_exists( 'get_plugins' ) ) { |
||
| 41 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
||
| 42 | } |
||
| 43 | |||
| 44 | // Get all plugins. |
||
| 45 | $plugins = get_plugins(); |
||
| 46 | $_plugin = ''; |
||
| 47 | foreach ( $plugins as $plugin => $args ) { |
||
| 48 | if ( ! $is_plugin && isset( $args['Name'] ) && ( 'Kirki' === $args['Name'] || 'Kirki Toolkit' === $args['Name'] ) ) { |
||
| 49 | $is_plugin = true; |
||
| 50 | $_plugin = $plugin; |
||
| 51 | } |
||
| 52 | } |
||
| 53 | |||
| 54 | // No need to proceed any further if Kirki wasn't found in the list of plugins. |
||
| 55 | if ( ! $is_plugin ) { |
||
| 56 | return false; |
||
| 57 | } |
||
| 58 | |||
| 59 | // Make sure the is_plugins_loaded function is loaded. |
||
| 60 | include_once ABSPATH . 'wp-admin/includes/plugin.php'; |
||
| 61 | |||
| 62 | // Extra logic in case the plugin is installed but not activated. |
||
| 63 | if ( $_plugin && is_plugin_inactive( $_plugin ) ) { |
||
| 64 | return false; |
||
| 65 | } |
||
| 66 | return $is_plugin; |
||
| 67 | } |
||
| 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() { |
||
| 113 | |||
| 114 | } |
||
| 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 = '' ) { |
||
| 157 | } |
||
| 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 | * @return int|string Returns integer when getting the 'major' version. |
||
| 167 | * Returns string when getting the 'minor' version. |
||
| 168 | */ |
||
| 169 | public static function get_wp_version( $context = 'minor' ) { |
||
| 179 | } |
||
| 180 | |||
| 181 | /** |
||
| 182 | * Returns the $wp_version, only numeric value. |
||
| 183 | * |
||
| 184 | * @static |
||
| 185 | * @access public |
||
| 186 | * @since 3.0.12 |
||
| 187 | * @param string $context Use 'minor' or 'major'. |
||
| 188 | * @param bool $only_numeric Whether we wwant to return numeric value or include beta/alpha etc. |
||
| 189 | * @return int|float Returns integer when getting the 'major' version. |
||
| 190 | * Returns float when getting the 'minor' version. |
||
| 191 | */ |
||
| 192 | public static function get_wp_version_numeric( $context = 'minor', $only_numeric = true ) { |
||
| 211 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.