| Conditions | 10 |
| Paths | 4 |
| Total Lines | 69 |
| Code Lines | 49 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 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 |
||
| 51 | public static function from(array $attributes, $included = []): self |
||
| 52 | { |
||
| 53 | // location |
||
| 54 | $location = LocationsRetrieveResponse::from([ |
||
| 55 | 'attributes' => [ |
||
| 56 | 'address_text' => null, |
||
| 57 | 'additional_info' => null, |
||
| 58 | 'latitude' => null, |
||
| 59 | 'longitude' => null, |
||
| 60 | 'map_url' => null, |
||
| 61 | 'zoom' => null |
||
| 62 | ], |
||
| 63 | 'id' => $attributes['relationships']['location']['data']['id'] |
||
| 64 | ]); |
||
| 65 | |||
| 66 | // tickets |
||
| 67 | $tickets = []; |
||
| 68 | foreach($attributes['relationships']['tickets']['data'] as $ticket) { |
||
| 69 | array_push($tickets, TicketsRetrieveResponse::from([ |
||
| 70 | 'attributes' => [ |
||
| 71 | 'available' => null, |
||
| 72 | 'available_from' => null, |
||
| 73 | 'available_to' => null, |
||
| 74 | 'built_basket_url' => null, |
||
| 75 | 'built_basket_iframe_url' => null, |
||
| 76 | 'course_ticket' => null, |
||
| 77 | 'details' => null, |
||
| 78 | 'group_ticket' => null, |
||
| 79 | 'group_min' => null, |
||
| 80 | 'group_max' => null, |
||
| 81 | 'number_issued' => null, |
||
| 82 | 'number_taken' => null, |
||
| 83 | 'title' => null |
||
| 84 | ], |
||
| 85 | 'id' => $ticket['id'] |
||
| 86 | ])); |
||
| 87 | } |
||
| 88 | |||
| 89 | if(!empty($included)) { |
||
| 90 | foreach ($included as $includedData) { |
||
| 91 | if($includedData['type'] === 'location' && $includedData['id'] = $location->id) { |
||
| 92 | $location = LocationsRetrieveResponse::from($includedData); |
||
| 93 | } |
||
| 94 | } |
||
| 95 | |||
| 96 | //tickets |
||
| 97 | foreach($tickets as $index => $ticket) { |
||
| 98 | foreach ($included as $includedData) { |
||
| 99 | if($includedData['type'] === 'ticket' && $includedData['id'] = $ticket->id) { |
||
| 100 | $tickets[$index] = TicketsRetrieveResponse::from($includedData); |
||
| 101 | } |
||
| 102 | } |
||
| 103 | } |
||
| 104 | } |
||
| 105 | |||
| 106 | return new self( |
||
| 107 | $attributes['attributes']['all_day'], |
||
| 108 | $attributes['relationships']['attachments']['data'], |
||
| 109 | $attributes['attributes']['attendee_count'], |
||
| 110 | $attributes['attributes']['attendee_limit'], |
||
| 111 | $attributes['attributes']['details'], |
||
| 112 | $attributes['attributes']['end_at'], |
||
| 113 | $attributes['id'], |
||
| 114 | $location, |
||
| 115 | $attributes['attributes']['max_tickets_per_booking'], |
||
| 116 | $attributes['attributes']['start_at'], |
||
| 117 | $tickets, |
||
| 118 | $attributes['attributes']['title'], |
||
| 119 | $attributes['attributes']['waiting_list'] |
||
| 120 | ); |
||
| 123 |