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\UserField.Event' |
||
| 61 | ); |
||
| 62 | |||
| 63 | private static $defaults = array( |
||
| 64 | 'Capacity' => 50 |
||
| 65 | ); |
||
| 66 | |||
| 67 | private static $translate = array( |
||
| 68 | 'SuccessMessage', |
||
| 69 | 'SuccessMessageMail' |
||
| 70 | ); |
||
| 71 | |||
| 72 | public function updateCMSFields(FieldList $fields) |
||
| 119 | |||
| 120 | /** |
||
| 121 | * Trigger actions after write |
||
| 122 | */ |
||
| 123 | public function onAfterWrite() |
||
| 128 | |||
| 129 | /** |
||
| 130 | * Creates and sets up the default fields |
||
| 131 | */ |
||
| 132 | public function createDefaultFields() |
||
| 142 | |||
| 143 | /** |
||
| 144 | * Extend the page actions with an start check in action |
||
| 145 | * |
||
| 146 | * @param FieldList $actions |
||
| 147 | */ |
||
| 148 | public function updateCMSActions(FieldList $actions) |
||
| 164 | |||
| 165 | /** |
||
| 166 | * Get the leftover capacity |
||
| 167 | * |
||
| 168 | * @return int |
||
| 169 | */ |
||
| 170 | public function getAvailability() |
||
| 174 | |||
| 175 | /** |
||
| 176 | * Check if the event is expired, either by unavailable tickets or because the date has passed |
||
| 177 | * |
||
| 178 | * @return bool |
||
| 179 | */ |
||
| 180 | public function getEventExpired() |
||
| 192 | |||
| 193 | /** |
||
| 194 | * Get only the attendees who are certain to attend |
||
| 195 | * Fixme: Using callback filter instead of join, because join gives ambiguous error on 'EventID' |
||
| 196 | * |
||
| 197 | * @return \ArrayList |
||
| 198 | */ |
||
| 199 | public function getGuestList() |
||
| 205 | |||
| 206 | /** |
||
| 207 | * Get the success message |
||
| 208 | * |
||
| 209 | * @return mixed|string |
||
| 210 | */ |
||
| 211 | View Code Duplication | public function getSuccessContent() |
|
| 219 | |||
| 220 | /** |
||
| 221 | * Get the mail message |
||
| 222 | * |
||
| 223 | * @return mixed|string |
||
| 224 | */ |
||
| 225 | View Code Duplication | public function getMailContent() |
|
| 233 | |||
| 234 | /** |
||
| 235 | * Get the Ticket logo |
||
| 236 | * |
||
| 237 | * @return \Image |
||
| 238 | */ |
||
| 239 | public function getMailLogo() |
||
| 243 | |||
| 244 | /** |
||
| 245 | * Check if the current event can have tickets |
||
| 246 | * |
||
| 247 | * @return bool |
||
| 248 | */ |
||
| 249 | public function canCreateTickets() |
||
| 258 | |||
| 259 | /** |
||
| 260 | * Get the calendar controller |
||
| 261 | * |
||
| 262 | * @return CalendarEvent_Controller |
||
| 263 | */ |
||
| 264 | public function getController() |
||
| 270 | } |
||
| 271 |
This check marks private properties in classes that are never used. Those properties can be removed.