Completed
Push — master ( 40bf07...dbb18c )
by Mikhail
01:23
created

Api   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 38
ccs 9
cts 10
cp 0.9
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A rest() 0 8 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace R3bers\BittrexApi\Api;
6
7
use GuzzleHttp\Client;
8
use GuzzleHttp\Exception\GuzzleException;
9
use R3bers\BittrexApi\Exception\TransformResponseException;
10
use R3bers\BittrexApi\Message\ResponseTransformer;
11
12
/**
13
 * Class Api
14
 * @package R3bers\BittrexApi\Api
15
 */
16
class Api
17
{
18
    /** @var Client */
19
    protected $client;
20
    /** @var ResponseTransformer */
21
    protected $transformer;
22
    /** @var string */
23
    private $version = 'v3';
24
    private $endpoint = '/';
25
26
    /**
27
     * Api constructor.
28
     * @param Client $client
29
     */
30 28
    public function __construct(Client $client)
31
    {
32 28
        $this->client = $client;
33 28
        $this->transformer = new ResponseTransformer();
34 28
    }
35
36
    /**
37
     * @param string $method
38
     * @param string $uri
39
     * @param array $options
40
     * @param bool|null $needSequence
41
     * @return array
42
     * @throws GuzzleException
43
     * @throws TransformResponseException
44
     */
45 25
    public function rest(string $method, string $uri, array $options = [], ?bool $needSequence = null): array
46
    {
47 25
        $response = $this->client->request($method, $this->endpoint . $this->version . $uri, $options);
48 25
        if ($method === 'HEAD')
49 2
            return $this->transformer->transformHeader($response);
50
        else
51 23
            return $this->transformer->transform($response, $needSequence);
52
    }
53
}