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