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 |
||
| 23 | class VerifiedData extends BaseVerifiedData |
||
| 24 | { |
||
| 25 | |||
| 26 | use MagicPropertiesTrait; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @inheritdoc |
||
| 30 | */ |
||
| 31 | 4 | View Code Duplication | public function rules() |
| 39 | |||
| 40 | /** |
||
| 41 | * Phương thức kiểm tra chữ ký dữ liệu nhận từ OnePay. |
||
| 42 | * |
||
| 43 | * @param string $attribute Attribute chứa giá trị chữ ký cần kiểm tra. |
||
| 44 | * @param array $params Mảng các tham trị được thiết lập từ rule. |
||
| 45 | * @param \yii\validators\InlineValidator $validator Đối tượng thực thi kiểm tra. |
||
| 46 | * @throws \yii\base\InvalidConfigException|\yii\base\NotSupportedException |
||
| 47 | */ |
||
| 48 | 4 | public function validateSecureHash($attribute, $params, \yii\validators\InlineValidator $validator) |
|
| 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.