From 4d936a6279376097350d8f60844f44fa11311960 Mon Sep 17 00:00:00 2001 From: brabli <67018167+Brabli@users.noreply.github.com> Date: Mon, 5 Aug 2024 12:16:42 +0100 Subject: [PATCH] Rename LatLongModel to GeoCoordinates --- src/Model/{LatLongModel.php => GeoCoordinates.php} | 2 +- src/Service/Geocoder.php | 14 ++++++++------ tests/Service/GeocodeTest.php | 6 +++--- 3 files changed, 12 insertions(+), 10 deletions(-) rename src/Model/{LatLongModel.php => GeoCoordinates.php} (94%) diff --git a/src/Model/LatLongModel.php b/src/Model/GeoCoordinates.php similarity index 94% rename from src/Model/LatLongModel.php rename to src/Model/GeoCoordinates.php index 88bc3c9..cb150d2 100644 --- a/src/Model/LatLongModel.php +++ b/src/Model/GeoCoordinates.php @@ -9,7 +9,7 @@ namespace Pcm\GeocodeBundle\Model; * * @package Pcm\GeocodeBundle */ -final class LatLongModel +final class GeoCoordinates { public function __construct(private float $latitude, private float $longitude) {} diff --git a/src/Service/Geocoder.php b/src/Service/Geocoder.php index 12e7248..e06c93e 100644 --- a/src/Service/Geocoder.php +++ b/src/Service/Geocoder.php @@ -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']; } } + diff --git a/tests/Service/GeocodeTest.php b/tests/Service/GeocodeTest.php index a6fa965..8976c4d 100644 --- a/tests/Service/GeocodeTest.php +++ b/tests/Service/GeocodeTest.php @@ -6,7 +6,7 @@ namespace Pcm\GeocodeBundle\Tests; use Pcm\GeocodeBundle\Entity\Interface\MappableInterface; use Pcm\GeocodeBundle\Entity\Trait\MappableTrait; -use Pcm\GeocodeBundle\Model\LatLongModel; +use Pcm\GeocodeBundle\Model\GeoCoordinates; use Pcm\GeocodeBundle\Service\Geocoder; use Pcm\GeocodeBundle\Tests\AppKernel; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; @@ -39,11 +39,11 @@ final class GeocodeTest extends KernelTestCase $this->assertNull($this->geocoder->geocodePostcode('')); } - public function testGeocodePostcodeReturnsLatLonModel(): void + public function testGeocodePostcodeReturnsGeoCoordinates(): void { sleep(1); $result = $this->geocoder->geocodePostcode(self::POSTCODE); - $this->assertInstanceOf(LatLongModel::class, $result); + $this->assertInstanceOf(GeoCoordinates::class, $result); } private function getMappableEntity(): MappableInterface