1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace NotificationChannels\PusherPushNotifications; |
4
|
|
|
|
5
|
|
|
use Illuminate\Events\Dispatcher; |
6
|
|
|
use Illuminate\Notifications\Notification; |
7
|
|
|
use Illuminate\Notifications\Events\NotificationFailed; |
8
|
|
|
use Pusher\PushNotifications\PushNotifications; |
9
|
|
|
|
10
|
|
|
class PusherChannel |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var \Pusher\PushNotifications\PushNotifications $pusher |
14
|
|
|
*/ |
15
|
|
|
protected $pusher; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var \Illuminate\Events\Dispatcher |
19
|
|
|
*/ |
20
|
|
|
private $events; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @param \Pusher\PushNotifications\PushNotifications $pusher |
24
|
|
|
* @param \Illuminate\Events\Dispatcher |
25
|
|
|
*/ |
26
|
2 |
|
public function __construct(PushNotifications $pusher, Dispatcher $events) |
27
|
|
|
{ |
28
|
2 |
|
$this->pusher = $pusher; |
29
|
2 |
|
$this->events = $events; |
30
|
2 |
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Send the given notification. |
34
|
|
|
* |
35
|
|
|
* @param mixed $notifiable |
36
|
|
|
* @param \Illuminate\Notifications\Notification $notification |
37
|
|
|
* |
38
|
|
|
* @return void |
39
|
|
|
*/ |
40
|
2 |
|
public function send($notifiable, Notification $notification) |
41
|
|
|
{ |
42
|
2 |
|
$interest = $notifiable->routeNotificationFor('PusherPushNotifications') |
43
|
2 |
|
?: $this->interestName($notifiable); |
44
|
|
|
|
45
|
2 |
|
if(is_string($interest)) { |
46
|
2 |
|
$interest = [$interest]; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
try { |
50
|
2 |
|
$response = $this->pusher->publish( |
|
|
|
|
51
|
2 |
|
$interest, |
52
|
2 |
|
$notification->toPushNotification($notifiable)->toArray() |
|
|
|
|
53
|
|
|
); |
54
|
1 |
|
}catch (\Exception $e) { |
55
|
1 |
|
$this->events->fire( |
56
|
1 |
|
new NotificationFailed($notifiable, $notification, 'pusher-push-notifications') |
57
|
|
|
); |
58
|
|
|
} |
59
|
2 |
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Get the interest name for the notifiable. |
63
|
|
|
* |
64
|
|
|
* @param $notifiable |
65
|
|
|
* |
66
|
|
|
* @return string |
67
|
|
|
*/ |
68
|
|
|
protected function interestName($notifiable) |
69
|
|
|
{ |
70
|
|
|
$class = str_replace('\\', '.', get_class($notifiable)); |
71
|
|
|
|
72
|
|
|
return $class.'.'.$notifiable->getKey(); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.