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 |
||
| 29 | class Session extends AbstractAPI |
||
| 30 | { |
||
| 31 | |||
| 32 | const API_CREATE = 'https://api.weixin.qq.com/customservice/kfsession/create'; |
||
| 33 | const API_CLOSE = 'https://api.weixin.qq.com/customservice/kfsession/close'; |
||
| 34 | const API_GET = 'https://api.weixin.qq.com/customservice/kfsession/getsession'; |
||
| 35 | const API_LISTS = 'https://api.weixin.qq.com/customservice/kfsession/getsessionlist'; |
||
| 36 | const API_WAITERS = 'https://api.weixin.qq.com/customservice/kfsession/getwaitcase'; |
||
| 37 | |||
| 38 | |||
| 39 | /** |
||
| 40 | * List all sessions of $account. |
||
| 41 | * |
||
| 42 | * @param string $account |
||
| 43 | * |
||
| 44 | * @return array |
||
| 45 | */ |
||
| 46 | 1 | public function lists($account) |
|
| 50 | |||
| 51 | /** |
||
| 52 | * List all waiters of $account. |
||
| 53 | * |
||
| 54 | * @return array |
||
| 55 | */ |
||
| 56 | 1 | public function waiters() |
|
| 60 | |||
| 61 | /** |
||
| 62 | * Create a session. |
||
| 63 | * |
||
| 64 | * @param string $account |
||
| 65 | * @param string $openid |
||
|
|
|||
| 66 | * |
||
| 67 | * @return bool |
||
| 68 | */ |
||
| 69 | 1 | View Code Duplication | public function create($account, $openId) |
| 78 | |||
| 79 | /** |
||
| 80 | * Close a session. |
||
| 81 | * |
||
| 82 | * @param string $account |
||
| 83 | * @param string $openId |
||
| 84 | * |
||
| 85 | * @return bool |
||
| 86 | */ |
||
| 87 | 1 | View Code Duplication | public function close($account, $openId) |
| 96 | |||
| 97 | /** |
||
| 98 | * Get a session. |
||
| 99 | * |
||
| 100 | * @param string $openId |
||
| 101 | * |
||
| 102 | * @return bool |
||
| 103 | */ |
||
| 104 | 1 | public function get($openId) |
|
| 108 | } |
||
| 109 |
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.