Conditions | 8 |
Paths | 6 |
Total Lines | 78 |
Code Lines | 53 |
Lines | 0 |
Ratio | 0 % |
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 |
||
50 | public function doCheckIn($data, CheckInForm $form) |
||
51 | { |
||
52 | /** @var CheckInController $controller */ |
||
53 | $controller = $form->getController(); |
||
54 | |||
55 | // Check if the ticket code is set |
||
56 | if (!isset($data['TicketCode'])) { |
||
57 | $form->addErrorMessage('TicketCode', _t( |
||
58 | 'CheckInForm.NO_CODE', |
||
59 | 'Please submit a ticket code' |
||
60 | ), 'error'); |
||
61 | |||
62 | $controller->redirect("{$controller->Link()}?success=-3"); |
||
63 | return false; |
||
64 | } |
||
65 | |||
66 | // Check if the event has registered attendees |
||
67 | if (!$controller->Attendees()->exists()) { |
||
68 | $form->addErrorMessage('TicketCode', _t( |
||
69 | 'CheckInForm.NO_ATTENDEES', |
||
70 | 'This event has no registered attendees' |
||
71 | ), 'error'); |
||
72 | |||
73 | $controller->redirect("{$controller->Link()}?success=-2"); |
||
74 | return false; |
||
75 | } |
||
76 | |||
77 | // Check if the ticket is found on the current event |
||
78 | /** @var Attendee $attendee */ |
||
79 | if (!$attendee = $controller->Attendees()->find('TicketCode', $data['TicketCode'])) { |
||
80 | $form->addErrorMessage('TicketCode', _t( |
||
81 | 'CheckInForm.CODE_NOT_FOUND', |
||
82 | 'The given ticket is not found on this event' |
||
83 | ), 'error'); |
||
84 | |||
85 | $controller->redirect("{$controller->Link()}?success=-1"); |
||
86 | return false; |
||
87 | } |
||
88 | |||
89 | // Check if the ticket is already used |
||
90 | if ($attendee->CheckedIn && !(bool)self::config()->get('allow_checkout')) { |
||
91 | $form->addErrorMessage('TicketCode', _t( |
||
92 | 'CheckInForm.ALREADY_CHECKED_IN', |
||
93 | 'This ticket is already checked in' |
||
94 | ), 'error'); |
||
95 | |||
96 | $controller->redirect("{$controller->Link()}?success=0"); |
||
97 | return false; |
||
98 | } else { |
||
99 | if ((bool)$attendee->CheckedIn && (bool)self::config()->get('allow_checkout')) { |
||
100 | $attendee->CheckedIn = false; |
||
101 | $message = 'CHECK_OUT_SUCCESS'; |
||
102 | $messageType = 'notice'; |
||
103 | } else { |
||
104 | $attendee->CheckedIn = true; |
||
105 | $message = 'SUCCESS'; |
||
106 | $messageType = 'good'; |
||
107 | } |
||
108 | |||
109 | $attendee->write(); |
||
110 | $messages = array( |
||
111 | 'SUCCESS' => 'The ticket is valid. {name} has a {ticket} ticket with number {number}', |
||
112 | 'CHECK_OUT_SUCCESS' => 'The ticket with number {number} is checked out.' |
||
113 | ); |
||
114 | |||
115 | $form->sessionMessage(_t( |
||
116 | "CheckInForm.$message", |
||
117 | $messages[$message], |
||
118 | null, array( |
||
119 | 'name' => $attendee->getName(), |
||
120 | 'ticket' => $attendee->Ticket()->Title, |
||
121 | 'number' => $attendee->TicketCode |
||
122 | ) |
||
123 | ), $messageType, false); |
||
124 | $controller->redirect("{$controller->Link()}?success=1"); |
||
125 | return true; |
||
126 | } |
||
127 | } |
||
128 | |||
129 | } |
This check marks private properties in classes that are never used. Those properties can be removed.