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 |
||
13 | class Subaccounts extends Client |
||
14 | { |
||
15 | /** |
||
16 | * @var string |
||
17 | */ |
||
18 | protected $namespace = __CLASS__; |
||
19 | |||
20 | /** |
||
21 | * Create a new API Key for this application to access a subaccount |
||
22 | * |
||
23 | * Install this application in a subaccount. |
||
24 | * Note that the API key used in this call must be that of the portal manager account. The application installed in the subaccount will be the same as this one, with the same permissions. |
||
25 | * If this application was already installed in the subaccount, its API key will be replaced by the one created in this call. |
||
26 | * |
||
27 | * @param string $subaccountId |
||
28 | * |
||
29 | * @return $this |
||
30 | */ |
||
31 | View Code Duplication | public function create(string $subaccountId): self |
|
39 | |||
40 | /** |
||
41 | * Delete the API Key for this application from a subaccount |
||
42 | * |
||
43 | * Uninstall this application from a subaccount. |
||
44 | * |
||
45 | * @param string $subaccountId |
||
46 | * @param string $apiKey |
||
47 | * |
||
48 | * @return $this |
||
49 | */ |
||
50 | View Code Duplication | public function delete(string $subaccountId, string $apiKey): self |
|
58 | |||
59 | /** |
||
60 | * List all subaccounts in the portal |
||
61 | * |
||
62 | * Retrieve all the webhooks for this api key |
||
63 | * |
||
64 | * @param int $itemsPerPage |
||
65 | * @param string|null $pageNavigationToken |
||
66 | * @param int $pageNumber |
||
67 | * |
||
68 | * @return $this |
||
69 | */ |
||
70 | public function all(int $itemsPerPage = 100, string $pageNavigationToken = null, int $pageNumber = 1): self |
||
91 | } |
||
92 |
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.