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 |
||
8 | class FormElementFileMultiple extends FormElement |
||
9 | { |
||
10 | /** |
||
11 | * Constructor |
||
12 | * |
||
13 | * @param string $name of the element. |
||
14 | * @param array $attributes to set to the element. Default is an empty array. |
||
15 | */ |
||
16 | public function __construct($name, $attributes = []) |
||
22 | |||
23 | |||
24 | |||
25 | /** |
||
26 | * Get HTML code for a element. |
||
27 | * |
||
28 | * @return string HTML code for the element. |
||
29 | * |
||
30 | * @SuppressWarnings(PHPMD.UnusedLocalVariable) |
||
31 | */ |
||
32 | View Code Duplication | public function getHTML() |
|
46 | } |
||
47 |
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.