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 Comments extends AbstractPackage |
||
| 24 | { |
||
| 25 | /** |
||
| 26 | * List comments on an issue. |
||
| 27 | * |
||
| 28 | * @param string $owner The name of the owner of the GitHub repository. |
||
| 29 | * @param string $repo The name of the GitHub repository. |
||
| 30 | * @param integer $issueId The issue number. |
||
| 31 | * @param integer $page The page number from which to get items. |
||
| 32 | * @param integer $limit The number of items on a page. |
||
| 33 | * @param \DateTime $since Only comments updated at or after this time are returned. |
||
| 34 | * |
||
| 35 | * @return object |
||
| 36 | * |
||
| 37 | * @since 1.0 |
||
| 38 | * @throws \DomainException |
||
| 39 | */ |
||
| 40 | public function getList($owner, $repo, $issueId, $page = 0, $limit = 0, \DateTime $since = null) |
||
| 51 | |||
| 52 | /** |
||
| 53 | * List comments in a repository. |
||
| 54 | * |
||
| 55 | * @param string $owner The name of the owner of the GitHub repository. |
||
| 56 | * @param string $repo The name of the GitHub repository. |
||
| 57 | * @param string $sort The sort field - created or updated. |
||
| 58 | * @param string $direction The sort order- asc or desc. Ignored without sort parameter. |
||
| 59 | * @param \DateTime $since Only comments updated at or after this time are returned. |
||
| 60 | * |
||
| 61 | * @return object |
||
| 62 | * |
||
| 63 | * @since 1.0 |
||
| 64 | * @throws \UnexpectedValueException |
||
| 65 | * @throws \DomainException |
||
| 66 | */ |
||
| 67 | public function getRepositoryList($owner, $repo, $sort = 'created', $direction = 'asc', \DateTime $since = null) |
||
| 101 | |||
| 102 | /** |
||
| 103 | * Get a single comment. |
||
| 104 | * |
||
| 105 | * @param string $owner The name of the owner of the GitHub repository. |
||
| 106 | * @param string $repo The name of the GitHub repository. |
||
| 107 | * @param integer $id The comment id. |
||
| 108 | * |
||
| 109 | * @return object |
||
| 110 | * |
||
| 111 | * @since 1.0 |
||
| 112 | * @throws \DomainException |
||
| 113 | */ |
||
| 114 | public function get($owner, $repo, $id) |
||
| 124 | |||
| 125 | /** |
||
| 126 | * Edit a comment. |
||
| 127 | * |
||
| 128 | * @param string $user The name of the owner of the GitHub repository. |
||
| 129 | * @param string $repo The name of the GitHub repository. |
||
| 130 | * @param integer $commentId The id of the comment to update. |
||
| 131 | * @param string $body The new body text for the comment. |
||
| 132 | * |
||
| 133 | * @return object |
||
| 134 | * |
||
| 135 | * @since 1.0 |
||
| 136 | * @throws \DomainException |
||
| 137 | */ |
||
| 138 | public function edit($user, $repo, $commentId, $body) |
||
| 155 | |||
| 156 | /** |
||
| 157 | * Create a comment. |
||
| 158 | * |
||
| 159 | * @param string $user The name of the owner of the GitHub repository. |
||
| 160 | * @param string $repo The name of the GitHub repository. |
||
| 161 | * @param integer $issueId The issue number. |
||
| 162 | * @param string $body The comment body text. |
||
| 163 | * |
||
| 164 | * @return object |
||
| 165 | * |
||
| 166 | * @since 1.0 |
||
| 167 | * @throws \DomainException |
||
| 168 | */ |
||
| 169 | public function create($user, $repo, $issueId, $body) |
||
| 187 | |||
| 188 | /** |
||
| 189 | * Delete a comment. |
||
| 190 | * |
||
| 191 | * @param string $user The name of the owner of the GitHub repository. |
||
| 192 | * @param string $repo The name of the GitHub repository. |
||
| 193 | * @param integer $commentId The id of the comment to delete. |
||
| 194 | * |
||
| 195 | * @return boolean |
||
| 196 | * |
||
| 197 | * @since 1.0 |
||
| 198 | * @throws \DomainException |
||
| 199 | */ |
||
| 200 | View Code Duplication | public function delete($user, $repo, $commentId) |
|
| 213 | } |
||
| 214 |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.