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 |
||
| 16 | class HtmlGridSystem extends HtmlDoubleElement { |
||
| 17 | private $rows; |
||
| 18 | |||
| 19 | public function __construct($identifier,$numRows=1,$numCols=NULL){ |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Add a new row |
||
| 28 | * @param int $numCols |
||
| 29 | * @return \Ajax\bootstrap\html\content\HtmlGridRow |
||
| 30 | */ |
||
| 31 | public function addRow($numCols=NULL){ |
||
| 36 | |||
| 37 | /** |
||
| 38 | * return the row at $index |
||
| 39 | * @param int $index |
||
| 40 | * @param boolean $force add the row at $index if true |
||
| 41 | * @return \Ajax\bootstrap\html\content\HtmlGridRow |
||
| 42 | */ |
||
| 43 | public function getRow($index,$force=true){ |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Create $numRows rows |
||
| 55 | * @param int $numRows |
||
| 56 | * @param int $numCols |
||
| 57 | * @return \Ajax\bootstrap\html\HtmlGridSystem |
||
| 58 | */ |
||
| 59 | public function setNumRows($numRows,$numCols=NULL){ |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @param int $row |
||
| 68 | * @param int $col |
||
| 69 | * @param $force add the cell at $row,$col if true |
||
| 70 | * @return HtmlGridCol |
||
| 71 | */ |
||
| 72 | public function getCell($row,$col,$force=true){ |
||
| 79 | |||
| 80 | /** |
||
| 81 | * @param int $row |
||
| 82 | * @param int $col |
||
| 83 | * @return HtmlGridCol |
||
| 84 | */ |
||
| 85 | public function getCellAt($row,$col,$force=true){ |
||
| 92 | |||
| 93 | public function compile(JsUtils $js=NULL, View $view=NULL) { |
||
| 104 | } |
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.