Passed
Push — master ( 92591d...b586f0 )
by Aimeos
15:24
created

Base::setMobile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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

476
		if( $email != '' && preg_match( $regex, /** @scrutinizer ignore-type */ $email ) !== 1 ) {
Loading history...
477
			throw new \Aimeos\MShop\Exception( sprintf( 'Invalid characters in email address: "%1$s"', $email ) );
478
		}
479
480
		return $this->set( $this->prefix . 'email', (string) $email );
481
	}
482
483
484
	/**
485
	 * Returns the website URL.
486
	 *
487
	 * @return string Website URL
488
	 */
489
	public function getWebsite() : string
490
	{
491
		return $this->get( $this->prefix . 'website', '' );
492
	}
493
494
495
	/**
496
	 * Sets a new website URL.
497
	 *
498
	 * @param string|null $website New website URL
499
	 * @return \Aimeos\MShop\Common\Item\Address\Iface Common address item for chaining method calls
500
	 */
501
	public function setWebsite( ?string $website ) : \Aimeos\MShop\Common\Item\Address\Iface
502
	{
503
		$pattern = '#^([a-z]+://)?[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]+)+(:[0-9]+)?(/.*)?$#';
504
505
		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

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