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 |
||
36 | View Code Duplication | class ScaleComponent extends ComponentAbstract implements ScaleInterface |
|
|
|||
37 | { |
||
38 | use ComponentHelper; |
||
39 | |||
40 | /** |
||
41 | * Initialize Component |
||
42 | * |
||
43 | * {@inheritdoc} |
||
44 | * |
||
45 | * @return bool |
||
46 | */ |
||
47 | 58 | public function initializeComponent(): bool |
|
52 | |||
53 | /** |
||
54 | * Return DOM attribute contents |
||
55 | * |
||
56 | * @return string |
||
57 | */ |
||
58 | 4 | public function getDomAttributeString(): string |
|
63 | |||
64 | /** |
||
65 | * Get scale |
||
66 | * |
||
67 | * {@inheritdoc} |
||
68 | * |
||
69 | * @return string |
||
70 | */ |
||
71 | 1 | public function getScale(): string |
|
75 | } |
||
76 |
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.