Skip to content

Commit

Permalink
Merge pull request #57 from Setono/48-lat-long-decimals
Browse files Browse the repository at this point in the history
Refactor latitude and longitude to decimals
  • Loading branch information
loevgaard authored Jul 7, 2021
2 parents 2798763 + afcdc7f commit 83cdfe9
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 47 deletions.
8 changes: 4 additions & 4 deletions spec/Provider/DAOProviderSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ private function testPickupPoint($pickupPoint, string $id): void
$pickupPoint->getZipCode()->shouldReturn('7100');
$pickupPoint->getCity()->shouldReturn('Vejle');
$pickupPoint->getCountry()->shouldReturn('DK');
$pickupPoint->getLatitude()->shouldReturn('55.7119');
$pickupPoint->getLongitude()->shouldReturn('9.539939');
$pickupPoint->getLatitude()->shouldReturn(55.7119);
$pickupPoint->getLongitude()->shouldReturn(9.539939);
}

private function pickupPointArray(string $id): array
Expand All @@ -118,8 +118,8 @@ private function pickupPointArray(string $id): array
'postnr' => '7100',
'bynavn' => 'Vejle',
'udsortering' => 'E',
'latitude' => '55.7119',
'longitude' => '9.539939',
'latitude' => 55.7119,
'longitude' => 9.539939,
'afstand' => 2.652,
'aabningstider' => [
'man' => '08:00 - 22:00',
Expand Down
17 changes: 11 additions & 6 deletions src/Model/PickupPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Setono\SyliusPickupPointPlugin\Model;

use function sprintf;
use Webmozart\Assert\Assert;

class PickupPoint implements PickupPointInterface
{
Expand All @@ -22,9 +23,9 @@ class PickupPoint implements PickupPointInterface

protected ?string $country = null;

protected ?string $latitude = null;
protected ?float $latitude = null;

protected ?string $longitude = null;
protected ?float $longitude = null;

public function getId(): ?int
{
Expand Down Expand Up @@ -91,23 +92,27 @@ public function setCountry(string $country): void
$this->country = $country;
}

public function getLatitude(): ?string
public function getLatitude(): ?float
{
return $this->latitude;
}

public function setLatitude(?string $latitude): void
public function setLatitude(?float $latitude): void
{
Assert::nullOrRange($latitude, -90, 90);

$this->latitude = $latitude;
}

public function getLongitude(): ?string
public function getLongitude(): ?float
{
return $this->longitude;
}

public function setLongitude(?string $longitude): void
public function setLongitude(?float $longitude): void
{
Assert::nullOrRange($longitude, -180, 180);

$this->longitude = $longitude;
}

Expand Down
14 changes: 10 additions & 4 deletions src/Model/PickupPointInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,19 @@ public function getCountry(): ?string;

public function setCountry(string $country): void;

public function getLatitude(): ?string;
public function getLatitude(): ?float;

public function setLatitude(?string $latitude): void;
/**
* @throws \InvalidArgumentException if the $latitude is invalid
*/
public function setLatitude(?float $latitude): void;

public function getLongitude(): ?string;
public function getLongitude(): ?float;

public function setLongitude(?string $longitude): void;
/**
* @throws \InvalidArgumentException if the $longitude is invalid
*/
public function setLongitude(?float $longitude): void;

public function getFullAddress(): string;
}
4 changes: 2 additions & 2 deletions src/Provider/FakerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ private function createFakePickupPoint(string $index, ?string $countryCode = nul
$pickupPoint->setZipCode((string) $this->faker->numberBetween(11111, 99999));
$pickupPoint->setCity($this->faker->city);
$pickupPoint->setCountry($countryCode);
$pickupPoint->setLatitude((string) $this->faker->latitude);
$pickupPoint->setLongitude((string) $this->faker->longitude);
$pickupPoint->setLatitude($this->faker->latitude);
$pickupPoint->setLongitude($this->faker->longitude);

return $pickupPoint;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Provider/GlsProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ private function transform(ParcelShop $parcelShop): PickupPointInterface
$pickupPoint->setZipCode($parcelShop->getZipCode());
$pickupPoint->setCity($parcelShop->getCity());
$pickupPoint->setCountry($parcelShop->getCountryCode());
$pickupPoint->setLatitude($parcelShop->getLatitude());
$pickupPoint->setLongitude($parcelShop->getLongitude());
$pickupPoint->setLatitude((float) $parcelShop->getLatitude());
$pickupPoint->setLongitude((float) $parcelShop->getLongitude());

return $pickupPoint;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Provider/PostNordProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ private function transform(array $servicePoint): PickupPointInterface

$latitude = $longitude = null;
if (isset($servicePoint['coordinates'][0])) {
$latitude = (string) $servicePoint['coordinates'][0]['northing'];
$longitude = (string) $servicePoint['coordinates'][0]['easting'];
$latitude = (float) $servicePoint['coordinates'][0]['northing'];
$longitude = (float) $servicePoint['coordinates'][0]['easting'];
}

/** @var PickupPointInterface|object $pickupPoint */
Expand Down
14 changes: 7 additions & 7 deletions src/Resources/config/doctrine/model/PickupPoint.orm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

<embedded name="code" class="Setono\SyliusPickupPointPlugin\Model\PickupPointCode"/>

<field name="name"/>
<field name="address"/>
<field name="zipCode"/>
<field name="city"/>
<field name="country" column="country"/>
<field name="latitude" nullable="true"/>
<field name="longitude" nullable="true"/>
<field name="name" type="string"/>
<field name="address" type="string"/>
<field name="zipCode" type="string"/>
<field name="city" type="string"/>
<field name="country" column="country" type="string"/>
<field name="latitude" nullable="true" type="decimal" precision="10" scale="8"/>
<field name="longitude" nullable="true" type="decimal" precision="11" scale="8"/>
</mapped-superclass>
</doctrine-mapping>
21 changes: 11 additions & 10 deletions tests/Behat/Mocker/GlsProviderMocker.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,17 @@ public function findPickupPoints(OrderInterface $order): iterable

public function findPickupPoint(PickupPointCode $code): ?PickupPointInterface
{
return new PickupPoint(
new PickupPointCode(self::PICKUP_POINT_ID, $this->getCode(), 'DK'),
'Somewhere',
'1 Rainbow str',
'4499',
'Aalborg',
'DK',
'23N',
'180E'
);
$pickupPoint = new PickupPoint();
$pickupPoint->setCode(new PickupPointCode(self::PICKUP_POINT_ID, $this->getCode(), 'DK'));
$pickupPoint->setName('Somewhere');
$pickupPoint->setAddress('1 Rainbow str');
$pickupPoint->setZipCode('4499');
$pickupPoint->setCity('Aalborg');
$pickupPoint->setCountry('DK');
$pickupPoint->setLatitude(57.046707);
$pickupPoint->setLongitude(9.935932);

return $pickupPoint;
}

public function findAllPickupPoints(): iterable
Expand Down
21 changes: 11 additions & 10 deletions tests/Behat/Mocker/PostNordProviderMocker.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,17 @@ public function findPickupPoints(OrderInterface $order): iterable

public function findPickupPoint(PickupPointCode $code): ?PickupPointInterface
{
return new PickupPoint(
new PickupPointCode(self::PICKUP_POINT_ID, $this->getCode(), 'DK'),
'Somewhere',
'1 Rainbow str',
'1145',
'Aalborg',
'DK',
'23N',
'180E'
);
$pickupPoint = new PickupPoint();
$pickupPoint->setCode(new PickupPointCode(self::PICKUP_POINT_ID, $this->getCode(), 'DK'));
$pickupPoint->setName('Somewhere');
$pickupPoint->setAddress('1 Rainbow str');
$pickupPoint->setZipCode('4499');
$pickupPoint->setCity('Aalborg');
$pickupPoint->setCountry('DK');
$pickupPoint->setLatitude(57.046707);
$pickupPoint->setLongitude(9.935932);

return $pickupPoint;
}

public function findAllPickupPoints(): iterable
Expand Down

0 comments on commit 83cdfe9

Please sign in to comment.