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 |
||
13 | class CheckInValidator extends Object |
||
14 | { |
||
15 | const MESSAGE_NO_CODE = 'MESSAGE_NO_CODE'; |
||
16 | const MESSAGE_CODE_NOT_FOUND = 'MESSAGE_CODE_NOT_FOUND'; |
||
17 | const MESSAGE_TICKET_CANCELLED = 'MESSAGE_TICKET_CANCELLED'; |
||
18 | const MESSAGE_ALREADY_CHECKED_IN = 'MESSAGE_ALREADY_CHECKED_IN'; |
||
19 | const MESSAGE_CHECK_OUT_SUCCESS = 'MESSAGE_CHECK_OUT_SUCCESS'; |
||
20 | const MESSAGE_CHECK_IN_SUCCESS = 'MESSAGE_CHECK_IN_SUCCESS'; |
||
21 | |||
22 | const MESSAGE_TYPE_GOOD = 'Good'; |
||
23 | const MESSAGE_TYPE_WARNING = 'Warning'; |
||
24 | const MESSAGE_TYPE_BAD = 'Bad'; |
||
25 | |||
26 | /** |
||
27 | * Allow people to check in and out |
||
28 | * |
||
29 | * @config |
||
30 | * @var bool |
||
31 | */ |
||
32 | private static $allow_checkout = false; |
||
|
|||
33 | |||
34 | /** |
||
35 | * @var Attendee |
||
36 | */ |
||
37 | protected $attendee = null; |
||
38 | |||
39 | /** |
||
40 | * Validate the given ticket code |
||
41 | * |
||
42 | * @param null|string $ticketCode |
||
43 | * |
||
44 | * @return array |
||
45 | */ |
||
46 | public function validate($ticketCode = null) { |
||
100 | |||
101 | /** |
||
102 | * Get the attendee instance |
||
103 | * |
||
104 | * @return Attendee |
||
105 | */ |
||
106 | public function getAttendee() |
||
110 | |||
111 | /** |
||
112 | * Translate the given type to a readable message |
||
113 | * |
||
114 | * @param $message string |
||
115 | * |
||
116 | * @return string |
||
117 | */ |
||
118 | private static function message($message) { |
||
121 | } |
This check marks private properties in classes that are never used. Those properties can be removed.