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 |
||
33 | View Code Duplication | class ContactPostApiModel extends iDokladAbstractModel |
|
|
|||
34 | { |
||
35 | public $City; |
||
36 | |||
37 | /** |
||
38 | * @Assert\NotBlank() |
||
39 | * @Assert\Length(min="0", max="200") |
||
40 | */ |
||
41 | public $CompanyName; |
||
42 | |||
43 | /** |
||
44 | * @Assert\NotBlank() |
||
45 | */ |
||
46 | public $CountryId; |
||
47 | |||
48 | /** |
||
49 | * @var BankAccountPostApiModel |
||
50 | */ |
||
51 | public $DefaultBankAccount; |
||
52 | |||
53 | public $DiscountPercentage; |
||
54 | |||
55 | public $Email; |
||
56 | |||
57 | public $Fax; |
||
58 | |||
59 | public $Firstname; |
||
60 | |||
61 | public $IdentificationNumber; |
||
62 | |||
63 | /** |
||
64 | * @Assert\Expression(expression="value == true or value == false", message="This value must be true or false.") |
||
65 | */ |
||
66 | public $IsRegisteredForVatOnPay; |
||
67 | |||
68 | /** |
||
69 | * @Assert\Expression(expression="value == true or value == false", message="This value must be true or false.") |
||
70 | */ |
||
71 | public $IsSendReminder; |
||
72 | |||
73 | public $Mobile; |
||
74 | |||
75 | public $Phone; |
||
76 | |||
77 | public $PostalCode; |
||
78 | |||
79 | public $Street; |
||
80 | |||
81 | public $Surname; |
||
82 | |||
83 | public $Title; |
||
84 | |||
85 | public $VatIdentificationNumber; |
||
86 | |||
87 | public $VatIdentificationNumberSk; |
||
88 | |||
89 | public $Www; |
||
90 | |||
91 | /** |
||
92 | * @return array |
||
93 | */ |
||
94 | public static function getModelMap(): array |
||
100 | } |
||
101 |
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.