1 | <?php |
||
2 | |||
3 | namespace NotificationChannels\Sendberry; |
||
4 | |||
5 | use Illuminate\Events\Dispatcher; |
||
6 | use Illuminate\Notifications\Events\NotificationFailed; |
||
7 | use NotificationChannels\Sendberry\Exceptions\CouldNotSendNotification; |
||
8 | use Illuminate\Notifications\Notification; |
||
9 | use Exception; |
||
10 | |||
11 | class SendberryChannel |
||
12 | { |
||
13 | /** |
||
14 | * @var TurboSmsApi |
||
15 | */ |
||
16 | protected $smsApi; |
||
17 | |||
18 | /** |
||
19 | * @var Dispatcher |
||
20 | */ |
||
21 | protected $events; |
||
22 | |||
23 | /** |
||
24 | * SendberryChannel constructor. |
||
25 | * @param TurboSmsApi $smsApi |
||
26 | * @param Dispatcher $events |
||
27 | */ |
||
28 | public function __construct(SendberryApi $smsApi, Dispatcher $events) |
||
29 | { |
||
30 | $this->smsApi = $smsApi; |
||
0 ignored issues
–
show
|
|||
31 | $this->events = $events; |
||
32 | } |
||
33 | /** |
||
34 | * Send the given notification. |
||
35 | * |
||
36 | * @param mixed $notifiable |
||
37 | * @param Notification $notification |
||
38 | * |
||
39 | * @throws CouldNotSendNotification |
||
40 | * |
||
41 | * @return array|null |
||
42 | */ |
||
43 | public function send($notifiable, Notification $notification) |
||
44 | { |
||
45 | try { |
||
46 | $recipient = $this->getRecipient($notifiable); |
||
47 | $message = $notification->toSendberry($notifiable); |
||
48 | |||
49 | if (is_string($message)) { |
||
50 | $message = new SendberryMessage($message); |
||
51 | } |
||
52 | if (! $message instanceof SendberryMessage) { |
||
53 | throw CouldNotSendNotification::invalidMessageObject($message); |
||
54 | } |
||
55 | return $this->smsApi->sendMessage($recipient, $message); |
||
56 | |||
57 | } catch (Exception $exception) { |
||
58 | $event = new NotificationFailed($notifiable, $notification, 'Sendberry', ['message' => $exception->getMessage(), 'exception' => $exception]); |
||
59 | |||
60 | if (function_exists('event')) { // Use event helper when possible to add Lumen support |
||
61 | event($event); |
||
62 | } else { |
||
63 | $this->events->fire($event); |
||
64 | } |
||
65 | } |
||
66 | } |
||
67 | |||
68 | protected function getRecipient($notifiable) |
||
69 | { |
||
70 | if ($notifiable->routeNotificationFor('Sendberry')) { |
||
71 | return $notifiable->routeNotificationFor('Sendberry'); |
||
72 | } |
||
73 | |||
74 | if (isset($notifiable->phone)) { |
||
75 | return $notifiable->phone; |
||
76 | } |
||
77 | |||
78 | throw CouldNotSendNotification::invalidReceiver(); |
||
79 | } |
||
80 | } |
||
81 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..