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 = "ramverk1_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 | * @param array $param  | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 65 | *  | 
            ||
| 66 | * @return object  | 
            ||
| 67 | */  | 
            ||
| 68 | 7 | public function setupUser($user)  | 
            |
| 98 | |||
| 99 | /**  | 
            ||
| 100 | * Returns post with markdown and gravatar  | 
            ||
| 101 | * @param string $sql  | 
            ||
| 102 | * @param array $param  | 
            ||
| 103 | *  | 
            ||
| 104 | * @return array  | 
            ||
| 105 | */  | 
            ||
| 106 | 3 | View Code Duplication | public function getAllUsers($sql = null, $params = null)  | 
            
| 117 | |||
| 118 | /**  | 
            ||
| 119 | * return question/answer, three attributes are set, comments connected to them is an array.  | 
            ||
| 120 | *  | 
            ||
| 121 | * @return object  | 
            ||
| 122 | */  | 
            ||
| 123 | 4 | public function getUser($name)  | 
            |
| 129 | |||
| 130 | |||
| 131 | /**  | 
            ||
| 132 | * Check if user exists  | 
            ||
| 133 | *  | 
            ||
| 134 | * @param string $name  | 
            ||
| 135 | *  | 
            ||
| 136 | * @return boolean true if user exists in database else false  | 
            ||
| 137 | */  | 
            ||
| 138 | 1 | public function userExists($name)  | 
            |
| 143 | /**  | 
            ||
| 144 | * Returns gravatar link  | 
            ||
| 145 | *  | 
            ||
| 146 | * @param string $email  | 
            ||
| 147 | *  | 
            ||
| 148 | * @return string as gravatar link  | 
            ||
| 149 | */  | 
            ||
| 150 | 1 | public function setGravatar()  | 
            |
| 154 | |||
| 155 | /**  | 
            ||
| 156 | * Returns gravatar link  | 
            ||
| 157 | *  | 
            ||
| 158 | * @param string $name  | 
            ||
| 159 | *  | 
            ||
| 160 | * @return string as gravatar link  | 
            ||
| 161 | */  | 
            ||
| 162 | 10 | public function getGravatar($name)  | 
            |
| 167 | |||
| 168 | /**  | 
            ||
| 169 | * Set the pass.  | 
            ||
| 170 | *  | 
            ||
| 171 | * @param string $pass the pass to use.  | 
            ||
| 172 | *  | 
            ||
| 173 | * @return void  | 
            ||
| 174 | */  | 
            ||
| 175 | 4 | public function setPassword($pass)  | 
            |
| 179 | |||
| 180 | /**  | 
            ||
| 181 | * Verify the name and the pass, if successful the object contains  | 
            ||
| 182 | * all details from the database row.  | 
            ||
| 183 | *  | 
            ||
| 184 | * @param string $name name to check.  | 
            ||
| 185 | * @param string $pass the pass to use.  | 
            ||
| 186 | *  | 
            ||
| 187 | * @return boolean true if name and pass matches, else false.  | 
            ||
| 188 | */  | 
            ||
| 189 | 3 | public function verifyPassword($name, $pass)  | 
            |
| 194 | |||
| 195 | /**  | 
            ||
| 196 | * Verify the name and the anaswer, if successful the object contains  | 
            ||
| 197 | * all details from the database row.  | 
            ||
| 198 | *  | 
            ||
| 199 | * @param string $name name to check.  | 
            ||
| 200 | * @param string $answer the answer.  | 
            ||
| 201 | *  | 
            ||
| 202 | * @return boolean true if name and pass matches, else false.  | 
            ||
| 203 | */  | 
            ||
| 204 | 1 | public function verifyQuestion($name, $answer)  | 
            |
| 209 | |||
| 210 | |||
| 211 | /**  | 
            ||
| 212 | * Check if a post belongs to user  | 
            ||
| 213 | *  | 
            ||
| 214 | *  | 
            ||
| 215 | * @return boolean  | 
            ||
| 216 | */  | 
            ||
| 217 | 2 | public function controlAuthority($loggedUser, $name)  | 
            |
| 226 | }  | 
            ||
| 227 | 
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.