StatClient   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 44
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A performQuery() 0 7 1
A downloadBulkJobStream() 0 6 1
A buildRequest() 0 12 2
1
<?php
2
3
namespace SchulzeFelix\Stat;
4
5
use GuzzleHttp\Client;
6
7
class StatClient
8
{
9
    /**
10
     * @var Client
11
     */
12
    private $client;
13
14
    /**
15
     * Sistrix constructor.
16
     * @param Client $client
17
     */
18
    public function __construct(Client $client)
19
    {
20
        $this->client = $client;
21
    }
22
23
    public function performQuery(string $method, array $parameters)
24
    {
25
        $request = $this->buildRequest($method, $parameters);
26
        $response = $this->client->get($request);
27
28
        return json_decode($response->getBody()->getContents(), true);
29
    }
30
31
    public function downloadBulkJobStream($streamUrl)
32
    {
33
        $response = $this->client->get($streamUrl);
34
35
        return json_decode($response->getBody()->getContents(), true);
36
    }
37
38
    protected function buildRequest($method, $parameters = [])
39
    {
40
        $parameterString = '?format=json';
41
42
        foreach ($parameters as $parameter => $value) {
43
            $parameterString .= '&'.$parameter.'='.$value;
44
        }
45
46
        $request = $method.$parameterString;
47
48
        return $request;
49
    }
50
}
51