1313 * The recommended way to construct this class is through the AddressChangeBuilder
1414 */
1515class AddressChange {
16-
17- public const ADDRESS_TYPE_PERSON = 'person ' ;
18- public const ADDRESS_TYPE_COMPANY = 'company ' ;
19-
2016 public const EXTERNAL_ID_TYPE_DONATION = 'donation ' ;
2117 public const EXTERNAL_ID_TYPE_MEMBERSHIP = 'membership ' ;
2218
@@ -30,44 +26,32 @@ class AddressChange {
3026 */
3127 private ?int $ id ;
3228
33- private AddressChangeId $ identifier ;
34-
3529 private AddressChangeId $ previousIdentifier ;
3630
37- private ?Address $ address ;
38-
39- private string $ addressType ;
40-
4131 private bool $ donationReceipt ;
4232
43- private int $ externalId ;
44-
45- private string $ externalIdType ;
46-
4733 private ?\DateTimeInterface $ exportDate ;
4834
4935 private \DateTimeInterface $ createdAt ;
5036
5137 private \DateTimeInterface $ modifiedAt ;
5238
53- public function __construct ( string $ addressType , string $ externalIdType , int $ externalId , AddressChangeId $ identifier ,
54- ?Address $ address = null , ?\DateTime $ createdAt = null ) {
55- $ this ->addressType = $ addressType ;
56- $ this ->identifier = $ identifier ;
39+ public function __construct (
40+ private readonly AddressType $ addressType ,
41+ private readonly string $ externalIdType ,
42+ private readonly int $ externalId ,
43+ private AddressChangeId $ identifier ,
44+ private ?Address $ address = null ,
45+ ?\DateTime $ createdAt = null
46+ ) {
5747 $ this ->previousIdentifier = $ identifier ;
58- $ this ->address = $ address ;
59- if ( $ addressType !== self ::ADDRESS_TYPE_PERSON && $ addressType !== self ::ADDRESS_TYPE_COMPANY ) {
60- throw new \InvalidArgumentException ( 'Invalid address type ' );
61- }
6248 if ( $ externalIdType !== self ::EXTERNAL_ID_TYPE_DONATION && $ externalIdType !== self ::EXTERNAL_ID_TYPE_MEMBERSHIP ) {
6349 throw new \InvalidArgumentException ( 'Invalid external reference type ' );
6450 }
6551 $ this ->exportDate = null ;
6652 $ this ->createdAt = $ createdAt ?? new \DateTime ();
6753 $ this ->modifiedAt = clone $ this ->createdAt ;
6854 $ this ->donationReceipt = true ;
69- $ this ->externalId = $ externalId ;
70- $ this ->externalIdType = $ externalIdType ;
7155 }
7256
7357 public function performAddressChange ( Address $ address , AddressChangeId $ newIdentifier ): void {
@@ -96,11 +80,11 @@ public function getAddress(): ?Address {
9680 }
9781
9882 public function isPersonalAddress (): bool {
99- return $ this ->addressType === self :: ADDRESS_TYPE_PERSON ;
83+ return $ this ->addressType === AddressType::Person ;
10084 }
10185
10286 public function isCompanyAddress (): bool {
103- return $ this ->addressType === self :: ADDRESS_TYPE_COMPANY ;
87+ return $ this ->addressType === AddressType::Company ;
10488 }
10589
10690 public function isOptedIntoDonationReceipt (): bool {
0 commit comments