AbstractToken::getIdentifier()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
4
namespace Mvdstam\Oauth2ServerLaravel\Entities;
5
6
7
use DateTime;
8
use League\OAuth2\Server\Entities\ClientEntityInterface;
9
use League\OAuth2\Server\Entities\ScopeEntityInterface;
10
use Mvdstam\Oauth2ServerLaravel\Repositories\ScopeRepository;
11
12
/**
13
 * Class AbstractToken
14
 * @package Mvdstam\Oauth2ServerLaravel\Entities
15
 * @property-read string $id
16
 * @property-read DateTime $expires_at
17
 * @property-read string|int|null $user_id
18
 * @property-read Scope[]|\Illuminate\Database\Eloquent\Collection $scopes
19
 * @property-read User|null $user
20
 * @property-read Client $client
21
 */
22
abstract class AbstractToken extends AbstractEntity
23
{
24
25
    protected $dates = [
26
        'expires_at'
27
    ];
28
29 12
    public function getIdentifier()
30
    {
31 12
        return $this->id;
32
    }
33
34 11
    public function setIdentifier($identifier)
35
    {
36 11
        $this->forceFill(['id' => $identifier]);
37 11
    }
38
39 12
    public function getExpiryDateTime()
40
    {
41 12
        return $this->expires_at;
42
    }
43
44 11
    public function setExpiryDateTime(DateTime $dateTime)
45
    {
46 11
        $this->forceFill(['expires_at' => $dateTime]);
47 11
    }
48
49 11
    public function setUserIdentifier($identifier)
50
    {
51 11
        $this->forceFill(['user_id' => $identifier]);
52 11
    }
53
54 12
    public function getUserIdentifier()
55
    {
56 12
        return $this->user_id;
57
    }
58
59 11
    public function getClient()
60
    {
61 11
        return $this->client;
62
    }
63
64 11
    public function setClient(ClientEntityInterface $client)
65
    {
66 11
        $this->client()->associate($client->getIdentifier());
67 11
    }
68
69 4
    public function addScope(ScopeEntityInterface $scope)
70
    {
71
        /** @var ScopeRepository $scopes */
72 4
        $scopes = app(ScopeRepository::class);
73
74 4
        if (!in_array($scope->getIdentifier(), $this->scopes->modelKeys())) {
75 4
            $this->scopes->add($scopes->findOrFail($scope->getIdentifier()));
76
        }
77 4
    }
78
79 11
    public function getScopes()
80
    {
81 11
        return $this->scopes->all();
82
    }
83
84 12
    public function client()
85
    {
86 12
        return $this->belongsTo(Client::class);
87
    }
88
89 11
    public function scopes()
90
    {
91 11
        return $this->belongsToMany(Scope::class);
92
    }
93
94 1
    public function user()
95
    {
96 1
        return $this->belongsTo(User::class);
97
    }
98
99
}
100