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 |
||
21 | class Key extends HttpApi |
||
22 | { |
||
23 | /** |
||
24 | * Create a new key. |
||
25 | * |
||
26 | * @param string $projectKey |
||
27 | * @param string $name |
||
28 | * @param array $params |
||
29 | * |
||
30 | * @throws DomainException |
||
31 | * @throws ClientExceptionInterface |
||
32 | * |
||
33 | * @return KeyCreated|ResponseInterface |
||
34 | */ |
||
35 | View Code Duplication | public function create(string $projectKey, string $name, array $params = []) |
|
51 | |||
52 | /** |
||
53 | * Search keys. |
||
54 | * |
||
55 | * @param string $projectKey |
||
56 | * @param array $params |
||
57 | * |
||
58 | * @throws ClientExceptionInterface |
||
59 | * @throws DomainException |
||
60 | * |
||
61 | * @return KeySearchResults|ResponseInterface |
||
62 | */ |
||
63 | public function search(string $projectKey, array $params = []) |
||
95 | |||
96 | /** |
||
97 | * Delete a key. |
||
98 | * |
||
99 | * @param string $projectKey |
||
100 | * @param string $keyId |
||
101 | * |
||
102 | * @throws ClientExceptionInterface |
||
103 | * @throws DomainException |
||
104 | * |
||
105 | * @return bool|ResponseInterface |
||
106 | */ |
||
107 | public function delete(string $projectKey, string $keyId) |
||
121 | } |
||
122 |
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.