ExternalLibraryHttpClient   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 66.67%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 42
ccs 8
cts 12
cp 0.6667
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A client() 0 4 1
A applicationParams() 0 4 1
A request() 0 4 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