Rename LatLongModel to GeoCoordinates
This commit is contained in:
@@ -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) {}
|
||||
|
||||
@@ -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'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user