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 |
||
7 | class HtmlTR extends HtmlSemCollection{ |
||
8 | |||
9 | private $_tdTagName; |
||
10 | private $_container; |
||
11 | private $_row; |
||
12 | |||
13 | public function __construct( $identifier, $colCount){ |
||
16 | |||
17 | public function setColCount($colCount){ |
||
25 | |||
26 | |||
27 | protected function createItem($value){ |
||
33 | |||
34 | public function setTdTagName($tagName="td"){ |
||
37 | |||
38 | public function setContainer($container,$row){ |
||
42 | |||
43 | View Code Duplication | public function setValues($values=array()){ |
|
55 | |||
56 | public function delete($index){ |
||
60 | } |
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.