Passed
Push — master ( 379433...409871 )
by Alexey
02:52
created

CurlRequestContentResolver::handle()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 27
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
cc 4
eloc 16
nc 4
nop 3
dl 0
loc 27
ccs 0
cts 22
cp 0
crap 20
rs 9.7333
c 0
b 0
f 0
1
<?php
2
3
namespace CodeblogPro\YandexSpeller\Application\Services\YandexSpeller\Resolvers;
4
5
class CurlRequestContentResolver
6
{
7
    /**
8
     * @param string $url
9
     * @param array $postData
10
     * @param array $optionsList
11
     * @return array
12
     */
13
    public function handle(string $url, array $postData = [], array $optionsList = []): array
14
    {
15
        $curl = curl_init();
16
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
0 ignored issues
show
Bug introduced by
It seems like $curl 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

16
        curl_setopt(/** @scrutinizer ignore-type */ $curl, CURLOPT_RETURNTRANSFER, true);
Loading history...
17
        curl_setopt($curl, CURLOPT_URL, $url);
18
19
        if (!empty($postData)) {
20
            curl_setopt($curl, CURLOPT_POST, 1);
21
            curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($postData));
22
        }
23
24
        if (!empty($optionsList)) {
25
            foreach ($optionsList as $optionKey => $optionValue) {
26
                curl_setopt($curl, $optionKey, $optionValue);
27
            }
28
        }
29
30
        $result = [
31
            'result' => curl_exec($curl),
0 ignored issues
show
Bug introduced by
It seems like $curl 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

31
            'result' => curl_exec(/** @scrutinizer ignore-type */ $curl),
Loading history...
32
            'errno' => curl_errno($curl),
0 ignored issues
show
Bug introduced by
It seems like $curl can also be of type false; however, parameter $ch of curl_errno() 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

32
            'errno' => curl_errno(/** @scrutinizer ignore-type */ $curl),
Loading history...
33
            'error' => curl_error($curl),
0 ignored issues
show
Bug introduced by
It seems like $curl can also be of type false; however, parameter $ch of curl_error() 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

33
            'error' => curl_error(/** @scrutinizer ignore-type */ $curl),
Loading history...
34
            'http_code' => curl_getinfo($curl, CURLINFO_HTTP_CODE),
0 ignored issues
show
Bug introduced by
It seems like $curl 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

34
            'http_code' => curl_getinfo(/** @scrutinizer ignore-type */ $curl, CURLINFO_HTTP_CODE),
Loading history...
35
        ];
36
37
        curl_close($curl);
0 ignored issues
show
Bug introduced by
It seems like $curl 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

37
        curl_close(/** @scrutinizer ignore-type */ $curl);
Loading history...
38
39
        return $result;
40
    }
41
}
42