Complex classes like MslsPlugin 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 MslsPlugin, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
16 | class MslsPlugin { |
||
17 | |||
18 | /** |
||
19 | * @var MslsOptions |
||
20 | */ |
||
21 | protected $options; |
||
22 | |||
23 | /** |
||
24 | * @param MslsOptions $options |
||
25 | */ |
||
26 | public function __construct( MslsOptions $options ) { |
||
29 | |||
30 | /** |
||
31 | * Factory |
||
32 | * |
||
33 | * @codeCoverageIgnore |
||
34 | * |
||
35 | * @return MslsPlugin |
||
36 | */ |
||
37 | public static function init() { |
||
92 | |||
93 | /** |
||
94 | * @return MslsOutput |
||
95 | */ |
||
96 | public function get_output() { |
||
105 | |||
106 | /** |
||
107 | * Callback for action wp_head |
||
108 | */ |
||
109 | public function print_alternate_links() { |
||
112 | |||
113 | /** |
||
114 | * Filter for the_content() |
||
115 | * |
||
116 | * @package Msls |
||
117 | * @uses MslsOptions |
||
118 | * @param string $content |
||
119 | * @return string |
||
120 | */ |
||
121 | function content_filter( $content ) { |
||
132 | |||
133 | /** |
||
134 | * Create filterstring for msls_content_filter() |
||
135 | * |
||
136 | * @package Msls |
||
137 | * @uses MslsOutput |
||
138 | * @param string $pref |
||
139 | * @param string $post |
||
140 | * @return string |
||
141 | */ |
||
142 | function filter_string( $pref = '<p id="msls">', $post = '</p>' ) { |
||
180 | |||
181 | /** |
||
182 | * Loads styles and some js if needed |
||
183 | * |
||
184 | * The methiod returns true if JS is loaded or false if not |
||
185 | * |
||
186 | * @return boolean |
||
187 | */ |
||
188 | public function admin_menu() { |
||
211 | |||
212 | /** |
||
213 | * Register widget |
||
214 | * |
||
215 | * The widget will only be registered if the current blog is not |
||
216 | * excluded in the configuration of the plugin. |
||
217 | * @return boolean |
||
218 | */ |
||
219 | public function init_widget() { |
||
228 | |||
229 | /** |
||
230 | * Load textdomain |
||
231 | * |
||
232 | * The method should be executed always on init because we have some |
||
233 | * translatable string in the frontend too. |
||
234 | * |
||
235 | * @return boolean |
||
236 | */ |
||
237 | public function init_i18n_support() { |
||
244 | |||
245 | /** |
||
246 | * Message handler |
||
247 | * |
||
248 | * Prints a message box to the screen. |
||
249 | * @param string $message |
||
250 | * @param string $css_class |
||
251 | * @return boolean |
||
252 | */ |
||
253 | public static function message_handler( $message, $css_class = 'error' ) { |
||
266 | |||
267 | /** |
||
268 | * Activate plugin |
||
269 | */ |
||
270 | public static function activate(){ |
||
273 | |||
274 | /** |
||
275 | * Uninstall plugin |
||
276 | * |
||
277 | * The plugin data in all blogs of the current network will be |
||
278 | * deleted after the uninstall procedure. |
||
279 | * |
||
280 | * @return boolean |
||
281 | */ |
||
282 | public static function uninstall() { |
||
308 | |||
309 | /** |
||
310 | * Cleanup the options |
||
311 | * |
||
312 | * Removes all values of the current blogs which are stored in the |
||
313 | * options-table and returns true if it was successful. |
||
314 | * |
||
315 | * @return boolean |
||
316 | */ |
||
317 | public static function cleanup() { |
||
330 | |||
331 | /** |
||
332 | * Get specific vars from $_POST and $_GET in a safe way |
||
333 | * @param array $list |
||
334 | * @return array |
||
335 | */ |
||
336 | public static function get_superglobals( array $list ) { |
||
352 | |||
353 | } |
||
354 |