Insights   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 39
rs 10
c 0
b 0
f 0
ccs 16
cts 16
cp 1
wmc 2
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A sendEvent() 0 12 1
1
<?php
2
3
namespace DJStarCOM\NewRelic;
4
5
use GuzzleHttp\Client;
6
use DJStarCOM\NewRelic\Entity\Insights\EventCollection;
7
use Respect\Validation\Validator;
8
9
class Insights
10
{
11
    private $key;
12
    private $client;
13
14
    /**
15
     * Insights constructor.
16
     * @param Client $client
17
     * @param string $key
18
     */
19 6
    public function __construct(Client $client, $key)
20
    {
21 6
        $this->client = $client;
22 6
        $this->key = $key;
23 6
        $baseUrl = $this->client->getConfig('base_uri');
24 6
        Validator::notEmpty()
25 6
            ->url()
26 6
            ->endsWith('/')
27 6
            ->setName("URL for NewRelic's Insights API must be valid and have a trailing slash")
28 6
            ->assert($baseUrl);
29 6
    }
30
31
    /**
32
     * @param EventCollection $events
33
     * @return \GuzzleHttp\Promise\PromiseInterface
34
     */
35 6
    public function sendEvent(EventCollection $events)
36
    {
37 6
        $promise = $this->client->postAsync('events', [
38 6
            'body' => json_encode($events),
39
            'headers' => [
40 3
                'X-Insert-Key' => $this->key,
41 3
                'Content-Type' => 'application/json',
42
            ]
43
        ]);
44
45 3
        return $promise;
46
    }
47
}
48