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 | class Textarea extends Common |
||
32 | { |
||
33 | /** |
||
34 | * the label of element |
||
35 | * |
||
36 | * @access private |
||
37 | * @var string |
||
38 | */ |
||
39 | private $_sLabel = null; |
||
40 | |||
41 | /** |
||
42 | * the value of element |
||
43 | * |
||
44 | * @access private |
||
45 | * @var string |
||
46 | */ |
||
47 | private $_sValue = null; |
||
48 | |||
49 | /** |
||
50 | * constructor that it increment (static) for all use |
||
51 | * |
||
52 | * @access public |
||
53 | * @param string $sName name |
||
54 | * @param string $sLabel label of textarea |
||
55 | * @param string $sValue value of textarea |
||
56 | * @return \Venus\lib\Form\Textarea |
||
|
|||
57 | */ |
||
58 | View Code Duplication | public function __construct(string $sName, string $sLabel = null, string $sValue = null) |
|
66 | |||
67 | /** |
||
68 | * get the Value |
||
69 | * |
||
70 | * @access public |
||
71 | * @return string |
||
72 | */ |
||
73 | public function getValue() : string |
||
77 | |||
78 | /** |
||
79 | * set the Value |
||
80 | * |
||
81 | * @access public |
||
82 | * @param string $sValue Value of input; |
||
83 | * @return \Venus\lib\Form\Textarea |
||
84 | */ |
||
85 | public function setValue(string $sValue) : Textarea |
||
90 | |||
91 | /** |
||
92 | * get the Label |
||
93 | * |
||
94 | * @access public |
||
95 | * @return string |
||
96 | */ |
||
97 | public function getLabel() : string |
||
101 | |||
102 | /** |
||
103 | * set the Label |
||
104 | * |
||
105 | * @access public |
||
106 | * @param string $sLabel Label of input; |
||
107 | * @return \Venus\lib\Form\Textarea |
||
108 | */ |
||
109 | public function setLabel(string $sLabel) : Textarea |
||
114 | |||
115 | /** |
||
116 | * if the button is clicked |
||
117 | * |
||
118 | * @access public |
||
119 | * @param string $sType type of input; |
||
120 | * @return bool |
||
121 | */ |
||
122 | public function isClicked(string $sType) : bool |
||
131 | |||
132 | /** |
||
133 | * get the <html> |
||
134 | * |
||
135 | * @access public |
||
136 | * @return string |
||
137 | */ |
||
138 | public function fetch() : string |
||
155 | } |
||
156 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.