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.
Completed
Pull Request — master (#124)
by
unknown
15:51
created

HasPushSubscriptions::ownsPushSubscription()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
1
<?php
2
3
namespace NotificationChannels\WebPush;
4
5
trait HasPushSubscriptions
6
{
7
    /**
8
     *  Get all of the subscriptions.
9
     *
10
     * @return \Illuminate\Database\Eloquent\Relations\MorphMany
11
     */
12 2
    public function pushSubscriptions()
13
    {
14 2
        return $this->morphMany(config('webpush.model'), 'subscribable');
0 ignored issues
show
Bug introduced by
It seems like morphMany() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
15
    }
16
17
    /**
18
     * Update (or create) subscription.
19
     *
20
     * @param  string $endpoint
21
     * @param  string $endpoint_key
0 ignored issues
show
Documentation introduced by
There is no parameter named $endpoint_key. Did you maybe mean $endpoint?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
22
     * @param  string|null $key
23
     * @param  string|null $token
24
     * @param  string|null $contentEncoding
25
     * @return \NotificationChannels\WebPush\PushSubscription
26
     */
27 2
    public function updatePushSubscription($endpoint, $key = null, $token = null, $contentEncoding = null)
28
    {
29 2
        $subscription = app(config('webpush.model'))->findByEndpoint($endpoint);
30
31 2
        if ($subscription && $this->ownsPushSubscription($subscription)) {
32
            $subscription->public_key = $key;
33
            $subscription->auth_token = $token;
34
            $subscription->content_encoding = $contentEncoding;
35
            $subscription->save();
36
37
            return $subscription;
38
        }
39
40 2
        if ($subscription && ! $this->ownsPushSubscription($subscription)) {
41
            $subscription->delete();
42
        }
43
44 2
        return $this->pushSubscriptions()->create([
45 2
            'endpoint' => $endpoint,
46 2
            'endpoint_key' => md5($endpoint),
47 2
            'public_key' => $key,
48 2
            'auth_token' => $token,
49 2
            'content_encoding' => $contentEncoding,
50
        ]);
51
    }
52
53
    /**
54
     * Determine if the model owns the given subscription.
55
     *
56
     * @param  \NotificationChannels\WebPush\PushSubscription $subscription
57
     * @return bool
58
     */
59
    public function ownsPushSubscription($subscription)
60
    {
61
        return (string) $subscription->subscribable_id === (string) $this->getKey() &&
0 ignored issues
show
Bug introduced by
It seems like getKey() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
62
                        $subscription->subscribable_type === $this->getMorphClass();
0 ignored issues
show
Bug introduced by
It seems like getMorphClass() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
63
    }
64
65
    /**
66
     * Delete subscription by endpoint.
67
     *
68
     * @param  string $endpoint
69
     * @return void
70
     */
71
    public function deletePushSubscription($endpoint)
72
    {
73
        $this->pushSubscriptions()
74
            ->where('endpoint_key', md5($endpoint))
75
            ->delete();
76
    }
77
78
    /**
79
     * Get all of the subscriptions.
80
     *
81
     * @return \Illuminate\Database\Eloquent\Collection
82
     */
83
    public function routeNotificationForWebPush()
84
    {
85
        return $this->pushSubscriptions;
0 ignored issues
show
Bug introduced by
The property pushSubscriptions does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
86
    }
87
}
88