Api::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Codenixsv\CoinGeckoApi\Api;
6
7
use Codenixsv\CoinGeckoApi\CoinGeckoClient;
8
use Codenixsv\CoinGeckoApi\Message\ResponseTransformer;
9
use Exception;
10
11
class Api
12
{
13
    /** @var CoinGeckoClient */
14
    protected $client;
15
16
    private $version = 'v3';
17
18
    /** @var ResponseTransformer */
19
    protected $transformer;
20
21 48
    public function __construct(CoinGeckoClient $client)
22
    {
23 48
        $this->client = $client;
24 48
        $this->transformer = new ResponseTransformer();
25 48
    }
26
27
    /**
28
     * @param string $uri
29
     * @param array $query
30
     * @return array
31
     * @throws Exception
32
     */
33 37
    public function get(string $uri, array $query = []): array
34
    {
35 37
        $response = $this->client->getHttpClient()->request('GET', '/api/' . $this->version
36 37
            . $uri, ['query' => $query]);
37 37
        $this->client->setLastResponse($response);
38
39 37
        return $this->transformer->transform($response);
40
    }
41
}
42