forked from smartemailing/types
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Address.php
82 lines (66 loc) · 1.47 KB
/
Address.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
declare(strict_types = 1);
namespace SmartEmailing\Types;
use SmartEmailing\Types\Comparable\ArrayComparableTrait;
use SmartEmailing\Types\Comparable\ComparableInterface;
use SmartEmailing\Types\ExtractableTraits\ArrayExtractableTrait;
final class Address implements ToArrayInterface, ComparableInterface
{
use ArrayExtractableTrait;
use ArrayComparableTrait;
/**
* @var string
*/
private $streetAndNumber;
/**
* @var string
*/
private $town;
/**
* @var \SmartEmailing\Types\ZipCode
*/
private $zipCode;
/**
* @var \SmartEmailing\Types\CountryCode
*/
private $country;
/**
* @param array<mixed> $data
*/
private function __construct(
array $data
) {
$this->streetAndNumber = StringType::extract($data, 'street_and_number');
$this->town = StringType::extract($data, 'town');
$this->zipCode = ZipCode::extract($data, 'zip_code');
$this->country = CountryCode::extract($data, 'country');
}
/**
* @return array<mixed>
*/
public function toArray(): array
{
return [
'street_and_number' => $this->streetAndNumber,
'town' => $this->town,
'zip_code' => $this->zipCode->getValue(),
'country' => $this->country->getValue(),
];
}
public function getStreetAndNumber(): string
{
return $this->streetAndNumber;
}
public function getTown(): string
{
return $this->town;
}
public function getZipCode(): ZipCode
{
return $this->zipCode;
}
public function getCountry(): CountryCode
{
return $this->country;
}
}