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