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 Collaborators extends AbstractPackage |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * List collaborators. |
||
| 24 | * |
||
| 25 | * When authenticating as an organization owner of an organization-owned repository, all organization |
||
| 26 | * owners are included in the list of collaborators. Otherwise, only users with access to the repository |
||
| 27 | * are returned in the collaborators list. |
||
| 28 | * |
||
| 29 | * @param string $owner The name of the owner of the GitHub repository. |
||
| 30 | * @param string $repo The name of the GitHub repository. |
||
| 31 | * |
||
| 32 | * @since 1.0 |
||
| 33 | * |
||
| 34 | * @return object |
||
| 35 | */ |
||
| 36 | public function getList($owner, $repo) |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Check if a user is a collaborator. |
||
| 48 | * |
||
| 49 | * @param string $owner The name of the owner of the GitHub repository. |
||
| 50 | * @param string $repo The name of the GitHub repository. |
||
| 51 | * @param string $user The name of the GitHub user. |
||
| 52 | * |
||
| 53 | * @throws \UnexpectedValueException |
||
| 54 | * @since 1.0 |
||
| 55 | * |
||
| 56 | * @return boolean |
||
| 57 | */ |
||
| 58 | public function get($owner, $repo, $user) |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Add user as a collaborator. |
||
| 83 | * |
||
| 84 | * @param string $owner The name of the owner of the GitHub repository. |
||
| 85 | * @param string $repo The name of the GitHub repository. |
||
| 86 | * @param string $user The name of the GitHub user. |
||
| 87 | * |
||
| 88 | * @since 1.0 |
||
| 89 | * |
||
| 90 | * @return object |
||
| 91 | */ |
||
| 92 | View Code Duplication | public function add($owner, $repo, $user) |
|
| 102 | |||
| 103 | /** |
||
| 104 | * Remove user as a collaborator. |
||
| 105 | * |
||
| 106 | * @param string $owner The name of the owner of the GitHub repository. |
||
| 107 | * @param string $repo The name of the GitHub repository. |
||
| 108 | * @param string $user The name of the GitHub user. |
||
| 109 | * |
||
| 110 | * @since 1.0 |
||
| 111 | * |
||
| 112 | * @return object |
||
| 113 | */ |
||
| 114 | View Code Duplication | public function remove($owner, $repo, $user) |
|
| 124 | } |
||
| 125 |
The break statement is not necessary if it is preceded for example by a return statement:
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.