Failed Conditions
Push — develop ( 65cebf...5eea29 )
by Remco
04:22 queued 01:23
created

Name   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 149
Duplicated Lines 0 %

Test Coverage

Coverage 97.44%

Importance

Changes 0
Metric Value
eloc 29
dl 0
loc 149
ccs 38
cts 39
cp 0.9744
rs 10
c 0
b 0
f 0
wmc 13

10 Methods

Rating   Name   Duplication   Size   Complexity  
A get_last_name() 0 2 1
A get_gender() 0 2 1
A get_infix() 0 2 1
A __construct() 0 4 1
A get_first_name() 0 2 1
A set_gender() 0 2 1
A set_last_name() 0 2 1
A get_json() 0 21 2
A set_first_name() 0 2 1
A set_infix() 0 11 3
1
<?php
2
/**
3
 * Name
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2019 Pronamic
7
 * @license   GPL-3.0-or-later
8
 * @package   Pronamic\WordPress\Pay\Gateways\Adyen
9
 */
10
11
namespace Pronamic\WordPress\Pay\Gateways\Adyen;
12
13
use InvalidArgumentException;
14
15
/**
16
 * Name
17
 *
18
 * @link https://docs.adyen.com/developers/api-reference/common-api/name
19
 *
20
 * @author  Remco Tolsma
21
 * @version 2.1.0
22
 * @since   2.0.2
23
 */
24
class Name {
25
	/**
26
	 * First name.
27
	 *
28
	 * @var string
29
	 */
30
	private $first_name;
31
32
	/**
33
	 * Gender.
34
	 *
35
	 * @var string
36
	 */
37
	private $gender;
38
39
	/**
40
	 * The name's infix, if applicable.
41
	 *
42
	 * @var string|null
43
	 */
44
	private $infix;
45
46
	/**
47
	 * Last name.
48
	 *
49
	 * @var string
50
	 */
51
	private $last_name;
52
53
	/**
54
	 * Construct shopper name.
55
	 *
56
	 * @param string $first_name First name.
57
	 * @param string $last_name  Last name.
58
	 * @param string $gender     Gender.
59
	 */
60 3
	public function __construct( $first_name, $last_name, $gender ) {
61 3
		$this->set_first_name( $first_name );
62 3
		$this->set_last_name( $last_name );
63 3
		$this->set_gender( $gender );
64 3
	}
65
66
	/**
67
	 * Get first name.
68
	 *
69
	 * @return string
70
	 */
71 2
	public function get_first_name() {
72 2
		return $this->first_name;
73
	}
74
75
	/**
76
	 * Set first name.
77
	 *
78
	 * @param string $first_name First name.
79
	 */
80 3
	public function set_first_name( $first_name ) {
81 3
		$this->first_name = $first_name;
82 3
	}
83
84
	/**
85
	 * Get gender.
86
	 *
87
	 * @return string
88
	 */
89 2
	public function get_gender() {
90 2
		return $this->gender;
91
	}
92
93
	/**
94
	 * Set gender.
95
	 *
96
	 * @param string $gender Gender.
97
	 */
98 3
	public function set_gender( $gender ) {
99 3
		$this->gender = $gender;
100 3
	}
101
102
	/**
103
	 * Get infix.
104
	 *
105
	 * @return string|null
106
	 */
107 2
	public function get_infix() {
108 2
		return $this->infix;
109
	}
110
111
	/**
112
	 * Set infix.
113
	 *
114
	 * @param string|null $infix Infix.
115
	 */
116 2
	public function set_infix( $infix ) {
117 2
		if ( null !== $infix && mb_strlen( $infix ) > 20 ) {
118 1
			throw new InvalidArgumentException(
119 1
				sprintf(
120 1
					'Given infix `%s` is longer then 20 characters.',
121 1
					$infix
122
				)
123
			);
124
		}
125
126 1
		$this->infix = $infix;
127 1
	}
128
129
	/**
130
	 * Get last name.
131
	 *
132
	 * @return string
133
	 */
134 2
	public function get_last_name() {
135 2
		return $this->last_name;
136
	}
137
138
	/**
139
	 * Set last name.
140
	 *
141
	 * @param string $last_name Last name.
142
	 */
143 3
	public function set_last_name( $last_name ) {
144 3
		$this->last_name = $last_name;
145 3
	}
146
147
	/**
148
	 * Get JSON.
149
	 *
150
	 * @return object
151
	 */
152 1
	public function get_json() {
153 1
		$object = (object) array();
154
155
		// First name.
156 1
		$object->firstName = $this->get_first_name();
157
158
		// Gender.
159 1
		$object->gender = $this->get_gender();
160
161
		// Infix.
162 1
		$infix = $this->get_infix();
163
164 1
		if ( null !== $infix ) {
165
			$object->infix = $infix;
166
		}
167
168
		// Last name.
169 1
		$object->lastName = $this->get_last_name();
170
171
		// Return object.
172 1
		return $object;
173
	}
174
}
175