Completed
Push — master ( 60e8f7...7e9313 )
by Mikhail
02:24
created

Api   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 38
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0
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
    /**
19
     * @var Client
20
     */
21
    protected Client $client;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
22
    /**
23
     * @var ResponseTransformer
24
     */
25
    protected ResponseTransformer $transformer;
26
    /**
27
     * @var string
28
     */
29
    private string $version = 'v3';
30 29
    /**
31
     * @var string
32 29
     */
33 29
    private string $endpoint = '/';
34 29
35
    /**
36
     * Api constructor.
37
     * @param Client $client
38
     */
39
    public function __construct(Client $client)
40
    {
41
        $this->client = $client;
42
        $this->transformer = new ResponseTransformer();
43
    }
44
45 26
    /**
46
     * @param string $method
47 26
     * @param string $uri
48 26
     * @param array $options
49 2
     * @param bool|null $needSequence
50
     * @return array
51 24
     * @throws GuzzleException
52
     * @throws TransformResponseException
53 1
     */
54
    public function rest(string $method, string $uri, array $options = [], ?bool $needSequence = null): array
55
    {
56
        $response = $this->client->request($method, $this->endpoint . $this->version . $uri, $options);
57
        if ($method === 'HEAD')
58
            return $this->transformer->transformHeader($response);
59
        else
60
            return $this->transformer->transform($response, $needSequence);
61
    }
62
}