| Conditions | 5 |
| Paths | 12 |
| Total Lines | 56 |
| Code Lines | 34 |
| 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 |
||
| 74 | public function start( Payment $payment ) { |
||
| 75 | $payment->set_action_url( $this->client->get_payment_server_url() ); |
||
| 76 | |||
| 77 | $ogone_data = $this->client->get_data(); |
||
| 78 | |||
| 79 | // General. |
||
| 80 | $ogone_data_general = new DataGeneralHelper( $ogone_data ); |
||
| 81 | |||
| 82 | $ogone_data_general |
||
| 83 | ->set_order_id( $payment->format_string( $this->config->order_id ) ) |
||
| 84 | ->set_order_description( $payment->get_description() ) |
||
| 85 | ->set_param_plus( 'payment_id=' . $payment->get_id() ) |
||
| 86 | ->set_currency( $payment->get_total_amount()->get_currency()->get_alphabetic_code() ) |
||
| 87 | ->set_amount( $payment->get_total_amount()->get_cents() ); |
||
| 88 | |||
| 89 | $customer = $payment->get_customer(); |
||
| 90 | |||
| 91 | if ( null !== $customer ) { |
||
| 92 | // Localised language. |
||
| 93 | $ogone_data_general->set_language( $customer->get_locale() ); |
||
| 94 | } |
||
| 95 | |||
| 96 | // Customer. |
||
| 97 | $ogone_data_customer = new DataCustomerHelper( $ogone_data ); |
||
| 98 | |||
| 99 | if ( null !== $customer ) { |
||
| 100 | $name = $customer->get_name(); |
||
| 101 | |||
| 102 | if ( null !== $name ) { |
||
| 103 | $ogone_data_customer->set_name( strval( $name ) ); |
||
| 104 | } |
||
| 105 | |||
| 106 | $ogone_data_customer->set_email( $customer->get_email() ); |
||
| 107 | } |
||
| 108 | |||
| 109 | $billing_address = $payment->get_billing_address(); |
||
| 110 | |||
| 111 | if ( null !== $billing_address ) { |
||
| 112 | $ogone_data_customer |
||
| 113 | ->set_address( $billing_address->get_line_1() ) |
||
| 114 | ->set_zip( $billing_address->get_postal_code() ) |
||
| 115 | ->set_town( $billing_address->get_city() ) |
||
| 116 | ->set_country( $billing_address->get_country_code() ) |
||
| 117 | ->set_telephone_number( $billing_address->get_phone() ); |
||
| 118 | } |
||
| 119 | |||
| 120 | // URLs. |
||
| 121 | $ogone_url_helper = new DataUrlHelper( $ogone_data ); |
||
| 122 | |||
| 123 | $ogone_url_helper |
||
| 124 | ->set_accept_url( add_query_arg( 'status', Statuses::SUCCESS, $payment->get_return_url() ) ) |
||
|
|
|||
| 125 | ->set_cancel_url( add_query_arg( 'status', Statuses::CANCELLED, $payment->get_return_url() ) ) |
||
| 126 | ->set_decline_url( add_query_arg( 'status', Statuses::FAILURE, $payment->get_return_url() ) ) |
||
| 127 | ->set_exception_url( add_query_arg( 'status', Statuses::FAILURE, $payment->get_return_url() ) ) |
||
| 128 | ->set_back_url( home_url( '/' ) ) |
||
| 129 | ->set_home_url( home_url( '/' ) ); |
||
| 130 | } |
||
| 147 |