| Conditions | 19 |
| Paths | 17 |
| Total Lines | 111 |
| 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 |
||
| 166 | protected function getAllEventData($eventId) |
||
| 167 | { |
||
| 168 | // these should ultimately be extracted out into their own classes (one per model) |
||
| 169 | $event = $this->spoofer->getOneApiResult( |
||
| 170 | $this->event_model, |
||
| 171 | [['EVT_ID' => $eventId]] |
||
| 172 | ); |
||
| 173 | if (! (is_array($event) && isset($event['EVT_ID']) && $event['EVT_ID'] === $eventId)) { |
||
| 174 | return []; |
||
| 175 | } |
||
| 176 | $event = [$eventId => $event]; |
||
| 177 | $relations = [ |
||
| 178 | 'event' => [ $eventId => [] ], |
||
| 179 | 'datetime' => [], |
||
| 180 | 'ticket' => [], |
||
| 181 | 'price' => [], |
||
| 182 | ]; |
||
| 183 | $eventDates = $this->spoofer->getApiResults( |
||
| 184 | $this->datetime_model, |
||
| 185 | [[ |
||
| 186 | 'EVT_ID' => $eventId, |
||
| 187 | 'DTT_deleted' => ['IN', [true, false]] |
||
| 188 | ]] |
||
| 189 | ); |
||
| 190 | $relations['event'][ $eventId ]['datetime'] = []; |
||
| 191 | |||
| 192 | $datetimes = []; |
||
| 193 | $eventDateTickets = []; |
||
| 194 | if (is_array($eventDates)){ |
||
| 195 | foreach ($eventDates as $eventDate) { |
||
| 196 | if (isset($eventDate['DTT_ID']) && $eventDate['DTT_ID']) { |
||
| 197 | $DTT_ID = $eventDate['DTT_ID']; |
||
| 198 | $datetimes[ $DTT_ID ] = $eventDate; |
||
| 199 | $relations['event'][ $eventId ]['datetime'][] = $DTT_ID; |
||
| 200 | $eventDateTickets[ $DTT_ID ] = $this->spoofer->getApiResults( |
||
| 201 | $this->ticket_model, |
||
| 202 | [[ |
||
| 203 | 'Datetime.DTT_ID' => $DTT_ID, |
||
| 204 | 'TKT_deleted' => ['IN', [true, false]] |
||
| 205 | ]] |
||
| 206 | ); |
||
| 207 | } |
||
| 208 | } |
||
| 209 | } |
||
| 210 | |||
| 211 | $prices = []; |
||
| 212 | $tickets = []; |
||
| 213 | if (is_array($eventDateTickets)) { |
||
| 214 | foreach ($eventDateTickets as $DTT_ID => $dateTickets) { |
||
| 215 | if (is_array($dateTickets)) { |
||
| 216 | $relations['datetime'][ $DTT_ID ]['ticket'] = []; |
||
| 217 | foreach ($dateTickets as $ticket) { |
||
| 218 | if (isset($ticket['TKT_ID']) && $ticket['TKT_ID']) { |
||
| 219 | $TKT_ID = $ticket['TKT_ID']; |
||
| 220 | $tickets[ $TKT_ID ] = $ticket; |
||
| 221 | $relations['datetime'][ $DTT_ID ]['ticket'][] = $TKT_ID; |
||
| 222 | $ticketPrices[ $TKT_ID ] = $this->spoofer->getApiResults( |
||
| 223 | $this->price_model, |
||
| 224 | [['Ticket.TKT_ID' => $TKT_ID]] |
||
| 225 | ); |
||
| 226 | if (is_array($ticketPrices[ $TKT_ID ])) { |
||
| 227 | $relations['ticket'][ $TKT_ID ]['price'] = []; |
||
| 228 | foreach ($ticketPrices[ $TKT_ID ] as $ticketPrice) { |
||
| 229 | $PRC_ID = $ticketPrice['PRC_ID']; |
||
| 230 | $prices[ $PRC_ID ] = $ticketPrice; |
||
| 231 | $relations['ticket'][ $TKT_ID ]['price'][] = $PRC_ID; |
||
| 232 | } |
||
| 233 | } |
||
| 234 | } |
||
| 235 | } |
||
| 236 | } |
||
| 237 | } |
||
| 238 | } |
||
| 239 | $price_type_results = $this->spoofer->getApiResults( |
||
| 240 | $this->price_type_model, |
||
| 241 | [['PRT_deleted' => false]] |
||
| 242 | ); |
||
| 243 | $price_types = []; |
||
| 244 | foreach ($price_type_results as $price_type) { |
||
| 245 | $price_types[ $price_type['PRT_ID'] ] = $price_type; |
||
| 246 | } |
||
| 247 | $venue = $this->spoofer->getOneApiResult( |
||
| 248 | $this->venue_model, |
||
| 249 | [['Event.EVT_ID' => $eventId]] |
||
| 250 | ); |
||
| 251 | if (is_array($venue) && isset($venue['VNU_ID'])) { |
||
| 252 | $relations['event'][ $eventId ]['venue'] = [ $venue['VNU_ID'] ]; |
||
| 253 | $venue = [$venue['VNU_ID'] => $venue]; |
||
| 254 | } |
||
| 255 | |||
| 256 | $schemas = [ |
||
| 257 | 'event' => $this->spoofer->getModelSchema('events'), |
||
| 258 | 'datetime' => $this->spoofer->getModelSchema('datetimes'), |
||
| 259 | 'ticket' => $this->spoofer->getModelSchema('tickets'), |
||
| 260 | 'price' => $this->spoofer->getModelSchema('prices'), |
||
| 261 | 'price_type' => $this->spoofer->getModelSchema('price_types'), |
||
| 262 | 'venue' => $this->spoofer->getModelSchema('venues'), |
||
| 263 | ]; |
||
| 264 | |||
| 265 | return [ |
||
| 266 | 'eventId' => $eventId, |
||
| 267 | 'event' => $event, |
||
| 268 | 'datetime' => $datetimes, |
||
| 269 | 'ticket' => $tickets, |
||
| 270 | 'price' => $prices, |
||
| 271 | 'price_type' => $price_types, |
||
| 272 | 'venue' => $venue, |
||
| 273 | 'schemas' => $schemas, |
||
| 274 | 'relations' => $relations, |
||
| 275 | ]; |
||
| 276 | } |
||
| 277 | } |
||
| 278 |