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
Push — master ( fe092f...f32e18 )
by Cretu
09:19
created

HasPushSubscriptions::ownsPushSubscription()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
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 10
    public function pushSubscriptions()
13
    {
14 10
        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|null $key
22
     * @param  string|null $token
23
     * @param  string|null $contentEncoding
24
     * @return \NotificationChannels\WebPush\PushSubscription
25
     */
26 9
    public function updatePushSubscription($endpoint, $key = null, $token = null, $contentEncoding = null)
27
    {
28 9
        $subscription = app(config('webpush.model'))->findByEndpoint($endpoint);
29
30 9
        if ($subscription && $this->ownsPushSubscription($subscription)) {
31 1
            $subscription->public_key = $key;
32 1
            $subscription->auth_token = $token;
33 1
            $subscription->content_encoding = $contentEncoding;
34 1
            $subscription->save();
35
36 1
            return $subscription;
37
        }
38
39 9
        if ($subscription && ! $this->ownsPushSubscription($subscription)) {
40 1
            $subscription->delete();
41
        }
42
43 9
        return $this->pushSubscriptions()->create([
44 9
            'endpoint' => $endpoint,
45 9
            'public_key' => $key,
46 9
            'auth_token' => $token,
47 9
            'content_encoding' => $contentEncoding,
48
        ]);
49
    }
50
51
    /**
52
     * Determine if the model owns the given subscription.
53
     *
54
     * @param  \NotificationChannels\WebPush\PushSubscription $subscription
55
     * @return bool
56
     */
57 3
    public function ownsPushSubscription($subscription)
58
    {
59 3
        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...
60
                        $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...
61
    }
62
63
    /**
64
     * Delete subscription by endpoint.
65
     *
66
     * @param  string $endpoint
67
     * @return void
68
     */
69
    public function deletePushSubscription($endpoint)
70
    {
71
        $this->pushSubscriptions()
72
            ->where('endpoint', $endpoint)
73
            ->delete();
74
    }
75
76
    /**
77
     * Get all of the subscriptions.
78
     *
79
     * @return \Illuminate\Database\Eloquent\Collection
80 4
     */
81
    public function routeNotificationForWebPush()
82 4
    {
83
        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...
84
    }
85
}
86