Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
TransportApiFetcher
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
1 / 1
 fetchConnection
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3namespace Olz\Fetchers;
4
5class TransportApiFetcher {
6    /**
7     * Fetch a public transport connection.
8     *
9     * @param array<string, mixed> $request_data
10     *
11     * API docs: https://transport.opendata.ch/docs.html#connections
12     */
13    public function fetchConnection(array $request_data): mixed {
14        $transport_api_connection_url = 'https://transport.opendata.ch/v1/connections';
15
16        $get_params = http_build_query($request_data, '', '&');
17        $url = "{$transport_api_connection_url}?{$get_params}";
18
19        $ch = curl_init();
20        curl_setopt($ch, CURLOPT_URL, $url);
21        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
22        $connection_result = curl_exec($ch);
23        $connection_response = json_decode(!is_bool($connection_result) ? $connection_result : '', true);
24        curl_close($ch);
25
26        return $connection_response;
27    }
28}