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 |
||
30 | class BaseApi extends AbstractOpenPlatform |
||
31 | { |
||
32 | /** |
||
33 | * Get auth info api. |
||
34 | */ |
||
35 | const GET_AUTH_INFO = 'https://api.weixin.qq.com/cgi-bin/component/api_query_auth'; |
||
36 | |||
37 | /** |
||
38 | * Get authorizer token api. |
||
39 | */ |
||
40 | const GET_AUTHORIZER_TOKEN = 'https://api.weixin.qq.com/cgi-bin/component/api_authorizer_token'; |
||
41 | |||
42 | /** |
||
43 | * Get authorizer info api. |
||
44 | */ |
||
45 | const GET_AUTHORIZER_INFO = 'https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_info'; |
||
46 | |||
47 | /** |
||
48 | * Get authorizer options api. |
||
49 | */ |
||
50 | const GET_AUTHORIZER_OPTION = 'https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_option'; |
||
51 | |||
52 | /** |
||
53 | * Set authorizer options api. |
||
54 | */ |
||
55 | const SET_AUTHORIZER_OPTION = 'https://api.weixin.qq.com/cgi-bin/component/api_set_authorizer_option'; |
||
56 | |||
57 | const GET_AUTHORIZER_LIST = 'https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_list'; |
||
58 | |||
59 | /** |
||
60 | * Get authorization info. |
||
61 | * |
||
62 | * @param $authCode |
||
63 | * |
||
64 | * @return \EasyWeChat\Support\Collection |
||
65 | */ |
||
66 | 1 | public function getAuthorizationInfo($authCode = null) |
|
75 | |||
76 | /** |
||
77 | * Get authorizer token. |
||
78 | * |
||
79 | * It doesn't cache the authorizer-access-token. |
||
80 | * So developers should NEVER call this method. |
||
81 | * It'll called by: AuthorizerAccessToken::renewAccessToken() |
||
82 | * |
||
83 | * @param $appId |
||
84 | * @param $refreshToken |
||
85 | * |
||
86 | * @return \EasyWeChat\Support\Collection |
||
87 | */ |
||
88 | 1 | View Code Duplication | public function getAuthorizerToken($appId, $refreshToken) |
98 | |||
99 | /** |
||
100 | * Get authorizer info. |
||
101 | * |
||
102 | * @param string $authorizerAppId |
||
103 | * |
||
104 | * @return \EasyWeChat\Support\Collection |
||
105 | */ |
||
106 | 1 | public function getAuthorizerInfo($authorizerAppId) |
|
115 | |||
116 | /** |
||
117 | * Get options. |
||
118 | * |
||
119 | * @param $authorizerAppId |
||
120 | * @param $optionName |
||
121 | * |
||
122 | * @return \EasyWeChat\Support\Collection |
||
123 | */ |
||
124 | 1 | View Code Duplication | public function getAuthorizerOption($authorizerAppId, $optionName) |
134 | |||
135 | /** |
||
136 | * Set authorizer option. |
||
137 | * |
||
138 | * @param $authorizerAppId |
||
139 | * @param $optionName |
||
140 | * @param $optionValue |
||
141 | * |
||
142 | * @return \EasyWeChat\Support\Collection |
||
143 | */ |
||
144 | 1 | View Code Duplication | public function setAuthorizerOption($authorizerAppId, $optionName, $optionValue) |
155 | |||
156 | /** |
||
157 | * Get authorizer list. |
||
158 | * |
||
159 | * @param int $offset |
||
160 | * @param int $count |
||
161 | * |
||
162 | * @return \EasyWeChat\Support\Collection |
||
163 | */ |
||
164 | 1 | View Code Duplication | public function getAuthorizerList($offset = 0, $count = 500) |
174 | } |
||
175 |