HttpClientTransport   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 40%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 31
ccs 4
cts 10
cp 0.4
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A executeRequest() 0 9 1
1
<?php declare(strict_types=1);
2
3
namespace Fazland\SkebbyRestClient\Transport;
4
5
use Http\Client\HttpClient;
6
use Http\Message\MessageFactory;
7
8
/**
9
 * Http Client Transport.
10
 *
11
 * @author Alessandro Chitolina <[email protected]>
12
 */
13
class HttpClientTransport implements TransportInterface
14
{
15
    /**
16
     * @var HttpClient
17
     */
18
    private $client;
19
20
    /**
21
     * @var MessageFactory
22
     */
23
    private $messageFactory;
24
25 1
    public function __construct(HttpClient $client, MessageFactory $messageFactory)
26
    {
27 1
        $this->client = $client;
28 1
        $this->messageFactory = $messageFactory;
29 1
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function executeRequest(string $uri, string $body): string
35
    {
36
        $request = $this->messageFactory->createRequest('POST', $uri, [
37
            'Content-Type' => 'application/x-www-form-urlencoded',
38
        ], $body);
39
        $response = $this->client->sendRequest($request);
40
41
        return (string) $response->getBody();
42
    }
43
}
44