Completed
Push — master ( 4d66f1...f5cb76 )
by Derek Stephen
06:43
created

AccessToken::setIdentifier()   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
eloc 1
dl 0
loc 3
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace OAuth;
4
5
use DateTime;
6
use Doctrine\Common\Collections\ArrayCollection;
7
use Doctrine\ORM\Mapping as ORM;
8
use League\OAuth2\Server\Entities\AccessTokenEntityInterface;
9
use League\OAuth2\Server\Entities\ClientEntityInterface;
10
use League\OAuth2\Server\Entities\ScopeEntityInterface;
11
use League\OAuth2\Server\Entities\Traits\AccessTokenTrait;
12
13
/**
14
* @ORM\Entity(repositoryClass="OAuth\Repository\AccessTokenRepository")
15
* @ORM\Table(name="AccessToken")
16
*/
17
class AccessToken implements AccessTokenEntityInterface
18
{
19
    use AccessTokenTrait;
20
21
22
    /**
23
     * @ORM\Id()
24
     * @ORM\GeneratedValue()
25
     * @ORM\Column(type="integer")
26
     * @var int|null
27
     */
28
    private $id;
29
30
    /**
31
     * @var ArrayCollection $scopes
32
     * @ORM\ManyToMany(targetEntity="Oauth\Scope")
33
     * @ORM\JoinTable(name="AccessToken_Scope")
34
     */
35
    protected $scopes;
36
37
    /**
38
     * @var DateTime
39
     * @ORM\Column(type="date",nullable=true)
40
     */
41
    protected $expiryDateTime;
42
43
    /**
44
     * @var int
45
     * @ORM\Column(type="integer", length=11, nullable=true)
46
     */
47
    protected $userIdentifier;
48
49
    /**
50
     * @var ClientEntityInterface
51
     * @ORM\ManyToOne(targetEntity="OAuth\Client")
52
     * @ORM\JoinColumn(name="client", referencedColumnName="id")
53
     */
54
    protected $client;
55
56
    /**
57
     * @var string
58
     * @ORM\Column(type="string", length=255)
59
     */
60
    protected $identifier;
61
62
    /**
63 6
     * @var bool
64
     * @ORM\Column(type="boolean")
65 6
     */
66 6
    protected $revoked = false;
67
68
    public function __construct()
69
    {
70
        $this->scopes = new ArrayCollection();
71
    }
72
73
    /**
74
     * Set token
75
     *
76
     * @param string $token
77
     * @return AccessToken
78
     */
79
    public function setToken($token)
80
    {
81
        $this->token = $token;
0 ignored issues
show
Bug Best Practice introduced by
The property token does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
82
        return $this;
83
    }
84
85 2
    /**
86
     * Get token
87 2
     *
88
     * @return string
89
     */
90
    public function getIdentifier()
91
    {
92
        return $this->identifier;
93 2
    }
94
95 2
    /**
96 2
     * @param string $identifier
97
     */
98
    public function setIdentifier($identifier)
99
    {
100
        $this->identifier = $identifier;
101
    }
102 1
103
    /**
104 1
     * @param ScopeEntityInterface $scope
105 1
     * @return $this
106
     */
107
    public function addScope(ScopeEntityInterface $scope)
108
    {
109
        $this->scopes->add($scope);
110
        return $this;
111
    }
112
113 1
    /**
114
     * Return an array of scopes associated with the token.
115 1
     *
116
     * @return ScopeEntityInterface[]
117
     */
118
    public function getScopes()
119
    {
120
        return $this->scopes->toArray();
121
    }
122
123 1
    /**
124
     * Get the token's expiry date time.
125 1
     *
126
     * @return DateTime
127
     */
128
    public function getExpiryDateTime()
129
    {
130
        return $this->expiryDateTime;
131
    }
132
133 1
    /**
134
     * Set the date time when the token expires.
135 1
     *
136 1
     * @param DateTime $dateTime
137
     */
138
    public function setExpiryDateTime(DateTime $dateTime)
139
    {
140
        $this->expiryDateTime = $dateTime;
141
    }
142 1
143
    /**
144 1
     * @param int $identifier
145 1
     * @return $this
146
     */
147
    public function setUserIdentifier($identifier)
148
    {
149
        $this->userIdentifier = $identifier;
150
        return $this;
151
    }
152
153 1
    /**
154
     * Get the token user's identifier.
155 1
     *
156
     * @return int
157
     */
158
    public function getUserIdentifier()
159
    {
160
        return $this->userIdentifier;
161
    }
162
163 1
    /**
164
     * Get the client that the token was issued to.
165 1
     *
166
     * @return ClientEntityInterface
167
     */
168
    public function getClient()
169
    {
170
        return $this->client;
171
    }
172
173 1
    /**
174
     * Set the client that the token was issued to.
175 1
     *
176 1
     * @param ClientEntityInterface $client
177
     */
178
    public function setClient(ClientEntityInterface $client)
179
    {
180
        $this->client = $client;
181
    }
182
183
    /**
184
     * @return bool
185
     */
186
    public function isRevoked(): bool
187
    {
188
        return $this->revoked;
189
    }
190
191
    /**
192
     * @param bool $revoked
193
     */
194
    public function setRevoked(bool $revoked): void
195
    {
196
        $this->revoked = $revoked;
197
    }
198
199
    /**
200
     * @return int|null
201
     */
202
    public function getId(): ?int
203
    {
204
        return $this->id;
205
    }
206
}