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 |
||
| 23 | class Bankly |
||
| 24 | { |
||
| 25 | public $api_url; |
||
| 26 | public $login_url; |
||
| 27 | private $client_id; |
||
| 28 | private $client_secret; |
||
| 29 | private $token_expiry = 0; |
||
| 30 | private $token = null; |
||
| 31 | private $api_version = '1.0'; |
||
| 32 | private $headers; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Bankly constructor. |
||
| 36 | * @param null|string $client_secret provided by Bankly Staff |
||
| 37 | * @param null|string $client_id provided by Bankly Staff |
||
| 38 | */ |
||
| 39 | public function __construct($client_secret = null, $client_id = null) |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @param array|null $credentials |
||
| 49 | * @return $this |
||
| 50 | */ |
||
| 51 | public function setClientCredentials(array $credentials = null) |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @return array|mixed |
||
| 60 | * @throws RequestException |
||
| 61 | */ |
||
| 62 | public function getBankList() |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Retrieve your balance account |
||
| 69 | * @param string $branch |
||
| 70 | * @param string $account |
||
| 71 | * @return array|mixed |
||
| 72 | * @throws RequestException |
||
| 73 | * @note If you have a RequestException on this endpoint in staging environment, please use getAccount() method instead. |
||
| 74 | */ |
||
| 75 | public function getBalance(string $branch, string $account) |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @param string $account |
||
| 86 | * @param string $includeBalance |
||
| 87 | * @return array|mixed |
||
| 88 | * @throws RequestException |
||
| 89 | * @note This method on this date (2020-10-21) works only on staging environment. Contact Bankly/Acesso for more details |
||
| 90 | */ |
||
| 91 | public function getAccount(string $account, string $includeBalance = 'true') |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @param $branch |
||
| 100 | * @param $account |
||
| 101 | * @param int $offset |
||
| 102 | * @param int $limit |
||
| 103 | * @param string $details |
||
| 104 | * @param string $detailsLevelBasic |
||
| 105 | * @return array|mixed |
||
| 106 | * @throws RequestException |
||
| 107 | */ |
||
| 108 | public function getStatement( |
||
| 125 | |||
| 126 | /** |
||
| 127 | * @param string $branch |
||
| 128 | * @param string $account |
||
| 129 | * @param int $page |
||
| 130 | * @param int $pagesize |
||
| 131 | * @param string $include_details |
||
| 132 | * @param string[] $cardProxy |
||
| 133 | * @param string|null $begin_date |
||
| 134 | * @param string|null $end_date |
||
| 135 | * @return array|mixed |
||
| 136 | * @throws RequestException |
||
| 137 | * @note This endpoint has been deprecated for some clients. |
||
| 138 | * You need to check with Acesso/Bankly if your environment has different parameters also. |
||
| 139 | * The response of this request does not have a default interface between environments. |
||
| 140 | * Pay attention when use this in your project. |
||
| 141 | */ |
||
| 142 | public function getEvents( |
||
| 177 | |||
| 178 | /** |
||
| 179 | * @param int $amount |
||
| 180 | * @param string $description |
||
| 181 | * @param array $sender |
||
| 182 | * @param array $recipient |
||
| 183 | * @param string|null $correlation_id |
||
| 184 | * @return array|mixed |
||
| 185 | * @throws RequestException |
||
| 186 | */ |
||
| 187 | public function transfer( |
||
| 210 | |||
| 211 | /** |
||
| 212 | * Get transfer funds from an account |
||
| 213 | * @param string $branch |
||
| 214 | * @param string $account |
||
| 215 | * @param int $pageSize |
||
| 216 | * @param string|null $nextPage |
||
| 217 | * @return array|mixed |
||
| 218 | * @throws RequestException |
||
| 219 | */ |
||
| 220 | public function getTransferFunds(string $branch, string $account, int $pageSize = 10, string $nextPage = null) |
||
| 232 | |||
| 233 | /** |
||
| 234 | * Get Transfer Funds By Authentication Code |
||
| 235 | * @param string $branch |
||
| 236 | * @param string $account |
||
| 237 | * @param string $authenticationCode |
||
| 238 | * @return array|mixed |
||
| 239 | * @throws RequestException |
||
| 240 | */ |
||
| 241 | public function findTransferFundByAuthCode(string $branch, string $account, string $authenticationCode) |
||
| 249 | |||
| 250 | /** |
||
| 251 | * @param string $branch |
||
| 252 | * @param string $account |
||
| 253 | * @param string $authentication_id |
||
| 254 | * @return array|mixed |
||
| 255 | * @throws RequestException |
||
| 256 | */ |
||
| 257 | public function getTransferStatus(string $branch, string $account, string $authentication_id) |
||
| 264 | |||
| 265 | /** |
||
| 266 | * @param string $documentNumber |
||
| 267 | * @param DocumentAnalysis $document |
||
| 268 | * @param string $correlationId |
||
| 269 | * @return array|mixed |
||
| 270 | * @throws RequestException |
||
| 271 | */ |
||
| 272 | public function documentAnalysis( |
||
| 293 | |||
| 294 | /** |
||
| 295 | * @param string $documentNumber |
||
| 296 | * @param array $tokens |
||
| 297 | * @param string $resultLevel |
||
| 298 | * @param string $correlationId |
||
| 299 | * @return array|mixed |
||
| 300 | */ |
||
| 301 | public function getDocumentAnalysis( |
||
| 320 | |||
| 321 | /** |
||
| 322 | * @param string $documentNumber |
||
| 323 | * @param Customer $customer |
||
| 324 | * @param string $correlationId |
||
| 325 | * @return array|mixed |
||
| 326 | * @throws RequestException |
||
| 327 | */ |
||
| 328 | public function customer( |
||
| 339 | |||
| 340 | /** |
||
| 341 | * Validate of boleto or dealership |
||
| 342 | * |
||
| 343 | * @param string $code - Digitable line |
||
| 344 | * @param string $correlationId |
||
| 345 | * @return array|mixed |
||
| 346 | * @throws RequestException |
||
| 347 | */ |
||
| 348 | public function paymentValidate(string $code, string $correlationId) |
||
| 352 | |||
| 353 | /** |
||
| 354 | * Confirmation of payment of boleto or dealership |
||
| 355 | * |
||
| 356 | * @param BillPayment $billPayment |
||
| 357 | * @param string $correlationId |
||
| 358 | * @return array|mixed |
||
| 359 | */ |
||
| 360 | public function paymentConfirm( |
||
| 366 | |||
| 367 | /** |
||
| 368 | * @param DepositBillet $depositBillet |
||
| 369 | * @return array|mixed |
||
| 370 | */ |
||
| 371 | public function depositBillet(DepositBillet $depositBillet) |
||
| 375 | |||
| 376 | /** |
||
| 377 | * @param string $authenticationCode |
||
| 378 | * @return mixed |
||
| 379 | */ |
||
| 380 | public function printBillet(string $authenticationCode) |
||
| 384 | |||
| 385 | /** |
||
| 386 | * @param string $branch |
||
| 387 | * @param string $accountNumber |
||
| 388 | * @param string $authenticationCode |
||
| 389 | * @return array|mixed |
||
| 390 | */ |
||
| 391 | public function getBillet(string $branch, string $accountNumber, string $authenticationCode) |
||
| 395 | |||
| 396 | /** |
||
| 397 | * @param string $datetime |
||
| 398 | * @return array|mixed |
||
| 399 | */ |
||
| 400 | public function getBilletByDate(string $datetime) |
||
| 404 | |||
| 405 | /** |
||
| 406 | * @param string $barcode |
||
| 407 | * @return array|mixed |
||
| 408 | */ |
||
| 409 | public function getBilletByBarcode(string $barcode) |
||
| 413 | |||
| 414 | /** |
||
| 415 | * Create a new PIX key link with account. |
||
| 416 | * |
||
| 417 | * @param PixEntries $pixEntries |
||
| 418 | * @return array|mixed |
||
| 419 | */ |
||
| 420 | public function registerPixKey(PixEntries $pixEntries) |
||
| 427 | |||
| 428 | /** |
||
| 429 | * Gets the list of address keys linked to an account. |
||
| 430 | * |
||
| 431 | * @param string $accountNumber |
||
| 432 | * @return array|mixed |
||
| 433 | */ |
||
| 434 | public function getPixAddressingKeys(string $accountNumber) |
||
| 438 | |||
| 439 | /** |
||
| 440 | * Gets details of the account linked to an addressing key. |
||
| 441 | * |
||
| 442 | * @param string $documentNumber |
||
| 443 | * @param string $addressinKeyValue |
||
| 444 | * @return array|mixed |
||
| 445 | */ |
||
| 446 | public function getPixAddressingKeyValue(string $documentNumber, string $addressinKeyValue) |
||
| 451 | |||
| 452 | /** |
||
| 453 | * Delete a key link with account. |
||
| 454 | * |
||
| 455 | * @param string $addressingKeyValue |
||
| 456 | * @return array|mixed |
||
| 457 | */ |
||
| 458 | public function deletePixAddressingKeyValue(string $addressingKeyValue) |
||
| 462 | |||
| 463 | /** |
||
| 464 | * @param PixCashoutInterface $pixCashout |
||
| 465 | * @param string $correlationId |
||
| 466 | * @return array|mixed |
||
| 467 | */ |
||
| 468 | public function pixCashout(PixCashoutInterface $pixCashout, string $correlationId) |
||
| 472 | |||
| 473 | /** |
||
| 474 | * @param string $endpoint |
||
| 475 | * @param array|string|null $query |
||
| 476 | * @param null $correlation_id |
||
| 477 | * @return array|mixed |
||
| 478 | * @throws RequestException |
||
| 479 | */ |
||
| 480 | private function get(string $endpoint, $query = null, $correlation_id = null) |
||
| 496 | |||
| 497 | /** |
||
| 498 | * Create a new virtual card |
||
| 499 | * |
||
| 500 | * @param Card $virtualCard |
||
| 501 | * @return array|mixed |
||
| 502 | * @throws RequestException |
||
| 503 | */ |
||
| 504 | public function virtualCard(Card $virtualCard) |
||
| 508 | |||
| 509 | /** |
||
| 510 | * Create a new virtual card |
||
| 511 | * |
||
| 512 | * @param Card $virtualCard |
||
| 513 | * @return array|mixed |
||
| 514 | * @throws RequestException |
||
| 515 | */ |
||
| 516 | public function phisicalCard(Card $phisicalCard) |
||
| 520 | |||
| 521 | /** |
||
| 522 | * @param string $endpoint |
||
| 523 | * @param array|null $body |
||
| 524 | * @param string|null $correlation_id |
||
| 525 | * @param bool $asJson |
||
| 526 | * @return array|mixed |
||
| 527 | * @throws RequestException |
||
| 528 | */ |
||
| 529 | private function post(string $endpoint, array $body = null, string $correlation_id = null, bool $asJson = false) |
||
| 549 | |||
| 550 | /** |
||
| 551 | * @param string $endpoint |
||
| 552 | * @param array|null $body |
||
| 553 | * @param string|null $correlation_id |
||
| 554 | * @param bool $asJson |
||
| 555 | * @param bool $attachment |
||
| 556 | * @param DocumentAnalysis $document |
||
| 557 | * @param string $fieldName |
||
| 558 | * @return array|mixed |
||
| 559 | * @throws RequestException |
||
| 560 | */ |
||
| 561 | private function put( |
||
| 592 | |||
| 593 | /** |
||
| 594 | * Http delete method. |
||
| 595 | * |
||
| 596 | * @param string $endpoint |
||
| 597 | * @return array|mixed |
||
| 598 | * @throws RequestException |
||
| 599 | */ |
||
| 600 | private function delete(string $endpoint) |
||
| 613 | |||
| 614 | /** |
||
| 615 | * @param string $version API version |
||
| 616 | * @return $this |
||
| 617 | */ |
||
| 618 | private function setApiVersion($version = '1.0') |
||
| 623 | |||
| 624 | /** |
||
| 625 | * @param array $headers |
||
| 626 | * @return array|string[] |
||
| 627 | */ |
||
| 628 | private function getHeaders($headers = []) |
||
| 638 | |||
| 639 | /** |
||
| 640 | * @param array $header |
||
| 641 | * @return void |
||
| 642 | */ |
||
| 643 | private function setHeaders($header) |
||
| 647 | |||
| 648 | /** |
||
| 649 | * @param string $endpoint |
||
| 650 | * @return bool |
||
| 651 | */ |
||
| 652 | private function requireCorrelationId(string $endpoint) |
||
| 661 | |||
| 662 | /** |
||
| 663 | * @param string $endpoint |
||
| 664 | * @return string |
||
| 665 | */ |
||
| 666 | private function getFinalUrl(string $endpoint) |
||
| 670 | |||
| 671 | /** |
||
| 672 | * Do authentication |
||
| 673 | * @param string $grant_type Default sets to 'client_credentials' |
||
| 674 | * @throws RequestException |
||
| 675 | */ |
||
| 676 | private function auth($grant_type = 'client_credentials'): void |
||
| 689 | } |
||
| 690 |
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: