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 |
||
10 | class Web extends AbstractAuthentication |
||
11 | { |
||
12 | const AUTH_URL = 'https://qy.weixin.qq.com/cgi-bin/loginpage'; |
||
13 | |||
14 | const API_GET_LOGIN_INFO = 'https://qyapi.weixin.qq.com/cgi-bin/service/get_login_info'; |
||
15 | const API_GET_LOGIN_URL = 'https://qyapi.weixin.qq.com/cgi-bin/service/get_login_url'; |
||
16 | |||
17 | /** |
||
18 | * Indicates if the session state should be utilized. |
||
19 | * |
||
20 | * @var bool |
||
21 | */ |
||
22 | protected $stateless = true; |
||
23 | |||
24 | /** |
||
25 | * Get the SSO URL. |
||
26 | * |
||
27 | * @param string $loginTicket |
||
28 | * @param string $target |
||
29 | * @param int|null $agentId |
||
30 | * |
||
31 | * @return \EntWeChat\Support\Collection |
||
32 | */ |
||
33 | public function getSSOUrl($loginTicket, $target, $agentId = null) |
||
37 | |||
38 | /** |
||
39 | * Get the Login URL. |
||
40 | * |
||
41 | * @param string $loginTicket |
||
42 | * @param string $target |
||
43 | * @param int|null $agentId |
||
44 | * |
||
45 | * @return \EntWeChat\Support\Collection |
||
46 | */ |
||
47 | public function getLoginUrl($loginTicket, $target, $agentId = null) |
||
57 | |||
58 | /** |
||
59 | * @param string|null $authCode |
||
60 | * |
||
61 | * @throws InvalidStateException |
||
62 | * |
||
63 | * @return \EntWeChat\Support\Collection |
||
64 | */ |
||
65 | View Code Duplication | public function user($authCode = null) |
|
77 | |||
78 | /** |
||
79 | * {@inheritdoc}. |
||
80 | */ |
||
81 | protected function getAuthUrl($state = null) |
||
93 | } |
||
94 |
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.