Completed
Push — master ( f5cb76...abda7b )
by Derek Stephen
06:19 queued 04:17
created

AccessToken::setRevoked()   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 2
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
     * @var bool
64
     * @ORM\Column(type="boolean")
65
     */
66
    protected $revoked = false;
67
68 6
    public function __construct()
69
    {
70 6
        $this->scopes = new ArrayCollection();
71 6
    }
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
    /**
86
     * Get token
87
     *
88
     * @return string
89
     */
90 2
    public function getIdentifier()
91
    {
92 2
        return $this->identifier;
93
    }
94
95
    /**
96
     * @param string $identifier
97
     */
98 2
    public function setIdentifier($identifier)
99
    {
100 2
        $this->identifier = $identifier;
101 2
    }
102
103
    /**
104
     * @param ScopeEntityInterface $scope
105
     * @return $this
106
     */
107 1
    public function addScope(ScopeEntityInterface $scope)
108
    {
109 1
        $this->scopes->add($scope);
110 1
        return $this;
111
    }
112
113
    /**
114
     * Return an array of scopes associated with the token.
115
     *
116
     * @return ScopeEntityInterface[]
117
     */
118 1
    public function getScopes()
119
    {
120 1
        return $this->scopes->toArray();
121
    }
122
123
    /**
124
     * Get the token's expiry date time.
125
     *
126
     * @return DateTime
127
     */
128 1
    public function getExpiryDateTime()
129
    {
130 1
        return $this->expiryDateTime;
131
    }
132
133
    /**
134
     * Set the date time when the token expires.
135
     *
136
     * @param DateTime $dateTime
137
     */
138 1
    public function setExpiryDateTime(DateTime $dateTime)
139
    {
140 1
        $this->expiryDateTime = $dateTime;
141 1
    }
142
143
    /**
144
     * @param int $identifier
145
     * @return $this
146
     */
147 1
    public function setUserIdentifier($identifier)
148
    {
149 1
        $this->userIdentifier = $identifier;
150 1
        return $this;
151
    }
152
153
    /**
154
     * Get the token user's identifier.
155
     *
156
     * @return int
157
     */
158 1
    public function getUserIdentifier()
159
    {
160 1
        return $this->userIdentifier;
161
    }
162
163
    /**
164
     * Get the client that the token was issued to.
165
     *
166
     * @return ClientEntityInterface
167
     */
168 1
    public function getClient()
169
    {
170 1
        return $this->client;
171
    }
172
173
    /**
174
     * Set the client that the token was issued to.
175
     *
176
     * @param ClientEntityInterface $client
177
     */
178 1
    public function setClient(ClientEntityInterface $client)
179
    {
180 1
        $this->client = $client;
181 1
    }
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
}