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 | * @param int $id |
||
72 | * |
||
73 | * @return MslsOptions |
||
74 | */ |
||
75 | public static function create( $id = 0 ) { |
||
100 | |||
101 | /** |
||
102 | * Checks if the current page is a home, front or 404 page |
||
103 | * @return boolean |
||
104 | */ |
||
105 | public static function is_main_page() { |
||
108 | |||
109 | /** |
||
110 | * Checks if the current page is a category, tag or any other tax archive |
||
111 | * @return boolean |
||
112 | */ |
||
113 | public static function is_tax_page() { |
||
116 | |||
117 | /** |
||
118 | * Checks if the current page is a date, author any other post_type archive |
||
119 | * @return boolean |
||
120 | */ |
||
121 | public static function is_query_page() { |
||
124 | |||
125 | /** |
||
126 | * Constructor |
||
127 | */ |
||
128 | public function __construct() { |
||
133 | |||
134 | /** |
||
135 | * Gets an element of arg by index |
||
136 | * The returning value is casted to the type of $retval or will be the |
||
137 | * value of $retval if nothing is set at this index. |
||
138 | * |
||
139 | * @param int $idx |
||
140 | * @param mixed $val |
||
141 | * |
||
142 | * @return mixed |
||
143 | */ |
||
144 | public function get_arg( $idx, $val = null ) { |
||
150 | |||
151 | /** |
||
152 | * Save |
||
153 | * |
||
154 | * @param mixed $arr |
||
155 | * |
||
156 | * @codeCoverageIgnore |
||
157 | */ |
||
158 | public function save( $arr ) { |
||
167 | |||
168 | /** |
||
169 | * Delete |
||
170 | * @codeCoverageIgnore |
||
171 | */ |
||
172 | public function delete() { |
||
178 | |||
179 | /** |
||
180 | * Set |
||
181 | * |
||
182 | * @param mixed $arr |
||
183 | * |
||
184 | * @return bool |
||
185 | */ |
||
186 | public function set( $arr ) { |
||
207 | |||
208 | /** |
||
209 | * Get permalink |
||
210 | * |
||
211 | * @param string $language |
||
212 | * |
||
213 | * @return string |
||
214 | */ |
||
215 | public function get_permalink( $language ) { |
||
231 | |||
232 | /** |
||
233 | * Get postlink |
||
234 | * |
||
235 | * @param string $language |
||
236 | * |
||
237 | * @return string |
||
238 | */ |
||
239 | public function get_postlink( $language ) { |
||
242 | |||
243 | /** |
||
244 | * Get current link |
||
245 | * @return string |
||
246 | */ |
||
247 | public function get_current_link() { |
||
250 | |||
251 | /** |
||
252 | * Is excluded |
||
253 | * @return bool |
||
254 | */ |
||
255 | public function is_excluded() { |
||
258 | |||
259 | /** |
||
260 | * Is content |
||
261 | * @return bool |
||
262 | */ |
||
263 | public function is_content_filter() { |
||
266 | |||
267 | /** |
||
268 | * Get order |
||
269 | * @return string |
||
270 | */ |
||
271 | public function get_order() { |
||
278 | |||
279 | /** |
||
280 | * Get url |
||
281 | * |
||
282 | * @param string $dir |
||
283 | * |
||
284 | * @return string |
||
285 | */ |
||
286 | public function get_url( $dir ) { |
||
289 | |||
290 | /** |
||
291 | * Returns slug for a post type |
||
292 | * @param string $post_type |
||
293 | * |
||
294 | * @return string |
||
295 | */ |
||
296 | public function get_slug( $post_type ) { |
||
303 | |||
304 | /** |
||
305 | * Get flag url |
||
306 | * |
||
307 | * @param string $language |
||
308 | * |
||
309 | * @return string |
||
310 | */ |
||
311 | public function get_flag_url( $language ) { |
||
344 | |||
345 | /** |
||
346 | * Get all available languages |
||
347 | * |
||
348 | * @uses get_available_languages |
||
349 | * @uses format_code_lang |
||
350 | * @return array |
||
351 | */ |
||
352 | public function get_available_languages() { |
||
376 | |||
377 | /** |
||
378 | * The 'blog'-slug-problem :/ |
||
379 | * |
||
380 | * @param string $url |
||
381 | * @param MslsOptions $options |
||
382 | * |
||
383 | * @return string |
||
384 | */ |
||
385 | public static function check_for_blog_slug( $url, $options ) { |
||
411 | |||
412 | } |
||
413 |