Completed
Push — master ( 5d4787...e552c3 )
by Mike
07:55
created

WC_Payment_Gateway_CC   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
dl 0
loc 83
rs 10
c 2
b 0
f 1
wmc 10
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A payment_fields() 0 14 4
A field_name() 0 3 2
B form() 0 42 4
1
<?php
1 ignored issue
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 13 and the first side effect is on line 3.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
if ( ! defined( 'ABSPATH' ) ) {
3
	exit;
4
}
5
6
/**
7
 * Credit Card Payment Gateway
8
 *
9
 * @since       2.6.0
10
 * @package		WooCommerce/Classes
11
 * @author 		WooThemes
12
 */
13
class WC_Payment_Gateway_CC extends WC_Payment_Gateway {
14
15
	/**
16
	 * Builds our payment fields area - including tokenization fields and the actualy payment fields.
17
	 * If tokenization is displayed, just the fields will be displayed.
18
	 * @since 2.6.0
19
	 */
20
	public function payment_fields() {
21
		$display_tokenization = $this->supports( 'tokenization' ) && is_checkout();
22
23
		if ( $display_tokenization ) {
24
			$this->tokenization_script();
25
			$this->saved_payment_methods();
26
		}
27
28
		$this->form();
29
30
		if ( $display_tokenization ) {
31
			$this->save_payment_method_checkbox();
32
		}
33
	}
34
35
	/**
36
	 * Output field name HTML
37
	 *
38
	 * Gateways which support tokenization do not require names - we don't want the data to post to the server.
39
	 *
40
	 * @since  2.6.0
41
	 * @param  string $name
42
	 * @return string
43
	 */
44
	public function field_name( $name ) {
45
		return $this->supports( 'tokenization' ) ? '' : ' name="' . esc_attr( $this->id . '-' . $name ) . '" ';
46
	}
47
48
	/**
49
	 * Outputs fields for entering credit card information.
50
	 * @since 2.6.0
51
	 */
52
	public function form() {
53
		$html   = '';
0 ignored issues
show
Unused Code introduced by
$html is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
54
		$fields = array();
55
56
		$cvc_field = '<p class="form-row form-row-last">
57
			<label for="' . esc_attr( $this->id ) . '-card-cvc">' . __( 'Card Code', 'woocommerce' ) . ' <span class="required">*</span></label>
58
			<input id="' . esc_attr( $this->id ) . '-card-cvc" class="input-text wc-credit-card-form-card-cvc" type="text" autocomplete="off" placeholder="' . esc_attr__( 'CVC', 'woocommerce' ) . '" ' . $this->field_name( 'card-cvc' ) . ' style="width:100px" />
59
		</p>';
60
61
		$default_fields = array(
62
			'card-number-field' => '<p class="form-row form-row-wide">
63
				<label for="' . esc_attr( $this->id ) . '-card-number">' . __( 'Card Number', 'woocommerce' ) . ' <span class="required">*</span></label>
64
				<input id="' . esc_attr( $this->id ) . '-card-number" class="input-text wc-credit-card-form-card-number" type="text" maxlength="20" autocomplete="off" placeholder="•••• •••• •••• ••••" ' . $this->field_name( 'card-number' ) . ' />
65
			</p>',
66
			'card-expiry-field' => '<p class="form-row form-row-first">
67
				<label for="' . esc_attr( $this->id ) . '-card-expiry">' . __( 'Expiry (MM/YY)', 'woocommerce' ) . ' <span class="required">*</span></label>
68
				<input id="' . esc_attr( $this->id ) . '-card-expiry" class="input-text wc-credit-card-form-card-expiry" type="text" autocomplete="off" placeholder="' . esc_attr__( 'MM / YY', 'woocommerce' ) . '" ' . $this->field_name( 'card-expiry' ) . ' />
69
			</p>'
70
		);
71
72
		if ( ! $this->supports( 'credit_card_form_cvc_on_saved_method' ) ) {
73
			$default_fields['card-cvc-field'] = $cvc_field;
74
		}
75
76
		$fields = wp_parse_args( $fields, apply_filters( 'woocommerce_credit_card_form_fields', $default_fields, $this->id ) );
77
		?>
78
79
		<fieldset id="wc-<?php echo esc_attr( $this->id ); ?>-cc-form" class='wc-credit-card-form'>
80
			<?php do_action( 'woocommerce_credit_card_form_start', $this->id ); ?>
81
			<?php
82
				foreach ( $fields as $field ) {
83
					echo $field;
84
				}
85
			?>
86
			<?php do_action( 'woocommerce_credit_card_form_end', $this->id ); ?>
87
			<div class="clear"></div>
88
		</fieldset>
89
		<?php
90
		if ( $this->supports( 'credit_card_form_cvc_on_saved_method' ) ) {
91
			echo '<fieldset>' . $cvc_field . '</fieldset>';
92
		}
93
	}
94
95
}
96