AwsPinpointClient   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 57
ccs 0
cts 32
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A send() 0 33 4
1
<?php
2
3
namespace NotificationChannels\AwsPinpoint;
4
5
use Aws\AwsClient;
6
use NotificationChannels\AwsPinpoint\Events\DeliveryFailed;
7
use NotificationChannels\AwsPinpoint\Events\DeliverySuccess;
8
use NotificationChannels\AwsPinpoint\Exceptions\CouldNotSendNotification;
9
10
class AwsPinpointClient
11
{
12
    /**
13
     * @var AwsClient
14
     */
15
    protected $client;
16
17
    /**
18
     * Create a AwsPinpointClient instance.
19
     *
20
     * @param AwsClient $client
21
     */
22
    public function __construct(AwsClient $client = null)
23
    {
24
        $this->client = $client;
25
    }
26
27
    /**
28
     * Send the Message.
29
     *
30
     * @param AwsPinpointSmsMessage $message
31
     * @throws CouldNotSendNotification
32
     */
33
    public function send(AwsPinpointSmsMessage $message)
34
    {
35
        try {
36
            $result = $this->client->sendMessages([
37
                'ApplicationId' => config('aws.Pinpoint.application_id'),
38
                'MessageRequest' => [
39
                    'Addresses' => $message->recipients,
40
                    'MessageConfiguration' => [
41
                        'SMSMessage' => [
42
                            'Body' => $message->body,
43
                            'MessageType' => $message->messageType,
44
                            'SenderId' => config('aws.Pinpoint.sender_id'),
45
                        ],
46
                    ],
47
                ],
48
            ]);
49
50
            $output = $result->get('MessageResponse');
51
52
            foreach ($output['Result'] as $number => $res) {
53
                if ($res['DeliveryStatus'] === 'SUCCESSFUL') {
54
                    // Trigger event for successful deliveries
55
                    event(new DeliverySuccess($number, $message->body, $res['StatusMessage']));
56
                    continue;
57
                }
58
59
                // Trigger event for failed deliveries
60
                event(new DeliveryFailed($number, $message->body, $res['StatusMessage']));
61
            }
62
        } catch (Exception $exception) {
0 ignored issues
show
Bug introduced by
The class NotificationChannels\AwsPinpoint\Exception does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
63
            throw CouldNotSendNotification::serviceRespondedWithAnError($exception);
64
        }
65
    }
66
}
67