Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
MapRoutingService
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
3 / 3
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 calculateRoute
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 optimizeTrip
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5/** @license For full copyright and license information, please see the LICENSE.md file. */
6
7namespace App\Modules\Map\Application\Service;
8
9defined('AMMONLY_APP') || exit('Direct script access is forbidden.');
10
11use App\Modules\Map\Domain\Model\GeoPoint;
12use App\Modules\Map\Domain\Model\RouteResultDto;
13use App\Modules\Map\Domain\Repository\MapApiClientInterface;
14
15/**
16 * Map Routing Application Service.
17 *
18 * Coordinates turn-by-turn driving route calculations and multi-point travel itineraries.
19 *
20 * @package App\Modules\Map\Application\Service
21 */
22final class MapRoutingService
23{
24    /**
25     * MapRoutingService constructor.
26     *
27     * @param MapApiClientInterface $client Maps API client.
28     */
29    public function __construct(
30        private readonly MapApiClientInterface $client
31    ) {
32    }
33
34    /**
35     * Calculates driving route between two points.
36     *
37     * @param GeoPoint $origin      Starting location.
38     * @param GeoPoint $destination Target destination location.
39     * @return RouteResultDto|null Calculated route geometry and steps or null.
40     */
41    public function calculateRoute(GeoPoint $origin, GeoPoint $destination): ?RouteResultDto
42    {
43        return $this->client->calculateRoute($origin, $destination);
44    }
45
46    /**
47     * Calculates optimal multi-point trip route (TSP).
48     *
49     * @param array<int, GeoPoint> $points    List of stop points to visit.
50     * @param bool                 $roundtrip Whether to return to starting point.
51     * @return RouteResultDto|null Calculated optimal trip itinerary or null.
52     */
53    public function optimizeTrip(array $points, bool $roundtrip = true): ?RouteResultDto
54    {
55        return $this->client->optimizeTrip($points, $roundtrip);
56    }
57}