Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like EE_Front_Controller 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 EE_Front_Controller, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
26 | final class EE_Front_Controller |
||
27 | { |
||
28 | |||
29 | /** |
||
30 | * @var string $_template_path |
||
31 | */ |
||
32 | private $_template_path; |
||
33 | |||
34 | /** |
||
35 | * @var string $_template |
||
36 | */ |
||
37 | private $_template; |
||
38 | |||
39 | /** |
||
40 | * @type EE_Registry $Registry |
||
41 | */ |
||
42 | protected $Registry; |
||
43 | |||
44 | /** |
||
45 | * @type EE_Request_Handler $Request_Handler |
||
46 | */ |
||
47 | protected $Request_Handler; |
||
48 | |||
49 | /** |
||
50 | * @type EE_Module_Request_Router $Module_Request_Router |
||
51 | */ |
||
52 | protected $Module_Request_Router; |
||
53 | |||
54 | |||
55 | /** |
||
56 | * class constructor |
||
57 | * should fire after shortcode, module, addon, or other plugin's default priority init phases have run |
||
58 | * |
||
59 | * @access public |
||
60 | * @param \EE_Registry $Registry |
||
61 | * @param \EE_Request_Handler $Request_Handler |
||
62 | * @param \EE_Module_Request_Router $Module_Request_Router |
||
63 | */ |
||
64 | public function __construct( |
||
106 | |||
107 | |||
108 | /** |
||
109 | * @return EE_Request_Handler |
||
110 | */ |
||
111 | public function Request_Handler() |
||
115 | |||
116 | |||
117 | /** |
||
118 | * @return EE_Module_Request_Router |
||
119 | */ |
||
120 | public function Module_Request_Router() |
||
124 | |||
125 | |||
126 | |||
127 | /** |
||
128 | * @return LegacyShortcodesManager |
||
129 | */ |
||
130 | public function getLegacyShortcodesManager() |
||
134 | |||
135 | |||
136 | |||
137 | |||
138 | |||
139 | /*********************************************** INIT ACTION HOOK ***********************************************/ |
||
140 | |||
141 | |||
142 | |||
143 | /** |
||
144 | * filter_wp_comments |
||
145 | * This simply makes sure that any "private" EE CPTs do not have their comments show up in any wp comment |
||
146 | * widgets/queries done on frontend |
||
147 | * |
||
148 | * @param array $clauses array of comment clauses setup by WP_Comment_Query |
||
149 | * @return array array of comment clauses with modifications. |
||
150 | */ |
||
151 | public function filter_wp_comments($clauses) |
||
162 | |||
163 | |||
164 | /** |
||
165 | * employ_CPT_Strategy |
||
166 | * |
||
167 | * @access public |
||
168 | * @return void |
||
169 | */ |
||
170 | public function employ_CPT_Strategy() |
||
176 | |||
177 | |||
178 | /** |
||
179 | * this just makes sure that if the site is using ssl that we force that for any admin ajax calls from frontend |
||
180 | * |
||
181 | * @param string $url incoming url |
||
182 | * @return string final assembled url |
||
183 | */ |
||
184 | public function maybe_force_admin_ajax_ssl($url) |
||
191 | |||
192 | |||
193 | |||
194 | |||
195 | |||
196 | |||
197 | /*********************************************** WP_LOADED ACTION HOOK ***********************************************/ |
||
198 | |||
199 | |||
200 | /** |
||
201 | * wp_loaded - should fire after shortcode, module, addon, or other plugin's have been registered and their |
||
202 | * default priority init phases have run |
||
203 | * |
||
204 | * @access public |
||
205 | * @return void |
||
206 | */ |
||
207 | public function wp_loaded() |
||
210 | |||
211 | |||
212 | |||
213 | |||
214 | |||
215 | /*********************************************** PARSE_REQUEST HOOK ***********************************************/ |
||
216 | /** |
||
217 | * _get_request |
||
218 | * |
||
219 | * @access public |
||
220 | * @param WP $WP |
||
221 | * @return void |
||
222 | */ |
||
223 | public function get_request(WP $WP) |
||
229 | |||
230 | |||
231 | |||
232 | /** |
||
233 | * pre_get_posts - basically a module factory for instantiating modules and selecting the final view template |
||
234 | * |
||
235 | * @access public |
||
236 | * @param WP_Query $WP_Query |
||
237 | * @return void |
||
238 | */ |
||
239 | public function pre_get_posts($WP_Query) |
||
261 | |||
262 | |||
263 | |||
264 | |||
265 | |||
266 | /*********************************************** WP HOOK ***********************************************/ |
||
267 | |||
268 | |||
269 | /** |
||
270 | * wp - basically last chance to do stuff before headers sent |
||
271 | * |
||
272 | * @access public |
||
273 | * @return void |
||
274 | */ |
||
275 | public function wp() |
||
278 | |||
279 | |||
280 | |||
281 | /*********************** GET_HEADER, WP_ENQUEUE_SCRIPTS && WP_HEAD HOOK ***********************/ |
||
282 | |||
283 | |||
284 | |||
285 | /** |
||
286 | * callback for the WP "get_header" hook point |
||
287 | * checks sidebars for EE widgets |
||
288 | * loads resources and assets accordingly |
||
289 | * |
||
290 | * @return void |
||
291 | */ |
||
292 | public function get_header() |
||
307 | |||
308 | |||
309 | |||
310 | /** |
||
311 | * builds list of active widgets then scans active sidebars looking for them |
||
312 | * returns true is an EE widget is found in an active sidebar |
||
313 | * Please Note: this does NOT mean that the sidebar or widget |
||
314 | * is actually in use in a given template, as that is unfortunately not known |
||
315 | * until a sidebar and it's widgets are actually loaded |
||
316 | * |
||
317 | * @return boolean |
||
318 | */ |
||
319 | private function espresso_widgets_in_active_sidebars() |
||
342 | |||
343 | |||
344 | |||
345 | |||
346 | /** |
||
347 | * wp_enqueue_scripts |
||
348 | * |
||
349 | * @access public |
||
350 | * @return void |
||
351 | */ |
||
352 | public function wp_enqueue_scripts() |
||
470 | |||
471 | |||
472 | /** |
||
473 | * header_meta_tag |
||
474 | * |
||
475 | * @access public |
||
476 | * @return void |
||
477 | */ |
||
478 | public function header_meta_tag() |
||
504 | |||
505 | |||
506 | |||
507 | /** |
||
508 | * wp_print_scripts |
||
509 | * |
||
510 | * @return void |
||
511 | */ |
||
512 | public function wp_print_scripts() |
||
524 | |||
525 | |||
526 | |||
527 | |||
528 | /*********************************************** THE_CONTENT FILTER HOOK ********************************************** |
||
529 | |||
530 | |||
531 | |||
532 | // /** |
||
533 | // * the_content |
||
534 | // * |
||
535 | // * @access public |
||
536 | // * @param $the_content |
||
537 | // * @return string |
||
538 | // */ |
||
539 | // public function the_content( $the_content ) { |
||
540 | // // nothing gets loaded at this point unless other systems turn this hookpoint on by using: add_filter( 'FHEE_run_EE_the_content', '__return_true' ); |
||
541 | // if ( apply_filters( 'FHEE_run_EE_the_content', FALSE ) ) { |
||
542 | // } |
||
543 | // return $the_content; |
||
544 | // } |
||
545 | |||
546 | |||
547 | |||
548 | /*********************************************** WP_FOOTER ***********************************************/ |
||
549 | |||
550 | |||
551 | /** |
||
552 | * display_errors |
||
553 | * |
||
554 | * @access public |
||
555 | * @return void |
||
556 | */ |
||
557 | public function display_errors() |
||
575 | |||
576 | |||
577 | |||
578 | |||
579 | |||
580 | /*********************************************** UTILITIES ***********************************************/ |
||
581 | /** |
||
582 | * template_include |
||
583 | * |
||
584 | * @access public |
||
585 | * @param string $template_include_path |
||
586 | * @return string |
||
587 | */ |
||
588 | public function template_include($template_include_path = null) |
||
599 | |||
600 | |||
601 | /** |
||
602 | * get_selected_template |
||
603 | * |
||
604 | * @access public |
||
605 | * @param bool $with_path |
||
606 | * @return string |
||
607 | */ |
||
608 | public function get_selected_template($with_path = false) |
||
612 | |||
613 | |||
614 | |||
615 | /** |
||
616 | * @deprecated 4.9.26 |
||
617 | * @param string $shortcode_class |
||
618 | * @param \WP $wp |
||
619 | */ |
||
620 | public function initialize_shortcode($shortcode_class = '', WP $wp = null) |
||
632 | |||
633 | } |
||
634 | // End of file EE_Front_Controller.core.php |
||
636 |