Complex classes like MslsAdmin 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 MslsAdmin, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
12 | class MslsAdmin extends MslsMain { |
||
13 | |||
14 | /** |
||
15 | * Init |
||
16 | * @return MslsAdmin |
||
17 | */ |
||
18 | public static function init() { |
||
33 | |||
34 | /** |
||
35 | * There is something wrong? Here comes the message... |
||
36 | * @return bool |
||
37 | */ |
||
38 | public function has_problems() { |
||
58 | |||
59 | /** |
||
60 | * Render the options-page |
||
61 | * @codeCoverageIgnore |
||
62 | */ |
||
63 | public function render() { |
||
79 | |||
80 | /** |
||
81 | * Create a submenu which contains links to all blogs of the current user |
||
82 | * @return string |
||
83 | */ |
||
84 | public function subsubsub() { |
||
107 | |||
108 | /** |
||
109 | * Register the form-elements |
||
110 | * @codeCoverageIgnore |
||
111 | */ |
||
112 | public function register() { |
||
126 | |||
127 | /** |
||
128 | * Register the fields in the language_section |
||
129 | * @codeCoverageIgnore |
||
130 | */ |
||
131 | public function language_section() { |
||
143 | |||
144 | /** |
||
145 | * Register the fields in the main_section |
||
146 | * @codeCoverageIgnore |
||
147 | */ |
||
148 | public function main_section() { |
||
170 | |||
171 | /** |
||
172 | * Register the fields in the advanced_section |
||
173 | * @codeCoverageIgnore |
||
174 | */ |
||
175 | public function advanced_section() { |
||
189 | |||
190 | /** |
||
191 | * Shows the select-form-field 'blog_language' |
||
192 | */ |
||
193 | public function blog_language() { |
||
200 | |||
201 | /** |
||
202 | * Shows the select-form-field 'admin_language' |
||
203 | */ |
||
204 | public function admin_language() { |
||
212 | |||
213 | /** |
||
214 | * Shows the select-form-field 'display' |
||
215 | */ |
||
216 | public function display() { |
||
223 | |||
224 | /** |
||
225 | * Shows the select-form-field 'reference_user' |
||
226 | */ |
||
227 | public function reference_user() { |
||
236 | |||
237 | /** |
||
238 | * Activate autocomplete |
||
239 | * |
||
240 | * You can decide if you want to activate the experimental autocomplete |
||
241 | * input fields in the backend instead of the traditional select-menus. |
||
242 | */ |
||
243 | public function activate_autocomplete() { |
||
246 | |||
247 | /** |
||
248 | * Show sort_by_description-field |
||
249 | * |
||
250 | * You can decide that the ouput will be sorted by the description. If not |
||
251 | * the output will be sorted by the language-code. |
||
252 | */ |
||
253 | public function sort_by_description() { |
||
256 | |||
257 | /** |
||
258 | * Exclude the current blog |
||
259 | * |
||
260 | * You can exclude a blog explicitly. All your settings will be safe but the |
||
261 | * plugin will ignore this blog while this option is active. |
||
262 | */ |
||
263 | public function exclude_current_blog() { |
||
266 | |||
267 | /** |
||
268 | * Show only a link if a translation is available |
||
269 | * |
||
270 | * Some user requested this feature. Shows only links to available |
||
271 | * translations. |
||
272 | */ |
||
273 | public function only_with_translation() { |
||
276 | |||
277 | /** |
||
278 | * Show a link to the current blog |
||
279 | * |
||
280 | * Some user requested this feature. If active the plugin will place also a |
||
281 | * link to the current blog. |
||
282 | */ |
||
283 | public function output_current_blog() { |
||
286 | |||
287 | /** |
||
288 | * Use this blog's hreflang as x-default |
||
289 | */ |
||
290 | public function x_default() { |
||
293 | |||
294 | /** |
||
295 | * The description for the current blog |
||
296 | * |
||
297 | * The language will be used ff there is no description. |
||
298 | */ |
||
299 | public function description() { |
||
302 | |||
303 | /** |
||
304 | * A String which will be placed before the output of the list |
||
305 | */ |
||
306 | public function before_output() { |
||
309 | |||
310 | /** |
||
311 | * A String which will be placed after the output of the list |
||
312 | */ |
||
313 | public function after_output() { |
||
316 | |||
317 | /** |
||
318 | * A String which will be placed before every item of the list |
||
319 | */ |
||
320 | public function before_item() { |
||
323 | |||
324 | /** |
||
325 | * A String which will be placed after every item of the list |
||
326 | */ |
||
327 | public function after_item() { |
||
330 | |||
331 | /** |
||
332 | * The output can be placed after the_content |
||
333 | */ |
||
334 | public function content_filter() { |
||
337 | |||
338 | /** |
||
339 | * If the output in the_content is active you can set the priority too |
||
340 | * |
||
341 | * Default is 10. But may be there are other plugins active and you run into |
||
342 | * trouble. So you can decide a higher (from 1) or a lower (to 100) priority |
||
343 | * for the output |
||
344 | */ |
||
345 | public function content_priority() { |
||
353 | |||
354 | /** |
||
355 | * Alternative image-url |
||
356 | * @todo This is a value of a directory-url which should be more clear |
||
357 | */ |
||
358 | public function image_url() { |
||
361 | |||
362 | /** |
||
363 | * Render form-element (checkbox) |
||
364 | * @param string $key Name and ID of the form-element |
||
365 | * @return string |
||
366 | */ |
||
367 | public function render_checkbox( $key ) { |
||
374 | |||
375 | /** |
||
376 | * Render form-element (text-input) |
||
377 | * @param string $key Name and ID of the form-element |
||
378 | * @param string $size Size-attribute of the input-field |
||
379 | * @return string |
||
380 | */ |
||
381 | public function render_input( $key, $size = '30' ) { |
||
389 | |||
390 | /** |
||
391 | * Render form-element (select) |
||
392 | * @uses selected |
||
393 | * @param string $key Name and ID of the form-element |
||
394 | * @param array $arr Options as associative array |
||
395 | * @param string $selected Values which should be selected |
||
396 | * @return string |
||
397 | */ |
||
398 | public function render_select( $key, array $arr, $selected = '' ) { |
||
416 | |||
417 | /** |
||
418 | * Validates input before saving it |
||
419 | * @param array $arr Values of the submitted form |
||
420 | * @return array Validated input |
||
421 | */ |
||
422 | public function validate( array $arr ) { |
||
439 | |||
440 | /** |
||
441 | * Filter which sets the global blog language |
||
442 | * @param array $arr |
||
443 | * @return array |
||
444 | */ |
||
445 | public function set_blog_language( array $arr ) { |
||
453 | |||
454 | } |
||
455 |