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