Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 6 | class Contacts extends Resource |
||
| 7 | { |
||
| 8 | /** |
||
| 9 | * @param array $properties Array of contact properties. |
||
| 10 | * @return \SevenShores\Hubspot\Http\Response |
||
| 11 | */ |
||
| 12 | View Code Duplication | function create($properties) |
|
|
|
|||
| 13 | { |
||
| 14 | $endpoint = "https://api.hubapi.com/contacts/v1/contact"; |
||
| 15 | |||
| 16 | $options['json'] = ['properties' => $properties]; |
||
| 17 | |||
| 18 | return $this->client->request('post', $endpoint, $options); |
||
| 19 | } |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @param int $id The contact id. |
||
| 23 | * @param array $properties The contact properties to update. |
||
| 24 | * @return \SevenShores\Hubspot\Http\Response |
||
| 25 | */ |
||
| 26 | View Code Duplication | function update($id, $properties) |
|
| 27 | { |
||
| 28 | $endpoint = "https://api.hubapi.com/contacts/v1/contact/vid/{$id}/profile"; |
||
| 29 | |||
| 30 | $options['json'] = ['properties' => $properties]; |
||
| 31 | |||
| 32 | return $this->client->request('post', $endpoint, $options); |
||
| 33 | } |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @param string $email The contact's email address. |
||
| 37 | * @param array $properties The contact properties to update. |
||
| 38 | * @return \SevenShores\Hubspot\Http\Response |
||
| 39 | */ |
||
| 40 | View Code Duplication | function updateByEmail($email, $properties) |
|
| 41 | { |
||
| 42 | $endpoint = "https://api.hubapi.com/contacts/v1/contact/email/{$email}/profile"; |
||
| 43 | |||
| 44 | $options['json'] = ['properties' => $properties]; |
||
| 45 | |||
| 46 | return $this->client->request('post', $endpoint, $options); |
||
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @param string $email The contact's email address. |
||
| 51 | * @param array $properties The contact properties. |
||
| 52 | * @return \SevenShores\Hubspot\Http\Response |
||
| 53 | */ |
||
| 54 | View Code Duplication | function createOrUpdate($email, $properties = []) |
|
| 55 | { |
||
| 56 | $endpoint = "https://api.hubapi.com/contacts/v1/contact/createOrUpdate/email/{$email}"; |
||
| 57 | |||
| 58 | $options['json'] = ['properties' => $properties]; |
||
| 59 | |||
| 60 | return $this->client->request('post', $endpoint, $options); |
||
| 61 | } |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @param array $contacts The contacts and properties. |
||
| 65 | * @param array $params Array of optional parameters ['auditId'] |
||
| 66 | * @return \SevenShores\Hubspot\Http\Response |
||
| 67 | */ |
||
| 68 | function createOrUpdateBatch($contacts, $params = []) |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @param int $id |
||
| 81 | * @return \SevenShores\Hubspot\Http\Response |
||
| 82 | */ |
||
| 83 | function delete($id) |
||
| 89 | |||
| 90 | /** |
||
| 91 | * For a given portal, return all contacts that have been created in the portal. |
||
| 92 | * |
||
| 93 | * A paginated list of contacts will be returned to you, with a maximum of 100 contacts per page. |
||
| 94 | * |
||
| 95 | * Please Note: There are 2 fields here to pay close attention to: the "has-more" field that will let you know |
||
| 96 | * whether there are more contacts that you can pull from this portal, and the "vid-offset" field which will let |
||
| 97 | * you know where you are in the list of contacts. You can then use the "vid-offset" field in the "vidOffset" |
||
| 98 | * parameter described below. |
||
| 99 | * |
||
| 100 | * @see http://developers.hubspot.com/docs/methods/contacts/get_contacts |
||
| 101 | * |
||
| 102 | * @param array $params Array of optional parameters ['count', 'property', 'vidOffset'] |
||
| 103 | * @return \SevenShores\Hubspot\Http\Response |
||
| 104 | */ |
||
| 105 | View Code Duplication | function all($params = []) |
|
| 106 | { |
||
| 107 | $endpoint = "https://api.hubapi.com/contacts/v1/lists/all/contacts/all"; |
||
| 108 | |||
| 109 | $queryString = build_query_string($params); |
||
| 110 | |||
| 111 | return $this->client->request('get', $endpoint, [], $queryString); |
||
| 112 | } |
||
| 113 | |||
| 114 | /** |
||
| 115 | * For a given portal, return all contacts that have been recently updated or created. |
||
| 116 | * A paginated list of contacts will be returned to you, with a maximum of 100 contacts per page, as specified by |
||
| 117 | * the "count" parameter. The endpoint only scrolls back in time 30 days. |
||
| 118 | * |
||
| 119 | * @see http://developers.hubspot.com/docs/methods/contacts/get_recently_updated_contacts |
||
| 120 | * |
||
| 121 | * @param array $params Array of optional parameters ['count', 'timeOffset', 'vidOffset', 'property', |
||
| 122 | * 'propertyMode', 'formSubmissionMode', 'showListMemberships'] |
||
| 123 | * @return \SevenShores\Hubspot\Http\Response |
||
| 124 | */ |
||
| 125 | View Code Duplication | function recent($params = []) |
|
| 126 | { |
||
| 127 | $endpoint = "https://api.hubapi.com/contacts/v1/lists/recently_updated/contacts/recent"; |
||
| 128 | |||
| 129 | $queryString = build_query_string($params); |
||
| 130 | |||
| 131 | return $this->client->request('get', $endpoint, [], $queryString); |
||
| 132 | } |
||
| 133 | |||
| 134 | /** |
||
| 135 | * For a given portal, return all contacts that have been recently created. |
||
| 136 | * A paginated list of contacts will be returned to you, with a maximum of 100 contacts per page, as specified by |
||
| 137 | * the "count" parameter. The endpoint only scrolls back in time 30 days. |
||
| 138 | * |
||
| 139 | * @see http://developers.hubspot.com/docs/methods/contacts/get_recently_updated_contacts |
||
| 140 | * |
||
| 141 | * @param array $params Array of optional parameters ['count', 'timeOffset', 'vidOffset', 'property', |
||
| 142 | * 'propertyMode', 'formSubmissionMode', 'showListMemberships'] |
||
| 143 | * @return \SevenShores\Hubspot\Http\Response |
||
| 144 | */ |
||
| 145 | View Code Duplication | function recentNew($params = []) |
|
| 146 | { |
||
| 147 | $endpoint = "https://api.hubapi.com/contacts/v1/lists/all/contacts/recent"; |
||
| 148 | |||
| 149 | $queryString = build_query_string($params); |
||
| 150 | |||
| 151 | return $this->client->request('get', $endpoint, [], $queryString); |
||
| 152 | } |
||
| 153 | |||
| 154 | /** |
||
| 155 | * @param int $id |
||
| 156 | * @param array $params Array of optional parameters ['property', 'propertyMode', 'formSubmissionMode', |
||
| 157 | * 'showListMemberships'] |
||
| 158 | * @return \SevenShores\Hubspot\Http\Response |
||
| 159 | */ |
||
| 160 | View Code Duplication | function getById($id, $params = []) |
|
| 161 | { |
||
| 162 | $endpoint = "https://api.hubapi.com/contacts/v1/contact/vid/{$id}/profile"; |
||
| 163 | |||
| 164 | $queryString = build_query_string($params); |
||
| 165 | |||
| 166 | return $this->client->request('get', $endpoint, [], $queryString); |
||
| 167 | } |
||
| 168 | |||
| 169 | /** |
||
| 170 | * For a given portal, return information about a group of contacts by their unique ID's. A contact's unique ID's |
||
| 171 | * is stored in a field called 'vid' which stands for 'visitor ID'. |
||
| 172 | * |
||
| 173 | * This method will also return you much of the HubSpot lead "intelligence" for each requested contact record. The |
||
| 174 | * endpoint accepts many query parameters that allow for customization based on a variety of integration use cases. |
||
| 175 | * |
||
| 176 | * @see http://developers.hubspot.com/docs/methods/contacts/get_batch_by_vid |
||
| 177 | * |
||
| 178 | * @param array $vids Array of visitor IDs |
||
| 179 | * @param array $params Array of optional parameters ['property', 'propertyMode', 'formSubmissionMode', |
||
| 180 | * 'showListMemberships', 'includeDeletes'] |
||
| 181 | * @return \SevenShores\Hubspot\Http\Response |
||
| 182 | */ |
||
| 183 | View Code Duplication | function getBatchByIds($vids, $params = []) |
|
| 184 | { |
||
| 185 | $endpoint = "https://api.hubapi.com/contacts/v1/contact/vids/batch/"; |
||
| 186 | |||
| 187 | $params['vid'] = $vids; |
||
| 188 | |||
| 189 | $queryString = build_query_string($params); |
||
| 190 | |||
| 191 | return $this->client->request('get', $endpoint, [], $queryString); |
||
| 192 | } |
||
| 193 | |||
| 194 | /** |
||
| 195 | * @param string $email |
||
| 196 | * @param array $params Array of optional parameters ['property', 'propertyMode', 'formSubmissionMode', |
||
| 197 | * 'showListMemberships'] |
||
| 198 | * @return \SevenShores\Hubspot\Http\Response |
||
| 199 | */ |
||
| 200 | View Code Duplication | function getByEmail($email, $params = []) |
|
| 201 | { |
||
| 202 | $endpoint = "https://api.hubapi.com/contacts/v1/contact/email/{$email}/profile"; |
||
| 203 | |||
| 204 | $queryString = build_query_string($params); |
||
| 205 | |||
| 206 | return $this->client->request('get', $endpoint, [], $queryString); |
||
| 207 | } |
||
| 208 | |||
| 209 | /** |
||
| 210 | * For a given portal, return information about a group of contacts by their email addresses. |
||
| 211 | * |
||
| 212 | * This method will also return you much of the HubSpot lead "intelligence" for each requested contact record. The |
||
| 213 | * endpoint accepts many query parameters that allow for customization based on a variety of integration use cases. |
||
| 214 | * |
||
| 215 | * @see http://developers.hubspot.com/docs/methods/contacts/get_batch_by_email |
||
| 216 | * |
||
| 217 | * @param array $emails Array of email adresses |
||
| 218 | * @param array $params Array of optional parameters ['property', 'propertyMode', 'formSubmissionMode', |
||
| 219 | * 'showListMemberships', 'includeDeletes'] |
||
| 220 | * @return \SevenShores\Hubspot\Http\Response |
||
| 221 | */ |
||
| 222 | View Code Duplication | function getBatchByEmails($emails, $params = []) |
|
| 223 | { |
||
| 224 | $endpoint = "https://api.hubapi.com/contacts/v1/contact/emails/batch/"; |
||
| 225 | |||
| 226 | $params['email'] = $emails; |
||
| 227 | |||
| 228 | $queryString = build_query_string($params); |
||
| 229 | |||
| 230 | return $this->client->request('get', $endpoint, [], $queryString); |
||
| 231 | } |
||
| 232 | |||
| 233 | /** |
||
| 234 | * @param string $utk |
||
| 235 | * @param array $params Array of optional parameters ['property', 'propertyMode', 'formSubmissionMode', |
||
| 236 | * 'showListMemberships'] |
||
| 237 | * @return \SevenShores\Hubspot\Http\Response |
||
| 238 | */ |
||
| 239 | View Code Duplication | function getByToken($utk, $params = []) |
|
| 240 | { |
||
| 241 | $endpoint = "https://api.hubapi.com/contacts/v1/contact/utk/{$utk}/profile"; |
||
| 242 | |||
| 243 | $queryString = build_query_string($params); |
||
| 244 | |||
| 245 | return $this->client->request('get', $endpoint, [], $queryString); |
||
| 246 | } |
||
| 247 | |||
| 248 | /** |
||
| 249 | * For a given portal, return information about a group of contacts by their user tokens (hubspotutk). |
||
| 250 | * |
||
| 251 | * This method will also return you much of the HubSpot lead "intelligence" for each requested contact |
||
| 252 | * record. The endpoint accepts many query parameters that allow for customization based on a variety of |
||
| 253 | * integration use cases. |
||
| 254 | * |
||
| 255 | * The endpoint does not allow for CORS, so if you are looking up contacts from their user token on the client, |
||
| 256 | * you'll need to spin up a proxy server to interact with the API. |
||
| 257 | * |
||
| 258 | * @see http://developers.hubspot.com/docs/methods/contacts/get_batch_by_utk |
||
| 259 | * |
||
| 260 | * @param array $utks Array of hubspot user tokens (hubspotutk) |
||
| 261 | * @param array $params Array of optional parameters ['property', 'propertyMode', 'formSubmissionMode', |
||
| 262 | * 'showListMemberships', 'includeDeletes'] |
||
| 263 | * @return \SevenShores\Hubspot\Http\Response |
||
| 264 | */ |
||
| 265 | View Code Duplication | function getBatchByTokens($utks, $params = []) |
|
| 266 | { |
||
| 267 | $endpoint = "https://api.hubapi.com/contacts/v1/contact/utks/batch/"; |
||
| 268 | |||
| 269 | $params['utk'] = $utks; |
||
| 270 | |||
| 271 | $queryString = build_query_string($params); |
||
| 272 | |||
| 273 | return $this->client->request('get', $endpoint, [], $queryString); |
||
| 274 | } |
||
| 275 | |||
| 276 | /** |
||
| 277 | * For a given portal, return contacts and some data associated with |
||
| 278 | * those contacts by the contact's email address or name. |
||
| 279 | * |
||
| 280 | * Please note that you should expect this method to only return a small |
||
| 281 | * subset of data about the contact. One piece of data that the method will |
||
| 282 | * return is the contact ID (vid) that you can then use to look up much |
||
| 283 | * more data about that particular contact by its ID. |
||
| 284 | * |
||
| 285 | * @see http://developers.hubspot.com/docs/methods/contacts/search_contacts |
||
| 286 | * |
||
| 287 | * @param string $query Search query |
||
| 288 | * @param array $params Array of optional parameters ['count', 'offset'] |
||
| 289 | * @return \SevenShores\Hubspot\Http\Response |
||
| 290 | */ |
||
| 291 | View Code Duplication | function search($query, $params = []) |
|
| 292 | { |
||
| 293 | $endpoint = "https://api.hubapi.com/contacts/v1/search/query"; |
||
| 294 | |||
| 295 | $params['q'] = $query; |
||
| 296 | |||
| 297 | $queryString = build_query_string($params); |
||
| 298 | |||
| 299 | return $this->client->request('get', $endpoint, [], $queryString); |
||
| 300 | } |
||
| 301 | |||
| 302 | /** |
||
| 303 | * @return \SevenShores\Hubspot\Http\Response |
||
| 304 | */ |
||
| 305 | function statistics() |
||
| 311 | |||
| 312 | /** |
||
| 313 | * Merge two contact records. The contact ID in the URL will be treated as the |
||
| 314 | * primary contact, and the contact ID in the request body will be treated as |
||
| 315 | * the secondary contact. |
||
| 316 | * |
||
| 317 | * @param int $id Primary contact id. |
||
| 318 | * @param int $vidToMerge Contact ID of the secondary contact. |
||
| 319 | * @return \SevenShores\Hubspot\Http\Response |
||
| 320 | */ |
||
| 321 | function merge($id, $vidToMerge) |
||
| 329 | |||
| 330 | } |
||
| 331 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.