| Conditions | 6 |
| Paths | 6 |
| Total Lines | 55 |
| Code Lines | 32 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 5 | ||
| 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 |
||
| 40 | public function send($notifiable, Notification $notification): ?array |
||
| 41 | { |
||
| 42 | $hubspotContactId = $notifiable->getHubspotContactId($notification); |
||
| 43 | |||
| 44 | if (empty($hubspotContactId)) { |
||
| 45 | return null; |
||
| 46 | } |
||
| 47 | |||
| 48 | if (! method_exists($notification, 'toMail')) { |
||
| 49 | return null; |
||
| 50 | } |
||
| 51 | |||
| 52 | $message = $notification->toMail($notifiable); |
||
| 53 | |||
| 54 | $params = [ |
||
| 55 | "properties" => [ |
||
| 56 | "hs_timestamp" => round(microtime(true) * 1000), |
||
| 57 | "hubspot_owner_id" => $message->metadata['hubspot_owner_id'] ?? config('hubspot.hubspot_owner_id'), |
||
| 58 | "hs_email_direction" => "EMAIL", |
||
| 59 | "hs_email_status" => "SENT", |
||
| 60 | "hs_email_subject" => $message->subject, |
||
| 61 | "hs_email_text" => (string)$message->render(), |
||
| 62 | ], |
||
| 63 | ]; |
||
| 64 | |||
| 65 | $hubspotEmail = $this->callApi(self::HUBSPOT_URL_V3 . 'emails', 'post', $params); |
||
| 66 | |||
| 67 | if (! empty($hubspotEmail['id'])) { |
||
| 68 | |||
| 69 | $this->callApi( |
||
| 70 | self::HUBSPOT_URL_V4 . 'contact/'. $hubspotContactId .'/associations/default/email/' . $hubspotEmail['id'], |
||
| 71 | 'put', |
||
| 72 | ["associationTypeId" => 197] |
||
| 73 | ); |
||
| 74 | |||
| 75 | if(config('hubspot.company_email_associations')) { |
||
| 76 | $contactResp = $this->callApi( |
||
| 77 | self::HUBSPOT_URL_V3 . 'contacts/' . $hubspotContactId, |
||
| 78 | 'get', |
||
| 79 | ['properties' => 'associatedcompanyid'] |
||
| 80 | ); |
||
| 81 | |||
| 82 | $hubspotCompanyId = $contactResp['properties']['associatedcompanyid'] ?? null; |
||
| 83 | |||
| 84 | if ($hubspotCompanyId) { |
||
| 85 | $this->callApi( |
||
| 86 | self::HUBSPOT_URL_V4 . 'company/' . $hubspotCompanyId . '/associations/default/email/' . $hubspotEmail['id'], |
||
| 87 | 'put', |
||
| 88 | ["associationTypeId" => 185] |
||
| 89 | ); |
||
| 90 | } |
||
| 91 | } |
||
| 92 | } |
||
| 93 | |||
| 94 | return $hubspotEmail; |
||
| 95 | } |
||
| 126 |