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 | ||
| 8 | class User extends ActiveRecordModelExtender | ||
| 9 | { | ||
| 10 | |||
| 11 | /** | ||
| 12 | * @var string $tableName name of the database table. | ||
| 13 | */ | ||
| 14 | protected $tableName = "coffee_users"; | ||
| 15 | |||
| 16 | /** | ||
| 17 | * Columns in the table. | ||
| 18 | * | ||
| 19 | * @var integer $id primary key auto incremented. | ||
| 20 | */ | ||
| 21 | public $id; | ||
| 22 | public $name; | ||
| 23 | public $email; | ||
| 24 | public $pass; | ||
| 25 | public $authority = "user"; | ||
| 26 | public $question; | ||
| 27 | |||
| 28 | 7 | public function getReputation($user) | |
| 59 | |||
| 60 | |||
| 61 | /** | ||
| 62 | * Sets up user | ||
| 63 | * @param object $user | ||
| 64 | * | ||
| 65 | * @return object | ||
| 66 | */ | ||
| 67 | 7 | public function setupUser($user) | |
| 100 | |||
| 101 | /** | ||
| 102 | * Returns post with markdown and gravatar | ||
| 103 | * @param string $sql | ||
| 104 | * @param array $param | ||
|  | |||
| 105 | * | ||
| 106 | * @return array | ||
| 107 | */ | ||
| 108 | 3 | View Code Duplication | public function getAllUsers($sql = null, $params = null) | 
| 119 | |||
| 120 | /** | ||
| 121 | * return question/answer, three attributes are set, comments connected to them is an array. | ||
| 122 | * @param string $name | ||
| 123 | * | ||
| 124 | * @return object | ||
| 125 | */ | ||
| 126 | 4 | public function getUser($name) | |
| 132 | |||
| 133 | |||
| 134 | /** | ||
| 135 | * Check if user exists | ||
| 136 | * | ||
| 137 | * @param string $name | ||
| 138 | * | ||
| 139 | * @return boolean true if user exists in database else false | ||
| 140 | */ | ||
| 141 | 1 | public function userExists($name) | |
| 146 | /** | ||
| 147 | * Returns gravatar link | ||
| 148 | * | ||
| 149 | * @param string $email | ||
| 150 | * | ||
| 151 | * @return string as gravatar link | ||
| 152 | */ | ||
| 153 | 1 | public function setGravatar() | |
| 157 | |||
| 158 | /** | ||
| 159 | * Returns gravatar link | ||
| 160 | * | ||
| 161 | * @param string $name | ||
| 162 | * | ||
| 163 | * @return string as gravatar link | ||
| 164 | */ | ||
| 165 | 10 | public function getGravatar($name) | |
| 170 | |||
| 171 | /** | ||
| 172 | * Set the pass. | ||
| 173 | * | ||
| 174 | * @param string $pass the pass to use. | ||
| 175 | * | ||
| 176 | * @return void | ||
| 177 | */ | ||
| 178 | 4 | public function setPassword($pass) | |
| 182 | |||
| 183 | /** | ||
| 184 | * Verify the name and the pass, if successful the object contains | ||
| 185 | * all details from the database row. | ||
| 186 | * | ||
| 187 | * @param string $name name to check. | ||
| 188 | * @param string $pass the pass to use. | ||
| 189 | * | ||
| 190 | * @return boolean true if name and pass matches, else false. | ||
| 191 | */ | ||
| 192 | 3 | public function verifyPassword($name, $pass) | |
| 197 | |||
| 198 | /** | ||
| 199 | * Verify the name and the anaswer, if successful the object contains | ||
| 200 | * all details from the database row. | ||
| 201 | * | ||
| 202 | * @param string $name name to check. | ||
| 203 | * @param string $answer the answer. | ||
| 204 | * | ||
| 205 | * @return boolean true if name and pass matches, else false. | ||
| 206 | */ | ||
| 207 | 1 | public function verifyQuestion($name, $answer) | |
| 212 | |||
| 213 | |||
| 214 | /** | ||
| 215 | * Check if a post belongs to user | ||
| 216 | * | ||
| 217 | * | ||
| 218 | * @return boolean | ||
| 219 | */ | ||
| 220 | 2 | public function controlAuthority($loggedUser, $name) | |
| 229 | } | ||
| 230 | 
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$irelandis not defined by the methodfinale(...).The most likely cause is that the parameter was changed, but the annotation was not.