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 |
||
| 27 | class Issues extends AbstractPackage |
||
| 28 | { |
||
| 29 | /** |
||
| 30 | * Create an issue. |
||
| 31 | * |
||
| 32 | * @param string $user The name of the owner of the GitHub repository. |
||
| 33 | * @param string $repo The name of the GitHub repository. |
||
| 34 | * @param string $title The title of the new issue. |
||
| 35 | * @param string $body The body text for the new issue. |
||
| 36 | * @param string $assignee The login for the GitHub user that this issue should be assigned to. |
||
| 37 | * @param integer $milestone The milestone to associate this issue with. |
||
| 38 | * @param string[] $labels The labels to associate with this issue. |
||
| 39 | * @param string[] $assignees The logins for GitHub users to assign to this issue. |
||
| 40 | * |
||
| 41 | * @return object |
||
| 42 | * |
||
| 43 | * @since 1.0 |
||
| 44 | * @throws \DomainException |
||
| 45 | */ |
||
| 46 | public function create($user, $repo, $title, $body = null, $assignee = null, $milestone = null, array $labels = array(), |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Edit an issue. |
||
| 90 | * |
||
| 91 | * @param string $user The name of the owner of the GitHub repository. |
||
| 92 | * @param string $repo The name of the GitHub repository. |
||
| 93 | * @param integer $issueId The issue number. |
||
| 94 | * @param string $state The optional new state for the issue. [open, closed] |
||
| 95 | * @param string $title The title of the new issue. |
||
| 96 | * @param string $body The body text for the new issue. |
||
| 97 | * @param string $assignee The login for the GitHub user that this issue should be assigned to. |
||
| 98 | * @param integer $milestone The milestone to associate this issue with. |
||
| 99 | * @param array $labels The labels to associate with this issue. |
||
| 100 | * |
||
| 101 | * @return object |
||
| 102 | * |
||
| 103 | * @since 1.0 |
||
| 104 | * @throws \DomainException |
||
| 105 | */ |
||
| 106 | public function edit($user, $repo, $issueId, $state = null, $title = null, $body = null, $assignee = null, $milestone = null, |
||
| 164 | |||
| 165 | /** |
||
| 166 | * Get a single issue. |
||
| 167 | * |
||
| 168 | * @param string $user The name of the owner of the GitHub repository. |
||
| 169 | * @param string $repo The name of the GitHub repository. |
||
| 170 | * @param integer $issueId The issue number. |
||
| 171 | * |
||
| 172 | * @return object |
||
| 173 | * |
||
| 174 | * @since 1.0 |
||
| 175 | * @throws \DomainException |
||
| 176 | */ |
||
| 177 | public function get($user, $repo, $issueId) |
||
| 185 | |||
| 186 | /** |
||
| 187 | * List issues. |
||
| 188 | * |
||
| 189 | * @param string $filter The filter type: assigned, created, mentioned, subscribed. |
||
| 190 | * @param string $state The optional state to filter requests by. [open, closed] |
||
| 191 | * @param string $labels The list of comma separated Label names. Example: bug,ui,@high. |
||
| 192 | * @param string $sort The sort order: created, updated, comments, default: created. |
||
| 193 | * @param string $direction The list direction: asc or desc, default: desc. |
||
| 194 | * @param \DateTime $since Only issues updated at or after this time are returned. |
||
| 195 | * @param integer $page The page number from which to get items. |
||
| 196 | * @param integer $limit The number of items on a page. |
||
| 197 | * |
||
| 198 | * @return object |
||
| 199 | * |
||
| 200 | * @since 1.0 |
||
| 201 | * @throws \DomainException |
||
| 202 | */ |
||
| 203 | public function getList($filter = null, $state = null, $labels = null, $sort = null, |
||
| 245 | |||
| 246 | /** |
||
| 247 | * List issues for a repository. |
||
| 248 | * |
||
| 249 | * @param string $user The name of the owner of the GitHub repository. |
||
| 250 | * @param string $repo The name of the GitHub repository. |
||
| 251 | * @param string $milestone The milestone number, 'none', or *. |
||
| 252 | * @param string $state The optional state to filter requests by. [open, closed] |
||
| 253 | * @param string $assignee The assignee name, 'none', or *. |
||
| 254 | * @param string $mentioned The GitHub user name. |
||
| 255 | * @param string $labels The list of comma separated Label names. Example: bug,ui,@high. |
||
| 256 | * @param string $sort The sort order: created, updated, comments, default: created. |
||
| 257 | * @param string $direction The list direction: asc or desc, default: desc. |
||
| 258 | * @param \DateTime $since Only issues updated at or after this time are returned. |
||
| 259 | * @param integer $page The page number from which to get items. |
||
| 260 | * @param integer $limit The number of items on a page. |
||
| 261 | * |
||
| 262 | * @return object |
||
| 263 | * |
||
| 264 | * @since 1.0 |
||
| 265 | * @throws \DomainException |
||
| 266 | */ |
||
| 267 | public function getListByRepository($user, $repo, $milestone = null, $state = null, $assignee = null, $mentioned = null, $labels = null, |
||
| 319 | |||
| 320 | /** |
||
| 321 | * Lock an issue. |
||
| 322 | * |
||
| 323 | * @param string $user The name of the owner of the GitHub repository. |
||
| 324 | * @param string $repo The name of the GitHub repository. |
||
| 325 | * @param integer $issueId The issue number. |
||
| 326 | * |
||
| 327 | * @return object |
||
| 328 | * |
||
| 329 | * @since 1.4.0 |
||
| 330 | * @throws \DomainException |
||
| 331 | */ |
||
| 332 | View Code Duplication | public function lock($user, $repo, $issueId) |
|
| 339 | |||
| 340 | /** |
||
| 341 | * Unlock an issue. |
||
| 342 | * |
||
| 343 | * @param string $user The name of the owner of the GitHub repository. |
||
| 344 | * @param string $repo The name of the GitHub repository. |
||
| 345 | * @param integer $issueId The issue number. |
||
| 346 | * |
||
| 347 | * @return object |
||
| 348 | * |
||
| 349 | * @since 1.4.0 |
||
| 350 | * @throws \DomainException |
||
| 351 | */ |
||
| 352 | public function unlock($user, $repo, $issueId) |
||
| 359 | } |
||
| 360 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: