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 Deals extends Resource |
||
| 7 | { |
||
| 8 | /** |
||
| 9 | * @param array $deal Array of deal properties. |
||
| 10 | * @return mixed |
||
| 11 | * @throws HubSpotException |
||
| 12 | */ |
||
| 13 | function create(array $deal) |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @param int $id The deal id. |
||
| 24 | * @param array $deal The deal properties to update. |
||
| 25 | * @return mixed |
||
| 26 | */ |
||
| 27 | View Code Duplication | function update($id, array $deal) |
|
| 35 | |||
| 36 | /** |
||
| 37 | * Update a group of existing deal records by their dealId. |
||
| 38 | * |
||
| 39 | * @see https://developers.hubspot.com/docs/methods/deals/batch-update-deals |
||
| 40 | * |
||
| 41 | * @param array $deals The deals and properties. |
||
| 42 | * @return \SevenShores\Hubspot\Http\Response |
||
| 43 | */ |
||
| 44 | function updateBatch(array $deals) |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @param array $params |
||
| 55 | * |
||
| 56 | * @return \Psr\Http\Message\ResponseInterface|\SevenShores\Hubspot\Http\Response |
||
| 57 | * @throws \SevenShores\Hubspot\Exceptions\BadRequest |
||
| 58 | */ |
||
| 59 | function getAll(array $params = []){ |
||
| 66 | |||
| 67 | |||
| 68 | /** |
||
| 69 | * @param int $id |
||
| 70 | * @return mixed |
||
| 71 | */ |
||
| 72 | function delete($id) |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @param array $params Optional parameters ['limit', 'offset'] |
||
| 81 | * @return mixed |
||
| 82 | */ |
||
| 83 | function getRecentlyModified(array $params = []) |
||
| 90 | |||
| 91 | /** |
||
| 92 | * @param array $params Optional parameters ['limit', 'offset'] |
||
| 93 | * @return mixed |
||
| 94 | */ |
||
| 95 | function getRecentlyCreated(array $params = []) |
||
| 102 | |||
| 103 | /** |
||
| 104 | * @param int $id |
||
| 105 | * @return mixed |
||
| 106 | */ |
||
| 107 | function getById($id) |
||
| 113 | |||
| 114 | /** |
||
| 115 | * @param int $dealId |
||
| 116 | * @param int|int[] $companyIds |
||
| 117 | * @return mixed |
||
| 118 | */ |
||
| 119 | function associateWithCompany($dealId, $companyIds) |
||
| 127 | |||
| 128 | /** |
||
| 129 | * @param int $dealId |
||
| 130 | * @param int|int[] $companyIds |
||
| 131 | * @return mixed |
||
| 132 | */ |
||
| 133 | function disassociateFromCompany($dealId, $companyIds) |
||
| 141 | |||
| 142 | /** |
||
| 143 | * @param int $dealId |
||
| 144 | * @param int|int[] $contactIds |
||
| 145 | * @return mixed |
||
| 146 | */ |
||
| 147 | function associateWithContact($dealId, $contactIds) |
||
| 155 | |||
| 156 | /** |
||
| 157 | * @param int $contactId |
||
| 158 | * @param array $params Optional parameters ['limit', 'offset'] |
||
| 159 | * @return mixed |
||
| 160 | */ |
||
| 161 | function associatedWithContact($contactId, $params = []) |
||
| 169 | |||
| 170 | /** |
||
| 171 | * @param int $dealId |
||
| 172 | * @param int|int[] $contactIds |
||
| 173 | * @return mixed |
||
| 174 | */ |
||
| 175 | function disassociateFromContact($dealId, $contactIds) |
||
| 183 | |||
| 184 | /** |
||
| 185 | * @param string $objectType |
||
| 186 | * @param int $objectId |
||
| 187 | * @param array $params |
||
| 188 | * @return \Psr\Http\Message\ResponseInterface|\SevenShores\Hubspot\Http\Response |
||
| 189 | * |
||
| 190 | * @see https://developers.hubspot.com/docs/methods/deals/get-associated-deals |
||
| 191 | */ |
||
| 192 | public function getAssociatedDeals($objectType, $objectId, $params = []) |
||
| 200 | } |
||
| 201 |
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.