Skip to content

Commit 3f6637a

Browse files
committed
Remove Freezable trait from ChangeAddressRequest
This is now using modern php to make the properties readonly Ticket: https://phabricator.wikimedia.org/T359090
1 parent 0a00da4 commit 3f6637a

File tree

5 files changed

+229
-281
lines changed

5 files changed

+229
-281
lines changed

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
"php": ">=8.1",
77
"doctrine/orm": "~2.18 | ~3.0",
88
"doctrine/dbal": "~3.8 | ~4.0",
9-
"ramsey/uuid": "^4.0",
10-
"wmde/freezable-value-object": "~2.0"
9+
"ramsey/uuid": "^4.0"
1110
},
1211
"require-dev": {
1312
"phpunit/phpunit": "~9.2",

src/UseCases/ChangeAddress/ChangeAddressRequest.php

Lines changed: 67 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -4,130 +4,76 @@
44

55
namespace WMDE\Fundraising\AddressChangeContext\UseCases\ChangeAddress;
66

7-
use WMDE\FreezableValueObject\FreezableValueObject;
87
use WMDE\Fundraising\AddressChangeContext\Domain\Model\AddressType;
98

109
class 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
}

src/UseCases/ChangeAddress/ChangeAddressUseCase.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function __construct( AddressChangeRepository $addressChangeRepository )
1818
}
1919

2020
public function changeAddress( ChangeAddressRequest $request ): ChangeAddressResponse {
21-
$addressChange = $this->addressChangeRepository->getAddressChangeByUuid( $request->getIdentifier() );
21+
$addressChange = $this->addressChangeRepository->getAddressChangeByUuid( $request->identifier );
2222
if ( $addressChange === null ) {
2323
return ChangeAddressResponse::newErrorResponse( [ ChangeAddressResponse::ERROR_ADDRESS_NOT_FOUND ] );
2424
}
@@ -43,22 +43,22 @@ public function changeAddress( ChangeAddressRequest $request ): ChangeAddressRes
4343
private function buildAddress( ChangeAddressRequest $request ): Address {
4444
if ( $request->isPersonal() ) {
4545
return Address::newPersonalAddress(
46-
$request->getSalutation(),
47-
$request->getTitle(),
48-
$request->getFirstName(),
49-
$request->getLastName(),
50-
$request->getAddress(),
51-
$request->getPostcode(),
52-
$request->getCity(),
53-
$request->getCountry()
46+
$request->salutation,
47+
$request->title,
48+
$request->firstName,
49+
$request->lastName,
50+
$request->address,
51+
$request->postcode,
52+
$request->city,
53+
$request->country
5454
);
5555
} elseif ( $request->isCompany() ) {
5656
return Address::newCompanyAddress(
57-
$request->getCompany(),
58-
$request->getAddress(),
59-
$request->getPostcode(),
60-
$request->getCity(),
61-
$request->getCountry()
57+
$request->company,
58+
$request->address,
59+
$request->postcode,
60+
$request->city,
61+
$request->country
6262
);
6363
}
6464
throw new ChangeAddressValidationException( 'Address Type' );

0 commit comments

Comments
 (0)