Api   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 60
ccs 16
cts 16
cp 1
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A timeseries() 0 7 1
A all() 0 6 1
A getClient() 0 3 1
A __construct() 0 5 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Codenixsv\MessariApi\Api;
6
7
use Codenixsv\MessariApi\Message\ResponseTransformer;
8
use Codenixsv\MessariApi\MessariClient;
9
use Codenixsv\MessariApi\Api\Query\QueryBuilder;
10
use Codenixsv\MessariApi\Api\Query\QueryBuilderInterface;
11
use Exception;
12
13
/**
14
 * Class Api
15
 * @package Codenixsv\MessariApi\Api
16
 */
17
class Api
18
{
19
    /** @var MessariClient  */
20
    protected $client;
21
22
    /** @var ResponseTransformer  */
23
    protected $transformer;
24
25
    /** @var QueryBuilderInterface */
26
    protected $queryBuilder;
27
28
    /**
29
     * Api constructor.
30
     * @param MessariClient $client
31
     * @param QueryBuilderInterface|null $queryBuilder
32
     */
33 19
    public function __construct(MessariClient $client, ?QueryBuilderInterface $queryBuilder = null)
34
    {
35 19
        $this->client = $client;
36 19
        $this->transformer = new ResponseTransformer();
37 19
        $this->queryBuilder = $queryBuilder ?: new QueryBuilder();
38 19
    }
39
40
    /**
41
     * @return MessariClient
42
     */
43 16
    public function getClient(): MessariClient
44
    {
45 16
        return $this->client;
46
    }
47
48
    /**
49
     * @param string $path
50
     * @param string $assetKey
51
     * @param string $metricId
52
     * @param array $params
53
     * @return array
54
     * @throws Exception
55
     */
56 4
    protected function timeseries(string $path, string $assetKey, string $metricId, array $params): array
57
    {
58 4
        $query = $this->queryBuilder->buildQuery($params);
59 4
        $response = $this->client->getBaseClient()->get('/' . $path . '/' . strtolower($assetKey) . '/metrics/'
60 4
            . $metricId . '/time-series' . $query);
61
62 4
        return $this->transformer->transform($response);
63
    }
64
65
    /**
66
     * @param string $path
67
     * @param array $params
68
     * @return array
69
     * @throws Exception
70
     */
71 6
    protected function all(string $path, array $params): array
72
    {
73 6
        $query = $this->queryBuilder->buildQuery($params);
74 6
        $response = $this->client->getBaseClient()->get('/' . $path . $query);
75
76 6
        return $this->transformer->transform($response);
77
    }
78
}
79