Skip to content

Commit 939be05

Browse files
committed
[HostIp] Fixed notice error
1 parent 342ea22 commit 939be05

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

src/Geocoder/Provider/HostIpProvider.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,17 @@ protected function executeQuery($query)
7373
->children('', true)
7474
->Hostip;
7575

76-
$lngLat = explode(',', (string) $dataNode
77-
->ipLocation
78-
->children('gml', true)
79-
->pointProperty
80-
->Point
81-
->coordinates);
76+
if (isset($dataNode->ipLocation)) {
77+
$lngLat = explode(',', (string) $dataNode
78+
->ipLocation
79+
->children('gml', true)
80+
->pointProperty
81+
->Point
82+
->coordinates
83+
);
84+
} else {
85+
$lngLat = array(null, null);
86+
}
8287

8388
$city = (string) $dataNode
8489
->children('gml', true)

tests/Geocoder/Tests/Provider/HostIpProviderTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,13 @@ public function testGetReverseData()
9494
$this->provider = new HostIpProvider($this->getMockAdapter($this->never()));
9595
$this->provider->getReversedData(array(1, 2));
9696
}
97+
98+
public function testGetGeocodedDataWithAnotherIp()
99+
{
100+
$this->provider = new HostIpProvider(new \Geocoder\HttpAdapter\BuzzHttpAdapter());
101+
$result = $this->provider->getGeocodedData('33.33.33.22');
102+
103+
$this->assertNull($result['latitude']);
104+
$this->assertNull($result['longitude']);
105+
}
97106
}

0 commit comments

Comments
 (0)