Changed latitude and longitude to float

This commit is contained in:
Alejandro Celaya
2019-12-31 23:37:49 +01:00
parent 0cf1d8d375
commit 0e04968bc2
6 changed files with 24 additions and 34 deletions

View File

@@ -11,10 +11,10 @@
"type": "string" "type": "string"
}, },
"latitude": { "latitude": {
"type": "string" "type": "number"
}, },
"longitude": { "longitude": {
"type": "string" "type": "number"
}, },
"regionName": { "regionName": {
"type": "string" "type": "string"

View File

@@ -105,8 +105,8 @@
"cityName": "Cupertino", "cityName": "Cupertino",
"countryCode": "US", "countryCode": "US",
"countryName": "United States", "countryName": "United States",
"latitude": "37.3042", "latitude": 37.3042,
"longitude": "-122.0946", "longitude": -122.0946,
"regionName": "California", "regionName": "California",
"timezone": "America/Los_Angeles" "timezone": "America/Los_Angeles"
} }

View File

@@ -14,8 +14,8 @@ class VisitLocation extends AbstractEntity implements VisitLocationInterface
private string $countryName; private string $countryName;
private string $regionName; private string $regionName;
private string $cityName; private string $cityName;
private string $latitude; // FIXME Should be float private float $latitude;
private string $longitude; // FIXME Should be float private float $longitude;
private string $timezone; private string $timezone;
public function __construct(Location $location) public function __construct(Location $location)
@@ -25,22 +25,22 @@ class VisitLocation extends AbstractEntity implements VisitLocationInterface
public function getCountryName(): string public function getCountryName(): string
{ {
return $this->countryName ?? ''; return $this->countryName;
} }
public function getLatitude(): string public function getLatitude(): float
{ {
return $this->latitude ?? ''; return $this->latitude;
} }
public function getLongitude(): string public function getLongitude(): float
{ {
return $this->longitude ?? ''; return $this->longitude;
} }
public function getCityName(): string public function getCityName(): string
{ {
return $this->cityName ?? ''; return $this->cityName;
} }
private function exchangeLocationInfo(Location $info): void private function exchangeLocationInfo(Location $info): void
@@ -49,8 +49,8 @@ class VisitLocation extends AbstractEntity implements VisitLocationInterface
$this->countryName = $info->countryName(); $this->countryName = $info->countryName();
$this->regionName = $info->regionName(); $this->regionName = $info->regionName();
$this->cityName = $info->city(); $this->cityName = $info->city();
$this->latitude = (string) $info->latitude(); $this->latitude = $info->latitude();
$this->longitude = (string) $info->longitude(); $this->longitude = $info->longitude();
$this->timezone = $info->timeZone(); $this->timezone = $info->timeZone();
} }
@@ -74,8 +74,8 @@ class VisitLocation extends AbstractEntity implements VisitLocationInterface
$this->countryName === '' && $this->countryName === '' &&
$this->regionName === '' && $this->regionName === '' &&
$this->cityName === '' && $this->cityName === '' &&
((float) $this->latitude) === 0.0 && $this->latitude === 0.0 &&
((float) $this->longitude) === 0.0 && $this->longitude === 0.0 &&
$this->timezone === ''; $this->timezone === '';
} }
} }

View File

@@ -11,14 +11,14 @@ final class UnknownVisitLocation implements VisitLocationInterface
return 'Unknown'; return 'Unknown';
} }
public function getLatitude(): string public function getLatitude(): float
{ {
return '0.0'; return 0.0;
} }
public function getLongitude(): string public function getLongitude(): float
{ {
return '0.0'; return 0.0;
} }
public function getCityName(): string public function getCityName(): string
@@ -33,8 +33,8 @@ final class UnknownVisitLocation implements VisitLocationInterface
'countryName' => 'Unknown', 'countryName' => 'Unknown',
'regionName' => 'Unknown', 'regionName' => 'Unknown',
'cityName' => 'Unknown', 'cityName' => 'Unknown',
'latitude' => '0.0', 'latitude' => 0.0,
'longitude' => '0.0', 'longitude' => 0.0,
'timezone' => 'Unknown', 'timezone' => 'Unknown',
]; ];
} }

View File

@@ -10,9 +10,9 @@ interface VisitLocationInterface extends JsonSerializable
{ {
public function getCountryName(): string; public function getCountryName(): string;
public function getLatitude(): string; public function getLatitude(): float;
public function getLongitude(): string; public function getLongitude(): float;
public function getCityName(): string; public function getCityName(): string;
} }

View File

@@ -10,16 +10,6 @@ use Shlinkio\Shlink\IpGeolocation\Model\Location;
class VisitLocationTest extends TestCase class VisitLocationTest extends TestCase
{ {
/** @test */
public function valuesFoundWhenExchangingArrayAreCastToString(): void
{
$payload = new Location('', '', '', '', 1000.7, -2000.4, '');
$location = new VisitLocation($payload);
$this->assertSame('1000.7', $location->getLatitude());
$this->assertSame('-2000.4', $location->getLongitude());
}
/** /**
* @test * @test
* @dataProvider provideArgs * @dataProvider provideArgs