Conditions | 10 |
Paths | 160 |
Total Lines | 64 |
Code Lines | 36 |
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 |
||
68 | public function start( Payment $payment ) { |
||
69 | $payment_method = $payment->get_method(); |
||
70 | $currency = $payment->get_total_amount()->get_currency()->get_alphabetic_code(); |
||
71 | $amount = $payment->get_total_amount()->get_value(); |
||
72 | |||
73 | if ( empty( $payment_method ) ) { |
||
74 | $payment_method = PaymentMethods::GULDEN; |
||
75 | } |
||
76 | |||
77 | if ( PaymentMethods::GULDEN === $payment_method ) { |
||
78 | switch ( $currency ) { |
||
79 | case 'EUR': |
||
80 | // Convert to EUR. |
||
81 | $quote = $this->client->get_transaction_quote( 'EUR', 'NLG', $amount, Methods::IDEAL ); |
||
82 | |||
83 | if ( $quote ) { |
||
84 | $amount = $quote->data->target_amount->amount; |
||
85 | $currency = 'NLG'; |
||
86 | } |
||
87 | |||
88 | break; |
||
89 | } |
||
90 | } |
||
91 | |||
92 | $transaction = new Transaction(); |
||
93 | |||
94 | $transaction->payment_id = $payment->get_id(); |
||
95 | $transaction->merchant_profile = $this->config->merchant_profile; |
||
96 | $transaction->description = $payment->get_description(); |
||
97 | $transaction->currency = $currency; |
||
98 | $transaction->amount = $amount; |
||
99 | $transaction->payment_method = Methods::transform( $payment->get_method() ); |
||
100 | $transaction->redirect_url = $payment->get_return_url(); |
||
101 | $transaction->callback_url = add_query_arg( 'nocks_webhook', '', home_url( '/' ) ); |
||
102 | $transaction->description = $payment->get_description(); |
||
103 | |||
104 | if ( null !== $payment->get_customer() ) { |
||
105 | $transaction->locale = $payment->get_customer()->get_locale(); |
||
106 | } |
||
107 | |||
108 | // Issuer. |
||
109 | if ( Methods::IDEAL === $transaction->payment_method ) { |
||
110 | $transaction->issuer = $payment->get_issuer(); |
||
111 | } |
||
112 | |||
113 | // Start transaction. |
||
114 | $result = $this->client->start_transaction( $transaction ); |
||
115 | |||
116 | // Handle errors. |
||
117 | $error = $this->client->get_error(); |
||
118 | |||
119 | if ( is_wp_error( $error ) ) { |
||
120 | $this->error = $error; |
||
121 | |||
122 | return; |
||
123 | } |
||
124 | |||
125 | // Update payment. |
||
126 | if ( isset( $result->data->payments->data[0]->uuid ) ) { |
||
127 | $payment->set_transaction_id( $result->data->uuid ); |
||
128 | } |
||
129 | |||
130 | if ( isset( $result->data->payments->data[0]->metadata->url ) ) { |
||
131 | $payment->set_action_url( $result->data->payments->data[0]->metadata->url ); |
||
132 | } |
||
160 |