Complex classes like Client often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Client, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
15 | class Client extends GenericClient |
||
16 | { |
||
17 | const STATUS_OK_REPORT_RECORDED = 'OK_REPORT_RECORDED'; |
||
18 | |||
19 | /** |
||
20 | * @var int |
||
21 | */ |
||
22 | protected $recaptchaRTimeout = 15; |
||
23 | |||
24 | /** |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $serverBaseUri = 'http://rucaptcha.com'; |
||
28 | |||
29 | /** |
||
30 | * Your application ID in Rucaptcha catalog. |
||
31 | * The value `1013` is ID of this library. Set in false if you want to turn off sending any ID. |
||
32 | * |
||
33 | * @see https://rucaptcha.com/software/view/php-api-client |
||
34 | * @var string |
||
35 | */ |
||
36 | protected $softId = '1013'; |
||
37 | |||
38 | /** |
||
39 | * @inheritdoc |
||
40 | */ |
||
41 | public function sendCaptcha($content, array $extra = []) |
||
48 | |||
49 | /** |
||
50 | * Bulk captcha result. |
||
51 | * |
||
52 | * @param int[] $captchaIds # Captcha task Ids array |
||
53 | * @return string[] # Array $captchaId => $captchaText or false if is not ready |
||
54 | * @throws ErrorResponseException |
||
55 | */ |
||
56 | public function getCaptchaResultBulk(array $captchaIds) |
||
80 | |||
81 | /** |
||
82 | * Returns balance of account. |
||
83 | * |
||
84 | * @return string |
||
85 | */ |
||
86 | public function getBalance() |
||
94 | |||
95 | /** |
||
96 | * Report of wrong recognition. |
||
97 | * |
||
98 | * @param string $captchaId |
||
99 | * @return bool |
||
100 | * @throws ErrorResponseException |
||
101 | */ |
||
102 | public function badCaptcha($captchaId) |
||
119 | |||
120 | /** |
||
121 | * Returns server health data. |
||
122 | * |
||
123 | * @param string|string[] $paramsList # List of metrics to be returned |
||
124 | * @return array # Array of load metrics $metric => $value formatted |
||
125 | */ |
||
126 | public function getLoad($paramsList = ['waiting', 'load', 'minbid', 'averageRecognitionTime']) |
||
142 | |||
143 | /** |
||
144 | * Returns load data as XML. |
||
145 | * |
||
146 | * @return \SimpleXMLElement |
||
147 | */ |
||
148 | public function getLoadXml() |
||
156 | |||
157 | /** |
||
158 | * @param string $captchaId # Captcha task ID |
||
159 | * @return array | false # Solved captcha and cost array or false if captcha is not ready |
||
160 | * @throws ErrorResponseException |
||
161 | */ |
||
162 | public function getCaptchaResultWithCost($captchaId) |
||
188 | |||
189 | /** |
||
190 | * Add pingback url to rucaptcha whitelist. |
||
191 | * |
||
192 | * @param string $url |
||
193 | * @return bool # true if added and exception if fail |
||
194 | * @throws ErrorResponseException |
||
195 | */ |
||
196 | public function addPingback($url) |
||
213 | |||
214 | /** |
||
215 | * Returns pingback whitelist items. |
||
216 | * |
||
217 | * @return string[] # List of urls |
||
218 | * @throws ErrorResponseException |
||
219 | */ |
||
220 | public function getPingbacks() |
||
239 | |||
240 | /** |
||
241 | * Remove pingback url from whitelist. |
||
242 | * |
||
243 | * @param string $uri |
||
244 | * @return bool |
||
245 | * @throws ErrorResponseException |
||
246 | */ |
||
247 | public function deletePingback($uri) |
||
263 | |||
264 | /** |
||
265 | * Truncate pingback whitelist. |
||
266 | * |
||
267 | * @return bool |
||
268 | * @throws ErrorResponseException |
||
269 | */ |
||
270 | public function deleteAllPingbacks() |
||
274 | |||
275 | /* Recaptcha v2 */ |
||
276 | |||
277 | public function sendRecapthaV2($googleKey, $pageUrl, $extra = []) |
||
300 | |||
301 | /** |
||
302 | * @param string $googleKey |
||
303 | * @param string $pageUrl |
||
304 | * @param array $extra # Captcha options |
||
305 | * @return string # Code to place in hidden form |
||
306 | * @throws RuntimeException |
||
307 | */ |
||
308 | public function recognizeRecaptchaV2($googleKey, $pageUrl, $extra = []) |
||
335 | |||
336 | /** |
||
337 | * Match error code by response. |
||
338 | * |
||
339 | * @param string $responseText |
||
340 | * @return int |
||
341 | */ |
||
342 | private function getErrorCode($responseText) |
||
349 | } |
||
350 |