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 |
||
40 | class TicketExtension extends DataExtension |
||
41 | { |
||
42 | /** |
||
43 | * @var CalendarEvent_Controller |
||
44 | */ |
||
45 | protected $controller; |
||
46 | |||
47 | private static $db = array( |
||
|
|||
48 | 'Capacity' => 'Int', |
||
49 | 'OrderMin' => 'Int', |
||
50 | 'OrderMax' => 'Int', |
||
51 | 'SuccessMessage' => 'HTMLText', |
||
52 | 'SuccessMessageMail' => 'HTMLText' |
||
53 | ); |
||
54 | |||
55 | private static $has_many = array( |
||
56 | 'Tickets' => 'Broarm\EventTickets\Ticket.Event', |
||
57 | 'Reservations' => 'Broarm\EventTickets\Reservation.Event', |
||
58 | 'Attendees' => 'Broarm\EventTickets\Attendee.Event', |
||
59 | 'WaitingList' => 'Broarm\EventTickets\WaitingListRegistration.Event', |
||
60 | 'Fields' => 'Broarm\EventTickets\AttendeeExtraField.Event' |
||
61 | ); |
||
62 | |||
63 | private static $defaults = array( |
||
64 | 'Capacity' => 50, |
||
65 | 'OrderMin' => 1, |
||
66 | 'OrderMax' => 5 |
||
67 | ); |
||
68 | |||
69 | private static $translate = array( |
||
70 | 'SuccessMessage', |
||
71 | 'SuccessMessageMail' |
||
72 | ); |
||
73 | |||
74 | public function updateCMSFields(FieldList $fields) |
||
129 | |||
130 | /** |
||
131 | * Trigger actions after write |
||
132 | */ |
||
133 | public function onAfterWrite() |
||
138 | |||
139 | /** |
||
140 | * Creates and sets up the default fields |
||
141 | */ |
||
142 | public function createDefaultFields() |
||
165 | |||
166 | /** |
||
167 | * Extend the page actions with an start check in action |
||
168 | * |
||
169 | * @param FieldList $actions |
||
170 | */ |
||
171 | public function updateCMSActions(FieldList $actions) |
||
187 | |||
188 | /** |
||
189 | * Get the leftover capacity |
||
190 | * |
||
191 | * @return int |
||
192 | */ |
||
193 | public function getAvailability() |
||
197 | |||
198 | /** |
||
199 | * Get the success message |
||
200 | * |
||
201 | * @return mixed|string |
||
202 | */ |
||
203 | View Code Duplication | public function getSuccessContent() |
|
211 | |||
212 | /** |
||
213 | * Get the mail message |
||
214 | * |
||
215 | * @return mixed|string |
||
216 | */ |
||
217 | View Code Duplication | public function getMailContent() |
|
225 | |||
226 | /** |
||
227 | * Get the Ticket logo |
||
228 | * |
||
229 | * @return \Image |
||
230 | */ |
||
231 | public function getMailLogo() |
||
235 | |||
236 | /** |
||
237 | * Check if the current event can have tickets |
||
238 | * |
||
239 | * @return bool |
||
240 | */ |
||
241 | public function canCreateTickets() |
||
250 | |||
251 | /** |
||
252 | * Get the calendar controller |
||
253 | * |
||
254 | * @return CalendarEvent_Controller |
||
255 | */ |
||
256 | public function getController() |
||
262 | } |
||
263 |
This check marks private properties in classes that are never used. Those properties can be removed.