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 |
||
26 | View Code Duplication | class DefaultMethods |
|
|
|||
27 | { |
||
28 | /** |
||
29 | * When any rotation component methods are called then init others |
||
30 | * |
||
31 | * @param array $dom_attributes |
||
32 | * @return void |
||
33 | */ |
||
34 | 15 | private function init(array &$dom_attributes) |
|
40 | |||
41 | /** |
||
42 | * Roll, rotation about the X-axis. |
||
43 | * |
||
44 | * @param array $dom_attributes |
||
45 | * @param double $roll |
||
46 | * @return void |
||
47 | */ |
||
48 | 15 | public function roll(array &$dom_attributes, float $roll) |
|
53 | |||
54 | /** |
||
55 | * Pitch, rotation about the Y-axis. |
||
56 | * |
||
57 | * @param array $dom_attributes |
||
58 | * @param double $pitch |
||
59 | * @return void |
||
60 | */ |
||
61 | 14 | public function pitch(array &$dom_attributes, float $pitch) |
|
66 | |||
67 | /** |
||
68 | * Yaw, rotation about the Z-axis. |
||
69 | * |
||
70 | * @param array $dom_attributes |
||
71 | * @param double $yaw |
||
72 | * @return void |
||
73 | */ |
||
74 | 14 | public function yaw(array &$dom_attributes, float $yaw) |
|
79 | } |
||
80 |
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.