Completed
Push — master ( 6e7dc7...dc36db )
by Pol
03:54
created

AbstractClient::sendRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 1
cts 1
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 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
10
/**
11
 * Class AbstractClient.
12
 */
13
abstract class AbstractClient
14
{
15
    /**
16
     * The HTTP client.
17
     *
18
     * @var \Symfony\Contracts\HttpClient\HttpClientInterface
19
     */
20
    private $httpClient;
21
22
    /**
23
     * AbstractClient constructor.
24
     *
25
     * @param \Symfony\Contracts\HttpClient\HttpClientInterface $client
26
     */
27
    public function __construct(HttpClientInterface $client = null)
28
    {
29
        $this->httpClient = $client ?? new NativeHttpClient();
30
    }
31
32
    /**
33
     * Returns the HTTP adapter.
34
     *
35
     * @return HttpClientInterface
36
     */
37
    public function getHttpClient(): HttpClientInterface
38
    {
39 10
        return $this->httpClient;
40
    }
41 10
42 10
    /**
43 10
     * @param \Symfony\Contracts\HttpClient\HttpClientInterface $httpClient
44
     *
45
     * @return \drupol\Yaroc\Http\AbstractClient
46
     */
47
    public function withHttpClient(HttpClientInterface $httpClient): self
48
    {
49
        $clone = clone $this;
50 5
        $clone->httpClient = $httpClient;
51
52 5
        return $clone;
53 5
    }
54
}
55