Test Setup Failed
Push — master ( 281bb8...f6d3b0 )
by Neo
22:43 queued 12:54
created

PusherBeams::send()   B

Complexity

Conditions 5
Paths 12

Size

Total Lines 24
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 24
rs 8.5125
cc 5
eloc 15
nc 12
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();
1 ignored issue
show
Bug introduced by
The method pushNotificationInterest() does not seem to exist on object<Illuminate\Notifications\Notification>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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->publish(
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()
1 ignored issue
show
Bug introduced by
The method toPushNotification() does not seem to exist on object<Illuminate\Notifications\Notification>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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();
1 ignored issue
show
Bug introduced by
The method getKey cannot be called on $notifiable (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
74
    }
75
}
76