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 Labels extends AbstractPackage |
||
21 | { |
||
22 | /** |
||
23 | * List all labels for this repository. |
||
24 | * |
||
25 | * @param string $owner The name of the owner of the GitHub repository. |
||
26 | * @param string $repo The name of the GitHub repository. |
||
27 | * |
||
28 | * @return array |
||
29 | * |
||
30 | * @since 1.0 |
||
31 | */ |
||
32 | public function getList($owner, $repo) |
||
42 | |||
43 | /** |
||
44 | * Get a single label. |
||
45 | * |
||
46 | * @param string $user The name of the owner of the GitHub repository. |
||
47 | * @param string $repo The name of the GitHub repository. |
||
48 | * @param string $name The label name to get. |
||
49 | * |
||
50 | * @return object |
||
51 | * |
||
52 | * @since 1.0 |
||
53 | */ |
||
54 | public function get($user, $repo, $name) |
||
64 | |||
65 | /** |
||
66 | * Create a label. |
||
67 | * |
||
68 | * @param string $owner The name of the owner of the GitHub repository. |
||
69 | * @param string $repo The name of the GitHub repository. |
||
70 | * @param string $name The label name. |
||
71 | * @param string $color The label color. |
||
72 | * |
||
73 | * @return object |
||
74 | * |
||
75 | * @since 1.0 |
||
76 | * @throws \DomainException |
||
77 | */ |
||
78 | public function create($owner, $repo, $name, $color) |
||
94 | |||
95 | /** |
||
96 | * Delete a label. |
||
97 | * |
||
98 | * @param string $owner The name of the owner of the GitHub repository. |
||
99 | * @param string $repo The name of the GitHub repository. |
||
100 | * @param string $name The label name. |
||
101 | * |
||
102 | * @return object |
||
103 | * |
||
104 | * @since 1.0 |
||
105 | */ |
||
106 | View Code Duplication | public function delete($owner, $repo, $name) |
|
117 | |||
118 | /** |
||
119 | * Update a label. |
||
120 | * |
||
121 | * @param string $user The name of the owner of the GitHub repository. |
||
122 | * @param string $repo The name of the GitHub repository. |
||
123 | * @param string $label The label name. |
||
124 | * @param string $name The new label name. |
||
125 | * @param string $color The new label color. |
||
126 | * |
||
127 | * @return object |
||
128 | * |
||
129 | * @since 1.0 |
||
130 | */ |
||
131 | public function update($user, $repo, $label, $name, $color) |
||
149 | |||
150 | /** |
||
151 | * List labels on an issue. |
||
152 | * |
||
153 | * @param string $owner The name of the owner of the GitHub repository. |
||
154 | * @param string $repo The name of the GitHub repository. |
||
155 | * @param integer $number The issue number. |
||
156 | * |
||
157 | * @return object |
||
158 | * |
||
159 | * @since 1.0 |
||
160 | */ |
||
161 | public function getListByIssue($owner, $repo, $number) |
||
171 | |||
172 | /** |
||
173 | * Add labels to an issue. |
||
174 | * |
||
175 | * @param string $owner The name of the owner of the GitHub repository. |
||
176 | * @param string $repo The name of the GitHub repository. |
||
177 | * @param string $number The issue number. |
||
178 | * @param array $labels An array of labels to add. |
||
179 | * |
||
180 | * @return object |
||
181 | * |
||
182 | * @since 1.0 |
||
183 | */ |
||
184 | View Code Duplication | public function add($owner, $repo, $number, array $labels) |
|
194 | |||
195 | /** |
||
196 | * Remove a label from an issue. |
||
197 | * |
||
198 | * @param string $owner The name of the owner of the GitHub repository. |
||
199 | * @param string $repo The name of the GitHub repository. |
||
200 | * @param string $number The issue number. |
||
201 | * @param string $name The name of the label to remove. |
||
202 | * |
||
203 | * @return object |
||
204 | * |
||
205 | * @since 1.0 |
||
206 | */ |
||
207 | public function removeFromIssue($owner, $repo, $number, $name) |
||
217 | |||
218 | /** |
||
219 | * Replace all labels for an issue. |
||
220 | * |
||
221 | * Sending an empty array ([]) will remove all Labels from the Issue. |
||
222 | * |
||
223 | * @param string $owner The name of the owner of the GitHub repository. |
||
224 | * @param string $repo The name of the GitHub repository. |
||
225 | * @param string $number The issue number. |
||
226 | * @param array $labels New labels |
||
227 | * |
||
228 | * @return object |
||
229 | * |
||
230 | * @since 1.0 |
||
231 | */ |
||
232 | View Code Duplication | public function replace($owner, $repo, $number, array $labels) |
|
242 | |||
243 | /** |
||
244 | * Remove all labels from an issue. |
||
245 | * |
||
246 | * @param string $owner The name of the owner of the GitHub repository. |
||
247 | * @param string $repo The name of the GitHub repository. |
||
248 | * @param string $number The issue number. |
||
249 | * |
||
250 | * @return object |
||
251 | * |
||
252 | * @since 1.0 |
||
253 | */ |
||
254 | View Code Duplication | public function removeAllFromIssue($owner, $repo, $number) |
|
265 | |||
266 | /** |
||
267 | * Get labels for every issue in a milestone. |
||
268 | * |
||
269 | * @param string $owner The name of the owner of the GitHub repository. |
||
270 | * @param string $repo The name of the GitHub repository. |
||
271 | * @param string $number The issue number. |
||
272 | * |
||
273 | * @return object |
||
274 | * |
||
275 | * @since 1.0 |
||
276 | */ |
||
277 | public function getListByMilestone($owner, $repo, $number) |
||
287 | } |
||
288 |
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.