| Conditions | 5 |
| Paths | 8 |
| Total Lines | 81 |
| Code Lines | 51 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 81 | public function start( Payment $payment ) { |
||
| 82 | // Merchant order ID. |
||
| 83 | $merchant_order_id = $payment->format_string( $this->config->order_id ); |
||
| 84 | |||
| 85 | $payment->set_meta( 'omnikassa_2_merchant_order_id', $merchant_order_id ); |
||
| 86 | |||
| 87 | // Billing and shipping details. |
||
| 88 | $shipping_address = $payment->get_shipping_address(); |
||
| 89 | $billing_address = $payment->get_billing_address(); |
||
| 90 | |||
| 91 | $shipping_detail = new Address(); |
||
| 92 | $shipping_detail->set_first_name( $shipping_address->get_name()->get_first_name() ); |
||
| 93 | $shipping_detail->set_middle_name( $shipping_address->get_name()->get_middle_name() ); |
||
| 94 | $shipping_detail->set_last_name( $shipping_address->get_name()->get_last_name() ); |
||
| 95 | $shipping_detail->set_street( $shipping_address->get_street_name() ); |
||
| 96 | $shipping_detail->set_house_number( $shipping_address->get_house_number() ); |
||
| 97 | $shipping_detail->set_house_number_addition( $shipping_address->get_house_number_addition() ); |
||
| 98 | $shipping_detail->set_postal_code( $shipping_address->get_postal_code() ); |
||
| 99 | $shipping_detail->set_city( $shipping_address->get_city() ); |
||
| 100 | $shipping_detail->set_country_code( $shipping_address->get_country_code() ); |
||
| 101 | |||
| 102 | $billing_detail = new Address(); |
||
| 103 | $billing_detail->set_first_name( $billing_address->get_name()->get_first_name() ); |
||
| 104 | $billing_detail->set_middle_name( $billing_address->get_name()->get_middle_name() ); |
||
| 105 | $billing_detail->set_last_name( $billing_address->get_name()->get_last_name() ); |
||
| 106 | $billing_detail->set_street( $billing_address->get_street_name() ); |
||
| 107 | $billing_detail->set_house_number( $billing_address->get_house_number() ); |
||
| 108 | $billing_detail->set_house_number_addition( $billing_address->get_house_number_addition() ); |
||
| 109 | $billing_detail->set_postal_code( $billing_address->get_postal_code() ); |
||
| 110 | $billing_detail->set_city( $billing_address->get_city() ); |
||
| 111 | $billing_detail->set_country_code( $billing_address->get_country_code() ); |
||
| 112 | |||
| 113 | // Customer information. |
||
| 114 | $customer_information = new CustomerInformation(); |
||
| 115 | $customer_information->set_email_address( $payment->get_contact()->get_email() ); |
||
| 116 | $customer_information->set_telephone_number( $payment->get_contact()->get_phone() ); |
||
| 117 | |||
| 118 | // Payment brand. |
||
| 119 | $payment_brand = PaymentBrands::transform( $payment->get_method() ); |
||
| 120 | |||
| 121 | // New order. |
||
| 122 | $order = new Order( |
||
| 123 | $merchant_order_id, |
||
| 124 | new Money( |
||
| 125 | $payment->get_currency(), |
||
| 126 | Core_Util::amount_to_cents( $payment->get_amount()->get_amount() ) |
||
| 127 | ), |
||
| 128 | $payment->get_return_url() |
||
| 129 | ); |
||
| 130 | |||
| 131 | $order->set_description( $payment->get_description() ); |
||
| 132 | $order->set_language( $payment->get_contact()->get_language() ); |
||
| 133 | $order->set_order_items( $payment->get_order_items() ); |
||
| 134 | $order->set_shipping_detail( $shipping_detail ); |
||
| 135 | $order->set_billing_detail( $billing_detail ); |
||
| 136 | $order->set_customer_information( $customer_information ); |
||
| 137 | $order->set_payment_brand( $payment_brand ); |
||
| 138 | |||
| 139 | if ( null !== $payment_brand ) { |
||
| 140 | // Payment brand force should only be set if payment brand is not empty. |
||
| 141 | $order->set_payment_brand_force( PaymentBrandForce::FORCE_ONCE ); |
||
| 142 | } |
||
| 143 | |||
| 144 | // Maybe update access token. |
||
| 145 | $this->maybe_update_access_token(); |
||
| 146 | |||
| 147 | // Handle errors. |
||
| 148 | if ( $this->get_client_error() ) { |
||
| 149 | return; |
||
| 150 | } |
||
| 151 | |||
| 152 | // Announce order. |
||
| 153 | $result = $this->client->order_announce( $this->config, $order ); |
||
| 154 | |||
| 155 | // Handle errors. |
||
| 156 | if ( $this->get_client_error() ) { |
||
| 157 | return; |
||
| 158 | } |
||
| 159 | |||
| 160 | if ( $result ) { |
||
| 161 | $payment->set_action_url( $result->redirectUrl ); |
||
| 162 | } |
||
| 315 |