Conditions | 10 |
Paths | 7 |
Total Lines | 43 |
Code Lines | 26 |
Lines | 6 |
Ratio | 13.95 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
27 | public function bind() |
||
28 | { |
||
29 | $metaData = json_decode($this->request->getContent(), true); |
||
30 | |||
31 | if (isset($params['Type']) && $metaData['Type'] == 'SubscriptionConfirmation') { |
||
|
|||
32 | throw new \Exception('AWS SNS Require a subscription confirmation: '.$metaData['SubscribeURL']); |
||
33 | } |
||
34 | |||
35 | if (!isset($metaData['Message'])) { |
||
36 | throw new \Exception('Could not find data'); |
||
37 | } |
||
38 | |||
39 | $sesMessage = json_decode($metaData['Message'], true); |
||
40 | |||
41 | $hooks = []; |
||
42 | |||
43 | switch ($sesMessage['notificationType']) { |
||
44 | case self::SNS_BOUNCE: |
||
45 | $event = strtolower($sesMessage['bounce']['bounceType']).'_bounce'; |
||
46 | View Code Duplication | foreach ($sesMessage['bounce']['bouncedRecipients'] as $recipient) { |
|
47 | $hooks[] = new DefaultHook($event, $recipient['emailAddress'], 'ses', $sesMessage, $this->eventAssoc[$event]); |
||
48 | } |
||
49 | |||
50 | break; |
||
51 | case self::SNS_COMPLAINT: |
||
52 | $event = 'spam_complaint'; |
||
53 | View Code Duplication | foreach ($sesMessage['complaint']['complainedRecipients'] as $recipient) { |
|
54 | $hooks[] = new DefaultHook($event, $recipient['emailAddress'], 'ses', $sesMessage, $this->eventAssoc[$event]); |
||
55 | } |
||
56 | |||
57 | break; |
||
58 | case self::SNS_DELIVERY: |
||
59 | $event = 'delivery'; |
||
60 | foreach ($sesMessage['delivery']['recipients'] as $recipient) { |
||
61 | $hooks[] = new DefaultHook($event, $recipient, 'ses', $sesMessage, $this->eventAssoc[$event]); |
||
62 | } |
||
63 | |||
64 | break; |
||
65 | default: |
||
66 | } |
||
67 | |||
68 | return $hooks; |
||
69 | } |
||
70 | } |
||
71 |
This check looks for calls to
isset(...)
orempty()
on variables that are yet undefined. These calls will always produce the same result and can be removed.This is most likely caused by the renaming of a variable or the removal of a function/method parameter.