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 EcommerceBridge extends Resource |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * Installs the ecommerce bridge into a portal. |
||
| 9 | * |
||
| 10 | * @return \SevenShores\Hubspot\Http\Response |
||
| 11 | * @throws \SevenShores\Hubspot\Exceptions\BadRequest |
||
| 12 | */ |
||
| 13 | function install() |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Check the status of the ecommerce bridge. |
||
| 22 | * |
||
| 23 | * @return \SevenShores\Hubspot\Http\Response |
||
| 24 | * @throws \SevenShores\Hubspot\Exceptions\BadRequest |
||
| 25 | */ |
||
| 26 | function checkInstall() |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Uninstall the ecommerce settings from a portal. |
||
| 35 | * |
||
| 36 | * @return \SevenShores\Hubspot\Http\Response |
||
| 37 | * @throws \SevenShores\Hubspot\Exceptions\BadRequest |
||
| 38 | */ |
||
| 39 | function uninstall() |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Create or update the ecommerce settings. |
||
| 48 | * |
||
| 49 | * @param array $settings |
||
| 50 | * @return \SevenShores\Hubspot\Http\Response |
||
| 51 | * @throws \SevenShores\Hubspot\Exceptions\BadRequest |
||
| 52 | */ |
||
| 53 | function upsertSettings($settings = []) |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Delete the ecommerce settings for your app or portal. |
||
| 64 | * Note: This action cannot be undone. If you want to disable sync messages from being applied, it is recommended that you disable the settings rather than deleting them. |
||
| 65 | * |
||
| 66 | * @return \SevenShores\Hubspot\Http\Response |
||
| 67 | * @throws \SevenShores\Hubspot\Exceptions\BadRequest |
||
| 68 | */ |
||
| 69 | function deleteSettings() |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Send a group of sync messages for a specific object type. Sync messages would be notifications of creates, updates, or deletes of ecommerce objects. |
||
| 78 | * |
||
| 79 | * @param string $objectType - The object type that the updates are for. One of CONTACT, DEAL, PRODUCT, or LINE_ITEM. |
||
| 80 | * @param array $messages |
||
| 81 | * @return \SevenShores\Hubspot\Http\Response |
||
| 82 | * @throws \SevenShores\Hubspot\Exceptions\BadRequest |
||
| 83 | */ |
||
| 84 | View Code Duplication | function sendSyncMessages($objectType, $messages = []) |
|
| 92 | |||
| 93 | /** |
||
| 94 | * Get errors from previously processed sync messages. |
||
| 95 | * |
||
| 96 | * @return \SevenShores\Hubspot\Http\Response |
||
| 97 | * @throws \SevenShores\Hubspot\Exceptions\BadRequest |
||
| 98 | */ |
||
| 99 | function getSyncErrors() |
||
| 105 | |||
| 106 | /** |
||
| 107 | * Set the URI for the import initialization webhook. |
||
| 108 | * |
||
| 109 | * @param string $importTriggerUri - The URI that will be hit with the import webhook. |
||
| 110 | * @return \SevenShores\Hubspot\Http\Response |
||
| 111 | * @throws \SevenShores\Hubspot\Exceptions\BadRequest |
||
| 112 | */ |
||
| 113 | View Code Duplication | function setImportUri($importTriggerUri) |
|
| 123 | |||
| 124 | /** |
||
| 125 | * Retrieve the ecommerce import settings for an app. |
||
| 126 | * |
||
| 127 | * @return \SevenShores\Hubspot\Http\Response |
||
| 128 | * @throws \SevenShores\Hubspot\Exceptions\BadRequest |
||
| 129 | */ |
||
| 130 | function getImportSettings() |
||
| 136 | |||
| 137 | /** |
||
| 138 | * @param int $importStartedAt - Timestamp from the import initialization request |
||
| 139 | * @param string $objectType - The object type this data corresponds to. Must be one of CONTACT, DEAL, LINE_ITEM, or PRODUCT. |
||
| 140 | * @param int $pageNumber - A numeric page number that identifies this page of data |
||
| 141 | * @param array $messages - The import messages |
||
| 142 | * @return \SevenShores\Hubspot\Http\Response |
||
| 143 | * @throws \SevenShores\Hubspot\Exceptions\BadRequest |
||
| 144 | */ |
||
| 145 | View Code Duplication | function importObjects($importStartedAt, $objectType, $pageNumber, $messages) |
|
| 153 | |||
| 154 | /** |
||
| 155 | * @param int $importStartedAt - Timestamp from the import initialization request |
||
| 156 | * @param string $objectType - The object type this data corresponds to. Must be one of CONTACT, DEAL, LINE_ITEM, or PRODUCT. |
||
| 157 | * @param int $pageCount - The total number of pages sent via the import pages endpoint. |
||
| 158 | * @param int $itemCount - The total number of items sent via the import pages endpoint. |
||
| 159 | * @return \SevenShores\Hubspot\Http\Response |
||
| 160 | * @throws \SevenShores\Hubspot\Exceptions\BadRequest |
||
| 161 | */ |
||
| 162 | function signalImportEnd($importStartedAt, $objectType, $pageCount, $itemCount) |
||
| 173 | } |
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.