| Conditions | 19 |
| Paths | 186 |
| Total Lines | 164 |
| Code Lines | 100 |
| Lines | 15 |
| Ratio | 9.15 % |
| 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 |
||
| 105 | public function processTicketSelections() |
||
| 106 | { |
||
| 107 | do_action('EED_Ticket_Selector__process_ticket_selections__before'); |
||
| 108 | // do we have an event id? |
||
| 109 | View Code Duplication | if ( ! \EE_Registry::instance()->REQ->is_set('tkt-slctr-event-id')) { |
|
| 110 | // $_POST['tkt-slctr-event-id'] was not set ?!?!?!? |
||
| 111 | \EE_Error::add_error( |
||
| 112 | sprintf( |
||
| 113 | __( |
||
| 114 | 'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.', |
||
| 115 | 'event_espresso' |
||
| 116 | ), |
||
| 117 | '<br/>' |
||
| 118 | ), |
||
| 119 | __FILE__, |
||
| 120 | __FUNCTION__, |
||
| 121 | __LINE__ |
||
| 122 | ); |
||
| 123 | } |
||
| 124 | //if event id is valid |
||
| 125 | $id = absint(\EE_Registry::instance()->REQ->get('tkt-slctr-event-id')); |
||
| 126 | // check nonce |
||
| 127 | if ( ! $this->processTicketSelectorNonce('process_ticket_selections', $id)) { |
||
| 128 | return false; |
||
| 129 | } |
||
| 130 | // d( \EE_Registry::instance()->REQ ); |
||
| 131 | self::$_available_spaces = array( |
||
| 132 | 'tickets' => array(), |
||
| 133 | 'datetimes' => array(), |
||
| 134 | ); |
||
| 135 | //we should really only have 1 registration in the works now (ie, no MER) so clear any previous items in the cart. |
||
| 136 | // When MER happens this will probably need to be tweaked, possibly wrapped in a conditional checking for some constant defined in MER etc. |
||
| 137 | \EE_Registry::instance()->load_core('Session'); |
||
| 138 | // unless otherwise requested, clear the session |
||
| 139 | if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) { |
||
| 140 | \EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
||
| 141 | } |
||
| 142 | //d( \EE_Registry::instance()->SSN ); |
||
| 143 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
||
| 144 | // validate/sanitize data |
||
| 145 | $valid = $this->validatePostData($id); |
||
| 146 | //EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ ); |
||
| 147 | //EEH_Debug_Tools::printr( $valid, '$valid', __FILE__, __LINE__ ); |
||
| 148 | //EEH_Debug_Tools::printr( $valid[ 'total_tickets' ], 'total_tickets', __FILE__, __LINE__ ); |
||
| 149 | //EEH_Debug_Tools::printr( $valid[ 'max_atndz' ], 'max_atndz', __FILE__, __LINE__ ); |
||
| 150 | //check total tickets ordered vs max number of attendees that can register |
||
| 151 | if ($valid['total_tickets'] > $valid['max_atndz']) { |
||
| 152 | // ordering too many tickets !!! |
||
| 153 | $total_tickets_string = _n( |
||
| 154 | 'You have attempted to purchase %s ticket.', |
||
| 155 | 'You have attempted to purchase %s tickets.', |
||
| 156 | $valid['total_tickets'], |
||
| 157 | 'event_espresso' |
||
| 158 | ); |
||
| 159 | $limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']); |
||
| 160 | // dev only message |
||
| 161 | $max_atndz_string = _n( |
||
| 162 | 'The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
||
| 163 | 'The registration limit for this event is %s tickets per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
||
| 164 | $valid['max_atndz'], |
||
| 165 | 'event_espresso' |
||
| 166 | ); |
||
| 167 | $limit_error_2 = sprintf($max_atndz_string, $valid['max_atndz'], $valid['max_atndz']); |
||
| 168 | \EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
||
| 169 | } else { |
||
| 170 | // all data appears to be valid |
||
| 171 | $tckts_slctd = false; |
||
| 172 | $tickets_added = 0; |
||
| 173 | $valid = apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data', $valid); |
||
| 174 | if ($valid['total_tickets'] > 0) { |
||
| 175 | // load cart |
||
| 176 | \EE_Registry::instance()->load_core('Cart'); |
||
| 177 | // cycle thru the number of data rows sent from the event listing |
||
| 178 | for ($x = 0; $x < $valid['rows']; $x++) { |
||
| 179 | // does this row actually contain a ticket quantity? |
||
| 180 | if (isset($valid['qty'][$x]) && $valid['qty'][$x] > 0) { |
||
| 181 | // YES we have a ticket quantity |
||
| 182 | $tckts_slctd = true; |
||
| 183 | // d( $valid['ticket_obj'][$x] ); |
||
| 184 | if ($valid['ticket_obj'][$x] instanceof \EE_Ticket) { |
||
| 185 | // then add ticket to cart |
||
| 186 | $tickets_added += $this->addTicketToCart( |
||
| 187 | $valid['ticket_obj'][$x], |
||
| 188 | $valid['qty'][$x] |
||
| 189 | ); |
||
| 190 | if (\EE_Error::has_error()) { |
||
| 191 | break; |
||
| 192 | } |
||
| 193 | } else { |
||
| 194 | // nothing added to cart retrieved |
||
| 195 | \EE_Error::add_error( |
||
| 196 | sprintf( |
||
| 197 | __( |
||
| 198 | 'A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.', |
||
| 199 | 'event_espresso' |
||
| 200 | ), |
||
| 201 | '<br/>' |
||
| 202 | ), |
||
| 203 | __FILE__, __FUNCTION__, __LINE__ |
||
| 204 | ); |
||
| 205 | } |
||
| 206 | } |
||
| 207 | } |
||
| 208 | } |
||
| 209 | do_action( |
||
| 210 | 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
||
| 211 | \EE_Registry::instance()->CART, |
||
| 212 | $this |
||
| 213 | ); |
||
| 214 | //d( \EE_Registry::instance()->CART ); |
||
| 215 | //die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE |
||
| 216 | if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tckts_slctd)) { |
||
| 217 | if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) { |
||
| 218 | do_action( |
||
| 219 | 'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout', |
||
| 220 | \EE_Registry::instance()->CART, |
||
| 221 | $this |
||
| 222 | ); |
||
| 223 | \EE_Registry::instance()->CART->recalculate_all_cart_totals(); |
||
| 224 | \EE_Registry::instance()->CART->save_cart(false); |
||
| 225 | // exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<< OR HERE TO KILL REDIRECT AFTER CART UPDATE |
||
| 226 | // just return TRUE for registrations being made from admin |
||
| 227 | if (is_admin()) { |
||
| 228 | return true; |
||
| 229 | } |
||
| 230 | \EE_Error::get_notices(false, true); |
||
| 231 | wp_safe_redirect( |
||
| 232 | apply_filters( |
||
| 233 | 'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url', |
||
| 234 | \EE_Registry::instance()->CFG->core->reg_page_url() |
||
| 235 | ) |
||
| 236 | ); |
||
| 237 | exit(); |
||
| 238 | } else { |
||
| 239 | if ( ! \EE_Error::has_error() && ! \EE_Error::has_error(true, 'attention')) { |
||
| 240 | // nothing added to cart |
||
| 241 | \EE_Error::add_attention(__('No tickets were added for the event', 'event_espresso'), |
||
| 242 | __FILE__, __FUNCTION__, __LINE__); |
||
| 243 | } |
||
| 244 | } |
||
| 245 | } else { |
||
| 246 | // no ticket quantities were selected |
||
| 247 | \EE_Error::add_error(__('You need to select a ticket quantity before you can proceed.', |
||
| 248 | 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
||
| 249 | } |
||
| 250 | } |
||
| 251 | //die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT |
||
| 252 | // at this point, just return if registration is being made from admin |
||
| 253 | if (is_admin()) { |
||
| 254 | return false; |
||
| 255 | } |
||
| 256 | if ($valid['return_url']) { |
||
| 257 | \EE_Error::get_notices(false, true); |
||
| 258 | wp_safe_redirect($valid['return_url']); |
||
| 259 | exit(); |
||
| 260 | } elseif (isset($event_to_add['id'])) { |
||
|
|
|||
| 261 | \EE_Error::get_notices(false, true); |
||
| 262 | wp_safe_redirect(get_permalink($event_to_add['id'])); |
||
| 263 | exit(); |
||
| 264 | } else { |
||
| 265 | echo \EE_Error::get_notices(); |
||
| 266 | } |
||
| 267 | return false; |
||
| 268 | } |
||
| 269 | |||
| 594 | // Location: /ProcessTicketSelector.php |
This check looks for calls to
isset(...)orempty()on variables that are yet undefined. These calls will always produce the same result and can be removed.This is most likely caused by the renaming of a variable or the removal of a function/method parameter.