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 | trait ResponseProperties |
||
15 | { |
||
16 | /** |
||
17 | * Phương thức hổ trợ tạo các thuộc tính của đối tượng từ dữ liệu gửi về từ VNPay. |
||
18 | * |
||
19 | * @param string $name |
||
20 | * @return null|string |
||
21 | */ |
||
22 | View Code Duplication | public function __get($name) |
|
34 | |||
35 | /** |
||
36 | * Phương thức hổ trợ bảo vệ các thuộc tính của đối tượng từ dữ liệu gửi về từ VNPay. |
||
37 | * |
||
38 | * @param string $name |
||
39 | * @param mixed $value |
||
40 | * @return null|string |
||
41 | */ |
||
42 | View Code Duplication | public function __set($name, $value) |
|
52 | |||
53 | /** |
||
54 | * Phương thức hổ trợ chuyển đổi property `vpcAbc` thành `vpc_Abc`. |
||
55 | * |
||
56 | * @param string $property |
||
57 | * @return string |
||
58 | */ |
||
59 | private function propertyNormalize(string $property): string |
||
67 | } |
||
68 |
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.