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:
1 | <?php use EventEspresso\modules\ticket_selector\DisplayTicketSelector; |
||
23 | class EED_Ticket_Selector extends EED_Module { |
||
24 | |||
25 | /** |
||
26 | * @var EventEspresso\modules\ticket_selector\DisplayTicketSelector $ticket_selector |
||
27 | */ |
||
28 | private static $ticket_selector; |
||
29 | |||
30 | /** |
||
31 | * @var EventEspresso\modules\ticket_selector\TicketSelectorIframeEmbedButton $iframe_embed_button |
||
32 | */ |
||
33 | private static $iframe_embed_button; |
||
34 | |||
35 | |||
36 | |||
37 | /** |
||
38 | * @return EED_Ticket_Selector |
||
39 | */ |
||
40 | public static function instance() { |
||
43 | |||
44 | |||
45 | |||
46 | protected function set_config(){ |
||
51 | |||
52 | |||
53 | |||
54 | /** |
||
55 | * set_hooks - for hooking into EE Core, other modules, etc |
||
56 | * |
||
57 | * @access public |
||
58 | * @return void |
||
59 | */ |
||
60 | public static function set_hooks() { |
||
61 | // routing |
||
62 | EE_Config::register_route( 'iframe', 'EED_Ticket_Selector', 'ticket_selector_iframe', 'ticket_selector' ); |
||
63 | EE_Config::register_route( 'process_ticket_selections', 'EED_Ticket_Selector', 'process_ticket_selections' ); |
||
64 | EE_Config::register_route('cancel_ticket_selections', 'EED_Ticket_Selector', 'cancel_ticket_selections'); |
||
65 | add_action( 'wp_loaded', array( 'EED_Ticket_Selector', 'set_definitions' ), 2 ); |
||
66 | add_action( 'AHEE_event_details_header_bottom', array( 'EED_Ticket_Selector', 'display_ticket_selector' ), 10, 1 ); |
||
67 | add_action( 'wp_enqueue_scripts', array( 'EED_Ticket_Selector', 'translate_js_strings' ), 0 ); |
||
68 | add_action( 'wp_enqueue_scripts', array( 'EED_Ticket_Selector', 'load_tckt_slctr_assets' ), 10 ); |
||
69 | EED_Ticket_Selector::loadIframeAssets(); |
||
70 | } |
||
71 | |||
72 | |||
73 | |||
74 | /** |
||
75 | * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
||
76 | * |
||
77 | * @access public |
||
78 | * @return void |
||
79 | */ |
||
80 | public static function set_hooks_admin() { |
||
81 | // hook into the end of the \EE_Admin_Page::_load_page_dependencies() |
||
82 | // to load assets for "espresso_events" page on the "edit" route (action) |
||
83 | add_action( |
||
84 | 'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_events__edit', |
||
85 | array( 'EED_Ticket_Selector', 'ticket_selector_iframe_embed_button' ), |
||
86 | 10 |
||
87 | ); |
||
88 | |||
89 | /** |
||
90 | * Make sure assets for the ticket selector are loaded on the espresso registrations route so admin side |
||
91 | * registrations work. |
||
92 | */ |
||
93 | add_action( |
||
94 | 'FHEE__EE_Admin_Page___load_page_dependencies__after_load__espresso_registrations__new_registration', |
||
95 | array('EED_Ticket_Selector', 'set_definitions'), |
||
96 | 10 |
||
97 | ); |
||
98 | } |
||
99 | |||
100 | |||
101 | |||
102 | /** |
||
103 | * set_definitions |
||
104 | * |
||
105 | * @access public |
||
106 | * @return void |
||
107 | */ |
||
108 | public static function set_definitions() { |
||
109 | define( 'TICKET_SELECTOR_ASSETS_URL', plugin_dir_url( __FILE__ ) . 'assets' . DS ); |
||
110 | define( 'TICKET_SELECTOR_TEMPLATES_PATH', str_replace( '\\', DS, plugin_dir_path( __FILE__ )) . 'templates' . DS ); |
||
111 | |||
112 | //if config is not set, initialize |
||
113 | View Code Duplication | if ( ! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config ) { |
|
114 | \EED_Ticket_Selector::instance()->set_config(); |
||
115 | \EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector = \EED_Ticket_Selector::instance()->config(); |
||
116 | } |
||
117 | } |
||
118 | |||
119 | |||
120 | |||
121 | /** |
||
122 | * @return \EventEspresso\modules\ticket_selector\DisplayTicketSelector |
||
123 | */ |
||
124 | public static function ticketSelector() |
||
131 | |||
132 | |||
133 | /** |
||
134 | * gets the ball rolling |
||
135 | * |
||
136 | * @access public |
||
137 | * @param WP $WP |
||
138 | * @return void |
||
139 | */ |
||
140 | public function run( $WP ) {} |
||
141 | |||
142 | |||
143 | |||
144 | /** |
||
145 | * @return \EventEspresso\modules\ticket_selector\TicketSelectorIframeEmbedButton |
||
146 | */ |
||
147 | public static function getIframeEmbedButton() { |
||
153 | |||
154 | |||
155 | |||
156 | /** |
||
157 | * ticket_selector_iframe_embed_button |
||
158 | * |
||
159 | * @return void |
||
160 | * @throws \EE_Error |
||
161 | */ |
||
162 | public static function ticket_selector_iframe_embed_button() { |
||
166 | |||
167 | |||
168 | |||
169 | /** |
||
170 | * ticket_selector_iframe |
||
171 | * |
||
172 | * @return void |
||
173 | * @throws \DomainException |
||
174 | * @throws \EE_Error |
||
175 | */ |
||
176 | public function ticket_selector_iframe() { |
||
180 | |||
181 | |||
182 | |||
183 | /** |
||
184 | * creates buttons for selecting number of attendees for an event |
||
185 | * |
||
186 | * @access public |
||
187 | * @param WP_Post|int $event |
||
188 | * @param bool $view_details |
||
189 | * @return string |
||
190 | * @throws \EE_Error |
||
191 | */ |
||
192 | public static function display_ticket_selector( $event = NULL, $view_details = FALSE ) { |
||
195 | |||
196 | |||
197 | |||
198 | /** |
||
199 | * process_ticket_selections |
||
200 | * |
||
201 | * @access public |
||
202 | * @return array or FALSE |
||
203 | * @throws \EE_Error |
||
204 | */ |
||
205 | public function process_ticket_selections() { |
||
209 | |||
210 | |||
211 | |||
212 | /** |
||
213 | * cancel_ticket_selections |
||
214 | * |
||
215 | * @access public |
||
216 | * @return string |
||
217 | */ |
||
218 | public static function cancel_ticket_selections() |
||
223 | |||
224 | |||
225 | |||
226 | /** |
||
227 | * @return void |
||
228 | */ |
||
229 | public static function translate_js_strings() { |
||
234 | |||
235 | |||
236 | |||
237 | /** |
||
238 | * load js |
||
239 | * |
||
240 | * @access public |
||
241 | * @return void |
||
242 | */ |
||
243 | public static function load_tckt_slctr_assets() { |
||
255 | |||
256 | |||
257 | |||
258 | /** |
||
259 | * @return void |
||
260 | */ |
||
261 | public static function loadIframeAssets() |
||
282 | |||
283 | |||
284 | |||
285 | /** |
||
286 | * Informs the rest of the forms system what CSS and JS is needed to display the input |
||
287 | * |
||
288 | * @param array $iframe_css |
||
289 | * @return array |
||
290 | */ |
||
291 | public static function iframeCss(array $iframe_css) |
||
296 | |||
297 | |||
298 | |||
299 | /** |
||
300 | * Informs the rest of the forms system what CSS and JS is needed to display the input |
||
301 | * |
||
302 | * @param array $iframe_js |
||
303 | * @return array |
||
304 | */ |
||
305 | public static function iframeJs(array $iframe_js) |
||
310 | |||
311 | |||
312 | /****************************** DEPRECATED ******************************/ |
||
313 | |||
314 | |||
315 | |||
316 | /** |
||
317 | * @deprecated |
||
318 | * @return string |
||
319 | * @throws \EE_Error |
||
320 | */ |
||
321 | public static function display_view_details_btn() |
||
326 | |||
327 | |||
328 | |||
329 | /** |
||
330 | * @deprecated |
||
331 | * @return string |
||
332 | * @throws \EE_Error |
||
333 | */ |
||
334 | public static function display_ticket_selector_submit() |
||
339 | |||
340 | |||
341 | |||
342 | /** |
||
343 | * @deprecated |
||
344 | * @param string $permalink_string |
||
345 | * @param int $id |
||
346 | * @param string $new_title |
||
347 | * @param string $new_slug |
||
348 | * @return string |
||
349 | */ |
||
350 | public static function iframe_code_button($permalink_string, $id, $new_title = '', $new_slug = '') |
||
362 | |||
363 | |||
364 | |||
365 | /** |
||
366 | * @deprecated |
||
367 | * @param int $ID |
||
368 | * @param string $external_url |
||
369 | * @return string |
||
370 | */ |
||
371 | public static function ticket_selector_form_open($ID = 0, $external_url = '') |
||
376 | |||
377 | |||
378 | |||
379 | /** |
||
380 | * @deprecated |
||
381 | * @return string |
||
382 | */ |
||
383 | public static function ticket_selector_form_close() |
||
388 | |||
389 | |||
390 | |||
391 | /** |
||
392 | * @deprecated |
||
393 | * @return string |
||
394 | */ |
||
395 | public static function no_tkt_slctr_end_dv() |
||
400 | |||
401 | |||
402 | |||
403 | /** |
||
404 | * @deprecated 4.9.13 |
||
405 | * @return string |
||
406 | */ |
||
407 | public static function tkt_slctr_end_dv() |
||
411 | |||
412 | |||
413 | |||
414 | /** |
||
415 | * @deprecated |
||
416 | * @return string |
||
417 | */ |
||
418 | public static function clear_tkt_slctr() |
||
422 | |||
423 | |||
424 | |||
425 | /** |
||
426 | * @deprecated |
||
427 | */ |
||
428 | public static function load_tckt_slctr_assets_admin() |
||
439 | |||
440 | |||
441 | } |
||
442 | // End of file EED_Ticket_Selector.module.php |
||
444 |
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()
method in theSon
calls the wrong method in the parent class.