Rename LatLongModel to GeoCoordinates
This commit is contained in:
@@ -4,7 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Pcm\GeocodeBundle\Service;
|
||||
|
||||
use Pcm\GeocodeBundle\Model\LatLongModel;
|
||||
use Pcm\GeocodeBundle\Model\GeoCoordinates;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
use Symfony\Contracts\HttpClient\ResponseInterface;
|
||||
|
||||
@@ -18,14 +18,15 @@ final class Geocoder
|
||||
* Convert a postcode into latitude and longitude. Returns null if conversion failed.
|
||||
*
|
||||
* @param string $postcode
|
||||
* @return null|LatLongModel
|
||||
* @return null|GeoCoordinates
|
||||
*/
|
||||
public function geocodePostcode(string $postcode): ?LatLongModel
|
||||
public function geocodePostcode(string $postcode): ?GeoCoordinates
|
||||
{
|
||||
$client = $this->createClient();
|
||||
$response = $this->makeApiRequest($client, $postcode);
|
||||
$data = $this->getDataFromResponse($response);
|
||||
|
||||
// @todo remove check, I don't think it's needed
|
||||
if (empty($data)) {
|
||||
return null;
|
||||
}
|
||||
@@ -34,7 +35,7 @@ final class Geocoder
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->createLatLongModel($data);
|
||||
return $this->createGeoCoordinates($data);
|
||||
}
|
||||
|
||||
private function createClient(): HttpClientInterface
|
||||
@@ -63,12 +64,12 @@ final class Geocoder
|
||||
return $response->toArray(false);
|
||||
}
|
||||
|
||||
private function createLatLongModel(array $data): LatLongModel
|
||||
private function createGeoCoordinates(array $data): GeoCoordinates
|
||||
{
|
||||
$lat = $this->getLatitudeFromData($data);
|
||||
$long = $this->getLongitudeFromData($data);
|
||||
|
||||
return new LatLongModel($lat, $long);
|
||||
return new GeoCoordinates($lat, $long);
|
||||
}
|
||||
|
||||
private function getLatitudeFromData(array $data): float
|
||||
@@ -81,3 +82,4 @@ final class Geocoder
|
||||
return (float) $data[0]['lon'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user