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 Intraface_Intranet extends Intraface_Standard |
||
10 | { |
||
11 | /** |
||
12 | * @var object |
||
13 | */ |
||
14 | public $address; |
||
15 | |||
16 | /** |
||
17 | * @var array |
||
18 | */ |
||
19 | public $value; |
||
20 | |||
21 | /** |
||
22 | * @var integer |
||
23 | */ |
||
24 | protected $id; |
||
25 | |||
26 | /** |
||
27 | * @var object |
||
28 | */ |
||
29 | private $db; |
||
30 | |||
31 | /** |
||
32 | * @var array |
||
33 | */ |
||
34 | protected $permissions; |
||
35 | |||
36 | /** |
||
37 | * Constructor |
||
38 | * |
||
39 | * @param integer $intranet_id The id of the intranet |
||
|
|||
40 | * |
||
41 | * @return void |
||
42 | */ |
||
43 | 5 | function __construct($id) |
|
53 | |||
54 | function getName() |
||
58 | |||
59 | /** |
||
60 | * loads |
||
61 | * |
||
62 | * @return void |
||
63 | */ |
||
64 | 23 | function load() |
|
94 | |||
95 | 23 | public function getAddress() |
|
99 | |||
100 | /** |
||
101 | * Returns whether the intranet has access to the module |
||
102 | * |
||
103 | * @todo might be smarter to throw in an actual module object |
||
104 | * that would make us sure that it is actually valid |
||
105 | * |
||
106 | * @param mixed $module The id or name of the module |
||
107 | * |
||
108 | * @return void |
||
109 | */ |
||
110 | 2 | function hasModuleAccess($module) |
|
161 | |||
162 | /** |
||
163 | * Returns the id of the intranet |
||
164 | * |
||
165 | * @return integer |
||
166 | */ |
||
167 | function getId() |
||
171 | } |
||
172 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.