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 TextArea extends FieldAbstract |
|
|
|||
16 | { |
||
17 | /** |
||
18 | * @return string |
||
19 | */ |
||
20 | 1 | public function getTag() |
|
24 | |||
25 | |||
26 | 1 | public function init() |
|
36 | |||
37 | /** |
||
38 | * @return string |
||
39 | */ |
||
40 | 1 | public function getPlaceholder() |
|
41 | { |
||
42 | 1 | return $this->getAttribute('placeholder'); |
|
43 | } |
||
44 | |||
45 | /** |
||
46 | * @param string $placeholder |
||
47 | */ |
||
48 | 1 | public function setPlaceholder($placeholder) |
|
52 | } |
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.