Completed
Push — master ( a9822c...8aa0e0 )
by Derek Stephen
14:27
created

AccessToken::setUserIdentifier()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 5
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 5
loc 5
c 0
b 0
f 0
ccs 0
cts 3
cp 0
rs 10
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 View Code Duplication
class AccessToken implements AccessTokenEntityInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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 5
    public function __construct()
58
    {
59 5
        $this->scopes = new ArrayCollection();
60 5
    }
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 introduced by
The property token does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
71
        return $this;
72
    }
73
74
    /**
75
     * Get token
76
     *
77
     * @return string
78
     */
79 2
    public function getIdentifier()
80
    {
81 2
        return $this->identifier;
82
    }
83
84
    /**
85
     * @param string $identifier
86
     */
87 2
    public function setIdentifier($identifier)
88
    {
89 2
        $this->identifier = $identifier;
90 2
    }
91
92
    /**
93
     * @param ScopeEntityInterface $scope
94
     * @return $this
95
     */
96 1
    public function addScope(ScopeEntityInterface $scope)
97
    {
98 1
        $this->scopes->add($scope);
99 1
        return $this;
100
    }
101
102
    /**
103
     * Return an array of scopes associated with the token.
104
     *
105
     * @return ScopeEntityInterface[]
106
     */
107 1
    public function getScopes()
108
    {
109 1
        return $this->scopes->toArray();
110
    }
111
112
    /**
113
     * Get the token's expiry date time.
114
     *
115
     * @return DateTime
116
     */
117 1
    public function getExpiryDateTime()
118
    {
119 1
        return $this->expiryDateTime;
120
    }
121
122
    /**
123
     * Set the date time when the token expires.
124
     *
125
     * @param DateTime $dateTime
126
     */
127 1
    public function setExpiryDateTime(DateTime $dateTime)
128
    {
129 1
        $this->expiryDateTime = $dateTime;
130 1
    }
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 1
    public function getClient()
158
    {
159 1
        return $this->client;
160
    }
161
162
    /**
163
     * Set the client that the token was issued to.
164
     *
165
     * @param ClientEntityInterface $client
166
     */
167 1
    public function setClient(ClientEntityInterface $client)
168
    {
169 1
        $this->client = $client;
170
    }
171
}