ESM::testConnection()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
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