Passed
Pull Request — master (#19)
by Alex
02:51
created

Client   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 37
ccs 6
cts 8
cp 0.75
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A send() 0 11 2
1
<?php
2
3
namespace Digitonic\IexCloudSdk;
4
5
use GuzzleHttp\Client as Guzzle;
6
use GuzzleHttp\Exception\ClientException;
7
use GuzzleHttp\Exception\GuzzleException;
8
use Psr\Http\Message\RequestInterface;
9
use Psr\Http\Message\ResponseInterface;
10
use Digitonic\IexCloudSdk\Contracts\IEXCloud;
11
use Digitonic\IexCloudSdk\Exceptions\WrongData;
12
use GuzzleHttp\Psr7\Uri;
13
14
class Client implements IEXCloud
15
{
16
    /**
17
     * @var Guzzle|null
18
     */
19
    private $client = null;
20
21
    /**
22
     * Client constructor.
23
     *
24
     * @param  Guzzle  $client
25
     */
26 167
    public function __construct(Guzzle $client)
27
    {
28 167
        $this->client = $client;
29 167
    }
30
31
    /**
32
     * @param  RequestInterface  $request
33
     * @param  array  $options
34
     *
35
     * @return ResponseInterface
36
     * @throws GuzzleException
37
     * @throws WrongData
38
     */
39 67
    public function send(RequestInterface $request, array $options = []): ResponseInterface
40
    {
41
        try {
42 67
            return $this->client->send($request, [
43 67
                'query' => Uri::withQueryValues($request->getUri(), $this->client->getConfig('query') ?? [])->getQuery()
44
            ]);
45
        }
46
        catch (ClientException $e) {
47
            throw WrongData::invalidValuesProvided($e->getMessage());
48
        }
49
    }
50
}
51