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 |
||
15 | View Code Duplication | class StringFormSubmissionField extends FormSubmissionField |
|
|
|||
16 | { |
||
17 | |||
18 | /** |
||
19 | * @ORM\Column(name="sfsf_value", type="string") |
||
20 | */ |
||
21 | protected $value; |
||
22 | |||
23 | /** |
||
24 | * Returns the default form type for this FormSubmissionField |
||
25 | * |
||
26 | * @return string |
||
27 | */ |
||
28 | public function getDefaultAdminType() |
||
32 | |||
33 | /** |
||
34 | * Return a string representation of this FormSubmissionField |
||
35 | * |
||
36 | * @return string |
||
37 | */ |
||
38 | public function __toString() |
||
44 | |||
45 | /** |
||
46 | * Returns the current value of this field |
||
47 | * |
||
48 | * @return string |
||
49 | */ |
||
50 | public function getValue() |
||
54 | |||
55 | /** |
||
56 | * Sets the current value of this field |
||
57 | * |
||
58 | * @param string $value |
||
59 | * |
||
60 | * @return StringFormSubmissionField |
||
61 | */ |
||
62 | public function setValue($value) |
||
68 | } |
||
69 |
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.