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) |
||
134 | |||
135 | /** |
||
136 | * Trigger actions after write |
||
137 | */ |
||
138 | public function onAfterWrite() |
||
143 | |||
144 | /** |
||
145 | * Creates and sets up the default fields |
||
146 | */ |
||
147 | public function createDefaultFields() |
||
157 | |||
158 | /** |
||
159 | * Extend the page actions with an start check in action |
||
160 | * |
||
161 | * @param FieldList $actions |
||
162 | */ |
||
163 | public function updateCMSActions(FieldList $actions) |
||
179 | |||
180 | /** |
||
181 | * Get the leftover capacity |
||
182 | * |
||
183 | * @return int |
||
184 | */ |
||
185 | public function getAvailability() |
||
189 | |||
190 | /** |
||
191 | * Get only the attendees who are certain to attend |
||
192 | * Fixme: Using callback filter instead of join, because join gives ambiguous error on 'EventID' |
||
193 | * |
||
194 | * @return \ArrayList |
||
195 | */ |
||
196 | public function getGuestList() |
||
202 | |||
203 | /** |
||
204 | * Get the success message |
||
205 | * |
||
206 | * @return mixed|string |
||
207 | */ |
||
208 | View Code Duplication | public function getSuccessContent() |
|
216 | |||
217 | /** |
||
218 | * Get the mail message |
||
219 | * |
||
220 | * @return mixed|string |
||
221 | */ |
||
222 | View Code Duplication | public function getMailContent() |
|
230 | |||
231 | /** |
||
232 | * Get the Ticket logo |
||
233 | * |
||
234 | * @return \Image |
||
235 | */ |
||
236 | public function getMailLogo() |
||
240 | |||
241 | /** |
||
242 | * Check if the current event can have tickets |
||
243 | * |
||
244 | * @return bool |
||
245 | */ |
||
246 | public function canCreateTickets() |
||
255 | |||
256 | /** |
||
257 | * Get the calendar controller |
||
258 | * |
||
259 | * @return CalendarEvent_Controller |
||
260 | */ |
||
261 | public function getController() |
||
267 | } |
||
268 |
This check marks private properties in classes that are never used. Those properties can be removed.