Completed
Push — master ( efbe60...e38209 )
by Derek Stephen
05:09
created

AccessToken::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace OAuth;
4
5
use DateTime;
6
use Doctrine\Common\Collections\ArrayCollection;
7
use League\OAuth2\Server\Entities\AccessTokenEntityInterface;
8
use League\OAuth2\Server\Entities\ClientEntityInterface;
9
use League\OAuth2\Server\Entities\ScopeEntityInterface;
10
use League\OAuth2\Server\Entities\Traits\AccessTokenTrait;
11
12
/**
13
* @Entity
14
* @Table(name="AccessToken")
15
*/
16
class AccessToken implements AccessTokenEntityInterface
17
{
18
    use AccessTokenTrait;
19
20
    /**
21
     * @var ArrayCollection $scopes
22
     * @ManyToMany(targetEntity="OAuth\Scope")
23
     * @JoinTable(name="AccessTokenScope",
24
     *      joinColumns={@JoinColumn(name="scopeId", referencedColumnName="identifier")},
25
     *      inverseJoinColumns={@JoinColumn(name="accessTokenId", referencedColumnName="identifier")}
26
     *      )
27
     */
28
    protected $scopes;
29
30
    /**
31
     * @var DateTime
32
     * @Column(type="date",nullable=true)
33
     */
34
    protected $expiryDateTime;
35
36
    /**
37
     * @var string
38
     * @ManyToOne(targetEntity="OAuth\User")
39
     * @JoinColumn(name="userIdentifier", referencedColumnName="id")
40
     */
41
    protected $userIdentifier;
42
43
    /**
44
     * @var ClientEntityInterface
45
     * @ManyToOne(targetEntity="OAuth\Client")
46
     * @JoinColumn(name="client", referencedColumnName="identifier")
47
     */
48
    protected $client;
49
50
    /**
51
     * @var string
52
     * @Id
53
     * @Column(type="string", length=40)
54
     */
55
    protected $identifier;
56
57
    public function __construct()
58
    {
59
        $this->scopes = new ArrayCollection();
60
    }
61
62
    /**
63
     * @return mixed
64
     */
65
    public function getIdentifier()
66
    {
67
        return $this->identifier;
68
    }
69
70
    /**
71
     * @param mixed $identifier
72
     */
73
    public function setIdentifier($identifier)
74
    {
75
        $this->identifier = $identifier;
76
    }
77
78
    /**
79
     * Associate a scope with the token.
80
     *
81
     * @param ScopeEntityInterface $scope
82
     */
83
    public function addScope(ScopeEntityInterface $scope)
84
    {
85
        $this->scopes[$scope->getIdentifier()] = $scope;
86
    }
87
88
    /**
89
     * Return an array of scopes associated with the token.
90
     *
91
     * @return ScopeEntityInterface[]
92
     */
93
    public function getScopes()
94
    {
95
        return array_values($this->scopes);
96
    }
97
98
    /**
99
     * Get the token's expiry date time.
100
     *
101
     * @return DateTime
102
     */
103
    public function getExpiryDateTime()
104
    {
105
        return $this->expiryDateTime;
106
    }
107
108
    /**
109
     * Set the date time when the token expires.
110
     *
111
     * @param DateTime $dateTime
112
     */
113
    public function setExpiryDateTime(DateTime $dateTime)
114
    {
115
        $this->expiryDateTime = $dateTime;
116
    }
117
118
    /**
119
     * Set the identifier of the user associated with the token.
120
     *
121
     * @param string|int $identifier The identifier of the user
122
     */
123
    public function setUserIdentifier($identifier)
124
    {
125
        $this->userIdentifier = $identifier;
0 ignored issues
show
Documentation Bug introduced by
It seems like $identifier can also be of type integer. However, the property $userIdentifier is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
126
    }
127
128
    /**
129
     * Get the token user's identifier.
130
     *
131
     * @return string|int
132
     */
133
    public function getUserIdentifier()
134
    {
135
        return $this->userIdentifier;
136
    }
137
138
    /**
139
     * Get the client that the token was issued to.
140
     *
141
     * @return ClientEntityInterface
142
     */
143
    public function getClient()
144
    {
145
        return $this->client;
146
    }
147
148
    /**
149
     * Set the client that the token was issued to.
150
     *
151
     * @param ClientEntityInterface $client
152
     */
153
    public function setClient(ClientEntityInterface $client)
154
    {
155
        $this->client = $client;
156
    }
157
}