PusherBeams::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Neo\PusherBeams;
4
5
use Illuminate\Events\Dispatcher;
6
use Illuminate\Notifications\Events\NotificationFailed;
7
use Illuminate\Notifications\Notification;
8
use Pusher\PushNotifications\PushNotifications;
9
10
class PusherBeams
11
{
12
    /**
13
     * @var \Pusher\PushNotifications\PushNotifications
14
     */
15
    protected $beams;
16
17
    /**
18
     * @param \Pusher\PushNotifications\PushNotifications $beams
19
     * @param \Illuminate\Events\Dispatcher $events
20
     */
21
    public function __construct(PushNotifications $beams, Dispatcher $events)
22
    {
23
        $this->beams = $beams;
24
        $this->events = $events;
25
    }
26
27
    /**
28
     * @var \Illuminate\Events\Dispatcher
29
     */
30
    protected $events;
31
32
    /**
33
     * Send the given notification.
34
     *
35
     * @param mixed $notifiable
36
     * @param \Illuminate\Notifications\Notification $notification
37
     */
38
    public function send($notifiable, Notification $notification)
39
    {
40
        if (method_exists($notification, 'pushNotificationInterest')) {
41
            $interest = $notification->pushNotificationInterest();
42
        } else {
43
            $interest = $notifiable->routeNotificationFor('PusherBeams')
44
                ?: $this->interestName($notifiable);
45
        }
46
47
        if (is_string($interest)) {
48
            $interest = [$interest];
49
        }
50
51
        try {
52
            $response = $this->beams->publishToInterests(
0 ignored issues
show
Unused Code introduced by
$response is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
53
                $interest,
54
                $notification->toPushNotification($notifiable)->toArray()
55
            );
56
        } catch (\Exception $e) {
57
            $this->events->fire(
58
                new NotificationFailed($notifiable, $notification, 'pusher-beams')
59
            );
60
        }
61
    }
62
63
    /**
64
     * Get the interest name for the notifiable.
65
     *
66
     * @param  string $notifiable
67
     * @return string
68
     */
69
    protected function interestName($notifiable)
70
    {
71
        $class = str_replace('\\', '.', get_class($notifiable));
72
73
        return $class . '.' . $notifiable->getKey();
74
    }
75
}
76