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 |
||
| 23 | class WeWorkProvider extends AbstractProvider implements ProviderInterface |
||
| 24 | { |
||
| 25 | /** |
||
| 26 | * @var string |
||
| 27 | */ |
||
| 28 | protected $agentId; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var bool |
||
| 32 | */ |
||
| 33 | protected $detailed = false; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Set agent id. |
||
| 37 | * |
||
| 38 | * @param string $agentId |
||
| 39 | * |
||
| 40 | * @return $this |
||
| 41 | */ |
||
| 42 | public function setAgentId($agentId) |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Return user details. |
||
| 51 | * |
||
| 52 | * @return $this |
||
| 53 | */ |
||
| 54 | public function detailed() |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @param string $state |
||
| 63 | * |
||
| 64 | * @return string |
||
| 65 | */ |
||
| 66 | protected function getAuthUrl($state) |
||
| 76 | |||
| 77 | /** |
||
| 78 | * OAuth url. |
||
| 79 | * |
||
| 80 | * @param string $state |
||
| 81 | * |
||
| 82 | * @return string |
||
| 83 | */ |
||
| 84 | protected function getOAuthUrl($state) |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Qr connect url. |
||
| 100 | * |
||
| 101 | * @param string $state |
||
| 102 | * |
||
| 103 | * @return string |
||
| 104 | */ |
||
| 105 | protected function getQrConnectUrl($state) |
||
| 116 | |||
| 117 | protected function getTokenUrl() |
||
| 121 | |||
| 122 | /** |
||
| 123 | * @param \Overtrue\Socialite\AccessTokenInterface $token |
||
| 124 | * |
||
| 125 | * @return mixed |
||
| 126 | */ |
||
| 127 | protected function getUserByToken(AccessTokenInterface $token) |
||
| 139 | |||
| 140 | /** |
||
| 141 | * Get user base info. |
||
| 142 | * |
||
| 143 | * @param \Overtrue\Socialite\AccessTokenInterface $token |
||
| 144 | * |
||
| 145 | * @return mixed |
||
| 146 | */ |
||
| 147 | View Code Duplication | protected function getUserInfo(AccessTokenInterface $token) |
|
| 158 | |||
| 159 | /** |
||
| 160 | * Get user detail info. |
||
| 161 | * |
||
| 162 | * @param \Overtrue\Socialite\AccessTokenInterface $token |
||
| 163 | * @param $ticket |
||
| 164 | * |
||
| 165 | * @return mixed |
||
| 166 | */ |
||
| 167 | View Code Duplication | protected function getUserDetail(AccessTokenInterface $token, $ticket) |
|
| 180 | |||
| 181 | /** |
||
| 182 | * @param array $user |
||
| 183 | * |
||
| 184 | * @return \Overtrue\Socialite\User |
||
| 185 | */ |
||
| 186 | protected function mapUserToObject(array $user) |
||
| 204 | } |
||
| 205 |
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.