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() { |
||
| 68 | |||
| 69 | |||
| 70 | |||
| 71 | /** |
||
| 72 | * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
||
| 73 | * |
||
| 74 | * @access public |
||
| 75 | * @return void |
||
| 76 | */ |
||
| 77 | public static function set_hooks_admin() { |
||
| 86 | |||
| 87 | |||
| 88 | |||
| 89 | /** |
||
| 90 | * set_definitions |
||
| 91 | * |
||
| 92 | * @access public |
||
| 93 | * @return void |
||
| 94 | */ |
||
| 95 | public static function set_definitions() { |
||
| 105 | |||
| 106 | |||
| 107 | |||
| 108 | /** |
||
| 109 | * @return \EventEspresso\modules\ticket_selector\DisplayTicketSelector |
||
| 110 | */ |
||
| 111 | public static function ticketSelector() |
||
| 118 | |||
| 119 | |||
| 120 | /** |
||
| 121 | * gets the ball rolling |
||
| 122 | * |
||
| 123 | * @access public |
||
| 124 | * @param WP $WP |
||
| 125 | * @return void |
||
| 126 | */ |
||
| 127 | public function run( $WP ) {} |
||
| 128 | |||
| 129 | |||
| 130 | |||
| 131 | /** |
||
| 132 | * @return \EventEspresso\modules\ticket_selector\TicketSelectorIframeEmbedButton |
||
| 133 | */ |
||
| 134 | public static function getIframeEmbedButton() { |
||
| 140 | |||
| 141 | |||
| 142 | |||
| 143 | /** |
||
| 144 | * ticket_selector_iframe_embed_button |
||
| 145 | * |
||
| 146 | * @return void |
||
| 147 | * @throws \EE_Error |
||
| 148 | */ |
||
| 149 | public static function ticket_selector_iframe_embed_button() { |
||
| 153 | |||
| 154 | |||
| 155 | |||
| 156 | /** |
||
| 157 | * ticket_selector_iframe |
||
| 158 | * |
||
| 159 | * @return void |
||
| 160 | * @throws \DomainException |
||
| 161 | * @throws \EE_Error |
||
| 162 | */ |
||
| 163 | public function ticket_selector_iframe() { |
||
| 167 | |||
| 168 | |||
| 169 | |||
| 170 | /** |
||
| 171 | * creates buttons for selecting number of attendees for an event |
||
| 172 | * |
||
| 173 | * @access public |
||
| 174 | * @param WP_Post|int $event |
||
| 175 | * @param bool $view_details |
||
| 176 | * @return string |
||
| 177 | * @throws \EE_Error |
||
| 178 | */ |
||
| 179 | public static function display_ticket_selector( $event = NULL, $view_details = FALSE ) { |
||
| 182 | |||
| 183 | |||
| 184 | |||
| 185 | /** |
||
| 186 | * process_ticket_selections |
||
| 187 | * |
||
| 188 | * @access public |
||
| 189 | * @access public |
||
| 190 | * @return array or FALSE |
||
| 191 | * @throws \EE_Error |
||
| 192 | */ |
||
| 193 | public function process_ticket_selections() { |
||
| 197 | |||
| 198 | |||
| 199 | |||
| 200 | /** |
||
| 201 | * cancel_ticket_selections |
||
| 202 | * |
||
| 203 | * @access public |
||
| 204 | * @return string |
||
| 205 | */ |
||
| 206 | public static function cancel_ticket_selections() |
||
| 211 | |||
| 212 | |||
| 213 | |||
| 214 | /** |
||
| 215 | * load js |
||
| 216 | * |
||
| 217 | * @access public |
||
| 218 | * @return void |
||
| 219 | */ |
||
| 220 | public static function load_tckt_slctr_assets() { |
||
| 230 | |||
| 231 | |||
| 232 | |||
| 233 | /****************************** DEPRECATED ******************************/ |
||
| 234 | |||
| 235 | |||
| 236 | |||
| 237 | /** |
||
| 238 | * @deprecated |
||
| 239 | * @return string |
||
| 240 | * @throws \EE_Error |
||
| 241 | */ |
||
| 242 | public static function display_view_details_btn() |
||
| 247 | |||
| 248 | |||
| 249 | |||
| 250 | /** |
||
| 251 | * @deprecated |
||
| 252 | * @return string |
||
| 253 | * @throws \EE_Error |
||
| 254 | */ |
||
| 255 | public static function display_ticket_selector_submit() |
||
| 260 | |||
| 261 | |||
| 262 | |||
| 263 | /** |
||
| 264 | * @deprecated |
||
| 265 | * @param string $permalink_string |
||
| 266 | * @param int $id |
||
| 267 | * @param string $new_title |
||
| 268 | * @param string $new_slug |
||
| 269 | * @return string |
||
| 270 | */ |
||
| 271 | public static function iframe_code_button($permalink_string, $id, $new_title = '', $new_slug = '') |
||
| 283 | |||
| 284 | |||
| 285 | |||
| 286 | /** |
||
| 287 | * @deprecated |
||
| 288 | * @param int $ID |
||
| 289 | * @param string $external_url |
||
| 290 | * @return string |
||
| 291 | */ |
||
| 292 | public static function ticket_selector_form_open($ID = 0, $external_url = '') |
||
| 297 | |||
| 298 | |||
| 299 | |||
| 300 | /** |
||
| 301 | * @deprecated |
||
| 302 | * @return string |
||
| 303 | */ |
||
| 304 | public static function ticket_selector_form_close() |
||
| 309 | |||
| 310 | |||
| 311 | |||
| 312 | /** |
||
| 313 | * @deprecated |
||
| 314 | * @return string |
||
| 315 | */ |
||
| 316 | public static function no_tkt_slctr_end_dv() |
||
| 321 | |||
| 322 | |||
| 323 | |||
| 324 | /** |
||
| 325 | * @deprecated 4.9.13 |
||
| 326 | * @return string |
||
| 327 | */ |
||
| 328 | public static function tkt_slctr_end_dv() |
||
| 332 | |||
| 333 | |||
| 334 | |||
| 335 | /** |
||
| 336 | * @deprecated |
||
| 337 | * @return string |
||
| 338 | */ |
||
| 339 | public static function clear_tkt_slctr() |
||
| 343 | |||
| 344 | |||
| 345 | |||
| 346 | /** |
||
| 347 | * @deprecated |
||
| 348 | */ |
||
| 349 | public static function load_tckt_slctr_assets_admin() |
||
| 360 | |||
| 361 | |||
| 362 | } |
||
| 363 | // End of file EED_Ticket_Selector.module.php |
||
| 365 |
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 theSoncalls the wrong method in the parent class.