44
55namespace WMDE \Fundraising \AddressChangeContext \UseCases \ChangeAddress ;
66
7- use WMDE \FreezableValueObject \FreezableValueObject ;
87use WMDE \Fundraising \AddressChangeContext \Domain \Model \AddressType ;
98
109class ChangeAddressRequest {
11- use FreezableValueObject;
12-
13- private string $ salutation ;
14-
15- private string $ company ;
16-
17- private string $ title ;
18-
19- private string $ firstName ;
20-
21- private string $ lastName ;
22-
23- private string $ address ;
24-
25- private string $ postcode ;
26-
27- private string $ city ;
28-
29- private string $ country ;
30-
31- private AddressType $ addressType ;
32-
33- private string $ identifier ;
34-
35- private bool $ donationReceipt ;
36-
37- private bool $ isOptOutOnly ;
38-
39- public function getSalutation (): string {
40- return $ this ->salutation ;
41- }
42-
43- public function setSalutation ( string $ salutation ): self {
44- $ this ->assertIsWritable ();
45- $ this ->salutation = trim ( $ salutation );
46- return $ this ;
47- }
48-
49- public function getCompany (): string {
50- return $ this ->company ;
51- }
52-
53- public function setCompany ( string $ company ): self {
54- $ this ->assertIsWritable ();
55- $ this ->company = trim ( $ company );
56- return $ this ;
57- }
58-
59- public function getTitle (): string {
60- return $ this ->title ;
61- }
62-
63- public function setTitle ( string $ title ): self {
64- $ this ->assertIsWritable ();
65- $ this ->title = trim ( $ title );
66- return $ this ;
67- }
68-
69- public function getFirstName (): string {
70- return $ this ->firstName ;
71- }
72-
73- public function setFirstName ( string $ firstName ): self {
74- $ this ->assertIsWritable ();
75- $ this ->firstName = trim ( $ firstName );
76- return $ this ;
77- }
78-
79- public function getLastName (): string {
80- return $ this ->lastName ;
81- }
82-
83- public function setLastName ( string $ lastName ): self {
84- $ this ->assertIsWritable ();
85- $ this ->lastName = trim ( $ lastName );
86- return $ this ;
87- }
88-
89- public function getAddress (): string {
90- return $ this ->address ;
91- }
92-
93- public function setAddress ( string $ address ): self {
94- $ this ->assertIsWritable ();
95- $ this ->address = trim ( $ address );
96- return $ this ;
97- }
98-
99- public function getPostcode (): string {
100- return $ this ->postcode ;
101- }
102-
103- public function setPostcode ( string $ postcode ): self {
104- $ this ->assertIsWritable ();
105- $ this ->postcode = trim ( $ postcode );
106- return $ this ;
107- }
108-
109- public function getCity (): string {
110- return $ this ->city ;
111- }
112-
113- public function setCity ( string $ city ): self {
114- $ this ->assertIsWritable ();
115- $ this ->city = trim ( $ city );
116- return $ this ;
117- }
118-
119- public function getCountry (): string {
120- return $ this ->country ;
121- }
122-
123- public function setCountry ( string $ country ): self {
124- $ this ->assertIsWritable ();
125- $ this ->country = trim ( $ country );
126- return $ this ;
127- }
128-
129- public function getAddressType (): AddressType {
130- return $ this ->addressType ;
10+ private function __construct (
11+ public readonly AddressType $ addressType ,
12+ public readonly string $ address ,
13+ public readonly string $ postcode ,
14+ public readonly string $ city ,
15+ public readonly string $ country ,
16+ public readonly string $ identifier ,
17+ public readonly bool $ donationReceipt ,
18+ public readonly bool $ isOptOutOnly ,
19+ public readonly string $ company = '' ,
20+ public readonly string $ salutation = '' ,
21+ public readonly string $ title = '' ,
22+ public readonly string $ firstName = '' ,
23+ public readonly string $ lastName = '' ,
24+ ) {
25+ }
26+
27+ public static function newPersonalChangeAddressRequest (
28+ string $ salutation ,
29+ string $ title ,
30+ string $ firstName ,
31+ string $ lastName ,
32+ string $ address ,
33+ string $ postcode ,
34+ string $ city ,
35+ string $ country ,
36+ string $ identifier ,
37+ bool $ donationReceipt ,
38+ bool $ isOptOutOnly ,
39+ ): ChangeAddressRequest {
40+ return new self (
41+ addressType: AddressType::Person,
42+ address: trim ( $ address ),
43+ postcode: trim ( $ postcode ),
44+ city: trim ( $ city ),
45+ country: trim ( $ country ),
46+ identifier: trim ( $ identifier ),
47+ donationReceipt: $ donationReceipt ,
48+ isOptOutOnly: $ isOptOutOnly ,
49+ salutation: trim ( $ salutation ),
50+ title: trim ( $ title ),
51+ firstName: trim ( $ firstName ),
52+ lastName: trim ( $ lastName ),
53+ );
54+ }
55+
56+ public static function newCompanyChangeAddressRequest (
57+ string $ company ,
58+ string $ address ,
59+ string $ postcode ,
60+ string $ city ,
61+ string $ country ,
62+ string $ identifier ,
63+ bool $ donationReceipt ,
64+ bool $ isOptOutOnly ,
65+ ): ChangeAddressRequest {
66+ return new self (
67+ addressType: AddressType::Company,
68+ address: trim ( $ address ),
69+ postcode: trim ( $ postcode ),
70+ city: trim ( $ city ),
71+ country: trim ( $ country ),
72+ identifier: trim ( $ identifier ),
73+ donationReceipt: $ donationReceipt ,
74+ isOptOutOnly: $ isOptOutOnly ,
75+ company: trim ( $ company ),
76+ );
13177 }
13278
13379 public function isPersonal (): bool {
@@ -138,38 +84,10 @@ public function isCompany(): bool {
13884 return $ this ->addressType === AddressType::Company;
13985 }
14086
141- public function setAddressType ( AddressType $ addressType ): self {
142- $ this ->assertIsWritable ();
143- $ this ->addressType = $ addressType ;
144- return $ this ;
145- }
146-
147- public function getIdentifier (): string {
148- return $ this ->identifier ;
149- }
150-
151- public function setIdentifier ( string $ identifier ): self {
152- $ this ->assertIsWritable ();
153- $ this ->identifier = trim ( $ identifier );
154- return $ this ;
155- }
156-
15787 public function isOptedOutOfDonationReceipt (): bool {
15888 return !$ this ->donationReceipt ;
15989 }
16090
161- public function setDonationReceipt ( bool $ donationReceipt ): self {
162- $ this ->assertIsWritable ();
163- $ this ->donationReceipt = $ donationReceipt ;
164- return $ this ;
165- }
166-
167- public function setIsOptOutOnly ( bool $ isOptOutOnly ): self {
168- $ this ->assertIsWritable ();
169- $ this ->isOptOutOnly = $ isOptOutOnly ;
170- return $ this ;
171- }
172-
17391 public function hasAddressChangeData (): bool {
17492 return !$ this ->isOptOutOnly ;
17593 }
0 commit comments