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 |
||
24 | class MslsOptions extends MslsGetSet { |
||
25 | |||
26 | /** |
||
27 | * Args |
||
28 | * @var array |
||
29 | */ |
||
30 | protected $args; |
||
31 | |||
32 | /** |
||
33 | * Name |
||
34 | * @var string |
||
35 | */ |
||
36 | protected $name; |
||
37 | |||
38 | /** |
||
39 | * Exists |
||
40 | * @var bool |
||
41 | */ |
||
42 | protected $exists = false; |
||
43 | |||
44 | /** |
||
45 | * Separator |
||
46 | * @var string |
||
47 | */ |
||
48 | protected $sep = ''; |
||
49 | |||
50 | /** |
||
51 | * Autoload |
||
52 | * @var string |
||
53 | */ |
||
54 | protected $autoload = 'yes'; |
||
55 | |||
56 | /** |
||
57 | * Available languages |
||
58 | * @var array |
||
59 | */ |
||
60 | private $available_languages; |
||
61 | |||
62 | /** |
||
63 | * Rewrite with front |
||
64 | * @var bool |
||
65 | */ |
||
66 | public $with_front; |
||
67 | |||
68 | /** |
||
69 | * Factory method |
||
70 | * |
||
71 | * @codeCoverageIgnore |
||
72 | * |
||
73 | * @param int $id |
||
74 | * |
||
75 | * @return MslsOptions |
||
76 | */ |
||
77 | public static function create( $id = 0 ) { |
||
102 | |||
103 | /** |
||
104 | * Checks if the current page is a home, front or 404 page |
||
105 | * @return boolean |
||
106 | */ |
||
107 | public static function is_main_page() { |
||
110 | |||
111 | /** |
||
112 | * Checks if the current page is a category, tag or any other tax archive |
||
113 | * @return boolean |
||
114 | */ |
||
115 | public static function is_tax_page() { |
||
118 | |||
119 | /** |
||
120 | * Checks if the current page is a date, author any other post_type archive |
||
121 | * @return boolean |
||
122 | */ |
||
123 | public static function is_query_page() { |
||
126 | |||
127 | /** |
||
128 | * Constructor |
||
129 | */ |
||
130 | public function __construct() { |
||
135 | |||
136 | /** |
||
137 | * Gets an element of arg by index |
||
138 | * The returning value is casted to the type of $retval or will be the |
||
139 | * value of $retval if nothing is set at this index. |
||
140 | * |
||
141 | * @param int $idx |
||
142 | * @param mixed $val |
||
143 | * |
||
144 | * @return mixed |
||
145 | */ |
||
146 | public function get_arg( $idx, $val = null ) { |
||
152 | |||
153 | /** |
||
154 | * Save |
||
155 | * |
||
156 | * @param mixed $arr |
||
157 | * |
||
158 | * @codeCoverageIgnore |
||
159 | */ |
||
160 | public function save( $arr ) { |
||
169 | |||
170 | /** |
||
171 | * Delete |
||
172 | * @codeCoverageIgnore |
||
173 | */ |
||
174 | public function delete() { |
||
180 | |||
181 | /** |
||
182 | * Set |
||
183 | * |
||
184 | * @param mixed $arr |
||
185 | * |
||
186 | * @return bool |
||
187 | */ |
||
188 | public function set( $arr ) { |
||
209 | |||
210 | /** |
||
211 | * Get permalink |
||
212 | * |
||
213 | * @param string $language |
||
214 | * |
||
215 | * @return string |
||
216 | */ |
||
217 | public function get_permalink( $language ) { |
||
233 | |||
234 | /** |
||
235 | * Get postlink |
||
236 | * |
||
237 | * @param string $language |
||
238 | * |
||
239 | * @return string |
||
240 | */ |
||
241 | public function get_postlink( $language ) { |
||
244 | |||
245 | /** |
||
246 | * Get the queried taxonomy |
||
247 | * @return string |
||
248 | */ |
||
249 | public function get_tax_query() { |
||
252 | |||
253 | /** |
||
254 | * Get current link |
||
255 | * @return string |
||
256 | */ |
||
257 | public function get_current_link() { |
||
260 | |||
261 | /** |
||
262 | * Is excluded |
||
263 | * @return bool |
||
264 | */ |
||
265 | public function is_excluded() { |
||
268 | |||
269 | /** |
||
270 | * Is content |
||
271 | * @return bool |
||
272 | */ |
||
273 | public function is_content_filter() { |
||
276 | |||
277 | /** |
||
278 | * Get order |
||
279 | * @return string |
||
280 | */ |
||
281 | public function get_order() { |
||
288 | |||
289 | /** |
||
290 | * Get url |
||
291 | * |
||
292 | * @param string $dir |
||
293 | * |
||
294 | * @return string |
||
295 | */ |
||
296 | public function get_url( $dir ) { |
||
299 | |||
300 | /** |
||
301 | * Returns slug for a post type |
||
302 | * @param string $post_type |
||
303 | * |
||
304 | * @return string |
||
305 | */ |
||
306 | public function get_slug( $post_type ) { |
||
313 | |||
314 | /** |
||
315 | * Get flag url |
||
316 | * |
||
317 | * @param string $language |
||
318 | * |
||
319 | * @return string |
||
320 | */ |
||
321 | public function get_flag_url( $language ) { |
||
354 | |||
355 | /** |
||
356 | * Get all available languages |
||
357 | * |
||
358 | * @uses get_available_languages |
||
359 | * @uses format_code_lang |
||
360 | * @return array |
||
361 | */ |
||
362 | public function get_available_languages() { |
||
386 | |||
387 | /** |
||
388 | * The 'blog'-slug-problem :/ |
||
389 | * |
||
390 | * @param string $url |
||
391 | * @param MslsOptions $options |
||
392 | * |
||
393 | * @return string |
||
394 | */ |
||
395 | public static function check_for_blog_slug( $url, $options ) { |
||
421 | |||
422 | } |
||
423 |