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 |
||
15 | class HtmlTR extends HtmlSemCollection { |
||
16 | use TableElementTrait; |
||
17 | private $_tdTagName; |
||
18 | private $_container; |
||
19 | private $_row; |
||
20 | |||
21 | public function __construct($identifier) { |
||
25 | |||
26 | public function setColCount($colCount) { |
||
34 | |||
35 | public function getColCount(){ |
||
38 | |||
39 | /** |
||
40 | * |
||
41 | * {@inheritDoc} |
||
42 | * |
||
43 | * @see \Ajax\common\html\HtmlCollection::createItem() |
||
44 | */ |
||
45 | protected function createItem($value) { |
||
51 | |||
52 | public function setTdTagName($tagName="td") { |
||
55 | |||
56 | /** |
||
57 | * Define the container (HtmlTableContent) and the num of the row |
||
58 | * @param HtmlTableContent $container |
||
59 | * @param int $row |
||
60 | */ |
||
61 | public function setContainer($container, $row) { |
||
65 | |||
66 | /** |
||
67 | * Sets values to the row cols |
||
68 | * @param mixed $values |
||
69 | */ |
||
70 | public function setValues($values=array()) { |
||
73 | |||
74 | /** |
||
75 | * Adds values to the row cols |
||
76 | * @param mixed $values |
||
77 | */ |
||
78 | public function addValues($values=array()) { |
||
81 | |||
82 | /** |
||
83 | * Sets or adds values to the row cols |
||
84 | * @param mixed $values |
||
85 | */ |
||
86 | protected function _addOrSetValues($values,$callback) { |
||
103 | |||
104 | /** |
||
105 | * Removes the col at $index |
||
106 | * @param int $index the index of the col to remove |
||
107 | * @return \Ajax\semantic\html\content\table\HtmlTR |
||
108 | */ |
||
109 | public function delete($index) { |
||
113 | |||
114 | public function mergeCol($colIndex=0) { |
||
117 | |||
118 | public function mergeRow($colIndex=0) { |
||
121 | |||
122 | public function getColPosition($colIndex) { |
||
145 | |||
146 | public function conditionalCellFormat($callback, $format) { |
||
153 | |||
154 | public function conditionalRowFormat($callback, $format) { |
||
160 | |||
161 | public function containsStr($needle) { |
||
169 | |||
170 | public function apply($callback) { |
||
174 | |||
175 | public function applyCells($callback) { |
||
182 | |||
183 | public function toDelete($colIndex){ |
||
187 | } |
||
188 |
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.