feat: add distance value object and ci workflows

This commit is contained in:
Bernard Ngandu
2025-10-10 16:13:48 +02:00
parent d3338e8901
commit 2ed7a48d36
44 changed files with 4263 additions and 1370 deletions
+2 -14
View File
@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\Service;
use App\ValueObject\Distance;
use App\ValueObject\Point;
use App\Exception\PointTooFarException;
use Psr\Log\LoggerInterface;
@@ -21,7 +22,7 @@ final class PointProximityValidator
public function assertWithinRange(Point $userLocation, Point $signalLocation): void
{
$distance = $this->distanceInKm($userLocation, $signalLocation);
$distance = Distance::betweenPoints($userLocation, $signalLocation)->inKilometers();
$this->logger->debug('Calculated proximity between user and signal.', [
'distance_km' => $distance,
@@ -36,17 +37,4 @@ final class PointProximityValidator
throw new PointTooFarException($this->maximumDistanceKm);
}
}
private function distanceInKm(Point $a, Point $b): float
{
$lat1 = deg2rad($a->getLat());
$lat2 = deg2rad($b->getLat());
$deltaLat = deg2rad($b->getLat() - $a->getLat());
$deltaLng = deg2rad($b->getLng() - $a->getLng());
$haversine = sin($deltaLat / 2) ** 2 + cos($lat1) * cos($lat2) * sin($deltaLng / 2) ** 2;
$c = 2 * atan2(sqrt($haversine), sqrt(1 - $haversine));
return 6371 * $c;
}
}