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 |
||
30 | View Code Duplication | class ScaleComponent extends ComponentAbstract implements ScaleCMPTIF |
|
|
|||
31 | { |
||
32 | use ComponentHelper; |
||
33 | |||
34 | /** |
||
35 | * Initialize Scale Component |
||
36 | * |
||
37 | * The scale component defines a shrinking, stretching, or skewing transformation of an entity. |
||
38 | * It takes three scaling factors for the X, Y, and Z axes. |
||
39 | * |
||
40 | * Scale compnent dom attribute is scale |
||
41 | * |
||
42 | * {@inheritdoc} |
||
43 | * |
||
44 | * @return bool |
||
45 | */ |
||
46 | 67 | public function initializeComponent(): bool |
|
51 | |||
52 | /** |
||
53 | * Scaling factor in the X direction. |
||
54 | * |
||
55 | * {@inheritdoc} |
||
56 | * |
||
57 | * @param double $scale_x |
||
58 | * @return void |
||
59 | */ |
||
60 | 10 | public function scaleX(float $scale_x) |
|
65 | |||
66 | /** |
||
67 | * Scaling factor in the Y direction.. |
||
68 | * |
||
69 | * {@inheritdoc} |
||
70 | * |
||
71 | * @param double $scale_y |
||
72 | * @return void |
||
73 | */ |
||
74 | 9 | public function scaleY(float $scale_y) |
|
79 | |||
80 | /** |
||
81 | * Scaling factor in the Z direction. |
||
82 | * |
||
83 | * {@inheritdoc} |
||
84 | * |
||
85 | * @param double $scale_z |
||
86 | * @return void |
||
87 | */ |
||
88 | 9 | public function scaleZ(float $scale_z) |
|
93 | |||
94 | /** |
||
95 | * Get scale |
||
96 | * |
||
97 | * {@inheritdoc} |
||
98 | * |
||
99 | * @return string |
||
100 | */ |
||
101 | 1 | public function getScale(): string |
|
105 | |||
106 | /** |
||
107 | * Return DOM attribute contents |
||
108 | * |
||
109 | * Scale Components dom atribute contains coordinates |
||
110 | * Ex: scale="1 1 1" |
||
111 | * |
||
112 | * {@inheritdoc} |
||
113 | * |
||
114 | * @return string |
||
115 | */ |
||
116 | 4 | public function getDomAttributeString(): string |
|
121 | |||
122 | /** |
||
123 | * When any scale component methods are called then init others |
||
124 | * |
||
125 | * @param array $dom_attributes |
||
126 | * @return void |
||
127 | */ |
||
128 | 10 | private function setValues() |
|
134 | |||
135 | } |
||
136 |
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.