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 Comments extends AbstractGists |
||
| 13 | { |
||
| 14 | |||
| 15 | /** |
||
| 16 | * List comments on a gist |
||
| 17 | * |
||
| 18 | * @link https://developer.github.com/v3/gists/comments/#list-comments-on-a-gist |
||
| 19 | * |
||
| 20 | * @param string $gistId |
||
| 21 | * |
||
| 22 | * @return array |
||
| 23 | */ |
||
| 24 | public function listComments(string $gistId): array |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Get a single comment |
||
| 31 | * |
||
| 32 | * @link https://developer.github.com/v3/gists/comments/#get-a-single-comment |
||
| 33 | * |
||
| 34 | * @param string $gistId |
||
| 35 | * @param int $id |
||
| 36 | * |
||
| 37 | * @return array |
||
| 38 | */ |
||
| 39 | public function getSingleComment(string $gistId, int $id): array |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Create a comment |
||
| 46 | * |
||
| 47 | * @link https://developer.github.com/v3/gists/comments/#create-a-comment |
||
| 48 | * |
||
| 49 | * @param string $gistId |
||
| 50 | * @param string $body |
||
| 51 | * |
||
| 52 | * @return array |
||
| 53 | */ |
||
| 54 | public function createComment(string $gistId, string $body): array |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Edit a comment |
||
| 64 | * |
||
| 65 | * @link https://developer.github.com/v3/gists/comments/#edit-a-comment |
||
| 66 | * |
||
| 67 | * @param string $gistId |
||
| 68 | * @param int $id |
||
| 69 | * @param string $body |
||
| 70 | * |
||
| 71 | * @return array |
||
| 72 | */ |
||
| 73 | public function editComment(string $gistId, int $id, string $body): array |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Delete a comment |
||
| 83 | * |
||
| 84 | * @link https://developer.github.com/v3/gists/comments/#delete-a-comment |
||
| 85 | * |
||
| 86 | * @param string $gistId |
||
| 87 | * @param int $id |
||
| 88 | * |
||
| 89 | * @return bool |
||
| 90 | */ |
||
| 91 | View Code Duplication | public function deleteComment(string $gistId, int $id): bool |
|
| 102 | } |
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.