Complex classes like Assets 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 Assets, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
22 | class Assets { |
||
23 | |||
24 | /** |
||
25 | * Load minified assets. |
||
26 | * |
||
27 | * @access private |
||
28 | * @var string |
||
29 | */ |
||
30 | private $min = '.min'; |
||
31 | |||
32 | /** |
||
33 | * Scripts. |
||
34 | * |
||
35 | * @access private |
||
36 | * @var array |
||
37 | */ |
||
38 | private $scripts = array(); |
||
39 | |||
40 | /** |
||
41 | * Styles. |
||
42 | * |
||
43 | * @access private |
||
44 | * @var array |
||
45 | */ |
||
46 | private $styles = array(); |
||
47 | |||
48 | /** |
||
49 | * Disable styles. |
||
50 | * |
||
51 | * @access public |
||
52 | * @var bool |
||
53 | */ |
||
54 | public $disable_styles = false; |
||
55 | |||
56 | /** |
||
57 | * Hook in tabs. |
||
58 | * |
||
59 | * @since 3.0.0 |
||
60 | */ |
||
61 | public function __construct() { |
||
74 | |||
75 | /** |
||
76 | * Register scripts and styles. |
||
77 | * |
||
78 | * @since 3.0.0 |
||
79 | */ |
||
80 | public function register() { |
||
83 | |||
84 | /** |
||
85 | * Enqueue scripts and styles. |
||
86 | * |
||
87 | * @since 3.0.0 |
||
88 | */ |
||
89 | public function enqueue() { |
||
111 | |||
112 | /** |
||
113 | * Load scripts and styles. |
||
114 | * |
||
115 | * @since 3.0.0 |
||
116 | */ |
||
117 | public function load() { |
||
128 | |||
129 | /** |
||
130 | * Get widgets assets. |
||
131 | * |
||
132 | * @since 3.0.0 |
||
133 | */ |
||
134 | public function get_widgets_assets() { |
||
164 | |||
165 | /** |
||
166 | * Scripts. |
||
167 | * |
||
168 | * @since 3.0.0 |
||
169 | * |
||
170 | * @param array $scripts |
||
171 | */ |
||
172 | public function load_scripts( $scripts ) { |
||
202 | |||
203 | /** |
||
204 | * Styles. |
||
205 | * |
||
206 | * @since 3.0.0 |
||
207 | * |
||
208 | * @param array $styles |
||
209 | */ |
||
210 | public function load_styles( $styles ) { |
||
235 | |||
236 | /** |
||
237 | * Return the default scripts that are loaded. Used mainly for the always enqueue scripts option. |
||
238 | * |
||
239 | * This can be improved. |
||
240 | */ |
||
241 | public function get_default_scripts() { |
||
263 | |||
264 | /** |
||
265 | * Return the default styles that are loaded. Used mainly for the always enqueue scripts option. |
||
266 | * |
||
267 | * This can be improved. |
||
268 | */ |
||
269 | public function get_default_styles() { |
||
294 | |||
295 | } |
||
296 |