Reader   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 54
ccs 25
cts 25
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getOptions() 0 4 1
A get() 0 5 1
A getHttpQueryEndpoint() 0 4 1
A getHttpEndpoint() 0 13 1
A query() 0 12 1
1
<?php
2
namespace InfluxDB\Adapter\Http;
3
4
use InfluxDB\Adapter\Http\Options;
5
use GuzzleHttp\Client;
6
use InfluxDB\Adapter\QueryableInterface;
7
8
class Reader implements QueryableInterface
9
{
10
    private $httpClient;
11
    private $options;
12
13 15
    public function __construct(Client $httpClient, Options $options)
14
    {
15 15
        $this->httpClient = $httpClient;
16 15
        $this->options = $options;
17 15
    }
18
19 15
    public function getOptions()
20
    {
21 15
        return $this->options;
22
    }
23
24 12
    public function query($query)
25
    {
26
        $options = [
27 12
            "auth" => [$this->getOptions()->getUsername(), $this->getOptions()->getPassword()],
28
            'query' => [
29 12
                "q" => $query,
30 12
                "db" => $this->getOptions()->getDatabase(),
31
            ]
32
        ];
33
34 12
        return $this->get($options);
35
    }
36
37 12
    private function get(array $httpMessage)
38
    {
39 12
        $endpoint = $this->getHttpQueryEndpoint();
40 12
        return json_decode($this->httpClient->get($endpoint, $httpMessage)->getBody(), true);
41
    }
42
43 15
    protected function getHttpQueryEndpoint()
44
    {
45 15
        return $this->getHttpEndpoint("query");
46
    }
47
48 15
    private function getHttpEndpoint($operation)
49
    {
50 15
        $url = sprintf(
51 15
            "%s://%s:%d%s/%s",
52 15
            $this->getOptions()->getProtocol(),
53 15
            $this->getOptions()->getHost(),
54 15
            $this->getOptions()->getPort(),
55 15
            $this->getOptions()->getPrefix(),
56 15
            $operation
57
        );
58
59 15
        return $url;
60
    }
61
}
62