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 ReviewComments extends AbstractPullRequests | ||
| 15 | { | ||
| 16 | |||
| 17 | /** | ||
| 18 | * List comments on a pull request | ||
| 19 | * | ||
| 20 | * @link https://developer.github.com/v3/pulls/comments/#list-comments-on-a-pull-request | ||
| 21 | * | ||
| 22 | * @param int $number | ||
| 23 | * | ||
| 24 | * @return array | ||
| 25 | * @throws \Exception | ||
| 26 | */ | ||
| 27 | public function listCommentsPullRequest(int $number): array | ||
| 32 | |||
| 33 | /** | ||
| 34 | * List comments in a repository | ||
| 35 | * | ||
| 36 | * @link https://developer.github.com/v3/pulls/comments/#list-comments-in-a-repository | ||
| 37 | * | ||
| 38 | * @param string $sort | ||
| 39 | * @param string $direction | ||
| 40 | * @param string $since | ||
| 41 | * | ||
| 42 | * @return array | ||
| 43 | * @throws \Exception | ||
| 44 | */ | ||
| 45 | View Code Duplication | public function listCommentsRepository(string $sort = AbstractApi::SORT_CREATED, | |
|  | |||
| 46 | string $direction = AbstractApi::DIRECTION_DESC, | ||
| 47 | string $since = 'now'): array | ||
| 48 |     { | ||
| 49 |         return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/pulls/comments?:args', | ||
| 50 | $this->getPullRequests()->getOwner(), $this->getPullRequests()->getRepo(), http_build_query([ | ||
| 51 | 'sort' => $sort, | ||
| 52 | 'direction' => $direction, | ||
| 53 | 'since' => (new DateTime($since))->format(DateTime::ATOM) | ||
| 54 | ]))); | ||
| 55 | } | ||
| 56 | |||
| 57 | /** | ||
| 58 | * Get a single comment | ||
| 59 | * | ||
| 60 | * @link https://developer.github.com/v3/pulls/comments/#get-a-single-comment | ||
| 61 | * | ||
| 62 | * @param int $number | ||
| 63 | * | ||
| 64 | * @return array | ||
| 65 | * @throws \Exception | ||
| 66 | */ | ||
| 67 | public function getSingleComment(int $number): array | ||
| 72 | |||
| 73 | /** | ||
| 74 | * Create a comment | ||
| 75 | * | ||
| 76 | * @link https://developer.github.com/v3/pulls/comments/#create-a-comment | ||
| 77 | * | ||
| 78 | * @param int $number | ||
| 79 | * @param string $body | ||
| 80 | * @param string $commitId | ||
| 81 | * @param string $path | ||
| 82 | * @param int $position | ||
| 83 | * | ||
| 84 | * @return array | ||
| 85 | * @throws \Exception | ||
| 86 | */ | ||
| 87 | public function createComment(int $number, string $body, string $commitId, string $path, int $position): array | ||
| 97 | |||
| 98 | /** | ||
| 99 | * Edit a comment | ||
| 100 | * | ||
| 101 | * @link https://developer.github.com/v3/pulls/comments/#edit-a-comment | ||
| 102 | * | ||
| 103 | * @param int $number | ||
| 104 | * @param string $body | ||
| 105 | * | ||
| 106 | * @return array | ||
| 107 | * @throws \Exception | ||
| 108 | */ | ||
| 109 | public function editComment(int $number, string $body): array | ||
| 117 | |||
| 118 | /** | ||
| 119 | * Delete a comment | ||
| 120 | * | ||
| 121 | * @link https://developer.github.com/v3/pulls/comments/#delete-a-comment | ||
| 122 | * | ||
| 123 | * @param int $number | ||
| 124 | * | ||
| 125 | * @return bool | ||
| 126 | * @throws \Exception | ||
| 127 | */ | ||
| 128 | public function deleteComment(int $number): bool | ||
| 139 | } | 
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.