Passed
Pull Request — master (#1122)
by Sebastian
02:44
created

TokenEntityTrait::getUserIdentifier()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
1
<?php
2
/**
3
 * @author      Alex Bilbie <[email protected]>
4
 * @copyright   Copyright (c) Alex Bilbie
5
 * @license     http://mit-license.org/
6
 *
7
 * @link        https://github.com/thephpleague/oauth2-server
8
 */
9
10
namespace League\OAuth2\Server\Entities\Traits;
11
12
use DateTimeImmutable;
13
use League\OAuth2\Server\Entities\ClaimEntityInterface;
14
use League\OAuth2\Server\Entities\ClientEntityInterface;
15
use League\OAuth2\Server\Entities\ScopeEntityInterface;
16
17
trait TokenEntityTrait
18
{
19
    /**
20
     * @var ScopeEntityInterface[]
21
     */
22
    protected $scopes = [];
23
24
    /**
25
     * @var ClaimEntityInterface[]
26
     */
27
    protected $claims = [];
28
29
    /**
30
     * @var DateTimeImmutable
31
     */
32
    protected $expiryDateTime;
33
34
    /**
35
     * @var string|int|null
36
     */
37
    protected $userIdentifier;
38
39
    /**
40
     * @var ClientEntityInterface
41
     */
42
    protected $client;
43
44
    /**
45
     * Associate a scope with the token.
46
     *
47
     * @param ScopeEntityInterface $scope
48
     */
49
    public function addScope(ScopeEntityInterface $scope)
50
    {
51
        $this->scopes[$scope->getIdentifier()] = $scope;
52
    }
53
54
    /**
55
     * Return an array of scopes associated with the token.
56
     *
57
     * @return ScopeEntityInterface[]
58
     */
59
    public function getScopes()
60
    {
61
        return \array_values($this->scopes);
62
    }
63
64
    /**
65
     * Associate a claim with the token.
66
     *
67
     * @param ClaimEntityInterface $claim
68
     */
69
    public function addClaim(ClaimEntityInterface $claim)
70
    {
71
        $this->claims[] = $claim;
72
    }
73
74
    /**
75
     * Return an array of claims associated with the token.
76
     *
77
     * @return ClaimEntityInterface[]
78
     */
79
    public function getClaims()
80
    {
81
        return $this->claims;
82
    }
83
84
85
86
    /**
87
     * Get the token's expiry date time.
88
     *
89
     * @return DateTimeImmutable
90
     */
91
    public function getExpiryDateTime()
92
    {
93
        return $this->expiryDateTime;
94
    }
95
96
    /**
97
     * Set the date time when the token expires.
98
     *
99
     * @param DateTimeImmutable $dateTime
100
     */
101
    public function setExpiryDateTime(DateTimeImmutable $dateTime)
102
    {
103
        $this->expiryDateTime = $dateTime;
104
    }
105
106
    /**
107
     * Set the identifier of the user associated with the token.
108
     *
109
     * @param string|int|null $identifier The identifier of the user
110
     */
111
    public function setUserIdentifier($identifier)
112
    {
113
        $this->userIdentifier = $identifier;
114
    }
115
116
    /**
117
     * Get the token user's identifier.
118
     *
119
     * @return string|int|null
120
     */
121
    public function getUserIdentifier()
122
    {
123
        return $this->userIdentifier;
124
    }
125
126
    /**
127
     * Get the client that the token was issued to.
128
     *
129
     * @return ClientEntityInterface
130
     */
131
    public function getClient()
132
    {
133
        return $this->client;
134
    }
135
136
    /**
137
     * Set the client that the token was issued to.
138
     *
139
     * @param ClientEntityInterface $client
140
     */
141
    public function setClient(ClientEntityInterface $client)
142
    {
143
        $this->client = $client;
144
    }
145
}
146