WC_Payment_Gateway_eCheck   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 52
Duplicated Lines 19.23 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 10
loc 52
rs 10
wmc 6
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
B form() 0 28 2
A payment_fields() 10 10 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
if ( ! defined( 'ABSPATH' ) ) {
3
	exit;
4
}
5
6
/**
7
 * eCheck Payment Gateway
8
 *
9
 * @since       2.6.0
10
 * @package		WooCommerce/Classes
11
 * @author 		WooThemes
12
 */
13
class WC_Payment_Gateway_eCheck extends WC_Payment_Gateway {
14
15
	/**
16
	 * Builds our payment fields area - including tokenization fields for logged
17
	 * in users, and the actual payment fields.
18
	 * @since 2.6.0
19
	 */
20 View Code Duplication
	public function payment_fields() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
21
		if ( $this->supports( 'tokenization' ) && is_checkout() && is_user_logged_in() ) {
22
			$this->tokenization_script();
23
			$this->saved_payment_methods();
24
			$this->form();
25
			$this->save_payment_method_checkbox();
26
		} else {
27
			$this->form();
28
		}
29
	}
30
31
	/**
32
	 * Outputs fields for entering eCheck information.
33
	 * @since 2.6.0
34
	 */
35
	public function form() {
36
		$fields = array();
37
38
		$default_fields = array(
39
			'routing-number' => '<p class="form-row form-row-first">
40
				<label for="' . esc_attr( $this->id ) . '-routing-number">' . __( 'Routing Number', 'woocommerce' ) . ' <span class="required">*</span></label>
41
				<input id="' . esc_attr( $this->id ) . '-routing-number" class="input-text wc-echeck-form-routing-number" type="text" maxlength="9" autocomplete="off" placeholder="&bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;" name="' . esc_attr( $this->id ) . '-routing-number" />
42
			</p>',
43
			'account-number' => '<p class="form-row form-row-wide">
44
				<label for="' . esc_attr( $this->id ) . '-account-number">' . __( 'Account Number', 'woocommerce' ) . ' <span class="required">*</span></label>
45
				<input id="' . esc_attr( $this->id ) . '-account-number" class="input-text wc-echeck-form-account-number" type="text" autocomplete="off" name="' . esc_attr( $this->id ) . '-account-number" maxlength="17" />
46
			</p>',
47
		);
48
49
		$fields = wp_parse_args( $fields, apply_filters( 'woocommerce_echeck_form_fields', $default_fields, $this->id ) );
50
		?>
51
52
		<fieldset id="<?php echo esc_attr( $this->id ); ?>-cc-form" class='wc-echeck-form wc-payment-form'>
53
			<?php do_action( 'woocommerce_echeck_form_start', $this->id ); ?>
54
			<?php
55
				foreach ( $fields as $field ) {
56
					echo $field;
57
				}
58
			?>
59
			<?php do_action( 'woocommerce_echeck_form_end', $this->id ); ?>
60
			<div class="clear"></div>
61
		</fieldset><?php
62
	}
63
64
}
65