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 Members extends AbstractOrganizations |
||
13 | { |
||
14 | |||
15 | /** |
||
16 | * Members list |
||
17 | * |
||
18 | * @link https://developer.github.com/v3/orgs/members/#members-list |
||
19 | * |
||
20 | * @param string $org |
||
21 | * @param string $filter |
||
22 | * @param string $role |
||
23 | * |
||
24 | * @return array |
||
25 | */ |
||
26 | public function listMembers(string $org, string $filter = AbstractApi::FILTER_ALL, string $role = 'admin'): array |
||
33 | |||
34 | /** |
||
35 | * Check membership |
||
36 | * |
||
37 | * @link https://developer.github.com/v3/orgs/members/#check-membership |
||
38 | * |
||
39 | * @param string $org |
||
40 | * @param string $username |
||
41 | * |
||
42 | * @return bool |
||
43 | * @throws \Exception |
||
44 | */ |
||
45 | View Code Duplication | public function checkMembership(string $org, string $username): bool |
|
55 | |||
56 | /** |
||
57 | * Remove a member |
||
58 | * |
||
59 | * @link https://developer.github.com/v3/orgs/members/#remove-a-member |
||
60 | * |
||
61 | * @param string $org |
||
62 | * @param string $username |
||
63 | * |
||
64 | * @return bool |
||
65 | * @throws \Exception |
||
66 | */ |
||
67 | View Code Duplication | public function removeMember(string $org, string $username): bool |
|
78 | |||
79 | /** |
||
80 | * Public members list |
||
81 | * |
||
82 | * @link https://developer.github.com/v3/orgs/members/#public-members-list |
||
83 | * |
||
84 | * @param string $org |
||
85 | * |
||
86 | * @return array |
||
87 | * @throws \Exception |
||
88 | */ |
||
89 | public function listPublicMembers(string $org): array |
||
93 | |||
94 | /** |
||
95 | * Check public membership |
||
96 | * |
||
97 | * @link https://developer.github.com/v3/orgs/members/#check-public-membership |
||
98 | * |
||
99 | * @param string $org |
||
100 | * @param string $username |
||
101 | * |
||
102 | * @return bool |
||
103 | * @throws \Exception |
||
104 | */ |
||
105 | View Code Duplication | public function checkPublicMembership(string $org, string $username): bool |
|
115 | |||
116 | /** |
||
117 | * Publicize a user’s membership |
||
118 | * |
||
119 | * @link https://developer.github.com/v3/orgs/members/#publicize-a-users-membership |
||
120 | * |
||
121 | * @param string $org |
||
122 | * @param string $username |
||
123 | * |
||
124 | * @return bool |
||
125 | * @throws \Exception |
||
126 | */ |
||
127 | View Code Duplication | public function publicizeUsersMembership(string $org, string $username): bool |
|
138 | |||
139 | /** |
||
140 | * Conceal a user’s membership |
||
141 | * |
||
142 | * @link https://developer.github.com/v3/orgs/members/#conceal-a-users-membership |
||
143 | * |
||
144 | * @param string $org |
||
145 | * @param string $username |
||
146 | * |
||
147 | * @return bool |
||
148 | * @throws \Exception |
||
149 | */ |
||
150 | View Code Duplication | public function concealUsersMembership(string $org, string $username): bool |
|
161 | |||
162 | /** |
||
163 | * Get organization membership |
||
164 | * |
||
165 | * @link https://developer.github.com/v3/orgs/members/#get-organization-membership |
||
166 | * |
||
167 | * @param string $org |
||
168 | * @param string $username |
||
169 | * |
||
170 | * @return array |
||
171 | * @throws \Exception |
||
172 | */ |
||
173 | public function getOrganizationMembership(string $org, string $username): array |
||
179 | |||
180 | /** |
||
181 | * Add or update organization membership |
||
182 | * |
||
183 | * @link https://developer.github.com/v3/orgs/members/#add-or-update-organization-membership |
||
184 | * |
||
185 | * @param string $org |
||
186 | * @param string $username |
||
187 | * @param string $role |
||
188 | * |
||
189 | * @return array |
||
190 | * @throws \Exception |
||
191 | */ |
||
192 | public function addUpdateOrganizationMembership(string $org, string $username, string $role): array |
||
200 | |||
201 | /** |
||
202 | * Remove organization membership |
||
203 | * |
||
204 | * @link https://developer.github.com/v3/orgs/members/#remove-organization-membership |
||
205 | * |
||
206 | * @param string $org |
||
207 | * @param string $username |
||
208 | * |
||
209 | * @return bool |
||
210 | * @throws \Exception |
||
211 | */ |
||
212 | View Code Duplication | public function removeOrganizationMembership(string $org, string $username): bool |
|
225 | |||
226 | /** |
||
227 | * List your organization memberships |
||
228 | * |
||
229 | * @link https://developer.github.com/v3/orgs/members/#list-your-organization-memberships |
||
230 | * |
||
231 | * @param string|null $state |
||
232 | * |
||
233 | * @return array |
||
234 | * @throws \Exception |
||
235 | */ |
||
236 | public function listYourOrganizationMembership(string $state = null): array |
||
241 | |||
242 | /** |
||
243 | * Get your organization membership |
||
244 | * |
||
245 | * @link https://developer.github.com/v3/orgs/members/#get-your-organization-membership |
||
246 | * |
||
247 | * @param string $org |
||
248 | * |
||
249 | * @return array |
||
250 | * @throws \Exception |
||
251 | */ |
||
252 | public function getYourOrganizationMembership(string $org): array |
||
256 | |||
257 | /** |
||
258 | * Edit your organization membership |
||
259 | * |
||
260 | * @link https://developer.github.com/v3/orgs/members/#edit-your-organization-membership |
||
261 | * |
||
262 | * @param string $org |
||
263 | * @param string $state |
||
264 | * |
||
265 | * @return array |
||
266 | * @throws \Exception |
||
267 | */ |
||
268 | public function editYourOrganizationMembership(string $org, string $state = AbstractApi::STATE_ACTIVE): array |
||
275 | } |
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.