1
|
|
|
<?php declare(strict_types = 1); |
2
|
|
|
|
3
|
|
|
namespace Link0\Bunq\Domain; |
4
|
|
|
|
5
|
|
|
final class Address |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* @var string |
9
|
|
|
*/ |
10
|
|
|
private $street; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @var string |
14
|
|
|
*/ |
15
|
|
|
private $houseNumber; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
private $postalCode; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
private $city; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
private $country; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
private $province; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param string $street |
39
|
|
|
* @param string $houseNumber |
40
|
|
|
* @param string $postalCode |
41
|
|
|
* @param string $city |
42
|
|
|
* @param string $country |
43
|
|
|
* @param string $province |
44
|
|
|
*/ |
45
|
|
|
public function __construct( |
46
|
|
|
string $street, |
47
|
|
|
string $houseNumber, |
48
|
|
|
string $postalCode, |
49
|
|
|
string $city, |
50
|
|
|
string $country, |
51
|
|
|
string $province |
52
|
|
|
) { |
53
|
|
|
$this->street = $street; |
54
|
|
|
$this->houseNumber = $houseNumber; |
55
|
|
|
$this->postalCode = $postalCode; |
56
|
|
|
$this->city = $city; |
57
|
|
|
$this->country = $country; |
58
|
|
|
$this->province = $province; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param array $address |
63
|
|
|
* @return Address |
64
|
|
|
*/ |
65
|
|
|
public static function fromArray(array $address): Address |
66
|
|
|
{ |
67
|
|
|
return new Address( |
68
|
|
|
$address['street'], |
69
|
|
|
$address['house_number'], |
70
|
|
|
$address['postal_code'], |
71
|
|
|
$address['city'], |
72
|
|
|
$address['country'], |
73
|
|
|
$address['province'] === null ? '' : $address['province'] |
74
|
|
|
); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return array |
79
|
|
|
*/ |
80
|
|
|
public function toArray() |
81
|
|
|
{ |
82
|
|
|
return [ |
83
|
|
|
'street' => $this->street(), |
84
|
|
|
'house_number' => $this->houseNumber(), |
85
|
|
|
'postal_code' => $this->postalCode(), |
86
|
|
|
'city' => $this->city(), |
87
|
|
|
'country' => $this->country(), |
88
|
|
|
'province' => $this->province(), |
89
|
|
|
]; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return string |
94
|
|
|
*/ |
95
|
|
|
public function street(): string |
96
|
|
|
{ |
97
|
|
|
return $this->street; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @return string |
102
|
|
|
*/ |
103
|
|
|
public function houseNumber(): string |
104
|
|
|
{ |
105
|
|
|
return $this->houseNumber; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @return string |
110
|
|
|
*/ |
111
|
|
|
public function postalCode(): string |
112
|
|
|
{ |
113
|
|
|
return $this->postalCode; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @return string |
118
|
|
|
*/ |
119
|
|
|
public function city(): string |
120
|
|
|
{ |
121
|
|
|
return $this->city; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @return string |
126
|
|
|
*/ |
127
|
|
|
public function country(): string |
128
|
|
|
{ |
129
|
|
|
return $this->country; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @return string |
134
|
|
|
*/ |
135
|
|
|
public function province(): string |
136
|
|
|
{ |
137
|
|
|
return $this->province; |
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
|