| Conditions | 3 |
| Paths | 2 |
| Total Lines | 30 |
| Code Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 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); |
||
|
|
|||
| 54 | |||
| 55 | $body = curl_exec($ch); |
||
| 56 | $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
||
| 57 | |||
| 58 | curl_close($ch); |
||
| 59 | |||
| 60 | return [ |
||
| 61 | $body, |
||
| 62 | $code |
||
| 63 | ]; |
||
| 66 |