| Conditions | 15 | 
| Paths | 270 | 
| Total Lines | 111 | 
| Code Lines | 67 | 
| 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  | 
            ||
| 175 | 	public function start( Payment $payment ) { | 
            ||
| 176 | $payment_method = $payment->get_method();  | 
            ||
| 177 | |||
| 178 | $transaction_description = $payment->get_description();  | 
            ||
| 179 | |||
| 180 | 		if ( empty( $transaction_description ) ) { | 
            ||
| 181 | $transaction_description = $payment->get_id();  | 
            ||
| 182 | }  | 
            ||
| 183 | |||
| 184 | // Merchant.  | 
            ||
| 185 | $merchant = new Merchant();  | 
            ||
| 186 | $merchant->account = $this->config->account_id;  | 
            ||
| 187 | $merchant->site_id = $this->config->site_id;  | 
            ||
| 188 | $merchant->site_secure_code = $this->config->site_code;  | 
            ||
| 189 | $merchant->notification_url = $payment->get_return_url();  | 
            ||
| 190 | $merchant->redirect_url = $payment->get_return_url();  | 
            ||
| 191 | $merchant->cancel_url = $payment->get_return_url();  | 
            ||
| 192 | $merchant->close_window = 'false';  | 
            ||
| 193 | |||
| 194 | // Customer.  | 
            ||
| 195 | $customer = new Customer();  | 
            ||
| 196 | $customer->ip_address = Server::get( 'REMOTE_ADDR', FILTER_VALIDATE_IP );  | 
            ||
| 197 | $customer->forwarded_ip = Server::get( 'HTTP_X_FORWARDED_FOR', FILTER_VALIDATE_IP );  | 
            ||
| 198 | |||
| 199 | 		if ( null !== $payment->get_customer() ) { | 
            ||
| 200 | $name = $payment->get_customer()->get_name();  | 
            ||
| 201 | |||
| 202 | 			if ( null !== $name ) { | 
            ||
| 203 | $customer->first_name = $name->get_first_name();  | 
            ||
| 204 | $customer->last_name = $name->get_last_name();  | 
            ||
| 205 | }  | 
            ||
| 206 | |||
| 207 | $customer->locale = $payment->get_customer()->get_locale();  | 
            ||
| 208 | $customer->email = $payment->get_customer()->get_email();  | 
            ||
| 209 | }  | 
            ||
| 210 | |||
| 211 | // Transaction.  | 
            ||
| 212 | $transaction = new Transaction();  | 
            ||
| 213 | $transaction->id = uniqid();  | 
            ||
| 214 | $transaction->currency = $payment->get_total_amount()->get_currency()->get_alphabetic_code();  | 
            ||
| 215 | $transaction->amount = $payment->get_total_amount()->get_cents();  | 
            ||
| 216 | $transaction->description = $transaction_description;  | 
            ||
| 217 | |||
| 218 | 		switch ( $payment_method ) { | 
            ||
| 219 | case PaymentMethods::IDEAL:  | 
            ||
| 220 | $transaction->gateway = Methods::IDEAL;  | 
            ||
| 221 | |||
| 222 | $issuer = $payment->get_issuer();  | 
            ||
| 223 | |||
| 224 | 				if ( empty( $issuer ) ) { | 
            ||
| 225 | $message = new RedirectTransactionRequestMessage( $merchant, $customer, $transaction );  | 
            ||
| 226 | 				} else { | 
            ||
| 227 | $gateway_info = new GatewayInfo();  | 
            ||
| 228 | |||
| 229 | $gateway_info->issuer_id = $issuer;  | 
            ||
| 230 | |||
| 231 | $message = new DirectTransactionRequestMessage( $merchant, $customer, $transaction, $gateway_info );  | 
            ||
| 232 | }  | 
            ||
| 233 | |||
| 234 | break;  | 
            ||
| 235 | case PaymentMethods::CREDIT_CARD:  | 
            ||
| 236 | $gateway = Methods::transform( $payment_method );  | 
            ||
| 237 | |||
| 238 | $issuer = $payment->get_issuer();  | 
            ||
| 239 | |||
| 240 | 				if ( empty( $issuer ) ) { | 
            ||
| 241 | 					if ( $gateway ) { | 
            ||
| 242 | $transaction->gateway = $gateway;  | 
            ||
| 243 | }  | 
            ||
| 244 | 				} else { | 
            ||
| 245 | $transaction->gateway = $issuer;  | 
            ||
| 246 | }  | 
            ||
| 247 | |||
| 248 | $message = new RedirectTransactionRequestMessage( $merchant, $customer, $transaction );  | 
            ||
| 249 | |||
| 250 | break;  | 
            ||
| 251 | default:  | 
            ||
| 252 | $gateway = Methods::transform( $payment_method );  | 
            ||
| 253 | |||
| 254 | 				if ( $gateway ) { | 
            ||
| 255 | $transaction->gateway = $gateway;  | 
            ||
| 256 | }  | 
            ||
| 257 | |||
| 258 | 				if ( ! isset( $transaction->gateway ) && ! empty( $payment_method ) ) { | 
            ||
| 259 | // Leap of faith if the WordPress payment method could not transform to a Mollie method?  | 
            ||
| 260 | $transaction->gateway = $payment_method;  | 
            ||
| 261 | }  | 
            ||
| 262 | |||
| 263 | $message = new RedirectTransactionRequestMessage( $merchant, $customer, $transaction );  | 
            ||
| 264 | }  | 
            ||
| 265 | |||
| 266 | $signature = Signature::generate( $transaction->amount, $transaction->currency, $merchant->account, $merchant->site_id, $transaction->id );  | 
            ||
| 267 | |||
| 268 | $message->signature = $signature;  | 
            ||
| 269 | |||
| 270 | $response = $this->client->start_transaction( $message );  | 
            ||
| 271 | |||
| 272 | 		if ( $response ) { | 
            ||
| 273 | $transaction = $response->transaction;  | 
            ||
| 274 | |||
| 275 | $payment->set_transaction_id( $transaction->id );  | 
            ||
| 276 | |||
| 277 | 			if ( isset( $transaction->payment_url ) ) { | 
            ||
| 278 | $payment->set_action_url( $transaction->payment_url );  | 
            ||
| 279 | }  | 
            ||
| 280 | |||
| 281 | 			if ( isset( $response->gateway_info->redirect_url ) ) { | 
            ||
| 282 | $payment->set_action_url( $response->gateway_info->redirect_url );  | 
            ||
| 283 | }  | 
            ||
| 284 | 		} else { | 
            ||
| 285 | $this->error = $this->client->get_error();  | 
            ||
| 286 | }  | 
            ||
| 318 |