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 ContactLists extends Resource |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * Create a new contact list. |
||
| 9 | * |
||
| 10 | * @param array $list Contact list properties. |
||
| 11 | * @return \SevenShores\Hubspot\Http\Response |
||
| 12 | */ |
||
| 13 | function create($list) |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Update a contact list. |
||
| 24 | * |
||
| 25 | * @param int $id The contact list id. |
||
| 26 | * @param array $list The contact list properties to update. |
||
| 27 | * @return \SevenShores\Hubspot\Http\Response |
||
| 28 | */ |
||
| 29 | View Code Duplication | function update($id, $list) |
|
| 37 | |||
| 38 | /** |
||
| 39 | * Delete a contact list. |
||
| 40 | * |
||
| 41 | * @param int $id |
||
| 42 | * @return \SevenShores\Hubspot\Http\Response |
||
| 43 | */ |
||
| 44 | function delete($id) |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Get a set of contact lists. |
||
| 53 | * |
||
| 54 | * @param array $params ['count', 'offset'] |
||
| 55 | * @return \SevenShores\Hubspot\Http\Response |
||
| 56 | */ |
||
| 57 | function all($params = []) |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @param int $id |
||
| 68 | * @return \SevenShores\Hubspot\Http\Response |
||
| 69 | */ |
||
| 70 | function getById($id) |
||
| 76 | |||
| 77 | /** |
||
| 78 | * @param array $ids |
||
| 79 | * @return \SevenShores\Hubspot\Http\Response |
||
| 80 | */ |
||
| 81 | function getBatchByIds($ids) |
||
| 89 | |||
| 90 | /** |
||
| 91 | * @param array $params Optional parameters ['count', 'offset'] |
||
| 92 | * @return \SevenShores\Hubspot\Http\Response |
||
| 93 | */ |
||
| 94 | function getAllStatic($params = []) |
||
| 102 | |||
| 103 | /** |
||
| 104 | * @param array $params Optional parameters ['count', 'offset'] |
||
| 105 | * @return \SevenShores\Hubspot\Http\Response |
||
| 106 | */ |
||
| 107 | function getAllDynamic($params = []) |
||
| 115 | |||
| 116 | /** |
||
| 117 | * Get contacts in a list. |
||
| 118 | * |
||
| 119 | * @param int $id List id |
||
| 120 | * @param array $params Optional parameters |
||
| 121 | * { count, vidOffset, property, propertyMode, formSubmissionMode, showListMemberships } |
||
| 122 | * @return \SevenShores\Hubspot\Http\Response |
||
| 123 | */ |
||
| 124 | function contacts($id, $params = []) |
||
| 132 | |||
| 133 | /** |
||
| 134 | * Get recently added contact from a list. |
||
| 135 | * |
||
| 136 | * @param int $id List id |
||
| 137 | * @param array $params |
||
| 138 | * @return \SevenShores\Hubspot\Http\Response |
||
| 139 | */ |
||
| 140 | function recentContacts($id, $params = []) |
||
| 148 | |||
| 149 | /** |
||
| 150 | * Refresh a list. |
||
| 151 | * |
||
| 152 | * @param int $id List id |
||
| 153 | * @return \SevenShores\Hubspot\Http\Response |
||
| 154 | */ |
||
| 155 | function refresh($id) |
||
| 161 | |||
| 162 | /** |
||
| 163 | * Add a contact to a list. |
||
| 164 | * |
||
| 165 | * @param int $list_id |
||
| 166 | * @param array $contact_ids |
||
| 167 | * @param array $emails |
||
| 168 | * @return \SevenShores\Hubspot\Http\Response |
||
| 169 | */ |
||
| 170 | View Code Duplication | function addContact($list_id, $contact_ids, $emails = []) |
|
| 181 | |||
| 182 | /** |
||
| 183 | * Remove a contact from a list. |
||
| 184 | * |
||
| 185 | * @param int $list_id |
||
| 186 | * @param array $contact_ids |
||
| 187 | * @return \SevenShores\Hubspot\Http\Response |
||
| 188 | */ |
||
| 189 | View Code Duplication | function removeContact($list_id, $contact_ids) |
|
| 197 | |||
| 198 | } |
||
| 199 |
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.