Passed
Pull Request — develop (#12)
by Darío
07:27 queued 05:11
created

SymfonyAdapter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 11
c 0
b 0
f 0
dl 0
loc 22
ccs 11
cts 11
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A request() 0 13 3
1
<?php
2
3
namespace EasyHttp\SymfonyLayer;
4
5
use EasyHttp\LayerContracts\Contracts\HttpClientAdapter;
6
use EasyHttp\LayerContracts\Contracts\HttpClientRequest;
7
use EasyHttp\LayerContracts\Contracts\HttpClientResponse;
8
use EasyHttp\LayerContracts\Exceptions\HttpClientException;
9
use Symfony\Component\HttpClient\Exception\ClientException;
10
use Symfony\Component\HttpClient\Exception\RedirectionException;
11
use Symfony\Component\HttpClient\Exception\ServerException;
12
use Symfony\Component\HttpClient\Exception\TransportException;
13
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
14
use Symfony\Contracts\HttpClient\HttpClientInterface;
15
16
class SymfonyAdapter implements HttpClientAdapter
17
{
18
    protected HttpClientInterface $client;
19
20 14
    public function __construct(HttpClientInterface $client)
21
    {
22 14
        $this->client = $client;
23 14
    }
24
25 14
    public function request(HttpClientRequest $request): HttpClientResponse
26
    {
27
        try {
28 14
            $response = $this->client->request($request->getMethod(), $request->getUri(), $request->options());
0 ignored issues
show
Bug introduced by
The method options() does not exist on EasyHttp\LayerContracts\...racts\HttpClientRequest. It seems like you code against a sub-type of EasyHttp\LayerContracts\...racts\HttpClientRequest such as EasyHttp\SymfonyLayer\SymfonyRequest. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

28
            $response = $this->client->request($request->getMethod(), $request->getUri(), $request->/** @scrutinizer ignore-call */ options());
Loading history...
29
30 12
            return new SymfonyResponse($response, $response->getContent());
31 3
        } catch (ClientException | RedirectionException $exception) {
32 1
            $response = $exception->getResponse();
33 2
        } catch (ServerException | TransportException | TransportExceptionInterface $exception) {
34 2
            throw HttpClientException::fromThrowable($exception);
35
        }
36
37 1
        return new SymfonyResponse($response);
38
    }
39
}
40