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 LinkedinProvider extends AbstractProvider implements ProviderInterface |
||
24 | { |
||
25 | /** |
||
26 | * The scopes being requested. |
||
27 | * |
||
28 | * @var array |
||
29 | */ |
||
30 | protected $scopes = ['r_liteprofile', 'r_emailaddress']; |
||
31 | |||
32 | /** |
||
33 | * {@inheritdoc} |
||
34 | */ |
||
35 | protected function getAuthUrl($state) |
||
39 | |||
40 | /** |
||
41 | * Get the access token for the given code. |
||
42 | * |
||
43 | * @param string $code |
||
44 | * |
||
45 | * @return \Overtrue\Socialite\AccessToken |
||
46 | */ |
||
47 | View Code Duplication | public function getAccessToken($code) |
|
54 | |||
55 | /** |
||
56 | * {@inheritdoc} |
||
57 | */ |
||
58 | protected function getTokenUrl() |
||
62 | |||
63 | /** |
||
64 | * Get the POST fields for the token request. |
||
65 | * |
||
66 | * @param string $code |
||
67 | * |
||
68 | * @return array |
||
69 | */ |
||
70 | protected function getTokenFields($code) |
||
74 | |||
75 | /** |
||
76 | * {@inheritdoc} |
||
77 | */ |
||
78 | protected function getUserByToken(AccessTokenInterface $token) |
||
85 | |||
86 | /** |
||
87 | * Get the basic profile fields for the user. |
||
88 | * |
||
89 | * @param string $token |
||
90 | * @return array |
||
91 | */ |
||
92 | protected function getBasicProfile($token) |
||
105 | /** |
||
106 | * Get the email address for the user. |
||
107 | * |
||
108 | * @param string $token |
||
109 | * @return array |
||
110 | */ |
||
111 | View Code Duplication | protected function getEmailAddress($token) |
|
124 | |||
125 | /** |
||
126 | * {@inheritdoc} |
||
127 | */ |
||
128 | protected function mapUserToObject(array $user) |
||
154 | |||
155 | /** |
||
156 | * Set the user fields to request from LinkedIn. |
||
157 | * |
||
158 | * @param array $fields |
||
159 | * |
||
160 | * @return $this |
||
161 | */ |
||
162 | public function fields(array $fields) |
||
168 | |||
169 | /** |
||
170 | * Determine if the provider is operating as stateless. |
||
171 | * |
||
172 | * @return bool |
||
173 | */ |
||
174 | protected function isStateless() |
||
178 | } |
||
179 |
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.