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 Labels extends AbstractIssues |
||
| 13 | { |
||
| 14 | |||
| 15 | /** |
||
| 16 | * List all labels for this repository |
||
| 17 | * |
||
| 18 | * @link https://developer.github.com/v3/issues/labels/#list-all-labels-for-this-repository |
||
| 19 | * @return array |
||
| 20 | */ |
||
| 21 | public function listRepositoryLabels(): array |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Get a single label |
||
| 30 | * |
||
| 31 | * @link https://developer.github.com/v3/issues/labels/#get-a-single-label |
||
| 32 | * |
||
| 33 | * @param string $name |
||
| 34 | * |
||
| 35 | * @return array |
||
| 36 | */ |
||
| 37 | public function getLabel(string $name): array |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Create a label |
||
| 45 | * |
||
| 46 | * @link https://developer.github.com/v3/issues/labels/#create-a-label |
||
| 47 | * |
||
| 48 | * @param string $name |
||
| 49 | * @param string $color |
||
| 50 | * |
||
| 51 | * @return array |
||
| 52 | */ |
||
| 53 | public function createLabel(string $name, string $color): array |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Update a label |
||
| 65 | * |
||
| 66 | * @link https://developer.github.com/v3/issues/labels/#update-a-label |
||
| 67 | * |
||
| 68 | * @param string $name |
||
| 69 | * @param string $color |
||
| 70 | * |
||
| 71 | * @return array |
||
| 72 | */ |
||
| 73 | public function updateLabel(string $name, string $color): array |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Delete a label |
||
| 83 | * |
||
| 84 | * @link https://developer.github.com/v3/issues/labels/#delete-a-label |
||
| 85 | * |
||
| 86 | * @param string $name |
||
| 87 | * |
||
| 88 | * @return bool |
||
| 89 | */ |
||
| 90 | public function deleteLabel(string $name): bool |
||
| 102 | |||
| 103 | /** |
||
| 104 | * List labels on an issue |
||
| 105 | * |
||
| 106 | * @link https://developer.github.com/v3/issues/labels/#list-labels-on-an-issue |
||
| 107 | * |
||
| 108 | * @param int $number |
||
| 109 | * |
||
| 110 | * @return array |
||
| 111 | */ |
||
| 112 | public function listIssueLabels(int $number): array |
||
| 117 | |||
| 118 | /** |
||
| 119 | * Add labels to an issue |
||
| 120 | * |
||
| 121 | * @link https://developer.github.com/v3/issues/labels/#add-labels-to-an-issue |
||
| 122 | * |
||
| 123 | * @param int $number |
||
| 124 | * |
||
| 125 | * @return array |
||
| 126 | */ |
||
| 127 | public function addIssueLabels(int $number): array |
||
| 132 | |||
| 133 | /** |
||
| 134 | * Remove a label from an issue |
||
| 135 | * |
||
| 136 | * @link https://developer.github.com/v3/issues/labels/#remove-a-label-from-an-issue |
||
| 137 | * |
||
| 138 | * @param int $number |
||
| 139 | * @param string $name |
||
| 140 | * |
||
| 141 | * @return bool |
||
| 142 | */ |
||
| 143 | View Code Duplication | public function removeIssueLabel(int $number, string $name): bool |
|
| 154 | |||
| 155 | /** |
||
| 156 | * Replace all labels for an issue |
||
| 157 | * |
||
| 158 | * @link https://developer.github.com/v3/issues/labels/#replace-all-labels-for-an-issue |
||
| 159 | * |
||
| 160 | * @param int $number |
||
| 161 | * |
||
| 162 | * @return array |
||
| 163 | */ |
||
| 164 | public function replaceIssuesLabels(int $number): array |
||
| 169 | |||
| 170 | /** |
||
| 171 | * Remove all labels from an issue |
||
| 172 | * |
||
| 173 | * @link https://developer.github.com/v3/issues/labels/#remove-all-labels-from-an-issue |
||
| 174 | * |
||
| 175 | * @param int $number |
||
| 176 | * |
||
| 177 | * @return bool |
||
| 178 | */ |
||
| 179 | public function removeIssueLabels(int $number): bool |
||
| 190 | |||
| 191 | /** |
||
| 192 | * Get labels for every issue in a milestone |
||
| 193 | * |
||
| 194 | * @link https://developer.github.com/v3/issues/labels/#get-labels-for-every-issue-in-a-milestone |
||
| 195 | * |
||
| 196 | * @param int $number |
||
| 197 | * |
||
| 198 | * @return array |
||
| 199 | */ |
||
| 200 | public function getIssueLabelsInMilestone(int $number): array |
||
| 205 | } |
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.