| Total Complexity | 57 |
| Total Lines | 594 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like Client 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.
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 Client, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 17 | class Client { |
||
| 18 | /** |
||
| 19 | * Gateway URL |
||
| 20 | * |
||
| 21 | * @var string |
||
| 22 | */ |
||
| 23 | const GATEWAY_URL = 'https://checkout.buckaroo.nl/html/'; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Gateway test URL |
||
| 27 | * |
||
| 28 | * @var string |
||
| 29 | */ |
||
| 30 | const GATEWAY_TEST_URL = 'https://testcheckout.buckaroo.nl/html/'; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Gateway Name-Value-Pair URL |
||
| 34 | * |
||
| 35 | * @var string |
||
| 36 | */ |
||
| 37 | const GATEWAY_NVP_URL = 'https://checkout.buckaroo.nl/nvp/'; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Gateway Name-Value-Pair test URL |
||
| 41 | * |
||
| 42 | * @var string |
||
| 43 | */ |
||
| 44 | const GATEWAY_NVP_TEST_URL = 'https://testcheckout.buckaroo.nl/nvp/'; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Indicator for the iDEAL payment method |
||
| 48 | * |
||
| 49 | * @var string |
||
| 50 | */ |
||
| 51 | const PAYMENT_METHOD_IDEAL = 'ideal'; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * The payment server URL |
||
| 55 | * |
||
| 56 | * @var string |
||
| 57 | */ |
||
| 58 | private $payment_server_url; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * The amount |
||
| 62 | * |
||
| 63 | * @var int |
||
| 64 | */ |
||
| 65 | private $amount; |
||
| 66 | |||
| 67 | /** |
||
| 68 | * The website key |
||
| 69 | * |
||
| 70 | * @var string |
||
| 71 | */ |
||
| 72 | private $website_key; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * The secret key |
||
| 76 | * |
||
| 77 | * @var string |
||
| 78 | */ |
||
| 79 | private $secret_key; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * The payment method |
||
| 83 | * |
||
| 84 | * @var string |
||
| 85 | */ |
||
| 86 | private $payment_method; |
||
| 87 | |||
| 88 | /** |
||
| 89 | * The iDEAL issuer |
||
| 90 | * |
||
| 91 | * @since 1.2.4 |
||
| 92 | * @var string |
||
| 93 | */ |
||
| 94 | private $ideal_issuer; |
||
| 95 | |||
| 96 | /** |
||
| 97 | * The country code (culture) |
||
| 98 | * |
||
| 99 | * @var string |
||
| 100 | */ |
||
| 101 | private $culture; |
||
| 102 | |||
| 103 | /** |
||
| 104 | * The currency |
||
| 105 | * |
||
| 106 | * @var string |
||
| 107 | */ |
||
| 108 | private $currency; |
||
| 109 | |||
| 110 | /** |
||
| 111 | * The invoice number |
||
| 112 | * |
||
| 113 | * @var string |
||
| 114 | */ |
||
| 115 | private $invoice_number; |
||
| 116 | |||
| 117 | /** |
||
| 118 | * The description |
||
| 119 | * |
||
| 120 | * @var string |
||
| 121 | */ |
||
| 122 | private $description; |
||
| 123 | |||
| 124 | /** |
||
| 125 | * The return url |
||
| 126 | * |
||
| 127 | * @var string |
||
| 128 | */ |
||
| 129 | private $return_url; |
||
| 130 | |||
| 131 | /** |
||
| 132 | * The return reject url |
||
| 133 | * |
||
| 134 | * @var string |
||
| 135 | */ |
||
| 136 | private $return_reject_url; |
||
| 137 | |||
| 138 | /** |
||
| 139 | * The return error url |
||
| 140 | * |
||
| 141 | * @var string |
||
| 142 | */ |
||
| 143 | private $return_error_url; |
||
| 144 | |||
| 145 | /** |
||
| 146 | * The return cancel url |
||
| 147 | * |
||
| 148 | * @var string |
||
| 149 | */ |
||
| 150 | private $return_cancel_url; |
||
| 151 | |||
| 152 | /** |
||
| 153 | * Push URL |
||
| 154 | * |
||
| 155 | * @var string |
||
| 156 | */ |
||
| 157 | private $push_url; |
||
| 158 | |||
| 159 | /** |
||
| 160 | * Requested services |
||
| 161 | * |
||
| 162 | * @var array |
||
| 163 | */ |
||
| 164 | private $requested_services; |
||
| 165 | |||
| 166 | /** |
||
| 167 | * Excluded services |
||
| 168 | * |
||
| 169 | * @var array |
||
| 170 | */ |
||
| 171 | private $excluded_services; |
||
| 172 | |||
| 173 | /** |
||
| 174 | * Pronamic payment ID |
||
| 175 | * |
||
| 176 | * @var array |
||
| 177 | */ |
||
| 178 | private $payment_id; |
||
| 179 | |||
| 180 | /** |
||
| 181 | * Error. |
||
| 182 | * |
||
| 183 | * @since 1.2.6 |
||
| 184 | * @var WP_Error |
||
| 185 | */ |
||
| 186 | private $error; |
||
| 187 | |||
| 188 | /** |
||
| 189 | * Constructs and initialize a iDEAL kassa object |
||
| 190 | */ |
||
| 191 | public function __construct() { |
||
| 192 | $this->set_payment_server_url( self::GATEWAY_URL ); |
||
| 193 | |||
| 194 | $this->requested_services = array(); |
||
| 195 | } |
||
| 196 | |||
| 197 | /** |
||
| 198 | * Get error. |
||
| 199 | * |
||
| 200 | * @since 1.2.6 |
||
| 201 | * @return WP_Error |
||
| 202 | */ |
||
| 203 | public function get_error() { |
||
| 204 | return $this->error; |
||
| 205 | } |
||
| 206 | |||
| 207 | /** |
||
| 208 | * Get the payment server URL |
||
| 209 | * |
||
| 210 | * @return string the payment server URL |
||
| 211 | */ |
||
| 212 | public function get_payment_server_url() { |
||
| 213 | return $this->payment_server_url; |
||
| 214 | } |
||
| 215 | |||
| 216 | /** |
||
| 217 | * Set the payment server URL |
||
| 218 | * |
||
| 219 | * @param string $url an URL |
||
| 220 | */ |
||
| 221 | public function set_payment_server_url( $url ) { |
||
| 222 | $this->payment_server_url = $url; |
||
| 223 | } |
||
| 224 | |||
| 225 | public function get_website_key() { |
||
| 226 | return $this->website_key; |
||
| 227 | } |
||
| 228 | |||
| 229 | public function set_website_key( $website_key ) { |
||
| 230 | $this->website_key = $website_key; |
||
| 231 | } |
||
| 232 | |||
| 233 | public function get_secret_key() { |
||
| 234 | return $this->secret_key; |
||
| 235 | } |
||
| 236 | |||
| 237 | public function set_secret_key( $secret_key ) { |
||
| 238 | $this->secret_key = $secret_key; |
||
| 239 | } |
||
| 240 | |||
| 241 | public function get_payment_method() { |
||
| 242 | return $this->payment_method; |
||
| 243 | } |
||
| 244 | |||
| 245 | public function set_payment_method( $payment_method ) { |
||
| 246 | $this->payment_method = $payment_method; |
||
| 247 | } |
||
| 248 | |||
| 249 | /** |
||
| 250 | * Get iDEAL issuer. |
||
| 251 | * |
||
| 252 | * @since 1.2.4 |
||
| 253 | * @return string |
||
| 254 | */ |
||
| 255 | public function get_ideal_issuer() { |
||
| 256 | return $this->ideal_issuer; |
||
| 257 | } |
||
| 258 | |||
| 259 | /** |
||
| 260 | * Set iDEAL issuer. |
||
| 261 | * |
||
| 262 | * @since 1.2.4 |
||
| 263 | * |
||
| 264 | * @param string $issuer |
||
| 265 | */ |
||
| 266 | public function set_ideal_issuer( $issuer ) { |
||
| 268 | } |
||
| 269 | |||
| 270 | public function get_requested_services() { |
||
| 271 | return $this->requested_services; |
||
| 272 | } |
||
| 273 | |||
| 274 | public function add_requested_service( $service ) { |
||
| 275 | $this->requested_services[] = $service; |
||
| 276 | } |
||
| 277 | |||
| 278 | public function get_excluded_services() { |
||
| 279 | return $this->excluded_services; |
||
| 280 | } |
||
| 281 | |||
| 282 | public function set_excluded_services( $service ) { |
||
| 284 | } |
||
| 285 | |||
| 286 | public function get_culture() { |
||
| 287 | return $this->culture; |
||
| 288 | } |
||
| 289 | |||
| 290 | public function set_culture( $culture ) { |
||
| 291 | $this->culture = $culture; |
||
| 292 | } |
||
| 293 | |||
| 294 | public function get_currency() { |
||
| 295 | return $this->currency; |
||
| 296 | } |
||
| 297 | |||
| 298 | public function set_currency( $currency ) { |
||
| 299 | $this->currency = $currency; |
||
| 300 | } |
||
| 301 | |||
| 302 | public function get_invoice_number() { |
||
| 303 | return $this->invoice_number; |
||
| 304 | } |
||
| 305 | |||
| 306 | public function set_invoice_number( $invoice_number ) { |
||
| 308 | } |
||
| 309 | |||
| 310 | public function get_description() { |
||
| 311 | return $this->description; |
||
| 312 | } |
||
| 313 | |||
| 314 | public function set_description( $description ) { |
||
| 315 | $this->description = $description; |
||
| 316 | } |
||
| 317 | |||
| 318 | /** |
||
| 319 | * Get amount. |
||
| 320 | * |
||
| 321 | * @return int |
||
| 322 | */ |
||
| 323 | public function get_amount() { |
||
| 324 | return $this->amount; |
||
| 325 | } |
||
| 326 | |||
| 327 | /** |
||
| 328 | * Set amount. |
||
| 329 | * |
||
| 330 | * @param int $amount Amount. |
||
| 331 | */ |
||
| 332 | public function set_amount( $amount ) { |
||
| 334 | } |
||
| 335 | |||
| 336 | /** |
||
| 337 | * Get return URL |
||
| 338 | * |
||
| 339 | * @return string |
||
| 340 | */ |
||
| 341 | public function get_return_url() { |
||
| 342 | return $this->return_url; |
||
| 343 | } |
||
| 344 | |||
| 345 | /** |
||
| 346 | * Set return URL |
||
| 347 | * |
||
| 348 | * @param string $url Return URL. |
||
| 349 | */ |
||
| 350 | public function set_return_url( $url ) { |
||
| 351 | $this->return_url = $url; |
||
| 352 | } |
||
| 353 | |||
| 354 | /** |
||
| 355 | * Get return reject URL |
||
| 356 | * |
||
| 357 | * @return string |
||
| 358 | */ |
||
| 359 | public function get_return_reject_url() { |
||
| 360 | return $this->return_reject_url; |
||
| 361 | } |
||
| 362 | |||
| 363 | /** |
||
| 364 | * Set return reject URL |
||
| 365 | * |
||
| 366 | * @param string $url Return reject URL. |
||
| 367 | */ |
||
| 368 | public function set_return_reject_url( $url ) { |
||
| 369 | $this->return_reject_url = $url; |
||
| 370 | } |
||
| 371 | |||
| 372 | /** |
||
| 373 | * Get return error URL |
||
| 374 | * |
||
| 375 | * @return string |
||
| 376 | */ |
||
| 377 | public function get_return_error_url() { |
||
| 378 | return $this->return_error_url; |
||
| 379 | } |
||
| 380 | |||
| 381 | /** |
||
| 382 | * Set return error URL |
||
| 383 | * |
||
| 384 | * @param string $url Return error URL. |
||
| 385 | */ |
||
| 386 | public function set_return_error_url( $url ) { |
||
| 387 | $this->return_error_url = $url; |
||
| 388 | } |
||
| 389 | |||
| 390 | /** |
||
| 391 | * Get return cancel URL |
||
| 392 | * |
||
| 393 | * @return string |
||
| 394 | */ |
||
| 395 | public function get_return_cancel_url() { |
||
| 396 | return $this->return_cancel_url; |
||
| 397 | } |
||
| 398 | |||
| 399 | /** |
||
| 400 | * Set return cancel URL |
||
| 401 | * |
||
| 402 | * @param string $url Return cancel URL. |
||
| 403 | */ |
||
| 404 | public function set_return_cancel_url( $url ) { |
||
| 405 | $this->return_cancel_url = $url; |
||
| 406 | } |
||
| 407 | |||
| 408 | /** |
||
| 409 | * Get push URL |
||
| 410 | * |
||
| 411 | * @return string |
||
| 412 | */ |
||
| 413 | public function get_push_url() { |
||
| 414 | return $this->push_url; |
||
| 415 | } |
||
| 416 | |||
| 417 | /** |
||
| 418 | * Set push URL |
||
| 419 | * |
||
| 420 | * @param string $url Push URL. |
||
| 421 | */ |
||
| 422 | public function set_push_url( $url ) { |
||
| 423 | $this->push_url = $url; |
||
| 424 | } |
||
| 425 | |||
| 426 | /** |
||
| 427 | * Get Pronamic payment ID |
||
| 428 | * |
||
| 429 | * @return string |
||
| 430 | */ |
||
| 431 | public function get_payment_id() { |
||
| 432 | return $this->payment_id; |
||
| 433 | } |
||
| 434 | |||
| 435 | /** |
||
| 436 | * Set Pronamic payment ID |
||
| 437 | * |
||
| 438 | * @param string $payment_id Payment ID. |
||
| 439 | */ |
||
| 440 | public function set_payment_id( $payment_id ) { |
||
| 442 | } |
||
| 443 | |||
| 444 | /** |
||
| 445 | * Get issuers |
||
| 446 | * |
||
| 447 | * @since 1.2.4 |
||
| 448 | * @link http://support.buckaroo.nl/index.php/Service_iDEAL#iDEAL_banken_lijst_opvragen |
||
| 449 | * @return array |
||
| 450 | */ |
||
| 451 | public function get_issuers() { |
||
| 452 | $issuers = array(); |
||
| 453 | |||
| 454 | $url = add_query_arg( 'op', 'TransactionRequestSpecification', self::GATEWAY_NVP_TEST_URL ); |
||
| 455 | |||
| 456 | $data = array( |
||
| 457 | 'brq_websitekey' => $this->get_website_key(), |
||
| 458 | 'brq_services' => 'ideal', |
||
| 459 | 'brq_latestversiononly' => 'True', |
||
| 460 | ); |
||
| 461 | |||
| 462 | $signature = Security::create_signature( $data, $this->get_secret_key() ); |
||
| 463 | |||
| 464 | $data[ Parameters::SIGNATURE ] = $signature; |
||
| 465 | |||
| 466 | $result = wp_remote_post( |
||
| 467 | $url, |
||
| 468 | array( |
||
| 469 | 'body' => http_build_query( $data ), |
||
| 470 | ) |
||
| 471 | ); |
||
| 472 | |||
| 473 | $body = wp_remote_retrieve_body( $result ); |
||
| 474 | |||
| 475 | wp_parse_str( $body, $data ); |
||
| 476 | |||
| 477 | $data = Util::transform_flat_response( $data ); |
||
| 478 | |||
| 479 | $error_msg = __( 'Unable to retrieve issuers from Buckaroo.', 'pronamic_ideal' ); |
||
| 480 | |||
| 481 | if ( 200 !== wp_remote_retrieve_response_code( $result ) ) { |
||
| 482 | $this->error = new WP_Error( 'buckaroo_error', $error_msg, $data ); |
||
| 483 | |||
| 484 | return $issuers; |
||
| 485 | } |
||
| 486 | |||
| 487 | if ( isset( $data['BRQ_APIRESULT'] ) && 'Fail' === $data['BRQ_APIRESULT'] ) { |
||
| 488 | if ( isset( $data['BRQ_APIERRORMESSAGE'] ) ) { |
||
| 489 | $error_msg = sprintf( '%s %s', $error_msg, $data['BRQ_APIERRORMESSAGE'] ); |
||
| 490 | } |
||
| 491 | |||
| 492 | $this->error = new WP_Error( 'buckaroo_error', $error_msg, $data ); |
||
| 493 | |||
| 494 | return $issuers; |
||
| 495 | } |
||
| 496 | |||
| 497 | if ( ! isset( $data['BRQ_SERVICES'] ) ) { |
||
| 498 | return $issuers; |
||
| 499 | } |
||
| 500 | |||
| 501 | foreach ( $data['BRQ_SERVICES'] as $service ) { |
||
| 502 | if ( ! isset( $service['NAME'], $service['VERSION'], $service['ACTIONDESCRIPTION'] ) ) { |
||
| 503 | return $issuers; |
||
| 504 | } |
||
| 505 | |||
| 506 | if ( PaymentMethods::IDEAL !== $service['NAME'] ) { |
||
| 507 | continue; |
||
| 508 | } |
||
| 509 | |||
| 510 | foreach ( $service['ACTIONDESCRIPTION'] as $action ) { |
||
| 511 | if ( ! isset( $action['NAME'], $action['REQUESTPARAMETERS'] ) ) { |
||
| 512 | return $issuers; |
||
| 513 | } |
||
| 514 | |||
| 515 | if ( 'Pay' !== $action['NAME'] ) { |
||
| 516 | continue; |
||
| 517 | } |
||
| 518 | |||
| 519 | foreach ( $action['REQUESTPARAMETERS'] as $parameter ) { |
||
| 520 | |||
| 521 | if ( ! isset( $parameter['NAME'], $parameter['LISTITEMDESCRIPTION'] ) ) { |
||
| 522 | return $issuers; |
||
| 523 | } |
||
| 524 | |||
| 525 | if ( 'issuer' !== $parameter['NAME'] ) { |
||
| 526 | continue; |
||
| 527 | } |
||
| 528 | |||
| 529 | foreach ( $parameter['LISTITEMDESCRIPTION'] as $issuer ) { |
||
| 530 | $issuers[ $issuer['VALUE'] ] = $issuer['DESCRIPTION']; |
||
| 531 | } |
||
| 532 | |||
| 533 | break; |
||
| 534 | } |
||
| 535 | } |
||
| 536 | } |
||
| 537 | |||
| 538 | return $issuers; |
||
| 539 | } |
||
| 540 | |||
| 541 | /** |
||
| 542 | * Get HTML fields |
||
| 543 | * |
||
| 544 | * @since 1.1.1 |
||
| 545 | * @return string |
||
| 546 | */ |
||
| 547 | public function get_fields() { |
||
| 573 | } |
||
| 574 | |||
| 575 | /** |
||
| 576 | * Verify request Buckaroo |
||
| 577 | */ |
||
| 578 | public function verify_request( $data ) { |
||
| 611 | } |
||
| 612 | } |
||
| 613 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths