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 Pages extends Resource |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * Create a new page. |
||
| 9 | * |
||
| 10 | * @param array $params Optional Parameters. |
||
| 11 | * @return \SevenShores\Hubspot\Http\Response |
||
| 12 | */ |
||
| 13 | function create($params) |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Get all pages. |
||
| 24 | * |
||
| 25 | * @param array $params Optional parameters. |
||
| 26 | * @return \SevenShores\Hubspot\Http\Response |
||
| 27 | */ |
||
| 28 | function all($params = []) |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Update a page. |
||
| 39 | * |
||
| 40 | * @param int $page_id The page id. |
||
| 41 | * @param array $params The page fields to update. |
||
| 42 | * @return \SevenShores\Hubspot\Http\Response |
||
| 43 | */ |
||
| 44 | function update($page_id, $params) |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Delete a page. |
||
| 55 | * |
||
| 56 | * @param int $page_id |
||
| 57 | * @return \SevenShores\Hubspot\Http\Response |
||
| 58 | */ |
||
| 59 | function delete($page_id) |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Get a specific page. |
||
| 68 | * |
||
| 69 | * @param int $page_id |
||
| 70 | * @return \SevenShores\Hubspot\Http\Response |
||
| 71 | */ |
||
| 72 | function getById($page_id) |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Updates the auto-save buffer. |
||
| 81 | * |
||
| 82 | * @param in $page_id The page ID |
||
| 83 | * @return \SevenShores\Hubspot\Http\Response |
||
| 84 | */ |
||
| 85 | function updateAutoSaveBuffer($page_id) |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Gets the current contents of the auto-save buffer. |
||
| 94 | * |
||
| 95 | * @param int $page_id The page ID |
||
| 96 | * @return \SevenShores\Hubspot\Http\Response |
||
| 97 | */ |
||
| 98 | function getAutoSaveBufferContents($page_id) |
||
| 104 | |||
| 105 | /** |
||
| 106 | * Clone the page. |
||
| 107 | * |
||
| 108 | * @param int $page_id The page ID |
||
| 109 | * @param string $name The cloned page name |
||
| 110 | * @return \SevenShores\Hubspot\Http\Response |
||
| 111 | */ |
||
| 112 | function clonePage($page_id, $name) |
||
| 120 | |||
| 121 | /** |
||
| 122 | * Determine if the auto-save buffer differs from the live page. |
||
| 123 | * |
||
| 124 | * @param int $page_id The page ID |
||
| 125 | * @return \SevenShores\Hubspot\Http\Response |
||
| 126 | */ |
||
| 127 | function hasBufferedChanges($page_id) |
||
| 133 | |||
| 134 | /** |
||
| 135 | * Either publishes or cancels publishing based on the POSTed JSON. |
||
| 136 | * |
||
| 137 | * Allowable actions are: "push-buffer-live", "schedule-publish", "cancel-publish". |
||
| 138 | * "push-buffer-live": copies the current contents of the auto-save buffer into the live object. |
||
| 139 | * "schedule-publish": which pushes the buffer live and then sets up the content for publishing at |
||
| 140 | * the existing publish_date time. |
||
| 141 | * "cancel-publish": cancels a previous schedule-publish action. |
||
| 142 | * |
||
| 143 | * @param int $page_id The page ID |
||
| 144 | * @param string $action The publish action |
||
| 145 | * @return \SevenShores\Hubspot\Http\Response |
||
| 146 | */ |
||
| 147 | function publishAction($page_id, $action) |
||
| 155 | |||
| 156 | /** |
||
| 157 | * Copies the contents of the auto-save buffer into the live page. |
||
| 158 | * |
||
| 159 | * @param int $page_id The page ID |
||
| 160 | * @return \SevenShores\Hubspot\Http\Response |
||
| 161 | */ |
||
| 162 | function pushBufferLive($page_id) |
||
| 168 | |||
| 169 | /** |
||
| 170 | * Restores a previously deleted page. |
||
| 171 | * |
||
| 172 | * @param int $page_id The page ID |
||
| 173 | * @return \SevenShores\Hubspot\Http\Response |
||
| 174 | */ |
||
| 175 | function restoreDeleted($page_id) |
||
| 181 | |||
| 182 | /** |
||
| 183 | * Validates the auto-save buffer version of the page. |
||
| 184 | * |
||
| 185 | * @param int $page_id The page ID |
||
| 186 | * @return \SevenShores\Hubspot\Http\Response |
||
| 187 | */ |
||
| 188 | function validateBuffer($page_id) |
||
| 194 | |||
| 195 | /** |
||
| 196 | * List previous versions of the page. |
||
| 197 | * |
||
| 198 | * @param int $page_id The page ID |
||
| 199 | * @return \SevenShores\Hubspot\Http\Response |
||
| 200 | */ |
||
| 201 | function versions($page_id) |
||
| 207 | |||
| 208 | /** |
||
| 209 | * Restore a previous version of the page. |
||
| 210 | * |
||
| 211 | * @param int $page_id The page ID |
||
| 212 | * @param int $version_id The version ID |
||
| 213 | * @return \SevenShores\Hubspot\Http\Response |
||
| 214 | */ |
||
| 215 | View Code Duplication | function restoreVersion($page_id, $version_id) |
|
| 223 | } |
||
| 224 |
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.