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 |
||
18 | class HmacDataSignature extends DataSignature |
||
19 | { |
||
20 | |||
21 | /** |
||
22 | * Tên loại mã hóa. Ví dụ: md5, sha1, sha256... |
||
23 | * |
||
24 | * @var string |
||
25 | */ |
||
26 | public $hmacAlgo; |
||
27 | |||
28 | /** |
||
29 | * Khóa mã hóa. Độ phức tạp càng cao thì dữ liệu càng được an toàn. |
||
30 | * |
||
31 | * @var string |
||
32 | */ |
||
33 | public $key; |
||
34 | |||
35 | /** |
||
36 | * @var bool phân biệt ký tự hoa thường khi xác minh chữ ký. |
||
37 | * @since 1.0.3 |
||
38 | */ |
||
39 | public $caseSensitive = true; |
||
40 | |||
41 | /** |
||
42 | * @inheritdoc |
||
43 | * @throws InvalidConfigException |
||
44 | */ |
||
45 | 6 | public function init() |
|
55 | |||
56 | /** |
||
57 | * @inheritdoc |
||
58 | */ |
||
59 | 6 | public function generate(): string |
|
63 | |||
64 | /** |
||
65 | * @inheritdoc |
||
66 | * @throws InvalidConfigException |
||
67 | */ |
||
68 | 1 | View Code Duplication | public function validate(string $expect): bool |
78 | |||
79 | } |
||
80 |
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.