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 |
||
| 21 | class Assignees extends AbstractPackage |
||
| 22 | { |
||
| 23 | /** |
||
| 24 | * List assignees. |
||
| 25 | * |
||
| 26 | * This call lists all the available assignees (owner + collaborators) to which issues may be assigned. |
||
| 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 | * |
||
| 31 | * @return object |
||
| 32 | * |
||
| 33 | * @since 1.0 |
||
| 34 | */ |
||
| 35 | public function getList($owner, $repo) |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Check assignee. |
||
| 47 | * |
||
| 48 | * You may check to see if a particular user is an assignee for a repository. |
||
| 49 | * If the given assignee login belongs to an assignee for the repository, a 204 header |
||
| 50 | * with no content is returned. |
||
| 51 | * Otherwise a 404 status code is returned. |
||
| 52 | * |
||
| 53 | * @param string $owner The name of the owner of the GitHub repository. |
||
| 54 | * @param string $repo The name of the GitHub repository. |
||
| 55 | * @param string $assignee The assignees login name. |
||
| 56 | * |
||
| 57 | * @return boolean |
||
| 58 | * |
||
| 59 | * @since 1.0 |
||
| 60 | * @throws \DomainException |
||
| 61 | */ |
||
| 62 | public function check($owner, $repo, $assignee) |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Add assignees to an Issue |
||
| 91 | * |
||
| 92 | * This call adds the users passed in the assignees key (as their logins) to the issue. |
||
| 93 | * |
||
| 94 | * @param string $owner The name of the owner of the GitHub repository. |
||
| 95 | * @param string $repo The name of the GitHub repository. |
||
| 96 | * @param integer $number The issue number to add assignees to. |
||
| 97 | * @param string[] $assignees The logins for GitHub users to assign to this issue. |
||
| 98 | * |
||
| 99 | * @return object |
||
| 100 | * |
||
| 101 | * @since 1.4.0 |
||
| 102 | * @throws \DomainException |
||
| 103 | */ |
||
| 104 | View Code Duplication | public function add($owner, $repo, $number, array $assignees) |
|
| 117 | |||
| 118 | /** |
||
| 119 | * Remove assignees from an Issue |
||
| 120 | * |
||
| 121 | * This call removes the users passed in the assignees key (as their logins) from the issue. |
||
| 122 | * |
||
| 123 | * @param string $owner The name of the owner of the GitHub repository. |
||
| 124 | * @param string $repo The name of the GitHub repository. |
||
| 125 | * @param integer $number The issue number to add assignees to. |
||
| 126 | * @param string[] $assignees The logins for GitHub users to assign to this issue. |
||
| 127 | * |
||
| 128 | * @return object |
||
| 129 | * |
||
| 130 | * @since 1.4.0 |
||
| 131 | * @throws \DomainException |
||
| 132 | */ |
||
| 133 | View Code Duplication | public function remove($owner, $repo, $number, array $assignees) |
|
| 146 | } |
||
| 147 |
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.