Total Complexity | 50 |
Total Lines | 198 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Complex classes like Kirki_Field_Typography 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_Field_Typography, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
15 | class Kirki_Field_Typography extends Kirki_Field { |
||
16 | |||
17 | /** |
||
18 | * Sets the control type. |
||
19 | * |
||
20 | * @access protected |
||
21 | */ |
||
22 | protected function set_type() { |
||
23 | $this->type = 'kirki-typography'; |
||
24 | } |
||
25 | |||
26 | /** |
||
27 | * The class constructor. |
||
28 | * Parses and sanitizes all field arguments. |
||
29 | * Then it adds the field to Kirki::$fields. |
||
30 | * |
||
31 | * @access public |
||
32 | * @param string $config_id The ID of the config we want to use. |
||
33 | * Defaults to "global". |
||
34 | * Configs are handled by the Kirki_Config class. |
||
35 | * @param array $args The arguments of the field. |
||
36 | */ |
||
37 | public function __construct( $config_id = 'global', $args = array() ) { |
||
38 | parent::__construct( $config_id, $args ); |
||
39 | $this->set_default(); |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * Sets the default value. |
||
44 | * |
||
45 | * @access protected |
||
46 | */ |
||
47 | protected function set_default() { |
||
48 | |||
49 | // Accomodate the use of font-weight and convert to variant. |
||
50 | if ( isset( $this->default['font-weight'] ) ) { |
||
51 | $this->default['variant'] = ( 'regular' === $this->default['font-weight'] ) ? 400 : (string) intval( $this->default['font-weight'] ); |
||
52 | } |
||
53 | |||
54 | // Make sure letter-spacing has units. |
||
55 | if ( isset( $this->default['letter-spacing'] ) && is_numeric( $this->default['letter-spacing'] ) && $this->default['letter-spacing'] ) { |
||
56 | $this->default['letter-spacing'] .= 'px'; |
||
57 | } |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * Sets the $sanitize_callback |
||
62 | * |
||
63 | * @access protected |
||
64 | */ |
||
65 | protected function set_sanitize_callback() { |
||
66 | |||
67 | // If a custom sanitize_callback has been defined, |
||
68 | // then we don't need to proceed any further. |
||
69 | if ( ! empty( $this->sanitize_callback ) ) { |
||
70 | return; |
||
71 | } |
||
72 | $this->sanitize_callback = array( __CLASS__, 'sanitize' ); |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * Sets the $js_vars |
||
77 | * |
||
78 | * @access protected |
||
79 | */ |
||
80 | protected function set_js_vars() { |
||
123 | } |
||
124 | } |
||
125 | |||
126 | /** |
||
127 | * Sanitizes typography controls |
||
128 | * |
||
129 | * @static |
||
130 | * @since 2.2.0 |
||
131 | * @param array $value The value. |
||
132 | * @return array |
||
133 | */ |
||
134 | public static function sanitize( $value ) { |
||
195 | } |
||
196 | |||
197 | /** |
||
198 | * Sets the $choices |
||
199 | * |
||
200 | * @access protected |
||
201 | * @since 3.0.0 |
||
202 | */ |
||
203 | protected function set_choices() { |
||
218 |