| Conditions | 10 |
| Paths | 144 |
| Total Lines | 104 |
| Code Lines | 59 |
| 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 | // Shipping address. |
||
| 88 | $shipping_address = $payment->get_shipping_address(); |
||
| 89 | |||
| 90 | if ( null !== $shipping_address ) { |
||
| 91 | $shipping_detail = new Address(); |
||
| 92 | |||
| 93 | $name = $shipping_address->get_name(); |
||
| 94 | |||
| 95 | if ( null !== $name ) { |
||
| 96 | $shipping_detail->set_first_name( $name->get_first_name() ); |
||
| 97 | $shipping_detail->set_middle_name( $name->get_middle_name() ); |
||
| 98 | $shipping_detail->set_last_name( $name->get_last_name() ); |
||
| 99 | } |
||
| 100 | |||
| 101 | $shipping_detail->set_street( $shipping_address->get_street_name() ); |
||
| 102 | $shipping_detail->set_house_number( $shipping_address->get_house_number() ); |
||
| 103 | $shipping_detail->set_house_number_addition( $shipping_address->get_house_number_addition() ); |
||
| 104 | $shipping_detail->set_postal_code( $shipping_address->get_postal_code() ); |
||
| 105 | $shipping_detail->set_city( $shipping_address->get_city() ); |
||
| 106 | $shipping_detail->set_country_code( $shipping_address->get_country_code() ); |
||
| 107 | } |
||
| 108 | |||
| 109 | // Billing address. |
||
| 110 | $billing_address = $payment->get_billing_address(); |
||
| 111 | |||
| 112 | if ( null !== $billing_address ) { |
||
| 113 | $billing_detail = new Address(); |
||
| 114 | |||
| 115 | $name = $billing_address->get_name(); |
||
| 116 | |||
| 117 | if ( null !== $name ) { |
||
| 118 | $billing_detail->set_first_name( $name->get_first_name() ); |
||
| 119 | $billing_detail->set_middle_name( $name->get_middle_name() ); |
||
| 120 | $billing_detail->set_last_name( $name->get_last_name() ); |
||
| 121 | } |
||
| 122 | |||
| 123 | $billing_detail->set_street( $billing_address->get_street_name() ); |
||
| 124 | $billing_detail->set_house_number( $billing_address->get_house_number() ); |
||
| 125 | $billing_detail->set_house_number_addition( $billing_address->get_house_number_addition() ); |
||
| 126 | $billing_detail->set_postal_code( $billing_address->get_postal_code() ); |
||
| 127 | $billing_detail->set_city( $billing_address->get_city() ); |
||
| 128 | $billing_detail->set_country_code( $billing_address->get_country_code() ); |
||
| 129 | } |
||
| 130 | |||
| 131 | // Customer information. |
||
| 132 | $customer = $payment->get_customer(); |
||
| 133 | |||
| 134 | if ( null !== $customer ) { |
||
| 135 | $customer_information = new CustomerInformation(); |
||
| 136 | |||
| 137 | $customer_information->set_email_address( $customer->get_email() ); |
||
| 138 | $customer_information->set_telephone_number( $customer->get_phone() ); |
||
| 139 | } |
||
| 140 | |||
| 141 | // Payment brand. |
||
| 142 | $payment_brand = PaymentBrands::transform( $payment->get_method() ); |
||
| 143 | |||
| 144 | // New order. |
||
| 145 | $order = new Order( |
||
| 146 | $merchant_order_id, |
||
| 147 | new Money( |
||
| 148 | $payment->get_currency(), |
||
| 149 | $payment->get_amount()->get_cents() |
||
| 150 | ), |
||
| 151 | $payment->get_return_url() |
||
| 152 | ); |
||
| 153 | |||
| 154 | $order->set_description( $payment->get_description() ); |
||
| 155 | $order->set_language( $payment->get_customer()->get_language() ); |
||
| 156 | $order->set_order_items( $payment->get_order_items() ); |
||
| 157 | $order->set_shipping_detail( $shipping_detail ); |
||
| 158 | $order->set_billing_detail( $billing_detail ); |
||
| 159 | $order->set_customer_information( $customer_information ); |
||
| 160 | $order->set_payment_brand( $payment_brand ); |
||
| 161 | |||
| 162 | if ( null !== $payment_brand ) { |
||
| 163 | // Payment brand force should only be set if payment brand is not empty. |
||
| 164 | $order->set_payment_brand_force( PaymentBrandForce::FORCE_ONCE ); |
||
| 165 | } |
||
| 166 | |||
| 167 | // Maybe update access token. |
||
| 168 | $this->maybe_update_access_token(); |
||
| 169 | |||
| 170 | // Handle errors. |
||
| 171 | if ( $this->get_client_error() ) { |
||
| 172 | return; |
||
| 173 | } |
||
| 174 | |||
| 175 | // Announce order. |
||
| 176 | $result = $this->client->order_announce( $this->config, $order ); |
||
| 177 | |||
| 178 | // Handle errors. |
||
| 179 | if ( $this->get_client_error() ) { |
||
| 180 | return; |
||
| 181 | } |
||
| 182 | |||
| 183 | if ( $result ) { |
||
| 184 | $payment->set_action_url( $result->redirectUrl ); |
||
| 185 | } |
||
| 338 |