Skip to content

Commit e3911db

Browse files
committed
fix addresses
1 parent 483c824 commit e3911db

File tree

5 files changed

+44
-28
lines changed

5 files changed

+44
-28
lines changed

src/Geography/Address/Country.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,11 @@ public function getFormatted() : string
130130
public function __toString() : string
131131
{
132132
if ($this->isoAlpha2 !== null) {
133-
return $this->isoAlpha2;
133+
return strtoupper($this->isoAlpha2);
134134
}
135135

136136
if ($this->isoAlpha3 !== null) {
137-
return $this->isoAlpha3;
137+
return strtoupper($this->isoAlpha3);
138138
}
139139
return $this->name;
140140
}

src/Geography/Address/Physical/ByCountry/Br/BrPhysicalAddress.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,19 @@ public function getAddress() : string
167167

168168
$street = $this->getStreet() ? $this->getStreet()->getFormatted() : '';
169169
$municipality = $this->getMunicipality() ? $this->getMunicipality()->getFormatted() : '';
170-
$state = $this->getState() ? $this->getState()->getFormatted() : '';
170+
$state = $this->getState() ? $this->getState()->__toString() : '';
171171
$postalCode = $this->getPostalCode() ? $this->getPostalCode()->getFormatted() : '';
172-
$country = $this->getCountry() ? $this->getCountry()->getFormatted() : '';
172+
$country = $this->getCountry() ? $this->getCountry()->__toString() : '';
173+
174+
$values = [$street, $municipality, $state, $postalCode, $country];
175+
$nonEmptyValues = [];
176+
foreach ($values as $value) {
177+
if($value !== ''){
178+
$nonEmptyValues[] = $value;
179+
}
180+
}
173181

174-
$formatted = sprintf(
175-
'%s. %s, %s, %s %s', $street, $municipality, $state, $postalCode, $country
176-
);
182+
$formatted = implode(', ', $nonEmptyValues);
177183

178184
return StringUtils::trimSpacesWisely($formatted);
179185
}

src/Geography/Address/Physical/ByCountry/Us/UsPhysicalAddress.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -175,22 +175,22 @@ public function getAddress() : string
175175
return $this->formattedAddress;
176176
}
177177

178-
$street = $this->getStreet() ? $this->getStreet()
179-
->getFormatted() : '';
180-
$city = $this->getCity() ? $this->getCity()
181-
->getFormatted() : '';
182-
$county = $this->getCounty() ? $this->getCounty()
183-
->getFormatted() : '';
184-
$state = $this->getState() ? $this->getState()
185-
->getFormatted() : '';
186-
$postalCode = $this->getPostalCode() ? $this->getPostalCode()
187-
->getFormatted() : '';
188-
$country = $this->getCountry() ? $this->getCountry()
189-
->getFormatted() : '';
190-
191-
$formatted = sprintf(
192-
'%s, %s, %s, %s %s', $street, $city, $state, $postalCode, $country
193-
);
178+
$street = $this->getStreet() ? $this->getStreet()->getFormatted() : '';
179+
$city = $this->getCity() ? $this->getCity()->getFormatted() : '';
180+
$county = $this->getCounty() ? $this->getCounty()->getFormatted() : '';
181+
$state = $this->getState() ? $this->getState()->__toString() : '';
182+
$postalCode = $this->getPostalCode() ? $this->getPostalCode()->getFormatted() : '';
183+
$country = $this->getCountry() ? $this->getCountry()->__toString() : '';
184+
185+
$values = [$street, $city, $state, $postalCode, $country];
186+
$nonEmptyValues = [];
187+
foreach ($values as $value) {
188+
if($value !== ''){
189+
$nonEmptyValues[] = $value;
190+
}
191+
}
192+
193+
$formatted = implode(', ', $nonEmptyValues);
194194

195195
return StringUtils::trimSpacesWisely($formatted);
196196
}

src/Geography/Address/Physical/GenericPhysicalAddress.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,19 @@ public function getAddress() : string
117117

118118
$street = $this->getStreet() ? $this->getStreet()->getFormatted() : '';
119119
$city = $this->getCity() ? $this->getCity()->getFormatted() : '';
120-
$region = $this->getRegion() ? $this->getRegion()->getFormatted() : '';
120+
$region = $this->getRegion() ? $this->getRegion()->__toString() : '';
121121
$postalCode = $this->getPostalCode() ? $this->getPostalCode()->getFormatted() : '';
122-
$country = $this->getCountry() ? $this->getCountry()->getFormatted() : '';
122+
$country = $this->getCountry() ? $this->getCountry()->__toString() : '';
123+
124+
$values = [$street, $city, $region, $postalCode, $country];
125+
$nonEmptyValues = [];
126+
foreach ($values as $value) {
127+
if($value !== ''){
128+
$nonEmptyValues[] = $value;
129+
}
130+
}
123131

124-
$formatted = sprintf(
125-
'%s, %s, %s, %s %s', $street, $city, $region, $postalCode, $country
126-
);
132+
$formatted = implode(', ', $nonEmptyValues);
127133

128134
return StringUtils::trimSpacesWisely($formatted);
129135
}

src/Geography/Address/Region.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ public function getFormatted() : string
9494

9595
public function __toString() : string
9696
{
97+
if ($this->isoAlpha2 !== null) {
98+
return strtoupper($this->isoAlpha2);
99+
}
100+
97101
return $this->name;
98102
}
99103
}

0 commit comments

Comments
 (0)