ClientAdapter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 13
c 2
b 0
f 1
dl 0
loc 28
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A request() 0 4 1
A setHandler() 0 3 1
A call() 0 13 2
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