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 |
||
27 | class Complaint extends HttpApi |
||
28 | { |
||
29 | use Pagination; |
||
30 | |||
31 | /** |
||
32 | * @param string $domain Domain to get complaints for |
||
33 | * @param int $limit optional |
||
34 | * |
||
35 | * @return IndexResponse |
||
36 | */ |
||
37 | 1 | View Code Duplication | public function index(string $domain, int $limit = 100) |
50 | |||
51 | /** |
||
52 | * @param string $domain Domain to show complaint for |
||
53 | * @param string $address Complaint address |
||
54 | * |
||
55 | * @return ShowResponse |
||
56 | */ |
||
57 | 1 | public function show(string $domain, string $address) |
|
65 | |||
66 | /** |
||
67 | * @param string $domain Domain to create complaint for |
||
68 | * @param string $address Complaint address |
||
69 | * @param string $createdAt (optional) rfc2822 compliant format. (new \DateTime())->format('r') |
||
70 | * |
||
71 | * @return CreateResponse |
||
72 | */ |
||
73 | 1 | View Code Duplication | public function create(string $domain, string $address, string $createdAt = null) |
88 | |||
89 | /** |
||
90 | * @param string $domain Domain to delete complaint for |
||
91 | * @param string $address Complaint address |
||
92 | * |
||
93 | * @return DeleteResponse |
||
94 | */ |
||
95 | 1 | View Code Duplication | public function delete(string $domain, string $address) |
104 | |||
105 | /** |
||
106 | * @param string $domain Domain to delete all bounces for |
||
107 | * |
||
108 | * @return DeleteResponse |
||
109 | */ |
||
110 | 1 | public function deleteAll(string $domain) |
|
118 | } |
||
119 |
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.