Token   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 112
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 112
ccs 0
cts 25
cp 0
rs 10
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A client() 0 3 1
A can() 0 4 2
A user() 0 5 1
A cant() 0 3 1
A revoke() 0 3 1
A transient() 0 3 1
1
<?php
2
3
namespace CodexShaper\DBM\MongoDB\Passport;
4
5
use Jenssegers\Mongodb\Eloquent\Model;
0 ignored issues
show
Bug introduced by
The type Jenssegers\Mongodb\Eloquent\Model was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
7
class Token extends Model
8
{
9
    /**
10
     * The primary key for the model.
11
     *
12
     * @var string
13
     */
14
    protected $primaryKey = 'id';
15
16
    /**
17
     * The database table used by the model.
18
     *
19
     * @var string
20
     */
21
    protected $table = 'oauth_access_tokens';
22
23
    /**
24
     * Indicates if the IDs are auto-incrementing.
25
     *
26
     * @var bool
27
     */
28
    public $incrementing = false;
29
30
    /**
31
     * The guarded attributes on the model.
32
     *
33
     * @var array
34
     */
35
    protected $guarded = [];
36
37
    /**
38
     * The attributes that should be cast to native types.
39
     *
40
     * @var array
41
     */
42
    protected $casts = [
43
        'revoked' => 'bool',
44
    ];
45
46
    /**
47
     * The attributes that should be mutated to dates.
48
     *
49
     * @var array
50
     */
51
    protected $dates = [
52
        'expires_at',
53
    ];
54
55
    /**
56
     * Get the client that the token belongs to.
57
     *
58
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
59
     */
60
    public function client()
61
    {
62
        return $this->belongsTo(Client::class);
63
    }
64
65
    /**
66
     * Get the user that the token belongs to.
67
     *
68
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
69
     */
70
    public function user()
71
    {
72
        $provider = config('auth.guards.api.provider');
73
74
        return $this->belongsTo(config('auth.providers.'.$provider.'.model'));
75
    }
76
77
    /**
78
     * Determine if the token has a given scope.
79
     *
80
     * @param string $scope
81
     *
82
     * @return bool
83
     */
84
    public function can($scope)
85
    {
86
        return in_array('*', $this->scopes) ||
87
        array_key_exists($scope, array_flip($this->scopes));
88
    }
89
90
    /**
91
     * Determine if the token is missing a given scope.
92
     *
93
     * @param string $scope
94
     * @return bool
95
     */
96
    public function cant($scope)
97
    {
98
        return ! $this->can($scope);
99
    }
100
101
    /**
102
     * Revoke the token instance.
103
     *
104
     * @return void
105
     */
106
    public function revoke()
107
    {
108
        $this->forceFill(['revoked' => true])->save();
109
    }
110
111
    /**
112
     * Determine if the token is a transient JWT token.
113
     *
114
     * @return bool
115
     */
116
    public function transient()
117
    {
118
        return false;
119
    }
120
}
121