| Conditions | 4 |
| Paths | 4 |
| Total Lines | 27 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 20 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 13 | public function handle(string $url, array $postData = [], array $optionsList = []): array |
||
| 14 | { |
||
| 15 | $curl = curl_init(); |
||
| 16 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
||
|
|
|||
| 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), |
||
| 32 | 'errno' => curl_errno($curl), |
||
| 33 | 'error' => curl_error($curl), |
||
| 34 | 'http_code' => curl_getinfo($curl, CURLINFO_HTTP_CODE), |
||
| 35 | ]; |
||
| 36 | |||
| 37 | curl_close($curl); |
||
| 38 | |||
| 39 | return $result; |
||
| 40 | } |
||
| 42 |