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