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 |
||
9 | class HtmlLabel extends HtmlSemDoubleElement { |
||
10 | |||
11 | public function __construct($identifier,$caption="",$tagName="div") { |
||
16 | |||
17 | /** |
||
18 | * @param string $side |
||
19 | * @return \Ajax\semantic\html\elements\HtmlLabel |
||
20 | */ |
||
21 | public function setPointing($side=""){ |
||
24 | |||
25 | /** |
||
26 | * @param string $side |
||
27 | * @return \Ajax\semantic\html\elements\HtmlLabel |
||
28 | */ |
||
29 | public function toCorner($side="left"){ |
||
32 | |||
33 | /** |
||
34 | * @return \Ajax\semantic\html\elements\HtmlLabel |
||
35 | */ |
||
36 | public function asTag(){ |
||
39 | |||
40 | public function setBasic(){ |
||
43 | |||
44 | /** |
||
45 | * Adds an image to emphasize |
||
46 | * @param string $src |
||
47 | * @param string $alt |
||
48 | * @param string $before |
||
49 | * @return \Ajax\semantic\html\elements\HtmlLabel |
||
50 | */ |
||
51 | public function addImage($src,$alt="",$before=true){ |
||
55 | |||
56 | /** |
||
57 | * @param string $detail |
||
58 | * @return \Ajax\common\html\HtmlDoubleElement |
||
59 | */ |
||
60 | View Code Duplication | public function addDetail($detail){ |
|
67 | } |
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.