Conditions | 9 |
Paths | 12 |
Total Lines | 59 |
Code Lines | 33 |
Lines | 14 |
Ratio | 23.73 % |
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 |
||
47 | public function validate($ticketCode = null) |
||
48 | { |
||
49 | if (filter_var($ticketCode, FILTER_VALIDATE_URL)) { |
||
50 | $asURL = explode('/', parse_url($ticketCode, PHP_URL_PATH)); |
||
51 | $ticketCode = end($asURL); |
||
52 | } |
||
53 | |||
54 | // Check if a code is given to the validator |
||
55 | if (!isset($ticketCode)) { |
||
56 | return array( |
||
57 | 'Code' => self::MESSAGE_NO_CODE, |
||
58 | 'Message' => self::message(self::MESSAGE_NO_CODE), |
||
59 | 'Type' => self::MESSAGE_TYPE_BAD |
||
60 | ); |
||
61 | } |
||
62 | |||
63 | // Check if a ticket exists with the given ticket code |
||
64 | if (!$this->attendee = Attendee::get()->find('TicketCode', $ticketCode)) { |
||
65 | return array( |
||
66 | 'Code' => self::MESSAGE_CODE_NOT_FOUND, |
||
67 | 'Message' => self::message(self::MESSAGE_CODE_NOT_FOUND), |
||
68 | 'Type' => self::MESSAGE_TYPE_BAD |
||
69 | ); |
||
70 | } |
||
71 | |||
72 | // Check if the reservation is not canceled |
||
73 | if (!(bool)$this->attendee->Event()->getGuestList()->find('ID', $this->attendee->ID)) { |
||
74 | return array( |
||
75 | 'Code' => self::MESSAGE_TICKET_CANCELLED, |
||
76 | 'Message' => self::message(self::MESSAGE_TICKET_CANCELLED), |
||
77 | 'Type' => self::MESSAGE_TYPE_BAD |
||
78 | ); |
||
79 | } |
||
80 | |||
81 | // Check if the ticket is already checked in and not allowed to check out |
||
82 | View Code Duplication | elseif ((bool)$this->attendee->CheckedIn && !(bool)self::config()->get('allow_checkout')) { |
|
83 | return array( |
||
84 | 'Code' => self::MESSAGE_ALREADY_CHECKED_IN, |
||
85 | 'Message' => self::message(self::MESSAGE_ALREADY_CHECKED_IN), |
||
86 | 'Type' => self::MESSAGE_TYPE_BAD |
||
87 | ); |
||
88 | } |
||
89 | |||
90 | // Successfully checked out |
||
91 | View Code Duplication | elseif ((bool)$this->attendee->CheckedIn && (bool)self::config()->get('allow_checkout')) { |
|
92 | return array( |
||
93 | 'Code' => self::MESSAGE_CHECK_OUT_SUCCESS, |
||
94 | 'Message' => self::message(self::MESSAGE_CHECK_OUT_SUCCESS), |
||
95 | 'Type' => self::MESSAGE_TYPE_WARNING |
||
96 | ); |
||
97 | } |
||
98 | |||
99 | // Successfully checked in |
||
100 | else return array( |
||
101 | 'Code' => self::MESSAGE_CHECK_IN_SUCCESS, |
||
102 | 'Message' => self::message(self::MESSAGE_CHECK_IN_SUCCESS), |
||
103 | 'Type' => self::MESSAGE_TYPE_GOOD |
||
104 | ); |
||
105 | } |
||
106 | |||
127 | } |
This check marks private properties in classes that are never used. Those properties can be removed.