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() { |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Let's do this simple |
||
| 56 | * |
||
| 57 | * @return string |
||
| 58 | */ |
||
| 59 | public function get_menu_slug() { |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Get's the link for the switcher-settings in the wp-admin |
||
| 65 | * |
||
| 66 | * @return string |
||
| 67 | */ |
||
| 68 | public function get_options_page_link() { |
||
| 71 | |||
| 72 | /** |
||
| 73 | * You can use every method of the decorated object |
||
| 74 | * |
||
| 75 | * @param string $method |
||
| 76 | * @param mixed $args |
||
| 77 | * |
||
| 78 | * @return mixed |
||
| 79 | */ |
||
| 80 | public function __call( $method, $args ) { |
||
| 93 | |||
| 94 | /** |
||
| 95 | * There is something wrong? Here comes the message... |
||
| 96 | * @return bool |
||
| 97 | */ |
||
| 98 | public function has_problems() { |
||
| 116 | |||
| 117 | /** |
||
| 118 | * Render the options-page |
||
| 119 | * @codeCoverageIgnore |
||
| 120 | */ |
||
| 121 | public function render() { |
||
| 137 | |||
| 138 | |||
| 139 | /** |
||
| 140 | * Create a submenu which contains links to all blogs of the current user |
||
| 141 | * @return string |
||
| 142 | */ |
||
| 143 | public function subsubsub() { |
||
| 165 | |||
| 166 | /** |
||
| 167 | * Register the form-elements |
||
| 168 | * @codeCoverageIgnore |
||
| 169 | */ |
||
| 170 | public function register() { |
||
| 202 | |||
| 203 | /** |
||
| 204 | * Register the fields in the language_section |
||
| 205 | * @codeCoverageIgnore |
||
| 206 | */ |
||
| 207 | public function language_section() { |
||
| 222 | |||
| 223 | /** |
||
| 224 | * Register the fields in the main_section |
||
| 225 | * @codeCoverageIgnore |
||
| 226 | */ |
||
| 227 | public function main_section() { |
||
| 282 | |||
| 283 | /** |
||
| 284 | * Register the fields in the advanced_section |
||
| 285 | * @codeCoverageIgnore |
||
| 286 | */ |
||
| 287 | public function advanced_section() { |
||
| 318 | |||
| 319 | /** |
||
| 320 | * Register the fields in the rewrites_section |
||
| 321 | * @since 1.1 |
||
| 322 | * @codeCoverageIgnore |
||
| 323 | */ |
||
| 324 | public function rewrites_section() { |
||
| 338 | |||
| 339 | /** |
||
| 340 | * Shows the select-form-field 'blog_language' |
||
| 341 | */ |
||
| 342 | public function blog_language() { |
||
| 349 | |||
| 350 | /** |
||
| 351 | * Shows the select-form-field 'display' |
||
| 352 | */ |
||
| 353 | public function display() { |
||
| 360 | |||
| 361 | /** |
||
| 362 | * Shows the select-form-field 'reference_user' |
||
| 363 | */ |
||
| 364 | public function reference_user() { |
||
| 373 | |||
| 374 | /** |
||
| 375 | * render |
||
| 376 | * |
||
| 377 | * You can decide if you want to activate the experimental autocomplete |
||
| 378 | * input fields in the backend instead of the traditional select-menus. |
||
| 379 | */ |
||
| 380 | public function activate_autocomplete() { |
||
| 383 | |||
| 384 | /** |
||
| 385 | * render |
||
| 386 | * |
||
| 387 | * You can decide if you want to activate the content import functionality |
||
| 388 | * in the backend instead of the traditional select-menus. |
||
| 389 | */ |
||
| 390 | public function activate_content_import() { |
||
| 393 | |||
| 394 | /** |
||
| 395 | * Show sort_by_description-field |
||
| 396 | * |
||
| 397 | * You can decide that the ouput will be sorted by the description. If not |
||
| 398 | * the output will be sorted by the language-code. |
||
| 399 | */ |
||
| 400 | public function sort_by_description() { |
||
| 403 | |||
| 404 | /** |
||
| 405 | * Exclude the current blog |
||
| 406 | * |
||
| 407 | * You can exclude a blog explicitly. All your settings will be safe but the |
||
| 408 | * plugin will ignore this blog while this option is active. |
||
| 409 | */ |
||
| 410 | public function exclude_current_blog() { |
||
| 413 | |||
| 414 | /** |
||
| 415 | * Show only a link if a translation is available |
||
| 416 | * |
||
| 417 | * Some user requested this feature. Shows only links to available |
||
| 418 | * translations. |
||
| 419 | */ |
||
| 420 | public function only_with_translation() { |
||
| 423 | |||
| 424 | /** |
||
| 425 | * Show a link to the current blog |
||
| 426 | * |
||
| 427 | * Some user requested this feature. If active the plugin will place also a |
||
| 428 | * link to the current blog. |
||
| 429 | */ |
||
| 430 | public function output_current_blog() { |
||
| 433 | |||
| 434 | /** |
||
| 435 | * The description for the current blog |
||
| 436 | * |
||
| 437 | * The language will be used ff there is no description. |
||
| 438 | */ |
||
| 439 | public function description() { |
||
| 442 | |||
| 443 | /** |
||
| 444 | * The output can be placed after the_content |
||
| 445 | */ |
||
| 446 | public function content_filter() { |
||
| 449 | |||
| 450 | /** |
||
| 451 | * If the output in the_content is active you can set the priority too |
||
| 452 | * |
||
| 453 | * Default is 10. But may be there are other plugins active and you run into |
||
| 454 | * trouble. So you can decide a higher (from 1) or a lower (to 100) priority |
||
| 455 | * for the output |
||
| 456 | */ |
||
| 457 | public function content_priority() { |
||
| 468 | |||
| 469 | /** |
||
| 470 | * Rewrites slugs for registered post types |
||
| 471 | * |
||
| 472 | * @param string $key |
||
| 473 | */ |
||
| 474 | public function render_rewrite( $key ) { |
||
| 486 | |||
| 487 | /** |
||
| 488 | * Render form-element (checkbox) |
||
| 489 | * |
||
| 490 | * @param string $key Name and ID of the form-element |
||
| 491 | * |
||
| 492 | * @return string |
||
| 493 | */ |
||
| 494 | public function render_checkbox( $key ) { |
||
| 501 | |||
| 502 | /** |
||
| 503 | * Render form-element (text-input) |
||
| 504 | * |
||
| 505 | * @param string $key Name and ID of the form-element |
||
| 506 | * @param string $size Size-attribute of the input-field |
||
| 507 | * @param string $default |
||
| 508 | * @param bool $readonly |
||
| 509 | * |
||
| 510 | * @return string |
||
| 511 | */ |
||
| 512 | public function render_input( $key, $size = '30', $default = '', $readonly = false ) { |
||
| 521 | |||
| 522 | /** |
||
| 523 | * Render form-element (select) |
||
| 524 | * @uses selected |
||
| 525 | * |
||
| 526 | * @param string $key Name and ID of the form-element |
||
| 527 | * @param array $arr Options as associative array |
||
| 528 | * @param string $selected Values which should be selected |
||
| 529 | * |
||
| 530 | * @return string |
||
| 531 | */ |
||
| 532 | public function render_select( $key, array $arr, $selected = '' ) { |
||
| 550 | |||
| 551 | /** |
||
| 552 | * Validates input before saving it |
||
| 553 | * |
||
| 554 | * @param array $arr Values of the submitted form |
||
| 555 | * |
||
| 556 | * @return array Validated input |
||
| 557 | */ |
||
| 558 | public function validate( array $arr ) { |
||
| 579 | |||
| 580 | /** |
||
| 581 | * Filter which sets the global blog language |
||
| 582 | * |
||
| 583 | * @param array $arr |
||
| 584 | * |
||
| 585 | * @return array |
||
| 586 | */ |
||
| 587 | public function set_blog_language( array $arr ) { |
||
| 596 | |||
| 597 | } |
||
| 598 |
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.