Insights::sendEvent()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 12
c 0
b 0
f 0
ccs 6
cts 6
cp 1
rs 9.4285
cc 1
eloc 7
nc 1
nop 1
crap 1
1
<?php
2
3
namespace EasyTaxi\NewRelic;
4
5
use GuzzleHttp\Client;
6
use EasyTaxi\NewRelic\Entity\Insights\EventCollection;
7
use Respect\Validation\Validator;
8
9
class Insights
10
{
11
    private $key;
12
    private $client;
13
14 6
    public function __construct(Client $client, $key)
15
    {
16 6
        $this->client = $client;
17 6
        $this->key = $key;
18 6
        $baseUrl = $this->client->getConfig('base_uri');
19 6
        Validator::notEmpty()
20 6
            ->url()
21 6
            ->endsWith('/')
22 6
            ->setName("URL for NewRelic's Insights API must be valid and have a trailing slash")
23 6
            ->assert($baseUrl);
24 6
    }
25
26 6
    public function sendEvent(EventCollection $events)
27
    {
28 6
        $promise = $this->client->postAsync('events', [
29 6
            'body' => json_encode($events),
30
            'headers' => [
31 3
                'X-Insert-Key' => $this->key,
32 3
                'Content-Type' => 'application/json',
33
            ]
34
        ]);
35
36 3
        return $promise;
37
    }
38
}
39