GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

WebPushChannel   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 93.55%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 5
dl 0
loc 91
ccs 29
cts 31
cp 0.9355
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A send() 0 28 3
A handleReports() 0 9 4
A findSubscription() 0 8 3
1
<?php
2
3
namespace NotificationChannels\WebPush;
4
5
use Illuminate\Notifications\Notification;
6
use Minishlink\WebPush\Subscription;
7
use Minishlink\WebPush\WebPush;
8
9
class WebPushChannel
10
{
11
    /**
12
     * @var \Minishlink\WebPush\WebPush
13
     */
14
    protected $webPush;
15
16
    /**
17
     * @var \NotificationChannels\WebPush\ReportHandlerInterface
18
     */
19
    protected $reportHandler;
20
21
    /**
22
     * @param  \Minishlink\WebPush\WebPush $webPush
23
     * @param  \NotificationChannels\WebPush\ReportHandlerInterface $webPush
24
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
25
     */
26 2
    public function __construct(WebPush $webPush, ReportHandlerInterface $reportHandler)
27
    {
28 2
        $this->webPush = $webPush;
29 2
        $this->reportHandler = $reportHandler;
30 2
    }
31
32
    /**
33
     * Send the given notification.
34
     *
35
     * @param  mixed $notifiable
36
     * @param  \Illuminate\Notifications\Notification $notification
37
     * @return void
38
     */
39 2
    public function send($notifiable, Notification $notification)
40
    {
41
        /** @var \Illuminate\Database\Eloquent\Collection $subscriptions */
42 2
        $subscriptions = $notifiable->routeNotificationFor('WebPush', $notification);
43
44 2
        if (empty($subscriptions)) {
45
            return;
46
        }
47
48
        /** @var \NotificationChannels\WebPush\WebPushMessage $message */
49 2
        $message = $notification->toWebPush($notifiable, $notification);
0 ignored issues
show
Bug introduced by
The method toWebPush() 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...
50 2
        $payload = json_encode($message->toArray());
51 2
        $options = $message->getOptions();
52
53
        /** @var \NotificationChannels\WebPush\PushSubscription $subscription */
54 2
        foreach ($subscriptions as $subscription) {
55 2
            $this->webPush->queueNotification(new Subscription(
56 2
                $subscription->endpoint,
57 2
                $subscription->public_key,
58 2
                $subscription->auth_token,
59 2
                $subscription->content_encoding
60 2
            ), $payload, $options);
61
        }
62
63 2
        $reports = $this->webPush->flush();
64
65 2
        $this->handleReports($reports, $subscriptions, $message);
66 2
    }
67
68
    /**
69
     * Handle the reports.
70
     *
71
     * @param  \Generator $reports
72
     * @param  \Illuminate\Database\Eloquent\Collection $subscriptions
73
     * @param  \NotificationChannels\WebPush\WebPushMessage $message
74
     * @return void
75
     */
76 2
    protected function handleReports($reports, $subscriptions, $message)
77
    {
78
        /** @var \Minishlink\WebPush\MessageSentReport $report */
79 2
        foreach ($reports as $report) {
80 2
            if ($report && $subscription = $this->findSubscription($subscriptions, $report)) {
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $subscription is correct as $this->findSubscription($subscriptions, $report) (which targets NotificationChannels\Web...nel::findSubscription()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
81 2
                $this->reportHandler->handleReport($report, $subscription, $message);
82
            }
83
        }
84 2
    }
85
86
    /**
87
     * @param \Illuminate\Database\Eloquent\Collection $subscriptions
88
     * @param \Minishlink\WebPush\MessageSentReport $report
89
     * @return void
90
     */
91 2
    protected function findSubscription($subscriptions, $report)
92
    {
93 2
        foreach ($subscriptions as $subscription) {
94 2
            if ($subscription->endpoint === $report->getEndpoint()) {
95 2
                return $subscription;
96
            }
97
        }
98
    }
99
}
100