| Conditions | 7 |
| Paths | 24 |
| Total Lines | 51 |
| Code Lines | 37 |
| 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 |
||
| 21 | public static function createFromArray(array $parameters) : GetAvailabilityParameters |
||
| 22 | { |
||
| 23 | $originDestinationInformations = []; |
||
| 24 | foreach ($parameters['OriginDestinationInformation'] as $originDestinationInformation) { |
||
| 25 | $originLocation = new Location( |
||
| 26 | $originDestinationInformation['OriginLocation']['LocationCode'], |
||
| 27 | $originDestinationInformation['OriginLocation']['MultiAirportCityInd'] |
||
| 28 | ); |
||
| 29 | $destinationLocation = new Location( |
||
| 30 | $originDestinationInformation['DestinationLocation']['LocationCode'], |
||
| 31 | $originDestinationInformation['DestinationLocation']['MultiAirportCityInd'] |
||
| 32 | ); |
||
| 33 | $departureDateTime = (new DepartureDateTime( |
||
| 34 | DateTimeImmutable::createFromFormat('dM', $originDestinationInformation['DepartureDateTime']['Date']), |
||
|
|
|||
| 35 | $originDestinationInformation['DepartureDateTime']['WindowAfter'], |
||
| 36 | $originDestinationInformation['DepartureDateTime']['WindowBefore'] |
||
| 37 | ))->withDateFormat('dM'); |
||
| 38 | $originDestinationInformationObject = new OriginDestinationInformation( |
||
| 39 | $departureDateTime, |
||
| 40 | $originLocation, |
||
| 41 | $destinationLocation |
||
| 42 | ); |
||
| 43 | if (array_key_exists('CabinPreferences', $originDestinationInformation)) { |
||
| 44 | foreach ($originDestinationInformation['CabinPreferences'] as $cabinPreference) { |
||
| 45 | $originDestinationInformationObject = $originDestinationInformationObject |
||
| 46 | ->withCabinPreferences($cabinPreference['Cabin']); |
||
| 47 | } |
||
| 48 | } |
||
| 49 | $originDestinationInformations[] = $originDestinationInformationObject; |
||
| 50 | } |
||
| 51 | $passengerTypeQuantityObject = new PassengerTypeQuantity(); |
||
| 52 | foreach ($parameters['PassengerTypeQuantity'] as $passengerTypeQuantity) { |
||
| 53 | $passengerTypeQuantityObject->withQuantity( |
||
| 54 | $passengerTypeQuantity['Code'], |
||
| 55 | $passengerTypeQuantity['Quantity'] |
||
| 56 | ); |
||
| 57 | } |
||
| 58 | $getAvailabilityParameters = new GetAvailabilityParameters( |
||
| 59 | $parameters['ReducedDataIndicator'], |
||
| 60 | $parameters['RoutingType'], |
||
| 61 | $passengerTypeQuantityObject |
||
| 62 | ); |
||
| 63 | |||
| 64 | if (array_key_exists('TargetSource', $parameters)) { |
||
| 65 | $getAvailabilityParameters = $getAvailabilityParameters->withTargetSource(); |
||
| 66 | } |
||
| 67 | foreach ($originDestinationInformations as $originDestinationInformationObject) { |
||
| 68 | $getAvailabilityParameters = $getAvailabilityParameters |
||
| 69 | ->withOriginDestinationInformation($originDestinationInformationObject); |
||
| 70 | } |
||
| 71 | return $getAvailabilityParameters; |
||
| 72 | } |
||
| 91 |