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 |
||
5 | class BaseApi extends AbstractSuite |
||
6 | { |
||
7 | /** |
||
8 | * Get auth info api. |
||
9 | */ |
||
10 | const GET_AUTH_INFO = 'https://qyapi.weixin.qq.com/cgi-bin/service/get_auth_info'; |
||
11 | |||
12 | /** |
||
13 | * Get permanent token api. |
||
14 | */ |
||
15 | const GET_PERMANENT_TOKEN = 'https://qyapi.weixin.qq.com/cgi-bin/service/get_permanent_code'; |
||
16 | |||
17 | /** |
||
18 | * Set session info api. |
||
19 | */ |
||
20 | const SET_SESSION_INFO = 'https://qyapi.weixin.qq.com/cgi-bin/service/set_session_info'; |
||
21 | |||
22 | /** |
||
23 | * Get corp token api. |
||
24 | */ |
||
25 | const GET_CORP_TOKEN = 'https://qyapi.weixin.qq.com/cgi-bin/service/get_corp_token'; |
||
26 | |||
27 | /** |
||
28 | * Get provider token api. |
||
29 | */ |
||
30 | const GET_PROVIDER_TOKEN = 'https://qyapi.weixin.qq.com/cgi-bin/service/get_provider_token'; |
||
31 | |||
32 | /** |
||
33 | * @param $authorizerCorpId |
||
34 | * @param $permanentCode |
||
35 | * |
||
36 | * @return \EntWeChat\Support\Collection |
||
37 | */ |
||
38 | View Code Duplication | public function getAuthorizerInfo($authorizerCorpId, $permanentCode) |
|
48 | |||
49 | /** |
||
50 | * @param null $authCode |
||
51 | * |
||
52 | * @return \EntWeChat\Support\Collection |
||
53 | */ |
||
54 | View Code Duplication | public function getAuthorizationInfo($authCode = null) |
|
63 | |||
64 | /** |
||
65 | * @param $preAuthCode |
||
66 | * @param $sessionInfo |
||
67 | * |
||
68 | * @return \EntWeChat\Support\Collection |
||
69 | */ |
||
70 | public function setAuthorizerOption($preAuthCode, $sessionInfo) |
||
79 | |||
80 | /** |
||
81 | * @param $authorizerCorpId |
||
82 | * @param $permanentCode |
||
83 | * |
||
84 | * @return \EntWeChat\Support\Collection |
||
85 | */ |
||
86 | View Code Duplication | public function getAuthorizerToken($authorizerCorpId, $permanentCode) |
|
96 | |||
97 | /** |
||
98 | * @param $providerCorpId |
||
99 | * @param $providerSecret |
||
100 | * |
||
101 | * @return \EntWeChat\Support\Collection |
||
102 | */ |
||
103 | public function getProviderToken($providerCorpId, $providerSecret) |
||
112 | } |
||
113 |
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.