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 Customer extends CustomizableEntity |
|
|
|||
13 | { |
||
14 | /** |
||
15 | * @var string Название покупателя |
||
16 | */ |
||
17 | public $name; |
||
18 | |||
19 | /** |
||
20 | * @var string Дата и время следующей покупки |
||
21 | */ |
||
22 | public $next_date; |
||
23 | |||
24 | /** |
||
25 | * @var integer id пользователя создавшего покупателя |
||
26 | */ |
||
27 | public $created_by; |
||
28 | |||
29 | /** |
||
30 | * @var integer Ожидаемая сумма |
||
31 | */ |
||
32 | public $next_price; |
||
33 | |||
34 | /** |
||
35 | * @var integer Периодичность совершаемых покупок |
||
36 | */ |
||
37 | public $periodicity; |
||
38 | |||
39 | /** |
||
40 | * @var string Если вы хотите задать новые теги, перечислите их внутри строковой переменной через запятую |
||
41 | */ |
||
42 | public $tags; |
||
43 | |||
44 | /** |
||
45 | * @var integer id периода цифровой воронки покупателя |
||
46 | */ |
||
47 | public $period_id; |
||
48 | |||
49 | /** |
||
50 | * @var array |
||
51 | */ |
||
52 | protected $fieldList = [ |
||
53 | 'id', 'name', 'next_date', 'created_at', 'updated_at', |
||
54 | 'responsible_user_id', 'created_by', 'next_price', |
||
55 | 'periodicity', 'tags', 'period_id', 'contacts_id', 'company_id' |
||
56 | ]; |
||
57 | |||
58 | use CompanyLinkable, |
||
59 | ContactsLinkable; |
||
60 | } |
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.