| Conditions | 11 |
| Paths | 34 |
| Total Lines | 35 |
| Code Lines | 25 |
| 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 |
||
| 34 | public function updateSubscriberForFreeProduct($email, $productid) |
||
| 35 | { |
||
| 36 | try { |
||
| 37 | $productGroupId = ''; |
||
| 38 | $interestGroupIdForNo = ''; |
||
| 39 | $interestGroupIdForYes = ''; |
||
| 40 | $merge_fields = $this->field($email); |
||
| 41 | $hash = md5($email); |
||
| 42 | $isPaidStatus = StatusSetting::select()->value('mailchimp_ispaid_status'); |
||
| 43 | $productStatusStatus = StatusSetting::select()->value('mailchimp_product_status'); |
||
| 44 | if ($isPaidStatus == 1) { |
||
| 45 | $interestGroupIdForNo = $this->relation->is_paid_no; //Interest GroupId for IsPaid Is No |
||
| 46 | $interestGroupIdForYes = $this->relation->is_paid_yes; //Interest GroupId for IsPaid Is Yes |
||
| 47 | } |
||
| 48 | if ($productStatusStatus == 1) { |
||
| 49 | $productGroupId = $this->groupRelation->where('agora_product_id', $productid) |
||
| 50 | ->pluck('mailchimp_group_cat_id')->first(); |
||
| 51 | } |
||
| 52 | if ($interestGroupIdForNo && $productGroupId) { |
||
| 53 | $result = $this->mailchimp->patch("lists/$this->list_id/members/$hash", [ |
||
| 54 | 'interests' => [$interestGroupIdForNo => true, $interestGroupIdForYes=>false, $productGroupId =>true], |
||
| 55 | ]); |
||
| 56 | //refer to https://us7.api.mailchimp.com/playground |
||
| 57 | } elseif ($interestGroupIdForNo && $productGroupId == null) { |
||
| 58 | $result = $this->mailchimp->patch("lists/$this->list_id/members/$hash", [ |
||
| 59 | 'interests' => [$interestGroupIdForNo => true, $interestGroupIdForYes=>false], |
||
| 60 | ]); |
||
| 61 | //refer to https://us7.api.mailchimp.com/playground |
||
| 62 | } elseif ($productGroupId && $interestGroupIdForNo == null || $interestGroupIdForYes == null) { |
||
| 63 | $result = $this->mailchimp->patch("lists/$this->list_id/members/$hash", [ |
||
| 64 | 'interests' => [$productGroupId =>true], |
||
| 65 | ]); |
||
| 66 | } |
||
| 67 | } catch (Exception $ex) { |
||
| 68 | $exe = json_decode($ex->getMessage(), true); |
||
| 69 | } |
||
| 173 |