| Conditions | 5 |
| Paths | 7 |
| Total Lines | 43 |
| 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 | |||
| 42 | if (empty($this->sender)) { |
||
| 43 | return [ |
||
| 44 | 'error' => 'Error sending SMS: Unknown error', |
||
| 45 | 'sent' => false, |
||
| 46 | ]; |
||
| 47 | } |
||
| 48 | |||
| 49 | $data = $this->client->publish([ |
||
| 50 | 'Message' => $message, |
||
| 51 | 'PhoneNumber' => '+' . $to, |
||
| 52 | 'MessageAttributes' => [ |
||
| 53 | 'AWS.SNS.SMS.SenderID' => [ |
||
| 54 | 'DataType' => 'String', |
||
| 55 | 'StringValue' => $this->sender |
||
| 56 | ], |
||
| 57 | 'AWS.SNS.SMS.SMSType' => [ |
||
| 58 | 'DataType' => 'String', |
||
| 59 | 'StringValue' => 'Transactional', |
||
| 60 | ] |
||
| 61 | ] |
||
| 62 | ]); |
||
| 63 | |||
| 64 | $data = $data->toArray(); |
||
| 65 | |||
| 66 | if (empty($data) || empty($data['MessageId'])) { |
||
| 67 | return [ |
||
| 68 | 'error' => 'Error sending SMS: Unknown error', |
||
| 69 | 'sent' => false, |
||
| 70 | ]; |
||
| 71 | } |
||
| 72 | |||
| 73 | return [ |
||
| 74 | 'message_id' => $data['MessageId'], |
||
| 75 | 'sent' => true, |
||
| 76 | ]; |
||
| 77 | } catch (\Exception $e) { |
||
| 78 | return [ |
||
| 79 | 'error' => 'Error sending SMS: ' . $e->getMessage(), |
||
| 80 | 'sent' => false, |
||
| 81 | ]; |
||
| 100 | } |