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 |
||
36 | class TicketExtension extends DataExtension |
||
37 | { |
||
38 | /** |
||
39 | * @var CalendarEvent_Controller |
||
40 | */ |
||
41 | protected $controller; |
||
42 | |||
43 | private static $db = array( |
||
|
|||
44 | 'Capacity' => 'Int', |
||
45 | 'SuccessMessage' => 'HTMLText', |
||
46 | 'SuccessMessageMail' => 'HTMLText' |
||
47 | ); |
||
48 | |||
49 | private static $has_many = array( |
||
50 | 'Tickets' => 'Broarm\EventTickets\Ticket.Event', |
||
51 | 'Reservations' => 'Broarm\EventTickets\Reservation.Event', |
||
52 | 'Attendees' => 'Broarm\EventTickets\Attendee.Event' |
||
53 | ); |
||
54 | |||
55 | public function updateCMSFields(FieldList $fields) |
||
92 | |||
93 | /** |
||
94 | * Extend the page actions with an start check in action |
||
95 | * |
||
96 | * @param FieldList $actions |
||
97 | */ |
||
98 | public function updateCMSActions(FieldList $actions) |
||
114 | |||
115 | /** |
||
116 | * Get the leftover capacity |
||
117 | * |
||
118 | * @return int |
||
119 | */ |
||
120 | public function getAvailability() |
||
124 | |||
125 | /** |
||
126 | * Get the success message |
||
127 | * |
||
128 | * @return mixed|string |
||
129 | */ |
||
130 | View Code Duplication | public function getSuccessContent() |
|
138 | |||
139 | /** |
||
140 | * Get the mail message |
||
141 | * |
||
142 | * @return mixed|string |
||
143 | */ |
||
144 | View Code Duplication | public function getMailContent() |
|
152 | |||
153 | /** |
||
154 | * Check if the current event can have tickets |
||
155 | * |
||
156 | * @return bool |
||
157 | */ |
||
158 | public function canCreateTickets() |
||
167 | |||
168 | /** |
||
169 | * Get the calendar controller |
||
170 | * |
||
171 | * @return CalendarEvent_Controller |
||
172 | */ |
||
173 | public function getController() |
||
179 | } |
||
180 |
This check marks private properties in classes that are never used. Those properties can be removed.