Complex classes like Bankly 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 Bankly, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
19 | class Bankly |
||
20 | { |
||
21 | public $api_url; |
||
22 | public $login_url; |
||
23 | private $client_id; |
||
24 | private $client_secret; |
||
25 | private $token_expiry = 0; |
||
26 | private $token = null; |
||
27 | private $api_version = '1.0'; |
||
28 | |||
29 | /** |
||
30 | * Bankly constructor. |
||
31 | * @param null|string $client_secret provided by Bankly Staff |
||
32 | * @param null|string $client_id provided by Bankly Staff |
||
33 | */ |
||
34 | public function __construct($client_secret = null, $client_id = null) |
||
40 | |||
41 | /** |
||
42 | * @param array|null $credentials |
||
43 | * @return $this |
||
44 | */ |
||
45 | public function setClientCredentials(array $credentials = null) |
||
51 | |||
52 | /** |
||
53 | * @return array|mixed |
||
54 | * @throws RequestException |
||
55 | */ |
||
56 | public function getBankList() |
||
60 | |||
61 | /** |
||
62 | * Retrieve your balance account |
||
63 | * @param string $branch |
||
64 | * @param string $account |
||
65 | * @return array|mixed |
||
66 | * @throws RequestException |
||
67 | * @note If you have a RequestException on this endpoint in staging environment, please use getAccount() method instead. |
||
68 | */ |
||
69 | public function getBalance(string $branch, string $account) |
||
77 | |||
78 | /** |
||
79 | * @param string $account |
||
80 | * @param string $includeBalance |
||
81 | * @return array|mixed |
||
82 | * @throws RequestException |
||
83 | * @note This method on this date (2020-10-21) works only on staging environment. Contact Bankly/Acesso for more details |
||
84 | */ |
||
85 | public function getAccount(string $account, string $includeBalance = 'true') |
||
91 | |||
92 | /** |
||
93 | * @param $branch |
||
94 | * @param $account |
||
95 | * @param int $offset |
||
96 | * @param int $limit |
||
97 | * @param string $details |
||
98 | * @param string $detailsLevelBasic |
||
99 | * @return array|mixed |
||
100 | * @throws RequestException |
||
101 | */ |
||
102 | public function getStatement( |
||
119 | |||
120 | /** |
||
121 | * @param string $branch |
||
122 | * @param string $account |
||
123 | * @param int $page |
||
124 | * @param int $pagesize |
||
125 | * @param string $include_details |
||
126 | * @return array|mixed |
||
127 | * @throws RequestException |
||
128 | * @note This endpoint has been deprecated for some clients. |
||
129 | * You need to check with Acesso/Bankly if your environment has different parameters also. |
||
130 | * The response of this request does not have a default interface between environments. |
||
131 | * Pay attention when use this in your project. |
||
132 | */ |
||
133 | public function getEvents( |
||
152 | |||
153 | /** |
||
154 | * @param int $amount |
||
155 | * @param string $description |
||
156 | * @param array $sender |
||
157 | * @param array $recipient |
||
158 | * @param string|null $correlation_id |
||
159 | * @return array|mixed |
||
160 | * @throws RequestException |
||
161 | */ |
||
162 | public function transfer( |
||
185 | |||
186 | /** |
||
187 | * Get transfer funds from an account |
||
188 | * @param string $branch |
||
189 | * @param string $account |
||
190 | * @param int $pageSize |
||
191 | * @param string|null $nextPage |
||
192 | * @return array|mixed |
||
193 | * @throws RequestException |
||
194 | */ |
||
195 | public function getTransferFunds(string $branch, string $account, int $pageSize = 10, string $nextPage = null) |
||
207 | |||
208 | /** |
||
209 | * Get Transfer Funds By Authentication Code |
||
210 | * @param string $branch |
||
211 | * @param string $account |
||
212 | * @param string $authenticationCode |
||
213 | * @return array|mixed |
||
214 | * @throws RequestException |
||
215 | */ |
||
216 | public function findTransferFundByAuthCode(string $branch, string $account, string $authenticationCode) |
||
224 | |||
225 | /** |
||
226 | * @param string $branch |
||
227 | * @param string $account |
||
228 | * @param string $authentication_id |
||
229 | * @return array|mixed |
||
230 | * @throws RequestException |
||
231 | */ |
||
232 | public function getTransferStatus(string $branch, string $account, string $authentication_id) |
||
239 | |||
240 | /** |
||
241 | * @param string $documentNumber |
||
242 | * @param DocumentAnalysis $document |
||
243 | * @param string $correlationId |
||
244 | * @return array|mixed |
||
245 | * @throws RequestException |
||
246 | */ |
||
247 | public function documentAnalysis( |
||
268 | |||
269 | /** |
||
270 | * @param string $documentNumber |
||
271 | * @param array $tokens |
||
272 | * @param string $resultLevel |
||
273 | * @param string $correlationId |
||
274 | * @return array|mixed |
||
275 | */ |
||
276 | public function getDocumentAnalysis( |
||
294 | |||
295 | /** |
||
296 | * @param string $documentNumber |
||
297 | * @param Customer $customer |
||
298 | * @param string $correlationId |
||
299 | * @return array|mixed |
||
300 | * @throws RequestException |
||
301 | */ |
||
302 | public function customer( |
||
313 | |||
314 | /** |
||
315 | * @param string $endpoint |
||
316 | * @param array|null $query |
||
317 | * @param null $correlation_id |
||
318 | * @return array|mixed |
||
319 | * @throws RequestException |
||
320 | */ |
||
321 | private function get(string $endpoint, array $query = null, $correlation_id = null) |
||
337 | |||
338 | /** |
||
339 | * @param string $endpoint |
||
340 | * @param array|null $body |
||
341 | * @param string|null $correlation_id |
||
342 | * @param bool $asJson |
||
343 | * @return array|mixed |
||
344 | * @throws RequestException |
||
345 | */ |
||
346 | private function post(string $endpoint, array $body = null, string $correlation_id = null, bool $asJson = false) |
||
366 | |||
367 | /** |
||
368 | * @param string $endpoint |
||
369 | * @param array|null $body |
||
370 | * @param string|null $correlation_id |
||
371 | * @param bool $asJson |
||
372 | * @param bool $attachment |
||
373 | * @param DocumentAnalysis $document |
||
374 | * @param string $fieldName |
||
375 | * @return array|mixed |
||
376 | * @throws RequestException |
||
377 | */ |
||
378 | private function put( |
||
409 | |||
410 | /** |
||
411 | * @param string $version API version |
||
412 | * @return $this |
||
413 | */ |
||
414 | private function setApiVersion($version = '1.0') |
||
419 | |||
420 | /** |
||
421 | * @param array $headers |
||
422 | * @return array|string[] |
||
423 | */ |
||
424 | private function getHeaders($headers = []) |
||
436 | |||
437 | /** |
||
438 | * @param string $endpoint |
||
439 | * @return bool |
||
440 | */ |
||
441 | private function requireCorrelationId(string $endpoint) |
||
450 | |||
451 | /** |
||
452 | * @param string $endpoint |
||
453 | * @return string |
||
454 | */ |
||
455 | private function getFinalUrl(string $endpoint) |
||
459 | |||
460 | /** |
||
461 | * Do authentication |
||
462 | * @param string $grant_type Default sets to 'client_credentials' |
||
463 | * @throws RequestException |
||
464 | */ |
||
465 | private function auth($grant_type = 'client_credentials'): void |
||
478 | } |
||
479 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: