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 |
||
8 | class GooglePlusProvider extends BaseProvider |
||
9 | { |
||
10 | const ACCESS_TOKEN_URL = 'https://www.googleapis.com/oauth2/v3/token'; |
||
11 | const INFOS_URL = 'https://www.googleapis.com/oauth2/v3/userinfo'; |
||
12 | const PROVIDER_NAME = 'gp'; |
||
13 | const SCOPE = 'https://www.googleapis.com/auth/userinfo.email'; |
||
14 | |||
15 | /** |
||
16 | * @param $accessToken |
||
17 | * |
||
18 | * @return mixed|\Psr\Http\Message\ResponseInterface |
||
19 | */ |
||
20 | View Code Duplication | public function getUserInformation($accessToken) |
|
33 | |||
34 | /** |
||
35 | * @param $code |
||
36 | * |
||
37 | * @return mixed|\Psr\Http\Message\ResponseInterface |
||
38 | */ |
||
39 | public function getAccessToken($code) |
||
60 | |||
61 | /** |
||
62 | * @param $code |
||
63 | * |
||
64 | * @return UserDto |
||
65 | */ |
||
66 | public function getUser($code) |
||
80 | } |
||
81 |
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.