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 |
||
10 | trait BaseTrait { |
||
11 | protected $_variations=[ ]; |
||
12 | protected $_states=[ ]; |
||
13 | protected $_baseClass; |
||
14 | |||
15 | protected abstract function setPropertyCtrl($name, $value, $typeCtrl); |
||
16 | |||
17 | protected abstract function addToPropertyCtrl($name, $value, $typeCtrl); |
||
18 | |||
19 | protected abstract function addToPropertyCtrlCheck($name, $value, $typeCtrl); |
||
20 | |||
21 | public abstract function addToProperty($name, $value, $separator=" "); |
||
22 | |||
23 | public function addVariation($variation) { |
||
26 | |||
27 | public function addState($state) { |
||
30 | |||
31 | public function setVariation($variation) { |
||
35 | |||
36 | View Code Duplication | public function setVariations($variations) { |
|
45 | |||
46 | public function setState($state) { |
||
50 | |||
51 | public function addVariations($variations=array()) { |
||
59 | |||
60 | public function addStates($states=array()) { |
||
68 | |||
69 | View Code Duplication | public function setStates($states) { |
|
78 | |||
79 | public function addIcon($icon, $before=true) { |
||
82 | |||
83 | /** |
||
84 | * |
||
85 | * {@inheritDoc} |
||
86 | * |
||
87 | * @see \Ajax\common\html\HtmlSingleElement::setSize() |
||
88 | */ |
||
89 | public function setSize($size) { |
||
92 | |||
93 | /** |
||
94 | * show it is currently unable to be interacted with |
||
95 | * @return \Ajax\semantic\html\elements\HtmlSemDoubleElement |
||
96 | */ |
||
97 | public function setDisabled() { |
||
100 | |||
101 | /** |
||
102 | * |
||
103 | * @param string $color |
||
104 | * @return \Ajax\semantic\html\base\HtmlSemDoubleElement |
||
105 | */ |
||
106 | public function setColor($color) { |
||
109 | |||
110 | /** |
||
111 | * |
||
112 | * @return \Ajax\semantic\html\base\HtmlSemDoubleElement |
||
113 | */ |
||
114 | public function setFluid() { |
||
117 | |||
118 | /** |
||
119 | * show it is currently the active user selection |
||
120 | * @return \Ajax\semantic\html\base\HtmlSemDoubleElement |
||
121 | */ |
||
122 | public function setActive($value=true){ |
||
125 | |||
126 | /** |
||
127 | * can be formatted to appear on dark backgrounds |
||
128 | */ |
||
129 | public function setInverted() { |
||
132 | |||
133 | public function setCircular() { |
||
136 | |||
137 | public function setFloated($direction="right") { |
||
140 | |||
141 | public function floatRight() { |
||
144 | |||
145 | public function floatLeft() { |
||
148 | |||
149 | public function getBaseClass() { |
||
152 | } |
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.