NewRelicPostService   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
dl 0
loc 30
c 0
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A makeRequest() 0 9 1
A __construct() 0 4 1
1
<?php
2
3
namespace ErsoyInsider\NewrelicCustomEvent\Services;
4
5
use ErsoyInsider\NewrelicCustomEvent\Models\NewRelicConfig;
6
use Ixudra\Curl\CurlService;
7
8
/**
9
 * Class NewRelicPostService
10
 * @package ErsoyInsider\NewrelicCustomEvent\Services
11
 */
12
class NewRelicPostService
13
{
14
    /**
15
     * @var CurlService
16
     */
17
    private $curlService;
18
    /**
19
     * @var NewRelicConfig
20
     */
21
    private $newRelicConfig;
22
23
    public function __construct(NewRelicConfig $newRelicConfig, CurlService $curlService)
24
    {
25
        $this->curlService = $curlService;
26
        $this->newRelicConfig = $newRelicConfig;
27
    }
28
29
    /**
30
     * @param array $payload
31
     * @return mixed
32
     */
33
    public function makeRequest(array $payload)
34
    {
35
        return $this->curlService
36
            ->to("https://insights-collector.newrelic.com/v1/accounts/{$this->newRelicConfig->getAccountId()}/events")
37
            ->withContentType('application/json')
38
            ->withHeader('X-Insert-Key:' . $this->newRelicConfig->getApiKey())
39
            ->withData($payload)
40
            ->asJson()
41
            ->post();
42
    }
43
}
44