| Code Coverage | ||||||||||
| Classes and Traits | Functions and Methods | Lines | ||||||||
| Total |  | 100.00% | 1 / 1 |  | 100.00% | 2 / 2 | CRAP |  | 100.00% | 8 / 8 | 
| GetForecastQueryHandler |  | 100.00% | 1 / 1 |  | 100.00% | 2 / 2 | 2 |  | 100.00% | 8 / 8 | 
| __construct |  | 100.00% | 1 / 1 | 1 |  | 100.00% | 2 / 2 | |||
| __invoke |  | 100.00% | 1 / 1 | 1 |  | 100.00% | 6 / 6 | |||
| 1 | <?php | 
| 2 | |
| 3 | namespace App\Infrastructure; | 
| 4 | |
| 5 | use App\Application\ForecastResponse; | 
| 6 | use App\Application\GetForecastQuery; | 
| 7 | use App\Application\QueryHandler; | 
| 8 | use App\Domain\Weather\Forecast; | 
| 9 | use Symfony\Component\HttpFoundation\Request; | 
| 10 | use Symfony\Component\Serializer\Normalizer\UnwrappingDenormalizer; | 
| 11 | use Symfony\Component\Serializer\SerializerInterface; | 
| 12 | use Symfony\Contracts\HttpClient\HttpClientInterface; | 
| 13 | |
| 14 | class GetForecastQueryHandler implements QueryHandler | 
| 15 | { | 
| 16 | public function __construct( | 
| 17 | private HttpClientInterface $weatherClient, | 
| 18 | private SerializerInterface $serializer, | 
| 19 | ) { | 
| 20 | } | 
| 21 | |
| 22 | public function __invoke(GetForecastQuery $query): ForecastResponse | 
| 23 | { | 
| 24 | $request = $this->weatherClient->request(Request::METHOD_GET, '/v1/forecast.json', [ | 
| 25 | 'query' => [ | 
| 26 | 'q' => (string) $query, | 
| 27 | 'days' => $query->getDays(), | 
| 28 | ], | 
| 29 | ]); | 
| 30 | |
| 31 | /** @var Forecast[] $forecasts */ | 
| 32 | $forecasts = $this->serializer->deserialize($request->getContent(), Forecast::class.'[]', 'json', [ | 
| 33 | UnwrappingDenormalizer::UNWRAP_PATH => '[forecast][forecastday]', | 
| 34 | ]); | 
| 35 | |
| 36 | return new ForecastResponse($forecasts); | 
| 37 | } | 
| 38 | } |