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 |
||
| 28 | class FeiShuProvider extends AbstractProvider implements ProviderInterface |
||
| 29 | { |
||
| 30 | /** |
||
| 31 | * 飞书接口域名. |
||
| 32 | * |
||
| 33 | * @var string |
||
| 34 | */ |
||
| 35 | protected $baseUrl = 'https://open.feishu.cn'; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * 应用授权作用域. |
||
| 39 | * |
||
| 40 | * @var array |
||
| 41 | */ |
||
| 42 | protected $scopes = ['user_info']; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * 获取登录页面地址. |
||
| 46 | * |
||
| 47 | * {@inheritdoc} |
||
| 48 | */ |
||
| 49 | protected function getAuthUrl($state) |
||
| 53 | |||
| 54 | /** |
||
| 55 | * 获取授权码接口参数. |
||
| 56 | * |
||
| 57 | * @param string|null $state |
||
| 58 | * |
||
| 59 | * @return array |
||
| 60 | */ |
||
| 61 | protected function getCodeFields($state = null) |
||
| 74 | |||
| 75 | /** |
||
| 76 | * 获取 app_access_token 地址. |
||
| 77 | * |
||
| 78 | * {@inheritdoc} |
||
| 79 | */ |
||
| 80 | protected function getTokenUrl() |
||
| 84 | |||
| 85 | /** |
||
| 86 | * 获取 app_access_token. |
||
| 87 | * |
||
| 88 | * @return \Overtrue\Socialite\AccessToken |
||
| 89 | */ |
||
| 90 | View Code Duplication | public function getAccessToken($code = '') |
|
| 99 | |||
| 100 | /** |
||
| 101 | * 获取 app_access_token 接口参数. |
||
| 102 | * |
||
| 103 | * @return array |
||
| 104 | */ |
||
| 105 | protected function getTokenFields($code) |
||
| 112 | |||
| 113 | /** |
||
| 114 | * 格式化 token. |
||
| 115 | * |
||
| 116 | * @param \Psr\Http\Message\StreamInterface|array $body |
||
| 117 | * |
||
| 118 | * @return \Overtrue\Socialite\AccessTokenInterface |
||
| 119 | */ |
||
| 120 | View Code Duplication | protected function parseAccessToken($body) |
|
| 133 | |||
| 134 | /** |
||
| 135 | * 获取用户信息. |
||
| 136 | * |
||
| 137 | * @return array|mixed |
||
| 138 | */ |
||
| 139 | View Code Duplication | public function user(AccessTokenInterface $token = null) |
|
| 152 | |||
| 153 | /** |
||
| 154 | * 通过 token 获取用户信息. |
||
| 155 | * |
||
| 156 | * @return array|mixed |
||
| 157 | */ |
||
| 158 | protected function getUserByToken(AccessTokenInterface $token) |
||
| 177 | |||
| 178 | /** |
||
| 179 | * 格式化用户信息. |
||
| 180 | * |
||
| 181 | * @return User |
||
| 182 | */ |
||
| 183 | protected function mapUserToObject(array $user) |
||
| 192 | } |
||
| 193 |
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.