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 |
||
| 21 | class Bankly |
||
| 22 | { |
||
| 23 | public $api_url; |
||
| 24 | public $login_url; |
||
| 25 | private $client_id; |
||
| 26 | private $client_secret; |
||
| 27 | private $token_expiry = 0; |
||
| 28 | private $token = null; |
||
| 29 | private $api_version = '1.0'; |
||
| 30 | private $headers; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Bankly constructor. |
||
| 34 | * @param null|string $client_secret provided by Bankly Staff |
||
| 35 | * @param null|string $client_id provided by Bankly Staff |
||
| 36 | */ |
||
| 37 | public function __construct($client_secret = null, $client_id = null) |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @param array|null $credentials |
||
| 47 | * @return $this |
||
| 48 | */ |
||
| 49 | public function setClientCredentials(array $credentials = null) |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @return array|mixed |
||
| 58 | * @throws RequestException |
||
| 59 | */ |
||
| 60 | public function getBankList() |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Retrieve your balance account |
||
| 67 | * @param string $branch |
||
| 68 | * @param string $account |
||
| 69 | * @return array|mixed |
||
| 70 | * @throws RequestException |
||
| 71 | * @note If you have a RequestException on this endpoint in staging environment, please use getAccount() method instead. |
||
| 72 | */ |
||
| 73 | public function getBalance(string $branch, string $account) |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @param string $account |
||
| 84 | * @param string $includeBalance |
||
| 85 | * @return array|mixed |
||
| 86 | * @throws RequestException |
||
| 87 | * @note This method on this date (2020-10-21) works only on staging environment. Contact Bankly/Acesso for more details |
||
| 88 | */ |
||
| 89 | public function getAccount(string $account, string $includeBalance = 'true') |
||
| 95 | |||
| 96 | /** |
||
| 97 | * @param $branch |
||
| 98 | * @param $account |
||
| 99 | * @param int $offset |
||
| 100 | * @param int $limit |
||
| 101 | * @param string $details |
||
| 102 | * @param string $detailsLevelBasic |
||
| 103 | * @return array|mixed |
||
| 104 | * @throws RequestException |
||
| 105 | */ |
||
| 106 | public function getStatement( |
||
| 123 | |||
| 124 | /** |
||
| 125 | * @param string $branch |
||
| 126 | * @param string $account |
||
| 127 | * @param int $page |
||
| 128 | * @param int $pagesize |
||
| 129 | * @param string $include_details |
||
| 130 | * @return array|mixed |
||
| 131 | * @throws RequestException |
||
| 132 | * @note This endpoint has been deprecated for some clients. |
||
| 133 | * You need to check with Acesso/Bankly if your environment has different parameters also. |
||
| 134 | * The response of this request does not have a default interface between environments. |
||
| 135 | * Pay attention when use this in your project. |
||
| 136 | */ |
||
| 137 | public function getEvents( |
||
| 156 | |||
| 157 | /** |
||
| 158 | * @param int $amount |
||
| 159 | * @param string $description |
||
| 160 | * @param array $sender |
||
| 161 | * @param array $recipient |
||
| 162 | * @param string|null $correlation_id |
||
| 163 | * @return array|mixed |
||
| 164 | * @throws RequestException |
||
| 165 | */ |
||
| 166 | public function transfer( |
||
| 189 | |||
| 190 | /** |
||
| 191 | * Get transfer funds from an account |
||
| 192 | * @param string $branch |
||
| 193 | * @param string $account |
||
| 194 | * @param int $pageSize |
||
| 195 | * @param string|null $nextPage |
||
| 196 | * @return array|mixed |
||
| 197 | * @throws RequestException |
||
| 198 | */ |
||
| 199 | public function getTransferFunds(string $branch, string $account, int $pageSize = 10, string $nextPage = null) |
||
| 211 | |||
| 212 | /** |
||
| 213 | * Get Transfer Funds By Authentication Code |
||
| 214 | * @param string $branch |
||
| 215 | * @param string $account |
||
| 216 | * @param string $authenticationCode |
||
| 217 | * @return array|mixed |
||
| 218 | * @throws RequestException |
||
| 219 | */ |
||
| 220 | public function findTransferFundByAuthCode(string $branch, string $account, string $authenticationCode) |
||
| 228 | |||
| 229 | /** |
||
| 230 | * @param string $branch |
||
| 231 | * @param string $account |
||
| 232 | * @param string $authentication_id |
||
| 233 | * @return array|mixed |
||
| 234 | * @throws RequestException |
||
| 235 | */ |
||
| 236 | public function getTransferStatus(string $branch, string $account, string $authentication_id) |
||
| 243 | |||
| 244 | /** |
||
| 245 | * @param string $documentNumber |
||
| 246 | * @param DocumentAnalysis $document |
||
| 247 | * @param string $correlationId |
||
| 248 | * @return array|mixed |
||
| 249 | * @throws RequestException |
||
| 250 | */ |
||
| 251 | public function documentAnalysis( |
||
| 272 | |||
| 273 | /** |
||
| 274 | * @param string $documentNumber |
||
| 275 | * @param array $tokens |
||
| 276 | * @param string $resultLevel |
||
| 277 | * @param string $correlationId |
||
| 278 | * @return array|mixed |
||
| 279 | */ |
||
| 280 | public function getDocumentAnalysis( |
||
| 299 | |||
| 300 | /** |
||
| 301 | * @param string $documentNumber |
||
| 302 | * @param Customer $customer |
||
| 303 | * @param string $correlationId |
||
| 304 | * @return array|mixed |
||
| 305 | * @throws RequestException |
||
| 306 | */ |
||
| 307 | public function customer( |
||
| 318 | |||
| 319 | /** |
||
| 320 | * Validate of boleto or dealership |
||
| 321 | * |
||
| 322 | * @param string $code - Digitable line |
||
| 323 | * @param string $correlationId |
||
| 324 | * @return array|mixed |
||
| 325 | * @throws RequestException |
||
| 326 | */ |
||
| 327 | public function paymentValidate(string $code, string $correlationId) |
||
| 331 | |||
| 332 | /** |
||
| 333 | * Confirmation of payment of boleto or dealership |
||
| 334 | * |
||
| 335 | * @param BillPayment $billPayment |
||
| 336 | * @param string $correlationId |
||
| 337 | * @return array|mixed |
||
| 338 | */ |
||
| 339 | public function paymentConfirm( |
||
| 345 | |||
| 346 | /** |
||
| 347 | * Create a new PIX key link with account. |
||
| 348 | * |
||
| 349 | * @param PixEntries $pixEntries |
||
| 350 | * @return array|mixed |
||
| 351 | */ |
||
| 352 | public function registerPixKey(PixEntries $pixEntries) |
||
| 359 | |||
| 360 | /** |
||
| 361 | * Gets the list of address keys linked to an account. |
||
| 362 | * |
||
| 363 | * @param string $accountNumber |
||
| 364 | * @return array|mixed |
||
| 365 | */ |
||
| 366 | public function getPixAddressingKeys(string $accountNumber) |
||
| 370 | |||
| 371 | /** |
||
| 372 | * Gets details of the account linked to an addressing key. |
||
| 373 | * |
||
| 374 | * @param string $documentNumber |
||
| 375 | * @param string $addressinKeyValue |
||
| 376 | * @return array|mixed |
||
| 377 | */ |
||
| 378 | public function getPixAddressingKeyValue(string $documentNumber, string $addressinKeyValue) |
||
| 383 | |||
| 384 | /** |
||
| 385 | * Delete a key link with account. |
||
| 386 | * |
||
| 387 | * @param string $addressingKeyValue |
||
| 388 | * @return array|mixed |
||
| 389 | */ |
||
| 390 | public function deletePixAddressingKeyValue(string $addressingKeyValue) |
||
| 394 | |||
| 395 | /** |
||
| 396 | * @param string $endpoint |
||
| 397 | * @param array|string|null $query |
||
| 398 | * @param null $correlation_id |
||
| 399 | * @return array|mixed |
||
| 400 | * @throws RequestException |
||
| 401 | */ |
||
| 402 | private function get(string $endpoint, $query = null, $correlation_id = null) |
||
| 418 | |||
| 419 | /** |
||
| 420 | * Create a new virtual card |
||
| 421 | * |
||
| 422 | * @param VirtualCard $virtualCard |
||
| 423 | * @return array|mixed |
||
| 424 | * @throws RequestException |
||
| 425 | */ |
||
| 426 | public function virtualCard(VirtualCard $virtualCard) |
||
| 430 | |||
| 431 | /** |
||
| 432 | * @param string $endpoint |
||
| 433 | * @param array|null $body |
||
| 434 | * @param string|null $correlation_id |
||
| 435 | * @param bool $asJson |
||
| 436 | * @return array|mixed |
||
| 437 | * @throws RequestException |
||
| 438 | */ |
||
| 439 | private function post(string $endpoint, array $body = null, string $correlation_id = null, bool $asJson = false) |
||
| 459 | |||
| 460 | /** |
||
| 461 | * @param string $endpoint |
||
| 462 | * @param array|null $body |
||
| 463 | * @param string|null $correlation_id |
||
| 464 | * @param bool $asJson |
||
| 465 | * @param bool $attachment |
||
| 466 | * @param DocumentAnalysis $document |
||
| 467 | * @param string $fieldName |
||
| 468 | * @return array|mixed |
||
| 469 | * @throws RequestException |
||
| 470 | */ |
||
| 471 | private function put( |
||
| 502 | |||
| 503 | /** |
||
| 504 | * Http delete method. |
||
| 505 | * |
||
| 506 | * @param string $endpoint |
||
| 507 | * @return array|mixed |
||
| 508 | * @throws RequestException |
||
| 509 | */ |
||
| 510 | private function delete(string $endpoint) |
||
| 523 | |||
| 524 | /** |
||
| 525 | * @param string $version API version |
||
| 526 | * @return $this |
||
| 527 | */ |
||
| 528 | private function setApiVersion($version = '1.0') |
||
| 533 | |||
| 534 | /** |
||
| 535 | * @param array $headers |
||
| 536 | * @return array|string[] |
||
| 537 | */ |
||
| 538 | private function getHeaders($headers = []) |
||
| 548 | |||
| 549 | /** |
||
| 550 | * @param array $header |
||
| 551 | * @return void |
||
| 552 | */ |
||
| 553 | private function setHeaders($header) |
||
| 557 | |||
| 558 | /** |
||
| 559 | * @param string $endpoint |
||
| 560 | * @return bool |
||
| 561 | */ |
||
| 562 | private function requireCorrelationId(string $endpoint) |
||
| 571 | |||
| 572 | /** |
||
| 573 | * @param string $endpoint |
||
| 574 | * @return string |
||
| 575 | */ |
||
| 576 | private function getFinalUrl(string $endpoint) |
||
| 580 | |||
| 581 | /** |
||
| 582 | * Do authentication |
||
| 583 | * @param string $grant_type Default sets to 'client_credentials' |
||
| 584 | * @throws RequestException |
||
| 585 | */ |
||
| 586 | private function auth($grant_type = 'client_credentials'): void |
||
| 599 | } |
||
| 600 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: