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 |
||
| 20 | class Releases extends AbstractPackage |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * Create a release. |
||
| 24 | * |
||
| 25 | * @param string $user The name of the owner of the GitHub repository. |
||
| 26 | * @param string $repo The name of the GitHub repository. |
||
| 27 | * @param string $tagName The name of the tag. |
||
| 28 | * @param string $targetCommitish The commitish value that determines where the Git tag is created from. |
||
| 29 | * @param string $name The name of the release. |
||
| 30 | * @param string $body Text describing the contents of the tag. |
||
| 31 | * @param boolean $draft True to create a draft (unpublished) release, false to create a published one. |
||
| 32 | * @param boolean $preRelease True to identify the release as a prerelease. false to identify the release as a full release. |
||
| 33 | * |
||
| 34 | * @return object |
||
| 35 | * |
||
| 36 | * @link http://developer.github.com/v3/repos/releases/#create-a-release |
||
| 37 | * @since 1.1.0 |
||
| 38 | */ |
||
| 39 | public function create($user, $repo, $tagName, $targetCommitish = '', $name = '', $body = '', $draft = false, $preRelease = false) |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Delete a release. |
||
| 62 | * |
||
| 63 | * @param string $owner The name of the owner of the GitHub repository. |
||
| 64 | * @param string $repo The name of the GitHub repository. |
||
| 65 | * @param integer $releaseId The release id. |
||
| 66 | * |
||
| 67 | * @return object |
||
| 68 | * |
||
| 69 | * @since 1.4.0 |
||
| 70 | */ |
||
| 71 | View Code Duplication | public function delete($owner, $repo, $releaseId) |
|
| 81 | |||
| 82 | /** |
||
| 83 | * Edit a release. |
||
| 84 | * |
||
| 85 | * @param string $user The name of the owner of the GitHub repository. |
||
| 86 | * @param string $repo The name of the GitHub repository. |
||
| 87 | * @param integer $releaseId The release id. |
||
| 88 | * @param string $tagName The name of the tag. |
||
| 89 | * @param string $targetCommitish The commitish value that determines where the Git tag is created from. |
||
| 90 | * @param string $name The branch (or git ref) you want your changes pulled into. This |
||
| 91 | * should be an existing branch on the current repository. You cannot |
||
| 92 | * submit a pull request to one repo that requests a merge to a base |
||
| 93 | * of another repo. |
||
| 94 | * @param boolean $body The body text for the new pull request. |
||
| 95 | * @param boolean $draft The branch (or git ref) where your changes are implemented. |
||
| 96 | * @param string $preRelease The branch (or git ref) where your changes are implemented. |
||
| 97 | * |
||
| 98 | * @return object |
||
| 99 | * |
||
| 100 | * @link http://developer.github.com/v3/repos/releases/#edit-a-release |
||
| 101 | * @since 1.1.0 |
||
| 102 | * @throws \DomainException |
||
| 103 | */ |
||
| 104 | public function edit($user, $repo, $releaseId, $tagName, |
||
| 146 | |||
| 147 | /** |
||
| 148 | * Get a single release. |
||
| 149 | * |
||
| 150 | * @param string $user The name of the owner of the GitHub repository. |
||
| 151 | * @param string $repo The name of the GitHub repository. |
||
| 152 | * @param string $ref Valid values are: 'latest', 'tags/2.0.24' or Release Id, for example: '1643513' |
||
| 153 | * |
||
| 154 | * @return object |
||
| 155 | * |
||
| 156 | * @since 1.1.0 |
||
| 157 | * @throws \DomainException |
||
| 158 | */ |
||
| 159 | public function get($user, $repo, $ref) |
||
| 167 | |||
| 168 | /** |
||
| 169 | * Get the latest release. |
||
| 170 | * |
||
| 171 | * View the latest published full release for the repository. |
||
| 172 | * Draft releases and prereleases are not returned by this endpoint. |
||
| 173 | * |
||
| 174 | * @param string $user The name of the owner of the GitHub repository. |
||
| 175 | * @param string $repo The name of the GitHub repository. |
||
| 176 | * |
||
| 177 | * @return object |
||
| 178 | * |
||
| 179 | * @since 1.4.0 |
||
| 180 | */ |
||
| 181 | public function getLatest($user, $repo) |
||
| 189 | |||
| 190 | /** |
||
| 191 | * Get a release by tag name. |
||
| 192 | * |
||
| 193 | * @param string $user The name of the owner of the GitHub repository. |
||
| 194 | * @param string $repo The name of the GitHub repository. |
||
| 195 | * @param string $tag The name of the tag. |
||
| 196 | * |
||
| 197 | * @return object |
||
| 198 | * |
||
| 199 | * @since 1.4.0 |
||
| 200 | */ |
||
| 201 | public function getByTag($user, $repo, $tag) |
||
| 209 | |||
| 210 | /** |
||
| 211 | * List releases for a repository. |
||
| 212 | * |
||
| 213 | * @param string $user The name of the owner of the GitHub repository. |
||
| 214 | * @param string $repo The name of the GitHub repository. |
||
| 215 | * @param integer $page The page number from which to get items. |
||
| 216 | * @param integer $limit The number of items on a page. |
||
| 217 | * |
||
| 218 | * @return array An associative array of releases keyed by the tag name. |
||
| 219 | * |
||
| 220 | * @since 1.1.0 |
||
| 221 | * @throws \DomainException |
||
| 222 | */ |
||
| 223 | public function getList($user, $repo, $page = 0, $limit = 0) |
||
| 243 | |||
| 244 | /** |
||
| 245 | * List assets for a release. |
||
| 246 | * |
||
| 247 | * @param string $user The name of the owner of the GitHub repository. |
||
| 248 | * @param string $repo The name of the GitHub repository. |
||
| 249 | * @param integer $releaseId The release id. |
||
| 250 | * @param integer $page The page number from which to get items. |
||
| 251 | * @param integer $limit The number of items on a page. |
||
| 252 | * |
||
| 253 | * @return object |
||
| 254 | * |
||
| 255 | * @since 1.4.0 |
||
| 256 | */ |
||
| 257 | public function getListAssets($user, $repo, $releaseId, $page = 0, $limit = 0) |
||
| 265 | |||
| 266 | /** |
||
| 267 | * Get a single release asset. |
||
| 268 | * |
||
| 269 | * @param string $user The name of the owner of the GitHub repository. |
||
| 270 | * @param string $repo The name of the GitHub repository. |
||
| 271 | * @param integer $assetId The asset id. |
||
| 272 | * |
||
| 273 | * @return object |
||
| 274 | * |
||
| 275 | * @since 1.4.0 |
||
| 276 | */ |
||
| 277 | public function getAsset($user, $repo, $assetId) |
||
| 285 | |||
| 286 | /** |
||
| 287 | * Edit a release asset. |
||
| 288 | * |
||
| 289 | * @param string $user The name of the owner of the GitHub repository. |
||
| 290 | * @param string $repo The name of the GitHub repository. |
||
| 291 | * @param integer $assetId The asset id. |
||
| 292 | * @param string $name The file name of the asset. |
||
| 293 | * @param string $label An alternate short description of the asset. Used in place of the filename. |
||
| 294 | * |
||
| 295 | * @return object |
||
| 296 | * |
||
| 297 | * @since 1.4.0 |
||
| 298 | */ |
||
| 299 | View Code Duplication | public function editAsset($user, $repo, $assetId, $name, $label = '') |
|
| 316 | |||
| 317 | /** |
||
| 318 | * Delete a release asset. |
||
| 319 | * |
||
| 320 | * @param string $user The name of the owner of the GitHub repository. |
||
| 321 | * @param string $repo The name of the GitHub repository. |
||
| 322 | * @param integer $assetId The asset id. |
||
| 323 | * |
||
| 324 | * @return boolean |
||
| 325 | * |
||
| 326 | * @since 1.4.0 |
||
| 327 | */ |
||
| 328 | View Code Duplication | public function deleteAsset($user, $repo, $assetId) |
|
| 338 | } |
||
| 339 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.