Passed
Push — master ( 3ccc1d...1ca34e )
by Derek Stephen
03:01
created

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