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() { |
||
62 | |||
63 | $this->min = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG == true ) ? '' : '.min'; |
||
64 | |||
65 | $settings = get_option( 'simple-calendar_settings_advanced' ); |
||
66 | |||
67 | if ( isset( $settings['assets']['disable_css'] ) ) { |
||
68 | $this->disable_styles = 'yes' == $settings['assets']['disable_css'] ? true : false; |
||
69 | } |
||
70 | |||
71 | add_action( 'init', array( $this, 'register' ), 20 ); |
||
72 | add_action( 'init', array( $this, 'enqueue' ), 40 ); |
||
73 | } |
||
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() { |
||
151 | |||
152 | /** |
||
153 | * Get widgets assets. |
||
154 | * |
||
155 | * @since 3.0.0 |
||
156 | */ |
||
157 | public function get_widgets_assets() { |
||
187 | |||
188 | /** |
||
189 | * Scripts. |
||
190 | * |
||
191 | * @since 3.0.0 |
||
192 | * |
||
193 | * @param array $scripts |
||
194 | */ |
||
195 | public function load_scripts( $scripts ) { |
||
225 | |||
226 | /** |
||
227 | * Styles. |
||
228 | * |
||
229 | * @since 3.0.0 |
||
230 | * |
||
231 | * @param array $styles |
||
232 | */ |
||
233 | public function load_styles( $styles ) { |
||
258 | } |
||
259 |