Passed
Push — master ( 5e9e3d...710625 )
by Maciej
04:36 queued 11s
created

TransactionalEmailHandler   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Test Coverage

Coverage 61.9%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
c 1
b 0
f 0
dl 0
loc 59
ccs 13
cts 21
cp 0.619
rs 10
wmc 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getApiEndpoint() 0 3 1
B sendTransactionalEmail() 0 33 9
1
<?php
2
/**
3
 * File: TransactionalEmailHandler.php
4
 *
5
 * @author      Maciej Sławik <[email protected]>
6
 * Github:      https://github.com/maciejslawik
7
 */
8
9
namespace MSlwk\FreshMail\Handler\Message;
10
11
use MSlwk\FreshMail\Handler\AbstractHandler;
12
13
class TransactionalEmailHandler extends AbstractHandler
14
{
15
    const API_ENDPOINT = '/rest/mail';
16
17
    /**
18
     * @param string $email
19
     * @param string $subject
20
     * @param string $content
21
     * @param string $fromEmail
22
     * @param string $fromName
23
     * @param string $replyTo
24
     * @param string $encoding
25
     * @param string $attachmentUrl
26
     * @param string $tag
27
     * @param bool $tracking
28
     * @param string $domain
29
     * @return null
30
     */
31 112
    public function sendTransactionalEmail(
32
        string $email,
33
        string $subject,
34
        string $content,
35
        string $fromEmail = '',
36
        string $fromName = '',
37
        string $replyTo = '',
38
        string $encoding = 'UTF-8',
39
        string $attachmentUrl = '',
40
        string $tag = '',
41
        bool $tracking = false,
42
        string $domain = ''
43
    ) {
44 112
        $getParameters = [];
45 32
        $postParameters = [
46 112
            'subscriber' => $email,
47 112
            'subject' => $subject,
48 112
            'html' => $content,
49
            'from' => $fromEmail ?: null,
50
            'from_name' => $fromName ?: null,
51
            'reply_to' => $replyTo ?: null,
52
            'encoding' => $encoding ?: null,
53
            'attachments' => $attachmentUrl ?: null,
54
            'tracking' => $tracking ?: null,
55
            'domain' => $domain ?: null,
56
            'tag' => $tag ?: null
57
        ];
58
59 80
        $postParameters = array_filter($postParameters, function ($value) {
60 112
            return $value !== null;
61 112
        });
62 112
        $this->processRequest($getParameters, $postParameters);
63 7
        return null;
64
    }
65
66
    /**
67
     * @return string
68
     */
69 7
    protected function getApiEndpoint(): string
70
    {
71 7
        return self::API_ENDPOINT;
72
    }
73
}
74