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 |
||
16 | class Customer extends HttpApi |
||
17 | { |
||
18 | /** |
||
19 | * @param array $param |
||
20 | * |
||
21 | * @return CustomerCollection|ResponseInterface |
||
22 | * |
||
23 | * @see https://billogram.com/api/documentation#customers_list |
||
24 | */ |
||
25 | 1 | View Code Duplication | public function search(array $param = []) |
38 | |||
39 | /** |
||
40 | * @param int $customerNo |
||
41 | * |
||
42 | * @return Model|ResponseInterface |
||
43 | * |
||
44 | * @throws NotFoundException |
||
45 | * |
||
46 | * @see https://billogram.com/api/documentation#customers_fetch |
||
47 | */ |
||
48 | 2 | View Code Duplication | public function fetch(int $customerNo) |
61 | |||
62 | /** |
||
63 | * @param array $customer |
||
64 | * |
||
65 | * @return Model|ResponseInterface |
||
66 | * |
||
67 | * @throws ValidationException |
||
68 | * |
||
69 | * @see https://billogram.com/api/documentation#customers_create |
||
70 | */ |
||
71 | 1 | View Code Duplication | public function create(array $customer) |
84 | |||
85 | /** |
||
86 | * @param int $customerNo |
||
87 | * @param array $customer |
||
88 | * |
||
89 | * @return Model|ResponseInterface |
||
90 | * |
||
91 | * @throws NotFoundException |
||
92 | * @throws ValidationException |
||
93 | * |
||
94 | * @see https://billogram.com/api/documentation#customers_edit |
||
95 | */ |
||
96 | 1 | View Code Duplication | public function update(int $customerNo, array $customer) |
109 | } |
||
110 |
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.