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(), array $assignees = array()) |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Edit an issue. |
||
| 75 | * |
||
| 76 | * @param string $user The name of the owner of the GitHub repository. |
||
| 77 | * @param string $repo The name of the GitHub repository. |
||
| 78 | * @param integer $issueId The issue number. |
||
| 79 | * @param string $state The optional new state for the issue. [open, closed] |
||
| 80 | * @param string $title The title of the new issue. |
||
| 81 | * @param string $body The body text for the new issue. |
||
| 82 | * @param string $assignee The login for the GitHub user that this issue should be assigned to. |
||
| 83 | * @param integer $milestone The milestone to associate this issue with. |
||
| 84 | * @param array $labels The labels to associate with this issue. |
||
| 85 | * |
||
| 86 | * @return object |
||
| 87 | * |
||
| 88 | * @since 1.0 |
||
| 89 | * @throws \DomainException |
||
| 90 | */ |
||
| 91 | public function edit($user, $repo, $issueId, $state = null, $title = null, $body = null, $assignee = null, $milestone = null, array $labels = null) |
||
| 147 | |||
| 148 | /** |
||
| 149 | * Get a single issue. |
||
| 150 | * |
||
| 151 | * @param string $user The name of the owner of the GitHub repository. |
||
| 152 | * @param string $repo The name of the GitHub repository. |
||
| 153 | * @param integer $issueId The issue number. |
||
| 154 | * |
||
| 155 | * @return object |
||
| 156 | * |
||
| 157 | * @since 1.0 |
||
| 158 | * @throws \DomainException |
||
| 159 | */ |
||
| 160 | public function get($user, $repo, $issueId) |
||
| 168 | |||
| 169 | /** |
||
| 170 | * List issues. |
||
| 171 | * |
||
| 172 | * @param string $filter The filter type: assigned, created, mentioned, subscribed. |
||
| 173 | * @param string $state The optional state to filter requests by. [open, closed] |
||
| 174 | * @param string $labels The list of comma separated Label names. Example: bug,ui,@high. |
||
| 175 | * @param string $sort The sort order: created, updated, comments, default: created. |
||
| 176 | * @param string $direction The list direction: asc or desc, default: desc. |
||
| 177 | * @param \DateTime $since Only issues updated at or after this time are returned. |
||
| 178 | * @param integer $page The page number from which to get items. |
||
| 179 | * @param integer $limit The number of items on a page. |
||
| 180 | * |
||
| 181 | * @return object |
||
| 182 | * |
||
| 183 | * @since 1.0 |
||
| 184 | * @throws \DomainException |
||
| 185 | */ |
||
| 186 | public function getList($filter = null, $state = null, $labels = null, $sort = null, |
||
| 227 | |||
| 228 | /** |
||
| 229 | * List issues for a repository. |
||
| 230 | * |
||
| 231 | * @param string $user The name of the owner of the GitHub repository. |
||
| 232 | * @param string $repo The name of the GitHub repository. |
||
| 233 | * @param string $milestone The milestone number, 'none', or *. |
||
| 234 | * @param string $state The optional state to filter requests by. [open, closed] |
||
| 235 | * @param string $assignee The assignee name, 'none', or *. |
||
| 236 | * @param string $mentioned The GitHub user name. |
||
| 237 | * @param string $labels The list of comma separated Label names. Example: bug,ui,@high. |
||
| 238 | * @param string $sort The sort order: created, updated, comments, default: created. |
||
| 239 | * @param string $direction The list direction: asc or desc, default: desc. |
||
| 240 | * @param \DateTime $since Only issues updated at or after this time are returned. |
||
| 241 | * @param integer $page The page number from which to get items. |
||
| 242 | * @param integer $limit The number of items on a page. |
||
| 243 | * |
||
| 244 | * @return object |
||
| 245 | * |
||
| 246 | * @since 1.0 |
||
| 247 | * @throws \DomainException |
||
| 248 | */ |
||
| 249 | public function getListByRepository($user, $repo, $milestone = null, $state = null, $assignee = null, $mentioned = null, $labels = null, |
||
| 300 | |||
| 301 | /** |
||
| 302 | * Lock an issue. |
||
| 303 | * |
||
| 304 | * @param string $user The name of the owner of the GitHub repository. |
||
| 305 | * @param string $repo The name of the GitHub repository. |
||
| 306 | * @param integer $issueId The issue number. |
||
| 307 | * |
||
| 308 | * @return object |
||
| 309 | * |
||
| 310 | * @since 1.4.0 |
||
| 311 | * @throws \DomainException |
||
| 312 | */ |
||
| 313 | View Code Duplication | public function lock($user, $repo, $issueId) |
|
| 320 | |||
| 321 | /** |
||
| 322 | * Unlock an issue. |
||
| 323 | * |
||
| 324 | * @param string $user The name of the owner of the GitHub repository. |
||
| 325 | * @param string $repo The name of the GitHub repository. |
||
| 326 | * @param integer $issueId The issue number. |
||
| 327 | * |
||
| 328 | * @return object |
||
| 329 | * |
||
| 330 | * @since 1.4.0 |
||
| 331 | * @throws \DomainException |
||
| 332 | */ |
||
| 333 | public function unlock($user, $repo, $issueId) |
||
| 340 | } |
||
| 341 |
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: