Conditions | 12 |
Paths | 12 |
Total Lines | 49 |
Code Lines | 42 |
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 |
||
26 | public function checkout(array $request): PaymentInterface |
||
27 | { |
||
28 | switch (strtoupper($request['brand'])) { |
||
29 | case 'MASTER': |
||
30 | case 'AMEX': |
||
31 | case 'VPAY': |
||
32 | case 'MAESTRO': |
||
33 | case 'VISADEBIT': |
||
34 | case 'VISAELECTRON': |
||
35 | case 'VISA': |
||
36 | $payment = new PaymentWithCard( |
||
37 | $request['amount'], |
||
38 | strtoupper($request['currency']), |
||
39 | strtoupper($request['brand']), |
||
40 | strtoupper($request['type']), |
||
41 | $request['optionalParameters'], |
||
42 | new Card( |
||
43 | $request['number'], |
||
44 | $request['holder'], |
||
45 | $request['expiry_month'], |
||
46 | $request['expiry_year'], |
||
47 | $request['cvv'] |
||
48 | ) |
||
49 | ); |
||
50 | break; |
||
51 | case 'CHECKOUT': |
||
52 | $payment = new Checkout($request['amount'], $request['currency'], $request['type'], $request['optionalParameters']); |
||
53 | break; |
||
54 | case 'SIBS_MULTIBANCO': |
||
55 | throw new \RuntimeException('SIBS_MULTIBANCO Service Payment not found.', 404); |
||
56 | break; |
||
57 | case 'DIRECTDEBIT_SEPA': |
||
58 | throw new \RuntimeException('DIRECTDEBIT_SEPA Service Payment not found.', 404); |
||
59 | break; |
||
60 | case 'MBWAY': |
||
61 | $payment = new PaymentWithMBWay( |
||
62 | $request['amount'], |
||
63 | strtoupper($request['currency']), |
||
64 | strtoupper($request['brand']), |
||
65 | strtoupper($request['type']), |
||
66 | $request['accountId'], |
||
67 | $request['optionalParameters'] |
||
68 | ); |
||
69 | break; |
||
70 | default: |
||
71 | throw new \RuntimeException('Sibs Service Payment not found.', 404); |
||
72 | } |
||
73 | |||
74 | return $payment; |
||
75 | } |
||
89 |