Conditions | 15 |
Paths | 15 |
Total Lines | 86 |
Code Lines | 50 |
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 namespace BB\Http\Controllers; |
||
35 | public function receive() |
||
36 | { |
||
37 | $request = \Request::instance(); |
||
38 | $webhookData = $request->getContent(); |
||
39 | $signature = $request->header('Webhook-Signature'); |
||
40 | |||
41 | $hash = hash_hmac('sha256', $webhookData, 'Z4Zw1Bna_aoHo1Ifg-ZyU3NRVOjcQSuQP10zWHKg'); |
||
42 | |||
43 | if ($signature != $hash) { |
||
44 | return \Response::make('', 403); |
||
45 | } |
||
46 | |||
47 | $webhookData = json_decode($webhookData, true); |
||
48 | |||
49 | foreach ($webhookData['events'] as $event) { |
||
50 | $parser = new \BB\Services\Payment\GoCardlessWebhookParser(); |
||
51 | $parser->parseResponse($event); |
||
52 | |||
53 | switch ($parser->getResourceType()) { |
||
54 | case 'payments': |
||
|
|||
55 | |||
56 | switch ($parser->getAction()) { |
||
57 | case 'created': |
||
58 | |||
59 | $this->processNewPayment($event); |
||
60 | |||
61 | break; |
||
62 | case 'submitted': |
||
63 | |||
64 | break; |
||
65 | case 'confirmed': |
||
66 | |||
67 | $this->processPaidBills($event); |
||
68 | |||
69 | break; |
||
70 | case 'paid_out': |
||
71 | |||
72 | break; |
||
73 | case 'failed': |
||
74 | case 'cancelled': |
||
75 | |||
76 | $this->paymentFailed($event); |
||
77 | |||
78 | break; |
||
79 | default: |
||
80 | |||
81 | \Log::info('GoCardless payment event. Action: ' . $parser->getAction() . '. Data: ' . json_encode($event)); |
||
82 | } |
||
83 | |||
84 | break; |
||
85 | case 'mandates': |
||
86 | |||
87 | switch ($parser->getAction()) { |
||
88 | case 'cancelled': |
||
89 | |||
90 | $this->cancelPreAuth($event); |
||
91 | |||
92 | break; |
||
93 | default: |
||
94 | } |
||
95 | |||
96 | break; |
||
97 | case 'subscriptions': |
||
98 | |||
99 | switch ($parser->getAction()) { |
||
100 | case 'cancelled': |
||
101 | |||
102 | $this->cancelSubscriptions($event); |
||
103 | |||
104 | break; |
||
105 | case 'payment_created': |
||
106 | |||
107 | $this->processNewSubscriptionPayment($event); |
||
108 | |||
109 | break; |
||
110 | default: |
||
111 | |||
112 | \Log::info('GoCardless subscription event. Action: ' . $parser->getAction() . '. Data: ' . json_encode($event)); |
||
113 | } |
||
114 | |||
115 | break; |
||
116 | } |
||
117 | } |
||
118 | |||
119 | return \Response::make('Success', 200); |
||
120 | } |
||
121 | |||
253 |
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.