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\ConsumerInterface; |
||
15 | use Bazinga\OAuthServerBundle\Model\RequestTokenInterface; |
||
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 RequestToken. |
||
22 | */ |
||
23 | class RequestToken implements RequestTokenInterface |
||
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 int |
||
52 | */ |
||
53 | protected $expiresAt; |
||
54 | |||
55 | /** |
||
56 | * @var string |
||
57 | */ |
||
58 | protected $verifier; |
||
59 | |||
60 | public static function loadMetadata(ORM\ClassMetadata $metadata) |
||
61 | { |
||
62 | $builder = new ClassMetadataBuilder($metadata); |
||
63 | |||
64 | $builder->setTable('oauth1_request_tokens') |
||
65 | ->addIndex(['token'], 'oauth1_request_token_search'); |
||
66 | |||
67 | $builder->createField('id', 'integer') |
||
68 | ->isPrimaryKey() |
||
69 | ->generatedValue() |
||
70 | ->build(); |
||
71 | |||
72 | $builder->createManyToOne('consumer', 'Consumer') |
||
73 | ->addJoinColumn('consumer_id', 'id', false, false, 'CASCADE') |
||
74 | ->build(); |
||
75 | |||
76 | $builder->createManyToOne('user', 'Mautic\UserBundle\Entity\User') |
||
77 | ->addJoinColumn('user_id', 'id', true, false, 'CASCADE') |
||
78 | ->build(); |
||
79 | |||
80 | $builder->addField('token', 'string'); |
||
81 | |||
82 | $builder->addField('secret', 'string'); |
||
83 | |||
84 | $builder->createField('expiresAt', 'bigint') |
||
85 | ->columnName('expires_at') |
||
86 | ->build(); |
||
87 | |||
88 | $builder->addField('verifier', 'string'); |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * {@inheritdoc} |
||
93 | */ |
||
94 | public function getId() |
||
95 | { |
||
96 | return $this->id; |
||
97 | } |
||
98 | |||
99 | /** |
||
100 | * {@inheritdoc} |
||
101 | */ |
||
102 | public function getToken() |
||
103 | { |
||
104 | return $this->token; |
||
105 | } |
||
106 | |||
107 | /** |
||
108 | * {@inheritdoc} |
||
109 | */ |
||
110 | public function setToken($token) |
||
111 | { |
||
112 | $this->token = $token; |
||
113 | |||
114 | return $this; |
||
115 | } |
||
116 | |||
117 | /** |
||
118 | * {@inheritdoc} |
||
119 | */ |
||
120 | public function getSecret() |
||
121 | { |
||
122 | return $this->secret; |
||
123 | } |
||
124 | |||
125 | /** |
||
126 | * {@inheritdoc} |
||
127 | */ |
||
128 | public function setSecret($secret) |
||
129 | { |
||
130 | $this->secret = $secret; |
||
131 | |||
132 | return $this; |
||
133 | } |
||
134 | |||
135 | /** |
||
136 | * {@inheritdoc} |
||
137 | */ |
||
138 | public function getExpiresAt() |
||
139 | { |
||
140 | return $this->expiresAt; |
||
141 | } |
||
142 | |||
143 | /** |
||
144 | * {@inheritdoc} |
||
145 | */ |
||
146 | public function setExpiresAt($expiresAt) |
||
147 | { |
||
148 | $this->expiresAt = $expiresAt; |
||
149 | |||
150 | return $this; |
||
151 | } |
||
152 | |||
153 | /** |
||
154 | * {@inheritdoc} |
||
155 | */ |
||
156 | public function getExpiresIn() |
||
157 | { |
||
158 | if ($this->expiresAt) { |
||
159 | return $this->expiresAt - time(); |
||
160 | } |
||
161 | |||
162 | return PHP_INT_MAX; |
||
163 | } |
||
164 | |||
165 | /** |
||
166 | * {@inheritdoc} |
||
167 | */ |
||
168 | public function hasExpired() |
||
169 | { |
||
170 | if ($this->expiresAt) { |
||
171 | return time() > $this->expiresAt; |
||
172 | } |
||
173 | |||
174 | return false; |
||
175 | } |
||
176 | |||
177 | /** |
||
178 | * {@inheritdoc} |
||
179 | */ |
||
180 | public function getUser() |
||
181 | { |
||
182 | return $this->user; |
||
183 | } |
||
184 | |||
185 | /** |
||
186 | * {@inheritdoc} |
||
187 | */ |
||
188 | public function setUser(UserInterface $user) |
||
189 | { |
||
190 | $this->user = $user; |
||
0 ignored issues
–
show
|
|||
191 | |||
192 | return $this; |
||
193 | } |
||
194 | |||
195 | /** |
||
196 | * {@inheritdoc} |
||
197 | */ |
||
198 | public function setConsumer(ConsumerInterface $consumer) |
||
199 | { |
||
200 | $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...
|
|||
201 | |||
202 | return $this; |
||
203 | } |
||
204 | |||
205 | /** |
||
206 | * {@inheritdoc} |
||
207 | */ |
||
208 | public function getConsumer() |
||
209 | { |
||
210 | return $this->consumer; |
||
211 | } |
||
212 | |||
213 | /** |
||
214 | * {@inheritdoc} |
||
215 | */ |
||
216 | public function getVerifier() |
||
217 | { |
||
218 | return $this->verifier; |
||
219 | } |
||
220 | |||
221 | /** |
||
222 | * {@inheritdoc} |
||
223 | */ |
||
224 | public function setVerifier($verifier) |
||
225 | { |
||
226 | $this->verifier = $verifier; |
||
227 | } |
||
228 | } |
||
229 |
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.