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 |
||
15 | trait BaseTrait { |
||
16 | protected $_variations=[ ]; |
||
17 | protected $_states=[ ]; |
||
18 | protected $_baseClass; |
||
19 | |||
20 | abstract protected function setPropertyCtrl($name, $value, $typeCtrl); |
||
21 | |||
22 | abstract protected function addToPropertyCtrl($name, $value, $typeCtrl); |
||
23 | |||
24 | abstract protected function addToPropertyCtrlCheck($name, $value, $typeCtrl); |
||
25 | |||
26 | abstract public function addToProperty($name, $value, $separator=" "); |
||
27 | |||
28 | abstract public function setProperty($name, $value); |
||
29 | |||
30 | abstract public function addContent($content,$before=false); |
||
31 | |||
32 | abstract public function onCreate($jsCode); |
||
33 | |||
34 | public function addVariation($variation) { |
||
37 | |||
38 | public function addState($state) { |
||
41 | |||
42 | public function setVariation($variation) { |
||
46 | |||
47 | View Code Duplication | public function setVariations($variations) { |
|
56 | |||
57 | public function setState($state) { |
||
61 | |||
62 | public function addVariations($variations=array()) { |
||
70 | |||
71 | public function addStates($states=array()) { |
||
79 | |||
80 | View Code Duplication | public function setStates($states) { |
|
89 | |||
90 | public function addIcon($icon, $before=true) { |
||
93 | |||
94 | public function addSticky($context="body"){ |
||
98 | |||
99 | /** |
||
100 | * |
||
101 | * {@inheritDoc} |
||
102 | * |
||
103 | * @see \Ajax\common\html\HtmlSingleElement::setSize() |
||
104 | */ |
||
105 | public function setSize($size) { |
||
108 | |||
109 | /** |
||
110 | * show it is currently unable to be interacted with |
||
111 | * @param boolean $disable |
||
112 | * @return \Ajax\semantic\html\elements\HtmlSemDoubleElement |
||
113 | */ |
||
114 | public function setDisabled($disable=true) { |
||
119 | |||
120 | /** |
||
121 | * |
||
122 | * @param string $color |
||
123 | * @return \Ajax\semantic\html\base\HtmlSemDoubleElement |
||
124 | */ |
||
125 | public function setColor($color) { |
||
128 | |||
129 | /** |
||
130 | * |
||
131 | * @return \Ajax\semantic\html\base\HtmlSemDoubleElement |
||
132 | */ |
||
133 | public function setFluid() { |
||
136 | |||
137 | /** |
||
138 | * |
||
139 | * @return \Ajax\semantic\html\base\HtmlSemDoubleElement |
||
140 | */ |
||
141 | public function asHeader(){ |
||
144 | |||
145 | /** |
||
146 | * show it is currently the active user selection |
||
147 | * @return \Ajax\semantic\html\base\HtmlSemDoubleElement |
||
148 | */ |
||
149 | public function setActive($value=true){ |
||
154 | |||
155 | public function setAttached($value=true){ |
||
160 | |||
161 | /** |
||
162 | * can be formatted to appear on dark backgrounds |
||
163 | */ |
||
164 | public function setInverted() { |
||
167 | |||
168 | public function setCircular() { |
||
171 | |||
172 | public function setFloated($direction="right") { |
||
175 | |||
176 | public function floatRight() { |
||
179 | |||
180 | public function floatLeft() { |
||
183 | |||
184 | public function getBaseClass() { |
||
187 | |||
188 | protected function addBehavior(&$array,$key,$value,$before="",$after=""){ |
||
199 | } |
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.