Passed
Push — master ( f52afb...8d8aff )
by Aimeos
04:36
created

Base::setTitle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2011
6
 * @copyright Aimeos (aimeos.org), 2015-2024
7
 * @package MShop
8
 * @subpackage Common
9
 */
10
11
12
namespace Aimeos\MShop\Common\Item\Address;
13
14
15
/**
16
 * Abstract class for address items.
17
 *
18
 * @package MShop
19
 * @subpackage Common
20
 */
21
abstract class Base
22
	extends \Aimeos\MShop\Common\Item\Base
23
	implements \Aimeos\MShop\Common\Item\Address\Iface
24
{
25
	private string $prefix;
26
27
28
	/**
29
	 * Initializes the address item.
30
	 *
31
	 * @param string $prefix Key prefix that should be used for toArray()/fromArray() like "customer.address."
32
	 * @param array $values Associative list of key/value pairs containing address data
33
	 */
34
	public function __construct( string $prefix, array $values = [] )
35
	{
36
		parent::__construct( $prefix, $values, str_replace( '.', '/', rtrim( $prefix, '.' ) ) );
37
38
		$this->prefix = $prefix;
39
	}
40
41
42
	/**
43
	 * Returns the company name.
44
	 *
45
	 * @return string Company name
46
	 */
47
	public function getCompany() : string
48
	{
49
		return (string) $this->get( $this->prefix . 'company', '' );
50
	}
51
52
53
	/**
54
	 * Sets a new company name.
55
	 *
56
	 * @param string|null $company New company name
57
	 * @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls
58
	 */
59
	public function setCompany( ?string $company ) : \Aimeos\MShop\Common\Item\Address\Iface
60
	{
61
		return $this->set( $this->prefix . 'company', (string) $company );
62
	}
63
64
65
	/**
66
	 * Returns the vatid.
67
	 *
68
	 * @return string vatid
69
	 */
70
	public function getVatID() : string
71
	{
72
		return (string) $this->get( $this->prefix . 'vatid', '' );
73
	}
74
75
76
	/**
77
	 * Sets a new vatid.
78
	 *
79
	 * @param string|null $vatid New vatid
80
	 * @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls
81
	 */
82
	public function setVatID( ?string $vatid ) : \Aimeos\MShop\Common\Item\Address\Iface
83
	{
84
		return $this->set( $this->prefix . 'vatid', (string) $vatid );
85
	}
86
87
88
	/**
89
	 * Returns the salutation constant for the person described by the address.
90
	 *
91
	 * @return string Saluatation code
92
	 */
93
	public function getSalutation() : string
94
	{
95
		return $this->get( $this->prefix . 'salutation', '' );
96
	}
97
98
99
	/**
100
	 * Sets the new salutation for the person described by the address.
101
	 *
102
	 * @param string|null $salutation Salutation constant defined in \Aimeos\MShop\Common\Item\Address\Base
103
	 * @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls
104
	 */
105
	public function setSalutation( ?string $salutation ) : \Aimeos\MShop\Common\Item\Address\Iface
106
	{
107
		return $this->set( $this->prefix . 'salutation', $this->checkSalutation( (string) $salutation ) );
108
	}
109
110
111
	/**
112
	 * Returns the title of the person.
113
	 *
114
	 * @return string Title of the person
115
	 */
116
	public function getTitle() : string
117
	{
118
		return $this->get( $this->prefix . 'title', '' );
119
	}
120
121
122
	/**
123
	 * Sets a new title of the person.
124
	 *
125
	 * @param string|null $title New title of the person
126
	 * @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls
127
	 */
128
	public function setTitle( ?string $title ) : \Aimeos\MShop\Common\Item\Address\Iface
129
	{
130
		return $this->set( $this->prefix . 'title', (string) $title );
131
	}
132
133
134
	/**
135
	 * Returns the first name of the person.
136
	 *
137
	 * @return string First name of the person
138
	 */
139
	public function getFirstname() : string
140
	{
141
		return $this->get( $this->prefix . 'firstname', '' );
142
	}
143
144
145
	/**
146
	 * Sets a new first name of the person.
147
	 *
148
	 * @param string|null $firstname New first name of the person
149
	 * @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls
150
	 */
151
	public function setFirstname( ?string $firstname ) : \Aimeos\MShop\Common\Item\Address\Iface
152
	{
153
		return $this->set( $this->prefix . 'firstname', (string) $firstname );
154
	}
155
156
157
	/**
158
	 * Returns the last name of the person.
159
	 *
160
	 * @return string Last name of the person
161
	 */
162
	public function getLastname() : string
163
	{
164
		return $this->get( $this->prefix . 'lastname', '' );
165
	}
166
167
168
	/**
169
	 * Sets a new last name of the person.
170
	 *
171
	 * @param string|null $lastname New last name of the person
172
	 * @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls
173
	 */
174
	public function setLastname( ?string $lastname ) : \Aimeos\MShop\Common\Item\Address\Iface
175
	{
176
		return $this->set( $this->prefix . 'lastname', (string) $lastname );
177
	}
178
179
180
	/**
181
	 * Returns the first address part, e.g. the street name.
182
	 *
183
	 * @return string First address part
184
	 */
185
	public function getAddress1() : string
186
	{
187
		return $this->get( $this->prefix . 'address1', '' );
188
	}
189
190
191
	/**
192
	 * Sets a new first address part, e.g. the street name.
193
	 *
194
	 * @param string|null $address1 New first address part
195
	 * @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls
196
	 */
197
	public function setAddress1( ?string $address1 ) : \Aimeos\MShop\Common\Item\Address\Iface
198
	{
199
		return $this->set( $this->prefix . 'address1', (string) $address1 );
200
	}
201
202
203
	/**
204
	 * Returns the second address part, e.g. the house number.
205
	 *
206
	 * @return string Second address part
207
	 */
208
	public function getAddress2() : string
209
	{
210
		return $this->get( $this->prefix . 'address2', '' );
211
	}
212
213
214
	/**
215
	 * Sets a new second address part, e.g. the house number.
216
	 *
217
	 * @param string|null $address2 New second address part
218
	 * @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls
219
	 */
220
	public function setAddress2( ?string $address2 ) : \Aimeos\MShop\Common\Item\Address\Iface
221
	{
222
		return $this->set( $this->prefix . 'address2', (string) $address2 );
223
	}
224
225
226
	/**
227
	 * Returns the third address part, e.g. the house name or floor number.
228
	 *
229
	 * @return string third address part
230
	 */
231
	public function getAddress3() : string
232
	{
233
		return $this->get( $this->prefix . 'address3', '' );
234
	}
235
236
237
	/**
238
	 * Sets a new third address part, e.g. the house name or floor number.
239
	 *
240
	 * @param string|null $address3 New third address part
241
	 * @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls
242
	 */
243
	public function setAddress3( ?string $address3 ) : \Aimeos\MShop\Common\Item\Address\Iface
244
	{
245
		return $this->set( $this->prefix . 'address3', (string) $address3 );
246
	}
247
248
249
	/**
250
	 * Returns the postal code.
251
	 *
252
	 * @return string Postal code
253
	 */
254
	public function getPostal() : string
255
	{
256
		return $this->get( $this->prefix . 'postal', '' );
257
	}
258
259
260
	/**
261
	 * Sets a new postal code.
262
	 *
263
	 * @param string|null $postal New postal code
264
	 * @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls
265
	 */
266
	public function setPostal( ?string $postal ) : \Aimeos\MShop\Common\Item\Address\Iface
267
	{
268
		return $this->set( $this->prefix . 'postal', (string) $postal );
269
	}
270
271
272
	/**
273
	 * Returns the city name.
274
	 *
275
	 * @return string City name
276
	 */
277
	public function getCity() : string
278
	{
279
		return $this->get( $this->prefix . 'city', '' );
280
	}
281
282
283
	/**
284
	 * Sets a new city name.
285
	 *
286
	 * @param string|null $city New city name
287
	 * @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls
288
	 */
289
	public function setCity( ?string $city ) : \Aimeos\MShop\Common\Item\Address\Iface
290
	{
291
		return $this->set( $this->prefix . 'city', (string) $city );
292
	}
293
294
295
	/**
296
	 * Returns the state name.
297
	 *
298
	 * @return string State name
299
	 */
300
	public function getState() : string
301
	{
302
		return $this->get( $this->prefix . 'state', '' );
303
	}
304
305
306
	/**
307
	 * Sets a new state name.
308
	 *
309
	 * @param string|null $state New state name
310
	 * @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls
311
	 */
312
	public function setState( ?string $state ) : \Aimeos\MShop\Common\Item\Address\Iface
313
	{
314
		return $this->set( $this->prefix . 'state', (string) $state );
315
	}
316
317
318
	/**
319
	 * Returns the unique ID of the country the address belongs to.
320
	 *
321
	 * @return string|null Unique ID of the country
322
	 */
323
	public function getCountryId() : ?string
324
	{
325
		return $this->get( $this->prefix . 'countryid' );
326
	}
327
328
329
	/**
330
	 * Sets the ID of the country the address is in.
331
	 *
332
	 * @param string|null $countryid Unique ID of the country
333
	 * @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls
334
	 */
335
	public function setCountryId( ?string $countryid ) : \Aimeos\MShop\Common\Item\Address\Iface
336
	{
337
		return $this->set( $this->prefix . 'countryid', $this->checkCountryId( $countryid ) );
338
	}
339
340
341
	/**
342
	 * Returns the unique ID of the language.
343
	 *
344
	 * @return string|null Unique ID of the language
345
	 */
346
	public function getLanguageId() : ?string
347
	{
348
		return $this->get( $this->prefix . 'languageid' );
349
	}
350
351
352
	/**
353
	 * Sets the ID of the language.
354
	 *
355
	 * @param string|null $langid Unique ID of the language
356
	 * @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls
357
	 */
358
	public function setLanguageId( ?string $langid ) : \Aimeos\MShop\Common\Item\Address\Iface
359
	{
360
		return $this->set( $this->prefix . 'languageid', $this->checkLanguageId( $langid ) );
361
	}
362
363
364
	/**
365
	 * Returns the telephone number.
366
	 *
367
	 * @return string Telephone number
368
	 */
369
	public function getTelephone() : string
370
	{
371
		return $this->get( $this->prefix . 'telephone', '' );
372
	}
373
374
375
	/**
376
	 * Sets a new telephone number.
377
	 *
378
	 * @param string|null $telephone New telephone number
379
	 * @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls
380
	 */
381
	public function setTelephone( ?string $telephone ) : \Aimeos\MShop\Common\Item\Address\Iface
382
	{
383
		return $this->set( $this->prefix . 'telephone', (string) $telephone );
384
	}
385
386
387
	/**
388
	 * Returns the telefax number.
389
	 *
390
	 * @return string Telefax number
391
	 */
392
	public function getTelefax() : string
393
	{
394
		return $this->get( $this->prefix . 'telefax', '' );
395
	}
396
397
398
	/**
399
	 * Sets a new telefax number.
400
	 *
401
	 * @param string|null $telefax New telefax number
402
	 * @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls
403
	 */
404
	public function setTelefax( ?string $telefax ) : \Aimeos\MShop\Common\Item\Address\Iface
405
	{
406
		return $this->set( $this->prefix . 'telefax', (string) $telefax );
407
	}
408
409
410
	/**
411
	 * Returns the mobile number.
412
	 *
413
	 * @return string Mobile number
414
	 */
415
	public function getMobile() : string
416
	{
417
		return $this->get( $this->prefix . 'mobile', '' );
418
	}
419
420
421
	/**
422
	 * Sets a new mobile number.
423
	 *
424
	 * @param string|null $value New mobile number
425
	 * @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls
426
	 */
427
	public function setMobile( ?string $value ) : \Aimeos\MShop\Common\Item\Address\Iface
428
	{
429
		return $this->set( $this->prefix . 'mobile', (string) $value );
430
	}
431
432
433
	/**
434
	 * Returns the email address.
435
	 *
436
	 * @return string Email address
437
	 */
438
	public function getEmail() : string
439
	{
440
		return $this->get( $this->prefix . 'email', '' );
441
	}
442
443
444
	/**
445
	 * Sets a new email address.
446
	 *
447
	 * @param string|null $email New email address
448
	 * @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls
449
	 */
450
	public function setEmail( ?string $email ) : \Aimeos\MShop\Common\Item\Address\Iface
451
	{
452
		$regex = '/^(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){255,})(?!(?:(?:\x22?\x5C[\x00-\x7E]\x22?)|(?:\x22?[^\x5C\x22]\x22?)){65,}@)(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22))(?:\.(?:(?:[\x21\x23-\x27\x2A\x2B\x2D\x2F-\x39\x3D\x3F\x5E-\x7E]+)|(?:\x22(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|(?:\x5C[\x00-\x7F]))*\x22)))*@(?:(?:(?!.*[^.]{64,})(?:(?:(?:xn--)?[a-z0-9]+(?:-[a-z0-9]+)*\.){1,126}){1,}(?:(?:[a-z][a-z0-9]*)|(?:(?:xn--)[a-z0-9]+))(?:-[a-z0-9]+)*)|(?:\[(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(?:(?!(?:.*[a-f0-9][:\]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))|(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}:)|(?:(?!(?:.*[a-f0-9]:){5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?)))?(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\.(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))\]))$/iD';
453
454
		if( $email != '' && preg_match( $regex, $email ) !== 1 ) {
0 ignored issues
show
Bug introduced by
It seems like $email can also be of type null; however, parameter $subject of preg_match() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

454
		if( $email != '' && preg_match( $regex, /** @scrutinizer ignore-type */ $email ) !== 1 ) {
Loading history...
455
			throw new \Aimeos\MShop\Exception( sprintf( 'Invalid characters in email address: "%1$s"', $email ) );
456
		}
457
458
		return $this->set( $this->prefix . 'email', (string) $email );
459
	}
460
461
462
	/**
463
	 * Returns the website URL.
464
	 *
465
	 * @return string Website URL
466
	 */
467
	public function getWebsite() : string
468
	{
469
		return $this->get( $this->prefix . 'website', '' );
470
	}
471
472
473
	/**
474
	 * Sets a new website URL.
475
	 *
476
	 * @param string|null $website New website URL
477
	 * @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls
478
	 */
479
	public function setWebsite( ?string $website ) : \Aimeos\MShop\Common\Item\Address\Iface
480
	{
481
		$pattern = '#^([a-z]+://)?[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]+)+(:[0-9]+)?(/.*)?$#';
482
483
		if( $website != '' && preg_match( $pattern, $website ) !== 1 ) {
0 ignored issues
show
Bug introduced by
It seems like $website can also be of type null; however, parameter $subject of preg_match() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

483
		if( $website != '' && preg_match( $pattern, /** @scrutinizer ignore-type */ $website ) !== 1 ) {
Loading history...
484
			throw new \Aimeos\MShop\Exception( sprintf( 'Invalid web site URL "%1$s"', $website ) );
485
		}
486
487
		return $this->set( $this->prefix . 'website', (string) $website );
488
	}
489
490
491
	/**
492
	 * Returns the longitude coordinate of the customer address
493
	 *
494
	 * @return float|null Longitude coordinate as decimal value or null
495
	 */
496
	public function getLongitude() : ?float
497
	{
498
		if( ( $result = $this->get( $this->prefix . 'longitude' ) ) !== null ) {
499
			return (float) $result;
500
		}
501
502
		return null;
503
	}
504
505
506
	/**
507
	 * Sets the longitude coordinate of the customer address
508
	 *
509
	 * @param string|null $value Longitude coordinate as decimal value or null
510
	 * @return \Aimeos\MShop\Customer\Item\Iface Customer address item for chaining method calls
511
	 */
512
	public function setLongitude( ?string $value ) : \Aimeos\MShop\Common\Item\Address\Iface
513
	{
514
		return $this->set( $this->prefix . 'longitude', $value !== '' && $value !== null ? $value : null );
515
	}
516
517
518
	/**
519
	 * Returns the latitude coordinate of the customer address
520
	 *
521
	 * @return float|null Latitude coordinate as decimal value or null
522
	 */
523
	public function getLatitude() : ?float
524
	{
525
		if( ( $result = $this->get( $this->prefix . 'latitude' ) ) !== null ) {
526
			return (float) $result;
527
		}
528
529
		return null;
530
	}
531
532
533
	/**
534
	 * Sets the latitude coordinate of the customer address
535
	 *
536
	 * @param string|null $value Latitude coordinate as decimal value or null
537
	 * @return \Aimeos\MShop\Customer\Item\Iface Customer address item for chaining method calls
538
	 */
539
	public function setLatitude( ?string $value ) : \Aimeos\MShop\Common\Item\Address\Iface
540
	{
541
		return $this->set( $this->prefix . 'latitude', $value !== '' && $value !== null ? $value : null );
542
	}
543
544
545
	/**
546
	 * Returns the birthday of the customer item.
547
	 *
548
	 * @return string|null Birthday in YYYY-MM-DD format
549
	 */
550
	public function getBirthday() : ?string
551
	{
552
		return $this->get( $this->prefix . 'birthday' );
553
	}
554
555
556
	/**
557
	 * Sets the birthday of the customer item.
558
	 *
559
	 * @param string|null $value Birthday of the customer item
560
	 * @return \Aimeos\MShop\Common\Item\Address\Iface Customer address item for chaining method calls
561
	 */
562
	public function setBirthday( ?string $value ) : \Aimeos\MShop\Common\Item\Address\Iface
563
	{
564
		return $this->set( $this->prefix . 'birthday', $this->checkDateOnlyFormat( $value ) );
565
	}
566
567
568
	/**
569
	 * Returns the customer ID this address belongs to
570
	 *
571
	 * @return string|null Customer ID of the address
572
	 */
573
	public function getParentId() : ?string
574
	{
575
		return $this->get( $this->prefix . 'parentid' );
576
	}
577
578
579
	/**
580
	 * Sets the new customer ID this address belongs to
581
	 *
582
	 * @param string|null $parentid New customer ID of the address
583
	 * @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls
584
	 */
585
	public function setParentId( ?string $parentid ) : \Aimeos\MShop\Common\Item\Iface
586
	{
587
		return $this->set( $this->prefix . 'parentid', $parentid );
588
	}
589
590
591
	/**
592
	 * Returns the position of the address item.
593
	 *
594
	 * @return int Position of the address item
595
	 */
596
	public function getPosition() : int
597
	{
598
		return $this->get( $this->prefix . 'position', 0 );
599
	}
600
601
602
	/**
603
	 * Sets the Position of the address item.
604
	 *
605
	 * @param int $position Position of the address item
606
	 * @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls
607
	 */
608
	public function setPosition( int $position ) : \Aimeos\MShop\Common\Item\Iface
609
	{
610
		return $this->set( $this->prefix . 'position', $position );
611
	}
612
613
614
	/**
615
	 * Copies the values of the address item into another one.
616
	 *
617
	 * @param \Aimeos\MShop\Common\Item\Address\Iface $item Address item
618
	 * @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls
619
	 */
620
	public function copyFrom( \Aimeos\MShop\Common\Item\Address\Iface $item ) : \Aimeos\MShop\Common\Item\Address\Iface
621
	{
622
		$values = $item->toArray();
623
		$this->fromArray( $values );
624
625
		$this->setCompany( $item->getCompany() );
626
		$this->setVatID( $item->getVatID() );
627
		$this->setSalutation( $item->getSalutation() );
628
		$this->setTitle( $item->getTitle() );
629
		$this->setFirstname( $item->getFirstname() );
630
		$this->setLastname( $item->getLastname() );
631
		$this->setAddress1( $item->getAddress1() );
632
		$this->setAddress2( $item->getAddress2() );
633
		$this->setAddress3( $item->getAddress3() );
634
		$this->setPostal( $item->getPostal() );
635
		$this->setCity( $item->getCity() );
636
		$this->setState( $item->getState() );
637
		$this->setCountryId( $item->getCountryId() );
638
		$this->setLanguageId( $item->getLanguageId() );
639
		$this->setTelephone( $item->getTelephone() );
640
		$this->setTelefax( $item->getTelefax() );
641
		$this->setMobile( $item->getMobile() );
642
		$this->setEmail( $item->getEmail() );
643
		$this->setWebsite( $item->getWebsite() );
644
		$this->setLongitude( $item->getLongitude() );
645
		$this->setLatitude( $item->getLatitude() );
646
		$this->setBirthday( $item->getBirthday() );
647
648
		return $this;
649
	}
650
651
652
	/*
653
	 * Sets the item values from the given array and removes that entries from the list
654
	 *
655
	 * @param array &$list Associative list of item keys and their values
656
	 * @param bool True to set private properties too, false for public only
657
	 * @return \Aimeos\MShop\Common\Item\Address\Iface Address item for chaining method calls
658
	 */
659
	public function fromArray( array &$list, bool $private = false ) : \Aimeos\MShop\Common\Item\Iface
660
	{
661
		$item = parent::fromArray( $list, $private );
662
663
		foreach( $list as $idx => $value )
664
		{
665
			$pos = strrpos( $idx, '.' );
666
			$key = $pos ? substr( $idx, $pos + 1 ) : $idx;
667
668
			switch( $key )
669
			{
670
				case 'parentid': !$private ?: $item = $item->setParentId( $value ); break;
671
				case 'salutation': $item = $item->setSalutation( $value ); break;
672
				case 'company': $item = $item->setCompany( $value ); break;
673
				case 'vatid': $item = $item->setVatID( $value ); break;
674
				case 'title': $item = $item->setTitle( $value ); break;
675
				case 'firstname': $item = $item->setFirstname( $value ); break;
676
				case 'lastname': $item = $item->setLastname( $value ); break;
677
				case 'address1': $item = $item->setAddress1( $value ); break;
678
				case 'address2': $item = $item->setAddress2( $value ); break;
679
				case 'address3': $item = $item->setAddress3( $value ); break;
680
				case 'postal': $item = $item->setPostal( $value ); break;
681
				case 'city': $item = $item->setCity( $value ); break;
682
				case 'state': $item = $item->setState( $value ); break;
683
				case 'countryid': $item = $item->setCountryId( $value ); break;
684
				case 'languageid': $item = $item->setLanguageId( $value ); break;
685
				case 'telephone': $item = $item->setTelephone( $value ); break;
686
				case 'telefax': $item = $item->setTelefax( $value ); break;
687
				case 'mobile': $item = $item->setMobile( $value ); break;
688
				case 'email': $item = $item->setEmail( $value ); break;
689
				case 'website': $item = $item->setWebsite( $value ); break;
690
				case 'longitude': $item = $item->setLongitude( $value ); break;
691
				case 'latitude': $item = $item->setLatitude( $value ); break;
692
				case 'birthday': $item = $item->setBirthday( $value ); break;
693
				case 'position': $item = $item->setPosition( $value ); break;
694
				default: continue 2;
695
			}
696
697
			unset( $list[$idx] );
698
		}
699
700
		return $item;
701
	}
702
703
704
	/**
705
	 * Returns the item values as array.
706
	 *
707
	 * @param bool True to return private properties, false for public only
708
	 * @return array Associative list of item properties and their values
709
	 */
710
	public function toArray( bool $private = false ) : array
711
	{
712
		$list = parent::toArray( $private );
713
714
		$list[$this->prefix . 'salutation'] = $this->getSalutation();
715
		$list[$this->prefix . 'company'] = $this->getCompany();
716
		$list[$this->prefix . 'vatid'] = $this->getVatID();
717
		$list[$this->prefix . 'title'] = $this->getTitle();
718
		$list[$this->prefix . 'firstname'] = $this->getFirstname();
719
		$list[$this->prefix . 'lastname'] = $this->getLastname();
720
		$list[$this->prefix . 'address1'] = $this->getAddress1();
721
		$list[$this->prefix . 'address2'] = $this->getAddress2();
722
		$list[$this->prefix . 'address3'] = $this->getAddress3();
723
		$list[$this->prefix . 'postal'] = $this->getPostal();
724
		$list[$this->prefix . 'city'] = $this->getCity();
725
		$list[$this->prefix . 'state'] = $this->getState();
726
		$list[$this->prefix . 'countryid'] = $this->getCountryId();
727
		$list[$this->prefix . 'languageid'] = $this->getLanguageId();
728
		$list[$this->prefix . 'telephone'] = $this->getTelephone();
729
		$list[$this->prefix . 'telefax'] = $this->getTelefax();
730
		$list[$this->prefix . 'mobile'] = $this->getMobile();
731
		$list[$this->prefix . 'email'] = $this->getEmail();
732
		$list[$this->prefix . 'website'] = $this->getWebsite();
733
		$list[$this->prefix . 'longitude'] = $this->getLongitude();
734
		$list[$this->prefix . 'latitude'] = $this->getLatitude();
735
		$list[$this->prefix . 'birthday'] = $this->getBirthday();
736
		$list[$this->prefix . 'position'] = $this->getPosition();
737
738
		if( $private === true ) {
739
			$list[$this->prefix . 'parentid'] = $this->getParentId();
740
		}
741
742
		return $list;
743
	}
744
745
746
	/**
747
	 * Checks the given address salutation is valid
748
	 *
749
	 * @param string $value Address salutation defined in \Aimeos\MShop\Common\Item\Address\Base
750
	 * @throws \Aimeos\MShop\Exception If salutation is invalid
751
	 */
752
	protected function checkSalutation( string $value )
753
	{
754
		if( strlen( $value ) > 8 ) {
755
			throw new \Aimeos\MShop\Exception( sprintf( 'Address salutation "%1$s" not within allowed range', $value ) );
756
		}
757
758
		return $value;
759
	}
760
761
762
	/**
763
	 * Returns the prefix for toArray() and fromArray() methods.
764
	 *
765
	 * @return string Prefix for toArray() and fromArray() methods
766
	 */
767
	protected function getPrefix() : string
768
	{
769
		return $this->prefix;
770
	}
771
}
772