Skip to content

Commit 96552c2

Browse files
vachobojanz
authored andcommitted
Add address line 3.
1 parent 13be3c2 commit 96552c2

12 files changed

+271
-212
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ The [address interface](https://github.com/commerceguys/addressing/blob/master/s
3232
- Sorting code
3333
- Address line 1
3434
- Address line 2
35+
- Address line 3
3536
- Organization
3637
- Given name (First name)
3738
- Additional name (Middle name / Patronymic)

src/Address.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,13 @@ class Address implements ImmutableAddressInterface
6565
*/
6666
protected string $addressLine2;
6767

68+
/**
69+
* The third line of the address block.
70+
*
71+
* @var string
72+
*/
73+
protected string $addressLine3;
74+
6875
/**
6976
* The organization.
7077
*
@@ -111,6 +118,7 @@ class Address implements ImmutableAddressInterface
111118
* @param string $sortingCode The sorting code
112119
* @param string $addressLine1 The first line of the address block.
113120
* @param string $addressLine2 The second line of the address block.
121+
* @param string $addressLine3 The third line of the address block.
114122
* @param string $organization The organization.
115123
* @param string $givenName The given name.
116124
* @param string $additionalName The additional name.
@@ -126,6 +134,7 @@ public function __construct(
126134
?string $sortingCode = '',
127135
?string $addressLine1 = '',
128136
?string $addressLine2 = '',
137+
?string $addressLine3 = '',
129138
?string $organization = '',
130139
?string $givenName = '',
131140
?string $additionalName = '',
@@ -140,6 +149,7 @@ public function __construct(
140149
$this->sortingCode = $sortingCode;
141150
$this->addressLine1 = $addressLine1;
142151
$this->addressLine2 = $addressLine2;
152+
$this->addressLine3 = $addressLine3;
143153
$this->organization = $organization;
144154
$this->givenName = $givenName;
145155
$this->additionalName = $additionalName;
@@ -299,6 +309,25 @@ public function withAddressLine2(string $addressLine2): ImmutableAddressInterfac
299309
return $new;
300310
}
301311

312+
/**
313+
* {@inheritdoc}
314+
*/
315+
public function getAddressLine3(): ?string
316+
{
317+
return $this->addressLine3;
318+
}
319+
320+
/**
321+
* {@inheritdoc}
322+
*/
323+
public function withAddressLine3(string $addressLine3): ImmutableAddressInterface|Address
324+
{
325+
$new = clone $this;
326+
$new->addressLine3 = $addressLine3;
327+
328+
return $new;
329+
}
330+
302331
/**
303332
* {@inheritdoc}
304333
*/

src/AddressFormat/AddressField.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ final class AddressField extends AbstractEnum
1919
public const SORTING_CODE = 'sortingCode';
2020
public const ADDRESS_LINE1 = 'addressLine1';
2121
public const ADDRESS_LINE2 = 'addressLine2';
22+
public const ADDRESS_LINE3 = 'addressLine3';
2223
public const ORGANIZATION = 'organization';
2324
public const GIVEN_NAME = 'givenName';
2425
public const ADDITIONAL_NAME = 'additionalName';

src/AddressFormat/AddressFormat.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ public function getLocale(): ?string
142142
* %organization
143143
* %addressLine1
144144
* %addressLine2
145+
* %addressLine3
145146
* %locality %administrativeArea %postalCode
146147
* </code>
147148
*

src/AddressFormat/AddressFormatHelper.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ final class AddressFormatHelper
2121
* [organization],
2222
* [addressLine1],
2323
* [addressLine2],
24+
* [addressLine3],
2425
* [locality, administrativeArea, postalCode]
2526
* ]
2627
* @throws \ReflectionException

src/AddressFormat/AddressFormatRepository.php

Lines changed: 207 additions & 207 deletions
Large diffs are not rendered by default.

src/AddressInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ public function getAddressLine1(): ?string;
8888
*/
8989
public function getAddressLine2(): ?string;
9090

91+
/**
92+
* Gets the third line of address block.
93+
*/
94+
public function getAddressLine3(): ?string;
95+
9196
/**
9297
* Gets the organization.
9398
*/

