Fixed region resolved in GeoLite2

This commit is contained in:
Alejandro Celaya 2018-11-11 18:57:32 +01:00
parent 0e3a0a1eec
commit 9a0f9207be
2 changed files with 9 additions and 3 deletions

View file

@ -48,6 +48,7 @@
"zendframework/zend-stdlib": "^3.0"
},
"require-dev": {
"devster/ubench": "^2.0",
"filp/whoops": "^2.0",
"infection/infection": "^0.11.0",
"phpstan/phpstan": "^0.10.0",

View file

@ -6,8 +6,10 @@ namespace Shlinkio\Shlink\Common\IpGeolocation;
use GeoIp2\Database\Reader;
use GeoIp2\Exception\AddressNotFoundException;
use GeoIp2\Model\City;
use GeoIp2\Record\Subdivision;
use MaxMind\Db\Reader\InvalidDatabaseException;
use Shlinkio\Shlink\Common\Exception\WrongIpException;
use function Functional\first;
class GeoLite2LocationResolver implements IpLocationResolverInterface
{
@ -40,13 +42,16 @@ class GeoLite2LocationResolver implements IpLocationResolverInterface
private function mapFields(City $city): array
{
/** @var Subdivision $region */
$region = first($city->subdivisions);
return [
'country_code' => $city->country->isoCode ?? '',
'country_name' => $city->country->name ?? '',
'region_name' => $city->mostSpecificSubdivision->name ?? '',
'region_name' => $region->name ?? '',
'city' => $city->city->name ?? '',
'latitude' => (string) $city->location->latitude, // FIXME Cast to string for BC compatibility
'longitude' => (string) $city->location->longitude, // FIXME Cast to string for BC compatibility
'latitude' => $city->location->latitude ?? '',
'longitude' => $city->location->longitude ?? '',
'time_zone' => $city->location->timeZone ?? '',
];
}