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.

Revision::scopeWhereUser()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Neurony\Revisions\Models;
4
5
use Illuminate\Contracts\Auth\Authenticatable;
6
use Illuminate\Database\Eloquent\Builder;
7
use Illuminate\Database\Eloquent\Model;
8
use Neurony\Revisions\Contracts\RevisionModelContract;
9
10
class Revision extends Model implements RevisionModelContract
11
{
12
    /**
13
     * The database table.
14
     *
15
     * @var string
16
     */
17
    protected $table = 'revisions';
18
19
    /**
20
     * The attributes that are mass assignable.
21
     *
22
     * @var array
23
     */
24
    protected $fillable = [
25
        'user_id',
26
        'revisionable_id',
27
        'revisionable_type',
28
        'metadata',
29
    ];
30
31
    /**
32
     * The attributes that are casted to a specific type.
33
     *
34
     * @var array
35
     */
36
    protected $casts = [
37
        'metadata' => 'array',
38
    ];
39
40
    /**
41
     * Revision belongs to user.
42
     *
43
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
44
     */
45
    public function user()
46
    {
47
        $user = config('revisions.user_model', null);
48
49
        if ($user && class_exists($user)) {
50
            return $this->belongsTo($user, 'user_id');
51
        }
52
    }
53
54
    /**
55
     * Get all of the owning revisionable models.
56
     *
57
     * @return \Illuminate\Database\Eloquent\Relations\MorphTo
58
     */
59
    public function revisionable()
60
    {
61
        return $this->morphTo();
62
    }
63
64
    /**
65
     * Filter the query by the given user id.
66
     *
67
     * @param Builder $query
68
     * @param Authenticatable|int $user
69
     */
70
    public function scopeWhereUser($query, Authenticatable $user): void
71
    {
72
        $query->where('user_id', $user->id);
0 ignored issues
show
Bug introduced by
Accessing id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
73
    }
74
75
    /**
76
     * Filter the query by the given revisionable params (id, type).
77
     *
78
     * @param Builder $query
79
     * @param int $id
80
     * @param string $type
81
     */
82
    public function scopeWhereRevisionable($query, int $id, string $type)
83
    {
84
        $query->where([
85
            'revisionable_id' => $id,
86
            'revisionable_type' => $type,
87
        ]);
88
    }
89
}
90