|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
|
4
|
|
|
|
|
5
|
|
|
namespace WMDE\Fundraising\AddressChangeContext\Domain\Model; |
|
6
|
|
|
|
|
7
|
|
|
use WMDE\Fundraising\AddressChangeContext\UseCases\ChangeAddress\ChangeAddressValidationException; |
|
8
|
|
|
|
|
9
|
|
|
class Address { |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @var int|null |
|
13
|
|
|
* @phpstan-ignore-next-line |
|
14
|
|
|
*/ |
|
15
|
|
|
private ?int $id; |
|
16
|
|
|
|
|
17
|
|
|
private string $salutation; |
|
18
|
|
|
|
|
19
|
|
|
private string $company; |
|
20
|
|
|
|
|
21
|
|
|
private string $title; |
|
22
|
|
|
|
|
23
|
|
|
private string $firstName = ''; |
|
24
|
|
|
|
|
25
|
|
|
private string $lastName = ''; |
|
26
|
|
|
|
|
27
|
|
|
private string $address; |
|
28
|
|
|
|
|
29
|
|
|
private string $postcode; |
|
30
|
|
|
|
|
31
|
|
|
private string $city; |
|
32
|
|
|
|
|
33
|
|
|
private string $country = ''; |
|
34
|
|
|
|
|
35
|
2 |
|
private function __construct( |
|
36
|
|
|
string $salutation, |
|
37
|
|
|
string $company, |
|
38
|
|
|
string $title, |
|
39
|
|
|
string $firstName, |
|
40
|
|
|
string $lastName, |
|
41
|
|
|
string $address, |
|
42
|
|
|
string $postcode, |
|
43
|
|
|
string $city, |
|
44
|
|
|
string $country |
|
45
|
|
|
) { |
|
46
|
2 |
|
$this->salutation = $salutation; |
|
47
|
2 |
|
$this->company = $company; |
|
48
|
2 |
|
$this->title = $title; |
|
49
|
2 |
|
$this->firstName = $firstName; |
|
50
|
2 |
|
$this->lastName = $lastName; |
|
51
|
2 |
|
$this->address = $address; |
|
52
|
2 |
|
$this->postcode = $postcode; |
|
53
|
2 |
|
$this->city = $city; |
|
54
|
2 |
|
$this->country = $country; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
8 |
|
public static function newPersonalAddress( |
|
58
|
|
|
string $salutation, |
|
59
|
|
|
string $title, |
|
60
|
|
|
string $firstName, |
|
61
|
|
|
string $lastName, |
|
62
|
|
|
string $address, |
|
63
|
|
|
string $postcode, |
|
64
|
|
|
string $city, |
|
65
|
|
|
string $country ): self { |
|
66
|
8 |
|
self::assertNotEmpty( 'Salutation', $salutation ); |
|
67
|
7 |
|
self::assertNotEmpty( 'First Name', $firstName ); |
|
68
|
6 |
|
self::assertNotEmpty( 'Last Name', $lastName ); |
|
69
|
5 |
|
self::assertNotEmpty( 'Address', $address ); |
|
70
|
4 |
|
self::assertNotEmpty( 'Post Code', $postcode ); |
|
71
|
3 |
|
self::assertNotEmpty( 'City', $city ); |
|
72
|
2 |
|
self::assertNotEmpty( 'Country', $country ); |
|
73
|
|
|
|
|
74
|
1 |
|
return new self( $salutation, '', $title, $firstName, $lastName, $address, $postcode, $city, $country ); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
6 |
|
public static function newCompanyAddress( |
|
78
|
|
|
string $company, |
|
79
|
|
|
string $address, |
|
80
|
|
|
string $postcode, |
|
81
|
|
|
string $city, |
|
82
|
|
|
string $country ): self { |
|
83
|
6 |
|
self::assertNotEmpty( 'Company', $company ); |
|
84
|
5 |
|
self::assertNotEmpty( 'Address', $address ); |
|
85
|
4 |
|
self::assertNotEmpty( 'Post Code', $postcode ); |
|
86
|
3 |
|
self::assertNotEmpty( 'City', $city ); |
|
87
|
2 |
|
self::assertNotEmpty( 'Country', $country ); |
|
88
|
1 |
|
return new self( '', $company, '', '', '', $address, $postcode, $city, $country ); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
14 |
|
private static function assertNotEmpty( string $field, string $value ): void { |
|
92
|
14 |
|
if ( $value === '' ) { |
|
93
|
12 |
|
throw new ChangeAddressValidationException( $field ); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
1 |
|
public function getSalutation(): string { |
|
98
|
1 |
|
return $this->salutation; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
1 |
|
public function getCompany(): string { |
|
102
|
1 |
|
return $this->company; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
1 |
|
public function getTitle(): string { |
|
106
|
1 |
|
return $this->title; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
1 |
|
public function getFirstName(): string { |
|
110
|
1 |
|
return $this->firstName; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
1 |
|
public function getLastName(): string { |
|
114
|
1 |
|
return $this->lastName; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
2 |
|
public function getAddress(): string { |
|
118
|
2 |
|
return $this->address; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
2 |
|
public function getPostcode(): string { |
|
122
|
2 |
|
return $this->postcode; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
2 |
|
public function getCity(): string { |
|
126
|
2 |
|
return $this->city; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
2 |
|
public function getCountry(): string { |
|
130
|
2 |
|
return $this->country; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
public function getId(): ?int { |
|
134
|
|
|
return $this->id; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
} |
|
138
|
|
|
|