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 |
||
60 | class Attendee extends DataObject |
||
61 | { |
||
62 | /** |
||
63 | * Set this to true when you want to have a QR code that opens the check in page and validates the code. |
||
64 | * The validation is only done with proper authorisation so guest cannot check themselves in by mistake. |
||
65 | * By default only the ticket number is translated to an QR code. (for use with USB QR scanners) |
||
66 | * |
||
67 | * @var bool |
||
68 | */ |
||
69 | private static $qr_as_link = false; |
||
1 ignored issue
–
show
|
|||
70 | |||
71 | private static $default_fields = array( |
||
1 ignored issue
–
show
|
|||
72 | 'FirstName' => array( |
||
73 | 'FieldType' => 'TextField' |
||
74 | ), |
||
75 | 'Surname' => array( |
||
76 | 'FieldType' => 'TextField' |
||
77 | ), |
||
78 | 'Email' => array( |
||
79 | 'FieldType' => 'TextField' |
||
80 | ) |
||
81 | ); |
||
82 | |||
83 | private static $table_fields = array( |
||
1 ignored issue
–
show
|
|||
84 | 'Title', |
||
85 | 'Email' |
||
86 | ); |
||
87 | |||
88 | private static $db = array( |
||
2 ignored issues
–
show
|
|||
89 | 'Title' => 'Varchar(255)', |
||
90 | 'TicketReceiver' => 'Boolean', |
||
91 | 'TicketCode' => 'Varchar(255)', |
||
92 | 'CheckedIn' => 'Boolean' |
||
93 | ); |
||
94 | |||
95 | private static $indexes = array( |
||
96 | 'TicketCode' => 'unique("TicketCode")' |
||
97 | ); |
||
98 | |||
99 | private static $has_one = array( |
||
2 ignored issues
–
show
|
|||
100 | 'Reservation' => 'Broarm\EventTickets\Reservation', |
||
101 | 'Ticket' => 'Broarm\EventTickets\Ticket', |
||
102 | 'Event' => 'CalendarEvent', |
||
103 | 'Member' => 'Member', |
||
104 | 'TicketQRCode' => 'Image', |
||
105 | 'TicketFile' => 'File' |
||
106 | ); |
||
107 | |||
108 | private static $many_many = array( |
||
2 ignored issues
–
show
|
|||
109 | 'Fields' => 'Broarm\EventTickets\AttendeeExtraField' |
||
110 | ); |
||
111 | |||
112 | private static $many_many_extraFields = array( |
||
2 ignored issues
–
show
|
|||
113 | 'Fields' => array( |
||
114 | 'Value' => 'Varchar(255)' |
||
115 | ) |
||
116 | ); |
||
117 | |||
118 | private static $summary_fields = array( |
||
2 ignored issues
–
show
|
|||
119 | 'Title' => 'Name', |
||
120 | 'Ticket.Title' => 'Ticket', |
||
121 | 'TicketCode' => 'Ticket #', |
||
122 | 'CheckedIn.Nice' => 'Checked in', |
||
123 | ); |
||
124 | |||
125 | public function getCMSFields() |
||
153 | |||
154 | /** |
||
155 | * Utility method for fetching the default field, FirstName, value |
||
156 | * |
||
157 | * @return string |
||
158 | */ |
||
159 | View Code Duplication | public function getFirstName() |
|
167 | |||
168 | /** |
||
169 | * Utility method for fetching the default field, Surname, value |
||
170 | * |
||
171 | * @return string |
||
172 | */ |
||
173 | View Code Duplication | public function getSurname() |
|
181 | |||
182 | /** |
||
183 | * Get the combined first and last nave for dispay on the ticket and attendee list |
||
184 | * |
||
185 | * @return string |
||
186 | */ |
||
187 | public function getName() |
||
198 | |||
199 | /** |
||
200 | * Utility method for fetching the default field, Email, value |
||
201 | * |
||
202 | * @return string |
||
203 | */ |
||
204 | View Code Duplication | public function getEmail() |
|
212 | |||
213 | /** |
||
214 | * Set the title and ticket code before writing |
||
215 | */ |
||
216 | public function onBeforeWrite() |
||
228 | |||
229 | /** |
||
230 | * Delete any stray files before deleting the object |
||
231 | */ |
||
232 | public function onBeforeDelete() |
||
247 | |||
248 | /** |
||
249 | * Get the table fields for this attendee |
||
250 | * |
||
251 | * @return ArrayList |
||
252 | */ |
||
253 | public function getTableFields() |
||
264 | |||
265 | /** |
||
266 | * Get the unnamespaced singular name for display in the CMS |
||
267 | * |
||
268 | * @return string |
||
269 | */ |
||
270 | public function singular_name() |
||
275 | |||
276 | /** |
||
277 | * Generate a unique ticket id |
||
278 | * Serves as the base for the QR code and ticket file |
||
279 | * |
||
280 | * @return string |
||
281 | */ |
||
282 | public function generateTicketCode() |
||
286 | |||
287 | /** |
||
288 | * Create a QRCode for the attendee based on the Ticket code |
||
289 | * |
||
290 | * @param Folder $folder |
||
291 | * |
||
292 | * @return Image |
||
293 | */ |
||
294 | public function createQRCode(Folder $folder) |
||
326 | |||
327 | /** |
||
328 | * Creates a printable ticket for the attendee |
||
329 | * |
||
330 | * @param Folder $folder |
||
331 | * |
||
332 | * @return File |
||
333 | */ |
||
334 | public function createTicketFile(Folder $folder) |
||
369 | |||
370 | public function canView($member = null) |
||
374 | |||
375 | public function canEdit($member = null) |
||
379 | |||
380 | public function canDelete($member = null) |
||
384 | |||
385 | public function canCreate($member = null) |
||
389 | } |
||
390 |
This check marks private properties in classes that are never used. Those properties can be removed.