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 |
||
| 21 | class User extends ZfcUser |
||
| 22 | { |
||
| 23 | |||
| 24 | /** |
||
| 25 | * user's confirmation/activation token |
||
| 26 | * |
||
| 27 | * @var string |
||
| 28 | */ |
||
| 29 | protected $token; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * user's ACL role |
||
| 33 | * |
||
| 34 | * @var string |
||
| 35 | */ |
||
| 36 | protected $aclrole; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * user's ID |
||
| 40 | * |
||
| 41 | * @var int |
||
| 42 | */ |
||
| 43 | protected $user_id; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Get ACL role. |
||
| 47 | * |
||
| 48 | * @return STRING |
||
| 49 | */ |
||
| 50 | public function getAclrole() |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Set ACL role. |
||
| 60 | * |
||
| 61 | * @param STRING $aclrole |
||
| 62 | * @return \Admin\Entity\User |
||
| 63 | */ |
||
| 64 | public function setAclrole($aclrole) |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Get token string. |
||
| 72 | * |
||
| 73 | * @return STRING |
||
| 74 | */ |
||
| 75 | public function getToken() |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Set token string. |
||
| 82 | * |
||
| 83 | * @param STRING $aclrole |
||
|
|
|||
| 84 | * @return \Admin\Entity\User |
||
| 85 | */ |
||
| 86 | public function setToken($token) |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Get user-id string. |
||
| 94 | * |
||
| 95 | * @return STRING |
||
| 96 | */ |
||
| 97 | public function getUserId() |
||
| 104 | |||
| 105 | /** |
||
| 106 | * Set user-id string. |
||
| 107 | * |
||
| 108 | * @param STRING $aclrole |
||
| 109 | * @return \Admin\Entity\User |
||
| 110 | */ |
||
| 111 | public function setUserId($user_id) |
||
| 116 | |||
| 117 | |||
| 118 | |||
| 119 | /** |
||
| 120 | * set user's object property data |
||
| 121 | * |
||
| 122 | * @param array $data |
||
| 123 | * @param boolean $forceEncryptPassword |
||
| 124 | * @return \Admin\Entity\User |
||
| 125 | */ |
||
| 126 | View Code Duplication | public function exchangeArray($data = array(), $forceEncryptPassword = false) |
|
| 156 | |||
| 157 | /** |
||
| 158 | * get copy of user's object properties in an assosiative array |
||
| 159 | * |
||
| 160 | * @return array |
||
| 161 | */ |
||
| 162 | public function __getArrayCopy() |
||
| 177 | |||
| 178 | /** |
||
| 179 | * get copy of user's object properties in an assosiative array |
||
| 180 | * |
||
| 181 | * @return array |
||
| 182 | * / |
||
| 183 | public function getArrayCopy() |
||
| 184 | { |
||
| 185 | return $this->__getArrayCopy(); |
||
| 186 | } // collides with some magic "__get" method in ZfcUser parent ?! |
||
| 187 | */ |
||
| 188 | |||
| 189 | } |
||
| 190 |
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
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.