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 |
||
15 | class MslsPlugin { |
||
16 | |||
17 | /** |
||
18 | * @var MslsOptions |
||
19 | */ |
||
20 | protected $options; |
||
21 | |||
22 | /** |
||
23 | * @param MslsOptions $options |
||
24 | */ |
||
25 | public function __construct( MslsOptions $options ) { |
||
28 | |||
29 | /** |
||
30 | * Factory |
||
31 | * |
||
32 | * @codeCoverageIgnore |
||
33 | * |
||
34 | * @return MslsPlugin |
||
35 | */ |
||
36 | public static function init() { |
||
88 | |||
89 | /** |
||
90 | * @return MslsOutput |
||
91 | */ |
||
92 | public function get_output() { |
||
101 | |||
102 | /** |
||
103 | * Filter for the_content() |
||
104 | * |
||
105 | * @package Msls |
||
106 | * @uses MslsOptions |
||
107 | * @param string $content |
||
108 | * @return string |
||
109 | */ |
||
110 | function content_filter( $content ) { |
||
121 | |||
122 | /** |
||
123 | * Create filterstring for msls_content_filter() |
||
124 | * |
||
125 | * @package Msls |
||
126 | * @uses MslsOutput |
||
127 | * @param string $pref |
||
128 | * @param string $post |
||
129 | * @return string |
||
130 | */ |
||
131 | function filter_string( $pref = '<p id="msls">', $post = '</p>' ) { |
||
169 | |||
170 | /** |
||
171 | * Loads styles and some js if needed |
||
172 | * |
||
173 | * The methiod returns true if JS is loaded or false if not |
||
174 | * |
||
175 | * @return boolean |
||
176 | */ |
||
177 | public function admin_menu() { |
||
200 | |||
201 | /** |
||
202 | * Register widget |
||
203 | * |
||
204 | * The widget will only be registered if the current blog is not |
||
205 | * excluded in the configuration of the plugin. |
||
206 | * @return boolean |
||
207 | */ |
||
208 | public function init_widget() { |
||
217 | |||
218 | /** |
||
219 | * Load textdomain |
||
220 | * |
||
221 | * The method should be executed always on init because we have some |
||
222 | * translatable string in the frontend too. |
||
223 | * |
||
224 | * @return boolean |
||
225 | */ |
||
226 | public function init_i18n_support() { |
||
233 | |||
234 | /** |
||
235 | * Message handler |
||
236 | * |
||
237 | * Prints a message box to the screen. |
||
238 | * @param string $message |
||
239 | * @param string $css_class |
||
240 | * @return boolean |
||
241 | */ |
||
242 | public static function message_handler( $message, $css_class = 'error' ) { |
||
254 | |||
255 | /** |
||
256 | * Activate plugin |
||
257 | */ |
||
258 | public function activate(){ |
||
261 | |||
262 | /** |
||
263 | * Uninstall plugin |
||
264 | * |
||
265 | * The plugin data in all blogs of the current network will be |
||
266 | * deleted after the uninstall procedure. |
||
267 | * |
||
268 | * @return boolean |
||
269 | */ |
||
270 | public function uninstall() { |
||
296 | |||
297 | /** |
||
298 | * Cleanup the options |
||
299 | * |
||
300 | * Removes all values of the current blogs which are stored in the |
||
301 | * options-table and returns true if it was successful. |
||
302 | * |
||
303 | * @return boolean |
||
304 | */ |
||
305 | public static function cleanup() { |
||
318 | |||
319 | /** |
||
320 | * Get specific vars from $_POST and $_GET in a safe way |
||
321 | * @param array $list |
||
322 | * @return array |
||
323 | */ |
||
324 | public static function get_superglobals( array $list ) { |
||
340 | |||
341 | } |
||
342 |