HttpClientTransport::executeRequest()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 6
cp 0
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 2
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