Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
19 / 19
100.00% covered (success)
100.00%
9 / 9
CRAP
100.00% covered (success)
100.00%
1 / 1
AmmonlyLocalMapProvider
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
9 / 9
13
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
 getName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getLabel
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getTileUrlTemplate
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
 supportsRegion
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
4
 geocode
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 reverseGeocode
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 isAvailable
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getLatencyMs
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\Infrastructure\Provider;
8
9defined('AMMONLY_APP') || exit('Direct script access is forbidden.');
10
11use App\Modules\Map\Domain\Model\GeoPoint;
12use App\Modules\Map\Domain\Repository\MapApiClientInterface;
13use App\Modules\Map\Domain\Repository\MapProviderInterface;
14
15/**
16 * Dedicated provider adapter for the self-hosted Ammonly Maps Engine (Poland coverage).
17 *
18 * @package App\Modules\Map\Infrastructure\Provider
19 */
20final class AmmonlyLocalMapProvider implements MapProviderInterface
21{
22    private const float LAT_MIN = 49.00;
23    private const float LAT_MAX = 54.90;
24    private const float LON_MIN = 14.12;
25    private const float LON_MAX = 24.15;
26
27    private float $lastLatencyMs = 5.0;
28
29    public function __construct(private readonly MapApiClientInterface $client)
30    {
31    }
32
33    public function getName(): string
34    {
35        return 'ammonly_local';
36    }
37
38    public function getLabel(): string
39    {
40        return 'Ammonly Maps Engine (Poland)';
41    }
42
43    public function getTileUrlTemplate(bool $darkMode = false): string
44    {
45        return $darkMode ? $this->client->getDarkTileUrlTemplate() : $this->client->getTileUrlTemplate();
46    }
47
48    public function supportsRegion(float $latitude, float $longitude): bool
49    {
50        return $latitude >= self::LAT_MIN
51            && $latitude <= self::LAT_MAX
52            && $longitude >= self::LON_MIN
53            && $longitude <= self::LON_MAX;
54    }
55
56    public function geocode(string $query, int $limit = 5): array
57    {
58        $start = microtime(true);
59        $res = $this->client->geocode($query, $limit);
60        $this->lastLatencyMs = (microtime(true) - $start) * 1000.0;
61        return $res;
62    }
63
64    public function reverseGeocode(float $latitude, float $longitude): ?GeoPoint
65    {
66        $start = microtime(true);
67        $res = $this->client->reverseGeocode($latitude, $longitude);
68        $this->lastLatencyMs = (microtime(true) - $start) * 1000.0;
69        return $res;
70    }
71
72    public function isAvailable(): bool
73    {
74        return $this->client->getApiUrl() !== '';
75    }
76
77    public function getLatencyMs(): float
78    {
79        return $this->lastLatencyMs;
80    }
81}