Complex classes like MslsOptions 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 MslsOptions, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 26 | class MslsOptions extends MslsGetSet { |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Args |
||
| 30 | * @var array |
||
| 31 | */ |
||
| 32 | protected $args; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Name |
||
| 36 | * @var string |
||
| 37 | */ |
||
| 38 | protected $name; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Exists |
||
| 42 | * @var bool |
||
| 43 | */ |
||
| 44 | protected $exists = false; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Separator |
||
| 48 | * @var string |
||
| 49 | */ |
||
| 50 | protected $sep = ''; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Autoload |
||
| 54 | * @var string |
||
| 55 | */ |
||
| 56 | protected $autoload = 'yes'; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Available languages |
||
| 60 | * @var array |
||
| 61 | */ |
||
| 62 | private $available_languages; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Rewrite with front |
||
| 66 | * @var bool |
||
| 67 | */ |
||
| 68 | public $with_front; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Factory method |
||
| 72 | * |
||
| 73 | * @codeCoverageIgnore |
||
| 74 | * |
||
| 75 | * @param int $id |
||
| 76 | * |
||
| 77 | * @return MslsOptions |
||
| 78 | */ |
||
| 79 | public static function create( $id = 0 ) { |
||
| 104 | |||
| 105 | /** |
||
| 106 | * Checks if the current page is a home, front or 404 page |
||
| 107 | * @return boolean |
||
| 108 | */ |
||
| 109 | public static function is_main_page() { |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Checks if the current page is a category, tag or any other tax archive |
||
| 115 | * @return boolean |
||
| 116 | */ |
||
| 117 | public static function is_tax_page() { |
||
| 120 | |||
| 121 | /** |
||
| 122 | * Checks if the current page is a date, author any other post_type archive |
||
| 123 | * @return boolean |
||
| 124 | */ |
||
| 125 | public static function is_query_page() { |
||
| 128 | |||
| 129 | /** |
||
| 130 | * Constructor |
||
| 131 | */ |
||
| 132 | public function __construct() { |
||
| 137 | |||
| 138 | /** |
||
| 139 | * Gets an element of arg by index |
||
| 140 | * The returning value is casted to the type of $retval or will be the |
||
| 141 | * value of $retval if nothing is set at this index. |
||
| 142 | * |
||
| 143 | * @param int $idx |
||
| 144 | * @param mixed $val |
||
| 145 | * |
||
| 146 | * @return mixed |
||
| 147 | */ |
||
| 148 | public function get_arg( $idx, $val = null ) { |
||
| 154 | |||
| 155 | /** |
||
| 156 | * Save |
||
| 157 | * |
||
| 158 | * @param mixed $arr |
||
| 159 | * |
||
| 160 | * @codeCoverageIgnore |
||
| 161 | */ |
||
| 162 | public function save( $arr ) { |
||
| 171 | |||
| 172 | /** |
||
| 173 | * Delete |
||
| 174 | * @codeCoverageIgnore |
||
| 175 | */ |
||
| 176 | public function delete() { |
||
| 182 | |||
| 183 | /** |
||
| 184 | * Set |
||
| 185 | * |
||
| 186 | * @param mixed $arr |
||
| 187 | * |
||
| 188 | * @return bool |
||
| 189 | */ |
||
| 190 | public function set( $arr ) { |
||
| 211 | |||
| 212 | /** |
||
| 213 | * Get permalink |
||
| 214 | * |
||
| 215 | * @param string $language |
||
| 216 | * |
||
| 217 | * @return string |
||
| 218 | */ |
||
| 219 | public function get_permalink( $language ) { |
||
| 235 | |||
| 236 | /** |
||
| 237 | * Get postlink |
||
| 238 | * |
||
| 239 | * @param string $language |
||
| 240 | * |
||
| 241 | * @return string |
||
| 242 | */ |
||
| 243 | public function get_postlink( $language ) { |
||
| 246 | |||
| 247 | /** |
||
| 248 | * Get the queried taxonomy |
||
| 249 | * @return string |
||
| 250 | */ |
||
| 251 | public function get_tax_query() { |
||
| 254 | |||
| 255 | /** |
||
| 256 | * Get current link |
||
| 257 | * @return string |
||
| 258 | */ |
||
| 259 | public function get_current_link() { |
||
| 262 | |||
| 263 | /** |
||
| 264 | * Is excluded |
||
| 265 | * @return bool |
||
| 266 | */ |
||
| 267 | public function is_excluded() { |
||
| 270 | |||
| 271 | /** |
||
| 272 | * Is content |
||
| 273 | * @return bool |
||
| 274 | */ |
||
| 275 | public function is_content_filter() { |
||
| 278 | |||
| 279 | /** |
||
| 280 | * Get order |
||
| 281 | * @return string |
||
| 282 | */ |
||
| 283 | public function get_order() { |
||
| 286 | |||
| 287 | /** |
||
| 288 | * Get url |
||
| 289 | * |
||
| 290 | * @param string $dir |
||
| 291 | * |
||
| 292 | * @return string |
||
| 293 | */ |
||
| 294 | public function get_url( $dir ) { |
||
| 297 | |||
| 298 | /** |
||
| 299 | * Returns slug for a post type |
||
| 300 | * @param string $post_type |
||
| 301 | * |
||
| 302 | * @return string |
||
| 303 | */ |
||
| 304 | public function get_slug( $post_type ) { |
||
| 311 | |||
| 312 | /** |
||
| 313 | * @param string $language |
||
| 314 | * |
||
| 315 | * @return string |
||
| 316 | */ |
||
| 317 | public function get_icon( $language ) { |
||
| 320 | |||
| 321 | /** |
||
| 322 | * Get flag url |
||
| 323 | * |
||
| 324 | * @param string $language |
||
| 325 | * |
||
| 326 | * @return string |
||
| 327 | */ |
||
| 328 | public function get_flag_url( $language ) { |
||
| 356 | |||
| 357 | /** |
||
| 358 | * Get all available languages |
||
| 359 | * |
||
| 360 | * @uses get_available_languages |
||
| 361 | * @uses format_code_lang |
||
| 362 | * @return array |
||
| 363 | */ |
||
| 364 | public function get_available_languages() { |
||
| 388 | |||
| 389 | /** |
||
| 390 | * The 'blog'-slug-problem :/ |
||
| 391 | * |
||
| 392 | * @param string $url |
||
| 393 | * @param MslsOptions $options |
||
| 394 | * |
||
| 395 | * @return string |
||
| 396 | */ |
||
| 397 | public static function check_for_blog_slug( $url, $options ) { |
||
| 423 | |||
| 424 | } |
||
| 425 |