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\PusherPushNotifications; |
||
4 | |||
5 | use Pusher; |
||
6 | use Illuminate\Events\Dispatcher; |
||
7 | use Illuminate\Notifications\Notification; |
||
8 | use Illuminate\Notifications\Events\NotificationFailed; |
||
9 | |||
10 | class PusherChannel |
||
11 | { |
||
12 | /** |
||
13 | * @var \Pusher |
||
14 | */ |
||
15 | protected $pusher; |
||
16 | |||
17 | /** |
||
18 | * @var \Illuminate\Events\Dispatcher |
||
19 | */ |
||
20 | private $events; |
||
21 | |||
22 | /** |
||
23 | * @param \Pusher $pusher |
||
24 | */ |
||
25 | 2 | public function __construct(Pusher $pusher, Dispatcher $events) |
|
26 | { |
||
27 | 2 | $this->pusher = $pusher; |
|
28 | 2 | $this->events = $events; |
|
29 | 2 | } |
|
30 | |||
31 | /** |
||
32 | * Send the given notification. |
||
33 | * |
||
34 | * @param mixed $notifiable |
||
35 | * @param \Illuminate\Notifications\Notification $notification |
||
36 | * |
||
37 | * @return void |
||
38 | */ |
||
39 | 2 | public function send($notifiable, Notification $notification) |
|
40 | { |
||
41 | 2 | $interest = $notifiable->routeNotificationFor('PusherPushNotifications') |
|
42 | 2 | ?: $this->interestName($notifiable); |
|
43 | |||
44 | 2 | $response = $this->pusher->notify( |
|
45 | 2 | $interest, |
|
46 | 2 | $notification->toPushNotification($notifiable)->toArray(), |
|
47 | true |
||
48 | 2 | ); |
|
49 | |||
50 | 2 | if (! in_array($response['status'], [200, 202])) { |
|
51 | 1 | $this->events->fire( |
|
52 | 1 | new NotificationFailed($notifiable, $notification, 'pusher-push-notifications', $response) |
|
0 ignored issues
–
show
|
|||
53 | 1 | ); |
|
54 | 1 | } |
|
55 | 2 | } |
|
56 | |||
57 | /** |
||
58 | * Get the interest name for the notifiable. |
||
59 | * |
||
60 | * @param $notifiable |
||
61 | * |
||
62 | * @return string |
||
63 | */ |
||
64 | protected function interestName($notifiable) |
||
65 | { |
||
66 | $class = str_replace('\\', '.', get_class($notifiable)); |
||
67 | |||
68 | return $class.'.'.$notifiable->getKey(); |
||
69 | } |
||
70 | } |
||
71 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.