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 |
||
| 5 | class Companies extends Resource |
||
| 6 | { |
||
| 7 | |||
| 8 | /** |
||
| 9 | * Create a company |
||
| 10 | * @param array $properties Array of company properties. |
||
| 11 | * |
||
| 12 | * @see http://developers.hubspot.com/docs/methods/companies/create_company |
||
| 13 | * |
||
| 14 | * @return \SevenShores\Hubspot\Http\Response |
||
| 15 | */ |
||
| 16 | function create($properties) |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Updates a company |
||
| 26 | * @param int $id The company id. |
||
| 27 | * @param array $properties The company properties to update. |
||
| 28 | * |
||
| 29 | * @see http://developers.hubspot.com/docs/methods/companies/update_company |
||
| 30 | * |
||
| 31 | * @return \SevenShores\Hubspot\Http\Response |
||
| 32 | */ |
||
| 33 | View Code Duplication | function update($id, $properties) |
|
| 40 | |||
| 41 | /** |
||
| 42 | * @param array $companies The companies and properties. |
||
| 43 | * @return \SevenShores\Hubspot\Http\Response |
||
| 44 | */ |
||
| 45 | function updateBatch($companies) |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Deletes a company |
||
| 55 | * @param int $id The company id |
||
| 56 | * |
||
| 57 | * @see http://developers.hubspot.com/docs/methods/companies/delete_company |
||
| 58 | * |
||
| 59 | * @return \SevenShores\Hubspot\Http\Response |
||
| 60 | */ |
||
| 61 | function delete($id) |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Returns all companies |
||
| 70 | * @param array $params Array of optional parameters ['limit', 'offset', 'properties'] |
||
| 71 | * |
||
| 72 | * @see http://developers.hubspot.com/docs/methods/companies/get-all-companies |
||
| 73 | * |
||
| 74 | * @return \SevenShores\Hubspot\Http\Response |
||
| 75 | */ |
||
| 76 | function all($params = []) |
||
| 77 | { |
||
| 78 | $endpoint = 'https://api.hubapi.com/companies/v2/companies/paged'; |
||
| 79 | |||
| 80 | $queryString = build_query_string($params); |
||
| 81 | |||
| 82 | return $this->client->request('get', $endpoint, [], $queryString); |
||
| 83 | } |
||
| 84 | |||
| 85 | /** |
||
| 86 | * Returns the recently modified companies |
||
| 87 | * @param array $params Array of optional parameters ['count', 'offset'] |
||
| 88 | * |
||
| 89 | * @see http://developers.hubspot.com/docs/methods/companies/get_companies_modified |
||
| 90 | * |
||
| 91 | * @return \SevenShores\Hubspot\Http\Response |
||
| 92 | */ |
||
| 93 | function getRecentlyModified($params = []) |
||
| 94 | { |
||
| 95 | $endpoint = 'https://api.hubapi.com/companies/v2/companies/recent/modified'; |
||
| 96 | |||
| 97 | $queryString = build_query_string($params); |
||
| 98 | |||
| 99 | return $this->client->request('get', $endpoint, [], $queryString); |
||
| 100 | } |
||
| 101 | |||
| 102 | /** |
||
| 103 | * Returns the recently created companies |
||
| 104 | * @param array $params Array of optional parameters ['count', 'offset'] |
||
| 105 | * |
||
| 106 | * @see http://developers.hubspot.com/docs/methods/companies/get_companies_created |
||
| 107 | * |
||
| 108 | * @return \SevenShores\Hubspot\Http\Response |
||
| 109 | */ |
||
| 110 | function getRecentlyCreated($params = []) |
||
| 118 | |||
| 119 | /** |
||
| 120 | * Returns an array of companies that have a matching domain |
||
| 121 | * @param string $domain The domain of the company eq. 'example.com'. |
||
| 122 | * |
||
| 123 | * @see http://developers.hubspot.com/docs/methods/companies/get_companies_by_domain |
||
| 124 | * |
||
| 125 | * @return \SevenShores\Hubspot\Http\Response |
||
| 126 | */ |
||
| 127 | function getByDomain($domain) |
||
| 133 | |||
| 134 | /** |
||
| 135 | * @param string $domain |
||
| 136 | * @param array $properties |
||
| 137 | * @param int $limit |
||
| 138 | * @param int $offset |
||
| 139 | * |
||
| 140 | * @see https://developers.hubspot.com/docs/methods/companies/search_companies_by_domain |
||
| 141 | * |
||
| 142 | * @return \Psr\Http\Message\ResponseInterface|\SevenShores\Hubspot\Http\Response |
||
| 143 | */ |
||
| 144 | public function searchByDomain($domain, $properties = [], $limit = 100, $offset = 0) |
||
| 159 | |||
| 160 | /** |
||
| 161 | * Returns a company with id $id |
||
| 162 | * @param int $id |
||
| 163 | * |
||
| 164 | * @see http://developers.hubspot.com/docs/methods/companies/get_company |
||
| 165 | * |
||
| 166 | * @return \SevenShores\Hubspot\Http\Response |
||
| 167 | */ |
||
| 168 | function getById($id) |
||
| 174 | |||
| 175 | /** |
||
| 176 | * Associates a given contact to a given company |
||
| 177 | * If a contact is already associated to a different company, the contact will be added to the new company |
||
| 178 | * @param int $contactId |
||
| 179 | * @param int $companyId |
||
| 180 | * |
||
| 181 | * @see http://developers.hubspot.com/docs/methods/companies/add_contact_to_company |
||
| 182 | * |
||
| 183 | * @return \SevenShores\Hubspot\Http\Response |
||
| 184 | */ |
||
| 185 | function addContact($contactId, $companyId) |
||
| 191 | |||
| 192 | /** |
||
| 193 | * Returns an array of the associated contacts for the given company |
||
| 194 | * @param int $companyId The id of the company. |
||
| 195 | * @param array $params Array of optional parameters ['count', 'vidOffset'] |
||
| 196 | * |
||
| 197 | * @see http://developers.hubspot.com/docs/methods/companies/get_company_contacts |
||
| 198 | * |
||
| 199 | * @return \SevenShores\Hubspot\Http\Response |
||
| 200 | */ |
||
| 201 | function getAssociatedContacts($companyId, $params = []) |
||
| 209 | |||
| 210 | /** |
||
| 211 | * Returns all of the contact IDs who are associated with the given company |
||
| 212 | * @param int $companyId The id of the company. |
||
| 213 | * @param array $params Array of optional parameters ['count', 'vidOffset'] |
||
| 214 | * |
||
| 215 | * @see http://developers.hubspot.com/docs/methods/companies/get_company_contacts_by_id |
||
| 216 | * |
||
| 217 | * @return \SevenShores\Hubspot\Http\Response |
||
| 218 | */ |
||
| 219 | function getAssociatedContactIds($companyId, $params = []) |
||
| 227 | |||
| 228 | /** |
||
| 229 | * Removes a contact from a company |
||
| 230 | * @param int $contactId |
||
| 231 | * @param int $companyId |
||
| 232 | * |
||
| 233 | * @see http://developers.hubspot.com/docs/methods/companies/remove_contact_from_company |
||
| 234 | * |
||
| 235 | * @return \SevenShores\Hubspot\Http\Response |
||
| 236 | */ |
||
| 237 | function removeContact($contactId, $companyId) |
||
| 243 | |||
| 244 | |||
| 245 | |||
| 246 | } |
||
| 247 |
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.