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 |
||
| 14 | class BaiduProvider extends AbstractProvider implements ProviderInterface |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * The base url of Weibo API. |
||
| 18 | * |
||
| 19 | * @var string |
||
| 20 | */ |
||
| 21 | protected $baseUrl = 'https://openapi.baidu.com'; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * The API version for the request. |
||
| 25 | * |
||
| 26 | * @var string |
||
| 27 | */ |
||
| 28 | protected $version = '2.0'; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * The scopes being requested. |
||
| 32 | * |
||
| 33 | * @var array |
||
| 34 | */ |
||
| 35 | protected $scopes = ['']; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * The uid of user authorized. |
||
| 39 | * |
||
| 40 | * @var int |
||
| 41 | */ |
||
| 42 | protected $uid; |
||
| 43 | |||
| 44 | protected $display = 'popup'; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Get the authentication URL for the provider. |
||
| 48 | * |
||
| 49 | * @param string $state |
||
| 50 | * |
||
| 51 | * @return string |
||
| 52 | */ |
||
| 53 | protected function getAuthUrl($state) |
||
| 57 | |||
| 58 | /** |
||
| 59 | * {@inheritdoc}. |
||
| 60 | */ |
||
| 61 | protected function getCodeFields($state = null) |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Get the token URL for the provider. |
||
| 74 | * |
||
| 75 | * @return string |
||
| 76 | */ |
||
| 77 | protected function getTokenUrl() |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Get the Post fields for the token request. |
||
| 84 | * |
||
| 85 | * @param string $code |
||
| 86 | * |
||
| 87 | * @return array |
||
| 88 | */ |
||
| 89 | protected function getTokenFields($code) |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Get the raw user for the given access token. |
||
| 96 | * |
||
| 97 | * @param \Overtrue\Socialite\AccessTokenInterface $token |
||
| 98 | * |
||
| 99 | * @return array |
||
| 100 | */ |
||
| 101 | View Code Duplication | protected function getUserByToken(AccessTokenInterface $token) |
|
| 114 | |||
| 115 | /** |
||
| 116 | * Map the raw user array to a Socialite User instance. |
||
| 117 | * |
||
| 118 | * @param array $user |
||
| 119 | * |
||
| 120 | * @return \Overtrue\Socialite\User |
||
| 121 | */ |
||
| 122 | protected function mapUserToObject(array $user) |
||
| 133 | } |
||
| 134 |
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.