Issues (45)

src/Metrics/Reporter/InventorioCloudReporter.php (1 issue)

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
}