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 BlogPosts extends Resource |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * Create a new blog post. |
||
| 9 | * |
||
| 10 | * @param array $params Optional Parameters. |
||
| 11 | * @return \SevenShores\Hubspot\Http\Response |
||
| 12 | */ |
||
| 13 | function create($params = []) |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Get all blog posts. |
||
| 24 | * |
||
| 25 | * @param array $params Optional parameters. |
||
| 26 | * @return \SevenShores\Hubspot\Http\Response |
||
| 27 | */ |
||
| 28 | function all($params = []) |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Update a blog post. |
||
| 39 | * |
||
| 40 | * @param int $id The blog post id. |
||
| 41 | * @param array $params The blog post fields to update. |
||
| 42 | * @return \SevenShores\Hubspot\Http\Response |
||
| 43 | */ |
||
| 44 | function update($id, $params = []) |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Delete a blog post. |
||
| 55 | * |
||
| 56 | * @param int $id |
||
| 57 | * @return \SevenShores\Hubspot\Http\Response |
||
| 58 | */ |
||
| 59 | function delete($id) |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Get a specific blog post. |
||
| 68 | * |
||
| 69 | * @param int $id |
||
| 70 | * @return \SevenShores\Hubspot\Http\Response |
||
| 71 | */ |
||
| 72 | function getById($id) |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Updates the auto-save buffer. Live objects will not be impacted. |
||
| 81 | * |
||
| 82 | * @see http://developers.hubspot.com/docs/methods/blogv2/put_blog_posts_blog_post_id_buffer |
||
| 83 | * |
||
| 84 | * @param int $id The blog post ID. |
||
| 85 | * @param array $params Allowed parameters. |
||
| 86 | * @return \SevenShores\Hubspot\Http\Response |
||
| 87 | */ |
||
| 88 | function updateAutoSaveBuffer($id, $params = []) |
||
| 96 | |||
| 97 | /** |
||
| 98 | * Gets the current contents of the auto-save buffer. |
||
| 99 | * |
||
| 100 | * @param int $id The blog post ID |
||
| 101 | * @return \SevenShores\Hubspot\Http\Response |
||
| 102 | */ |
||
| 103 | function getAutoSaveBufferContents($id) |
||
| 109 | |||
| 110 | /** |
||
| 111 | * Clone the blog post. |
||
| 112 | * Requires including a request body of {"name": "New Page Name"} |
||
| 113 | * |
||
| 114 | * @param int $id The blog post ID |
||
| 115 | * @param string $name The cloned post name |
||
| 116 | * @return \SevenShores\Hubspot\Http\Response |
||
| 117 | */ |
||
| 118 | View Code Duplication | function clonePost($id, $name) |
|
| 126 | |||
| 127 | /** |
||
| 128 | * Determine if the auto-save buffer differs from the live blog post. |
||
| 129 | * |
||
| 130 | * @param int $id The blog post ID |
||
| 131 | * @return \SevenShores\Hubspot\Http\Response |
||
| 132 | */ |
||
| 133 | function hasBufferedChanges($id) |
||
| 139 | |||
| 140 | /** |
||
| 141 | * Either publishes or cancels publishing based on the POSTed JSON. |
||
| 142 | * |
||
| 143 | * Allowable actions are: "push-buffer-live", "schedule-publish", "cancel-publish". |
||
| 144 | * "push-buffer-live": copies the current contents of the auto-save buffer into the live object. |
||
| 145 | * "schedule-publish": which pushes the buffer live and then sets up the content for publishing at |
||
| 146 | * the existing publish_date time. |
||
| 147 | * "cancel-publish": cancels a previous schedule-publish action. |
||
| 148 | * |
||
| 149 | * @param int $id The blog post ID |
||
| 150 | * @param string $action The publish action |
||
| 151 | * @return \SevenShores\Hubspot\Http\Response |
||
| 152 | */ |
||
| 153 | View Code Duplication | function publishAction($id, $action) |
|
| 161 | |||
| 162 | /** |
||
| 163 | * Copies the contents of the auto-save buffer into the live blog post. |
||
| 164 | * |
||
| 165 | * @param int $id The blog post ID |
||
| 166 | * @return \SevenShores\Hubspot\Http\Response |
||
| 167 | */ |
||
| 168 | function pushBufferLive($id) |
||
| 174 | |||
| 175 | /** |
||
| 176 | * Restores a previously deleted blog post. |
||
| 177 | * |
||
| 178 | * @param int $id The blog post ID |
||
| 179 | * @return \SevenShores\Hubspot\Http\Response |
||
| 180 | */ |
||
| 181 | function restoreDeleted($id) |
||
| 187 | |||
| 188 | /** |
||
| 189 | * Validates the auto-save buffer version of the blog post. |
||
| 190 | * |
||
| 191 | * @param int $id The blog post ID |
||
| 192 | * @return \SevenShores\Hubspot\Http\Response |
||
| 193 | */ |
||
| 194 | function validateBuffer($id) |
||
| 200 | |||
| 201 | /** |
||
| 202 | * List previous versions of the blog post. |
||
| 203 | * |
||
| 204 | * @param int $id The blog post ID |
||
| 205 | * @return \SevenShores\Hubspot\Http\Response |
||
| 206 | */ |
||
| 207 | function versions($id) |
||
| 213 | |||
| 214 | /** |
||
| 215 | * Get a previous version of the blog post. |
||
| 216 | * |
||
| 217 | * @param int $post_id The blog post ID |
||
| 218 | * @param int $version_id The version ID |
||
| 219 | * @return \SevenShores\Hubspot\Http\Response |
||
| 220 | */ |
||
| 221 | function getVersion($post_id, $version_id) |
||
| 227 | |||
| 228 | /** |
||
| 229 | * Restore a previous version of the blog post. |
||
| 230 | * |
||
| 231 | * @param int $post_id The blog post ID |
||
| 232 | * @param int $version_id The version ID |
||
| 233 | * @return \SevenShores\Hubspot\Http\Response |
||
| 234 | */ |
||
| 235 | View Code Duplication | function restoreVersion($post_id, $version_id) |
|
| 243 | } |
||
| 244 |
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.