| Conditions | 6 |
| Paths | 6 |
| Total Lines | 40 |
| Code Lines | 17 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 42 |
| Changes | 0 | ||
| 1 | <?php |
||
| 59 | public static function upload($options, array $data = []): Curl |
||
| 60 | { |
||
| 61 | |||
| 62 | if (is_string($options)) |
||
| 63 | { |
||
| 64 | $options = ['url' => $options]; |
||
| 65 | } |
||
| 66 | |||
| 67 | if (!isset($options['url'])) |
||
| 68 | { |
||
| 69 | throw new Exceptions\Invalid('Param option `URL` not found!'); |
||
| 70 | } |
||
| 71 | |||
| 72 | $url = $options['url']; |
||
| 73 | $method = $options['method'] ?? 'post'; |
||
| 74 | |||
| 75 | $data = Arr::map($data, function ($value) { |
||
| 76 | |||
| 77 | if (\is_string($value) && Str::sub($value, 0, 1) === '@') |
||
| 78 | { |
||
| 79 | return curl_file_create(Str::sub($value, 1)); |
||
| 80 | } |
||
| 81 | |||
| 82 | return $value; |
||
| 83 | |||
| 84 | }); |
||
| 85 | |||
| 86 | $curl = static::curl() |
||
| 87 | ->$method($url, $data); |
||
| 88 | |||
| 89 | $response = JSON::decode($curl->response); |
||
| 90 | |||
| 91 | if (JSON::errorNone()) |
||
| 92 | { |
||
| 93 | $curl->response = $response; |
||
| 94 | } |
||
| 95 | |||
| 96 | return $curl; |
||
| 97 | |||
| 98 | } |
||
| 99 | |||
| 101 |