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 |
||
| 26 | class CorpWechatProvider extends AbstractProvider implements ProviderInterface |
||
| 27 | { |
||
| 28 | /** |
||
| 29 | * The base url of WeChat API. |
||
| 30 | * |
||
| 31 | * @var string |
||
| 32 | */ |
||
| 33 | protected $user_baseinfo_api = 'https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo'; |
||
| 34 | protected $user_info_api = 'https://qyapi.weixin.qq.com/cgi-bin/user/get'; |
||
| 35 | protected $access_api_url = 'https://qyapi.weixin.qq.com/cgi-bin/gettoken'; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * {@inheritdoc}. |
||
| 39 | */ |
||
| 40 | protected $openId; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * {@inheritdoc}. |
||
| 44 | */ |
||
| 45 | protected $scopes = ['snsapi_base']; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Indicates if the session state should be utilized. |
||
| 49 | * |
||
| 50 | * @var bool |
||
| 51 | */ |
||
| 52 | protected $stateless = true; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * {@inheritdoc}. |
||
| 56 | */ |
||
| 57 | protected function getAuthUrl($state) |
||
| 65 | |||
| 66 | /** |
||
| 67 | * {@inheritdoc}. |
||
| 68 | */ |
||
| 69 | protected function buildAuthUrlFromBase($url, $state) |
||
| 75 | |||
| 76 | /** |
||
| 77 | * {@inheritdoc}. |
||
| 78 | */ |
||
| 79 | View Code Duplication | protected function getCodeFields($state = null) |
|
| 92 | |||
| 93 | /** |
||
| 94 | * 获取 access token的路径. |
||
| 95 | */ |
||
| 96 | protected function getTokenUrl() |
||
| 100 | |||
| 101 | /** |
||
| 102 | * {@inheritdoc}. |
||
| 103 | */ |
||
| 104 | protected function getUserByToken(AccessTokenInterface $token) |
||
| 121 | |||
| 122 | /** |
||
| 123 | * {@inheritdoc}. |
||
| 124 | */ |
||
| 125 | protected function mapUserToObject(array $user) |
||
| 138 | |||
| 139 | /** |
||
| 140 | * 构建access_token 的参数列表, 分为两种情况一种是 获取access token, 另一种是直接获取userid |
||
| 141 | */ |
||
| 142 | protected function getTokenFields($code = false) |
||
| 161 | |||
| 162 | /** |
||
| 163 | * 原始微信oauth 应该是返回 access token + openid |
||
| 164 | * 企业号因为用的是7200秒的, 所以需要支持从外部去获取access_token 不会冲突 要返回 userid |
||
| 165 | */ |
||
| 166 | public function getAccessToken($code) |
||
| 188 | // !!应该尽量不要调用, 除非 单独与overture/wechat使用, 否则同时获取accesstoken, 会冲突 |
||
| 189 | public function getLongiveAccessToken($forse_refresh = false){ |
||
| 198 | |||
| 199 | |||
| 200 | |||
| 201 | /** |
||
| 202 | * Remove the fucking callback parentheses. |
||
| 203 | * |
||
| 204 | * @param mixed $response |
||
| 205 | * |
||
| 206 | * @return string |
||
| 207 | */ |
||
| 208 | protected function removeCallback($response) |
||
| 218 | } |
||
| 219 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.