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 ( cdb1b9...55c78e )
by Cretu
09:06
created

pushSubscriptionBelongsToUser()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace NotificationChannels\WebPush;
4
5
trait HasPushSubscriptions
6
{
7
    /**
8
     * Get the user's subscriptions.
9
     *
10
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
11
     */
12
    public function pushSubscriptions()
13
    {
14
        return $this->hasMany(PushSubscription::class);
0 ignored issues
show
Bug introduced by
It seems like hasMany() 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) user subscription.
19
     *
20
     * @param  string $endpoint
21
     * @param  string|null $key
22
     * @param  string|null $token
23
     * @return \NotificationChannels\WebPush\PushSubscription
24
     */
25
    public function updatePushSubscription($endpoint, $key = null, $token = null)
26
    {
27
        $subscription = PushSubscription::findByEndpoint($endpoint);
28
29
        if ($subscription && $this->pushSubscriptionBelongsToUser($subscription)) {
30
            $subscription->public_key = $key;
0 ignored issues
show
Documentation introduced by
The property public_key does not exist on object<NotificationChann...bPush\PushSubscription>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
31
            $subscription->auth_token = $token;
0 ignored issues
show
Documentation introduced by
The property auth_token does not exist on object<NotificationChann...bPush\PushSubscription>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
32
            $subscription->save();
33
34
            return $subscription;
35
        }
36
37
        if ($subscription && ! $this->pushSubscriptionBelongsToUser($subscription)) {
38
            $subscription->delete();
39
        }
40
41
        return $this->pushSubscriptions()->save(new PushSubscription([
42
            'endpoint' => $endpoint,
43
            'public_key' => $key,
44
            'auth_token' => $token,
45
        ]));
46
    }
47
48
    /**
49
     * Determine if the given subscription belongs to this user.
50
     *
51
     * @param  \NotificationChannels\WebPush\PushSubscription $subscription
52
     * @return bool
53
     */
54
    public function pushSubscriptionBelongsToUser($subscription)
55
    {
56
        return (int) $subscription->user_id === (int) $this->getAuthIdentifier();
0 ignored issues
show
Documentation introduced by
The property user_id does not exist on object<NotificationChann...bPush\PushSubscription>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Bug introduced by
It seems like getAuthIdentifier() 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...
57
    }
58
59
    /**
60
     * Delete subscription by endpoint.
61
     *
62
     * @param  string $endpoint
63
     * @return void
64
     */
65
    public function deletePushSubscription($endpoint)
66
    {
67
        $this->pushSubscriptions()
68
            ->where('endpoint', $endpoint)
69
            ->delete();
70
    }
71
72
    /**
73
     * Get all subscriptions.
74
     *
75
     * @return \Illuminate\Database\Eloquent\Collection
76
     */
77
    public function routeNotificationForWebPush()
78
    {
79
        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...
80
    }
81
}
82