ESM   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 96%

Importance

Changes 5
Bugs 1 Features 2
Metric Value
wmc 7
c 5
b 1
f 2
lcom 1
cbo 5
dl 0
loc 52
ccs 24
cts 25
cp 0.96
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A testConnection() 0 4 1
A getRequestData() 0 8 2
A __toArray() 0 4 1
A get() 0 13 2
1
<?php
2
namespace Xigen;
3
4
use GuzzleHttp\Client;
5
6
class ESM
7
{
8
    use Shortcuts\Banner;
9
    use Shortcuts\Client;
10
    use Shortcuts\Templates;
11
12
    public $responseData;
13
    public $options;
14
    private $client;
15
    private $response;
0 ignored issues
show
Unused Code introduced by
The property $response is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
16
17 3
    public function __construct($options)
18
    {
19 3
        $this->options = $options;
20 3
        $this->client = new Client([
21 3
            'base_url' => [$this->options['URL'], ['version' => 'v2']]
22 3
        ]);
23 3
    }
24
25 1
    public function testConnection()
26
    {
27 1
        $this->get('/ping');
28 1
    }
29
30 3
    public function getRequestData($JsonDecode = true)
31
    {
32 3
        if ($JsonDecode == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
33 3
            $this->responseData = $this->__toArray($this->responseData);
34 3
        }
35
36 3
        return $this->responseData;
37
    }
38
39 3
    public function __toArray($data)
40
    {
41 3
        return @json_decode($data);
42
    }
43
44 3
    private function get($endpoint)
45
    {
46
        try {
47 3
            $response = $this->client->post($this->options['URL'] . $endpoint, [
48
                'body' => [
49 3
                    'APIKEY' => $this->options['APIKEY']
50 3
                ]
51 3
            ]);
52 3
            $this->responseData = (string) $response->getBody();
53 3
        } catch (\GuzzleHttp\Exception\RequestException $e) {
54
            var_dump($e);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($e); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
55
        }
56 3
    }
57
}
58