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 Files extends Resource |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * Upload a new file. |
||
| 9 | * |
||
| 10 | * @param string $file File path |
||
| 11 | * @param array $params Optional parameters |
||
| 12 | * @return \SevenShores\Hubspot\Http\Response |
||
| 13 | */ |
||
| 14 | function upload($file, $params = []) |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Get meta data for all files. |
||
| 41 | * |
||
| 42 | * @param array $params Optional parameters |
||
| 43 | * @return \SevenShores\Hubspot\Http\Response |
||
| 44 | */ |
||
| 45 | function all($params = []) |
||
| 53 | |||
| 54 | |||
| 55 | /** |
||
| 56 | * Upload a replacement file. |
||
| 57 | * |
||
| 58 | * @param int $file_id The file ID |
||
| 59 | * @param string $file The file path |
||
| 60 | * @return \SevenShores\Hubspot\Http\Response |
||
| 61 | */ |
||
| 62 | function replace($file_id, $file) |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Get file metadata. |
||
| 78 | * |
||
| 79 | * @param $file_id |
||
| 80 | * @return \SevenShores\Hubspot\Http\Response |
||
| 81 | */ |
||
| 82 | function meta($file_id) |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Archive a file. |
||
| 91 | * |
||
| 92 | * @param int $file_id The file ID |
||
| 93 | * @return \SevenShores\Hubspot\Http\Response |
||
| 94 | */ |
||
| 95 | function archive($file_id) |
||
| 101 | |||
| 102 | /** |
||
| 103 | * Delete a file. |
||
| 104 | * |
||
| 105 | * @param int $file_id The file ID |
||
| 106 | * @return \SevenShores\Hubspot\Http\Response |
||
| 107 | */ |
||
| 108 | function delete($file_id) |
||
| 114 | |||
| 115 | /** |
||
| 116 | * Move a file to a new folder. |
||
| 117 | * |
||
| 118 | * Parameters: |
||
| 119 | * folder_path string The path of the folder to move the file into. Use this OR folder_id - not both. |
||
| 120 | * folder_id string The id of the folder to move the file into. Use this OR folder_path - not both. |
||
| 121 | * name string The new name of the file. |
||
| 122 | * |
||
| 123 | * @param int $file_id |
||
| 124 | * @param array $params |
||
| 125 | * @return \SevenShores\Hubspot\Http\Response |
||
| 126 | */ |
||
| 127 | function move($file_id, $params = []) |
||
| 135 | |||
| 136 | /** |
||
| 137 | * Create a new folder. |
||
| 138 | * |
||
| 139 | * @param string $folder_name |
||
| 140 | * @param int $parent_folder_id |
||
| 141 | * @return \SevenShores\Hubspot\Http\Response |
||
| 142 | */ |
||
| 143 | View Code Duplication | function createFolder($folder_name, $parent_folder_id) |
|
| 154 | |||
| 155 | /** |
||
| 156 | * List folders metadata. |
||
| 157 | * |
||
| 158 | * @param array $params |
||
| 159 | * @return \SevenShores\Hubspot\Http\Response |
||
| 160 | */ |
||
| 161 | function folders($params = []) |
||
| 169 | |||
| 170 | /** |
||
| 171 | * Update a folder. |
||
| 172 | * |
||
| 173 | * @param int $folder_id |
||
| 174 | * @param array $params |
||
| 175 | * @return \SevenShores\Hubspot\Http\Response |
||
| 176 | */ |
||
| 177 | function updateFolder($folder_id, $params = []) |
||
| 185 | |||
| 186 | /** |
||
| 187 | * Delete a folder. |
||
| 188 | * |
||
| 189 | * @param int $folder_id |
||
| 190 | * @return \SevenShores\Hubspot\Http\Response |
||
| 191 | */ |
||
| 192 | function deleteFolder($folder_id) |
||
| 198 | |||
| 199 | /** |
||
| 200 | * Get the folder by ID. |
||
| 201 | * |
||
| 202 | * @param int $folder_id |
||
| 203 | * @return \SevenShores\Hubspot\Http\Response |
||
| 204 | */ |
||
| 205 | function getFolderById($folder_id) |
||
| 211 | |||
| 212 | /** |
||
| 213 | * Move a folder. |
||
| 214 | * |
||
| 215 | * @param int $folder_id |
||
| 216 | * @param array $params |
||
| 217 | * @return \SevenShores\Hubspot\Http\Response |
||
| 218 | */ |
||
| 219 | function moveFolder($folder_id, $params = []) |
||
| 227 | |||
| 228 | } |
||
| 229 |
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.