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 |
||
44 | class TicketExtension extends DataExtension |
||
45 | { |
||
46 | /** |
||
47 | * @var CalendarEvent_Controller |
||
48 | */ |
||
49 | protected $controller; |
||
50 | |||
51 | private static $db = array( |
||
|
|||
52 | 'Capacity' => 'Int', |
||
53 | 'OrderMin' => 'Int', |
||
54 | 'OrderMax' => 'Int', |
||
55 | 'SuccessMessage' => 'HTMLText', |
||
56 | 'SuccessMessageMail' => 'HTMLText' |
||
57 | ); |
||
58 | |||
59 | private static $has_many = array( |
||
60 | 'Tickets' => 'Broarm\EventTickets\Ticket.Event', |
||
61 | 'Reservations' => 'Broarm\EventTickets\Reservation.Event', |
||
62 | 'Attendees' => 'Broarm\EventTickets\Attendee.Event', |
||
63 | 'WaitingList' => 'Broarm\EventTickets\WaitingListRegistration.Event', |
||
64 | 'Fields' => 'Broarm\EventTickets\AttendeeExtraField.Event' |
||
65 | ); |
||
66 | |||
67 | private static $defaults = array( |
||
68 | 'Capacity' => 50, |
||
69 | 'OrderMin' => 1, |
||
70 | 'OrderMax' => 5 |
||
71 | ); |
||
72 | |||
73 | private static $translate = array( |
||
74 | 'SuccessMessage', |
||
75 | 'SuccessMessageMail' |
||
76 | ); |
||
77 | |||
78 | public function updateCMSFields(FieldList $fields) |
||
130 | |||
131 | /** |
||
132 | * Trigger actions after write |
||
133 | */ |
||
134 | public function onAfterWrite() |
||
139 | |||
140 | /** |
||
141 | * Creates and sets up the default fields |
||
142 | */ |
||
143 | public function createDefaultFields() |
||
166 | |||
167 | /** |
||
168 | * Extend the page actions with an start check in action |
||
169 | * |
||
170 | * @param FieldList $actions |
||
171 | */ |
||
172 | public function updateCMSActions(FieldList $actions) |
||
188 | |||
189 | /** |
||
190 | * Get the leftover capacity |
||
191 | * |
||
192 | * @return int |
||
193 | */ |
||
194 | public function getAvailability() |
||
198 | |||
199 | /** |
||
200 | * Get only the attendees who are certain to attend |
||
201 | * Fixme: Using callback filter instead of join, because join gives ambiguous error on 'EventID' |
||
202 | * |
||
203 | * @return \ArrayList |
||
204 | */ |
||
205 | public function getGuestList() |
||
211 | |||
212 | /** |
||
213 | * Get the success message |
||
214 | * |
||
215 | * @return mixed|string |
||
216 | */ |
||
217 | View Code Duplication | public function getSuccessContent() |
|
225 | |||
226 | /** |
||
227 | * Get the mail message |
||
228 | * |
||
229 | * @return mixed|string |
||
230 | */ |
||
231 | View Code Duplication | public function getMailContent() |
|
239 | |||
240 | /** |
||
241 | * Get the Ticket logo |
||
242 | * |
||
243 | * @return \Image |
||
244 | */ |
||
245 | public function getMailLogo() |
||
249 | |||
250 | /** |
||
251 | * Check if the current event can have tickets |
||
252 | * |
||
253 | * @return bool |
||
254 | */ |
||
255 | public function canCreateTickets() |
||
264 | |||
265 | /** |
||
266 | * Get the calendar controller |
||
267 | * |
||
268 | * @return CalendarEvent_Controller |
||
269 | */ |
||
270 | public function getController() |
||
276 | } |
||
277 |
This check marks private properties in classes that are never used. Those properties can be removed.