1 | <?php |
||
2 | |||
3 | /* |
||
4 | * @copyright 2014 Mautic Contributors. All rights reserved |
||
5 | * @author Mautic |
||
6 | * |
||
7 | * @link http://mautic.org |
||
8 | * |
||
9 | * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html |
||
10 | */ |
||
11 | |||
12 | namespace Mautic\ApiBundle\Entity\oAuth1; |
||
13 | |||
14 | use Bazinga\OAuthServerBundle\Model\AccessTokenInterface; |
||
15 | use Bazinga\OAuthServerBundle\Model\ConsumerInterface; |
||
16 | use Doctrine\ORM\Mapping as ORM; |
||
17 | use Mautic\CoreBundle\Doctrine\Mapping\ClassMetadataBuilder; |
||
18 | use Symfony\Component\Security\Core\User\UserInterface; |
||
19 | |||
20 | /** |
||
21 | * Class AccessToken. |
||
22 | */ |
||
23 | class AccessToken implements AccessTokenInterface |
||
24 | { |
||
25 | /** |
||
26 | * @var int |
||
27 | */ |
||
28 | protected $id; |
||
29 | |||
30 | /** |
||
31 | * @var Consumer |
||
32 | */ |
||
33 | protected $consumer; |
||
34 | |||
35 | /** |
||
36 | * @var \Mautic\UserBundle\Entity\User |
||
37 | */ |
||
38 | protected $user; |
||
39 | |||
40 | /** |
||
41 | * @var string |
||
42 | */ |
||
43 | protected $token; |
||
44 | |||
45 | /** |
||
46 | * @var string |
||
47 | */ |
||
48 | protected $secret; |
||
49 | |||
50 | /** |
||
51 | * @var null|int |
||
52 | */ |
||
53 | protected $expiresAt; |
||
54 | |||
55 | /** |
||
56 | * @param ORM\ClassMetadata $metadata |
||
57 | */ |
||
58 | public static function loadMetadata(ORM\ClassMetadata $metadata) |
||
59 | { |
||
60 | $builder = new ClassMetadataBuilder($metadata); |
||
61 | |||
62 | $builder->setTable('oauth1_access_tokens') |
||
63 | ->addIndex(['token'], 'oauth1_access_token_search'); |
||
64 | |||
65 | $builder->createField('id', 'integer') |
||
0 ignored issues
–
show
|
|||
66 | ->isPrimaryKey() |
||
67 | ->generatedValue() |
||
68 | ->build(); |
||
69 | |||
70 | $builder->createManyToOne('consumer', 'Consumer') |
||
71 | ->inversedBy('accessTokens') |
||
72 | ->addJoinColumn('consumer_id', 'id', false, false, 'CASCADE') |
||
73 | ->build(); |
||
74 | |||
75 | $builder->createManyToOne('user', 'Mautic\UserBundle\Entity\User') |
||
76 | ->addJoinColumn('user_id', 'id', false, false, 'CASCADE') |
||
77 | ->build(); |
||
78 | |||
79 | $builder->addField('token', 'string'); |
||
80 | |||
81 | $builder->addField('secret', 'string'); |
||
82 | |||
83 | $builder->createField('expiresAt', 'bigint') |
||
84 | ->columnName('expires_at') |
||
85 | ->nullable() |
||
86 | ->build(); |
||
87 | } |
||
88 | |||
89 | /** |
||
90 | * {@inheritdoc} |
||
91 | */ |
||
92 | public function getId() |
||
93 | { |
||
94 | return $this->id; |
||
95 | } |
||
96 | |||
97 | /** |
||
98 | * {@inheritdoc} |
||
99 | */ |
||
100 | public function getToken() |
||
101 | { |
||
102 | return $this->token; |
||
103 | } |
||
104 | |||
105 | /** |
||
106 | * {@inheritdoc} |
||
107 | */ |
||
108 | public function setToken($token) |
||
109 | { |
||
110 | $this->token = $token; |
||
111 | |||
112 | return $this; |
||
113 | } |
||
114 | |||
115 | /** |
||
116 | * {@inheritdoc} |
||
117 | */ |
||
118 | public function getSecret() |
||
119 | { |
||
120 | return $this->secret; |
||
121 | } |
||
122 | |||
123 | /** |
||
124 | * {@inheritdoc} |
||
125 | */ |
||
126 | public function setSecret($secret) |
||
127 | { |
||
128 | $this->secret = $secret; |
||
129 | |||
130 | return $this; |
||
131 | } |
||
132 | |||
133 | /** |
||
134 | * {@inheritdoc} |
||
135 | */ |
||
136 | public function getExpiresAt() |
||
137 | { |
||
138 | return $this->expiresAt; |
||
139 | } |
||
140 | |||
141 | /** |
||
142 | * {@inheritdoc} |
||
143 | */ |
||
144 | public function setExpiresAt($expiresAt) |
||
145 | { |
||
146 | $this->expiresAt = $expiresAt; |
||
147 | |||
148 | return $this; |
||
149 | } |
||
150 | |||
151 | /** |
||
152 | * {@inheritdoc} |
||
153 | */ |
||
154 | public function getExpiresIn() |
||
155 | { |
||
156 | if ($this->expiresAt) { |
||
0 ignored issues
–
show
The expression
$this->expiresAt of type integer|null is loosely compared to true ; this is ambiguous if the integer can be 0. You might want to explicitly use !== null instead.
In PHP, under loose comparison (like For 0 == false // true
0 == null // true
123 == false // false
123 == null // false
// It is often better to use strict comparison
0 === false // false
0 === null // false
Loading history...
|
|||
157 | return $this->expiresAt - time(); |
||
158 | } |
||
159 | |||
160 | return PHP_INT_MAX; |
||
161 | } |
||
162 | |||
163 | /** |
||
164 | * {@inheritdoc} |
||
165 | */ |
||
166 | public function hasExpired() |
||
167 | { |
||
168 | if ($this->expiresAt) { |
||
0 ignored issues
–
show
The expression
$this->expiresAt of type integer|null is loosely compared to true ; this is ambiguous if the integer can be 0. You might want to explicitly use !== null instead.
In PHP, under loose comparison (like For 0 == false // true
0 == null // true
123 == false // false
123 == null // false
// It is often better to use strict comparison
0 === false // false
0 === null // false
Loading history...
|
|||
169 | return time() > $this->expiresAt; |
||
170 | } |
||
171 | |||
172 | return false; |
||
173 | } |
||
174 | |||
175 | /** |
||
176 | * {@inheritdoc} |
||
177 | */ |
||
178 | public function getUser() |
||
179 | { |
||
180 | return $this->user; |
||
181 | } |
||
182 | |||
183 | /** |
||
184 | * {@inheritdoc} |
||
185 | */ |
||
186 | public function setUser(UserInterface $user) |
||
187 | { |
||
188 | $this->user = $user; |
||
0 ignored issues
–
show
$user is of type Symfony\Component\Security\Core\User\UserInterface , but the property $user was declared to be of type Mautic\UserBundle\Entity\User . Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof 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 given class or a super-class is assigned to a property that is type hinted more strictly. Either this assignment is in error or an instanceof check should be added for that assignment. class Alien {}
class Dalek extends Alien {}
class Plot
{
/** @var Dalek */
public $villain;
}
$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
$plot->villain = $alien;
}
Loading history...
|
|||
189 | |||
190 | return $this; |
||
191 | } |
||
192 | |||
193 | /** |
||
194 | * {@inheritdoc} |
||
195 | */ |
||
196 | public function setConsumer(ConsumerInterface $consumer) |
||
197 | { |
||
198 | $this->consumer = $consumer; |
||
0 ignored issues
–
show
$consumer is of type Bazinga\OAuthServerBundle\Model\ConsumerInterface , but the property $consumer was declared to be of type Mautic\ApiBundle\Entity\oAuth1\Consumer . Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof 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 given class or a super-class is assigned to a property that is type hinted more strictly. Either this assignment is in error or an instanceof check should be added for that assignment. class Alien {}
class Dalek extends Alien {}
class Plot
{
/** @var Dalek */
public $villain;
}
$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
$plot->villain = $alien;
}
Loading history...
|
|||
199 | |||
200 | return $this; |
||
201 | } |
||
202 | |||
203 | /** |
||
204 | * {@inheritdoc} |
||
205 | */ |
||
206 | public function getConsumer() |
||
207 | { |
||
208 | return $this->consumer; |
||
209 | } |
||
210 | } |
||
211 |
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.