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 Post extends ActiveRecordModelExtender |
||
| 9 | { |
||
| 10 | |||
| 11 | /** |
||
| 12 | * @var string $tableName name of the database table. |
||
| 13 | */ |
||
| 14 | protected $tableName = "ramverk1_posts"; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * Columns in the table. |
||
| 18 | * |
||
| 19 | * @var integer $id primary key auto incremented. |
||
| 20 | */ |
||
| 21 | public $id; |
||
| 22 | public $user; |
||
| 23 | public $questionId; # Connection to new Question() |
||
| 24 | |||
| 25 | public $type; # question/answer |
||
| 26 | public $text; |
||
| 27 | |||
| 28 | public $created; |
||
| 29 | |||
| 30 | public $di; |
||
| 31 | |||
| 32 | |||
| 33 | |||
| 34 | /** |
||
| 35 | * Returns post with markdown and gravatar |
||
| 36 | * @param string $sql |
||
| 37 | * @param array $param |
||
|
|
|||
| 38 | * |
||
| 39 | * @return array |
||
| 40 | */ |
||
| 41 | 1 | public function getAllPosts($sql, $params) |
|
| 62 | |||
| 63 | /** |
||
| 64 | * return question/answer, three attributes are set, comments connected to them is an array. |
||
| 65 | * |
||
| 66 | * @return object |
||
| 67 | */ |
||
| 68 | 1 | public function getPost($sql, $params) |
|
| 86 | |||
| 87 | /** |
||
| 88 | * Check if a post belongs to user |
||
| 89 | * |
||
| 90 | * |
||
| 91 | * @return boolean |
||
| 92 | */ |
||
| 93 | View Code Duplication | public function controlAuthority($name) |
|
| 105 | } |
||
| 106 |
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.