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 Comments extends AbstractPackage |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * List commit comments for a repository. |
||
| 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 integer $page Page to request |
||
| 28 | * @param integer $limit Number of results to return per page |
||
| 29 | * |
||
| 30 | * @return array |
||
| 31 | * |
||
| 32 | * @since 1.0 |
||
| 33 | */ |
||
| 34 | View Code Duplication | public function getListRepository($user, $repo, $page = 0, $limit = 0) |
|
| 44 | |||
| 45 | /** |
||
| 46 | * List comments for a single commit. |
||
| 47 | * |
||
| 48 | * @param string $user The name of the owner of the GitHub repository. |
||
| 49 | * @param string $repo The name of the GitHub repository. |
||
| 50 | * @param string $sha The SHA of the commit to retrieve. |
||
| 51 | * @param integer $page Page to request |
||
| 52 | * @param integer $limit Number of results to return per page |
||
| 53 | * |
||
| 54 | * @return array |
||
| 55 | * |
||
| 56 | * @since 1.0 |
||
| 57 | */ |
||
| 58 | public function getList($user, $repo, $sha, $page = 0, $limit = 0) |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Get a single commit comment. |
||
| 71 | * |
||
| 72 | * @param string $user The name of the owner of the GitHub repository. |
||
| 73 | * @param string $repo The name of the GitHub repository. |
||
| 74 | * @param integer $id ID of the comment to retrieve |
||
| 75 | * |
||
| 76 | * @return array |
||
| 77 | * |
||
| 78 | * @since 1.0 |
||
| 79 | */ |
||
| 80 | public function get($user, $repo, $id) |
||
| 90 | |||
| 91 | /** |
||
| 92 | * Update a commit comment. |
||
| 93 | * |
||
| 94 | * @param string $user The name of the owner of the GitHub repository. |
||
| 95 | * @param string $repo The name of the GitHub repository. |
||
| 96 | * @param string $id The ID of the comment to edit. |
||
| 97 | * @param string $comment The text of the comment. |
||
| 98 | * |
||
| 99 | * @return object |
||
| 100 | * |
||
| 101 | * @since 1.0 |
||
| 102 | */ |
||
| 103 | public function edit($user, $repo, $id, $comment) |
||
| 119 | |||
| 120 | /** |
||
| 121 | * Delete a commit comment. |
||
| 122 | * |
||
| 123 | * @param string $user The name of the owner of the GitHub repository. |
||
| 124 | * @param string $repo The name of the GitHub repository. |
||
| 125 | * @param string $id The ID of the comment to edit. |
||
| 126 | * |
||
| 127 | * @return object |
||
| 128 | * |
||
| 129 | * @since 1.0 |
||
| 130 | */ |
||
| 131 | View Code Duplication | public function delete($user, $repo, $id) |
|
| 142 | |||
| 143 | /** |
||
| 144 | * Create a commit comment. |
||
| 145 | * |
||
| 146 | * @param string $user The name of the owner of the GitHub repository. |
||
| 147 | * @param string $repo The name of the GitHub repository. |
||
| 148 | * @param string $sha The SHA of the commit to comment on. |
||
| 149 | * @param string $comment The text of the comment. |
||
| 150 | * @param integer $line The line number of the commit to comment on. |
||
| 151 | * @param string $filepath A relative path to the file to comment on within the commit. |
||
| 152 | * @param integer $position Line index in the diff to comment on. |
||
| 153 | * |
||
| 154 | * @return object |
||
| 155 | * |
||
| 156 | * @since 1.0 |
||
| 157 | */ |
||
| 158 | View Code Duplication | public function create($user, $repo, $sha, $comment, $line, $filepath, $position) |
|
| 178 | } |
||
| 179 |
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.