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 |
||
| 22 | abstract class TicketSelectorRow |
||
| 23 | { |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var EE_Ticket $ticket |
||
| 27 | */ |
||
| 28 | protected $ticket; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var int $total_tickets |
||
| 32 | */ |
||
| 33 | protected $total_tickets; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @var int $max_attendees |
||
| 37 | */ |
||
| 38 | protected $max_attendees; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @var string $date_format |
||
| 42 | */ |
||
| 43 | protected $date_format; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @var int $EVT_ID |
||
| 47 | */ |
||
| 48 | protected $EVT_ID; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @var string $event_status |
||
| 52 | */ |
||
| 53 | protected $event_status; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @var boolean $required_ticket_sold_out |
||
| 57 | */ |
||
| 58 | protected $required_ticket_sold_out; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @var string $ticket_status_display |
||
| 62 | */ |
||
| 63 | protected $ticket_status_display; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @var int $max |
||
| 67 | */ |
||
| 68 | protected $max = 0; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @var int $min |
||
| 72 | */ |
||
| 73 | protected $min = 0; |
||
| 74 | |||
| 75 | /** |
||
| 76 | * @var float $ticket_price |
||
| 77 | */ |
||
| 78 | protected $ticket_price = 0.00; |
||
| 79 | |||
| 80 | /** |
||
| 81 | * @var bool $ticket_bundle |
||
| 82 | */ |
||
| 83 | protected $ticket_bundle = false; |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @var string $ticket_status_id |
||
| 87 | */ |
||
| 88 | protected $ticket_status_id = EE_Ticket::sold_out; |
||
| 89 | |||
| 90 | /** |
||
| 91 | * @var string $ticket_status_html |
||
| 92 | */ |
||
| 93 | protected $ticket_status_html = 'ticket-sales-sold-out'; |
||
| 94 | |||
| 95 | /** |
||
| 96 | * @var string $status_class |
||
| 97 | */ |
||
| 98 | protected $status_class = 'ticket-sales-sold-out lt-grey-text'; |
||
| 99 | |||
| 100 | |||
| 101 | |||
| 102 | /** |
||
| 103 | * @param EE_Ticket $ticket |
||
| 104 | * @param int $max_attendees |
||
| 105 | * @param string $date_format |
||
| 106 | * @param string $event_status |
||
| 107 | * @param bool $required_ticket_sold_out |
||
| 108 | * @param int $total_tickets |
||
| 109 | * @throws EE_Error |
||
| 110 | * @throws UnexpectedEntityException |
||
| 111 | */ |
||
| 112 | public function __construct( |
||
| 128 | |||
| 129 | |||
| 130 | |||
| 131 | /** |
||
| 132 | * getTicketStatusClasses |
||
| 133 | * |
||
| 134 | * @param int $remaining |
||
| 135 | * @return void |
||
| 136 | * @throws EE_Error |
||
| 137 | */ |
||
| 138 | protected function setTicketStatusClasses($remaining = 0) |
||
| 185 | |||
| 186 | |||
| 187 | /** |
||
| 188 | * @return string |
||
| 189 | */ |
||
| 190 | public function getTicketStatusDisplay() |
||
| 194 | |||
| 195 | |||
| 196 | |||
| 197 | /** |
||
| 198 | * setTicketStatusDisplay |
||
| 199 | * |
||
| 200 | * @param int $remaining |
||
| 201 | * @throws EE_Error |
||
| 202 | */ |
||
| 203 | protected function setTicketStatusDisplay($remaining) { |
||
| 223 | |||
| 224 | |||
| 225 | |||
| 226 | /** |
||
| 227 | * registrationClosed |
||
| 228 | */ |
||
| 229 | protected function registrationClosed() |
||
| 239 | |||
| 240 | |||
| 241 | |||
| 242 | /** |
||
| 243 | * ticketsSoldOut |
||
| 244 | */ |
||
| 245 | protected function ticketsSoldOut() |
||
| 255 | |||
| 256 | |||
| 257 | |||
| 258 | /** |
||
| 259 | * ticketsSalesPending |
||
| 260 | * |
||
| 261 | * @throws EE_Error |
||
| 262 | */ |
||
| 263 | protected function ticketsSalesPending() |
||
| 287 | |||
| 288 | |||
| 289 | |||
| 290 | /** |
||
| 291 | * notEnoughTicketsAvailable |
||
| 292 | */ |
||
| 293 | protected function notEnoughTicketsAvailable() |
||
| 307 | |||
| 308 | |||
| 309 | |||
| 310 | /** |
||
| 311 | * setTicketMinAndMax |
||
| 312 | * |
||
| 313 | * @param int $remaining |
||
| 314 | * @return void |
||
| 315 | * @throws EE_Error |
||
| 316 | */ |
||
| 317 | protected function setTicketMinAndMax($remaining) |
||
| 335 | |||
| 336 | |||
| 337 | /** |
||
| 338 | * Allow plugins to hook in and abort the generation and display of this row to do |
||
| 339 | * something elseif they want. |
||
| 340 | * For an addon to abort things, all they have to do is register a filter with this hook, and |
||
| 341 | * return a value that is NOT false. Whatever is returned gets echoed instead of the |
||
| 342 | * current row. |
||
| 343 | * |
||
| 344 | * @return string|bool |
||
| 345 | */ |
||
| 346 | View Code Duplication | protected function getFilteredRowHtml() { |
|
| 361 | |||
| 362 | |||
| 363 | |||
| 364 | /** |
||
| 365 | * Allow plugins to hook in and abort the generation and display of the contents of this |
||
| 366 | * row to do something elseif they want. |
||
| 367 | * For an addon to abort things, all they have to do is register a filter with this hook, and |
||
| 368 | * return a value that is NOT false. Whatever is returned gets echoed instead of the |
||
| 369 | * current row. |
||
| 370 | * |
||
| 371 | * @return string|bool |
||
| 372 | */ |
||
| 373 | View Code Duplication | protected function getFilteredRowContents() |
|
| 389 | |||
| 390 | } |
||
| 391 | // End of file TicketSelectorRow.php |
||
| 393 |