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 |
||
31 | View Code Duplication | class Radio extends Common |
|
|
|||
32 | { |
||
33 | /** |
||
34 | * the name of element |
||
35 | * |
||
36 | * @access private |
||
37 | * @var string |
||
38 | */ |
||
39 | private $_sType = null; |
||
40 | |||
41 | /** |
||
42 | * the label of element |
||
43 | * |
||
44 | * @access private |
||
45 | * @var string |
||
46 | */ |
||
47 | private $_sLabel = null; |
||
48 | |||
49 | /** |
||
50 | * the value of element |
||
51 | * |
||
52 | * @access private |
||
53 | * @var string |
||
54 | */ |
||
55 | private $_sValue = null; |
||
56 | |||
57 | /** |
||
58 | * the value of the checked element |
||
59 | * |
||
60 | * @access private |
||
61 | * @var string |
||
62 | */ |
||
63 | private $_sValueChecked = null; |
||
64 | |||
65 | /** |
||
66 | * constructor that it increment (static) for all use |
||
67 | * |
||
68 | * @access public |
||
69 | * @param string $sName name |
||
70 | * @param string $sLabel label of radio |
||
71 | * @param string $sValue value of radio |
||
72 | * @param string $sValueChecked value checked of radio |
||
73 | * @return \Venus\lib\Form\Input |
||
74 | */ |
||
75 | public function __construct(string $sName, string $sLabel, string $sValue, string $sValueChecked = null) |
||
82 | |||
83 | /** |
||
84 | * get the Value |
||
85 | * |
||
86 | * @access public |
||
87 | * @return string |
||
88 | */ |
||
89 | public function getValue() : string |
||
93 | |||
94 | /** |
||
95 | * set the Value |
||
96 | * |
||
97 | * @access public |
||
98 | * @param string $sValue Value of input; |
||
99 | * @return Radio |
||
100 | */ |
||
101 | public function setValue(string $sValue) : Radio |
||
106 | |||
107 | /** |
||
108 | * get the Value Checked |
||
109 | * |
||
110 | * @access public |
||
111 | * @return string |
||
112 | */ |
||
113 | public function getValueChecked() : string |
||
117 | |||
118 | /** |
||
119 | * set the Value Checked |
||
120 | * |
||
121 | * @access public |
||
122 | * @param string $sValueChecked Value of input; |
||
123 | * @return Radio |
||
124 | */ |
||
125 | public function setValueChecked(string $sValueChecked) : Radio |
||
130 | |||
131 | /** |
||
132 | * get the Label |
||
133 | * |
||
134 | * @access public |
||
135 | * @return string |
||
136 | */ |
||
137 | public function getLabel() : string |
||
141 | |||
142 | /** |
||
143 | * set the Label |
||
144 | * |
||
145 | * @access public |
||
146 | * @param string $sLabel Label of input; |
||
147 | * @return Radio |
||
148 | */ |
||
149 | public function setLabel(string $sLabel) : Radio |
||
154 | |||
155 | /** |
||
156 | * if the button is clicked |
||
157 | * |
||
158 | * @access public |
||
159 | * @param string $sType type of input; |
||
160 | * @return bool |
||
161 | */ |
||
162 | public function isClicked(string $sType) : bool |
||
171 | |||
172 | /** |
||
173 | * get the <html> |
||
174 | * |
||
175 | * @access public |
||
176 | * @return string |
||
177 | */ |
||
178 | public function fetch() : string |
||
188 | } |
||
189 |
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.