InventorioCloudReporter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
c 0
b 0
f 0
dl 0
loc 27
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A report() 0 17 3
A __construct() 0 3 1
1
<?php
2
3
namespace Startwind\Inventorio\Metrics\Reporter;
4
5
use GuzzleHttp\Client;
6
use GuzzleHttp\Exception\ClientException;
7
use GuzzleHttp\Exception\RequestException;
8
use GuzzleHttp\RequestOptions;
9
10
class InventorioCloudReporter
11
{
12
    const COLLECT_URL = 'https://collect.inventorio.cloud/collect/index.php';
13
    private Client $client;
14
15
    public function __construct()
16
    {
17
        $this->client = new Client();
18
    }
19
20
    public function report(string $serverId, array $data): void
21
    {
22
        $payload = [
23
            'server_id' => $serverId,
24
            'values' => $data
25
        ];
26
27
        try {
28
            $this->client->post(self::COLLECT_URL, [
29
                RequestOptions::JSON => $payload,
30
                RequestOptions::TIMEOUT => 5,
31
                RequestOptions::CONNECT_TIMEOUT => 2
32
            ]);
33
        } catch (ClientException $exception) {
34
            var_dump('ce: ' . (string)$exception->getResponse()->getBody());
0 ignored issues
show
Security Debugging Code introduced by
var_dump('ce: ' . (strin...tResponse()->getBody()) looks like debug code. Are you sure you do not want to remove it?
Loading history...
35
        } catch (RequestException $exception) {
36
            var_dump('re: ' . (string)$exception->getResponse()->getBody());
37
        }
38
    }
39
}