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 WeChatProvider extends AbstractProvider implements ProviderInterface |
||
| 27 | { |
||
| 28 | /** |
||
| 29 | * The base url of WeChat API. |
||
| 30 | * |
||
| 31 | * @var string |
||
| 32 | */ |
||
| 33 | protected $baseUrl = 'https://api.weixin.qq.com/sns'; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * {@inheritdoc}. |
||
| 37 | */ |
||
| 38 | protected $openId; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * {@inheritdoc}. |
||
| 42 | */ |
||
| 43 | protected $scopes = ['snsapi_login']; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Indicates if the session state should be utilized. |
||
| 47 | * |
||
| 48 | * @var bool |
||
| 49 | */ |
||
| 50 | protected $stateless = true; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * {@inheritdoc}. |
||
| 54 | */ |
||
| 55 | protected function getAuthUrl($state) |
||
| 65 | |||
| 66 | /** |
||
| 67 | * {@inheritdoc}. |
||
| 68 | */ |
||
| 69 | protected function buildAuthUrlFromBase($url, $state) |
||
| 75 | |||
| 76 | /** |
||
| 77 | * {@inheritdoc}. |
||
| 78 | */ |
||
| 79 | protected function getCodeFields($state = null) |
||
| 89 | |||
| 90 | /** |
||
| 91 | * {@inheritdoc}. |
||
| 92 | */ |
||
| 93 | protected function getTokenUrl() |
||
| 100 | |||
| 101 | /** |
||
| 102 | * {@inheritdoc}. |
||
| 103 | */ |
||
| 104 | protected function getUserByToken(AccessTokenInterface $token) |
||
| 126 | |||
| 127 | /** |
||
| 128 | * {@inheritdoc}. |
||
| 129 | */ |
||
| 130 | protected function mapUserToObject(array $user) |
||
| 140 | |||
| 141 | /** |
||
| 142 | * {@inheritdoc}. |
||
| 143 | */ |
||
| 144 | protected function getTokenFields($code) |
||
| 163 | |||
| 164 | /** |
||
| 165 | * {@inheritdoc}. |
||
| 166 | */ |
||
| 167 | View Code Duplication | public function getAccessToken($code) |
|
| 175 | |||
| 176 | /** |
||
| 177 | * Detect wechat open platform. |
||
| 178 | * |
||
| 179 | * @return mixed |
||
| 180 | */ |
||
| 181 | protected function isOpenPlatform() |
||
| 185 | |||
| 186 | /** |
||
| 187 | * Remove the fucking callback parentheses. |
||
| 188 | * |
||
| 189 | * @param mixed $response |
||
| 190 | * |
||
| 191 | * @return string |
||
| 192 | */ |
||
| 193 | View Code Duplication | protected function removeCallback($response) |
|
| 203 | } |
||
| 204 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.