Sns::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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