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 |
||
| 18 | class HtmlGrid extends HtmlSemCollection{ |
||
| 19 | use TextAlignmentTrait; |
||
| 20 | private $_createCols; |
||
| 21 | private $_colSizing=true; |
||
| 22 | private $_implicitRows=false; |
||
| 23 | public function __construct( $identifier,$numRows=1,$numCols=NULL,$createCols=true,$implicitRows=false){ |
||
| 35 | |||
| 36 | public function setWide($wide){ |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Create $numRows rows |
||
| 44 | * @param int $numRows |
||
| 45 | * @param int $numCols |
||
| 46 | * @return \Ajax\semantic\html\collections\HtmlGrid |
||
| 47 | */ |
||
| 48 | View Code Duplication | public function setNumRows($numRows,$numCols=NULL){ |
|
| 55 | |||
| 56 | public function setNumCols($numCols){ |
||
| 65 | |||
| 66 | /** |
||
| 67 | * return the row at $index |
||
| 68 | * @param int $index |
||
| 69 | * @return \Ajax\semantic\html\collections\HtmlGridRow |
||
| 70 | */ |
||
| 71 | public function getRow($index){ |
||
| 74 | |||
| 75 | /** |
||
| 76 | * @param int $row |
||
| 77 | * @param int $col |
||
| 78 | * @return \Ajax\semantic\html\collections\HtmlGridCol |
||
| 79 | */ |
||
| 80 | public function getCell($row,$col){ |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Adds dividers between columns ($vertically=false) or between rows ($vertically=true) |
||
| 90 | * @param boolean $vertically |
||
| 91 | * @return \Ajax\semantic\html\collections\HtmlGrid |
||
| 92 | */ |
||
| 93 | public function setDivided($vertically=false){ |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Divides rows into cells |
||
| 100 | * @param boolean $internal true for internal cells |
||
| 101 | * @return \Ajax\semantic\html\collections\HtmlGrid |
||
| 102 | */ |
||
| 103 | public function setCelled($internal=false){ |
||
| 107 | |||
| 108 | /** |
||
| 109 | * automatically resize all elements to split the available width evenly |
||
| 110 | * @return \Ajax\semantic\html\collections\HtmlGrid |
||
| 111 | */ |
||
| 112 | public function setEqualWidth(){ |
||
| 115 | |||
| 116 | /** |
||
| 117 | * Adds vertical or/and horizontal gutters |
||
| 118 | * @param string $value |
||
| 119 | * @return \Ajax\semantic\html\collections\HtmlGrid |
||
| 120 | */ |
||
| 121 | public function setPadded($value=NULL){ |
||
| 126 | |||
| 127 | /** |
||
| 128 | * @param boolean $very |
||
| 129 | * @return \Ajax\semantic\html\collections\HtmlGrid |
||
| 130 | */ |
||
| 131 | public function setRelaxed($very=false){ |
||
| 135 | |||
| 136 | public function setVerticalAlignment($value=VerticalAlignment::MIDDLE){ |
||
| 139 | |||
| 140 | /** |
||
| 141 | * {@inheritDoc} |
||
| 142 | * @see \Ajax\common\html\HtmlCollection::createItem() |
||
| 143 | */ |
||
| 144 | protected function createItem($value){ |
||
| 150 | |||
| 151 | public function setValues($values){ |
||
| 164 | |||
| 165 | public function rowCount(){ |
||
| 168 | |||
| 169 | public function colCount(){ |
||
| 176 | |||
| 177 | } |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.