Http   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 30
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A request() 0 20 2
1
<?php declare(strict_types = 1);
2
3
namespace Suilven\CovidAPIClient\Transport;
4
5
class Http
6
{
7
8
    public const ENDPOINT = 'https://api.coronavirus.data.gov.uk/v1/data';
9
10
    /**
11
     * Execute a request
12
     *
13
     * @return bool|string
14
     */
15
    public function request(string $jsonurl)
16
    {
17
        $ch = \curl_init();
18
        \curl_setopt($ch, \CURLOPT_URL, \str_replace(' ', '%20', $jsonurl));
0 ignored issues
show
Bug introduced by
It seems like $ch can also be of type false; however, parameter $ch of curl_setopt() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

18
        \curl_setopt(/** @scrutinizer ignore-type */ $ch, \CURLOPT_URL, \str_replace(' ', '%20', $jsonurl));
Loading history...
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);
0 ignored issues
show
Bug introduced by
It seems like $ch can also be of type false; however, parameter $ch of curl_exec() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

24
        $response = \curl_exec(/** @scrutinizer ignore-type */ $ch);
Loading history...
25
        $info = \curl_getinfo($ch);
0 ignored issues
show
Bug introduced by
It seems like $ch can also be of type false; however, parameter $ch of curl_getinfo() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

25
        $info = \curl_getinfo(/** @scrutinizer ignore-type */ $ch);
Loading history...
26
        \curl_close($ch);
0 ignored issues
show
Bug introduced by
It seems like $ch can also be of type false; however, parameter $ch of curl_close() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

26
        \curl_close(/** @scrutinizer ignore-type */ $ch);
Loading history...
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
    }
36
}
37