These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace NotificationChannels\Plivo; |
||
4 | |||
5 | use Illuminate\Notifications\Notification; |
||
6 | use NotificationChannels\Plivo\Exceptions\CouldNotSendNotification; |
||
7 | |||
8 | class PlivoChannel |
||
9 | { |
||
10 | /** |
||
11 | * @var \NotificationChannels\Plivo\Plivo; |
||
12 | */ |
||
13 | protected $plivo; |
||
14 | |||
15 | /** |
||
16 | * The phone number notifications should be sent from. |
||
17 | * |
||
18 | * @var string |
||
19 | */ |
||
20 | protected $from; |
||
21 | |||
22 | /** |
||
23 | * @return void |
||
0 ignored issues
–
show
|
|||
24 | */ |
||
25 | public function __construct(Plivo $plivo) |
||
26 | { |
||
27 | $this->plivo = $plivo; |
||
28 | $this->from = $this->plivo->from(); |
||
29 | } |
||
30 | |||
31 | /** |
||
32 | * Send the given notification. |
||
33 | * |
||
34 | * @param mixed $notifiable |
||
35 | * @param \Illuminate\Notifications\Notification $notification |
||
36 | * |
||
37 | * @throws \NotificationChannels\Plivo\Exceptions\CouldNotSendNotification |
||
38 | */ |
||
39 | public function send($notifiable, Notification $notification) |
||
40 | { |
||
41 | if (! $to = $notifiable->routeNotificationFor('plivo')) { |
||
42 | return; |
||
43 | } |
||
44 | |||
45 | $message = $notification->toPlivo($notifiable); |
||
46 | |||
47 | if (is_string($message)) { |
||
48 | $message = new PlivoMessage($message); |
||
49 | } |
||
50 | |||
51 | $response = $this->plivo->send_message([ |
||
52 | 'src' => $message->from ?: $this->from, |
||
53 | 'dst' => $to, |
||
54 | 'text' => trim($message->content), |
||
55 | ]); |
||
56 | |||
57 | if ($response['status'] !== 202) { |
||
58 | throw CouldNotSendNotification::serviceRespondedWithAnError($response); |
||
59 | } |
||
60 | |||
61 | return $response; |
||
62 | } |
||
63 | } |
||
64 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.