| Conditions | 8 |
| Paths | 6 |
| Total Lines | 54 |
| Code Lines | 30 |
| Lines | 14 |
| Ratio | 25.93 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 46 | public function validate($ticketCode = null) { |
||
| 47 | |||
| 48 | // Check if a code is given to the validator |
||
| 49 | if (!isset($ticketCode)) { |
||
| 50 | return array( |
||
| 51 | 'Code' => self::MESSAGE_NO_CODE, |
||
| 52 | 'Message' => self::message(self::MESSAGE_NO_CODE), |
||
| 53 | 'Type' => self::MESSAGE_TYPE_BAD |
||
| 54 | ); |
||
| 55 | } |
||
| 56 | |||
| 57 | // Check if a ticket exists with the given ticket code |
||
| 58 | if (!$this->attendee = Attendee::get()->find('TicketCode', $ticketCode)) { |
||
| 59 | return array( |
||
| 60 | 'Code' => self::MESSAGE_CODE_NOT_FOUND, |
||
| 61 | 'Message' => self::message(self::MESSAGE_CODE_NOT_FOUND), |
||
| 62 | 'Type' => self::MESSAGE_TYPE_BAD |
||
| 63 | ); |
||
| 64 | } |
||
| 65 | |||
| 66 | // Check if the reservation is not canceled |
||
| 67 | if (!(bool)$this->attendee->Event()->getGuestList()->find('ID', $this->attendee->ID)) { |
||
| 68 | return array( |
||
| 69 | 'Code' => self::MESSAGE_TICKET_CANCELLED, |
||
| 70 | 'Message' => self::message(self::MESSAGE_TICKET_CANCELLED), |
||
| 71 | 'Type' => self::MESSAGE_TYPE_BAD |
||
| 72 | ); |
||
| 73 | } |
||
| 74 | |||
| 75 | // Check if the ticket is already checked in and not allowed to check out |
||
| 76 | View Code Duplication | elseif ((bool)$this->attendee->CheckedIn && !(bool)self::config()->get('allow_checkout')) { |
|
| 77 | return array( |
||
| 78 | 'Code' => self::MESSAGE_ALREADY_CHECKED_IN, |
||
| 79 | 'Message' => self::message(self::MESSAGE_ALREADY_CHECKED_IN), |
||
| 80 | 'Type' => self::MESSAGE_TYPE_BAD |
||
| 81 | ); |
||
| 82 | } |
||
| 83 | |||
| 84 | // Successfully checked out |
||
| 85 | View Code Duplication | elseif ((bool)$this->attendee->CheckedIn && (bool)self::config()->get('allow_checkout')) { |
|
| 86 | return array( |
||
| 87 | 'Code' => self::MESSAGE_CHECK_OUT_SUCCESS, |
||
| 88 | 'Message' => self::message(self::MESSAGE_CHECK_OUT_SUCCESS), |
||
| 89 | 'Type' => self::MESSAGE_TYPE_WARNING |
||
| 90 | ); |
||
| 91 | } |
||
| 92 | |||
| 93 | // Successfully checked in |
||
| 94 | else return array( |
||
| 95 | 'Code' => self::MESSAGE_CHECK_IN_SUCCESS, |
||
| 96 | 'Message' => self::message(self::MESSAGE_CHECK_IN_SUCCESS), |
||
| 97 | 'Type' => self::MESSAGE_TYPE_GOOD |
||
| 98 | ); |
||
| 99 | } |
||
| 100 | |||
| 121 | } |
This check marks private properties in classes that are never used. Those properties can be removed.