| Conditions | 5 |
| Paths | 11 |
| Total Lines | 32 |
| Code Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 17 |
| CRAP Score | 5.1727 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 26 | 4 | public function send($notifiable, Notification $notification): ?Response |
|
| 27 | { |
||
| 28 | // @phpstan-ignore-next-line |
||
| 29 | 4 | $message = $notification->toWhatsApp($notifiable); |
|
|
|
|||
| 30 | |||
| 31 | 4 | if (! $message->hasRecipient()) { |
|
| 32 | 2 | $to = $notifiable->routeNotificationFor('whatsapp', $notification) |
|
| 33 | 2 | ?? $notifiable->routeNotificationFor(self::class, $notification); |
|
| 34 | |||
| 35 | 2 | if (! $to) { |
|
| 36 | 1 | return null; |
|
| 37 | } |
||
| 38 | |||
| 39 | 1 | $message->to($to); |
|
| 40 | } |
||
| 41 | |||
| 42 | try { |
||
| 43 | 3 | if ($message->type() === 'text') { |
|
| 44 | return $this->whatsapp->sendTextMessage( |
||
| 45 | $message->recipient(), |
||
| 46 | $message->getMessage() |
||
| 47 | ); |
||
| 48 | } |
||
| 49 | |||
| 50 | 3 | return $this->whatsapp->sendTemplate( |
|
| 51 | 3 | $message->recipient(), |
|
| 52 | 3 | $message->configuredName(), |
|
| 53 | 3 | $message->configuredLanguage(), |
|
| 54 | 3 | $message->components() |
|
| 55 | 3 | ); |
|
| 56 | 1 | } catch (ResponseException $e) { |
|
| 57 | 1 | throw CouldNotSendNotification::serviceRespondedWithAnError($e->response()->body()); |
|
| 58 | } |
||
| 61 |