Passed
Push — master ( 56bc95...86ac78 )
by Pol
14:09
created

Client::stream()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
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
/**
13
 * Class Client.
14
 */
15
class Client implements HttpClientInterface
16
{
17
    /**
18
     * The HTTP client.
19
     *
20
     * @var \Symfony\Contracts\HttpClient\HttpClientInterface
21
     */
22
    private $httpClient;
23
24
    /**
25
     * Client constructor.
26
     *
27
     * @param null|\Symfony\Contracts\HttpClient\HttpClientInterface $httpClient
28
     */
29
    public function __construct(HttpClientInterface $httpClient = null)
30
    {
31
        $this->httpClient = $httpClient ?? new NativeHttpClient();
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function request(string $method, string $url, array $options = []): ResponseInterface
38
    {
39
        $options['headers']['User-Agent'] = 'YAROC (http://github.com/drupol/yaroc)';
40
41
        return $this->httpClient->request($method, $url, $options);
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function stream($responses, float $timeout = null): ResponseStreamInterface
48
    {
49
        return $this->httpClient->stream($responses, $timeout);
50
    }
51
}
52