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 | class MslsOptions extends MslsGetSet implements IMslsRegistryInstance { |
||
23 | |||
24 | /** |
||
25 | * Args |
||
26 | * @var array |
||
27 | */ |
||
28 | protected $args; |
||
29 | |||
30 | /** |
||
31 | * Name |
||
32 | * @var string |
||
33 | */ |
||
34 | protected $name; |
||
35 | |||
36 | /** |
||
37 | * Exists |
||
38 | * @var bool |
||
39 | */ |
||
40 | protected $exists = false; |
||
41 | |||
42 | /** |
||
43 | * Separator |
||
44 | * @var string |
||
45 | */ |
||
46 | protected $sep = ''; |
||
47 | |||
48 | /** |
||
49 | * Autoload |
||
50 | * @var string |
||
51 | */ |
||
52 | protected $autoload = 'yes'; |
||
53 | |||
54 | /** |
||
55 | * Available languages |
||
56 | * @var array |
||
57 | */ |
||
58 | private $available_languages; |
||
59 | |||
60 | /** |
||
61 | * Rewrite with front |
||
62 | * @var bool |
||
63 | */ |
||
64 | public $with_front; |
||
65 | |||
66 | /** |
||
67 | * Factory method |
||
68 | * |
||
69 | * @param int $id |
||
70 | * |
||
71 | * @return MslsOptions |
||
72 | */ |
||
73 | public static function create( $id = 0 ) { |
||
97 | |||
98 | /** |
||
99 | * Checks if the current page is a home, front or 404 page |
||
100 | * @return boolean |
||
101 | */ |
||
102 | public static function is_main_page() { |
||
105 | |||
106 | /** |
||
107 | * Checks if the current page is a category, tag or any other tax archive |
||
108 | * @return boolean |
||
109 | */ |
||
110 | public static function is_tax_page() { |
||
113 | |||
114 | /** |
||
115 | * Checks if the current page is a date, author any other post_type archive |
||
116 | * @return boolean |
||
117 | */ |
||
118 | public static function is_query_page() { |
||
121 | |||
122 | /** |
||
123 | * Constructor |
||
124 | */ |
||
125 | public function __construct() { |
||
130 | |||
131 | /** |
||
132 | * Gets an element of arg by index |
||
133 | * The returning value is casted to the type of $retval or will be the |
||
134 | * value of $retval if nothing is set at this index. |
||
135 | * |
||
136 | * @param int $idx |
||
137 | * @param mixed $val |
||
138 | * |
||
139 | * @return mixed |
||
140 | */ |
||
141 | public function get_arg( $idx, $val = null ) { |
||
147 | |||
148 | /** |
||
149 | * Save |
||
150 | * |
||
151 | * @param mixed $arr |
||
152 | * |
||
153 | * @codeCoverageIgnore |
||
154 | */ |
||
155 | public function save( $arr ) { |
||
164 | |||
165 | /** |
||
166 | * Delete |
||
167 | * @codeCoverageIgnore |
||
168 | */ |
||
169 | public function delete() { |
||
175 | |||
176 | /** |
||
177 | * Set |
||
178 | * |
||
179 | * @param mixed $arr |
||
180 | * |
||
181 | * @return bool |
||
182 | */ |
||
183 | public function set( $arr ) { |
||
194 | |||
195 | /** |
||
196 | * Get permalink |
||
197 | * |
||
198 | * @param string $language |
||
199 | * |
||
200 | * @return string |
||
201 | */ |
||
202 | public function get_permalink( $language ) { |
||
218 | |||
219 | /** |
||
220 | * Get postlink |
||
221 | * |
||
222 | * @param string $language |
||
223 | * |
||
224 | * @return string |
||
225 | */ |
||
226 | public function get_postlink( $language ) { |
||
229 | |||
230 | /** |
||
231 | * Get current link |
||
232 | * @return string |
||
233 | */ |
||
234 | public function get_current_link() { |
||
237 | |||
238 | /** |
||
239 | * Is excluded |
||
240 | * @return bool |
||
241 | */ |
||
242 | public function is_excluded() { |
||
245 | |||
246 | /** |
||
247 | * Is content |
||
248 | * @return bool |
||
249 | */ |
||
250 | public function is_content_filter() { |
||
253 | |||
254 | /** |
||
255 | * Get order |
||
256 | * @return string |
||
257 | */ |
||
258 | public function get_order() { |
||
265 | |||
266 | /** |
||
267 | * Get url |
||
268 | * |
||
269 | * @param string $dir |
||
270 | * |
||
271 | * @return string |
||
272 | */ |
||
273 | public function get_url( $dir ) { |
||
276 | |||
277 | /** |
||
278 | * Returns slug for a post type |
||
279 | * @param string $post_type |
||
280 | * |
||
281 | * @return string |
||
282 | */ |
||
283 | public function get_slug( $post_type ) { |
||
290 | |||
291 | /** |
||
292 | * Get flag url |
||
293 | * |
||
294 | * @param string $language |
||
295 | * |
||
296 | * @return string |
||
297 | */ |
||
298 | public function get_flag_url( $language ) { |
||
331 | |||
332 | /** |
||
333 | * Get all available languages |
||
334 | * @uses get_available_languages |
||
335 | * @uses format_code_lang |
||
336 | * @return array |
||
337 | */ |
||
338 | public function get_available_languages() { |
||
361 | |||
362 | /** |
||
363 | * The 'blog'-slug-problem :/ |
||
364 | * |
||
365 | * @param string $url |
||
366 | * @param MslsOptions $options |
||
367 | * |
||
368 | * @return string |
||
369 | */ |
||
370 | public static function check_for_blog_slug( $url, $options ) { |
||
396 | |||
397 | /** |
||
398 | * Get or create an instance of MslsOptions |
||
399 | * @todo Until PHP 5.2 is not longer the minimum for WordPress ... |
||
400 | * @return MslsOptions |
||
401 | */ |
||
402 | public static function instance() { |
||
410 | |||
411 | } |
||
412 |