Sparkable::spark()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 12
nc 1
nop 2
dl 0
loc 22
rs 9.2
c 1
b 0
f 0
1
<?php
2
3
namespace Brantwladichuk\Sparkify;
4
5
use BrantWladichuk\Sparkify\Jobs\SendSpark;
6
7
trait Sparkable {
8
9
    /**
10
     * Send the email.
11
     *
12
     * @param   string    $template_id
13
     * @param   array     $substituteData
14
     *
15
     * @return void
16
     */
17
    public function spark($template_id, $substituteData = [])
18
    {
19
        $firstNameColumn = config('sparkify.first_name_column');
20
        $lastNameColumn = config('sparkify.last_name_column');
21
        $emailColumn = config('sparkify.email_column');
22
23
        $substituteData['name'] = trim($this->{$firstNameColumn} . ' ' . $this->{$lastNameColumn});
24
25
        $postFields = [
26
            "recipients" => [
27
                [
28
                    "address" => $this->{$emailColumn},
29
                    "substitution_data"=> $substituteData
30
                ]
31
            ],
32
            "content" => [
33
                "template_id" => $template_id
34
            ]
35
        ];
36
37
        dispatch(new SendSpark($postFields));
38
    }
39
}
40