Address::set_street()   A
last analyzed

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-2022 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 implements \JsonSerializable {
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
	 * @return void
102
	 */
103 12
	public function __construct( $last_name, $street, $postal_code, $city, $country_code ) {
104 12
		$this->set_last_name( $last_name );
105 12
		$this->set_street( $street );
106 12
		$this->set_postal_code( $postal_code );
107 12
		$this->set_city( $city );
108 12
		$this->set_country_code( $country_code );
109 12
	}
110
111
	/**
112
	 * Get first name.
113
	 *
114
	 * @return string|null
115
	 */
116 1
	public function get_first_name() {
117 1
		return $this->first_name;
118
	}
119
120
	/**
121
	 * Set first name.
122
	 *
123
	 * @param string|null $first_name First name.
124
	 * @return void
125
	 */
126 12
	public function set_first_name( $first_name ) {
127 12
		DataHelper::validate_null_or_an( $first_name, 50, 'Address.firstName' );
128
129 12
		$this->first_name = $first_name;
130 12
	}
131
132
	/**
133
	 * Get middle name.
134
	 *
135
	 * @return string|null
136
	 */
137 1
	public function get_middle_name() {
138 1
		return $this->middle_name;
139
	}
140
141
	/**
142
	 * Set middle name.
143
	 *
144
	 * @param string|null $middle_name Middle name.
145
	 * @return void
146
	 */
147 12
	public function set_middle_name( $middle_name ) {
148 12
		DataHelper::validate_null_or_an( $middle_name, 20, 'Address.middleName' );
149
150 12
		$this->middle_name = $middle_name;
151 12
	}
152
153
	/**
154
	 * Get last name.
155
	 *
156
	 * @return string
157
	 */
158 1
	public function get_last_name() {
159 1
		return $this->last_name;
160
	}
161
162
	/**
163
	 * Set last name.
164
	 *
165
	 * @param string $last_name Last name.
166
	 * @return void
167
	 */
168 12
	public function set_last_name( $last_name ) {
169 12
		DataHelper::validate_an( $last_name, 50, 'Address.lastName' );
170
171 12
		$this->last_name = $last_name;
172 12
	}
173
174
	/**
175
	 * Get street.
176
	 *
177
	 * @return string
178
	 */
179 2
	public function get_street() {
180 2
		return $this->street;
181
	}
182
183
	/**
184
	 * Set street.
185
	 *
186
	 * @param string $street Street.
187
	 * @return void
188
	 */
189 12
	public function set_street( $street ) {
190 12
		DataHelper::validate_an( $street, 100, 'Address.street' );
191
192 12
		$this->street = $street;
193 12
	}
194
195
	/**
196
	 * Get house number.
197
	 *
198
	 * @return string|null
199
	 */
200 1
	public function get_house_number() {
201 1
		return $this->house_number;
202
	}
203
204
	/**
205
	 * Set house number.
206
	 *
207
	 * @param string|null $house_number House number.
208
	 * @return void
209
	 */
210 12
	public function set_house_number( $house_number ) {
211 12
		DataHelper::validate_null_or_an( $house_number, 100, 'Address.houseNumber' );
212
213 12
		$this->house_number = $house_number;
214 12
	}
215
216
	/**
217
	 * Get house number addition.
218
	 *
219
	 * @return string|null
220
	 */
221 1
	public function get_house_number_addition() {
222 1
		return $this->house_number_addition;
223
	}
224
225
	/**
226
	 * Set house number addition.
227
	 *
228
	 * @param string|null $house_number_addition House number addition.
229
	 * @return void
230
	 */
231 12
	public function set_house_number_addition( $house_number_addition ) {
232 12
		DataHelper::validate_null_or_an( $house_number_addition, 6, 'Address.houseNumberAddition' );
233
234 12
		$this->house_number_addition = $house_number_addition;
235 12
	}
236
237
	/**
238
	 * Get postal code.
239
	 *
240
	 * @return string
241
	 */
242 1
	public function get_postal_code() {
243 1
		return $this->postal_code;
244
	}
245
246
	/**
247
	 * Set postal code.
248
	 *
249
	 * @param string $postal_code Postal code.
250
	 * @return void
251
	 */
252 12
	public function set_postal_code( $postal_code ) {
253 12
		DataHelper::validate_an( $postal_code, 10, 'Address.postalCode' );
254
255 12
		$this->postal_code = $postal_code;
256 12
	}
257
258
	/**
259
	 * Get city.
260
	 *
261
	 * @return string
262
	 */
263 1
	public function get_city() {
264 1
		return $this->city;
265
	}
266
267
	/**
268
	 * Set city.
269
	 *
270
	 * @param string $city City.
271
	 * @return void
272
	 */
273 12
	public function set_city( $city ) {
274 12
		DataHelper::validate_an( $city, 40, 'Address.city' );
275
276 12
		$this->city = $city;
277 12
	}
278
279
	/**
280
	 * Get country code.
281
	 *
282
	 * @return string
283
	 */
284 1
	public function get_country_code() {
285 1
		return $this->country_code;
286
	}
287
288
	/**
289
	 * Set country code.
290
	 *
291
	 * @param string $country_code Country code.
292
	 * @return void
293
	 */
294 12
	public function set_country_code( $country_code ) {
295 12
		DataHelper::validate_an( $country_code, 2, 'Address.countryCode' );
296
297 12
		$this->country_code = $country_code;
298 12
	}
299
300
	/**
301
	 * Get JSON.
302
	 *
303
	 * @return object
304
	 */
305
	public function jsonSerialize() {
306
		$object = (object) array();
307
308
		$object->firstName  = $this->first_name;
309
		$object->middleName = $this->middle_name;
310
		$object->lastName   = $this->last_name;
311
		$object->street     = $this->street;
312
313
		if ( null !== $this->house_number ) {
314
			$object->houseNumber = $this->house_number;
315
		}
316
317
		if ( null !== $this->house_number_addition ) {
318
			$object->houseNumberAddition = $this->house_number_addition;
319
		}
320
321
		$object->postalCode  = $this->postal_code;
322
		$object->city        = $this->city;
323
		$object->countryCode = $this->country_code;
324
325
		return $object;
326
	}
327
328
	/**
329
	 * Get signature fields.
330
	 *
331
	 * @param array<string> $fields Fields.
332
	 * @return array<string>
333
	 */
334 1
	public function get_signature_fields( $fields = array() ) {
335 1
		$fields[] = (string) $this->first_name;
336 1
		$fields[] = (string) $this->middle_name;
337 1
		$fields[] = $this->last_name;
338 1
		$fields[] = $this->street;
339
340 1
		if ( null !== $this->house_number ) {
341 1
			$fields[] = $this->house_number;
342
		}
343
344 1
		if ( null !== $this->house_number_addition ) {
345 1
			$fields[] = $this->house_number_addition;
346
		}
347
348 1
		$fields[] = $this->postal_code;
349 1
		$fields[] = $this->city;
350 1
		$fields[] = $this->country_code;
351
352 1
		return $fields;
353
	}
354
}
355