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 |
||
| 12 | class Teams extends AbstractOrganizations |
||
| 13 | { |
||
| 14 | |||
| 15 | /** |
||
| 16 | * List teams |
||
| 17 | * |
||
| 18 | * @link https://developer.github.com/v3/orgs/teams/#list-teams |
||
| 19 | * |
||
| 20 | * @param string $org |
||
| 21 | * |
||
| 22 | * @return array |
||
| 23 | * @throws \Exception |
||
| 24 | */ |
||
| 25 | public function listTeams(string $org): array |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Get team |
||
| 32 | * |
||
| 33 | * @link https://developer.github.com/v3/orgs/teams/#get-team |
||
| 34 | * |
||
| 35 | * @param int $id |
||
| 36 | * |
||
| 37 | * @return array |
||
| 38 | * @throws \Exception |
||
| 39 | */ |
||
| 40 | public function getTeam(int $id): array |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Create team |
||
| 47 | * |
||
| 48 | * @link https://developer.github.com/v3/orgs/teams/#create-team |
||
| 49 | * |
||
| 50 | * @param string $org |
||
| 51 | * @param string $name |
||
| 52 | * @param null|string $description |
||
| 53 | * @param array $repoNames |
||
| 54 | * @param string $permission |
||
| 55 | * |
||
| 56 | * @return array |
||
| 57 | * @throws \Exception |
||
| 58 | */ |
||
| 59 | public function createTeam(string $org, string $name, string $description = null, array $repoNames = [], |
||
| 60 | string $permission = AbstractApi::PERMISSION_PULL): array |
||
| 61 | { |
||
| 62 | return $this->getApi()->request($this->getApi()->sprintf('/orgs/:org/teams', $org), Request::METHOD_POST, [ |
||
| 63 | 'name' => $name, |
||
| 64 | 'description' => $description, |
||
| 65 | 'repo_names' => $repoNames, |
||
| 66 | 'permission' => $permission |
||
| 67 | ]); |
||
| 68 | } |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Edit team |
||
| 72 | * |
||
| 73 | * @link https://developer.github.com/v3/orgs/teams/#edit-team |
||
| 74 | * |
||
| 75 | * @param int $id |
||
| 76 | * @param string $name |
||
| 77 | * @param null|string $description |
||
| 78 | * @param string $permission |
||
| 79 | * |
||
| 80 | * @return array |
||
| 81 | * @throws \Exception |
||
| 82 | */ |
||
| 83 | View Code Duplication | public function editTeam(int $id, string $name, string $description = null, |
|
| 92 | |||
| 93 | /** |
||
| 94 | * Delete team |
||
| 95 | * |
||
| 96 | * @link https://developer.github.com/v3/orgs/teams/#delete-team |
||
| 97 | * |
||
| 98 | * @param int $id |
||
| 99 | * |
||
| 100 | * @return bool |
||
| 101 | * @throws \Exception |
||
| 102 | */ |
||
| 103 | View Code Duplication | public function deleteTeam(int $id): bool |
|
| 113 | |||
| 114 | /** |
||
| 115 | * List team members |
||
| 116 | * |
||
| 117 | * @link https://developer.github.com/v3/orgs/teams/#list-team-members |
||
| 118 | * |
||
| 119 | * @param int $id |
||
| 120 | * |
||
| 121 | * @return array |
||
| 122 | * @throws \Exception |
||
| 123 | */ |
||
| 124 | public function listTeamMembers(int $id): array |
||
| 128 | |||
| 129 | /** |
||
| 130 | * Get team membership |
||
| 131 | * |
||
| 132 | * @link https://developer.github.com/v3/orgs/teams/#get-team-membership |
||
| 133 | * |
||
| 134 | * @param int $id |
||
| 135 | * @param string $username |
||
| 136 | * |
||
| 137 | * @return array |
||
| 138 | * @throws \Exception |
||
| 139 | */ |
||
| 140 | public function getTeamMembership(int $id, string $username): array |
||
| 145 | |||
| 146 | /** |
||
| 147 | * Add team membership |
||
| 148 | * |
||
| 149 | * @link https://developer.github.com/v3/orgs/teams/#add-team-membership |
||
| 150 | * |
||
| 151 | * @param int $id |
||
| 152 | * @param string $username |
||
| 153 | * |
||
| 154 | * @return array |
||
| 155 | * @throws \Exception |
||
| 156 | */ |
||
| 157 | public function addTeamMembership(int $id, string $username): array |
||
| 163 | |||
| 164 | /** |
||
| 165 | * Remove team membership |
||
| 166 | * |
||
| 167 | * @link https://developer.github.com/v3/orgs/teams/#remove-team-membership |
||
| 168 | * |
||
| 169 | * @param int $id |
||
| 170 | * @param string $username |
||
| 171 | * |
||
| 172 | * @return bool |
||
| 173 | * @throws \Exception |
||
| 174 | */ |
||
| 175 | View Code Duplication | public function removeTeamMembership(int $id, string $username): bool |
|
| 186 | |||
| 187 | /** |
||
| 188 | * List team repos |
||
| 189 | * |
||
| 190 | * @link https://developer.github.com/v3/orgs/teams/#list-team-repos |
||
| 191 | * |
||
| 192 | * @param int $id |
||
| 193 | * |
||
| 194 | * @return array |
||
| 195 | * @throws \Exception |
||
| 196 | */ |
||
| 197 | public function listTeamRepos(int $id): array |
||
| 201 | |||
| 202 | /** |
||
| 203 | * Check if a team manages a repository |
||
| 204 | * |
||
| 205 | * @link https://developer.github.com/v3/orgs/teams/#get-team-repo |
||
| 206 | * |
||
| 207 | * @param int $id |
||
| 208 | * |
||
| 209 | * @return bool |
||
| 210 | * @throws \Exception |
||
| 211 | */ |
||
| 212 | public function checkTeamManagesRepository(int $id): bool |
||
| 223 | |||
| 224 | /** |
||
| 225 | * Add team repository |
||
| 226 | * |
||
| 227 | * @link https://developer.github.com/v3/orgs/teams/#add-team-repo |
||
| 228 | * |
||
| 229 | * @param int $id |
||
| 230 | * |
||
| 231 | * @return bool|array |
||
| 232 | * @throws \Exception |
||
| 233 | */ |
||
| 234 | View Code Duplication | public function addTeamRepository(int $id) |
|
| 245 | |||
| 246 | /** |
||
| 247 | * Remove team repository |
||
| 248 | * |
||
| 249 | * @link https://developer.github.com/v3/orgs/teams/#remove-team-repo |
||
| 250 | * |
||
| 251 | * @param int $id |
||
| 252 | * |
||
| 253 | * @return bool |
||
| 254 | * @throws \Exception |
||
| 255 | */ |
||
| 256 | View Code Duplication | public function removeTeamRepository(int $id): bool |
|
| 267 | |||
| 268 | /** |
||
| 269 | * List user teams |
||
| 270 | * |
||
| 271 | * @link https://developer.github.com/v3/orgs/teams/#list-user-teams |
||
| 272 | * @return array |
||
| 273 | * @throws \Exception |
||
| 274 | */ |
||
| 275 | public function lisUserTeams(): array |
||
| 279 | } |
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.