Complex classes like ALNP_Install 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 ALNP_Install, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
20 | class ALNP_Install { |
||
21 | |||
22 | /** |
||
23 | * Constructor. |
||
24 | * |
||
25 | * @since 1.0.0 |
||
26 | * @version 1.6.0 |
||
27 | * @access public |
||
28 | */ |
||
29 | public function __construct() { |
||
42 | |||
43 | /** |
||
44 | * Check plugin version and run the updater if necessary. |
||
45 | * |
||
46 | * This check is done on all requests and runs if the versions do not match. |
||
47 | * |
||
48 | * @access public |
||
49 | * @static |
||
50 | * @since 1.4.10 |
||
51 | * @version 1.6.0 |
||
52 | */ |
||
53 | public static function check_version() { |
||
64 | |||
65 | /** |
||
66 | * Install Auto Load Next Post. |
||
67 | * |
||
68 | * @access public |
||
69 | * @static |
||
70 | * @since 1.0.0 |
||
71 | * @version 1.6.0 |
||
72 | */ |
||
73 | public static function install() { |
||
114 | |||
115 | /** |
||
116 | * Set theme selectors for the current active theme should it |
||
117 | * support Auto Load Next Post and have the theme selectors set. |
||
118 | * |
||
119 | * @access private |
||
120 | * @static |
||
121 | * @since 1.5.0 |
||
122 | */ |
||
123 | private static function set_theme_selectors() { |
||
136 | |||
137 | /** |
||
138 | * Sets Auto Load Next Post to load in the footer if the |
||
139 | * current active theme requires it and lock it so the |
||
140 | * user can not disable it should the theme not work any other way. |
||
141 | * |
||
142 | * @access private |
||
143 | * @static |
||
144 | * @since 1.5.0 |
||
145 | * @version 1.5.3 |
||
146 | */ |
||
147 | private static function set_js_in_footer() { |
||
156 | |||
157 | /** |
||
158 | * Sets the template directory for the current active theme should it |
||
159 | * support Auto Load Next Post and have the template directory specified. |
||
160 | * |
||
161 | * @access private |
||
162 | * @static |
||
163 | * @since 1.6.0 |
||
164 | */ |
||
165 | private static function set_template_directory() { |
||
172 | |||
173 | /** |
||
174 | * Update plugin version to current. |
||
175 | * |
||
176 | * @access private |
||
177 | * @static |
||
178 | */ |
||
179 | private static function update_version() { |
||
182 | |||
183 | /** |
||
184 | * Set the time the plugin was installed. |
||
185 | * |
||
186 | * @access public |
||
187 | * @static |
||
188 | * @since 1.4.4 |
||
189 | * @version 1.5.0 |
||
190 | */ |
||
191 | public static function set_install_date() { |
||
201 | |||
202 | /** |
||
203 | * Default Options |
||
204 | * |
||
205 | * Sets up the default options defined on the settings pages. |
||
206 | * |
||
207 | * @access public |
||
208 | * @static |
||
209 | * @since 1.0.0 |
||
210 | * @version 1.5.1 |
||
211 | */ |
||
212 | public static function create_options() { |
||
227 | |||
228 | /** |
||
229 | * Add rewrite endpoint for Auto Load Next Post. |
||
230 | * |
||
231 | * @access public |
||
232 | * @static |
||
233 | * @since 1.0.0 |
||
234 | * @version 1.5.0 |
||
235 | */ |
||
236 | public static function add_rewrite_endpoint() { |
||
239 | |||
240 | /** |
||
241 | * Flush rewrite rules. |
||
242 | * |
||
243 | * @access public |
||
244 | * @static |
||
245 | * @since 1.5.0 |
||
246 | */ |
||
247 | public static function flush_rewrite_rules() { |
||
250 | |||
251 | /** |
||
252 | * Resets all Auto Load Next Post settings. |
||
253 | * |
||
254 | * @access public |
||
255 | * @static |
||
256 | * @since 1.5.11 |
||
257 | * @version 1.6.0 |
||
258 | * @global object $wpdb |
||
259 | */ |
||
260 | public static function reset_alnp() { |
||
293 | |||
294 | /** |
||
295 | * Redirects to the Getting Started page upon plugin activation. |
||
296 | * |
||
297 | * @access public |
||
298 | * @static |
||
299 | * @since 1.6.0 |
||
300 | * @param string $plugin The activate plugin name. |
||
301 | */ |
||
302 | public static function redirect_getting_started( $plugin ) { |
||
334 | } // END class. |
||
335 | |||
339 |