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 |
||
14 | class Milestones extends AbstractIssues |
||
15 | { |
||
16 | |||
17 | /** |
||
18 | * List milestones for a repository |
||
19 | * |
||
20 | * @link https://developer.github.com/v3/issues/milestones/#list-milestones-for-a-repository |
||
21 | * |
||
22 | * @param string $state |
||
23 | * @param string $sort |
||
24 | * @param string $direction |
||
25 | * |
||
26 | * @return array |
||
27 | */ |
||
28 | public function listMilestones(string $state = AbstractApi::STATE_OPEN, string $sort = AbstractApi::SORT_DUE_DATE, |
||
38 | |||
39 | /** |
||
40 | * Get a single milestone |
||
41 | * |
||
42 | * @link https://developer.github.com/v3/issues/milestones/#get-a-single-milestone |
||
43 | * |
||
44 | * @param int $number |
||
45 | * |
||
46 | * @return array |
||
47 | */ |
||
48 | public function getMilestone(int $number): array |
||
53 | |||
54 | /** |
||
55 | * Create a milestone |
||
56 | * |
||
57 | * @link https://developer.github.com/v3/issues/milestones/#create-a-milestone |
||
58 | * |
||
59 | * @param string $title |
||
60 | * @param string $state |
||
61 | * @param string $description |
||
62 | * @param string $dueOn |
||
63 | * |
||
64 | * @return array |
||
65 | */ |
||
66 | View Code Duplication | public function createMilestone(string $title, string $state = AbstractApi::STATE_OPEN, string $description = '', |
|
78 | |||
79 | /** |
||
80 | * Update a milestone |
||
81 | * |
||
82 | * @link https://developer.github.com/v3/issues/milestones/#update-a-milestone |
||
83 | * |
||
84 | * @param int $number |
||
85 | * @param string $title |
||
86 | * @param string $state |
||
87 | * @param string $description |
||
88 | * @param string $dueOn |
||
89 | * |
||
90 | * @return array |
||
91 | */ |
||
92 | View Code Duplication | public function updateMilestone(int $number, string $title = '', string $state = AbstractApi::STATE_OPEN, |
|
103 | |||
104 | /** |
||
105 | * Delete a milestone |
||
106 | * |
||
107 | * @link https://developer.github.com/v3/issues/milestones/#delete-a-milestone |
||
108 | * |
||
109 | * @param int $number |
||
110 | * |
||
111 | * @return bool |
||
112 | */ |
||
113 | public function deleteMilestone(int $number): bool |
||
124 | } |
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.