WC_Payment_Token_CC   A
last analyzed

Complexity

Total Complexity 17

Size/Duplication

Total Lines 133
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 133
rs 10
wmc 17
lcom 2
cbo 1

10 Methods

Rating   Name   Duplication   Size   Complexity  
C validate() 0 31 8
A get_card_type() 0 3 1
A set_card_type() 0 3 1
A get_expiry_year() 0 3 1
A set_expiry_year() 0 3 1
A get_expiry_month() 0 3 1
A set_expiry_month() 0 3 1
A get_last4() 0 3 1
A set_last4() 0 3 1
A get_display_name() 0 6 1
1
<?php
2
if ( ! defined( 'ABSPATH' ) ) {
3
	exit; // Exit if accessed directly
4
}
5
6
/**
7
 * WooCommerce Credit Card Payment Token.
8
 *
9
 * Representation of a payment token for credit cards.
10
 *
11
 * @class 		WC_Payment_Token_CC
12
 * @since		2.6.0
13
 * @category 	PaymentTokens
14
 * @package 	WooCommerce/PaymentTokens
15
 * @author		WooThemes
16
 */
17
class WC_Payment_Token_CC extends WC_Payment_Token {
18
19
	/** @protected string Token Type String. */
20
	protected $type = 'CC';
21
22
 	/**
0 ignored issues
show
Coding Style introduced by
There is some trailing whitespace on this line which should be avoided as per coding-style.
Loading history...
23
	 * Validate credit card payment tokens.
24
	 *
25
	 * These fields are required by all credit card payment tokens:
26
	 * expiry_month  - string Expiration date (MM) for the card
27
	 * expiry_year   - string Expiration date (YYYY) for the card
28
	 * last4         - string Last 4 digits of the card
29
	 * card_type     - string Card type (visa, mastercard, etc)
30
	 *
31
	 * @since 2.6.0
32
	 * @return boolean True if the passed data is valid
33
	 */
34
	public function validate() {
35
		if ( false === parent::validate() ) {
36
			return false;
37
		}
38
39
		if ( ! $this->get_last4() ) {
40
			return false;
41
		}
42
43
		if ( ! $this->get_expiry_year() ) {
44
			return false;
45
		}
46
47
		if ( ! $this->get_expiry_month() ) {
48
			return false;
49
		}
50
51
		if ( ! $this->get_card_type() ) {
52
			return false;
53
		}
54
55
		if ( 4 !== strlen( $this->get_expiry_year() ) ) {
56
			return false;
57
		}
58
59
		if ( 2 !== strlen( $this->get_expiry_month() ) ) {
60
			return false;
61
		}
62
63
		return true;
64
	}
65
66
	/**
67
	 * Get type to display to user.
68
	 * @return string
69
	 */
70
	public function get_display_name() {
71
		$display = wc_get_credit_card_type_label( $this->get_card_type() );
72
		$display .= '&nbsp;' . sprintf( __( 'ending in %s', 'woocommerce' ), $this->get_last4() );
73
		$display .= ' ' . sprintf( __( '(expires %s)', 'woocommerce' ), $this->get_expiry_month() . '/' . substr( $this->get_expiry_year(), 2 ) );
74
		return $display;
75
	}
76
77
	/**
78
	 * Returns the card type (mastercard, visa, ...).
79
	 * @since 2.6.0
80
	 * @return string Card type
81
	 */
82
	public function get_card_type() {
83
		return $this->get_meta( 'card_type' );
84
	}
85
86
	/**
87
	 * Set the card type (mastercard, visa, ...).
88
	 * @since 2.6.0
89
	 * @param string $type
90
	 */
91
	public function set_card_type( $type ) {
92
		$this->add_meta_data( 'card_type', $type, true );
0 ignored issues
show
Documentation introduced by
'card_type' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$type is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
true is of type boolean, but the function expects a false|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
93
	}
94
95
	/**
96
	 * Returns the card expiration year (YYYY).
97
	 * @since 2.6.0
98
	 * @return string Expiration year
99
	 */
100
	public function get_expiry_year() {
101
		return $this->get_meta( 'expiry_year' );
102
	}
103
104
	/**
105
	 * Set the expiration year for the card (YYYY format).
106
	 * @since 2.6.0
107
	 * @param string $year
108
	 */
109
	public function set_expiry_year( $year ) {
110
		$this->add_meta_data( 'expiry_year', $year, true );
0 ignored issues
show
Documentation introduced by
'expiry_year' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$year is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
true is of type boolean, but the function expects a false|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
111
	}
112
113
	/**
114
	 * Returns the card expiration month (MM).
115
	 * @since 2.6.0
116
	 * @return string Expiration month
117
	 */
118
	public function get_expiry_month() {
119
		return $this->get_meta( 'expiry_month' );
120
	}
121
122
	/**
123
	 * Set the expiration month for the card (formats into MM format).
124
	 * @since 2.6.0
125
	 * @param string $month
126
	 */
127
	public function set_expiry_month( $month ) {
128
		$this->add_meta_data( 'expiry_month', str_pad( $month, 2, '0', STR_PAD_LEFT ), true );
0 ignored issues
show
Documentation introduced by
'expiry_month' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
str_pad($month, 2, '0', STR_PAD_LEFT) is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
true is of type boolean, but the function expects a false|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
129
	}
130
131
	/**
132
	 * Returns the last four digits.
133
	 * @since 2.6.0
134
	 * @return string Last 4 digits
135
	 */
136
	public function get_last4() {
137
		return $this->get_meta( 'last4' );
138
	}
139
140
	/**
141
	 * Set the last four digits.
142
	 * @since 2.6.0
143
	 * @param string $last4
144
	 */
145
	public function set_last4( $last4 ) {
146
		$this->add_meta_data( 'last4', $last4, true );
0 ignored issues
show
Documentation introduced by
'last4' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$last4 is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
true is of type boolean, but the function expects a false|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
147
	}
148
149
}
150