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 Organizations extends AbstractReceiver |
||
| 13 | { |
||
| 14 | |||
| 15 | /** Available sub-Receiver */ |
||
| 16 | const MEMBERS = 'Members'; |
||
| 17 | const TEAMS = 'Teams'; |
||
| 18 | const HOOKS = 'Hooks'; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * List your organizations |
||
| 22 | * |
||
| 23 | * @link https://developer.github.com/v3/orgs/#list-your-organizations |
||
| 24 | * @return array |
||
| 25 | * @throws \Exception |
||
| 26 | */ |
||
| 27 | public function listOrganizations(): array |
||
| 31 | |||
| 32 | /** |
||
| 33 | * List user organizations |
||
| 34 | * |
||
| 35 | * @link https://developer.github.com/v3/orgs/#list-user-organizations |
||
| 36 | * |
||
| 37 | * @param string $username |
||
| 38 | * |
||
| 39 | * @return array |
||
| 40 | * @throws \Exception |
||
| 41 | */ |
||
| 42 | public function listUserOrganizations(string $username): array |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Get an organization |
||
| 49 | * |
||
| 50 | * @link https://developer.github.com/v3/orgs/#get-an-organization |
||
| 51 | * |
||
| 52 | * @param string $org |
||
| 53 | * |
||
| 54 | * @return array |
||
| 55 | * @throws \Exception |
||
| 56 | */ |
||
| 57 | public function get(string $org): array |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Edit an organization |
||
| 64 | * |
||
| 65 | * @link https://developer.github.com/v3/orgs/#edit-an-organization |
||
| 66 | * |
||
| 67 | * @param string $org |
||
| 68 | * @param string $billingEmail |
||
| 69 | * @param string $company |
||
| 70 | * @param string $email |
||
| 71 | * @param string $location |
||
| 72 | * @param string $name |
||
| 73 | * @param string $description |
||
| 74 | * |
||
| 75 | * @return array |
||
| 76 | * @throws \Exception |
||
| 77 | */ |
||
| 78 | View Code Duplication | public function edit(string $org, string $billingEmail = null, string $company = null, string $email = null, |
|
| 90 | } |
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.