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 |
||
| 20 | class Bankly |
||
| 21 | { |
||
| 22 | public $api_url; |
||
| 23 | public $login_url; |
||
| 24 | private $client_id; |
||
| 25 | private $client_secret; |
||
| 26 | private $token_expiry = 0; |
||
| 27 | private $token = null; |
||
| 28 | private $api_version = '1.0'; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Bankly constructor. |
||
| 32 | * @param null|string $client_secret provided by Bankly Staff |
||
| 33 | * @param null|string $client_id provided by Bankly Staff |
||
| 34 | */ |
||
| 35 | public function __construct($client_secret = null, $client_id = null) |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @param array|null $credentials |
||
| 44 | * @return $this |
||
| 45 | */ |
||
| 46 | public function setClientCredentials(array $credentials = null) |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @return array|mixed |
||
| 55 | * @throws RequestException |
||
| 56 | */ |
||
| 57 | public function getBankList() |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Retrieve your balance account |
||
| 64 | * @param string $branch |
||
| 65 | * @param string $account |
||
| 66 | * @return array|mixed |
||
| 67 | * @throws RequestException |
||
| 68 | * @note If you have a RequestException on this endpoint in staging environment, please use getAccount() method instead. |
||
| 69 | */ |
||
| 70 | public function getBalance(string $branch, string $account) |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @param string $account |
||
| 81 | * @param string $includeBalance |
||
| 82 | * @return array|mixed |
||
| 83 | * @throws RequestException |
||
| 84 | * @note This method on this date (2020-10-21) works only on staging environment. Contact Bankly/Acesso for more details |
||
| 85 | */ |
||
| 86 | public function getAccount(string $account, string $includeBalance = 'true') |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @param $branch |
||
| 95 | * @param $account |
||
| 96 | * @param int $offset |
||
| 97 | * @param int $limit |
||
| 98 | * @param string $details |
||
| 99 | * @param string $detailsLevelBasic |
||
| 100 | * @return array|mixed |
||
| 101 | * @throws RequestException |
||
| 102 | */ |
||
| 103 | public function getStatement( |
||
| 120 | |||
| 121 | /** |
||
| 122 | * @param string $branch |
||
| 123 | * @param string $account |
||
| 124 | * @param int $page |
||
| 125 | * @param int $pagesize |
||
| 126 | * @param string $include_details |
||
| 127 | * @return array|mixed |
||
| 128 | * @throws RequestException |
||
| 129 | * @note This endpoint has been deprecated for some clients. |
||
| 130 | * You need to check with Acesso/Bankly if your environment has different parameters also. |
||
| 131 | * The response of this request does not have a default interface between environments. |
||
| 132 | * Pay attention when use this in your project. |
||
| 133 | */ |
||
| 134 | public function getEvents( |
||
| 153 | |||
| 154 | /** |
||
| 155 | * @param int $amount |
||
| 156 | * @param string $description |
||
| 157 | * @param array $sender |
||
| 158 | * @param array $recipient |
||
| 159 | * @param string|null $correlation_id |
||
| 160 | * @return array|mixed |
||
| 161 | * @throws RequestException |
||
| 162 | */ |
||
| 163 | public function transfer( |
||
| 186 | |||
| 187 | /** |
||
| 188 | * Get transfer funds from an account |
||
| 189 | * @param string $branch |
||
| 190 | * @param string $account |
||
| 191 | * @param int $pageSize |
||
| 192 | * @param string|null $nextPage |
||
| 193 | * @return array|mixed |
||
| 194 | * @throws RequestException |
||
| 195 | */ |
||
| 196 | public function getTransferFunds(string $branch, string $account, int $pageSize = 10, string $nextPage = null) |
||
| 208 | |||
| 209 | /** |
||
| 210 | * Get Transfer Funds By Authentication Code |
||
| 211 | * @param string $branch |
||
| 212 | * @param string $account |
||
| 213 | * @param string $authenticationCode |
||
| 214 | * @return array|mixed |
||
| 215 | * @throws RequestException |
||
| 216 | */ |
||
| 217 | public function findTransferFundByAuthCode(string $branch, string $account, string $authenticationCode) |
||
| 225 | |||
| 226 | /** |
||
| 227 | * @param string $branch |
||
| 228 | * @param string $account |
||
| 229 | * @param string $authentication_id |
||
| 230 | * @return array|mixed |
||
| 231 | * @throws RequestException |
||
| 232 | */ |
||
| 233 | public function getTransferStatus(string $branch, string $account, string $authentication_id) |
||
| 240 | |||
| 241 | /** |
||
| 242 | * @param string $documentNumber |
||
| 243 | * @param DocumentAnalysis $document |
||
| 244 | * @param string $correlationId |
||
| 245 | * @return array|mixed |
||
| 246 | * @throws RequestException |
||
| 247 | */ |
||
| 248 | public function documentAnalysis( |
||
| 269 | |||
| 270 | /** |
||
| 271 | * @param string $documentNumber |
||
| 272 | * @param array $tokens |
||
| 273 | * @param string $resultLevel |
||
| 274 | * @param string $correlationId |
||
| 275 | * @return array|mixed |
||
| 276 | */ |
||
| 277 | public function getDocumentAnalysis( |
||
| 295 | |||
| 296 | /** |
||
| 297 | * @param string $documentNumber |
||
| 298 | * @param Customer $customer |
||
| 299 | * @param string $correlationId |
||
| 300 | * @return array|mixed |
||
| 301 | * @throws RequestException |
||
| 302 | */ |
||
| 303 | public function customer( |
||
| 314 | |||
| 315 | /** |
||
| 316 | * Validate of boleto or dealership |
||
| 317 | * |
||
| 318 | * @param string $code - Digitable line |
||
| 319 | * @param string $correlationId |
||
| 320 | * @return array|mixed |
||
| 321 | * @throws RequestException |
||
| 322 | */ |
||
| 323 | public function paymentValidate(string $code, string $correlationId) |
||
| 327 | |||
| 328 | /** |
||
| 329 | * Confirmation of payment of boleto or dealership |
||
| 330 | * |
||
| 331 | * @param BillPayment $billPayment |
||
| 332 | * @param string $correlationId |
||
| 333 | * @return array|mixed |
||
| 334 | */ |
||
| 335 | public function paymentConfirm( |
||
| 341 | |||
| 342 | /** |
||
| 343 | * @param string $endpoint |
||
| 344 | * @param array|null $query |
||
| 345 | * @param null $correlation_id |
||
| 346 | * @return array|mixed |
||
| 347 | * @throws RequestException |
||
| 348 | */ |
||
| 349 | private function get(string $endpoint, array $query = null, $correlation_id = null) |
||
| 365 | |||
| 366 | /** |
||
| 367 | * Create a new virtual card |
||
| 368 | * |
||
| 369 | * @param VirtualCard $virtualCard |
||
| 370 | * @return array|mixed |
||
| 371 | * @throws RequestException |
||
| 372 | */ |
||
| 373 | public function virtualCard(VirtualCard $virtualCard) |
||
| 377 | |||
| 378 | /** |
||
| 379 | * @param string $endpoint |
||
| 380 | * @param array|null $body |
||
| 381 | * @param string|null $correlation_id |
||
| 382 | * @param bool $asJson |
||
| 383 | * @return array|mixed |
||
| 384 | * @throws RequestException |
||
| 385 | */ |
||
| 386 | private function post(string $endpoint, array $body = null, string $correlation_id = null, bool $asJson = false) |
||
| 406 | |||
| 407 | /** |
||
| 408 | * @param string $endpoint |
||
| 409 | * @param array|null $body |
||
| 410 | * @param string|null $correlation_id |
||
| 411 | * @param bool $asJson |
||
| 412 | * @param bool $attachment |
||
| 413 | * @param DocumentAnalysis $document |
||
| 414 | * @param string $fieldName |
||
| 415 | * @return array|mixed |
||
| 416 | * @throws RequestException |
||
| 417 | */ |
||
| 418 | private function put( |
||
| 449 | |||
| 450 | /** |
||
| 451 | * @param string $version API version |
||
| 452 | * @return $this |
||
| 453 | */ |
||
| 454 | private function setApiVersion($version = '1.0') |
||
| 459 | |||
| 460 | /** |
||
| 461 | * @param array $headers |
||
| 462 | * @return array|string[] |
||
| 463 | */ |
||
| 464 | private function getHeaders($headers = []) |
||
| 476 | |||
| 477 | /** |
||
| 478 | * @param string $endpoint |
||
| 479 | * @return bool |
||
| 480 | */ |
||
| 481 | private function requireCorrelationId(string $endpoint) |
||
| 490 | |||
| 491 | /** |
||
| 492 | * @param string $endpoint |
||
| 493 | * @return string |
||
| 494 | */ |
||
| 495 | private function getFinalUrl(string $endpoint) |
||
| 499 | |||
| 500 | /** |
||
| 501 | * Do authentication |
||
| 502 | * @param string $grant_type Default sets to 'client_credentials' |
||
| 503 | * @throws RequestException |
||
| 504 | */ |
||
| 505 | private function auth($grant_type = 'client_credentials'): void |
||
| 518 | } |
||
| 519 |
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: