ClientAdapter::setHandler()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace EasyHttp\LayerContracts\Tests\Unit\Example;
4
5
use EasyHttp\LayerContracts\Contracts\HttpClientAdapter;
6
use EasyHttp\LayerContracts\Contracts\HttpClientRequest;
7
use EasyHttp\LayerContracts\Contracts\HttpClientResponse;
8
9
class ClientAdapter implements HttpClientAdapter
10
{
11
    protected $handler;
12
13
    public function setHandler(callable $handler): void
14
    {
15
        $this->handler = $handler;
16
    }
17
18
    public function request(HttpClientRequest $request): HttpClientResponse
19
    {
20
        $response = $this->call($request->getMethod(), $request->getUri());
21
        return new ClientResponse($response);
22
    }
23
24
    private function call(string $method, string $uri): array
25
    {
26
        if ($this->handler) {
27
            return call_user_func($this->handler);
28
        }
29
30
        return [
31
            'status' => 200,
32
            'headers' => [
33
                'Server' => 'Apache/2.4.38 (Debian)',
34
                'X-Info' => $method . ' ' . $uri
35
            ],
36
            'body' => '{"key":"value"}',
37
        ];
38
    }
39
}
40