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 Hooks extends AbstractRepositories | ||
| 13 | { | ||
| 14 | |||
| 15 | /** | ||
| 16 | * List hooks | ||
| 17 | * | ||
| 18 | * @link https://developer.github.com/v3/repos/hooks/#list-hooks | ||
| 19 | * @return array | ||
| 20 | */ | ||
| 21 | public function listHooks(): array | ||
| 26 | |||
| 27 | /** | ||
| 28 | * Get single hook | ||
| 29 | * | ||
| 30 | * @link https://developer.github.com/v3/repos/hooks/#get-single-hook | ||
| 31 | * | ||
| 32 | * @param int $id | ||
| 33 | * | ||
| 34 | * @return array | ||
| 35 | */ | ||
| 36 | public function getSingleHook(int $id): array | ||
| 41 | |||
| 42 | /** | ||
| 43 | * Create a hook | ||
| 44 | * | ||
| 45 | * @link https://developer.github.com/v3/repos/hooks/#create-a-hook | ||
| 46 | * | ||
| 47 | * @param string $name | ||
| 48 | * @param string $config | ||
| 49 | * @param array $events | ||
| 50 | * @param bool $active | ||
| 51 | * | ||
| 52 | * @return array | ||
| 53 | */ | ||
| 54 | View Code Duplication | public function createHook(string $name, string $config, array $events = ['push'], bool $active = true): array | |
| 64 | |||
| 65 | /** | ||
| 66 | * Edit a hook | ||
| 67 | * | ||
| 68 | * @link https://developer.github.com/v3/repos/hooks/#edit-a-hook | ||
| 69 | * | ||
| 70 | * @param int $id | ||
| 71 | * @param string $config | ||
| 72 | * @param array $events | ||
| 73 | * @param array $addEvents | ||
| 74 | * @param array $removeEvents | ||
| 75 | * @param bool $active | ||
| 76 | * | ||
| 77 | * @return array | ||
| 78 | */ | ||
| 79 | public function editHook(int $id, string $config, array $events = ['push'], array $addEvents = [], | ||
| 91 | |||
| 92 | /** | ||
| 93 | * Test a push hook | ||
| 94 | * | ||
| 95 | * @link https://developer.github.com/v3/repos/hooks/#test-a-push-hook | ||
| 96 | * | ||
| 97 | * @param int $id | ||
| 98 | * | ||
| 99 | * @return array | ||
| 100 | */ | ||
| 101 | public function testPushHook(int $id): array | ||
| 106 | |||
| 107 | /** | ||
| 108 | * Ping a hook | ||
| 109 | * | ||
| 110 | * @link https://developer.github.com/v3/repos/hooks/#ping-a-hook | ||
| 111 | * | ||
| 112 | * @param int $id | ||
| 113 | * | ||
| 114 | * @return array | ||
| 115 | */ | ||
| 116 | public function pingHook(int $id): array | ||
| 121 | |||
| 122 | /** | ||
| 123 | * Delete a hook | ||
| 124 | * | ||
| 125 | * @link https://developer.github.com/v3/repos/hooks/#delete-a-hook | ||
| 126 | * | ||
| 127 | * @param int $id | ||
| 128 | * | ||
| 129 | * @return array | ||
| 130 | */ | ||
| 131 | public function deleteHook(int $id): array | ||
| 136 | } | 
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.