| Conditions | 16 |
| Paths | 1008 |
| Total Lines | 149 |
| Code Lines | 82 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 272 |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 83 | public function start( Payment $payment ) { |
||
| 84 | // Amount. |
||
| 85 | $amount = new Amount( |
||
| 86 | $payment->get_total_amount()->get_currency()->get_alphabetic_code(), |
||
| 87 | $payment->get_total_amount()->get_minor_units() |
||
|
|
|||
| 88 | ); |
||
| 89 | |||
| 90 | // Payment method. Take leap of faith for unknown payment methods. |
||
| 91 | $type = PaymentMethodType::transform( |
||
| 92 | $payment->get_method(), |
||
| 93 | $payment->get_method() |
||
| 94 | ); |
||
| 95 | |||
| 96 | $payment_method = new PaymentMethod( $type ); |
||
| 97 | |||
| 98 | switch ( $payment->get_method() ) { |
||
| 99 | case PaymentMethods::IDEAL: |
||
| 100 | $payment_method->issuer = $payment->get_issuer(); |
||
|
1 ignored issue
–
show
|
|||
| 101 | |||
| 102 | break; |
||
| 103 | } |
||
| 104 | |||
| 105 | // Country. |
||
| 106 | $locale = get_locale(); |
||
| 107 | |||
| 108 | if ( null !== $payment->get_customer() ) { |
||
| 109 | $locale = $payment->get_customer()->get_locale(); |
||
| 110 | } |
||
| 111 | |||
| 112 | $locale = explode( '_', $locale ); |
||
| 113 | |||
| 114 | $country_code = strtoupper( substr( $locale[1], 0, 2 ) ); |
||
| 115 | |||
| 116 | // Create payment or payment session request. |
||
| 117 | switch ( $payment->get_method() ) { |
||
| 118 | case PaymentMethods::IDEAL: |
||
| 119 | case PaymentMethods::SOFORT: |
||
| 120 | // API integration. |
||
| 121 | $request = new PaymentRequest( |
||
| 122 | $amount, |
||
| 123 | $this->config->merchant_account, |
||
| 124 | $payment->get_id(), |
||
| 125 | $payment->get_return_url(), |
||
| 126 | $payment_method |
||
| 127 | ); |
||
| 128 | |||
| 129 | $request->set_country_code( $country_code ); |
||
| 130 | |||
| 131 | break; |
||
| 132 | default: |
||
| 133 | // Web SDK integration. |
||
| 134 | $request = new PaymentSessionRequest( |
||
| 135 | $amount, |
||
| 136 | $this->config->merchant_account, |
||
| 137 | $payment->get_id(), |
||
| 138 | $payment->get_return_url(), |
||
| 139 | $country_code |
||
| 140 | ); |
||
| 141 | |||
| 142 | $request->set_origin( home_url() ); |
||
| 143 | $request->set_sdk_version( '1.6.3' ); |
||
| 144 | |||
| 145 | // Set allowed payment methods. |
||
| 146 | $allowed_methods = array( $type ); |
||
| 147 | |||
| 148 | // Add all available payment methods if no payment method is given. |
||
| 149 | if ( empty( $type ) ) { |
||
| 150 | $allowed_methods = array(); |
||
| 151 | |||
| 152 | foreach ( $this->get_available_payment_methods() as $method ) { |
||
| 153 | $allowed_methods[] = PaymentMethodType::transform( $method ); |
||
| 154 | } |
||
| 155 | } |
||
| 156 | |||
| 157 | $request->set_allowed_payment_methods( $allowed_methods ); |
||
| 158 | } |
||
| 159 | |||
| 160 | // Channel. |
||
| 161 | $request->set_channel( 'Web' ); |
||
| 162 | |||
| 163 | // Shopper. |
||
| 164 | $request->set_shopper_statement( $payment->get_description() ); |
||
| 165 | |||
| 166 | if ( null !== $payment->get_customer() ) { |
||
| 167 | $request->set_shopper_ip( $payment->get_customer()->get_ip_address() ); |
||
| 168 | $request->set_shopper_statement( $payment->get_customer()->get_gender() ); |
||
| 169 | $request->set_shopper_locale( $payment->get_customer()->get_locale() ); |
||
| 170 | $request->set_shopper_reference( $payment->get_customer()->get_user_id() ); |
||
| 171 | $request->set_telephone_number( $payment->get_customer()->get_phone() ); |
||
| 172 | |||
| 173 | if ( null !== $payment->get_customer()->get_name() ) { |
||
| 174 | $shopper_name = new ShopperName( |
||
| 175 | $payment->get_customer()->get_name()->get_first_name(), |
||
| 176 | $payment->get_customer()->get_name()->get_middle_name(), |
||
| 177 | $payment->get_customer()->get_name()->get_last_name() |
||
| 178 | ); |
||
| 179 | |||
| 180 | $request->set_shopper_name( $shopper_name ); |
||
| 181 | } |
||
| 182 | } |
||
| 183 | |||
| 184 | // Create payment or payment session. |
||
| 185 | switch ( $payment->get_method() ) { |
||
| 186 | case PaymentMethods::IDEAL: |
||
| 187 | case PaymentMethods::SOFORT: |
||
| 188 | // Create payment. |
||
| 189 | $result = $this->client->create_payment( $request ); |
||
| 190 | |||
| 191 | break; |
||
| 192 | default: |
||
| 193 | // Create payment session. |
||
| 194 | $result = $this->client->create_payment_session( $request ); |
||
| 195 | } |
||
| 196 | |||
| 197 | if ( ! $result ) { |
||
| 198 | $this->error = $this->client->get_error(); |
||
| 199 | |||
| 200 | return; |
||
| 201 | } |
||
| 202 | |||
| 203 | if ( isset( $result->paymentSession ) ) { |
||
| 204 | wp_register_script( |
||
| 205 | 'pronamic-pay-adyen-checkout', |
||
| 206 | 'https://checkoutshopper-test.adyen.com/checkoutshopper/assets/js/sdk/checkoutSDK.1.6.3.min.js', |
||
| 207 | array(), |
||
| 208 | '1.6.3', |
||
| 209 | false |
||
| 210 | ); |
||
| 211 | |||
| 212 | // No cache. |
||
| 213 | Util::no_cache(); |
||
| 214 | |||
| 215 | $payment_session = $result->paymentSession; |
||
| 216 | |||
| 217 | $context = ( self::MODE_TEST === $this->config->mode ? 'test' : 'live' ); |
||
| 218 | |||
| 219 | require __DIR__ . '/../views/checkout.php'; |
||
| 220 | |||
| 221 | exit; |
||
| 222 | } |
||
| 223 | |||
| 224 | // Set transaction ID. |
||
| 225 | if ( isset( $result->pspReference ) ) { |
||
| 226 | $payment->set_transaction_id( $result->pspReference ); |
||
| 227 | } |
||
| 228 | |||
| 229 | // Set redirect URL. |
||
| 230 | if ( isset( $result->redirect->url ) ) { |
||
| 231 | $payment->set_action_url( $result->redirect->url ); |
||
| 232 | } |
||
| 404 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.