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