ExternalLibraryHttpClient::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 2
crap 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace AppBuilder\Application\Module\HttpClient;
6
7
use AppBuilder\Application\Configuration\ValueObject\Parameters;
8
use GuzzleHttp\Client;
9
use GuzzleHttp\Psr7\Response;
10
11
/**
12
 * Class combines Guzzle Client object and an array with credentials for further convenience.
13
 */
14
class ExternalLibraryHttpClient implements HttpClient
15
{
16
    /** @var string */
17
    public const GET = 'GET';
18
19
    /** @var Client */
20
    private $client;
21
22
    /** @var array */
23
    private $headerConfig;
24
25
    /** @var Parameters */
26
    private $applicationParams;
27
28 2
    public function __construct(Client $client, Parameters $applicationParams)
29
    {
30 2
        $this->applicationParams = $applicationParams;
31 2
        $this->client            = $client;
32 2
        $this->headerConfig      = [
33 2
            'auth'    => [$applicationParams->authenticationUser(), $applicationParams->authenticationPassword()],
34
            'headers' => ['Accept' => 'application/json'],
35
        ];
36 2
    }
37
38
    public function client() : Client
39
    {
40
        return $this->client;
41
    }
42
43
    public function applicationParams() : Parameters
44
    {
45
        return $this->applicationParams;
46
    }
47
48
    /**
49
     * Sends a request with passed method and url.
50
     */
51 2
    public function request(string $method, string $url) : Response
52
    {
53 2
        return $this->client->request($method, $url, $this->headerConfig);
54
    }
55
}
56