Client   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 6
dl 0
loc 22
rs 10
c 2
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A stream() 0 3 1
A __construct() 0 3 1
A request() 0 5 1
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