Client::request()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 2
b 0
f 0
nc 1
nop 3
dl 0
loc 5
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace drupol\Yaroc\Http;
6
7
use Symfony\Component\HttpClient\NativeHttpClient;
8
use Symfony\Contracts\HttpClient\HttpClientInterface;
9
use Symfony\Contracts\HttpClient\ResponseInterface;
10
use Symfony\Contracts\HttpClient\ResponseStreamInterface;
11
12
final class Client implements HttpClientInterface
13
{
14
    /**
15
     * The HTTP client.
16
     */
17
    private HttpClientInterface $httpClient;
18
19
    public function __construct(?HttpClientInterface $httpClient = null)
20
    {
21
        $this->httpClient = $httpClient ?? new NativeHttpClient();
22
    }
23
24
    public function request(string $method, string $url, array $options = []): ResponseInterface
25
    {
26
        $options['headers']['User-Agent'] = 'YAROC (http://github.com/drupol/yaroc)';
27
28
        return $this->httpClient->request($method, $url, $options);
29
    }
30
31
    public function stream($responses, ?float $timeout = null): ResponseStreamInterface
32
    {
33
        return $this->httpClient->stream($responses, $timeout);
34
    }
35
}
36