Lines 100.00% 13 / 13
Methods 100.00% 2 / 2
Classes 100.00% 1 / 1
Name Lines Methods CRAP
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 fetch 100.00% 12 / 12 100.00% 1 / 1 2
7final readonly class TravelMapClient
8{
9    /** @param non-empty-string $url */
10    public function __construct(
11        private string $url = 'https://game.aq.com/game/api/data/travelmap',
12    ) {}
13
14    /** @throws TravelMapUnavailableException */
15    public function fetch(): TravelMap
16    {
17        $curl = curl_init($this->url);
18        curl_setopt_array($curl, [
19            CURLOPT_RETURNTRANSFER => true,
20            CURLOPT_FOLLOWLOCATION => true,
21            CURLOPT_TIMEOUT => 20,
22            CURLOPT_CONNECTTIMEOUT => 5,
23            CURLOPT_USERAGENT => 'Mozilla/5.0',
24        ]);
25
26        $response = curl_exec($curl);
27        if (!is_string($response)) {
28            throw new TravelMapUnavailableException('Could not reach the travel map API: ' . curl_error($curl));
29        }
30
31        return TravelMap::fromJson($response);
32    }
33}