SendSpark   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 43
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B handle() 0 31 2
1
<?php
2
3
namespace Brantwladichuk\Sparkify\Jobs;
4
5
use Illuminate\Bus\Queueable;
6
use Illuminate\Queue\SerializesModels;
7
use Illuminate\Queue\InteractsWithQueue;
8
use Illuminate\Contracts\Queue\ShouldQueue;
9
use Log;
10
11
class SendSpark implements ShouldQueue
12
{
13
    use InteractsWithQueue, Queueable, SerializesModels;
14
15
    private $postFields;
16
17
    public function __construct($postFields)
18
    {
19
        $this->postFields = $postFields;
20
    }
21
22
    public function handle()
23
    {
24
        $curl = curl_init();
25
26
        curl_setopt_array($curl, [
27
            CURLOPT_URL => "https://api.sparkpost.com/api/v1/transmissions",
28
            CURLOPT_RETURNTRANSFER => true,
29
            CURLOPT_ENCODING => "",
30
            CURLOPT_MAXREDIRS => 10,
31
            CURLOPT_TIMEOUT => 30,
32
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
33
            CURLOPT_CUSTOMREQUEST => "POST",
34
            CURLOPT_POSTFIELDS => json_encode($this->postFields),
35
            CURLOPT_HTTPHEADER => [
36
                "accept: application/json",
37
                "authorization: " . config('sparkify.sparkpost_api_key'),
38
                "cache-control: no-cache",
39
                "content-type: application/json"
40
            ]
41
        ]);
42
43
        curl_exec($curl);
44
45
        $error = curl_error($curl);
46
47
        curl_close($curl);
48
49
        if ($error) {
50
            Log::error("cURL Error: " . $error);
51
        }
52
    }
53
}
54