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() { |
||
| 174 | |||
| 175 | /** |
||
| 176 | * Register the fields in the advanced_section |
||
| 177 | * @codeCoverageIgnore |
||
| 178 | */ |
||
| 179 | public function advanced_section() { |
||
| 193 | |||
| 194 | /** |
||
| 195 | * Shows the select-form-field 'blog_language' |
||
| 196 | */ |
||
| 197 | public function blog_language() { |
||
| 204 | |||
| 205 | /** |
||
| 206 | * Shows the select-form-field 'admin_language' |
||
| 207 | */ |
||
| 208 | public function admin_language() { |
||
| 216 | |||
| 217 | /** |
||
| 218 | * Shows the select-form-field 'display' |
||
| 219 | */ |
||
| 220 | public function display() { |
||
| 227 | |||
| 228 | /** |
||
| 229 | * Shows the select-form-field 'reference_user' |
||
| 230 | */ |
||
| 231 | public function reference_user() { |
||
| 240 | |||
| 241 | /** |
||
| 242 | * Activate autocomplete |
||
| 243 | * |
||
| 244 | * You can decide if you want to activate the experimental autocomplete |
||
| 245 | * input fields in the backend instead of the traditional select-menus. |
||
| 246 | */ |
||
| 247 | public function activate_autocomplete() { |
||
| 250 | |||
| 251 | /** |
||
| 252 | * Show sort_by_description-field |
||
| 253 | * |
||
| 254 | * You can decide that the ouput will be sorted by the description. If not |
||
| 255 | * the output will be sorted by the language-code. |
||
| 256 | */ |
||
| 257 | public function sort_by_description() { |
||
| 260 | |||
| 261 | /** |
||
| 262 | * Exclude the current blog |
||
| 263 | * |
||
| 264 | * You can exclude a blog explicitly. All your settings will be safe but the |
||
| 265 | * plugin will ignore this blog while this option is active. |
||
| 266 | */ |
||
| 267 | public function exclude_current_blog() { |
||
| 270 | |||
| 271 | /** |
||
| 272 | * Show only a link if a translation is available |
||
| 273 | * |
||
| 274 | * Some user requested this feature. Shows only links to available |
||
| 275 | * translations. |
||
| 276 | */ |
||
| 277 | public function only_with_translation() { |
||
| 280 | |||
| 281 | /** |
||
| 282 | * Show a link to the current blog |
||
| 283 | * |
||
| 284 | * Some user requested this feature. If active the plugin will place also a |
||
| 285 | * link to the current blog. |
||
| 286 | */ |
||
| 287 | public function output_current_blog() { |
||
| 290 | |||
| 291 | /** |
||
| 292 | * Use this blog's hreflang as x-default |
||
| 293 | */ |
||
| 294 | public function x_default() { |
||
| 297 | |||
| 298 | /** |
||
| 299 | * The description for the current blog |
||
| 300 | * |
||
| 301 | * The language will be used ff there is no description. |
||
| 302 | */ |
||
| 303 | public function description() { |
||
| 306 | |||
| 307 | /** |
||
| 308 | * A String which will be placed before the output of the list |
||
| 309 | */ |
||
| 310 | public function before_output() { |
||
| 313 | |||
| 314 | /** |
||
| 315 | * A String which will be placed after the output of the list |
||
| 316 | */ |
||
| 317 | public function after_output() { |
||
| 320 | |||
| 321 | /** |
||
| 322 | * A String which will be placed before every item of the list |
||
| 323 | */ |
||
| 324 | public function before_item() { |
||
| 327 | |||
| 328 | /** |
||
| 329 | * A String which will be placed after every item of the list |
||
| 330 | */ |
||
| 331 | public function after_item() { |
||
| 334 | |||
| 335 | /** |
||
| 336 | * The output can be placed after the_content |
||
| 337 | */ |
||
| 338 | public function content_filter() { |
||
| 341 | |||
| 342 | /** |
||
| 343 | * If the output in the_content is active you can set the priority too |
||
| 344 | * |
||
| 345 | * Default is 10. But may be there are other plugins active and you run into |
||
| 346 | * trouble. So you can decide a higher (from 1) or a lower (to 100) priority |
||
| 347 | * for the output |
||
| 348 | */ |
||
| 349 | public function content_priority() { |
||
| 357 | |||
| 358 | /** |
||
| 359 | * A String which will be placed after the output of the list |
||
| 360 | */ |
||
| 361 | public function blog_slug() { |
||
| 371 | |||
| 372 | /** |
||
| 373 | * Alternative image-url |
||
| 374 | * @todo This is a value of a directory-url which should be more clear |
||
| 375 | */ |
||
| 376 | public function image_url() { |
||
| 379 | |||
| 380 | /** |
||
| 381 | * Render form-element (checkbox) |
||
| 382 | * @param string $key Name and ID of the form-element |
||
| 383 | * @return string |
||
| 384 | */ |
||
| 385 | public function render_checkbox( $key ) { |
||
| 392 | |||
| 393 | /** |
||
| 394 | * Render form-element (text-input) |
||
| 395 | * @param string $key Name and ID of the form-element |
||
| 396 | * @param string $size Size-attribute of the input-field |
||
| 397 | * @return string |
||
| 398 | */ |
||
| 399 | public function render_input( $key, $size = '30' ) { |
||
| 407 | |||
| 408 | /** |
||
| 409 | * Render form-element (select) |
||
| 410 | * @uses selected |
||
| 411 | * @param string $key Name and ID of the form-element |
||
| 412 | * @param array $arr Options as associative array |
||
| 413 | * @param string $selected Values which should be selected |
||
| 414 | * @return string |
||
| 415 | */ |
||
| 416 | public function render_select( $key, array $arr, $selected = '' ) { |
||
| 434 | |||
| 435 | /** |
||
| 436 | * Validates input before saving it |
||
| 437 | * @param array $arr Values of the submitted form |
||
| 438 | * @return array Validated input |
||
| 439 | */ |
||
| 440 | public function validate( array $arr ) { |
||
| 459 | |||
| 460 | /** |
||
| 461 | * Filter which sets the global blog language |
||
| 462 | * @param array $arr |
||
| 463 | * @return array |
||
| 464 | */ |
||
| 465 | public function set_blog_language( array $arr ) { |
||
| 473 | |||
| 474 | } |
||
| 475 |