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 | View Code Duplication | 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 | public function search(array $param = []) |
|
32 | |||
33 | /** |
||
34 | * @param int $customerNo |
||
35 | * |
||
36 | * @return Model|ResponseInterface |
||
37 | * |
||
38 | * @throws NotFoundException |
||
39 | * |
||
40 | * @see https://billogram.com/api/documentation#customers_fetch |
||
41 | */ |
||
42 | 1 | public function fetch(int $customerNo) |
|
48 | |||
49 | /** |
||
50 | * @param array $customer |
||
51 | * |
||
52 | * @return Model|ResponseInterface |
||
53 | * |
||
54 | * @throws ValidationException |
||
55 | * |
||
56 | * @see https://billogram.com/api/documentation#customers_create |
||
57 | */ |
||
58 | 1 | public function create(array $customer) |
|
64 | |||
65 | /** |
||
66 | * @param int $customerNo |
||
67 | * @param array $customer |
||
68 | * |
||
69 | * @return Model|ResponseInterface |
||
70 | * |
||
71 | * @throws NotFoundException |
||
72 | * @throws ValidationException |
||
73 | * |
||
74 | * @see https://billogram.com/api/documentation#customers_edit |
||
75 | */ |
||
76 | 1 | public function update(int $customerNo, array $customer) |
|
82 | } |
||
83 |
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.