1 | <?php |
||||
2 | namespace Mezon\CustomClient; |
||||
3 | |||||
4 | /** |
||||
5 | * Class CurlWrapper |
||||
6 | * |
||||
7 | * @package CustomClient |
||||
8 | * @subpackage CurlWrapper |
||||
9 | * @author Dodonov A.A. |
||||
10 | * @version v.1.0 (2019/08/07) |
||||
11 | * @copyright Copyright (c) 2019, aeon.org |
||||
12 | */ |
||||
13 | |||||
14 | /** |
||||
15 | * Wrapper for CURL routines |
||||
16 | */ |
||||
17 | class CurlWrapper |
||||
18 | { |
||||
19 | |||||
20 | /** |
||||
21 | * Method send HTTP request |
||||
22 | * |
||||
23 | * @param string $uRL |
||||
24 | * URL |
||||
25 | * @param array $headers |
||||
26 | * Headers |
||||
27 | * @param string $method |
||||
28 | * Request HTTP Method |
||||
29 | * @param array $data |
||||
30 | * Request data |
||||
31 | * @return array Response body and HTTP code |
||||
32 | */ |
||||
33 | public static function sendRequest(string $uRL, array $headers, string $method, array $data = []): array |
||||
34 | { |
||||
35 | $ch = curl_init(); |
||||
36 | |||||
37 | $curlConfig = [ |
||||
38 | CURLOPT_URL => $uRL, |
||||
39 | CURLOPT_HTTPHEADER => $headers, |
||||
40 | CURLOPT_POST => ($method == 'POST'), |
||||
41 | CURLOPT_RETURNTRANSFER => true, |
||||
42 | CURLOPT_SSL_VERIFYPEER => true |
||||
43 | ]; |
||||
44 | |||||
45 | if ($method == 'POST') { |
||||
46 | $formData = []; |
||||
47 | foreach ($data as $key => $value) { |
||||
48 | $formData[] = $key . '=' . urlencode($value); |
||||
49 | } |
||||
50 | $curlConfig[CURLOPT_POSTFIELDS] = implode('&', $formData); |
||||
51 | } |
||||
52 | |||||
53 | curl_setopt_array($ch, $curlConfig); |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
54 | |||||
55 | $body = curl_exec($ch); |
||||
0 ignored issues
–
show
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
![]() |
|||||
56 | $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
||||
0 ignored issues
–
show
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
![]() |
|||||
57 | |||||
58 | curl_close($ch); |
||||
0 ignored issues
–
show
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
![]() |
|||||
59 | |||||
60 | return [ |
||||
61 | $body, |
||||
62 | $code |
||||
63 | ]; |
||||
64 | } |
||||
65 | } |
||||
66 |