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' => 'TextField', |
||
73 | 'Surname' => 'TextField', |
||
74 | 'Email' => 'EmailField', |
||
75 | ); |
||
76 | |||
77 | private static $table_fields = array( |
||
1 ignored issue
–
show
|
|||
78 | 'Title', |
||
79 | 'Email' |
||
80 | ); |
||
81 | |||
82 | private static $db = array( |
||
2 ignored issues
–
show
|
|||
83 | 'Title' => 'Varchar(255)', |
||
84 | 'TicketReceiver' => 'Boolean', |
||
85 | 'TicketCode' => 'Varchar(255)', |
||
86 | 'CheckedIn' => 'Boolean' |
||
87 | ); |
||
88 | |||
89 | private static $indexes = array( |
||
90 | 'TicketCode' => 'unique("TicketCode")' |
||
91 | ); |
||
92 | |||
93 | private static $has_one = array( |
||
2 ignored issues
–
show
|
|||
94 | 'Reservation' => 'Broarm\EventTickets\Reservation', |
||
95 | 'Ticket' => 'Broarm\EventTickets\Ticket', |
||
96 | 'Event' => 'CalendarEvent', |
||
97 | 'Member' => 'Member', |
||
98 | 'TicketQRCode' => 'Image', |
||
99 | 'TicketFile' => 'File' |
||
100 | ); |
||
101 | |||
102 | private static $many_many = array( |
||
2 ignored issues
–
show
|
|||
103 | 'Fields' => 'Broarm\EventTickets\AttendeeExtraField' |
||
104 | ); |
||
105 | |||
106 | private static $many_many_extraFields = array( |
||
2 ignored issues
–
show
|
|||
107 | 'Fields' => array( |
||
108 | 'Value' => 'Varchar(255)' |
||
109 | ) |
||
110 | ); |
||
111 | |||
112 | private static $summary_fields = array( |
||
2 ignored issues
–
show
|
|||
113 | 'Title' => 'Name', |
||
114 | 'Email' => 'Email', |
||
115 | 'TicketCode' => 'Ticket', |
||
116 | 'CheckedInSummary' => 'Checked in', |
||
117 | ); |
||
118 | |||
119 | public function getCMSFields() |
||
149 | |||
150 | /** |
||
151 | * Utility method for fetching the default field, FirstName, value |
||
152 | * |
||
153 | * @return string |
||
154 | */ |
||
155 | View Code Duplication | public function getFirstName() |
|
163 | |||
164 | /** |
||
165 | * Utility method for fetching the default field, Surname, value |
||
166 | * |
||
167 | * @return string |
||
168 | */ |
||
169 | View Code Duplication | public function getSurname() |
|
177 | |||
178 | /** |
||
179 | * Get the combined first and last nave for dispay on the ticket and attendee list |
||
180 | * |
||
181 | * @return string |
||
182 | */ |
||
183 | public function getName() |
||
193 | |||
194 | /** |
||
195 | * Utility method for fetching the default field, Email, value |
||
196 | * |
||
197 | * @return string |
||
198 | */ |
||
199 | View Code Duplication | public function getEmail() |
|
207 | |||
208 | /** |
||
209 | * Set the title and ticket code before writing |
||
210 | */ |
||
211 | public function onBeforeWrite() |
||
223 | |||
224 | /** |
||
225 | * Delete any stray files before deleting the object |
||
226 | */ |
||
227 | public function onBeforeDelete() |
||
242 | |||
243 | /** |
||
244 | * Get the table fields for this attendee |
||
245 | * |
||
246 | * @return ArrayList |
||
247 | */ |
||
248 | public function getTableFields() |
||
259 | |||
260 | /** |
||
261 | * Get the unnamespaced singular name for display in the CMS |
||
262 | * |
||
263 | * @return string |
||
264 | */ |
||
265 | public function singular_name() |
||
270 | |||
271 | /** |
||
272 | * Return the checked in state for use in grid fields |
||
273 | * |
||
274 | * @return LiteralField |
||
275 | */ |
||
276 | public function getCheckedInSummary() |
||
285 | |||
286 | /** |
||
287 | * Generate a unique ticket id |
||
288 | * Serves as the base for the QR code and ticket file |
||
289 | * |
||
290 | * @return string |
||
291 | */ |
||
292 | public function generateTicketCode() |
||
296 | |||
297 | /** |
||
298 | * Create a QRCode for the attendee based on the Ticket code |
||
299 | * |
||
300 | * @param Folder $folder |
||
301 | * |
||
302 | * @return Image |
||
303 | */ |
||
304 | public function createQRCode(Folder $folder) |
||
336 | |||
337 | /** |
||
338 | * Creates a printable ticket for the attendee |
||
339 | * |
||
340 | * @param Folder $folder |
||
341 | * |
||
342 | * @return File |
||
343 | */ |
||
344 | public function createTicketFile(Folder $folder) |
||
379 | |||
380 | public function canView($member = null) |
||
384 | |||
385 | public function canEdit($member = null) |
||
389 | |||
390 | public function canDelete($member = null) |
||
394 | |||
395 | public function canCreate($member = null) |
||
399 | } |
||
400 |
This check marks private properties in classes that are never used. Those properties can be removed.