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 |
||
14 | class MslsAdmin extends MslsMain { |
||
15 | |||
16 | /** |
||
17 | * Factory |
||
18 | * |
||
19 | * @codeCoverageIgnore |
||
20 | * |
||
21 | * @return MslsAdmin |
||
22 | */ |
||
23 | public static function init() { |
||
40 | |||
41 | /** |
||
42 | * Let's do this simple |
||
43 | * |
||
44 | * @return string |
||
45 | */ |
||
46 | public function get_menu_slug() { |
||
49 | |||
50 | /** |
||
51 | * Get's the link for the switcher-settings in the wp-admin |
||
52 | * |
||
53 | * @return string |
||
54 | */ |
||
55 | public function get_options_page_link() { |
||
58 | |||
59 | /** |
||
60 | * You can use every method of the decorated object |
||
61 | * |
||
62 | * @param string $method |
||
63 | * @param mixed $args |
||
64 | * |
||
65 | * @return mixed |
||
66 | */ |
||
67 | public function __call( $method, $args ) { |
||
80 | |||
81 | /** |
||
82 | * There is something wrong? Here comes the message... |
||
83 | * @return bool |
||
84 | */ |
||
85 | public function has_problems() { |
||
103 | |||
104 | /** |
||
105 | * Render the options-page |
||
106 | * @codeCoverageIgnore |
||
107 | */ |
||
108 | public function render() { |
||
124 | |||
125 | |||
126 | /** |
||
127 | * Create a submenu which contains links to all blogs of the current user |
||
128 | * @return string |
||
129 | */ |
||
130 | public function subsubsub() { |
||
152 | |||
153 | /** |
||
154 | * Register the form-elements |
||
155 | * @codeCoverageIgnore |
||
156 | */ |
||
157 | public function register() { |
||
189 | |||
190 | /** |
||
191 | * Register the fields in the language_section |
||
192 | * @codeCoverageIgnore |
||
193 | */ |
||
194 | public function language_section() { |
||
209 | |||
210 | /** |
||
211 | * Register the fields in the main_section |
||
212 | * @codeCoverageIgnore |
||
213 | */ |
||
214 | public function main_section() { |
||
269 | |||
270 | /** |
||
271 | * Register the fields in the advanced_section |
||
272 | * @codeCoverageIgnore |
||
273 | */ |
||
274 | public function advanced_section() { |
||
301 | |||
302 | /** |
||
303 | * Register the fields in the rewrites_section |
||
304 | * @since 1.1 |
||
305 | * @codeCoverageIgnore |
||
306 | */ |
||
307 | public function rewrites_section() { |
||
321 | |||
322 | /** |
||
323 | * Shows the select-form-field 'blog_language' |
||
324 | */ |
||
325 | public function blog_language() { |
||
332 | |||
333 | /** |
||
334 | * Shows the select-form-field 'display' |
||
335 | */ |
||
336 | public function display() { |
||
343 | |||
344 | /** |
||
345 | * Shows the select-form-field 'reference_user' |
||
346 | */ |
||
347 | public function reference_user() { |
||
356 | |||
357 | /** |
||
358 | * render |
||
359 | * |
||
360 | * You can decide if you want to activate the experimental autocomplete |
||
361 | * input fields in the backend instead of the traditional select-menus. |
||
362 | */ |
||
363 | public function activate_autocomplete() { |
||
366 | |||
367 | /** |
||
368 | * Show sort_by_description-field |
||
369 | * |
||
370 | * You can decide that the ouput will be sorted by the description. If not |
||
371 | * the output will be sorted by the language-code. |
||
372 | */ |
||
373 | public function sort_by_description() { |
||
376 | |||
377 | /** |
||
378 | * Exclude the current blog |
||
379 | * |
||
380 | * You can exclude a blog explicitly. All your settings will be safe but the |
||
381 | * plugin will ignore this blog while this option is active. |
||
382 | */ |
||
383 | public function exclude_current_blog() { |
||
386 | |||
387 | /** |
||
388 | * Show only a link if a translation is available |
||
389 | * |
||
390 | * Some user requested this feature. Shows only links to available |
||
391 | * translations. |
||
392 | */ |
||
393 | public function only_with_translation() { |
||
396 | |||
397 | /** |
||
398 | * Show a link to the current blog |
||
399 | * |
||
400 | * Some user requested this feature. If active the plugin will place also a |
||
401 | * link to the current blog. |
||
402 | */ |
||
403 | public function output_current_blog() { |
||
406 | |||
407 | /** |
||
408 | * The description for the current blog |
||
409 | * |
||
410 | * The language will be used ff there is no description. |
||
411 | */ |
||
412 | public function description() { |
||
415 | |||
416 | /** |
||
417 | * The output can be placed after the_content |
||
418 | */ |
||
419 | public function content_filter() { |
||
422 | |||
423 | /** |
||
424 | * If the output in the_content is active you can set the priority too |
||
425 | * |
||
426 | * Default is 10. But may be there are other plugins active and you run into |
||
427 | * trouble. So you can decide a higher (from 1) or a lower (to 100) priority |
||
428 | * for the output |
||
429 | */ |
||
430 | public function content_priority() { |
||
441 | |||
442 | /** |
||
443 | * Rewrites slugs for registered post types |
||
444 | * |
||
445 | * @param string $key |
||
446 | */ |
||
447 | public function render_rewrite( $key ) { |
||
459 | |||
460 | /** |
||
461 | * Render form-element (checkbox) |
||
462 | * |
||
463 | * @param string $key Name and ID of the form-element |
||
464 | * |
||
465 | * @return string |
||
466 | */ |
||
467 | public function render_checkbox( $key ) { |
||
474 | |||
475 | /** |
||
476 | * Render form-element (text-input) |
||
477 | * |
||
478 | * @param string $key Name and ID of the form-element |
||
479 | * @param string $size Size-attribute of the input-field |
||
480 | * @param string $default |
||
481 | * @param bool $readonly |
||
482 | * |
||
483 | * @return string |
||
484 | */ |
||
485 | public function render_input( $key, $size = '30', $default = '', $readonly = false ) { |
||
494 | |||
495 | /** |
||
496 | * Render form-element (select) |
||
497 | * @uses selected |
||
498 | * |
||
499 | * @param string $key Name and ID of the form-element |
||
500 | * @param array $arr Options as associative array |
||
501 | * @param string $selected Values which should be selected |
||
502 | * |
||
503 | * @return string |
||
504 | */ |
||
505 | public function render_select( $key, array $arr, $selected = '' ) { |
||
523 | |||
524 | /** |
||
525 | * Validates input before saving it |
||
526 | * |
||
527 | * @param array $arr Values of the submitted form |
||
528 | * |
||
529 | * @return array Validated input |
||
530 | */ |
||
531 | public function validate( array $arr ) { |
||
552 | |||
553 | /** |
||
554 | * Filter which sets the global blog language |
||
555 | * |
||
556 | * @param array $arr |
||
557 | * |
||
558 | * @return array |
||
559 | */ |
||
560 | public function set_blog_language( array $arr ) { |
||
569 | |||
570 | } |
||
571 |
The break statement is not necessary if it is preceded for example by a return statement:
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.