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 | protected $cachedGuestList; |
||
73 | |||
74 | public function updateCMSFields(FieldList $fields) |
||
128 | |||
129 | /** |
||
130 | * Trigger actions after write |
||
131 | */ |
||
132 | public function onAfterWrite() |
||
137 | |||
138 | /** |
||
139 | * Creates and sets up the default fields |
||
140 | */ |
||
141 | public function createDefaultFields() |
||
151 | |||
152 | /** |
||
153 | * Extend the page actions with an start check in action |
||
154 | * |
||
155 | * @param FieldList $actions |
||
156 | */ |
||
157 | public function updateCMSActions(FieldList $actions) |
||
173 | |||
174 | /** |
||
175 | * Get the guest list status used in the summary fields |
||
176 | */ |
||
177 | public function getGuestListStatus() |
||
183 | |||
184 | /** |
||
185 | * Get the leftover capacity |
||
186 | * |
||
187 | * @return int |
||
188 | */ |
||
189 | public function getAvailability() |
||
193 | |||
194 | /** |
||
195 | * Check if the tickets are still available |
||
196 | * |
||
197 | * @return bool |
||
198 | */ |
||
199 | public function getTicketsAvailable() |
||
203 | |||
204 | /** |
||
205 | * Check if the tickets are sold out |
||
206 | * @return bool |
||
207 | */ |
||
208 | public function getTicketsSoldOut() |
||
212 | |||
213 | /** |
||
214 | * get The sale start date |
||
215 | * |
||
216 | * @return \SS_DateTime |
||
217 | */ |
||
218 | public function getTicketSaleStartDate() |
||
232 | |||
233 | /** |
||
234 | * Check if the event is expired, either by unavailable tickets or because the date has passed |
||
235 | * |
||
236 | * @return bool |
||
237 | */ |
||
238 | public function getEventExpired() |
||
250 | |||
251 | /** |
||
252 | * Check if the ticket sale is still pending |
||
253 | * |
||
254 | * @return bool |
||
255 | */ |
||
256 | public function getTicketSalePending() |
||
260 | |||
261 | /** |
||
262 | * Get only the attendees who are certain to attend |
||
263 | * Also includes attendees without any reservation, these are manually added |
||
264 | * |
||
265 | * @return \DataList |
||
266 | */ |
||
267 | public function getGuestList() |
||
281 | |||
282 | /** |
||
283 | * Get the checked in count for display in templates |
||
284 | * |
||
285 | * @return string |
||
286 | */ |
||
287 | public function getCheckedInCount() |
||
293 | |||
294 | /** |
||
295 | * Get the success message |
||
296 | * |
||
297 | * @return mixed|string |
||
298 | */ |
||
299 | View Code Duplication | public function getSuccessContent() |
|
307 | |||
308 | /** |
||
309 | * Get the mail message |
||
310 | * |
||
311 | * @return mixed|string |
||
312 | */ |
||
313 | View Code Duplication | public function getMailContent() |
|
321 | |||
322 | /** |
||
323 | * Get the Ticket logo |
||
324 | * |
||
325 | * @return \Image |
||
326 | */ |
||
327 | public function getMailLogo() |
||
331 | |||
332 | /** |
||
333 | * Check if the current event can have tickets |
||
334 | * |
||
335 | * @return bool |
||
336 | */ |
||
337 | public function canCreateTickets() |
||
346 | |||
347 | /** |
||
348 | * Get the calendar controller |
||
349 | * |
||
350 | * @return CalendarEvent_Controller |
||
351 | */ |
||
352 | public function getController() |
||
358 | } |
||
359 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: