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 |
||
29 | View Code Duplication | class StatsComponent extends ComponentAbstract implements StatsCMPTIF |
|
|
|||
30 | { |
||
31 | |||
32 | protected $dom_attribute; |
||
33 | |||
34 | /** |
||
35 | * Initialize Component |
||
36 | * |
||
37 | * {@inheritdoc} |
||
38 | * |
||
39 | * @return bool |
||
40 | */ |
||
41 | 1 | public function initializeComponent(): bool |
|
47 | |||
48 | /** |
||
49 | * Entity visible |
||
50 | * |
||
51 | * {@inheritdoc} |
||
52 | * |
||
53 | * @param bool $visible |
||
54 | * @return StatsCMPTIF |
||
55 | */ |
||
56 | 1 | public function set(bool $visible = true): StatsCMPTIF |
|
61 | |||
62 | /** |
||
63 | * Does component have DOM Atributes |
||
64 | * |
||
65 | * If compnent is called then we return true |
||
66 | * |
||
67 | * {@inheritdoc} |
||
68 | * |
||
69 | * @return bool |
||
70 | */ |
||
71 | 1 | public function hasDOMAttributes(): bool |
|
75 | |||
76 | /** |
||
77 | * Return DOM attribute contents |
||
78 | * |
||
79 | * Scale Components dom atribute contains roll, pitch, yaw |
||
80 | * Ex: rotation="1 1 1" |
||
81 | * |
||
82 | * @return string |
||
83 | */ |
||
84 | 1 | public function getDomAttributeString(): string |
|
88 | } |
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.