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 |
||
13 | class HtmlButton extends HtmlSemDoubleElement { |
||
14 | |||
15 | /** |
||
16 | * Constructs an HTML Semantic button |
||
17 | * @param string $identifier HTML id |
||
18 | * @param string $value value of the Button |
||
19 | * @param string $cssStyle btn-default, btn-primary... |
||
20 | * @param string $onClick JS Code for click event |
||
21 | */ |
||
22 | View Code Duplication | public function __construct($identifier, $value="", $cssStyle=null, $onClick=null) { |
|
33 | |||
34 | /** |
||
35 | * Set the button value |
||
36 | * @param string $value |
||
37 | * @return \Ajax\semantic\html\HtmlButton |
||
38 | */ |
||
39 | public function setValue($value) { |
||
43 | |||
44 | /** |
||
45 | * define the button style |
||
46 | * @param string|int $cssStyle |
||
47 | * @return \Ajax\semantic\html\HtmlButton default : "" |
||
48 | */ |
||
49 | public function setStyle($cssStyle) { |
||
52 | |||
53 | public function setFocusable(){ |
||
56 | |||
57 | public function setAnimated($content,$animation=""){ |
||
68 | |||
69 | /** |
||
70 | * @param string|HtmlIcon $icon |
||
71 | * @return \Ajax\semantic\html\elements\HtmlButton |
||
72 | */ |
||
73 | public function asIcon($icon){ |
||
82 | |||
83 | /** |
||
84 | * Add and return a button label |
||
85 | * @param string $caption |
||
86 | * @param string $before |
||
87 | * @return \Ajax\semantic\html\elements\HtmlLabel |
||
88 | */ |
||
89 | public function addLabel($caption,$before=false){ |
||
99 | /* |
||
100 | * (non-PHPdoc) |
||
101 | * @see \Ajax\common\html\BaseHtml::fromArray() |
||
102 | */ |
||
103 | public function fromArray($array) { |
||
110 | |||
111 | /** |
||
112 | * can be formatted to appear on dark backgrounds |
||
113 | * @return \Ajax\semantic\html\elements\HtmlButton |
||
114 | */ |
||
115 | public function setInverted(){ |
||
118 | |||
119 | /** |
||
120 | * show it is currently the active user selection |
||
121 | * @return \Ajax\semantic\html\elements\HtmlButton |
||
122 | */ |
||
123 | public function setActive(){ |
||
126 | |||
127 | /** |
||
128 | * show a loading indicator |
||
129 | * @return \Ajax\semantic\html\elements\HtmlButton |
||
130 | */ |
||
131 | public function asLoader(){ |
||
134 | |||
135 | /** |
||
136 | * hint towards a positive consequence |
||
137 | * @return \Ajax\semantic\html\elements\HtmlButton |
||
138 | */ |
||
139 | public function setPositive(){ |
||
142 | |||
143 | /** |
||
144 | * hint towards a negative consequence |
||
145 | * @return \Ajax\semantic\html\elements\HtmlButton |
||
146 | */ |
||
147 | public function setNegative(){ |
||
150 | |||
151 | /** |
||
152 | * formatted to toggle on/off |
||
153 | * @return \Ajax\semantic\html\elements\HtmlButton |
||
154 | */ |
||
155 | public function setToggle(){ |
||
158 | |||
159 | /** |
||
160 | * @return \Ajax\semantic\html\elements\HtmlButton |
||
161 | */ |
||
162 | public function setCircular(){ |
||
165 | |||
166 | /** |
||
167 | * button is less pronounced |
||
168 | * @return \Ajax\semantic\html\elements\HtmlButton |
||
169 | */ |
||
170 | public function setBasic(){ |
||
173 | } |
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.