Guzzle6Transport::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 GuzzleHttp\Client;
6
use GuzzleHttp\ClientInterface;
7
use GuzzleHttp\Psr7\Request;
8
9
/**
10
 * Guzzle6 Transport.
11
 *
12
 * @author Alessandro Chitolina <[email protected]>
13
 */
14
class Guzzle6Transport implements TransportInterface
15
{
16
    /**
17
     * @var ClientInterface
18
     */
19
    private $client;
20
21
    /**
22
     * Guzzle6Transport constructor.
23
     *
24
     * @param ClientInterface|null $client
25
     */
26 1
    public function __construct(ClientInterface $client = null)
27
    {
28 1
        $this->client = $client ?: new Client();
29 1
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function executeRequest(string $uri, string $body): string
35
    {
36
        $request = new Request('POST', $uri, [
37
            'Content-Type' => 'application/x-www-form-urlencoded',
38
        ], $body);
39
        $response = $this->client->send($request);
40
41
        return (string) $response->getBody();
42
    }
43
}
44