Conditions | 10 |
Paths | 128 |
Total Lines | 33 |
Code Lines | 23 |
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 |
||
17 | public static function createFromArray(array $parameters) : CalculateFlightMilesParameters |
||
18 | { |
||
19 | $calculateFlightMilesParameters = new CalculateFlightMilesParameters( |
||
20 | $parameters['origin'], |
||
21 | $parameters['destination'] |
||
22 | ); |
||
23 | if (array_key_exists('cabin_code', $parameters) && $parameters['cabin_code'] === 'Y') { |
||
24 | $calculateFlightMilesParameters = $calculateFlightMilesParameters->withCabinCode(); |
||
25 | } |
||
26 | if (array_key_exists('class_code', $parameters) && $parameters['class_code'] === 'Y') { |
||
27 | $calculateFlightMilesParameters = $calculateFlightMilesParameters->withClassCode(); |
||
28 | } |
||
29 | if (array_key_exists('marketingClassCode', $parameters)) { |
||
30 | $calculateFlightMilesParameters = $calculateFlightMilesParameters |
||
31 | ->withMarketingClassCode($parameters['marketingClassCode']); |
||
32 | } |
||
33 | if (array_key_exists('card_type', $parameters)) { |
||
34 | $calculateFlightMilesParameters = $calculateFlightMilesParameters |
||
35 | ->withCardType($parameters['card_type']); |
||
36 | } |
||
37 | if (array_key_exists('flightDate', $parameters)) { |
||
38 | $calculateFlightMilesParameters = $calculateFlightMilesParameters |
||
39 | ->withFlightDate(DateTimeImmutable::createFromFormat('d.m.Y', $parameters['flightDate'])); |
||
|
|||
40 | } |
||
41 | if (array_key_exists('operatingFlightNumber', $parameters)) { |
||
42 | $calculateFlightMilesParameters = $calculateFlightMilesParameters |
||
43 | ->withOperatingFlightNumber($parameters['operatingFlightNumber']); |
||
44 | } |
||
45 | if (array_key_exists('marketingFlightNumber', $parameters)) { |
||
46 | $calculateFlightMilesParameters = $calculateFlightMilesParameters |
||
47 | ->withMarketingFlightNumber($parameters['marketingFlightNumber']); |
||
48 | } |
||
49 | return $calculateFlightMilesParameters; |
||
50 | } |
||
70 |