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 |
||
30 | class Whitelist extends HttpApi |
||
31 | { |
||
32 | use Pagination; |
||
33 | |||
34 | /** |
||
35 | * @param string $domain Domain to get whitelist for |
||
36 | * @param int $limit optional |
||
37 | * |
||
38 | * @return IndexResponse |
||
39 | */ |
||
40 | View Code Duplication | public function index(string $domain, int $limit = 100) |
|
53 | |||
54 | /** |
||
55 | * @param string $domain Domain to show whitelist for |
||
56 | * @param string $address whitelist address |
||
57 | * |
||
58 | * @return ShowResponse |
||
59 | */ |
||
60 | public function show(string $domain, string $address) |
||
69 | |||
70 | /** |
||
71 | * @param string $domain Domain to create whitelist for |
||
72 | * @param string $address whitelist email address or domain name |
||
73 | * |
||
74 | * @return CreateResponse |
||
75 | */ |
||
76 | public function create(string $domain, string $address) |
||
95 | |||
96 | /** |
||
97 | * @param string $domain Domain to create whitelist for |
||
98 | * @param string $filePath csv file path |
||
99 | * |
||
100 | * @return ImportResponse |
||
101 | */ |
||
102 | public function import(string $domain, string $filePath) |
||
118 | |||
119 | /** |
||
120 | * @param string $domain Domain to delete whitelist for |
||
121 | * @param string $address whitelist address |
||
122 | * |
||
123 | * @return DeleteResponse |
||
124 | */ |
||
125 | View Code Duplication | public function delete(string $domain, string $address) |
|
134 | |||
135 | /** |
||
136 | * @param string $domain Domain to delete all whitelists for |
||
137 | * |
||
138 | * @return DeleteAllResponse |
||
139 | */ |
||
140 | public function deleteAll(string $domain) |
||
148 | } |
||
149 |
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.