Conditions | 5 |
Paths | 7 |
Total Lines | 42 |
Code Lines | 27 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 30 |
Changes | 0 |
1 | <?php |
||
38 | public function send(string $to, string $message) |
||
39 | { |
||
40 | try { |
||
41 | if (empty($this->sender)) { |
||
42 | return [ |
||
43 | 'error' => 'Error sending SMS: Unknown error', |
||
44 | 'sent' => false, |
||
45 | ]; |
||
46 | } |
||
47 | |||
48 | $data = $this->client->publish([ |
||
49 | 'Message' => $message, |
||
50 | 'PhoneNumber' => $to, |
||
51 | 'MessageAttributes' => [ |
||
52 | 'AWS.SNS.SMS.SenderID' => [ |
||
53 | 'DataType' => 'String', |
||
54 | 'StringValue' => $this->sender |
||
55 | ], |
||
56 | 'AWS.SNS.SMS.SMSType' => [ |
||
57 | 'DataType' => 'String', |
||
58 | 'StringValue' => 'Transactional', |
||
59 | ] |
||
60 | ] |
||
61 | ]); |
||
62 | |||
63 | $data = $data->toArray(); |
||
64 | |||
65 | if (empty($data) || empty($data['MessageId'])) { |
||
66 | return [ |
||
67 | 'error' => 'Error sending SMS: Unknown error', |
||
68 | 'sent' => false, |
||
69 | ]; |
||
70 | } |
||
71 | |||
72 | return [ |
||
73 | 'message_id' => $data['MessageId'], |
||
74 | 'sent' => true, |
||
75 | ]; |
||
76 | } catch (\Exception $e) { |
||
77 | return [ |
||
78 | 'error' => 'Error sending SMS: ' . $e->getMessage(), |
||
79 | 'sent' => false, |
||
80 | ]; |
||
97 | } |