Insights   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A sendEvent() 0 12 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