Skip to content

Commit 0955a84

Browse files
clicktrendwilldurand
authored andcommitted
Resourceset may be empty. Checking before accessing.
1 parent df79f98 commit 0955a84

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/Geocoder/Provider/BingMapsProvider.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ protected function executeQuery($query)
104104

105105
$json = json_decode($content);
106106

107-
if (isset($json->resourceSets[0])) {
107+
if (isset($json->resourceSets[0]) && isset($json->resourceSets[0]->resources[0])) {
108108
$data = (array) $json->resourceSets[0]->resources[0];
109109
} else {
110110
return $this->getDefaults();
@@ -124,11 +124,11 @@ protected function executeQuery($query)
124124

125125
$streetNumber = null;
126126
$streetName = property_exists($data['address'], 'addressLine') ? (string) $data['address']->addressLine : '';
127-
$zipcode = (string) $data['address']->postalCode;
128-
$city = (string) $data['address']->locality;
129-
$county = (string) $data['address']->adminDistrict2;
130-
$region = (string) $data['address']->adminDistrict;
131-
$country = (string) $data['address']->countryRegion;
127+
$zipcode = property_exists($data['address'], 'postalCode') ? (string) $data['address']->postalCode : '';
128+
$city = property_exists($data['address'], 'locality') ? (string) $data['address']->locality: '';
129+
$county = property_exists($data['address'], 'adminDistrict2') ? (string) $data['address']->adminDistrict2 : '';
130+
$region = property_exists($data['address'], 'adminDistrict') ? (string) $data['address']->adminDistrict: '';
131+
$country = property_exists($data['address'], 'countryRegion') ? (string) $data['address']->countryRegion: '';
132132

133133
return array(
134134
'latitude' => $coordinates[0],

0 commit comments

Comments
 (0)