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

WC_Payment_Token_eCheck   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 10 3
A get_display_name() 0 3 1
A get_last4() 0 3 1
A set_last4() 0 3 1
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 18 and the first side effect is on line 4.

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
3
if ( ! defined( 'ABSPATH' ) ) {
4
	exit; // Exit if accessed directly
5
}
6
7
/**
8
 * WooCommerce eCheck Payment Token.
9
 *
10
 * Representation of a payment token for eChecks.
11
 *
12
 * @class 		WC_Payment_Token_eCheck
13
 * @since		2.6.0
14
 * @category 	PaymentTokens
15
 * @package 	WooCommerce/PaymentTokens
16
 * @author		WooThemes
17
 */
18
class WC_Payment_Token_eCheck extends WC_Payment_Token {
19
20
	/** @protected string Token Type String */
21
	protected $type = 'eCheck';
22
23
 	/**
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...
24
	 * Validate eCheck payment tokens.
25
	 *
26
	 * These fields are required by all eCheck payment tokens:
27
	 * last4  - string Last 4 digits of the check
28
	 *
29
	 * @since 2.6.0
30
	 * @return boolean True if the passed data is valid
31
	 */
32
	public function validate() {
33
		if ( false === parent::validate() ) {
34
			return false;
35
		}
36
37
		if ( ! $this->get_last4() ) {
38
			return false;
39
		}
40
		return true;
41
	}
42
43
	/**
44
	 * Get type to display to user.
45
	 * @return string
46
	 */
47
	public function get_display_name() {
48
		return __( 'eCheck', 'woocommerce' );
49
	}
50
51
	/**
52
	 * Returns the last four digits.
53
	 * @since 2.6.0
54
	 * @return string Last 4 digits
55
	 */
56
	public function get_last4() {
57
		return $this->get_meta( 'last4' );
58
	}
59
60
	/**
61
	 * Set the last four digits.
62
	 * @since 2.6.0
63
	 * @param string $last4
64
	 */
65
	public function set_last4( $last4 ) {
66
		$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...
67
	}
68
69
}
70