Api::rest()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 7
ccs 5
cts 5
cp 1
c 0
b 0
f 0
rs 10
cc 2
nc 2
nop 4
crap 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
    /**
19
     * @var Client
20
     */
21
    protected Client $client;
22
    /**
23
     * @var ResponseTransformer
24
     */
25
    protected ResponseTransformer $transformer;
26
    /**
27
     * @var string
28
     */
29
    private string $version = 'v3';
30
    /**
31
     * @var string
32
     */
33
    private string $endpoint = '/';
34
35
    /**
36
     * Api constructor.
37
     * @param Client $client
38
     */
39 31
    public function __construct(Client $client)
40
    {
41 31
        $this->client = $client;
42 31
        $this->transformer = new ResponseTransformer();
43 31
    }
44
45
    /**
46
     * @param string $method
47
     * @param string $uri
48
     * @param array $options
49
     * @param bool|null $needSequence
50
     * @return array
51
     * @throws GuzzleException
52
     * @throws TransformResponseException
53
     */
54 27
    public function rest(string $method, string $uri, array $options = [], ?bool $needSequence = null): array
55
    {
56 27
        $response = $this->client->request($method, $this->endpoint . $this->version . $uri, $options);
57 27
        if ($method === 'HEAD')
58 2
            return $this->transformer->transformHeader($response);
59
        else
60 25
            return $this->transformer->transform($response, $needSequence);
61
    }
62
}