AmazonSesWrapper::send()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 1

Importance

Changes 4
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
c 4
b 0
f 0
nc 1
nop 1
dl 0
loc 20
ccs 13
cts 13
cp 1
crap 1
rs 10
1
<?php
2
3
namespace ByJG\Mail\Wrapper;
4
5
use Aws\Credentials\Credentials;
6
use Aws\Ses\SesClient;
7
use ByJG\Mail\Envelope;
8
use ByJG\Mail\Exception\InvalidEMailException;
9
use ByJG\Mail\Exception\InvalidMessageFormatException;
10
11
class AmazonSesWrapper extends PHPMailerWrapper
12
{
13
14 1
    public static function schema()
15
    {
16 1
        return ['ses'];
17
    }
18
19
    /**
20
     * @return SesClient
21
     */
22 1
    public function getSesClient()
23
    {
24
        //Send the message (which must be base 64 encoded):
25 1
        return new SesClient([
26 1
            'credentials' => new Credentials(
27 1
                $this->uri->getUsername(),
28 1
                $this->uri->getPassword()
29 1
            ),
30 1
            'region' => $this->uri->getHost(),
31 1
            'version' => '2010-12-01'
32 1
        ]);
33
    }
34
35
    /**
36
     * ses://accessid:aswsecret@region
37
     *
38
     * @param Envelope $envelope
39
     * @return bool
40
     * @throws InvalidEMailException
41
     * @throws InvalidMessageFormatException
42
     * @throws \PHPMailer\PHPMailer\Exception
43
     */
44 4
    public function send(Envelope $envelope)
45
    {
46 4
        $this->validate($envelope);
47
48 4
        $mail = $this->prepareMailer($envelope);
49
50
        // Call the preSend to set all PHPMailer variables and get the correct header and body;
51 4
        $message = $mail->getFullMessageEnvelope();
52
53 4
        $ses = $this->getSesClient();
54
55 4
        $ses->sendRawEmail(
56 4
            [
57 4
                'RawMessage' => [
58 4
                    'Data' => $message,
59 4
                ]
60 4
            ]
61 4
        );
62
63 4
        return true;
64
    }
65
}
66