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 |
||
11 | class HtmlProgressbar extends HtmlBsDoubleElement { |
||
12 | protected $value; |
||
13 | protected $max; |
||
14 | protected $min; |
||
15 | protected $striped=""; |
||
16 | protected $active; |
||
17 | protected $caption; |
||
18 | protected $stacked=false; |
||
19 | protected $style=""; |
||
20 | protected $styleLimits=null; |
||
21 | |||
22 | public function __construct($identifier, $style="info", $value=0, $max=100, $min=0) { |
||
30 | |||
31 | View Code Duplication | public function setActive($value) { |
|
44 | |||
45 | public function setStriped($value) { |
||
58 | |||
59 | View Code Duplication | public function showCaption($value) { |
|
72 | |||
73 | public function getValue() { |
||
76 | |||
77 | public function stack(HtmlProgressbar $progressBar) { |
||
88 | |||
89 | public function setValue($value) { |
||
93 | |||
94 | public function getMax() { |
||
97 | |||
98 | public function setMax($max) { |
||
102 | |||
103 | public function getMin() { |
||
106 | |||
107 | public function setMin($min) { |
||
111 | |||
112 | public function getStacked() { |
||
113 | return $this->stacked; |
||
114 | } |
||
115 | |||
116 | public function setStacked($stacked) { |
||
117 | $this->stacked=$stacked; |
||
118 | return $this; |
||
119 | } |
||
120 | |||
121 | /** |
||
122 | * define the progressbar style |
||
123 | * avaible values : "success","info","warning","danger" |
||
124 | * @param string|int $cssStyle |
||
125 | * @return \Ajax\bootstrap\html\HtmlProgressbar default : "" |
||
126 | */ |
||
127 | public function setStyle($cssStyle) { |
||
130 | |||
131 | /* |
||
132 | * (non-PHPdoc) |
||
133 | * @see \Ajax\bootstrap\html\base\BaseHtml::compile() |
||
134 | */ |
||
135 | public function compile(JsUtils $js=NULL, &$view=NULL) { |
||
151 | |||
152 | public function isStriped() { |
||
155 | |||
156 | public function isActive() { |
||
159 | |||
160 | /* (non-PHPdoc) |
||
161 | * @see \Ajax\bootstrap\html\base\BaseHtml::fromDatabaseObject() |
||
162 | */ |
||
163 | public function fromDatabaseObject($object, $function) { |
||
166 | |||
167 | public function getStyleLimits() { |
||
170 | |||
171 | /** |
||
172 | * Permet de modifier le style de la progressbar à partir de sa valeur actuelle |
||
173 | * $styleLimits est de la forme ["success"=>50, "warning"=>100] pour obtenir un style success de 0 à 50 et warning de 50 à 100 |
||
174 | * @param array $styleLimits tableau associatif des couples style=>valeur possibles |
||
175 | * @return \Ajax\bootstrap\html\HtmlProgressbar |
||
176 | */ |
||
177 | public function setStyleLimits($styleLimits) { |
||
181 | |||
182 | } |
||
183 |
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.