Completed
Push — master ( 1d37b9...2ba902 )
by Mike
07:44
created

WC_Payment_Token_CC::get_display_name()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 6
rs 9.4285
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 17 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; // 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 (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', $month, 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
$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
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