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 |
||
14 | class Customer extends Client |
||
15 | { |
||
16 | /** |
||
17 | * @param string $customerEmail |
||
18 | * |
||
19 | * @return array |
||
20 | */ |
||
21 | View Code Duplication | public function getListCustomersByEmail(string $customerEmail): array |
|
40 | |||
41 | /** |
||
42 | * @param string $customerEmail |
||
43 | * |
||
44 | * @return array |
||
45 | */ |
||
46 | public function getCustomerByEmail(string $customerEmail): array |
||
56 | |||
57 | /** |
||
58 | * @param string $customerId The customer's id |
||
59 | * |
||
60 | * @throws \Exception |
||
61 | * |
||
62 | * @return array |
||
63 | */ |
||
64 | View Code Duplication | public function getCustomerById(string $customerId): array |
|
82 | |||
83 | /** |
||
84 | * @param string $customerId The customer's id |
||
85 | * @param array $data |
||
86 | * |
||
87 | * @throws \Exception |
||
88 | * |
||
89 | * @return array|bool |
||
90 | */ |
||
91 | View Code Duplication | public function updateCustomer(string $customerId, array $data) |
|
107 | |||
108 | /** |
||
109 | * @param array $customer |
||
110 | */ |
||
111 | private function deleteCustomerCache(array $customer) |
||
119 | |||
120 | /** |
||
121 | * @param array $data |
||
122 | * |
||
123 | * @throws \Exception |
||
124 | * |
||
125 | * @return array|bool |
||
126 | */ |
||
127 | View Code Duplication | public function createCustomer(array $data) |
|
141 | } |
||
142 |
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.