| Conditions | 11 |
| Paths | 34 |
| Total Lines | 34 |
| Code Lines | 22 |
| 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 |
||
| 74 | public function updateSubscriberForPaidProduct($email, $productid) |
||
| 75 | { |
||
| 76 | try { |
||
| 77 | $merge_fields = $this->field($email); |
||
| 78 | $hash = md5($email); |
||
| 79 | $isPaidStatus = StatusSetting::select()->value('mailchimp_ispaid_status'); |
||
| 80 | $productStatusStatus = StatusSetting::select()->value('mailchimp_product_status'); |
||
| 81 | if ($isPaidStatus ==1) { |
||
| 82 | $interestGroupIdForNo = $this->relation->is_paid_no; //Interest GroupId for IsPaid Is No |
||
| 83 | $interestGroupIdForYes = $this->relation->is_paid_yes; //Interest GroupId for IsPaid Is Yes |
||
| 84 | } |
||
| 85 | if ($productStatusStatus ==1) { |
||
| 86 | $productGroupId = $this->groupRelation->where('agora_product_id', $productid) |
||
| 87 | ->pluck('mailchimp_group_cat_id')->first(); |
||
| 88 | } |
||
| 89 | if ($interestGroupIdForNo && $productGroupId) { |
||
| 90 | $result = $this->mailchimp->patch("lists/$this->list_id/members/$hash", [ |
||
| 91 | 'interests' => [$interestGroupIdForNo => false, $interestGroupIdForYes=>true, $productGroupId =>true], |
||
| 92 | //refer to https://us7.api.mailchimp.com/playground |
||
| 93 | ]); |
||
| 94 | } elseif ($interestGroupIdForNo && $productGroupId ==null) { |
||
| 95 | $result = $this->mailchimp->patch("lists/$this->list_id/members/$hash", [ |
||
| 96 | 'interests' => [$interestGroupIdForNo => false, $interestGroupIdForYes=>true], |
||
| 97 | ]); |
||
| 98 | //refer to https://us7.api.mailchimp.com/playground |
||
| 99 | } elseif ($productGroupId && $interestGroupIdForNo==null || $interestGroupIdForYes==null) { |
||
| 100 | $result = $this->mailchimp->patch("lists/$this->list_id/members/$hash", [ |
||
| 101 | 'interests' => [$productGroupId =>true], |
||
| 102 | ]); |
||
| 103 | } |
||
| 104 | //refer to https://us7.api.mailchimp.com/playground |
||
| 105 | |||
| 106 | } catch (Exception $ex) { |
||
| 107 | $exe = json_decode($ex->getMessage(), true); |
||
| 108 | } |
||
| 122 |