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 | * @var MslsOptions $options |
||
| 16 | */ |
||
| 17 | protected $options; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * MslsAdmin constructor. |
||
| 21 | */ |
||
| 22 | public function __construct() { |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Init |
||
| 28 | * @return MslsAdmin |
||
| 29 | */ |
||
| 30 | public static function init() { |
||
| 45 | |||
| 46 | /** |
||
| 47 | * You can use every method of the decorated object |
||
| 48 | * |
||
| 49 | * @param string $method |
||
| 50 | * @param mixed $args |
||
| 51 | * |
||
| 52 | * @return mixed |
||
| 53 | */ |
||
| 54 | public function __call( $method, $args ) { |
||
| 67 | |||
| 68 | /** |
||
| 69 | * There is something wrong? Here comes the message... |
||
| 70 | * @return bool |
||
| 71 | */ |
||
| 72 | public function has_problems() { |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Render the options-page |
||
| 94 | * @codeCoverageIgnore |
||
| 95 | */ |
||
| 96 | public function render() { |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Create a submenu which contains links to all blogs of the current user |
||
| 115 | * @return string |
||
| 116 | */ |
||
| 117 | public function subsubsub() { |
||
| 140 | |||
| 141 | /** |
||
| 142 | * Register the form-elements |
||
| 143 | * @codeCoverageIgnore |
||
| 144 | */ |
||
| 145 | public function register() { |
||
| 177 | |||
| 178 | /** |
||
| 179 | * Register the fields in the language_section |
||
| 180 | * @codeCoverageIgnore |
||
| 181 | */ |
||
| 182 | public function language_section() { |
||
| 201 | |||
| 202 | /** |
||
| 203 | * Register the fields in the main_section |
||
| 204 | * @codeCoverageIgnore |
||
| 205 | */ |
||
| 206 | public function main_section() { |
||
| 261 | |||
| 262 | /** |
||
| 263 | * Register the fields in the advanced_section |
||
| 264 | * @codeCoverageIgnore |
||
| 265 | */ |
||
| 266 | public function advanced_section() { |
||
| 293 | |||
| 294 | /** |
||
| 295 | * Register the fields in the rewrites_section |
||
| 296 | * @since 1.1 |
||
| 297 | * @codeCoverageIgnore |
||
| 298 | */ |
||
| 299 | public function rewrites_section() { |
||
| 313 | |||
| 314 | /** |
||
| 315 | * Shows the select-form-field 'blog_language' |
||
| 316 | */ |
||
| 317 | public function blog_language() { |
||
| 324 | |||
| 325 | /** |
||
| 326 | * Shows the select-form-field 'admin_language' |
||
| 327 | */ |
||
| 328 | public function admin_language() { |
||
| 336 | |||
| 337 | /** |
||
| 338 | * Shows the select-form-field 'display' |
||
| 339 | */ |
||
| 340 | public function display() { |
||
| 347 | |||
| 348 | /** |
||
| 349 | * Shows the select-form-field 'reference_user' |
||
| 350 | */ |
||
| 351 | public function reference_user() { |
||
| 360 | |||
| 361 | /** |
||
| 362 | render |
||
| 363 | * |
||
| 364 | * You can decide if you want to activate the experimental autocomplete |
||
| 365 | * input fields in the backend instead of the traditional select-menus. |
||
| 366 | */ |
||
| 367 | public function activate_autocomplete() { |
||
| 370 | |||
| 371 | /** |
||
| 372 | * Show sort_by_description-field |
||
| 373 | * |
||
| 374 | * You can decide that the ouput will be sorted by the description. If not |
||
| 375 | * the output will be sorted by the language-code. |
||
| 376 | */ |
||
| 377 | public function sort_by_description() { |
||
| 380 | |||
| 381 | /** |
||
| 382 | * Exclude the current blog |
||
| 383 | * |
||
| 384 | * You can exclude a blog explicitly. All your settings will be safe but the |
||
| 385 | * plugin will ignore this blog while this option is active. |
||
| 386 | */ |
||
| 387 | public function exclude_current_blog() { |
||
| 390 | |||
| 391 | /** |
||
| 392 | * Show only a link if a translation is available |
||
| 393 | * |
||
| 394 | * Some user requested this feature. Shows only links to available |
||
| 395 | * translations. |
||
| 396 | */ |
||
| 397 | public function only_with_translation() { |
||
| 400 | |||
| 401 | /** |
||
| 402 | * Show a link to the current blog |
||
| 403 | * |
||
| 404 | * Some user requested this feature. If active the plugin will place also a |
||
| 405 | * link to the current blog. |
||
| 406 | */ |
||
| 407 | public function output_current_blog() { |
||
| 410 | |||
| 411 | /** |
||
| 412 | * The description for the current blog |
||
| 413 | * |
||
| 414 | * The language will be used ff there is no description. |
||
| 415 | */ |
||
| 416 | public function description() { |
||
| 419 | |||
| 420 | /** |
||
| 421 | * The output can be placed after the_content |
||
| 422 | */ |
||
| 423 | public function content_filter() { |
||
| 426 | |||
| 427 | /** |
||
| 428 | * If the output in the_content is active you can set the priority too |
||
| 429 | * |
||
| 430 | * Default is 10. But may be there are other plugins active and you run into |
||
| 431 | * trouble. So you can decide a higher (from 1) or a lower (to 100) priority |
||
| 432 | * for the output |
||
| 433 | */ |
||
| 434 | public function content_priority() { |
||
| 445 | |||
| 446 | /** |
||
| 447 | * Rewrites slugs for registered post types |
||
| 448 | * |
||
| 449 | * @param string $key |
||
| 450 | */ |
||
| 451 | public function render_rewrite( $key ) { |
||
| 464 | |||
| 465 | /** |
||
| 466 | * Render form-element (checkbox) |
||
| 467 | * |
||
| 468 | * @param string $key Name and ID of the form-element |
||
| 469 | * |
||
| 470 | * @return string |
||
| 471 | */ |
||
| 472 | public function render_checkbox( $key ) { |
||
| 479 | |||
| 480 | /** |
||
| 481 | * Render form-element (text-input) |
||
| 482 | * |
||
| 483 | * @param string $key Name and ID of the form-element |
||
| 484 | * @param string $size Size-attribute of the input-field |
||
| 485 | * @param string $default |
||
| 486 | * @param bool $readonly |
||
| 487 | * |
||
| 488 | * @return string |
||
| 489 | */ |
||
| 490 | public function render_input( $key, $size = '30', $default = '', $readonly = false ) { |
||
| 499 | |||
| 500 | /** |
||
| 501 | * Render form-element (select) |
||
| 502 | * @uses selected |
||
| 503 | * |
||
| 504 | * @param string $key Name and ID of the form-element |
||
| 505 | * @param array $arr Options as associative array |
||
| 506 | * @param string $selected Values which should be selected |
||
| 507 | * |
||
| 508 | * @return string |
||
| 509 | */ |
||
| 510 | public function render_select( $key, array $arr, $selected = '' ) { |
||
| 528 | |||
| 529 | /** |
||
| 530 | * Validates input before saving it |
||
| 531 | * |
||
| 532 | * @param array $arr Values of the submitted form |
||
| 533 | * |
||
| 534 | * @return array Validated input |
||
| 535 | */ |
||
| 536 | public function validate( array $arr ) { |
||
| 557 | |||
| 558 | /** |
||
| 559 | * Filter which sets the global blog language |
||
| 560 | * |
||
| 561 | * @param array $arr |
||
| 562 | * |
||
| 563 | * @return array |
||
| 564 | */ |
||
| 565 | public function set_blog_language( array $arr ) { |
||
| 574 | |||
| 575 | } |
||
| 576 |