Passed
Pull Request — master (#6)
by
unknown
03:19
created

SendTemplate::success()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
namespace Slides\Connector\Auth\Clients\Mandrill\Requests;
4
5
use Illuminate\Support\Arr;
6
use Slides\Connector\Auth\Clients\AbstractRequest;
7
8
/**
9
 * Class SendTemplate
10
 *
11
 * @property string $template
12
 * @property array $recipients
13
 * @property array $variables
14
 * @property array $from
15
 * @property string $subject
16
 *
17
 * @package Slides\Connector\Auth\Clients\Mandrill\Requests
18
 */
19
class SendTemplate extends AbstractRequest
20
{
21
    /**
22
     * HTTP method
23
     *
24
     * @var string
25
     */
26
    protected $method = 'post';
27
28
    /**
29
     * Request URI
30
     *
31
     * @var string
32
     */
33
    protected $uri = 'messages/send-template.json';
34
35
    /**
36
     * Validate a response
37
     *
38
     * @return bool
39
     */
40
    public function success(): bool
41
    {
42
        return $this->client->getResponse()->getStatusCode() === 200;
43
    }
44
45
    /**
46
     * Compose a request
47
     *
48
     * @return void
49
     */
50
    public function compose()
51
    {
52
        $optional = [
53
            'from_email' => Arr::get($this->from, 'email'),
54
            'from_name' => Arr::get($this->from, 'name'),
55
            'subject' => $this->subject,
56
        ];
57
58
        $this->body([
59
            'template_name' => $this->template,
60
            'template_content' => [],
61
            'message' => [
62
                    'preserve_recipients' => false,
63
                    'track_opens' => true,
64
                    'track_clicks' => true,
65
                    'to' => $this->recipients,
66
                    'merge_vars' => $this->variables,
67
                    'merge_language' => 'handlebars'
68
                ] + array_filter($optional)
69
        ]);
70
    }
71
}