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 |
||
22 | * @property string $after_output |
||
23 | */ |
||
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 ) { |
||
197 | |||
198 | /** |
||
199 | * Get permalink |
||
200 | * |
||
201 | * @param string $language |
||
202 | * |
||
203 | * @return string |
||
204 | */ |
||
205 | public function get_permalink( $language ) { |
||
221 | |||
222 | /** |
||
223 | * Get postlink |
||
224 | * |
||
225 | * @param string $language |
||
226 | * |
||
227 | * @return string |
||
228 | */ |
||
229 | public function get_postlink( $language ) { |
||
232 | |||
233 | /** |
||
234 | * Get current link |
||
235 | * @return string |
||
236 | */ |
||
237 | public function get_current_link() { |
||
240 | |||
241 | /** |
||
242 | * Is excluded |
||
243 | * @return bool |
||
244 | */ |
||
245 | public function is_excluded() { |
||
248 | |||
249 | /** |
||
250 | * Is content |
||
251 | * @return bool |
||
252 | */ |
||
253 | public function is_content_filter() { |
||
256 | |||
257 | /** |
||
258 | * Get order |
||
259 | * @return string |
||
260 | */ |
||
261 | public function get_order() { |
||
268 | |||
269 | /** |
||
270 | * Get url |
||
271 | * |
||
272 | * @param string $dir |
||
273 | * |
||
274 | * @return string |
||
275 | */ |
||
276 | public function get_url( $dir ) { |
||
279 | |||
280 | /** |
||
281 | * Returns slug for a post type |
||
282 | * @param string $post_type |
||
283 | * |
||
284 | * @return string |
||
285 | */ |
||
286 | public function get_slug( $post_type ) { |
||
293 | |||
294 | /** |
||
295 | * Get flag url |
||
296 | * |
||
297 | * @param string $language |
||
298 | * |
||
299 | * @return string |
||
300 | */ |
||
301 | public function get_flag_url( $language ) { |
||
334 | |||
335 | /** |
||
336 | * Get all available languages |
||
337 | * @uses get_available_languages |
||
338 | * @uses format_code_lang |
||
339 | * @return array |
||
340 | */ |
||
341 | public function get_available_languages() { |
||
364 | |||
365 | /** |
||
366 | * The 'blog'-slug-problem :/ |
||
367 | * |
||
368 | * @param string $url |
||
369 | * @param MslsOptions $options |
||
370 | * |
||
371 | * @return string |
||
372 | */ |
||
373 | public static function check_for_blog_slug( $url, $options ) { |
||
399 | |||
400 | } |
||
401 |