Conditions | 2 |
Paths | 2 |
Total Lines | 20 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php declare(strict_types = 1); |
||
15 | public function request(string $jsonurl) |
||
16 | { |
||
17 | $ch = \curl_init(); |
||
18 | \curl_setopt($ch, \CURLOPT_URL, \str_replace(' ', '%20', $jsonurl)); |
||
|
|||
19 | \curl_setopt($ch, \CURLOPT_CUSTOMREQUEST, 'GET'); |
||
20 | \curl_setopt($ch, \CURLOPT_HTTPHEADER, [ |
||
21 | 'Content-Type: application/json', |
||
22 | ]); |
||
23 | \curl_setopt($ch, \CURLOPT_RETURNTRANSFER, 1); |
||
24 | $response = \curl_exec($ch); |
||
25 | $info = \curl_getinfo($ch); |
||
26 | \curl_close($ch); |
||
27 | |||
28 | $httpCode = \intval($info['http_code']); |
||
29 | |||
30 | if ($httpCode !== 200) { |
||
31 | throw new \Exception('http error returned'); |
||
32 | } |
||
33 | |||
34 | return $response; |
||
35 | } |
||
37 |