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 HtmlGridRow extends HtmlCollection{ |
||
17 | |||
18 | private $_colSize; |
||
19 | public function __construct( $identifier,$numCols=NULL,$colSizing=false){ |
||
35 | |||
36 | /** |
||
37 | * Defines the row width |
||
38 | * @param int $width |
||
39 | * @return \Ajax\semantic\html\content\HtmlGridRow |
||
40 | */ |
||
41 | View Code Duplication | public function setWidth($width){ |
|
48 | |||
49 | /** |
||
50 | * return the col at $index |
||
51 | * @param int $index |
||
52 | * @return \Ajax\semantic\html\collections\HtmlGridCol |
||
53 | */ |
||
54 | public function getCol($index){ |
||
57 | |||
58 | /** |
||
59 | * stretch the row contents to take up the entire column height |
||
60 | * @return \Ajax\semantic\html\content\HtmlGridRow |
||
61 | */ |
||
62 | public function setStretched(){ |
||
65 | |||
66 | /** |
||
67 | * @param string $color |
||
68 | * @return \Ajax\semantic\html\content\HtmlGridRow |
||
69 | */ |
||
70 | public function setColor($color){ |
||
73 | |||
74 | public function setTextAlignment($value=TextAlignment::LEFT){ |
||
77 | |||
78 | /** |
||
79 | * {@inheritDoc} |
||
80 | * @see \Ajax\common\html\HtmlCollection::createItem() |
||
81 | */ |
||
82 | protected function createItem($value){ |
||
86 | } |
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.