Passed
Push — master ( d57c11...8c6e4f )
by Joao
03:16 queued 36s
created

AmazonSesWrapper   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 1
cbo 5
dl 0
loc 46
ccs 19
cts 19
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getSesClient() 0 12 1
A send() 0 21 1
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
9
class AmazonSesWrapper extends PHPMailerWrapper
10
{
11
    /**
12
     * @return SesClient
13
     */
14 1
    public function getSesClient()
15
    {
16
        //Send the message (which must be base 64 encoded):
17 1
        return new SesClient([
18 1
            'credentials' => new Credentials(
19 1
                $this->uri->getUsername(),
20 1
                $this->uri->getPassword()
21 1
            ),
22 1
            'region' => $this->uri->getHost(),
23
            'version' => '2010-12-01'
24 1
        ]);
25 1
    }
26
27
    /**
28
     * ses://accessid:aswsecret@region
29
     *
30
     * @param Envelope $envelope
31
     * @return bool
32
     */
33 4
    public function send(Envelope $envelope)
34
    {
35 4
        $this->validate($envelope);
36
37 4
        $mail = $this->prepareMailer($envelope);
38
39
        // Call the preSend to set all PHPMailer variables and get the correct header and body;
40 4
        $message = $mail->getFullMessageEnvelope();
41
42 4
        $ses = $this->getSesClient();
43
44 4
        $ses->sendRawEmail(
45
            [
46
                'RawMessage' => [
47 4
                    'Data' => $message,
48
                ]
49 4
            ]
50 4
        );
51
52 4
        return true;
53
    }
54
}
55