Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
14 / 14 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| RouteResultDto | |
100.00% |
13 / 13 |
|
100.00% |
4 / 4 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getDistanceKm | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getDurationMinutes | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toArray | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** @license For full copyright and license information, please see the LICENSE.md file. */ |
| 6 | |
| 7 | namespace App\Modules\Map\Domain\Model; |
| 8 | |
| 9 | defined('AMMONLY_APP') || exit('Direct script access is forbidden.'); |
| 10 | |
| 11 | /** |
| 12 | * Route Result Data Transfer Object. |
| 13 | * |
| 14 | * Encapsulates full driving route calculation output, including GeoJSON geometry, |
| 15 | * total distance, duration, and turn-by-turn steps. |
| 16 | * |
| 17 | * @package App\Modules\Map\Domain\Model |
| 18 | */ |
| 19 | final readonly class RouteResultDto |
| 20 | { |
| 21 | /** |
| 22 | * RouteResultDto constructor. |
| 23 | * |
| 24 | * @param float $distanceMeters Total path distance in meters. |
| 25 | * @param float $durationSeconds Total expected travel duration in seconds. |
| 26 | * @param array<string, mixed> $geometryGeoJson GeoJSON LineString geometry array. |
| 27 | * @param array<int, RouteStepDto> $steps Ordered list of navigation steps. |
| 28 | * @param string $summary Route summary description (e.g. via S7). |
| 29 | */ |
| 30 | public function __construct( |
| 31 | public float $distanceMeters, |
| 32 | public float $durationSeconds, |
| 33 | public array $geometryGeoJson, |
| 34 | public array $steps = [], |
| 35 | public string $summary = '', |
| 36 | public array $waypoints = [] |
| 37 | ) { |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Returns total route distance in kilometers, rounded to 1 decimal. |
| 42 | */ |
| 43 | public function getDistanceKm(): float |
| 44 | { |
| 45 | return round($this->distanceMeters / 1000.0, 1); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Returns total route travel time in minutes. |
| 50 | */ |
| 51 | public function getDurationMinutes(): int |
| 52 | { |
| 53 | return (int) round($this->durationSeconds / 60.0); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Serializes result into associative array. |
| 58 | * |
| 59 | * @return array{ |
| 60 | * distance_km: float, |
| 61 | * distance_meters: float, |
| 62 | * duration_minutes: int, |
| 63 | * duration_seconds: float, |
| 64 | * summary: string, |
| 65 | * geometry: array<string, mixed>, |
| 66 | * steps: array<int, array{ |
| 67 | * instruction: string, |
| 68 | * distance_meters: float, |
| 69 | * duration_seconds: float, |
| 70 | * maneuver_type: string |
| 71 | * }> |
| 72 | * } |
| 73 | */ |
| 74 | public function toArray(): array |
| 75 | { |
| 76 | return [ |
| 77 | 'distance_km' => $this->getDistanceKm(), |
| 78 | 'distance_meters' => $this->distanceMeters, |
| 79 | 'duration_minutes' => $this->getDurationMinutes(), |
| 80 | 'duration_seconds' => $this->durationSeconds, |
| 81 | 'summary' => $this->summary, |
| 82 | 'geometry' => $this->geometryGeoJson, |
| 83 | 'steps' => array_map(static fn(RouteStepDto $s): array => $s->toArray(), $this->steps), |
| 84 | 'waypoints' => $this->waypoints, |
| 85 | ]; |
| 86 | } |
| 87 | } |