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 |
||
13 | View Code Duplication | class EmailFieldType implements FieldTypeInterface |
|
|
|||
14 | { |
||
15 | use FieldTypeImplementationTrait; |
||
16 | |||
17 | /** |
||
18 | * @var |
||
19 | */ |
||
20 | private $value; |
||
21 | |||
22 | /** |
||
23 | * @var string |
||
24 | */ |
||
25 | protected $columnType = "string"; |
||
26 | |||
27 | /** |
||
28 | * The field type name |
||
29 | * @var string |
||
30 | */ |
||
31 | public $name = "Email"; |
||
32 | |||
33 | /** |
||
34 | * get the column type for this field type |
||
35 | * @return string |
||
36 | */ |
||
37 | public function getColumnType() |
||
41 | |||
42 | /** |
||
43 | * Set a value for this field; |
||
44 | * @param $value |
||
45 | */ |
||
46 | public function setValue($value) |
||
50 | |||
51 | |||
52 | /** |
||
53 | * get the value for the field |
||
54 | * @return mixed |
||
55 | */ |
||
56 | public function getValue() |
||
60 | |||
61 | /** |
||
62 | * Get the presenter class if any |
||
63 | * @return mixed |
||
64 | */ |
||
65 | public function present() |
||
69 | |||
70 | /** |
||
71 | * Que the form for the options of the field type |
||
72 | * @return mixed |
||
73 | */ |
||
74 | public function getOptionsForm() |
||
78 | |||
79 | /** |
||
80 | * @return mixed |
||
81 | */ |
||
82 | public function presentFront() |
||
86 | } |
||
87 |
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.