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 | * @param string[] $cardProxy |
||
| 131 | * @param string|null $begin_date |
||
| 132 | * @param string|null $end_date |
||
| 133 | * @return array|mixed |
||
| 134 | * @throws RequestException |
||
| 135 | * @note This endpoint has been deprecated for some clients. |
||
| 136 | * You need to check with Acesso/Bankly if your environment has different parameters also. |
||
| 137 | * The response of this request does not have a default interface between environments. |
||
| 138 | * Pay attention when use this in your project. |
||
| 139 | */ |
||
| 140 | public function getEvents( |
||
| 175 | |||
| 176 | /** |
||
| 177 | * @param int $amount |
||
| 178 | * @param string $description |
||
| 179 | * @param array $sender |
||
| 180 | * @param array $recipient |
||
| 181 | * @param string|null $correlation_id |
||
| 182 | * @return array|mixed |
||
| 183 | * @throws RequestException |
||
| 184 | */ |
||
| 185 | public function transfer( |
||
| 208 | |||
| 209 | /** |
||
| 210 | * Get transfer funds from an account |
||
| 211 | * @param string $branch |
||
| 212 | * @param string $account |
||
| 213 | * @param int $pageSize |
||
| 214 | * @param string|null $nextPage |
||
| 215 | * @return array|mixed |
||
| 216 | * @throws RequestException |
||
| 217 | */ |
||
| 218 | public function getTransferFunds(string $branch, string $account, int $pageSize = 10, string $nextPage = null) |
||
| 230 | |||
| 231 | /** |
||
| 232 | * Get Transfer Funds By Authentication Code |
||
| 233 | * @param string $branch |
||
| 234 | * @param string $account |
||
| 235 | * @param string $authenticationCode |
||
| 236 | * @return array|mixed |
||
| 237 | * @throws RequestException |
||
| 238 | */ |
||
| 239 | public function findTransferFundByAuthCode(string $branch, string $account, string $authenticationCode) |
||
| 247 | |||
| 248 | /** |
||
| 249 | * @param string $branch |
||
| 250 | * @param string $account |
||
| 251 | * @param string $authentication_id |
||
| 252 | * @return array|mixed |
||
| 253 | * @throws RequestException |
||
| 254 | */ |
||
| 255 | public function getTransferStatus(string $branch, string $account, string $authentication_id) |
||
| 262 | |||
| 263 | /** |
||
| 264 | * @param string $documentNumber |
||
| 265 | * @param DocumentAnalysis $document |
||
| 266 | * @param string $correlationId |
||
| 267 | * @return array|mixed |
||
| 268 | * @throws RequestException |
||
| 269 | */ |
||
| 270 | public function documentAnalysis( |
||
| 291 | |||
| 292 | /** |
||
| 293 | * @param string $documentNumber |
||
| 294 | * @param array $tokens |
||
| 295 | * @param string $resultLevel |
||
| 296 | * @param string $correlationId |
||
| 297 | * @return array|mixed |
||
| 298 | */ |
||
| 299 | public function getDocumentAnalysis( |
||
| 318 | |||
| 319 | /** |
||
| 320 | * @param string $documentNumber |
||
| 321 | * @param Customer $customer |
||
| 322 | * @param string $correlationId |
||
| 323 | * @return array|mixed |
||
| 324 | * @throws RequestException |
||
| 325 | */ |
||
| 326 | public function customer( |
||
| 337 | |||
| 338 | /** |
||
| 339 | * Validate of boleto or dealership |
||
| 340 | * |
||
| 341 | * @param string $code - Digitable line |
||
| 342 | * @param string $correlationId |
||
| 343 | * @return array|mixed |
||
| 344 | * @throws RequestException |
||
| 345 | */ |
||
| 346 | public function paymentValidate(string $code, string $correlationId) |
||
| 350 | |||
| 351 | /** |
||
| 352 | * Confirmation of payment of boleto or dealership |
||
| 353 | * |
||
| 354 | * @param BillPayment $billPayment |
||
| 355 | * @param string $correlationId |
||
| 356 | * @return array|mixed |
||
| 357 | */ |
||
| 358 | public function paymentConfirm( |
||
| 364 | |||
| 365 | /** |
||
| 366 | * Create a new PIX key link with account. |
||
| 367 | * |
||
| 368 | * @param PixEntries $pixEntries |
||
| 369 | * @return array|mixed |
||
| 370 | */ |
||
| 371 | public function registerPixKey(PixEntries $pixEntries) |
||
| 378 | |||
| 379 | /** |
||
| 380 | * Gets the list of address keys linked to an account. |
||
| 381 | * |
||
| 382 | * @param string $accountNumber |
||
| 383 | * @return array|mixed |
||
| 384 | */ |
||
| 385 | public function getPixAddressingKeys(string $accountNumber) |
||
| 389 | |||
| 390 | /** |
||
| 391 | * Gets details of the account linked to an addressing key. |
||
| 392 | * |
||
| 393 | * @param string $documentNumber |
||
| 394 | * @param string $addressinKeyValue |
||
| 395 | * @return array|mixed |
||
| 396 | */ |
||
| 397 | public function getPixAddressingKeyValue(string $documentNumber, string $addressinKeyValue) |
||
| 402 | |||
| 403 | /** |
||
| 404 | * Delete a key link with account. |
||
| 405 | * |
||
| 406 | * @param string $addressingKeyValue |
||
| 407 | * @return array|mixed |
||
| 408 | */ |
||
| 409 | public function deletePixAddressingKeyValue(string $addressingKeyValue) |
||
| 413 | |||
| 414 | /** |
||
| 415 | * @param string $endpoint |
||
| 416 | * @param array|string|null $query |
||
| 417 | * @param null $correlation_id |
||
| 418 | * @return array|mixed |
||
| 419 | * @throws RequestException |
||
| 420 | */ |
||
| 421 | private function get(string $endpoint, $query = null, $correlation_id = null) |
||
| 437 | |||
| 438 | /** |
||
| 439 | * Create a new virtual card |
||
| 440 | * |
||
| 441 | * @param Card $virtualCard |
||
| 442 | * @return array|mixed |
||
| 443 | * @throws RequestException |
||
| 444 | */ |
||
| 445 | public function virtualCard(Card $virtualCard) |
||
| 449 | |||
| 450 | /** |
||
| 451 | * Create a new virtual card |
||
| 452 | * |
||
| 453 | * @param Card $virtualCard |
||
| 454 | * @return array|mixed |
||
| 455 | * @throws RequestException |
||
| 456 | */ |
||
| 457 | public function phisicalCard(Card $phisicalCard) |
||
| 461 | |||
| 462 | /** |
||
| 463 | * @param string $endpoint |
||
| 464 | * @param array|null $body |
||
| 465 | * @param string|null $correlation_id |
||
| 466 | * @param bool $asJson |
||
| 467 | * @return array|mixed |
||
| 468 | * @throws RequestException |
||
| 469 | */ |
||
| 470 | private function post(string $endpoint, array $body = null, string $correlation_id = null, bool $asJson = false) |
||
| 490 | |||
| 491 | /** |
||
| 492 | * @param string $endpoint |
||
| 493 | * @param array|null $body |
||
| 494 | * @param string|null $correlation_id |
||
| 495 | * @param bool $asJson |
||
| 496 | * @param bool $attachment |
||
| 497 | * @param DocumentAnalysis $document |
||
| 498 | * @param string $fieldName |
||
| 499 | * @return array|mixed |
||
| 500 | * @throws RequestException |
||
| 501 | */ |
||
| 502 | private function put( |
||
| 533 | |||
| 534 | /** |
||
| 535 | * Http delete method. |
||
| 536 | * |
||
| 537 | * @param string $endpoint |
||
| 538 | * @return array|mixed |
||
| 539 | * @throws RequestException |
||
| 540 | */ |
||
| 541 | private function delete(string $endpoint) |
||
| 554 | |||
| 555 | /** |
||
| 556 | * @param string $version API version |
||
| 557 | * @return $this |
||
| 558 | */ |
||
| 559 | private function setApiVersion($version = '1.0') |
||
| 564 | |||
| 565 | /** |
||
| 566 | * @param array $headers |
||
| 567 | * @return array|string[] |
||
| 568 | */ |
||
| 569 | private function getHeaders($headers = []) |
||
| 579 | |||
| 580 | /** |
||
| 581 | * @param array $header |
||
| 582 | * @return void |
||
| 583 | */ |
||
| 584 | private function setHeaders($header) |
||
| 588 | |||
| 589 | /** |
||
| 590 | * @param string $endpoint |
||
| 591 | * @return bool |
||
| 592 | */ |
||
| 593 | private function requireCorrelationId(string $endpoint) |
||
| 602 | |||
| 603 | /** |
||
| 604 | * @param string $endpoint |
||
| 605 | * @return string |
||
| 606 | */ |
||
| 607 | private function getFinalUrl(string $endpoint) |
||
| 611 | |||
| 612 | /** |
||
| 613 | * Do authentication |
||
| 614 | * @param string $grant_type Default sets to 'client_credentials' |
||
| 615 | * @throws RequestException |
||
| 616 | */ |
||
| 617 | private function auth($grant_type = 'client_credentials'): void |
||
| 630 | } |
||
| 631 |
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: