Passed
Push — master ( 897bc8...5aa273 )
by Derek Stephen
02:48
created

AccessToken::setClient()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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