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 |
||
12 | View Code Duplication | class Contact extends CustomizableEntity |
|
|
|||
13 | { |
||
14 | /** |
||
15 | * @var string Название контакта |
||
16 | */ |
||
17 | public $name; |
||
18 | |||
19 | /** |
||
20 | * @var integer id пользователя создавшего контакт |
||
21 | */ |
||
22 | public $created_by; |
||
23 | |||
24 | /** |
||
25 | * @var string Название новой компании. Параметр указывается для создания новой компании и привязке к ней контакта. Для привязки контакта к уже существующей компании, необходимо использовать параметр company_id |
||
26 | */ |
||
27 | public $company_name; |
||
28 | |||
29 | /** |
||
30 | * @var string Теги, привязываемые к контакту. Задаются целостной строковой переменной, внутри строки перечисляются через запятую |
||
31 | */ |
||
32 | public $tags; |
||
33 | |||
34 | /** |
||
35 | * @var string Покупатели, привязываемые к контакту. Перечисляются через запятую. |
||
36 | */ |
||
37 | public $customers_id; |
||
38 | |||
39 | use CompanyLinkable, |
||
40 | LeadsLinkable; |
||
41 | |||
42 | /** |
||
43 | * @var array |
||
44 | */ |
||
45 | protected $fieldList = [ |
||
46 | 'id', 'name', 'created_at', 'updated_at', |
||
47 | 'responsible_user_id', 'created_by', 'company_name', |
||
48 | 'tags', 'leads_id', 'customers_id', 'company_id', |
||
49 | ]; |
||
50 | } |
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.