src/ImmutableAddressInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ public function withAddressLine1(string $addressLine1): ImmutableAddressInterfac
5151
*/
5252
public function withAddressLine2(string $addressLine2): ImmutableAddressInterface;
5353

54+
/**
55+
* Returns an instance with the specified third line of address block.
56+
*/
57+
public function withAddressLine3(string $addressLine3): ImmutableAddressInterface;
58+
5459
/**
5560
* Returns an instance with the specified organization.
5661
*/

tests/AddressFormat/AddressFormatHelperTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ final class AddressFormatHelperTest extends TestCase
1919
*/
2020
public function testGetGroupedFields(): void
2121
{
22-
$format = "%givenName %familyName\n%organization\n%addressLine1\n%addressLine2\n%locality, %postalCode";
22+
$format = "%givenName %familyName\n%organization\n%addressLine1\n%addressLine2\n%addressLine3\n%locality, %postalCode";
2323
$expectedGroupedFields = [
2424
[AddressField::GIVEN_NAME, AddressField::FAMILY_NAME],
2525
[AddressField::ORGANIZATION],
2626
[AddressField::ADDRESS_LINE1],
2727
[AddressField::ADDRESS_LINE2],
28+
[AddressField::ADDRESS_LINE3],
2829
[AddressField::LOCALITY, AddressField::POSTAL_CODE],
2930
];
3031
$this->assertEquals($expectedGroupedFields, AddressFormatHelper::getGroupedFields($format));
@@ -37,6 +38,7 @@ public function testGetGroupedFields(): void
3738
[AddressField::GIVEN_NAME, AddressField::FAMILY_NAME],
3839
[AddressField::ADDRESS_LINE1],
3940
[AddressField::ADDRESS_LINE2],
41+
[AddressField::ADDRESS_LINE3],
4042
[AddressField::POSTAL_CODE],
4143
];
4244
$this->assertEquals($expectedGroupedFields, AddressFormatHelper::getGroupedFields($format, $fieldOverrides));
@@ -49,7 +51,7 @@ public function testGetRequiredFields(): void
4951
{
5052
$addressFormat = new AddressFormat([
5153
'country_code' => 'US',
52-
'format' => "%givenName %familyName\n%organization\n%addressLine1\n%addressLine2\n%locality, %administrativeArea %postalCode",
54+
'format' => "%givenName %familyName\n%organization\n%addressLine1\n%addressLine2\n%addressLine3\n%locality, %administrativeArea %postalCode",
5355
'required_fields' => [
5456
AddressField::ADMINISTRATIVE_AREA,
5557
AddressField::LOCALITY,

tests/AddressFormat/AddressFormatTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function testInvalidSubdivision(): void
3939
$this->expectException(\InvalidArgumentException::class);
4040
$definition = [
4141
'country_code' => 'US',
42-
'format' => "%givenName %familyName\n%organization\n%addressLine1\n%addressLine2\n%dependentLocality",
42+
'format' => "%givenName %familyName\n%organization\n%addressLine1\n%addressLine2\n%addressLine3\n%dependentLocality",
4343
'required_fields' => [AddressField::ADDRESS_LINE1],
4444
'dependent_locality_type' => 'WRONG',
4545
];
@@ -69,7 +69,7 @@ public function testValid(): void
6969
$definition = [
7070
'country_code' => 'US',
7171
'locale' => 'en',
72-
'format' => "%givenName %familyName\n%organization\n%addressLine1\n%addressLine2\n%locality, %administrativeArea %postalCode",
72+
'format' => "%givenName %familyName\n%organization\n%addressLine1\n%addressLine2\n%addressLine3\n%locality, %administrativeArea %postalCode",
7373
// The local format is made up, US doesn't have one usually.
7474
'local_format' => '%postalCode\n%addressLine1\n%organization\n%givenName %familyName',
7575
'required_fields' => [
@@ -114,6 +114,7 @@ public function testValid(): void
114114
AddressField::POSTAL_CODE,
115115
AddressField::ADDRESS_LINE1,
116116
AddressField::ADDRESS_LINE2,
117+
AddressField::ADDRESS_LINE3,
117118
AddressField::ORGANIZATION,
118119
AddressField::GIVEN_NAME,
119120
AddressField::FAMILY_NAME,

0 commit comments

Comments
 (0)