HttpClient   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 25
ccs 9
cts 10
cp 0.9
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A send() 0 12 3
1
<?php
2
declare(strict_types=1);
3
4
namespace IntegerNet\CallbackProxy;
5
6
use GuzzleHttp\Client;
7
use GuzzleHttp\Exception\RequestException;
8
use Psr\Http\Message\RequestInterface;
9
use Psr\Http\Message\ResponseInterface;
10
11
/**
12
 * Client to forward requests to configured Target
13
 */
14
class HttpClient
15
{
16
    /**
17
     * @var Client
18
     */
19
    private $client;
20
21 48
    public function __construct(Client $client)
22
    {
23 48
        $this->client = $client;
24 48
    }
25
26 48
    public function send(RequestInterface $request, Target $target, string $action): ResponseInterface
27
    {
28
        try {
29 48
            $response = $this->client->send($target->applyToRequest($request, $action));
30 42
            return $target->applyToResponse($response, $action);
31 15
        } catch (RequestException $e) {
32 15
            if ($e->getResponse() instanceof ResponseInterface) {
33 15
                return $target->applyToResponse($e->getResponse(), $action);
34
            }
35
            throw $e;
36
        }
37
    }
38
}
39