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() { |
||
290 | |||
291 | /** |
||
292 | * Get url |
||
293 | * |
||
294 | * @param string $dir |
||
295 | * |
||
296 | * @return string |
||
297 | */ |
||
298 | public function get_url( $dir ) { |
||
301 | |||
302 | /** |
||
303 | * Returns slug for a post type |
||
304 | * @param string $post_type |
||
305 | * |
||
306 | * @return string |
||
307 | */ |
||
308 | public function get_slug( $post_type ) { |
||
315 | |||
316 | /** |
||
317 | * @param string $language |
||
318 | * |
||
319 | * @return string |
||
320 | */ |
||
321 | public function get_icon( $language ) { |
||
324 | |||
325 | /** |
||
326 | * Get flag url |
||
327 | * |
||
328 | * @param string $language |
||
329 | * |
||
330 | * @return string |
||
331 | */ |
||
332 | public function get_flag_url( $language ) { |
||
360 | |||
361 | /** |
||
362 | * Get all available languages |
||
363 | * |
||
364 | * @uses get_available_languages |
||
365 | * @uses format_code_lang |
||
366 | * @return array |
||
367 | */ |
||
368 | public function get_available_languages() { |
||
392 | |||
393 | /** |
||
394 | * The 'blog'-slug-problem :/ |
||
395 | * |
||
396 | * @param string $url |
||
397 | * @param MslsOptions $options |
||
398 | * |
||
399 | * @return string |
||
400 | */ |
||
401 | public static function check_for_blog_slug( $url, $options ) { |
||
427 | |||
428 | } |
||
429 |