Passed
Pull Request — master (#1138)
by
unknown
02:07
created

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