Failed Conditions
Push — master ( e22298...bcbd11 )
by Reüel
10:06 queued 11s
created

Address::set_country_code()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
/**
3
 * Address
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2019 Pronamic
7
 * @license   GPL-3.0-or-later
8
 * @package   Pronamic\WordPress\Pay\Gateways\OmniKassa2
9
 */
10
11
namespace Pronamic\WordPress\Pay\Gateways\OmniKassa2;
12
13
/**
14
 * Address
15
 *
16
 * @author  Remco Tolsma
17
 * @version 2.1.10
18
 * @since   2.0.2
19
 */
20
class Address {
21
	/**
22
	 * First name.
23
	 *
24
	 * @var string|null
25
	 */
26
	private $first_name;
27
28
	/**
29
	 * Insert or second name.
30
	 *
31
	 * @var string|null
32
	 */
33
	private $middle_name;
34
35
	/**
36
	 * Surname.
37
	 *
38
	 * @var string
39
	 */
40
	private $last_name;
41
42
	/**
43
	 * Street.
44
	 *
45
	 * Note: In case of payment via Visa, Mastercard, V PAY,
46
	 * Bancontact and Maestro the street name will be
47
	 * truncated to 50 characters.
48
	 *
49
	 * @var string
50
	 */
51
	private $street;
52
53
	/**
54
	 * House number.
55
	 *
56
	 * Note: In case of payment via Visa, Mastercard, V PAY,
57
	 * Bancontact and Maestro the houseNumber concatenated
58
	 * with houseNumberAddition (see below) will be
59
	 * truncated to 10 characters.
60
	 *
61
	 * @var string|null
62
	 */
63
	private $house_number;
64
65
	/**
66
	 * House number additions.
67
	 *
68
	 * @var string|null
69
	 */
70
	private $house_number_addition;
71
72
	/**
73
	 * Postal code.
74
	 *
75
	 * @var string
76
	 */
77
	private $postal_code;
78
79
	/**
80
	 * City.
81
	 *
82
	 * @var string
83
	 */
84
	private $city;
85
86
	/**
87
	 * Country code, ISO 3166-1 alpha-2.
88
	 *
89
	 * @var string
90
	 */
91
	private $country_code;
92
93
	/**
94
	 * Construct address.
95
	 *
96
	 * @param string $last_name    Last name.
97
	 * @param string $street       Street.
98
	 * @param string $postal_code  Postal code.
99
	 * @param string $city         City.
100
	 * @param string $country_code Country code.
101
	 */
102 12
	public function __construct( $last_name, $street, $postal_code, $city, $country_code ) {
103 12
		$this->set_last_name( $last_name );
104 12
		$this->set_street( $street );
105 12
		$this->set_postal_code( $postal_code );
106 12
		$this->set_city( $city );
107 12
		$this->set_country_code( $country_code );
108 12
	}
109
110
	/**
111
	 * Get first name.
112
	 *
113
	 * @return string|null
114
	 */
115 1
	public function get_first_name() {
116 1
		return $this->first_name;
117
	}
118
119
	/**
120
	 * Set first name.
121
	 *
122
	 * @param string|null $first_name First name.
123
	 */
124 12
	public function set_first_name( $first_name ) {
125 12
		DataHelper::validate_null_or_an( $first_name, 50, 'Address.firstName' );
126
127 12
		$this->first_name = $first_name;
128 12
	}
129
130
	/**
131
	 * Get middle name.
132
	 *
133
	 * @return string|null
134
	 */
135 1
	public function get_middle_name() {
136 1
		return $this->middle_name;
137
	}
138
139
	/**
140
	 * Set middle name.
141
	 *
142
	 * @param string|null $middle_name Middle name.
143
	 */
144 12
	public function set_middle_name( $middle_name ) {
145 12
		DataHelper::validate_null_or_an( $middle_name, 20, 'Address.middleName' );
146
147 12
		$this->middle_name = $middle_name;
148 12
	}
149
150
	/**
151
	 * Get last name.
152
	 *
153
	 * @return string
154
	 */
155 1
	public function get_last_name() {
156 1
		return $this->last_name;
157
	}
158
159
	/**
160
	 * Set last name.
161
	 *
162
	 * @param string $last_name Last name.
163
	 */
164 12
	public function set_last_name( $last_name ) {
165 12
		DataHelper::validate_an( $last_name, 50, 'Address.lastName' );
166
167 12
		$this->last_name = $last_name;
168 12
	}
169
170
	/**
171
	 * Get street.
172
	 *
173
	 * @return string
174
	 */
175 2
	public function get_street() {
176 2
		return $this->street;
177
	}
178
179
	/**
180
	 * Set street.
181
	 *
182
	 * @param string $street Street.
183
	 */
184 12
	public function set_street( $street ) {
185 12
		DataHelper::validate_an( $street, 100, 'Address.street' );
186
187 12
		$this->street = $street;
188 12
	}
189
190
	/**
191
	 * Get house number.
192
	 *
193
	 * @return string|null
194
	 */
195 1
	public function get_house_number() {
196 1
		return $this->house_number;
197
	}
198
199
	/**
200
	 * Set house number.
201
	 *
202
	 * @param string|null $house_number House number.
203
	 */
204 12
	public function set_house_number( $house_number ) {
205 12
		DataHelper::validate_null_or_an( $house_number, 100, 'Address.houseNumber' );
206
207 12
		$this->house_number = $house_number;
208 12
	}
209
210
	/**
211
	 * Get house number addition.
212
	 *
213
	 * @return string|null
214
	 */
215 1
	public function get_house_number_addition() {
216 1
		return $this->house_number_addition;
217
	}
218
219
	/**
220
	 * Set house number addition.
221
	 *
222
	 * @param string|null $house_number_addition House number addition.
223
	 */
224 12
	public function set_house_number_addition( $house_number_addition ) {
225 12
		DataHelper::validate_null_or_an( $house_number_addition, 6, 'Address.houseNumberAddition' );
226
227 12
		$this->house_number_addition = $house_number_addition;
228 12
	}
229
230
	/**
231
	 * Get postal code.
232
	 *
233
	 * @return string
234
	 */
235 1
	public function get_postal_code() {
236 1
		return $this->postal_code;
237
	}
238
239
	/**
240
	 * Set postal code.
241
	 *
242
	 * @param string $postal_code Postal code.
243
	 */
244 12
	public function set_postal_code( $postal_code ) {
245 12
		DataHelper::validate_an( $postal_code, 10, 'Address.postalCode' );
246
247 12
		$this->postal_code = $postal_code;
248 12
	}
249
250
	/**
251
	 * Get city.
252
	 *
253
	 * @return string
254
	 */
255 1
	public function get_city() {
256 1
		return $this->city;
257
	}
258
259
	/**
260
	 * Set city.
261
	 *
262
	 * @param string $city City.
263
	 */
264 12
	public function set_city( $city ) {
265 12
		DataHelper::validate_an( $city, 40, 'Address.city' );
266
267 12
		$this->city = $city;
268 12
	}
269
270
	/**
271
	 * Get country code.
272
	 *
273
	 * @return string
274
	 */
275 1
	public function get_country_code() {
276 1
		return $this->country_code;
277
	}
278
279
	/**
280
	 * Set country code.
281
	 *
282
	 * @param string $country_code Country code.
283
	 */
284 12
	public function set_country_code( $country_code ) {
285 12
		DataHelper::validate_an( $country_code, 2, 'Address.countryCode' );
286
287 12
		$this->country_code = $country_code;
288 12
	}
289
290
	/**
291
	 * Get JSON.
292
	 *
293
	 * @return object|null
294
	 */
295
	public function get_json() {
296
		$object = (object) array();
297
298
		$object->firstName  = $this->first_name;
299
		$object->middleName = $this->middle_name;
300
		$object->lastName   = $this->last_name;
301
		$object->street     = $this->street;
302
303
		if ( null !== $this->house_number ) {
304
			$object->houseNumber = $this->house_number;
305
		}
306
307
		if ( null !== $this->house_number_addition ) {
308
			$object->houseNumberAddition = $this->house_number_addition;
309
		}
310
311
		$object->postalCode  = $this->postal_code;
312
		$object->city        = $this->city;
313
		$object->countryCode = $this->country_code;
314
315
		return $object;
316
	}
317
318
	/**
319
	 * Get signature fields.
320
	 *
321
	 * @param array<string> $fields Fields.
322
	 * @return array<string>
323
	 */
324 1
	public function get_signature_fields( $fields = array() ) {
325 1
		$fields[] = \strval( $this->first_name );
326 1
		$fields[] = \strval( $this->middle_name );
327 1
		$fields[] = $this->last_name;
328 1
		$fields[] = $this->street;
329
330 1
		if ( null !== $this->house_number ) {
331 1
			$fields[] = $this->house_number;
332
		}
333
334 1
		if ( null !== $this->house_number_addition ) {
335 1
			$fields[] = $this->house_number_addition;
336
		}
337
338 1
		$fields[] = $this->postal_code;
339 1
		$fields[] = $this->city;
340 1
		$fields[] = $this->country_code;
341
342 1
		return $fields;
343
	}
344
}
345