Completed
Push — master ( d14457...da0e1e )
by Derek Stephen
25:25 queued 19:55
created

AccessToken::addScope()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
ccs 0
cts 3
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
     * @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
    public function __construct()
58
    {
59
        $this->scopes = new ArrayCollection();
60
    }
61
62
    /**
63
     * Set token
64
     *
65
     * @param string $token
66
     * @return AccessToken
67
     */
68
    public function setToken($token)
69
    {
70
        $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...
71
        return $this;
72
    }
73
74
    /**
75
     * Get token
76
     *
77
     * @return string
78
     */
79
    public function getIdentifier()
80
    {
81
        return $this->identifier;
82
    }
83
84
    /**
85
     * @param string $identifier
86
     */
87
    public function setIdentifier($identifier)
88
    {
89
        $this->identifier = $identifier;
90
    }
91
92
    /**
93
     * @param ScopeEntityInterface $scope
94
     * @return $this
95
     */
96
    public function addScope(ScopeEntityInterface $scope)
97
    {
98
        $this->scopes->add($scope);
99
        return $this;
100
    }
101
102
    /**
103
     * Return an array of scopes associated with the token.
104
     *
105
     * @return ScopeEntityInterface[]
106
     */
107
    public function getScopes()
108
    {
109
        return $this->scopes->toArray();
110
    }
111
112
    /**
113
     * Get the token's expiry date time.
114
     *
115
     * @return DateTime
116
     */
117
    public function getExpiryDateTime()
118
    {
119
        return $this->expiryDateTime;
120
    }
121
122
    /**
123
     * Set the date time when the token expires.
124
     *
125
     * @param DateTime $dateTime
126
     */
127
    public function setExpiryDateTime(DateTime $dateTime)
128
    {
129
        $this->expiryDateTime = $dateTime;
130
    }
131
132
    /**
133
     * @param int $identifier
134
     * @return $this
135
     */
136
    public function setUserIdentifier($identifier)
137
    {
138
        $this->userIdentifier = $identifier;
139
        return $this;
140
    }
141
142
    /**
143
     * Get the token user's identifier.
144
     *
145
     * @return int
146
     */
147
    public function getUserIdentifier()
148
    {
149
        return $this->userIdentifier;
150
    }
151
152
    /**
153
     * Get the client that the token was issued to.
154
     *
155
     * @return ClientEntityInterface
156
     */
157
    public function getClient()
158
    {
159
        return $this->client;
160
    }
161
162
    /**
163
     * Set the client that the token was issued to.
164
     *
165
     * @param ClientEntityInterface $client
166
     */
167
    public function setClient(ClientEntityInterface $client)
168
    {
169
        $this->client = $client;
170
    }
171
}