| Conditions | 25 |
| Paths | 97 |
| Total Lines | 124 |
| 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 |
||
| 255 | protected function getAllEventData($eventId) |
||
| 256 | { |
||
| 257 | // these should ultimately be extracted out into their own classes (one per model) |
||
| 258 | $event = $this->spoofer->getOneApiResult( |
||
| 259 | $this->event_model, |
||
| 260 | [['EVT_ID' => $eventId]] |
||
| 261 | ); |
||
| 262 | if (! (is_array($event) && isset($event['EVT_ID']) && $event['EVT_ID'] === $eventId)) { |
||
| 263 | return []; |
||
| 264 | } |
||
| 265 | $eventDates = $this->getEventDates($eventId); |
||
| 266 | if ((! is_array($eventDates) || empty($eventDates)) |
||
| 267 | || (isset($_REQUEST['action']) && $_REQUEST['action'] === 'create_new') |
||
| 268 | ) { |
||
| 269 | $this->addDefaultEntities($eventId); |
||
| 270 | $eventDates = $this->getEventDates($eventId); |
||
| 271 | } |
||
| 272 | |||
| 273 | $event = [$eventId => $event]; |
||
| 274 | $relations = [ |
||
| 275 | 'event' => [ |
||
| 276 | $eventId => [ |
||
| 277 | 'datetime' => [] |
||
| 278 | ] |
||
| 279 | ], |
||
| 280 | 'datetime' => [], |
||
| 281 | 'ticket' => [], |
||
| 282 | 'price' => [], |
||
| 283 | ]; |
||
| 284 | |||
| 285 | $datetimes = []; |
||
| 286 | $eventDateTickets = []; |
||
| 287 | if (is_array($eventDates)) { |
||
| 288 | foreach ($eventDates as $eventDate) { |
||
| 289 | if (isset($eventDate['DTT_ID']) && $eventDate['DTT_ID']) { |
||
| 290 | $DTT_ID = $eventDate['DTT_ID']; |
||
| 291 | $datetimes[ $DTT_ID ] = $eventDate; |
||
| 292 | $relations['event'][ $eventId ]['datetime'][] = $DTT_ID; |
||
| 293 | $eventDateTickets[ $DTT_ID ] = $this->spoofer->getApiResults( |
||
| 294 | $this->ticket_model, |
||
| 295 | [[ |
||
| 296 | 'Datetime.DTT_ID' => $DTT_ID, |
||
| 297 | 'TKT_deleted' => ['IN', [true, false]] |
||
| 298 | ]] |
||
| 299 | ); |
||
| 300 | } |
||
| 301 | } |
||
| 302 | } |
||
| 303 | |||
| 304 | $prices = []; |
||
| 305 | $tickets = []; |
||
| 306 | if (is_array($eventDateTickets)) { |
||
| 307 | foreach ($eventDateTickets as $DTT_ID => $dateTickets) { |
||
| 308 | if (is_array($dateTickets)) { |
||
| 309 | $relations['datetime'][ $DTT_ID ]['ticket'] = []; |
||
| 310 | foreach ($dateTickets as $ticket) { |
||
| 311 | if (isset($ticket['TKT_ID']) && $ticket['TKT_ID']) { |
||
| 312 | $TKT_ID = $ticket['TKT_ID']; |
||
| 313 | $tickets[ $TKT_ID ] = $ticket; |
||
| 314 | $relations['datetime'][ $DTT_ID ]['ticket'][] = $TKT_ID; |
||
| 315 | $ticketPrices[ $TKT_ID ] = $this->spoofer->getApiResults( |
||
| 316 | $this->price_model, |
||
| 317 | [['Ticket.TKT_ID' => $TKT_ID]] |
||
| 318 | ); |
||
| 319 | if (is_array($ticketPrices[ $TKT_ID ])) { |
||
| 320 | $relations['ticket'][ $TKT_ID ]['price'] = []; |
||
| 321 | foreach ($ticketPrices[ $TKT_ID ] as $ticketPrice) { |
||
| 322 | $PRC_ID = $ticketPrice['PRC_ID']; |
||
| 323 | $prices[ $PRC_ID ] = $ticketPrice; |
||
| 324 | $relations['ticket'][ $TKT_ID ]['price'][] = $PRC_ID; |
||
| 325 | } |
||
| 326 | } |
||
| 327 | } |
||
| 328 | } |
||
| 329 | } |
||
| 330 | } |
||
| 331 | } |
||
| 332 | $price_type_results = $this->spoofer->getApiResults( |
||
| 333 | $this->price_type_model, |
||
| 334 | [['PRT_deleted' => false]] |
||
| 335 | ); |
||
| 336 | $price_types = []; |
||
| 337 | foreach ($price_type_results as $price_type) { |
||
| 338 | $price_types[ $price_type['PRT_ID'] ] = $price_type; |
||
| 339 | } |
||
| 340 | $venue = $this->spoofer->getOneApiResult( |
||
| 341 | $this->venue_model, |
||
| 342 | [['Event.EVT_ID' => $eventId]] |
||
| 343 | ); |
||
| 344 | if (is_array($venue) && isset($venue['VNU_ID'])) { |
||
| 345 | $relations['event'][ $eventId ]['venue'] = [ $venue['VNU_ID'] ]; |
||
| 346 | $venue = [$venue['VNU_ID'] => $venue]; |
||
| 347 | } |
||
| 348 | |||
| 349 | $schemas = [ |
||
| 350 | 'event' => $this->spoofer->getModelSchema('events'), |
||
| 351 | 'datetime' => $this->spoofer->getModelSchema('datetimes'), |
||
| 352 | 'ticket' => $this->spoofer->getModelSchema('tickets'), |
||
| 353 | 'price' => $this->spoofer->getModelSchema('prices'), |
||
| 354 | 'price_type' => $this->spoofer->getModelSchema('price_types'), |
||
| 355 | 'venue' => $this->spoofer->getModelSchema('venues'), |
||
| 356 | ]; |
||
| 357 | |||
| 358 | $tktRegCount = []; |
||
| 359 | foreach ($tickets as $ticket) { |
||
| 360 | $tkt_instance = $this->ticket_model->get_one_by_ID($ticket['TKT_ID']); |
||
| 361 | |||
| 362 | $tktRegCount[ $ticket['TKT_ID'] ] = $tkt_instance instanceof EE_Ticket ? |
||
| 363 | $tkt_instance->count_registrations() |
||
| 364 | : 0; |
||
| 365 | } |
||
| 366 | return [ |
||
| 367 | 'eventId' => $eventId, |
||
| 368 | 'event' => $event, |
||
| 369 | 'datetime' => $datetimes, |
||
| 370 | 'ticket' => $tickets, |
||
| 371 | 'price' => $prices, |
||
| 372 | 'price_type' => $price_types, |
||
| 373 | 'venue' => $venue, |
||
| 374 | 'schemas' => $schemas, |
||
| 375 | 'relations' => $relations, |
||
| 376 | 'tktRegCount' => $tktRegCount, |
||
| 377 | ]; |
||
| 378 | } |
||
| 379 | } |
||
| 380 |