Sns   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
eloc 22
c 2
b 0
f 0
dl 0
loc 52
ccs 13
cts 13
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A send() 0 34 3
1
<?php
2
3
namespace NotificationChannels\AwsSns;
4
5
use Aws\Exception\AwsException;
6
use Aws\Sns\SnsClient as SnsService;
7
8
class Sns
9
{
10
    /**
11
     * @var SnsService
12
     */
13
    protected $snsService;
14
15 5
    public function __construct(SnsService $snsService)
16
    {
17 5
        $this->snsService = $snsService;
18 5
    }
19
20
    /**
21
     * @param  string  $destination  Phone number as described by the E.164 format.
22
     * @return \Aws\Result
23
     *
24
     * @throws AwsException
25
     */
26
    public function send(SnsMessage $message, $destination)
27 3
    {
28
        $attributes = [
29
            'AWS.SNS.SMS.SMSType' => [
30
                'DataType' => 'String',
31 3
                'StringValue' => $message->getDeliveryType(),
32 3
            ],
33
        ];
34
35
        if (! empty($message->getSender())) {
36 3
            $attributes += [
37
                'AWS.SNS.SMS.SenderID' => [
38
                    'DataType' => 'String',
39 1
                    'StringValue' => $message->getSender(),
40 1
                ],
41
            ];
42
        }
43
44
        if (! empty($message->getOriginationNumber())) {
45
            $attributes += [
46 3
                'AWS.MM.SMS.OriginationNumber' => [
47 3
                    'DataType' => 'String',
48 3
                    'StringValue' => $message->getOriginationNumber(),
49
                ],
50
            ];
51 3
        }
52
53
        $parameters = [
54
            'Message' => $message->getBody(),
55
            'PhoneNumber' => $destination,
56
            'MessageAttributes' => $attributes,
57
        ];
58
59
        return $this->snsService->publish($parameters);
60
    }
61
}
62