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