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) |
|
| 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) |
|
| 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) |
|
| 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 = []) |
|
| 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 | function all($params = []) |
||
| 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 | function recent($params = []) |
||
| 133 | |||
| 134 | /** |
||
| 135 | * @param int $id |
||
| 136 | * @param array $params Array of optional parameters ['property', 'propertyMode', 'formSubmissionMode', |
||
| 137 | * 'showListMemberships'] |
||
| 138 | * @return \SevenShores\Hubspot\Http\Response |
||
| 139 | */ |
||
| 140 | function getById($id, $params = []) |
||
| 148 | |||
| 149 | /** |
||
| 150 | * For a given portal, return information about a group of contacts by their unique ID's. A contact's unique ID's |
||
| 151 | * is stored in a field called 'vid' which stands for 'visitor ID'. |
||
| 152 | * |
||
| 153 | * This method will also return you much of the HubSpot lead "intelligence" for each requested contact record. The |
||
| 154 | * endpoint accepts many query parameters that allow for customization based on a variety of integration use cases. |
||
| 155 | * |
||
| 156 | * @see http://developers.hubspot.com/docs/methods/contacts/get_batch_by_vid |
||
| 157 | * |
||
| 158 | * @param array $vids Array of visitor IDs |
||
| 159 | * @param array $params Array of optional parameters ['property', 'propertyMode', 'formSubmissionMode', |
||
| 160 | * 'showListMemberships', 'includeDeletes'] |
||
| 161 | * @return \SevenShores\Hubspot\Http\Response |
||
| 162 | */ |
||
| 163 | function getBatchByIds($vids, $params = []) |
||
| 173 | |||
| 174 | /** |
||
| 175 | * @param string $email |
||
| 176 | * @param array $params Array of optional parameters ['property', 'propertyMode', 'formSubmissionMode', |
||
| 177 | * 'showListMemberships'] |
||
| 178 | * @return \SevenShores\Hubspot\Http\Response |
||
| 179 | */ |
||
| 180 | function getByEmail($email, $params = []) |
||
| 188 | |||
| 189 | /** |
||
| 190 | * For a given portal, return information about a group of contacts by their email addresses. |
||
| 191 | * |
||
| 192 | * This method will also return you much of the HubSpot lead "intelligence" for each requested contact record. The |
||
| 193 | * endpoint accepts many query parameters that allow for customization based on a variety of integration use cases. |
||
| 194 | * |
||
| 195 | * @see http://developers.hubspot.com/docs/methods/contacts/get_batch_by_email |
||
| 196 | * |
||
| 197 | * @param array $emails Array of email adresses |
||
| 198 | * @param array $params Array of optional parameters ['property', 'propertyMode', 'formSubmissionMode', |
||
| 199 | * 'showListMemberships', 'includeDeletes'] |
||
| 200 | * @return \SevenShores\Hubspot\Http\Response |
||
| 201 | */ |
||
| 202 | function getBatchByEmails($emails, $params = []) |
||
| 212 | |||
| 213 | /** |
||
| 214 | * @param string $utk |
||
| 215 | * @param array $params Array of optional parameters ['property', 'propertyMode', 'formSubmissionMode', |
||
| 216 | * 'showListMemberships'] |
||
| 217 | * @return \SevenShores\Hubspot\Http\Response |
||
| 218 | */ |
||
| 219 | function getByToken($utk, $params = []) |
||
| 227 | |||
| 228 | /** |
||
| 229 | * For a given portal, return information about a group of contacts by their user tokens (hubspotutk). |
||
| 230 | * |
||
| 231 | * This method will also return you much of the HubSpot lead "intelligence" for each requested contact |
||
| 232 | * record. The endpoint accepts many query parameters that allow for customization based on a variety of |
||
| 233 | * integration use cases. |
||
| 234 | * |
||
| 235 | * The endpoint does not allow for CORS, so if you are looking up contacts from their user token on the client, |
||
| 236 | * you'll need to spin up a proxy server to interact with the API. |
||
| 237 | * |
||
| 238 | * @see http://developers.hubspot.com/docs/methods/contacts/get_batch_by_utk |
||
| 239 | * |
||
| 240 | * @param array $utks Array of hubspot user tokens (hubspotutk) |
||
| 241 | * @param array $params Array of optional parameters ['property', 'propertyMode', 'formSubmissionMode', |
||
| 242 | * 'showListMemberships', 'includeDeletes'] |
||
| 243 | * @return \SevenShores\Hubspot\Http\Response |
||
| 244 | */ |
||
| 245 | function getBatchByTokens($utks, $params = []) |
||
| 255 | |||
| 256 | /** |
||
| 257 | * For a given portal, return contacts and some data associated with |
||
| 258 | * those contacts by the contact's email address or name. |
||
| 259 | * |
||
| 260 | * Please note that you should expect this method to only return a small |
||
| 261 | * subset of data about the contact. One piece of data that the method will |
||
| 262 | * return is the contact ID (vid) that you can then use to look up much |
||
| 263 | * more data about that particular contact by its ID. |
||
| 264 | * |
||
| 265 | * @see http://developers.hubspot.com/docs/methods/contacts/search_contacts |
||
| 266 | * |
||
| 267 | * @param string $query Search query |
||
| 268 | * @param array $params Array of optional parameters ['count', 'offset'] |
||
| 269 | * @return \SevenShores\Hubspot\Http\Response |
||
| 270 | */ |
||
| 271 | function search($query, $params = []) |
||
| 281 | |||
| 282 | /** |
||
| 283 | * @return \SevenShores\Hubspot\Http\Response |
||
| 284 | */ |
||
| 285 | function statistics() |
||
| 291 | |||
| 292 | /** |
||
| 293 | * Merge two contact records. The contact ID in the URL will be treated as the |
||
| 294 | * primary contact, and the contact ID in the request body will be treated as |
||
| 295 | * the secondary contact. |
||
| 296 | * |
||
| 297 | * @param int $id Primary contact id. |
||
| 298 | * @param int $vidToMerge Contact ID of the secondary contact. |
||
| 299 | * @return \SevenShores\Hubspot\Http\Response |
||
| 300 | */ |
||
| 301 | View Code Duplication | function merge($id, $vidToMerge) |
|
| 309 | |||
| 310 | } |
||
| 311 |
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.