Test Failed
Push — master ( dde8d6...f259e6 )
by Richard
06:46 queued 24s
created

PusherBeams::send()   B

Complexity

Conditions 6
Paths 30

Size

Total Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 8.8017
c 0
b 0
f 0
cc 6
nc 30
nop 2
1
<?php
2
3
namespace Rich2k\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();
0 ignored issues
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
            if (method_exists($this->beams, 'publishToInterests')) {
53
                $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...
54
                    $interest,
55
                    $notification->toPusherBeamsNotification($notifiable)->toArray()
0 ignored issues
show
Bug introduced by
The method toPusherBeamsNotification() 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...
56
                );
57
            } else {
58
                $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...
59
                    $interest,
60
                    $notification->toPusherBeamsNotification($notifiable)->toArray()
0 ignored issues
show
Bug introduced by
The method toPusherBeamsNotification() 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...
61
                );
62
            }
63
        } catch (\Exception $e) {
64
            $this->events->fire(
65
                new NotificationFailed($notifiable, $notification, 'pusher-beams')
66
            );
67
        }
68
    }
69
70
    /**
71
     * Get the interest name for the notifiable.
72
     *
73
     * @param  string $notifiable
74
     * @return string
75
     */
76
    protected function interestName($notifiable)
77
    {
78
        $class = str_replace('\\', '.', get_class($notifiable));
79
80
        return $class . '.' . $notifiable->getKey();
0 ignored issues
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...
81
    }
82
}
83