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 HtmlDoubleElement { |
||
| 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 | View Code Duplication | public function addIcon($icon,$before=true){ |
|
| 76 | |||
| 77 | /* |
||
| 78 | * (non-PHPdoc) |
||
| 79 | * @see \Ajax\common\html\BaseHtml::fromArray() |
||
| 80 | */ |
||
| 81 | public function fromArray($array) { |
||
| 88 | } |
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.