| Conditions | 1 |
| Paths | 1 |
| Total Lines | 25 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 2 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 11 | public function postRequestInvoice(string $uri, string $body, array $headers = []): ?array |
||
| 12 | { |
||
| 13 | // TODO: Consider using something like this: |
||
| 14 | // HttpClient::create() |
||
| 15 | // ->request('POST', $url, $options) |
||
| 16 | // ->getContent(); |
||
| 17 | $options = [ |
||
| 18 | explode(':', $uri)[0] => [ // extract protocol from $uri |
||
| 19 | 'header' => implode( |
||
| 20 | "\r\n", |
||
| 21 | array_map( |
||
| 22 | static fn (string $v, string $k) => sprintf('%s: %s', $k, $v), |
||
| 23 | $headers, |
||
| 24 | array_keys($headers), |
||
| 25 | ), |
||
| 26 | ), |
||
| 27 | 'method' => 'POST', |
||
| 28 | 'content' => $body, |
||
| 29 | ], |
||
| 30 | ]; |
||
| 31 | |||
| 32 | $context = stream_context_create($options); |
||
| 33 | $response = (string)file_get_contents($uri, false, $context); |
||
| 34 | |||
| 35 | return json_decode($response, true, 512, JSON_THROW_ON_ERROR); |
||
| 36 | } |
||
| 38 |