Passed
Push — master ( 1e9aa0...37b4ec )
by Darío
02:15 queued 10s
created

AbstractClient::setAdapter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
namespace EasyHttp\LayerContracts;
4
5
use EasyHttp\LayerContracts\Contracts\EasyClientContract;
6
use EasyHttp\LayerContracts\Contracts\HttpClientAdapter;
7
use EasyHttp\LayerContracts\Contracts\HttpClientRequest;
8
use EasyHttp\LayerContracts\Contracts\HttpClientResponse;
9
10
abstract class AbstractClient implements EasyClientContract
11
{
12
    protected HttpClientAdapter $adapter;
13
14
    protected HttpClientRequest $request;
15
16
    protected $handler;
17
18 1
    public function getRequest(): HttpClientRequest
19
    {
20 1
        return $this->request;
21
    }
22
23 1
    public function call(string $method, string $uri): HttpClientResponse
24
    {
25 1
        $request = $this->buildRequest($method, $uri);
26 1
        return $this->getAdapter()->request($request);
27
    }
28
29 2
    public function prepareRequest(string $method, string $uri): self
30
    {
31 2
        $this->request = $this->buildRequest($method, $uri);
32
33 2
        return $this;
34
    }
35
36
    public function withHandler(callable $handler): self
37
    {
38
        $this->handler = $handler;
39
40
        return $this;
41
    }
42
43 1
    public function execute(): HttpClientResponse
44
    {
45 1
        return $this->getAdapter()->request($this->request);
46
    }
47
48
    abstract protected function buildRequest(string $method, string $uri): HttpClientRequest;
49
    abstract protected function getAdapter(): HttpClientAdapter;
50
}
51