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 |
||
| 23 | class Pulls extends AbstractPackage |
||
| 24 | { |
||
| 25 | /** |
||
| 26 | * Create a pull request. |
||
| 27 | * |
||
| 28 | * @param string $user The name of the owner of the GitHub repository. |
||
| 29 | * @param string $repo The name of the GitHub repository. |
||
| 30 | * @param string $title The title of the new pull request. |
||
| 31 | * @param string $base The branch (or git ref) you want your changes pulled into. This |
||
| 32 | * should be an existing branch on the current repository. You cannot |
||
| 33 | * submit a pull request to one repo that requests a merge to a base |
||
| 34 | * of another repo. |
||
| 35 | * @param string $head The branch (or git ref) where your changes are implemented. |
||
| 36 | * @param string $body The body text for the new pull request. |
||
| 37 | * |
||
| 38 | * @return object |
||
| 39 | * |
||
| 40 | * @since 1.0 |
||
| 41 | * @throws \DomainException |
||
| 42 | */ |
||
| 43 | View Code Duplication | public function create($user, $repo, $title, $base, $head, $body = '') |
|
| 61 | |||
| 62 | /** |
||
| 63 | * Method to create a pull request from an existing issue. |
||
| 64 | * |
||
| 65 | * @param string $user The name of the owner of the GitHub repository. |
||
| 66 | * @param string $repo The name of the GitHub repository. |
||
| 67 | * @param integer $issueId The issue number for which to attach the new pull request. |
||
| 68 | * @param string $base The branch (or git ref) you want your changes pulled into. This |
||
| 69 | * should be an existing branch on the current repository. You cannot |
||
| 70 | * submit a pull request to one repo that requests a merge to a base |
||
| 71 | * of another repo. |
||
| 72 | * @param string $head The branch (or git ref) where your changes are implemented. |
||
| 73 | * |
||
| 74 | * @return object |
||
| 75 | * |
||
| 76 | * @since 1.0 |
||
| 77 | * @throws \DomainException |
||
| 78 | */ |
||
| 79 | public function createFromIssue($user, $repo, $issueId, $base, $head) |
||
| 96 | |||
| 97 | /** |
||
| 98 | * Update a pull request. |
||
| 99 | * |
||
| 100 | * @param string $user The name of the owner of the GitHub repository. |
||
| 101 | * @param string $repo The name of the GitHub repository. |
||
| 102 | * @param integer $pullId The pull request number. |
||
| 103 | * @param string $title The optional new title for the pull request. |
||
| 104 | * @param string $body The optional new body text for the pull request. |
||
| 105 | * @param string $state The optional new state for the pull request. [open, closed] |
||
| 106 | * @param string $base The optional new base branch for the pull request. |
||
| 107 | * |
||
| 108 | * @return object |
||
| 109 | * |
||
| 110 | * @since 1.0 |
||
| 111 | * @throws \DomainException |
||
| 112 | */ |
||
| 113 | public function edit($user, $repo, $pullId, $title = null, $body = null, $state = null, $base = null) |
||
| 151 | |||
| 152 | /** |
||
| 153 | * Get a single pull request. |
||
| 154 | * |
||
| 155 | * @param string $user The name of the owner of the GitHub repository. |
||
| 156 | * @param string $repo The name of the GitHub repository. |
||
| 157 | * @param integer $pullId The pull request number. |
||
| 158 | * |
||
| 159 | * @return object |
||
| 160 | * |
||
| 161 | * @since 1.0 |
||
| 162 | * @throws \DomainException |
||
| 163 | */ |
||
| 164 | public function get($user, $repo, $pullId) |
||
| 172 | |||
| 173 | /** |
||
| 174 | * List commits on a pull request. |
||
| 175 | * |
||
| 176 | * @param string $user The name of the owner of the GitHub repository. |
||
| 177 | * @param string $repo The name of the GitHub repository. |
||
| 178 | * @param integer $pullId The pull request number. |
||
| 179 | * @param integer $page The page number from which to get items. |
||
| 180 | * @param integer $limit The number of items on a page. |
||
| 181 | * |
||
| 182 | * @return object |
||
| 183 | * |
||
| 184 | * @since 1.0 |
||
| 185 | * @throws \DomainException |
||
| 186 | */ |
||
| 187 | public function getCommits($user, $repo, $pullId, $page = 0, $limit = 0) |
||
| 195 | |||
| 196 | /** |
||
| 197 | * List pull requests files. |
||
| 198 | * |
||
| 199 | * @param string $user The name of the owner of the GitHub repository. |
||
| 200 | * @param string $repo The name of the GitHub repository. |
||
| 201 | * @param integer $pullId The pull request number. |
||
| 202 | * @param integer $page The page number from which to get items. |
||
| 203 | * @param integer $limit The number of items on a page. |
||
| 204 | * |
||
| 205 | * @return object |
||
| 206 | * |
||
| 207 | * @since 1.0 |
||
| 208 | * @throws \DomainException |
||
| 209 | */ |
||
| 210 | public function getFiles($user, $repo, $pullId, $page = 0, $limit = 0) |
||
| 218 | |||
| 219 | /** |
||
| 220 | * List pull requests. |
||
| 221 | * |
||
| 222 | * @param string $user The name of the owner of the GitHub repository. |
||
| 223 | * @param string $repo The name of the GitHub repository. |
||
| 224 | * @param string $state The optional state to filter requests by. [open, closed] |
||
| 225 | * @param integer $page The page number from which to get items. |
||
| 226 | * @param integer $limit The number of items on a page. |
||
| 227 | * |
||
| 228 | * @return array |
||
| 229 | * |
||
| 230 | * @since 1.0 |
||
| 231 | * @throws \DomainException |
||
| 232 | */ |
||
| 233 | View Code Duplication | public function getList($user, $repo, $state = 'open', $page = 0, $limit = 0) |
|
| 247 | |||
| 248 | /** |
||
| 249 | * Get if a pull request has been merged. |
||
| 250 | * |
||
| 251 | * @param string $user The name of the owner of the GitHub repository. |
||
| 252 | * @param string $repo The name of the GitHub repository. |
||
| 253 | * @param integer $pullId The pull request number. The pull request number. |
||
| 254 | * |
||
| 255 | * @return boolean True if the pull request has been merged |
||
| 256 | * |
||
| 257 | * @since 1.0 |
||
| 258 | * @throws UnexpectedResponseException |
||
| 259 | */ |
||
| 260 | public function isMerged($user, $repo, $pullId) |
||
| 284 | |||
| 285 | /** |
||
| 286 | * Merge a pull request (Merge Button). |
||
| 287 | * |
||
| 288 | * @param string $user The name of the owner of the GitHub repository. |
||
| 289 | * @param string $repo The name of the GitHub repository. |
||
| 290 | * @param integer $pullId The pull request number. |
||
| 291 | * @param string $message The message that will be used for the merge commit. |
||
| 292 | * |
||
| 293 | * @return object |
||
| 294 | * |
||
| 295 | * @since 1.0 |
||
| 296 | * @throws \DomainException |
||
| 297 | */ |
||
| 298 | public function merge($user, $repo, $pullId, $message = '') |
||
| 313 | } |
||
| 314 |
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.